2 * Implements HPUX syscalls.
4 * Copyright (C) 1999 Matthew Wilcox <willy with parisc-linux.org>
5 * Copyright (C) 2000 Philipp Rumpf
6 * Copyright (C) 2000 John Marvin <jsm with parisc-linux.org>
7 * Copyright (C) 2000 Michael Ang <mang with subcarrier.org>
8 * Copyright (C) 2001 Nathan Neulinger <nneul at umr.edu>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <linux/capability.h>
26 #include <linux/file.h>
28 #include <linux/namei.h>
29 #include <linux/sched.h>
30 #include <linux/slab.h>
31 #include <linux/smp_lock.h>
32 #include <linux/syscalls.h>
33 #include <linux/utsname.h>
34 #include <linux/vfs.h>
35 #include <linux/vmalloc.h>
36 #include <linux/vs_cvirt.h>
38 #include <asm/errno.h>
39 #include <asm/pgalloc.h>
40 #include <asm/uaccess.h>
42 unsigned long hpux_brk(unsigned long addr)
44 /* Sigh. Looks like HP/UX libc relies on kernel bugs. */
45 return sys_brk(addr + PAGE_SIZE);
53 /* Random other syscalls */
55 int hpux_nice(int priority_change)
65 int hpux_wait(int *stat_loc)
67 return sys_waitpid(-1, stat_loc, 0);
70 int hpux_setpgrp(void)
72 return sys_setpgid(0,0);
75 int hpux_setpgrp3(void)
77 return hpux_setpgrp();
80 #define _SC_CPU_VERSION 10001
81 #define _SC_OPEN_MAX 4
82 #define CPU_PA_RISC1_1 0x210
84 int hpux_sysconf(int which)
88 return CPU_PA_RISC1_1;
96 /*****************************************************************************/
101 struct hpux_utsname {
102 char sysname[HPUX_UTSLEN];
103 char nodename[HPUX_UTSLEN];
104 char release[HPUX_UTSLEN];
105 char version[HPUX_UTSLEN];
106 char machine[HPUX_UTSLEN];
107 char idnumber[HPUX_SNLEN];
111 int32_t f_tfree; /* total free (daddr_t) */
112 u_int32_t f_tinode; /* total inodes free (ino_t) */
113 char f_fname[6]; /* filsys name */
114 char f_fpack[6]; /* filsys pack name */
115 u_int32_t f_blksize; /* filsys block size (int) */
119 * HPUX's utssys() call. It's a collection of miscellaneous functions,
120 * alas, so there's no nice way of splitting them up.
123 /* This function is called from hpux_utssys(); HP-UX implements
124 * ustat() as an option to utssys().
126 * Now, struct ustat on HP-UX is exactly the same as on Linux, except
127 * that it contains one addition field on the end, int32_t f_blksize.
128 * So, we could have written this function to just call the Linux
129 * sys_ustat(), (defined in linux/fs/super.c), and then just
130 * added this additional field to the user's structure. But I figure
131 * if we're gonna be digging through filesystem structures to get
132 * this, we might as well just do the whole enchilada all in one go.
134 * So, most of this function is almost identical to sys_ustat().
135 * I have placed comments at the few lines changed or added, to
136 * aid in porting forward if and when sys_ustat() is changed from
137 * its form in kernel 2.2.5.
139 static int hpux_ustat(dev_t dev, struct hpux_ustat __user *ubuf)
141 struct super_block *s;
142 struct hpux_ustat tmp; /* Changed to hpux_ustat */
146 s = user_get_super(dev);
149 err = vfs_statfs(s->s_root, &sbuf);
154 memset(&tmp,0,sizeof(tmp));
156 tmp.f_tfree = (int32_t)sbuf.f_bfree;
157 tmp.f_tinode = (u_int32_t)sbuf.f_ffree;
158 tmp.f_blksize = (u_int32_t)sbuf.f_bsize; /* Added this line */
160 err = copy_to_user(ubuf, &tmp, sizeof(tmp)) ? -EFAULT : 0;
166 * Wrapper for hpux statfs call. At the moment, just calls the linux native one
167 * and ignores the extra fields at the end of the hpux statfs struct.
171 typedef int32_t hpux_fsid_t[2]; /* file system ID type */
172 typedef uint16_t hpux_site_t;
175 int32_t f_type; /* type of info, zero for now */
176 int32_t f_bsize; /* fundamental file system block size */
177 int32_t f_blocks; /* total blocks in file system */
178 int32_t f_bfree; /* free block in fs */
179 int32_t f_bavail; /* free blocks avail to non-superuser */
180 int32_t f_files; /* total file nodes in file system */
181 int32_t f_ffree; /* free file nodes in fs */
182 hpux_fsid_t f_fsid; /* file system ID */
183 int32_t f_magic; /* file system magic number */
184 int32_t f_featurebits; /* file system features */
185 int32_t f_spare[4]; /* spare for later */
186 hpux_site_t f_cnode; /* cluster node where mounted */
190 static int vfs_statfs_hpux(struct dentry *dentry, struct hpux_statfs *buf)
195 retval = vfs_statfs(dentry, &st);
199 memset(buf, 0, sizeof(*buf));
200 buf->f_type = st.f_type;
201 buf->f_bsize = st.f_bsize;
202 buf->f_blocks = st.f_blocks;
203 buf->f_bfree = st.f_bfree;
204 buf->f_bavail = st.f_bavail;
205 buf->f_files = st.f_files;
206 buf->f_ffree = st.f_ffree;
207 buf->f_fsid[0] = st.f_fsid.val[0];
208 buf->f_fsid[1] = st.f_fsid.val[1];
214 asmlinkage long hpux_statfs(const char __user *path,
215 struct hpux_statfs __user *buf)
220 error = user_path_walk(path, &nd);
222 struct hpux_statfs tmp;
223 error = vfs_statfs_hpux(nd.dentry, &tmp);
224 if (!error && copy_to_user(buf, &tmp, sizeof(tmp)))
231 asmlinkage long hpux_fstatfs(unsigned int fd, struct hpux_statfs __user * buf)
234 struct hpux_statfs tmp;
241 error = vfs_statfs_hpux(file->f_dentry, &tmp);
242 if (!error && copy_to_user(buf, &tmp, sizeof(tmp)))
250 /* This function is called from hpux_utssys(); HP-UX implements
251 * uname() as an option to utssys().
253 * The form of this function is pretty much copied from sys_olduname(),
254 * defined in linux/arch/i386/kernel/sys_i386.c.
256 /* TODO: Are these put_user calls OK? Should they pass an int?
257 * (I copied it from sys_i386.c like this.)
259 static int hpux_uname(struct hpux_utsname *name)
265 if (!access_ok(VERIFY_WRITE,name,sizeof(struct hpux_utsname)))
270 error = __copy_to_user(&name->sysname,vx_new_uts(sysname),HPUX_UTSLEN-1);
271 error |= __put_user(0,name->sysname+HPUX_UTSLEN-1);
272 error |= __copy_to_user(&name->nodename,vx_new_uts(nodename),HPUX_UTSLEN-1);
273 error |= __put_user(0,name->nodename+HPUX_UTSLEN-1);
274 error |= __copy_to_user(&name->release,vx_new_uts(release),HPUX_UTSLEN-1);
275 error |= __put_user(0,name->release+HPUX_UTSLEN-1);
276 error |= __copy_to_user(&name->version,vx_new_uts(version),HPUX_UTSLEN-1);
277 error |= __put_user(0,name->version+HPUX_UTSLEN-1);
278 error |= __copy_to_user(&name->machine,vx_new_uts(machine),HPUX_UTSLEN-1);
279 error |= __put_user(0,name->machine+HPUX_UTSLEN-1);
283 /* HP-UX utsname has no domainname field. */
285 /* TODO: Implement idnumber!!! */
287 error |= __put_user(0,name->idnumber);
288 error |= __put_user(0,name->idnumber+HPUX_SNLEN-1);
291 error = error ? -EFAULT : 0;
296 /* Note: HP-UX just uses the old suser() function to check perms
297 * in this system call. We'll use capable(CAP_SYS_ADMIN).
299 int hpux_utssys(char *ubuf, int n, int type)
306 return( hpux_uname( (struct hpux_utsname *)ubuf ) );
309 /* Obsolete (used to be umask().) */
314 return( hpux_ustat(new_decode_dev(n), (struct hpux_ustat *)ubuf) );
319 * On linux (unlike HP-UX), utsname.nodename
320 * is the same as the hostname.
322 * sys_sethostname() is defined in linux/kernel/sys.c.
324 if (!capable(CAP_SYS_ADMIN))
326 /* Unlike Linux, HP-UX returns an error if n==0: */
329 /* Unlike Linux, HP-UX truncates it if n is too big: */
330 len = (n <= __NEW_UTS_LEN) ? n : __NEW_UTS_LEN ;
331 return( sys_sethostname(ubuf, len) );
336 * sys_sethostname() is defined in linux/kernel/sys.c.
338 if (!capable(CAP_SYS_ADMIN))
340 /* Unlike Linux, HP-UX returns an error if n==0: */
343 /* Unlike Linux, HP-UX truncates it if n is too big: */
344 len = (n <= __NEW_UTS_LEN) ? n : __NEW_UTS_LEN ;
345 return( sys_sethostname(ubuf, len) );
350 * sys_gethostname() is defined in linux/kernel/sys.c.
352 /* Unlike Linux, HP-UX returns an error if n==0: */
355 return( sys_gethostname(ubuf, n) );
358 /* Supposedly called from setuname() in libc.
359 * TODO: When and why is this called?
360 * Is it ever even called?
362 * This code should look a lot like sys_sethostname(),
363 * defined in linux/kernel/sys.c. If that gets updated,
364 * update this code similarly.
366 if (!capable(CAP_SYS_ADMIN))
368 /* Unlike Linux, HP-UX returns an error if n==0: */
371 /* Unlike Linux, HP-UX truncates it if n is too big: */
372 len = (n <= __NEW_UTS_LEN) ? n : __NEW_UTS_LEN ;
374 /* TODO: print a warning about using this? */
375 down_write(&uts_sem);
377 if (!copy_from_user(vx_new_uts(sysname), ubuf, len)) {
378 vx_new_uts(sysname)[len] = 0;
385 /* Sets utsname.release, if you're allowed.
386 * Undocumented. Used by swinstall to change the
387 * OS version, during OS updates. Yuck!!!
389 * This code should look a lot like sys_sethostname()
390 * in linux/kernel/sys.c. If that gets updated, update
391 * this code similarly.
393 if (!capable(CAP_SYS_ADMIN))
395 /* Unlike Linux, HP-UX returns an error if n==0: */
398 /* Unlike Linux, HP-UX truncates it if n is too big: */
399 len = (n <= __NEW_UTS_LEN) ? n : __NEW_UTS_LEN ;
401 /* TODO: print a warning about this? */
402 down_write(&uts_sem);
404 if (!copy_from_user(vx_new_uts(release), ubuf, len)) {
405 vx_new_uts(release)[len] = 0;
412 /* This system call returns -EFAULT if given an unknown type.
413 * Why not -EINVAL? I don't know, it's just not what they did.
419 int hpux_getdomainname(char *name, int len)
426 nlen = strlen(vx_new_uts(domainname)) + 1;
430 if(len > __NEW_UTS_LEN)
432 if(copy_to_user(name, vx_new_uts(domainname), len))
441 int hpux_pipe(int *kstack_fildes)
446 error = do_pipe(kstack_fildes);
451 /* lies - says it works, but it really didn't lock anything */
452 int hpux_lockf(int fildes, int function, off_t size)
457 int hpux_sysfs(int opcode, unsigned long arg1, unsigned long arg2)
463 /*Unimplemented HP-UX syscall emulation. Syscall #334 (sysfs)
464 Args: 1 80057bf4 0 400179f0 0 0 0 */
465 printk(KERN_DEBUG "in hpux_sysfs\n");
466 printk(KERN_DEBUG "hpux_sysfs called with opcode = %d\n", opcode);
467 printk(KERN_DEBUG "hpux_sysfs called with arg1='%lx'\n", arg1);
469 if ( opcode == 1 ) { /* GETFSIND */
470 len = strlen_user((char *)arg1);
471 printk(KERN_DEBUG "len of arg1 = %d\n", len);
474 fsname = (char *) kmalloc(len, GFP_KERNEL);
476 printk(KERN_DEBUG "failed to kmalloc fsname\n");
480 if ( copy_from_user(fsname, (char *)arg1, len) ) {
481 printk(KERN_DEBUG "failed to copy_from_user fsname\n");
486 /* String could be altered by userspace after strlen_user() */
489 printk(KERN_DEBUG "that is '%s' as (char *)\n", fsname);
490 if ( !strcmp(fsname, "hfs") ) {
498 printk(KERN_DEBUG "returning fstype=%d\n", fstype);
499 return fstype; /* something other than default */
507 /* Table of syscall names and handle for unimplemented routines */
508 static const char *syscall_names[] = {
589 "setgroups", /* 80 */
609 "getpriority", /* 100 */
619 "sigsetmask", /* 110 */
639 "ftruncate", /* 130 */
654 "setrlimit", /* 145 */
684 "osetcontext", /* 175 */
689 "cnodeid/mysite", /* 180 */
694 "sigprocmask", /* 185 */
704 "getdirentries", /* 195 */
734 "sigsetstatemask", /* 225 */
739 "pathconf", /* 230 */
749 "getaudid", /* 240 */
754 "setevent", /* 245 */
789 "getsockopt", /* 280 */
804 "proc_recv", /* 295 */
809 "ipcnamerase", /* 300 */
819 "ipcshutdown", /* 310 */
848 "sched_setscheduler",
849 "sched_getscheduler", /* 340 */
851 "sched_get_priority_max",
852 "sched_get_priority_min",
853 "sched_rr_get_interval",
854 "clock_settime", /* 345 */
859 "timer_settime", /* 350 */
869 "ftruncate64", /* 360 */
879 "truncate64", /* 370 */
889 "setcontext", /* 380 */
894 "sendmsg2", /* 385 */
899 "lwp_terminate", /* 390 */
904 "lwp_abort_syscall", /* 395 */
909 "ksleep_abort", /* 400 */
919 "lwp_mutex_lock_sys", /* 410 */
923 "lwp_cond_broadcast",
924 "lwp_cond_wait_sys", /* 415 */
929 "lwp_detach", /* 420 */
934 "shm_open", /* 425 */
944 "aio_return", /* 435 */
949 "mq_unlink", /* 440 */
954 "mq_getattr", /* 445 */
959 "lw_sem_incr", /* 450 */
964 static const int syscall_names_max = 453;
967 hpux_unimplemented(unsigned long arg1,unsigned long arg2,unsigned long arg3,
968 unsigned long arg4,unsigned long arg5,unsigned long arg6,
969 unsigned long arg7,unsigned long sc_num)
971 /* NOTE: sc_num trashes arg8 for the few syscalls that actually
972 * have a valid 8th argument.
974 const char *name = NULL;
975 if ( sc_num <= syscall_names_max && sc_num >= 0 ) {
976 name = syscall_names[sc_num];
980 printk(KERN_DEBUG "Unimplemented HP-UX syscall emulation. Syscall #%lu (%s)\n",
983 printk(KERN_DEBUG "Unimplemented unknown HP-UX syscall emulation. Syscall #%lu\n",
987 printk(KERN_DEBUG " Args: %lx %lx %lx %lx %lx %lx %lx\n",
988 arg1, arg2, arg3, arg4, arg5, arg6, arg7);