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/syscalls.h>
32 #include <linux/utsname.h>
33 #include <linux/vfs.h>
34 #include <linux/vmalloc.h>
36 #include <asm/errno.h>
37 #include <asm/pgalloc.h>
38 #include <asm/uaccess.h>
40 unsigned long hpux_brk(unsigned long addr
)
42 /* Sigh. Looks like HP/UX libc relies on kernel bugs. */
43 return sys_brk(addr
+ PAGE_SIZE
);
51 /* Random other syscalls */
53 int hpux_nice(int priority_change
)
63 int hpux_wait(int __user
*stat_loc
)
65 return sys_waitpid(-1, stat_loc
, 0);
68 int hpux_setpgrp(void)
70 return sys_setpgid(0,0);
73 int hpux_setpgrp3(void)
75 return hpux_setpgrp();
78 #define _SC_CPU_VERSION 10001
79 #define _SC_OPEN_MAX 4
80 #define CPU_PA_RISC1_1 0x210
82 int hpux_sysconf(int which
)
86 return CPU_PA_RISC1_1
;
94 /*****************************************************************************/
100 char sysname
[HPUX_UTSLEN
];
101 char nodename
[HPUX_UTSLEN
];
102 char release
[HPUX_UTSLEN
];
103 char version
[HPUX_UTSLEN
];
104 char machine
[HPUX_UTSLEN
];
105 char idnumber
[HPUX_SNLEN
];
109 int32_t f_tfree
; /* total free (daddr_t) */
110 u_int32_t f_tinode
; /* total inodes free (ino_t) */
111 char f_fname
[6]; /* filsys name */
112 char f_fpack
[6]; /* filsys pack name */
113 u_int32_t f_blksize
; /* filsys block size (int) */
117 * HPUX's utssys() call. It's a collection of miscellaneous functions,
118 * alas, so there's no nice way of splitting them up.
121 /* This function is called from hpux_utssys(); HP-UX implements
122 * ustat() as an option to utssys().
124 * Now, struct ustat on HP-UX is exactly the same as on Linux, except
125 * that it contains one addition field on the end, int32_t f_blksize.
126 * So, we could have written this function to just call the Linux
127 * sys_ustat(), (defined in linux/fs/super.c), and then just
128 * added this additional field to the user's structure. But I figure
129 * if we're gonna be digging through filesystem structures to get
130 * this, we might as well just do the whole enchilada all in one go.
132 * So, most of this function is almost identical to sys_ustat().
133 * I have placed comments at the few lines changed or added, to
134 * aid in porting forward if and when sys_ustat() is changed from
135 * its form in kernel 2.2.5.
137 static int hpux_ustat(dev_t dev
, struct hpux_ustat __user
*ubuf
)
139 struct hpux_ustat tmp
; /* Changed to hpux_ustat */
141 int err
= vfs_ustat(dev
, &sbuf
);
145 memset(&tmp
,0,sizeof(tmp
));
147 tmp
.f_tfree
= (int32_t)sbuf
.f_bfree
;
148 tmp
.f_tinode
= (u_int32_t
)sbuf
.f_ffree
;
149 tmp
.f_blksize
= (u_int32_t
)sbuf
.f_bsize
; /* Added this line */
151 err
= copy_to_user(ubuf
, &tmp
, sizeof(tmp
)) ? -EFAULT
: 0;
157 * Wrapper for hpux statfs call. At the moment, just calls the linux native one
158 * and ignores the extra fields at the end of the hpux statfs struct.
162 typedef int32_t hpux_fsid_t
[2]; /* file system ID type */
163 typedef uint16_t hpux_site_t
;
166 int32_t f_type
; /* type of info, zero for now */
167 int32_t f_bsize
; /* fundamental file system block size */
168 int32_t f_blocks
; /* total blocks in file system */
169 int32_t f_bfree
; /* free block in fs */
170 int32_t f_bavail
; /* free blocks avail to non-superuser */
171 int32_t f_files
; /* total file nodes in file system */
172 int32_t f_ffree
; /* free file nodes in fs */
173 hpux_fsid_t f_fsid
; /* file system ID */
174 int32_t f_magic
; /* file system magic number */
175 int32_t f_featurebits
; /* file system features */
176 int32_t f_spare
[4]; /* spare for later */
177 hpux_site_t f_cnode
; /* cluster node where mounted */
181 static int do_statfs_hpux(struct kstatfs
*st
, struct hpux_statfs __user
*p
)
183 struct hpux_statfs buf
;
184 memset(&buf
, 0, sizeof(buf
));
185 buf
.f_type
= st
->f_type
;
186 buf
.f_bsize
= st
->f_bsize
;
187 buf
.f_blocks
= st
->f_blocks
;
188 buf
.f_bfree
= st
->f_bfree
;
189 buf
.f_bavail
= st
->f_bavail
;
190 buf
.f_files
= st
->f_files
;
191 buf
.f_ffree
= st
->f_ffree
;
192 buf
.f_fsid
[0] = st
->f_fsid
.val
[0];
193 buf
.f_fsid
[1] = st
->f_fsid
.val
[1];
194 if (copy_to_user(p
, &buf
, sizeof(buf
)))
200 asmlinkage
long hpux_statfs(const char __user
*pathname
,
201 struct hpux_statfs __user
*buf
)
204 int error
= user_statfs(pathname
, &st
);
206 error
= do_statfs_hpux(&st
, buf
);
210 asmlinkage
long hpux_fstatfs(unsigned int fd
, struct hpux_statfs __user
* buf
)
213 int error
= fd_statfs(fd
, &st
);
215 error
= do_statfs_hpux(&st
, buf
);
220 /* This function is called from hpux_utssys(); HP-UX implements
221 * uname() as an option to utssys().
223 * The form of this function is pretty much copied from sys_olduname(),
224 * defined in linux/arch/i386/kernel/sys_i386.c.
226 /* TODO: Are these put_user calls OK? Should they pass an int?
227 * (I copied it from sys_i386.c like this.)
229 static int hpux_uname(struct hpux_utsname __user
*name
)
235 if (!access_ok(VERIFY_WRITE
,name
,sizeof(struct hpux_utsname
)))
240 error
= __copy_to_user(&name
->sysname
, &utsname()->sysname
,
242 error
|= __put_user(0, name
->sysname
+ HPUX_UTSLEN
- 1);
243 error
|= __copy_to_user(&name
->nodename
, &utsname()->nodename
,
245 error
|= __put_user(0, name
->nodename
+ HPUX_UTSLEN
- 1);
246 error
|= __copy_to_user(&name
->release
, &utsname()->release
,
248 error
|= __put_user(0, name
->release
+ HPUX_UTSLEN
- 1);
249 error
|= __copy_to_user(&name
->version
, &utsname()->version
,
251 error
|= __put_user(0, name
->version
+ HPUX_UTSLEN
- 1);
252 error
|= __copy_to_user(&name
->machine
, &utsname()->machine
,
254 error
|= __put_user(0, name
->machine
+ HPUX_UTSLEN
- 1);
258 /* HP-UX utsname has no domainname field. */
260 /* TODO: Implement idnumber!!! */
262 error
|= __put_user(0,name
->idnumber
);
263 error
|= __put_user(0,name
->idnumber
+HPUX_SNLEN
-1);
266 error
= error
? -EFAULT
: 0;
271 /* Note: HP-UX just uses the old suser() function to check perms
272 * in this system call. We'll use capable(CAP_SYS_ADMIN).
274 int hpux_utssys(char __user
*ubuf
, int n
, int type
)
281 return hpux_uname((struct hpux_utsname __user
*)ubuf
);
284 /* Obsolete (used to be umask().) */
289 return hpux_ustat(new_decode_dev(n
),
290 (struct hpux_ustat __user
*)ubuf
);
295 * On linux (unlike HP-UX), utsname.nodename
296 * is the same as the hostname.
298 * sys_sethostname() is defined in linux/kernel/sys.c.
300 if (!capable(CAP_SYS_ADMIN
))
302 /* Unlike Linux, HP-UX returns an error if n==0: */
305 /* Unlike Linux, HP-UX truncates it if n is too big: */
306 len
= (n
<= __NEW_UTS_LEN
) ? n
: __NEW_UTS_LEN
;
307 return sys_sethostname(ubuf
, len
);
312 * sys_sethostname() is defined in linux/kernel/sys.c.
314 if (!capable(CAP_SYS_ADMIN
))
316 /* Unlike Linux, HP-UX returns an error if n==0: */
319 /* Unlike Linux, HP-UX truncates it if n is too big: */
320 len
= (n
<= __NEW_UTS_LEN
) ? n
: __NEW_UTS_LEN
;
321 return sys_sethostname(ubuf
, len
);
326 * sys_gethostname() is defined in linux/kernel/sys.c.
328 /* Unlike Linux, HP-UX returns an error if n==0: */
331 return sys_gethostname(ubuf
, n
);
334 /* Supposedly called from setuname() in libc.
335 * TODO: When and why is this called?
336 * Is it ever even called?
338 * This code should look a lot like sys_sethostname(),
339 * defined in linux/kernel/sys.c. If that gets updated,
340 * update this code similarly.
342 if (!capable(CAP_SYS_ADMIN
))
344 /* Unlike Linux, HP-UX returns an error if n==0: */
347 /* Unlike Linux, HP-UX truncates it if n is too big: */
348 len
= (n
<= __NEW_UTS_LEN
) ? n
: __NEW_UTS_LEN
;
350 /* TODO: print a warning about using this? */
351 down_write(&uts_sem
);
353 if (!copy_from_user(utsname()->sysname
, ubuf
, len
)) {
354 utsname()->sysname
[len
] = 0;
361 /* Sets utsname.release, if you're allowed.
362 * Undocumented. Used by swinstall to change the
363 * OS version, during OS updates. Yuck!!!
365 * This code should look a lot like sys_sethostname()
366 * in linux/kernel/sys.c. If that gets updated, update
367 * this code similarly.
369 if (!capable(CAP_SYS_ADMIN
))
371 /* Unlike Linux, HP-UX returns an error if n==0: */
374 /* Unlike Linux, HP-UX truncates it if n is too big: */
375 len
= (n
<= __NEW_UTS_LEN
) ? n
: __NEW_UTS_LEN
;
377 /* TODO: print a warning about this? */
378 down_write(&uts_sem
);
380 if (!copy_from_user(utsname()->release
, ubuf
, len
)) {
381 utsname()->release
[len
] = 0;
388 /* This system call returns -EFAULT if given an unknown type.
389 * Why not -EINVAL? I don't know, it's just not what they did.
395 int hpux_getdomainname(char __user
*name
, int len
)
402 nlen
= strlen(utsname()->domainname
) + 1;
406 if(len
> __NEW_UTS_LEN
)
408 if(copy_to_user(name
, utsname()->domainname
, len
))
417 int hpux_pipe(int *kstack_fildes
)
419 return do_pipe_flags(kstack_fildes
, 0);
422 /* lies - says it works, but it really didn't lock anything */
423 int hpux_lockf(int fildes
, int function
, off_t size
)
428 int hpux_sysfs(int opcode
, unsigned long arg1
, unsigned long arg2
)
434 /*Unimplemented HP-UX syscall emulation. Syscall #334 (sysfs)
435 Args: 1 80057bf4 0 400179f0 0 0 0 */
436 printk(KERN_DEBUG
"in hpux_sysfs\n");
437 printk(KERN_DEBUG
"hpux_sysfs called with opcode = %d\n", opcode
);
438 printk(KERN_DEBUG
"hpux_sysfs called with arg1='%lx'\n", arg1
);
440 if ( opcode
== 1 ) { /* GETFSIND */
441 char __user
*user_fsname
= (char __user
*)arg1
;
442 len
= strlen_user(user_fsname
);
443 printk(KERN_DEBUG
"len of arg1 = %d\n", len
);
446 fsname
= kmalloc(len
, GFP_KERNEL
);
448 printk(KERN_DEBUG
"failed to kmalloc fsname\n");
452 if (copy_from_user(fsname
, user_fsname
, len
)) {
453 printk(KERN_DEBUG
"failed to copy_from_user fsname\n");
458 /* String could be altered by userspace after strlen_user() */
461 printk(KERN_DEBUG
"that is '%s' as (char *)\n", fsname
);
462 if ( !strcmp(fsname
, "hfs") ) {
470 printk(KERN_DEBUG
"returning fstype=%d\n", fstype
);
471 return fstype
; /* something other than default */
479 /* Table of syscall names and handle for unimplemented routines */
480 static const char * const syscall_names
[] = {
561 "setgroups", /* 80 */
581 "getpriority", /* 100 */
591 "sigsetmask", /* 110 */
611 "ftruncate", /* 130 */
626 "setrlimit", /* 145 */
656 "osetcontext", /* 175 */
661 "cnodeid/mysite", /* 180 */
666 "sigprocmask", /* 185 */
676 "getdirentries", /* 195 */
706 "sigsetstatemask", /* 225 */
711 "pathconf", /* 230 */
721 "getaudid", /* 240 */
726 "setevent", /* 245 */
761 "getsockopt", /* 280 */
776 "proc_recv", /* 295 */
781 "ipcnamerase", /* 300 */
791 "ipcshutdown", /* 310 */
820 "sched_setscheduler",
821 "sched_getscheduler", /* 340 */
823 "sched_get_priority_max",
824 "sched_get_priority_min",
825 "sched_rr_get_interval",
826 "clock_settime", /* 345 */
831 "timer_settime", /* 350 */
841 "ftruncate64", /* 360 */
851 "truncate64", /* 370 */
861 "setcontext", /* 380 */
866 "sendmsg2", /* 385 */
871 "lwp_terminate", /* 390 */
876 "lwp_abort_syscall", /* 395 */
881 "ksleep_abort", /* 400 */
891 "lwp_mutex_lock_sys", /* 410 */
895 "lwp_cond_broadcast",
896 "lwp_cond_wait_sys", /* 415 */
901 "lwp_detach", /* 420 */
906 "shm_open", /* 425 */
916 "aio_return", /* 435 */
921 "mq_unlink", /* 440 */
926 "mq_getattr", /* 445 */
931 "lw_sem_incr", /* 450 */
936 static const int syscall_names_max
= 453;
939 hpux_unimplemented(unsigned long arg1
,unsigned long arg2
,unsigned long arg3
,
940 unsigned long arg4
,unsigned long arg5
,unsigned long arg6
,
941 unsigned long arg7
,unsigned long sc_num
)
943 /* NOTE: sc_num trashes arg8 for the few syscalls that actually
944 * have a valid 8th argument.
946 const char *name
= NULL
;
947 if ( sc_num
<= syscall_names_max
&& sc_num
>= 0 ) {
948 name
= syscall_names
[sc_num
];
952 printk(KERN_DEBUG
"Unimplemented HP-UX syscall emulation. Syscall #%lu (%s)\n",
955 printk(KERN_DEBUG
"Unimplemented unknown HP-UX syscall emulation. Syscall #%lu\n",
959 printk(KERN_DEBUG
" Args: %lx %lx %lx %lx %lx %lx %lx\n",
960 arg1
, arg2
, arg3
, arg4
, arg5
, arg6
, arg7
);