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
26 #include <linux/sched.h>
27 #include <linux/slab.h>
28 #include <linux/smp_lock.h>
29 #include <linux/syscalls.h>
30 #include <linux/utsname.h>
31 #include <linux/vmalloc.h>
32 #include <linux/vfs.h>
34 #include <asm/errno.h>
35 #include <asm/pgalloc.h>
36 #include <asm/uaccess.h>
38 unsigned long hpux_brk(unsigned long addr)
40 /* Sigh. Looks like HP/UX libc relies on kernel bugs. */
41 return sys_brk(addr + PAGE_SIZE);
49 /* Random other syscalls */
51 int hpux_nice(int priority_change)
61 int hpux_wait(int *stat_loc)
63 return sys_waitpid(-1, stat_loc, 0);
66 int hpux_setpgrp(void)
68 extern int sys_setpgid(int, int);
69 return sys_setpgid(0,0);
72 int hpux_setpgrp3(void)
74 return hpux_setpgrp();
77 #define _SC_CPU_VERSION 10001
78 #define _SC_OPEN_MAX 4
79 #define CPU_PA_RISC1_1 0x210
81 int hpux_sysconf(int which)
85 return CPU_PA_RISC1_1;
93 /*****************************************************************************/
99 char sysname[HPUX_UTSLEN];
100 char nodename[HPUX_UTSLEN];
101 char release[HPUX_UTSLEN];
102 char version[HPUX_UTSLEN];
103 char machine[HPUX_UTSLEN];
104 char idnumber[HPUX_SNLEN];
108 int32_t f_tfree; /* total free (daddr_t) */
109 u_int32_t f_tinode; /* total inodes free (ino_t) */
110 char f_fname[6]; /* filsys name */
111 char f_fpack[6]; /* filsys pack name */
112 u_int32_t f_blksize; /* filsys block size (int) */
116 * HPUX's utssys() call. It's a collection of miscellaneous functions,
117 * alas, so there's no nice way of splitting them up.
120 /* This function is called from hpux_utssys(); HP-UX implements
121 * ustat() as an option to utssys().
123 * Now, struct ustat on HP-UX is exactly the same as on Linux, except
124 * that it contains one addition field on the end, int32_t f_blksize.
125 * So, we could have written this function to just call the Linux
126 * sys_ustat(), (defined in linux/fs/super.c), and then just
127 * added this additional field to the user's structure. But I figure
128 * if we're gonna be digging through filesystem structures to get
129 * this, we might as well just do the whole enchilada all in one go.
131 * So, most of this function is almost identical to sys_ustat().
132 * I have placed comments at the few lines changed or added, to
133 * aid in porting forward if and when sys_ustat() is changed from
134 * its form in kernel 2.2.5.
136 static int hpux_ustat(dev_t dev, struct hpux_ustat *ubuf)
138 struct super_block *s;
139 struct hpux_ustat tmp; /* Changed to hpux_ustat */
143 s = user_get_super(dev);
146 err = vfs_statfs(s, &sbuf);
151 memset(&tmp,0,sizeof(struct hpux_ustat)); /* Changed to hpux_ustat */
153 tmp.f_tfree = (int32_t)sbuf.f_bfree;
154 tmp.f_tinode = (u_int32_t)sbuf.f_ffree;
155 tmp.f_blksize = (u_int32_t)sbuf.f_bsize; /* Added this line */
157 /* Changed to hpux_ustat: */
158 err = copy_to_user(ubuf,&tmp,sizeof(struct hpux_ustat)) ? -EFAULT : 0;
164 * Wrapper for hpux statfs call. At the moment, just calls the linux native one
165 * and ignores the extra fields at the end of the hpux statfs struct.
169 typedef int32_t hpux_fsid_t[2]; /* file system ID type */
170 typedef uint16_t hpux_site_t;
173 int32_t f_type; /* type of info, zero for now */
174 int32_t f_bsize; /* fundamental file system block size */
175 int32_t f_blocks; /* total blocks in file system */
176 int32_t f_bfree; /* free block in fs */
177 int32_t f_bavail; /* free blocks avail to non-superuser */
178 int32_t f_files; /* total file nodes in file system */
179 int32_t f_ffree; /* free file nodes in fs */
180 hpux_fsid_t f_fsid; /* file system ID */
181 int32_t f_magic; /* file system magic number */
182 int32_t f_featurebits; /* file system features */
183 int32_t f_spare[4]; /* spare for later */
184 hpux_site_t f_cnode; /* cluster node where mounted */
189 int hpux_statfs(const char *path, struct hpux_statfs *buf)
195 len = strlen_user((char *)path);
197 kpath = (char *) kmalloc(len+1, GFP_KERNEL);
199 printk(KERN_DEBUG "failed to kmalloc kpath\n");
203 if ( copy_from_user(kpath, (char *)path, len+1) ) {
204 printk(KERN_DEBUG "failed to copy_from_user kpath\n");
209 printk(KERN_DEBUG "hpux_statfs(\"%s\",-)\n", kpath);
213 /* just fake it, beginning of structures match */
214 error = sys_statfs(path, (struct statfs *) buf);
216 /* ignoring rest of statfs struct, but it should be zeros. Need to do
217 something with f_fsid[1], which is the fstype for sysfs */
223 /* This function is called from hpux_utssys(); HP-UX implements
224 * uname() as an option to utssys().
226 * The form of this function is pretty much copied from sys_olduname(),
227 * defined in linux/arch/i386/kernel/sys_i386.c.
229 /* TODO: Are these put_user calls OK? Should they pass an int?
230 * (I copied it from sys_i386.c like this.)
232 static int hpux_uname(struct hpux_utsname *name)
238 if (!access_ok(VERIFY_WRITE,name,sizeof(struct hpux_utsname)))
243 error = __copy_to_user(&name->sysname,&system_utsname.sysname,HPUX_UTSLEN-1);
244 error |= __put_user(0,name->sysname+HPUX_UTSLEN-1);
245 error |= __copy_to_user(&name->nodename,&system_utsname.nodename,HPUX_UTSLEN-1);
246 error |= __put_user(0,name->nodename+HPUX_UTSLEN-1);
247 error |= __copy_to_user(&name->release,&system_utsname.release,HPUX_UTSLEN-1);
248 error |= __put_user(0,name->release+HPUX_UTSLEN-1);
249 error |= __copy_to_user(&name->version,&system_utsname.version,HPUX_UTSLEN-1);
250 error |= __put_user(0,name->version+HPUX_UTSLEN-1);
251 error |= __copy_to_user(&name->machine,&system_utsname.machine,HPUX_UTSLEN-1);
252 error |= __put_user(0,name->machine+HPUX_UTSLEN-1);
256 /* HP-UX utsname has no domainname field. */
258 /* TODO: Implement idnumber!!! */
260 error |= __put_user(0,name->idnumber);
261 error |= __put_user(0,name->idnumber+HPUX_SNLEN-1);
264 error = error ? -EFAULT : 0;
269 /* Note: HP-UX just uses the old suser() function to check perms
270 * in this system call. We'll use capable(CAP_SYS_ADMIN).
272 int hpux_utssys(char *ubuf, int n, int type)
279 return( hpux_uname( (struct hpux_utsname *)ubuf ) );
282 /* Obsolete (used to be umask().) */
287 return( hpux_ustat(new_decode_dev(n), (struct hpux_ustat *)ubuf) );
292 * On linux (unlike HP-UX), utsname.nodename
293 * is the same as the hostname.
295 * sys_sethostname() is defined in linux/kernel/sys.c.
297 if (!capable(CAP_SYS_ADMIN))
299 /* Unlike Linux, HP-UX returns an error if n==0: */
302 /* Unlike Linux, HP-UX truncates it if n is too big: */
303 len = (n <= __NEW_UTS_LEN) ? n : __NEW_UTS_LEN ;
304 return( sys_sethostname(ubuf, len) );
309 * sys_sethostname() is defined in linux/kernel/sys.c.
311 if (!capable(CAP_SYS_ADMIN))
313 /* Unlike Linux, HP-UX returns an error if n==0: */
316 /* Unlike Linux, HP-UX truncates it if n is too big: */
317 len = (n <= __NEW_UTS_LEN) ? n : __NEW_UTS_LEN ;
318 return( sys_sethostname(ubuf, len) );
323 * sys_gethostname() is defined in linux/kernel/sys.c.
325 /* Unlike Linux, HP-UX returns an error if n==0: */
328 return( sys_gethostname(ubuf, n) );
331 /* Supposedly called from setuname() in libc.
332 * TODO: When and why is this called?
333 * Is it ever even called?
335 * This code should look a lot like sys_sethostname(),
336 * defined in linux/kernel/sys.c. If that gets updated,
337 * update this code similarly.
339 if (!capable(CAP_SYS_ADMIN))
341 /* Unlike Linux, HP-UX returns an error if n==0: */
344 /* Unlike Linux, HP-UX truncates it if n is too big: */
345 len = (n <= __NEW_UTS_LEN) ? n : __NEW_UTS_LEN ;
347 /* TODO: print a warning about using this? */
348 down_write(&uts_sem);
350 if (!copy_from_user(system_utsname.sysname, ubuf, len)) {
351 system_utsname.sysname[len] = 0;
358 /* Sets utsname.release, if you're allowed.
359 * Undocumented. Used by swinstall to change the
360 * OS version, during OS updates. Yuck!!!
362 * This code should look a lot like sys_sethostname()
363 * in linux/kernel/sys.c. If that gets updated, update
364 * 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 this? */
375 down_write(&uts_sem);
377 if (!copy_from_user(system_utsname.release, ubuf, len)) {
378 system_utsname.release[len] = 0;
385 /* This system call returns -EFAULT if given an unknown type.
386 * Why not -EINVAL? I don't know, it's just not what they did.
392 int hpux_getdomainname(char *name, int len)
399 nlen = strlen(system_utsname.domainname) + 1;
403 if(len > __NEW_UTS_LEN)
405 if(copy_to_user(name, system_utsname.domainname, len))
414 int hpux_pipe(int *kstack_fildes)
419 error = do_pipe(kstack_fildes);
424 /* lies - says it works, but it really didn't lock anything */
425 int hpux_lockf(int fildes, int function, off_t size)
430 int hpux_sysfs(int opcode, unsigned long arg1, unsigned long arg2)
436 /*Unimplemented HP-UX syscall emulation. Syscall #334 (sysfs)
437 Args: 1 80057bf4 0 400179f0 0 0 0 */
438 printk(KERN_DEBUG "in hpux_sysfs\n");
439 printk(KERN_DEBUG "hpux_sysfs called with opcode = %d\n", opcode);
440 printk(KERN_DEBUG "hpux_sysfs called with arg1='%lx'\n", arg1);
442 if ( opcode == 1 ) { /* GETFSIND */
443 len = strlen_user((char *)arg1);
444 printk(KERN_DEBUG "len of arg1 = %d\n", len);
446 fsname = (char *) kmalloc(len+1, GFP_KERNEL);
448 printk(KERN_DEBUG "failed to kmalloc fsname\n");
452 if ( copy_from_user(fsname, (char *)arg1, len+1) ) {
453 printk(KERN_DEBUG "failed to copy_from_user fsname\n");
458 printk(KERN_DEBUG "that is '%s' as (char *)\n", fsname);
459 if ( !strcmp(fsname, "hfs") ) {
467 printk(KERN_DEBUG "returning fstype=%d\n", fstype);
468 return fstype; /* something other than default */
476 /* Table of syscall names and handle for unimplemented routines */
477 static const char *syscall_names[] = {
558 "setgroups", /* 80 */
578 "getpriority", /* 100 */
588 "sigsetmask", /* 110 */
608 "ftruncate", /* 130 */
623 "setrlimit", /* 145 */
653 "osetcontext", /* 175 */
658 "cnodeid/mysite", /* 180 */
663 "sigprocmask", /* 185 */
673 "getdirentries", /* 195 */
703 "sigsetstatemask", /* 225 */
708 "pathconf", /* 230 */
718 "getaudid", /* 240 */
723 "setevent", /* 245 */
758 "getsockopt", /* 280 */
773 "proc_recv", /* 295 */
778 "ipcnamerase", /* 300 */
788 "ipcshutdown", /* 310 */
817 "sched_setscheduler",
818 "sched_getscheduler", /* 340 */
820 "sched_get_priority_max",
821 "sched_get_priority_min",
822 "sched_rr_get_interval",
823 "clock_settime", /* 345 */
828 "timer_settime", /* 350 */
838 "ftruncate64", /* 360 */
848 "truncate64", /* 370 */
858 "setcontext", /* 380 */
863 "sendmsg2", /* 385 */
868 "lwp_terminate", /* 390 */
873 "lwp_abort_syscall", /* 395 */
878 "ksleep_abort", /* 400 */
888 "lwp_mutex_lock_sys", /* 410 */
892 "lwp_cond_broadcast",
893 "lwp_cond_wait_sys", /* 415 */
898 "lwp_detach", /* 420 */
903 "shm_open", /* 425 */
913 "aio_return", /* 435 */
918 "mq_unlink", /* 440 */
923 "mq_getattr", /* 445 */
928 "lw_sem_incr", /* 450 */
933 static const int syscall_names_max = 453;
936 hpux_unimplemented(unsigned long arg1,unsigned long arg2,unsigned long arg3,
937 unsigned long arg4,unsigned long arg5,unsigned long arg6,
938 unsigned long arg7,unsigned long sc_num)
940 /* NOTE: sc_num trashes arg8 for the few syscalls that actually
941 * have a valid 8th argument.
943 const char *name = NULL;
944 if ( sc_num <= syscall_names_max && sc_num >= 0 ) {
945 name = syscall_names[sc_num];
949 printk(KERN_DEBUG "Unimplemented HP-UX syscall emulation. Syscall #%lu (%s)\n",
952 printk(KERN_DEBUG "Unimplemented unknown HP-UX syscall emulation. Syscall #%lu\n",
956 printk(KERN_DEBUG " Args: %lx %lx %lx %lx %lx %lx %lx\n",
957 arg1, arg2, arg3, arg4, arg5, arg6, arg7);