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>
37 #include <asm/errno.h>
38 #include <asm/pgalloc.h>
39 #include <asm/uaccess.h>
41 unsigned long hpux_brk(unsigned long addr)
43 /* Sigh. Looks like HP/UX libc relies on kernel bugs. */
44 return sys_brk(addr + PAGE_SIZE);
52 /* Random other syscalls */
54 int hpux_nice(int priority_change)
64 int hpux_wait(int *stat_loc)
66 return sys_waitpid(-1, stat_loc, 0);
69 int hpux_setpgrp(void)
71 return sys_setpgid(0,0);
74 int hpux_setpgrp3(void)
76 return hpux_setpgrp();
79 #define _SC_CPU_VERSION 10001
80 #define _SC_OPEN_MAX 4
81 #define CPU_PA_RISC1_1 0x210
83 int hpux_sysconf(int which)
87 return CPU_PA_RISC1_1;
95 /*****************************************************************************/
100 struct hpux_utsname {
101 char sysname[HPUX_UTSLEN];
102 char nodename[HPUX_UTSLEN];
103 char release[HPUX_UTSLEN];
104 char version[HPUX_UTSLEN];
105 char machine[HPUX_UTSLEN];
106 char idnumber[HPUX_SNLEN];
110 int32_t f_tfree; /* total free (daddr_t) */
111 u_int32_t f_tinode; /* total inodes free (ino_t) */
112 char f_fname[6]; /* filsys name */
113 char f_fpack[6]; /* filsys pack name */
114 u_int32_t f_blksize; /* filsys block size (int) */
118 * HPUX's utssys() call. It's a collection of miscellaneous functions,
119 * alas, so there's no nice way of splitting them up.
122 /* This function is called from hpux_utssys(); HP-UX implements
123 * ustat() as an option to utssys().
125 * Now, struct ustat on HP-UX is exactly the same as on Linux, except
126 * that it contains one addition field on the end, int32_t f_blksize.
127 * So, we could have written this function to just call the Linux
128 * sys_ustat(), (defined in linux/fs/super.c), and then just
129 * added this additional field to the user's structure. But I figure
130 * if we're gonna be digging through filesystem structures to get
131 * this, we might as well just do the whole enchilada all in one go.
133 * So, most of this function is almost identical to sys_ustat().
134 * I have placed comments at the few lines changed or added, to
135 * aid in porting forward if and when sys_ustat() is changed from
136 * its form in kernel 2.2.5.
138 static int hpux_ustat(dev_t dev, struct hpux_ustat __user *ubuf)
140 struct super_block *s;
141 struct hpux_ustat tmp; /* Changed to hpux_ustat */
145 s = user_get_super(dev);
148 err = vfs_statfs(s, &sbuf);
153 memset(&tmp,0,sizeof(tmp));
155 tmp.f_tfree = (int32_t)sbuf.f_bfree;
156 tmp.f_tinode = (u_int32_t)sbuf.f_ffree;
157 tmp.f_blksize = (u_int32_t)sbuf.f_bsize; /* Added this line */
159 err = copy_to_user(ubuf, &tmp, sizeof(tmp)) ? -EFAULT : 0;
165 * Wrapper for hpux statfs call. At the moment, just calls the linux native one
166 * and ignores the extra fields at the end of the hpux statfs struct.
170 typedef int32_t hpux_fsid_t[2]; /* file system ID type */
171 typedef uint16_t hpux_site_t;
174 int32_t f_type; /* type of info, zero for now */
175 int32_t f_bsize; /* fundamental file system block size */
176 int32_t f_blocks; /* total blocks in file system */
177 int32_t f_bfree; /* free block in fs */
178 int32_t f_bavail; /* free blocks avail to non-superuser */
179 int32_t f_files; /* total file nodes in file system */
180 int32_t f_ffree; /* free file nodes in fs */
181 hpux_fsid_t f_fsid; /* file system ID */
182 int32_t f_magic; /* file system magic number */
183 int32_t f_featurebits; /* file system features */
184 int32_t f_spare[4]; /* spare for later */
185 hpux_site_t f_cnode; /* cluster node where mounted */
189 static int vfs_statfs_hpux(struct super_block *sb, struct hpux_statfs *buf)
194 retval = vfs_statfs(sb, &st);
198 memset(buf, 0, sizeof(*buf));
199 buf->f_type = st.f_type;
200 buf->f_bsize = st.f_bsize;
201 buf->f_blocks = st.f_blocks;
202 buf->f_bfree = st.f_bfree;
203 buf->f_bavail = st.f_bavail;
204 buf->f_files = st.f_files;
205 buf->f_ffree = st.f_ffree;
206 buf->f_fsid[0] = st.f_fsid.val[0];
207 buf->f_fsid[1] = st.f_fsid.val[1];
213 asmlinkage long hpux_statfs(const char __user *path,
214 struct hpux_statfs __user *buf)
219 error = user_path_walk(path, &nd);
221 struct hpux_statfs tmp;
222 error = vfs_statfs_hpux(nd.dentry->d_inode->i_sb, &tmp);
223 if (!error && copy_to_user(buf, &tmp, sizeof(tmp)))
230 asmlinkage long hpux_fstatfs(unsigned int fd, struct hpux_statfs __user * buf)
233 struct hpux_statfs tmp;
240 error = vfs_statfs_hpux(file->f_dentry->d_inode->i_sb, &tmp);
241 if (!error && copy_to_user(buf, &tmp, sizeof(tmp)))
249 /* This function is called from hpux_utssys(); HP-UX implements
250 * uname() as an option to utssys().
252 * The form of this function is pretty much copied from sys_olduname(),
253 * defined in linux/arch/i386/kernel/sys_i386.c.
255 /* TODO: Are these put_user calls OK? Should they pass an int?
256 * (I copied it from sys_i386.c like this.)
258 static int hpux_uname(struct hpux_utsname *name)
264 if (!access_ok(VERIFY_WRITE,name,sizeof(struct hpux_utsname)))
269 error = __copy_to_user(&name->sysname,&system_utsname.sysname,HPUX_UTSLEN-1);
270 error |= __put_user(0,name->sysname+HPUX_UTSLEN-1);
271 error |= __copy_to_user(&name->nodename,&system_utsname.nodename,HPUX_UTSLEN-1);
272 error |= __put_user(0,name->nodename+HPUX_UTSLEN-1);
273 error |= __copy_to_user(&name->release,&system_utsname.release,HPUX_UTSLEN-1);
274 error |= __put_user(0,name->release+HPUX_UTSLEN-1);
275 error |= __copy_to_user(&name->version,&system_utsname.version,HPUX_UTSLEN-1);
276 error |= __put_user(0,name->version+HPUX_UTSLEN-1);
277 error |= __copy_to_user(&name->machine,&system_utsname.machine,HPUX_UTSLEN-1);
278 error |= __put_user(0,name->machine+HPUX_UTSLEN-1);
282 /* HP-UX utsname has no domainname field. */
284 /* TODO: Implement idnumber!!! */
286 error |= __put_user(0,name->idnumber);
287 error |= __put_user(0,name->idnumber+HPUX_SNLEN-1);
290 error = error ? -EFAULT : 0;
295 /* Note: HP-UX just uses the old suser() function to check perms
296 * in this system call. We'll use capable(CAP_SYS_ADMIN).
298 int hpux_utssys(char *ubuf, int n, int type)
305 return( hpux_uname( (struct hpux_utsname *)ubuf ) );
308 /* Obsolete (used to be umask().) */
313 return( hpux_ustat(new_decode_dev(n), (struct hpux_ustat *)ubuf) );
318 * On linux (unlike HP-UX), utsname.nodename
319 * is the same as the hostname.
321 * sys_sethostname() is defined in linux/kernel/sys.c.
323 if (!capable(CAP_SYS_ADMIN))
325 /* Unlike Linux, HP-UX returns an error if n==0: */
328 /* Unlike Linux, HP-UX truncates it if n is too big: */
329 len = (n <= __NEW_UTS_LEN) ? n : __NEW_UTS_LEN ;
330 return( sys_sethostname(ubuf, len) );
335 * sys_sethostname() is defined in linux/kernel/sys.c.
337 if (!capable(CAP_SYS_ADMIN))
339 /* Unlike Linux, HP-UX returns an error if n==0: */
342 /* Unlike Linux, HP-UX truncates it if n is too big: */
343 len = (n <= __NEW_UTS_LEN) ? n : __NEW_UTS_LEN ;
344 return( sys_sethostname(ubuf, len) );
349 * sys_gethostname() is defined in linux/kernel/sys.c.
351 /* Unlike Linux, HP-UX returns an error if n==0: */
354 return( sys_gethostname(ubuf, n) );
357 /* Supposedly called from setuname() in libc.
358 * TODO: When and why is this called?
359 * Is it ever even called?
361 * This code should look a lot like sys_sethostname(),
362 * defined in linux/kernel/sys.c. If that gets updated,
363 * update this code similarly.
365 if (!capable(CAP_SYS_ADMIN))
367 /* Unlike Linux, HP-UX returns an error if n==0: */
370 /* Unlike Linux, HP-UX truncates it if n is too big: */
371 len = (n <= __NEW_UTS_LEN) ? n : __NEW_UTS_LEN ;
373 /* TODO: print a warning about using this? */
374 down_write(&uts_sem);
376 if (!copy_from_user(system_utsname.sysname, ubuf, len)) {
377 system_utsname.sysname[len] = 0;
384 /* Sets utsname.release, if you're allowed.
385 * Undocumented. Used by swinstall to change the
386 * OS version, during OS updates. Yuck!!!
388 * This code should look a lot like sys_sethostname()
389 * in linux/kernel/sys.c. If that gets updated, update
390 * this code similarly.
392 if (!capable(CAP_SYS_ADMIN))
394 /* Unlike Linux, HP-UX returns an error if n==0: */
397 /* Unlike Linux, HP-UX truncates it if n is too big: */
398 len = (n <= __NEW_UTS_LEN) ? n : __NEW_UTS_LEN ;
400 /* TODO: print a warning about this? */
401 down_write(&uts_sem);
403 if (!copy_from_user(system_utsname.release, ubuf, len)) {
404 system_utsname.release[len] = 0;
411 /* This system call returns -EFAULT if given an unknown type.
412 * Why not -EINVAL? I don't know, it's just not what they did.
418 int hpux_getdomainname(char *name, int len)
425 nlen = strlen(system_utsname.domainname) + 1;
429 if(len > __NEW_UTS_LEN)
431 if(copy_to_user(name, system_utsname.domainname, len))
440 int hpux_pipe(int *kstack_fildes)
445 error = do_pipe(kstack_fildes);
450 /* lies - says it works, but it really didn't lock anything */
451 int hpux_lockf(int fildes, int function, off_t size)
456 int hpux_sysfs(int opcode, unsigned long arg1, unsigned long arg2)
462 /*Unimplemented HP-UX syscall emulation. Syscall #334 (sysfs)
463 Args: 1 80057bf4 0 400179f0 0 0 0 */
464 printk(KERN_DEBUG "in hpux_sysfs\n");
465 printk(KERN_DEBUG "hpux_sysfs called with opcode = %d\n", opcode);
466 printk(KERN_DEBUG "hpux_sysfs called with arg1='%lx'\n", arg1);
468 if ( opcode == 1 ) { /* GETFSIND */
469 len = strlen_user((char *)arg1);
470 printk(KERN_DEBUG "len of arg1 = %d\n", len);
472 fsname = (char *) kmalloc(len+1, GFP_KERNEL);
474 printk(KERN_DEBUG "failed to kmalloc fsname\n");
478 if ( copy_from_user(fsname, (char *)arg1, len+1) ) {
479 printk(KERN_DEBUG "failed to copy_from_user fsname\n");
484 printk(KERN_DEBUG "that is '%s' as (char *)\n", fsname);
485 if ( !strcmp(fsname, "hfs") ) {
493 printk(KERN_DEBUG "returning fstype=%d\n", fstype);
494 return fstype; /* something other than default */
502 /* Table of syscall names and handle for unimplemented routines */
503 static const char *syscall_names[] = {
584 "setgroups", /* 80 */
604 "getpriority", /* 100 */
614 "sigsetmask", /* 110 */
634 "ftruncate", /* 130 */
649 "setrlimit", /* 145 */
679 "osetcontext", /* 175 */
684 "cnodeid/mysite", /* 180 */
689 "sigprocmask", /* 185 */
699 "getdirentries", /* 195 */
729 "sigsetstatemask", /* 225 */
734 "pathconf", /* 230 */
744 "getaudid", /* 240 */
749 "setevent", /* 245 */
784 "getsockopt", /* 280 */
799 "proc_recv", /* 295 */
804 "ipcnamerase", /* 300 */
814 "ipcshutdown", /* 310 */
843 "sched_setscheduler",
844 "sched_getscheduler", /* 340 */
846 "sched_get_priority_max",
847 "sched_get_priority_min",
848 "sched_rr_get_interval",
849 "clock_settime", /* 345 */
854 "timer_settime", /* 350 */
864 "ftruncate64", /* 360 */
874 "truncate64", /* 370 */
884 "setcontext", /* 380 */
889 "sendmsg2", /* 385 */
894 "lwp_terminate", /* 390 */
899 "lwp_abort_syscall", /* 395 */
904 "ksleep_abort", /* 400 */
914 "lwp_mutex_lock_sys", /* 410 */
918 "lwp_cond_broadcast",
919 "lwp_cond_wait_sys", /* 415 */
924 "lwp_detach", /* 420 */
929 "shm_open", /* 425 */
939 "aio_return", /* 435 */
944 "mq_unlink", /* 440 */
949 "mq_getattr", /* 445 */
954 "lw_sem_incr", /* 450 */
959 static const int syscall_names_max = 453;
962 hpux_unimplemented(unsigned long arg1,unsigned long arg2,unsigned long arg3,
963 unsigned long arg4,unsigned long arg5,unsigned long arg6,
964 unsigned long arg7,unsigned long sc_num)
966 /* NOTE: sc_num trashes arg8 for the few syscalls that actually
967 * have a valid 8th argument.
969 const char *name = NULL;
970 if ( sc_num <= syscall_names_max && sc_num >= 0 ) {
971 name = syscall_names[sc_num];
975 printk(KERN_DEBUG "Unimplemented HP-UX syscall emulation. Syscall #%lu (%s)\n",
978 printk(KERN_DEBUG "Unimplemented unknown HP-UX syscall emulation. Syscall #%lu\n",
982 printk(KERN_DEBUG " Args: %lx %lx %lx %lx %lx %lx %lx\n",
983 arg1, arg2, arg3, arg4, arg5, arg6, arg7);