Merge with Linux 2.4.0-test3-pre2.
[linux-2.6/linux-mips.git] / arch / sparc64 / kernel / sys_sunos32.c
blob70adfe21a229216be4fdeaa17da28011b1e7696d
1 /* $Id: sys_sunos32.c,v 1.49 2000/06/22 11:42:25 davem Exp $
2 * sys_sunos32.c: SunOS binary compatability layer on sparc64.
4 * Copyright (C) 1995, 1996, 1997 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx)
7 * Based upon preliminary work which is:
9 * Copyright (C) 1995 Adrian M. Rodriguez (adrian@remus.rutgers.edu)
12 #include <linux/kernel.h>
13 #include <linux/sched.h>
14 #include <linux/types.h>
15 #include <linux/mman.h>
16 #include <linux/mm.h>
17 #include <linux/swap.h>
18 #include <linux/fs.h>
19 #include <linux/file.h>
20 #include <linux/resource.h>
21 #include <linux/ipc.h>
22 #include <linux/shm.h>
23 #include <linux/msg.h>
24 #include <linux/sem.h>
25 #include <linux/signal.h>
26 #include <linux/uio.h>
27 #include <linux/utsname.h>
28 #include <linux/major.h>
29 #include <linux/stat.h>
30 #include <linux/malloc.h>
31 #include <linux/pagemap.h>
32 #include <linux/errno.h>
33 #include <linux/smp.h>
34 #include <linux/smp_lock.h>
36 #include <asm/uaccess.h>
37 #include <asm/page.h>
38 #include <asm/pgtable.h>
39 #include <asm/pconf.h>
40 #include <asm/idprom.h> /* for gethostid() */
41 #include <asm/unistd.h>
42 #include <asm/system.h>
44 /* For the nfs mount emulation */
45 #include <linux/socket.h>
46 #include <linux/in.h>
47 #include <linux/nfs.h>
48 #include <linux/nfs2.h>
49 #include <linux/nfs_mount.h>
51 /* for sunos_select */
52 #include <linux/time.h>
53 #include <linux/personality.h>
55 /* Use this to get at 32-bit user passed pointers. */
56 #define A(__x) \
57 ({ unsigned long __ret; \
58 __asm__ ("srl %0, 0, %0" \
59 : "=r" (__ret) \
60 : "0" (__x)); \
61 __ret; \
64 #define SUNOS_NR_OPEN 256
66 asmlinkage u32 sunos_mmap(u32 addr, u32 len, u32 prot, u32 flags, u32 fd, u32 off)
68 struct file *file = NULL;
69 unsigned long retval, ret_type;
71 lock_kernel();
72 if(flags & MAP_NORESERVE) {
73 static int cnt;
74 if (cnt++ < 10)
75 printk("%s: unimplemented SunOS MAP_NORESERVE mmap() flag\n",
76 current->comm);
77 flags &= ~MAP_NORESERVE;
79 retval = -EBADF;
80 if(!(flags & MAP_ANONYMOUS)) {
81 struct inode * inode;
82 if(fd >= SUNOS_NR_OPEN)
83 goto out;
84 file = fget(fd);
85 if (!file)
86 goto out;
87 inode = file->f_dentry->d_inode;
88 if(MAJOR(inode->i_rdev)==MEM_MAJOR && MINOR(inode->i_rdev)==5) {
89 flags |= MAP_ANONYMOUS;
90 fput(file);
91 file = NULL;
95 retval = -EINVAL;
96 if(!(flags & MAP_FIXED))
97 addr = 0;
98 else if (len > 0xf0000000 || addr > 0xf0000000 - len)
99 goto out_putf;
100 ret_type = flags & _MAP_NEW;
101 flags &= ~_MAP_NEW;
103 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
104 down(&current->mm->mmap_sem);
105 retval = do_mmap(file,
106 (unsigned long) addr, (unsigned long) len,
107 (unsigned long) prot, (unsigned long) flags,
108 (unsigned long) off);
109 up(&current->mm->mmap_sem);
110 if(!ret_type)
111 retval = ((retval < 0xf0000000) ? 0 : retval);
112 out_putf:
113 if (file)
114 fput(file);
115 out:
116 unlock_kernel();
117 return (u32) retval;
120 asmlinkage int sunos_mctl(u32 addr, u32 len, int function, u32 arg)
122 return 0;
125 asmlinkage int sunos_brk(u32 baddr)
127 int freepages, retval = -ENOMEM;
128 unsigned long rlim;
129 unsigned long newbrk, oldbrk, brk = (unsigned long) baddr;
131 down(&current->mm->mmap_sem);
132 if (brk < current->mm->end_code)
133 goto out;
134 newbrk = PAGE_ALIGN(brk);
135 oldbrk = PAGE_ALIGN(current->mm->brk);
136 retval = 0;
137 if (oldbrk == newbrk) {
138 current->mm->brk = brk;
139 goto out;
141 /* Always allow shrinking brk. */
142 if (brk <= current->mm->brk) {
143 current->mm->brk = brk;
144 do_munmap(current->mm, newbrk, oldbrk-newbrk);
145 goto out;
147 /* Check against rlimit and stack.. */
148 retval = -ENOMEM;
149 rlim = current->rlim[RLIMIT_DATA].rlim_cur;
150 if (rlim >= RLIM_INFINITY)
151 rlim = ~0;
152 if (brk - current->mm->end_code > rlim)
153 goto out;
154 /* Check against existing mmap mappings. */
155 if (find_vma_intersection(current->mm, oldbrk, newbrk+PAGE_SIZE))
156 goto out;
157 /* stupid algorithm to decide if we have enough memory: while
158 * simple, it hopefully works in most obvious cases.. Easy to
159 * fool it, but this should catch most mistakes.
161 freepages = atomic_read(&buffermem_pages) >> PAGE_SHIFT;
162 freepages += atomic_read(&page_cache_size);
163 freepages >>= 1;
164 freepages += nr_free_pages();
165 freepages += nr_swap_pages;
166 freepages -= num_physpages >> 4;
167 freepages -= (newbrk-oldbrk) >> PAGE_SHIFT;
168 if (freepages < 0)
169 goto out;
170 /* Ok, we have probably got enough memory - let it rip. */
171 current->mm->brk = brk;
172 do_brk(oldbrk, newbrk-oldbrk);
173 retval = 0;
174 out:
175 up(&current->mm->mmap_sem);
176 return retval;
179 asmlinkage u32 sunos_sbrk(int increment)
181 int error, oldbrk;
183 /* This should do it hopefully... */
184 lock_kernel();
185 oldbrk = (int)current->mm->brk;
186 error = sunos_brk(((int) current->mm->brk) + increment);
187 if(!error)
188 error = oldbrk;
189 unlock_kernel();
190 return error;
193 asmlinkage u32 sunos_sstk(int increment)
195 lock_kernel();
196 printk("%s: Call to sunos_sstk(increment<%d>) is unsupported\n",
197 current->comm, increment);
198 unlock_kernel();
199 return (u32)-1;
202 /* Give hints to the kernel as to what paging strategy to use...
203 * Completely bogus, don't remind me.
205 #define VA_NORMAL 0 /* Normal vm usage expected */
206 #define VA_ABNORMAL 1 /* Abnormal/random vm usage probable */
207 #define VA_SEQUENTIAL 2 /* Accesses will be of a sequential nature */
208 #define VA_INVALIDATE 3 /* Page table entries should be flushed ??? */
209 static char *vstrings[] = {
210 "VA_NORMAL",
211 "VA_ABNORMAL",
212 "VA_SEQUENTIAL",
213 "VA_INVALIDATE",
216 asmlinkage void sunos_vadvise(u32 strategy)
218 /* I wanna see who uses this... */
219 lock_kernel();
220 printk("%s: Advises us to use %s paging strategy\n",
221 current->comm,
222 strategy <= 3 ? vstrings[strategy] : "BOGUS");
223 unlock_kernel();
226 /* This just wants the soft limit (ie. rlim_cur element) of the RLIMIT_NOFILE
227 * resource limit and is for backwards compatibility with older sunos
228 * revs.
230 asmlinkage int sunos_getdtablesize(void)
232 return SUNOS_NR_OPEN;
236 #define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
238 asmlinkage u32 sunos_sigblock(u32 blk_mask)
240 u32 old;
242 spin_lock_irq(&current->sigmask_lock);
243 old = (u32) current->blocked.sig[0];
244 current->blocked.sig[0] |= (blk_mask & _BLOCKABLE);
245 recalc_sigpending(current);
246 spin_unlock_irq(&current->sigmask_lock);
247 return old;
250 asmlinkage u32 sunos_sigsetmask(u32 newmask)
252 u32 retval;
254 spin_lock_irq(&current->sigmask_lock);
255 retval = (u32) current->blocked.sig[0];
256 current->blocked.sig[0] = (newmask & _BLOCKABLE);
257 recalc_sigpending(current);
258 spin_unlock_irq(&current->sigmask_lock);
259 return retval;
262 /* SunOS getdents is very similar to the newer Linux (iBCS2 compliant) */
263 /* getdents system call, the format of the structure just has a different */
264 /* layout (d_off+d_ino instead of d_ino+d_off) */
265 struct sunos_dirent {
266 s32 d_off;
267 u32 d_ino;
268 u16 d_reclen;
269 u16 d_namlen;
270 char d_name[1];
273 struct sunos_dirent_callback {
274 struct sunos_dirent *curr;
275 struct sunos_dirent *previous;
276 int count;
277 int error;
280 #define NAME_OFFSET(de) ((int) ((de)->d_name - (char *) (de)))
281 #define ROUND_UP(x) (((x)+sizeof(s32)-1) & ~(sizeof(s32)-1))
283 static int sunos_filldir(void * __buf, const char * name, int namlen,
284 off_t offset, ino_t ino)
286 struct sunos_dirent * dirent;
287 struct sunos_dirent_callback * buf = (struct sunos_dirent_callback *) __buf;
288 int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 1);
290 buf->error = -EINVAL; /* only used if we fail.. */
291 if (reclen > buf->count)
292 return -EINVAL;
293 dirent = buf->previous;
294 if (dirent)
295 put_user(offset, &dirent->d_off);
296 dirent = buf->curr;
297 buf->previous = dirent;
298 put_user(ino, &dirent->d_ino);
299 put_user(namlen, &dirent->d_namlen);
300 put_user(reclen, &dirent->d_reclen);
301 copy_to_user(dirent->d_name, name, namlen);
302 put_user(0, dirent->d_name + namlen);
303 ((char *) dirent) += reclen;
304 buf->curr = dirent;
305 buf->count -= reclen;
306 return 0;
309 asmlinkage int sunos_getdents(unsigned int fd, u32 u_dirent, int cnt)
311 struct file * file;
312 struct sunos_dirent * lastdirent;
313 struct sunos_dirent_callback buf;
314 int error = -EBADF;
315 void *dirent = (void *)A(u_dirent);
317 if(fd >= SUNOS_NR_OPEN)
318 goto out;
320 file = fget(fd);
321 if(!file)
322 goto out;
324 lock_kernel();
326 error = -EINVAL;
327 if(cnt < (sizeof(struct sunos_dirent) + 255))
328 goto out_putf;
330 buf.curr = (struct sunos_dirent *) dirent;
331 buf.previous = NULL;
332 buf.count = cnt;
333 buf.error = 0;
335 error = vfs_readdir(file, sunos_filldir, &buf);
336 if (error < 0)
337 goto out_putf;
339 lastdirent = buf.previous;
340 error = buf.error;
341 if (lastdirent) {
342 put_user(file->f_pos, &lastdirent->d_off);
343 error = cnt - buf.count;
346 out_putf:
347 unlock_kernel();
348 fput(file);
349 out:
350 return error;
353 /* Old sunos getdirentries, severely broken compatibility stuff here. */
354 struct sunos_direntry {
355 u32 d_ino;
356 u16 d_reclen;
357 u16 d_namlen;
358 char d_name[1];
361 struct sunos_direntry_callback {
362 struct sunos_direntry *curr;
363 struct sunos_direntry *previous;
364 int count;
365 int error;
368 static int sunos_filldirentry(void * __buf, const char * name, int namlen,
369 off_t offset, ino_t ino)
371 struct sunos_direntry * dirent;
372 struct sunos_direntry_callback * buf = (struct sunos_direntry_callback *) __buf;
373 int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 1);
375 buf->error = -EINVAL; /* only used if we fail.. */
376 if (reclen > buf->count)
377 return -EINVAL;
378 dirent = buf->previous;
379 dirent = buf->curr;
380 buf->previous = dirent;
381 put_user(ino, &dirent->d_ino);
382 put_user(namlen, &dirent->d_namlen);
383 put_user(reclen, &dirent->d_reclen);
384 copy_to_user(dirent->d_name, name, namlen);
385 put_user(0, dirent->d_name + namlen);
386 ((char *) dirent) += reclen;
387 buf->curr = dirent;
388 buf->count -= reclen;
389 return 0;
392 asmlinkage int sunos_getdirentries(unsigned int fd, u32 u_dirent,
393 int cnt, u32 u_basep)
395 void *dirent = (void *) A(u_dirent);
396 unsigned int *basep = (unsigned int *)A(u_basep);
397 struct file * file;
398 struct sunos_direntry * lastdirent;
399 int error = -EBADF;
400 struct sunos_direntry_callback buf;
402 if(fd >= SUNOS_NR_OPEN)
403 goto out;
405 file = fget(fd);
406 if(!file)
407 goto out;
409 lock_kernel();
411 error = -EINVAL;
412 if(cnt < (sizeof(struct sunos_direntry) + 255))
413 goto out_putf;
415 buf.curr = (struct sunos_direntry *) dirent;
416 buf.previous = NULL;
417 buf.count = cnt;
418 buf.error = 0;
420 error = vfs_readdir(file, sunos_filldirentry, &buf);
421 if (error < 0)
422 goto out_putf;
424 lastdirent = buf.previous;
425 error = buf.error;
426 if (lastdirent) {
427 put_user(file->f_pos, basep);
428 error = cnt - buf.count;
431 out_putf:
432 unlock_kernel();
433 fput(file);
434 out:
435 return error;
438 struct sunos_utsname {
439 char sname[9];
440 char nname[9];
441 char nnext[56];
442 char rel[9];
443 char ver[9];
444 char mach[9];
447 asmlinkage int sunos_uname(struct sunos_utsname *name)
449 int ret;
451 down_read(&uts_sem);
452 ret = copy_to_user(&name->sname[0], &system_utsname.sysname[0], sizeof(name->sname) - 1);
453 ret |= copy_to_user(&name->nname[0], &system_utsname.nodename[0], sizeof(name->nname) - 1);
454 ret |= put_user('\0', &name->nname[8]);
455 ret |= copy_to_user(&name->rel[0], &system_utsname.release[0], sizeof(name->rel) - 1);
456 ret |= copy_to_user(&name->ver[0], &system_utsname.version[0], sizeof(name->ver) - 1);
457 ret |= copy_to_user(&name->mach[0], &system_utsname.machine[0], sizeof(name->mach) - 1);
458 up_read(&uts_sem);
459 return ret;
462 asmlinkage int sunos_nosys(void)
464 struct pt_regs *regs;
465 siginfo_t info;
466 static int cnt;
468 lock_kernel();
469 regs = current->thread.kregs;
470 info.si_signo = SIGSYS;
471 info.si_errno = 0;
472 info.si_code = __SI_FAULT|0x100;
473 info.si_addr = (void *)regs->tpc;
474 info.si_trapno = regs->u_regs[UREG_G1];
475 send_sig_info(SIGSYS, &info, current);
476 if (cnt++ < 4) {
477 printk("Process makes ni_syscall number %d, register dump:\n",
478 (int) regs->u_regs[UREG_G1]);
479 show_regs(regs);
481 unlock_kernel();
482 return -ENOSYS;
485 /* This is not a real and complete implementation yet, just to keep
486 * the easy SunOS binaries happy.
488 asmlinkage int sunos_fpathconf(int fd, int name)
490 int ret;
492 lock_kernel();
493 switch(name) {
494 case _PCONF_LINK:
495 ret = LINK_MAX;
496 break;
497 case _PCONF_CANON:
498 ret = MAX_CANON;
499 break;
500 case _PCONF_INPUT:
501 ret = MAX_INPUT;
502 break;
503 case _PCONF_NAME:
504 ret = NAME_MAX;
505 break;
506 case _PCONF_PATH:
507 ret = PATH_MAX;
508 break;
509 case _PCONF_PIPE:
510 ret = PIPE_BUF;
511 break;
512 case _PCONF_CHRESTRICT: /* XXX Investigate XXX */
513 ret = 1;
514 break;
515 case _PCONF_NOTRUNC: /* XXX Investigate XXX */
516 case _PCONF_VDISABLE:
517 ret = 0;
518 break;
519 default:
520 ret = -EINVAL;
521 break;
523 unlock_kernel();
524 return ret;
527 asmlinkage int sunos_pathconf(u32 u_path, int name)
529 int ret;
531 lock_kernel();
532 ret = sunos_fpathconf(0, name); /* XXX cheese XXX */
533 unlock_kernel();
534 return ret;
537 /* SunOS mount system call emulation */
538 extern asmlinkage int
539 sys32_select(int n, u32 inp, u32 outp, u32 exp, u32 tvp);
541 struct timeval32
543 int tv_sec, tv_usec;
546 asmlinkage int sunos_select(int width, u32 inp, u32 outp, u32 exp, u32 tvp_x)
548 int ret;
550 /* SunOS binaries expect that select won't change the tvp contents */
551 lock_kernel();
552 ret = sys32_select (width, inp, outp, exp, tvp_x);
553 if (ret == -EINTR && tvp_x) {
554 struct timeval32 *tvp = (struct timeval32 *)A(tvp_x);
555 time_t sec, usec;
557 __get_user(sec, &tvp->tv_sec);
558 __get_user(usec, &tvp->tv_usec);
559 if (sec == 0 && usec == 0)
560 ret = 0;
562 unlock_kernel();
563 return ret;
566 asmlinkage void sunos_nop(void)
568 return;
571 /* XXXXXXXXXX SunOS mount/umount. XXXXXXXXXXX */
572 #define SMNT_RDONLY 1
573 #define SMNT_NOSUID 2
574 #define SMNT_NEWTYPE 4
575 #define SMNT_GRPID 8
576 #define SMNT_REMOUNT 16
577 #define SMNT_NOSUB 32
578 #define SMNT_MULTI 64
579 #define SMNT_SYS5 128
581 struct sunos_fh_t {
582 char fh_data [NFS_FHSIZE];
585 struct sunos_nfs_mount_args {
586 struct sockaddr_in *addr; /* file server address */
587 struct nfs_fh *fh; /* File handle to be mounted */
588 int flags; /* flags */
589 int wsize; /* write size in bytes */
590 int rsize; /* read size in bytes */
591 int timeo; /* initial timeout in .1 secs */
592 int retrans; /* times to retry send */
593 char *hostname; /* server's hostname */
594 int acregmin; /* attr cache file min secs */
595 int acregmax; /* attr cache file max secs */
596 int acdirmin; /* attr cache dir min secs */
597 int acdirmax; /* attr cache dir max secs */
598 char *netname; /* server's netname */
601 extern dev_t get_unnamed_dev(void);
602 extern void put_unnamed_dev(dev_t);
603 extern asmlinkage int sys_mount(char *, char *, char *, unsigned long, void *);
604 extern asmlinkage int sys_connect(int fd, struct sockaddr *uservaddr, int addrlen);
605 extern asmlinkage int sys_socket(int family, int type, int protocol);
606 extern asmlinkage int sys_bind(int fd, struct sockaddr *umyaddr, int addrlen);
609 /* Bind the socket on a local reserved port and connect it to the
610 * remote server. This on Linux/i386 is done by the mount program,
611 * not by the kernel.
613 /* XXXXXXXXXXXXXXXXXXXX */
614 static int
615 sunos_nfs_get_server_fd (int fd, struct sockaddr_in *addr)
617 struct sockaddr_in local;
618 struct sockaddr_in server;
619 int try_port;
620 int ret;
621 struct socket *socket;
622 struct dentry *dentry;
623 struct inode *inode;
624 struct file *file;
626 file = fget(fd);
627 if(!file)
628 return 0;
630 dentry = file->f_dentry;
631 inode = dentry->d_inode;
633 socket = &inode->u.socket_i;
634 local.sin_family = AF_INET;
635 local.sin_addr.s_addr = INADDR_ANY;
637 /* IPPORT_RESERVED = 1024, can't find the definition in the kernel */
638 try_port = 1024;
639 do {
640 local.sin_port = htons (--try_port);
641 ret = socket->ops->bind(socket, (struct sockaddr*)&local,
642 sizeof(local));
643 } while (ret && try_port > (1024 / 2));
645 if (ret) {
646 fput(file);
647 return 0;
650 server.sin_family = AF_INET;
651 server.sin_addr = addr->sin_addr;
652 server.sin_port = NFS_PORT;
654 /* Call sys_connect */
655 ret = socket->ops->connect (socket, (struct sockaddr *) &server,
656 sizeof (server), file->f_flags);
657 fput(file);
658 if (ret < 0)
659 return 0;
660 return 1;
663 /* XXXXXXXXXXXXXXXXXXXX */
664 static int get_default (int value, int def_value)
666 if (value)
667 return value;
668 else
669 return def_value;
672 /* XXXXXXXXXXXXXXXXXXXX */
673 static int sunos_nfs_mount(char *dir_name, int linux_flags, void *data)
675 int server_fd;
676 char *the_name;
677 struct nfs_mount_data linux_nfs_mount;
678 struct sunos_nfs_mount_args sunos_mount;
680 /* Ok, here comes the fun part: Linux's nfs mount needs a
681 * socket connection to the server, but SunOS mount does not
682 * require this, so we use the information on the destination
683 * address to create a socket and bind it to a reserved
684 * port on this system
686 if (copy_from_user(&sunos_mount, data, sizeof(sunos_mount)))
687 return -EFAULT;
689 server_fd = sys_socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP);
690 if (server_fd < 0)
691 return -ENXIO;
693 if (copy_from_user(&linux_nfs_mount.addr,sunos_mount.addr,
694 sizeof(*sunos_mount.addr)) ||
695 copy_from_user(&linux_nfs_mount.root,sunos_mount.fh,
696 sizeof(*sunos_mount.fh))) {
697 sys_close (server_fd);
698 return -EFAULT;
701 if (!sunos_nfs_get_server_fd (server_fd, &linux_nfs_mount.addr)){
702 sys_close (server_fd);
703 return -ENXIO;
706 /* Now, bind it to a locally reserved port */
707 linux_nfs_mount.version = NFS_MOUNT_VERSION;
708 linux_nfs_mount.flags = sunos_mount.flags;
709 linux_nfs_mount.fd = server_fd;
711 linux_nfs_mount.rsize = get_default (sunos_mount.rsize, 8192);
712 linux_nfs_mount.wsize = get_default (sunos_mount.wsize, 8192);
713 linux_nfs_mount.timeo = get_default (sunos_mount.timeo, 10);
714 linux_nfs_mount.retrans = sunos_mount.retrans;
716 linux_nfs_mount.acregmin = sunos_mount.acregmin;
717 linux_nfs_mount.acregmax = sunos_mount.acregmax;
718 linux_nfs_mount.acdirmin = sunos_mount.acdirmin;
719 linux_nfs_mount.acdirmax = sunos_mount.acdirmax;
721 the_name = getname(sunos_mount.hostname);
722 if(IS_ERR(the_name))
723 return PTR_ERR(the_name);
725 strncpy (linux_nfs_mount.hostname, the_name, 254);
726 linux_nfs_mount.hostname [255] = 0;
727 putname (the_name);
729 return do_mount ("", dir_name, "nfs", linux_flags, &linux_nfs_mount);
732 /* XXXXXXXXXXXXXXXXXXXX */
733 asmlinkage int
734 sunos_mount(char *type, char *dir, int flags, void *data)
736 int linux_flags = MS_MGC_MSK; /* new semantics */
737 int ret = -EINVAL;
738 char *dev_fname = 0;
739 char *dir_page, *type_page;
741 if (!capable (CAP_SYS_ADMIN))
742 return -EPERM;
743 lock_kernel();
744 /* We don't handle the integer fs type */
745 if ((flags & SMNT_NEWTYPE) == 0)
746 goto out;
748 /* Do not allow for those flags we don't support */
749 if (flags & (SMNT_GRPID|SMNT_NOSUB|SMNT_MULTI|SMNT_SYS5))
750 goto out;
752 if(flags & SMNT_REMOUNT)
753 linux_flags |= MS_REMOUNT;
754 if(flags & SMNT_RDONLY)
755 linux_flags |= MS_RDONLY;
756 if(flags & SMNT_NOSUID)
757 linux_flags |= MS_NOSUID;
759 dir_page = getname(dir);
760 ret = PTR_ERR(dir_page);
761 if (IS_ERR(dir_page))
762 goto out;
764 type_page = getname(type);
765 ret = PTR_ERR(type_page);
766 if (IS_ERR(type_page))
767 goto out1;
769 if(strcmp(type_page, "ext2") == 0) {
770 dev_fname = getname(data);
771 } else if(strcmp(type_page, "iso9660") == 0) {
772 dev_fname = getname(data);
773 } else if(strcmp(type_page, "minix") == 0) {
774 dev_fname = getname(data);
775 } else if(strcmp(type_page, "nfs") == 0) {
776 ret = sunos_nfs_mount (dir_page, flags, data);
777 goto out2;
778 } else if(strcmp(type_page, "ufs") == 0) {
779 printk("Warning: UFS filesystem mounts unsupported.\n");
780 ret = -ENODEV;
781 goto out2;
782 } else if(strcmp(type_page, "proc")) {
783 ret = -ENODEV;
784 goto out2;
786 ret = PTR_ERR(dev_fname);
787 if (IS_ERR(dev_fname))
788 goto out2;
789 ret = do_mount(dev_fname, dir_page, type_page, linux_flags, NULL);
790 if (dev_fname)
791 putname(dev_fname);
792 out2:
793 putname(type_page);
794 out1:
795 putname(dir_page);
796 out:
797 unlock_kernel();
798 return ret;
801 extern asmlinkage int sys_setsid(void);
802 extern asmlinkage int sys_setpgid(pid_t, pid_t);
804 asmlinkage int sunos_setpgrp(pid_t pid, pid_t pgid)
806 int ret;
808 /* So stupid... */
809 lock_kernel();
810 if((!pid || pid == current->pid) &&
811 !pgid) {
812 sys_setsid();
813 ret = 0;
814 } else {
815 ret = sys_setpgid(pid, pgid);
817 unlock_kernel();
818 return ret;
821 /* So stupid... */
822 extern asmlinkage int sys32_wait4(__kernel_pid_t32 pid,
823 u32 stat_addr, int options, u32 ru);
825 asmlinkage int sunos_wait4(__kernel_pid_t32 pid, u32 stat_addr, int options, u32 ru)
827 int ret;
829 lock_kernel();
830 ret = sys32_wait4((pid ? pid : ((__kernel_pid_t32)-1)),
831 stat_addr, options, ru);
832 unlock_kernel();
833 return ret;
836 extern int kill_pg(int, int, int);
837 asmlinkage int sunos_killpg(int pgrp, int sig)
839 int ret;
841 lock_kernel();
842 ret = kill_pg(pgrp, sig, 0);
843 unlock_kernel();
844 return ret;
847 asmlinkage int sunos_audit(void)
849 lock_kernel();
850 printk ("sys_audit\n");
851 unlock_kernel();
852 return -1;
855 extern asmlinkage u32 sunos_gethostid(void)
857 u32 ret;
859 lock_kernel();
860 ret = (((u32)idprom->id_machtype << 24) | ((u32)idprom->id_sernum));
861 unlock_kernel();
862 return ret;
865 /* sysconf options, for SunOS compatibility */
866 #define _SC_ARG_MAX 1
867 #define _SC_CHILD_MAX 2
868 #define _SC_CLK_TCK 3
869 #define _SC_NGROUPS_MAX 4
870 #define _SC_OPEN_MAX 5
871 #define _SC_JOB_CONTROL 6
872 #define _SC_SAVED_IDS 7
873 #define _SC_VERSION 8
875 extern asmlinkage s32 sunos_sysconf (int name)
877 s32 ret;
879 lock_kernel();
880 switch (name){
881 case _SC_ARG_MAX:
882 ret = ARG_MAX;
883 break;
884 case _SC_CHILD_MAX:
885 ret = CHILD_MAX;
886 break;
887 case _SC_CLK_TCK:
888 ret = HZ;
889 break;
890 case _SC_NGROUPS_MAX:
891 ret = NGROUPS_MAX;
892 break;
893 case _SC_OPEN_MAX:
894 ret = OPEN_MAX;
895 break;
896 case _SC_JOB_CONTROL:
897 ret = 1; /* yes, we do support job control */
898 break;
899 case _SC_SAVED_IDS:
900 ret = 1; /* yes, we do support saved uids */
901 break;
902 case _SC_VERSION:
903 /* mhm, POSIX_VERSION is in /usr/include/unistd.h
904 * should it go on /usr/include/linux?
906 ret = 199009;
907 break;
908 default:
909 ret = -1;
910 break;
912 unlock_kernel();
913 return ret;
916 asmlinkage int sunos_semsys(int op, u32 arg1, u32 arg2, u32 arg3, u32 ptr)
918 union semun arg4;
919 int ret;
921 lock_kernel();
922 switch (op) {
923 case 0:
924 /* Most arguments match on a 1:1 basis but cmd doesn't */
925 switch(arg3) {
926 case 4:
927 arg3=GETPID; break;
928 case 5:
929 arg3=GETVAL; break;
930 case 6:
931 arg3=GETALL; break;
932 case 3:
933 arg3=GETNCNT; break;
934 case 7:
935 arg3=GETZCNT; break;
936 case 8:
937 arg3=SETVAL; break;
938 case 9:
939 arg3=SETALL; break;
941 /* sys_semctl(): */
942 arg4.__pad=(void *)A(ptr); /* value to modify semaphore to */
943 ret = sys_semctl((int)arg1, (int)arg2, (int)arg3, arg4);
944 break;
945 case 1:
946 /* sys_semget(): */
947 ret = sys_semget((key_t)arg1, (int)arg2, (int)arg3);
948 break;
949 case 2:
950 /* sys_semop(): */
951 ret = sys_semop((int)arg1, (struct sembuf *)A(arg2), (unsigned)arg3);
952 break;
953 default:
954 ret = -EINVAL;
955 break;
957 unlock_kernel();
958 return ret;
961 struct msgbuf32 {
962 s32 mtype;
963 char mtext[1];
966 struct ipc_perm32
968 key_t key;
969 __kernel_uid_t32 uid;
970 __kernel_gid_t32 gid;
971 __kernel_uid_t32 cuid;
972 __kernel_gid_t32 cgid;
973 __kernel_mode_t32 mode;
974 unsigned short seq;
977 struct msqid_ds32
979 struct ipc_perm32 msg_perm;
980 u32 msg_first;
981 u32 msg_last;
982 __kernel_time_t32 msg_stime;
983 __kernel_time_t32 msg_rtime;
984 __kernel_time_t32 msg_ctime;
985 u32 wwait;
986 u32 rwait;
987 unsigned short msg_cbytes;
988 unsigned short msg_qnum;
989 unsigned short msg_qbytes;
990 __kernel_ipc_pid_t32 msg_lspid;
991 __kernel_ipc_pid_t32 msg_lrpid;
994 static inline int sunos_msqid_get(struct msqid_ds32 *user,
995 struct msqid_ds *kern)
997 if(get_user(kern->msg_perm.key, &user->msg_perm.key) ||
998 __get_user(kern->msg_perm.uid, &user->msg_perm.uid) ||
999 __get_user(kern->msg_perm.gid, &user->msg_perm.gid) ||
1000 __get_user(kern->msg_perm.cuid, &user->msg_perm.cuid) ||
1001 __get_user(kern->msg_perm.cgid, &user->msg_perm.cgid) ||
1002 __get_user(kern->msg_stime, &user->msg_stime) ||
1003 __get_user(kern->msg_rtime, &user->msg_rtime) ||
1004 __get_user(kern->msg_ctime, &user->msg_ctime) ||
1005 __get_user(kern->msg_ctime, &user->msg_cbytes) ||
1006 __get_user(kern->msg_ctime, &user->msg_qnum) ||
1007 __get_user(kern->msg_ctime, &user->msg_qbytes) ||
1008 __get_user(kern->msg_ctime, &user->msg_lspid) ||
1009 __get_user(kern->msg_ctime, &user->msg_lrpid))
1010 return -EFAULT;
1011 return 0;
1014 static inline int sunos_msqid_put(struct msqid_ds32 *user,
1015 struct msqid_ds *kern)
1017 if(put_user(kern->msg_perm.key, &user->msg_perm.key) ||
1018 __put_user(kern->msg_perm.uid, &user->msg_perm.uid) ||
1019 __put_user(kern->msg_perm.gid, &user->msg_perm.gid) ||
1020 __put_user(kern->msg_perm.cuid, &user->msg_perm.cuid) ||
1021 __put_user(kern->msg_perm.cgid, &user->msg_perm.cgid) ||
1022 __put_user(kern->msg_stime, &user->msg_stime) ||
1023 __put_user(kern->msg_rtime, &user->msg_rtime) ||
1024 __put_user(kern->msg_ctime, &user->msg_ctime) ||
1025 __put_user(kern->msg_ctime, &user->msg_cbytes) ||
1026 __put_user(kern->msg_ctime, &user->msg_qnum) ||
1027 __put_user(kern->msg_ctime, &user->msg_qbytes) ||
1028 __put_user(kern->msg_ctime, &user->msg_lspid) ||
1029 __put_user(kern->msg_ctime, &user->msg_lrpid))
1030 return -EFAULT;
1031 return 0;
1034 static inline int sunos_msgbuf_get(struct msgbuf32 *user, struct msgbuf *kern, int len)
1036 if(get_user(kern->mtype, &user->mtype) ||
1037 __copy_from_user(kern->mtext, &user->mtext, len))
1038 return -EFAULT;
1039 return 0;
1042 static inline int sunos_msgbuf_put(struct msgbuf32 *user, struct msgbuf *kern, int len)
1044 if(put_user(kern->mtype, &user->mtype) ||
1045 __copy_to_user(user->mtext, kern->mtext, len))
1046 return -EFAULT;
1047 return 0;
1050 asmlinkage int sunos_msgsys(int op, u32 arg1, u32 arg2, u32 arg3, u32 arg4)
1052 struct sparc_stackf32 *sp;
1053 struct msqid_ds kds;
1054 struct msgbuf *kmbuf;
1055 mm_segment_t old_fs = get_fs();
1056 u32 arg5;
1057 int rval;
1059 lock_kernel();
1060 switch(op) {
1061 case 0:
1062 rval = sys_msgget((key_t)arg1, (int)arg2);
1063 break;
1064 case 1:
1065 if(!sunos_msqid_get((struct msqid_ds32 *)A(arg3), &kds)) {
1066 set_fs(KERNEL_DS);
1067 rval = sys_msgctl((int)arg1, (int)arg2,
1068 (struct msqid_ds *)A(arg3));
1069 set_fs(old_fs);
1070 if(!rval)
1071 rval = sunos_msqid_put((struct msqid_ds32 *)A(arg3),
1072 &kds);
1073 } else
1074 rval = -EFAULT;
1075 break;
1076 case 2:
1077 rval = -EFAULT;
1078 kmbuf = (struct msgbuf *)kmalloc(sizeof(struct msgbuf) + arg3,
1079 GFP_KERNEL);
1080 if(!kmbuf)
1081 break;
1082 sp = (struct sparc_stackf32 *)
1083 (current->thread.kregs->u_regs[UREG_FP] & 0xffffffffUL);
1084 if(get_user(arg5, &sp->xxargs[0])) {
1085 rval = -EFAULT;
1086 break;
1088 set_fs(KERNEL_DS);
1089 rval = sys_msgrcv((int)arg1, kmbuf, (size_t)arg3,
1090 (long)arg4, (int)arg5);
1091 set_fs(old_fs);
1092 if(!rval)
1093 rval = sunos_msgbuf_put((struct msgbuf32 *)A(arg2),
1094 kmbuf, arg3);
1095 kfree(kmbuf);
1096 break;
1097 case 3:
1098 rval = -EFAULT;
1099 kmbuf = (struct msgbuf *)kmalloc(sizeof(struct msgbuf) + arg3,
1100 GFP_KERNEL);
1101 if(!kmbuf || sunos_msgbuf_get((struct msgbuf32 *)A(arg2),
1102 kmbuf, arg3))
1103 break;
1104 set_fs(KERNEL_DS);
1105 rval = sys_msgsnd((int)arg1, kmbuf, (size_t)arg3, (int)arg4);
1106 set_fs(old_fs);
1107 kfree(kmbuf);
1108 break;
1109 default:
1110 rval = -EINVAL;
1111 break;
1113 unlock_kernel();
1114 return rval;
1117 struct shmid_ds32 {
1118 struct ipc_perm32 shm_perm;
1119 int shm_segsz;
1120 __kernel_time_t32 shm_atime;
1121 __kernel_time_t32 shm_dtime;
1122 __kernel_time_t32 shm_ctime;
1123 __kernel_ipc_pid_t32 shm_cpid;
1124 __kernel_ipc_pid_t32 shm_lpid;
1125 unsigned short shm_nattch;
1128 static inline int sunos_shmid_get(struct shmid_ds32 *user,
1129 struct shmid_ds *kern)
1131 if(get_user(kern->shm_perm.key, &user->shm_perm.key) ||
1132 __get_user(kern->shm_perm.uid, &user->shm_perm.uid) ||
1133 __get_user(kern->shm_perm.gid, &user->shm_perm.gid) ||
1134 __get_user(kern->shm_perm.cuid, &user->shm_perm.cuid) ||
1135 __get_user(kern->shm_perm.cgid, &user->shm_perm.cgid) ||
1136 __get_user(kern->shm_segsz, &user->shm_segsz) ||
1137 __get_user(kern->shm_atime, &user->shm_atime) ||
1138 __get_user(kern->shm_dtime, &user->shm_dtime) ||
1139 __get_user(kern->shm_ctime, &user->shm_ctime) ||
1140 __get_user(kern->shm_cpid, &user->shm_cpid) ||
1141 __get_user(kern->shm_lpid, &user->shm_lpid) ||
1142 __get_user(kern->shm_nattch, &user->shm_nattch))
1143 return -EFAULT;
1144 return 0;
1147 static inline int sunos_shmid_put(struct shmid_ds32 *user,
1148 struct shmid_ds *kern)
1150 if(put_user(kern->shm_perm.key, &user->shm_perm.key) ||
1151 __put_user(kern->shm_perm.uid, &user->shm_perm.uid) ||
1152 __put_user(kern->shm_perm.gid, &user->shm_perm.gid) ||
1153 __put_user(kern->shm_perm.cuid, &user->shm_perm.cuid) ||
1154 __put_user(kern->shm_perm.cgid, &user->shm_perm.cgid) ||
1155 __put_user(kern->shm_segsz, &user->shm_segsz) ||
1156 __put_user(kern->shm_atime, &user->shm_atime) ||
1157 __put_user(kern->shm_dtime, &user->shm_dtime) ||
1158 __put_user(kern->shm_ctime, &user->shm_ctime) ||
1159 __put_user(kern->shm_cpid, &user->shm_cpid) ||
1160 __put_user(kern->shm_lpid, &user->shm_lpid) ||
1161 __put_user(kern->shm_nattch, &user->shm_nattch))
1162 return -EFAULT;
1163 return 0;
1166 asmlinkage int sunos_shmsys(int op, u32 arg1, u32 arg2, u32 arg3)
1168 struct shmid_ds ksds;
1169 unsigned long raddr;
1170 mm_segment_t old_fs = get_fs();
1171 int rval;
1173 lock_kernel();
1174 switch(op) {
1175 case 0:
1176 /* sys_shmat(): attach a shared memory area */
1177 rval = sys_shmat((int)arg1,(char *)A(arg2),(int)arg3,&raddr);
1178 if(!rval)
1179 rval = (int) raddr;
1180 break;
1181 case 1:
1182 /* sys_shmctl(): modify shared memory area attr. */
1183 if(!sunos_shmid_get((struct shmid_ds32 *)A(arg3), &ksds)) {
1184 set_fs(KERNEL_DS);
1185 rval = sys_shmctl((int)arg1,(int)arg2, &ksds);
1186 set_fs(old_fs);
1187 if(!rval)
1188 rval = sunos_shmid_put((struct shmid_ds32 *)A(arg3),
1189 &ksds);
1190 } else
1191 rval = -EFAULT;
1192 break;
1193 case 2:
1194 /* sys_shmdt(): detach a shared memory area */
1195 rval = sys_shmdt((char *)A(arg1));
1196 break;
1197 case 3:
1198 /* sys_shmget(): get a shared memory area */
1199 rval = sys_shmget((key_t)arg1,(int)arg2,(int)arg3);
1200 break;
1201 default:
1202 rval = -EINVAL;
1203 break;
1205 unlock_kernel();
1206 return rval;
1209 extern asmlinkage long sparc32_open(const char * filename, int flags, int mode);
1211 asmlinkage int sunos_open(u32 fname, int flags, int mode)
1213 const char *filename = (const char *)(long)fname;
1215 return sparc32_open(filename, flags, mode);
1218 #define SUNOS_EWOULDBLOCK 35
1220 /* see the sunos man page read(2v) for an explanation
1221 of this garbage. We use O_NDELAY to mark
1222 file descriptors that have been set non-blocking
1223 using 4.2BSD style calls. (tridge) */
1225 static inline int check_nonblock(int ret, int fd)
1227 if (ret == -EAGAIN) {
1228 struct file * file = fcheck(fd);
1229 if (file && (file->f_flags & O_NDELAY))
1230 ret = -SUNOS_EWOULDBLOCK;
1232 return ret;
1235 extern asmlinkage int sys_read(unsigned int fd, char *buf, unsigned long count);
1236 extern asmlinkage int sys_write(unsigned int fd, char *buf, unsigned long count);
1237 extern asmlinkage int sys_recv(int fd, void *ubuf, size_t size, unsigned flags);
1238 extern asmlinkage int sys_send(int fd, void *buff, size_t len, unsigned flags);
1239 extern asmlinkage int sys_accept(int fd, struct sockaddr *sa, int *addrlen);
1240 extern asmlinkage int sys32_readv(u32 fd, u32 vector, s32 count);
1241 extern asmlinkage int sys32_writev(u32 fd, u32 vector, s32 count);
1243 asmlinkage int sunos_read(unsigned int fd, u32 buf, u32 count)
1245 int ret;
1247 lock_kernel();
1248 ret = check_nonblock(sys_read(fd, (char *)A(buf), count), fd);
1249 unlock_kernel();
1250 return ret;
1253 asmlinkage int sunos_readv(u32 fd, u32 vector, s32 count)
1255 int ret;
1257 lock_kernel();
1258 ret = check_nonblock(sys32_readv(fd, vector, count), fd);
1259 unlock_kernel();
1260 return ret;
1263 asmlinkage int sunos_write(unsigned int fd, u32 buf, u32 count)
1265 int ret;
1267 lock_kernel();
1268 ret = check_nonblock(sys_write(fd, (char *)A(buf), count), fd);
1269 unlock_kernel();
1270 return ret;
1273 asmlinkage int sunos_writev(u32 fd, u32 vector, s32 count)
1275 int ret;
1277 lock_kernel();
1278 ret = check_nonblock(sys32_writev(fd, vector, count), fd);
1279 unlock_kernel();
1280 return ret;
1283 asmlinkage int sunos_recv(int fd, u32 ubuf, int size, unsigned flags)
1285 int ret;
1287 lock_kernel();
1288 ret = check_nonblock(sys_recv(fd, (void *)A(ubuf), size, flags), fd);
1289 unlock_kernel();
1290 return ret;
1293 asmlinkage int sunos_send(int fd, u32 buff, int len, unsigned flags)
1295 int ret;
1297 lock_kernel();
1298 ret = check_nonblock(sys_send(fd, (void *)A(buff), len, flags), fd);
1299 unlock_kernel();
1300 return ret;
1303 extern asmlinkage int sys_setsockopt(int fd, int level, int optname,
1304 char *optval, int optlen);
1306 asmlinkage int sunos_socket(int family, int type, int protocol)
1308 int ret, one = 1;
1310 lock_kernel();
1311 ret = sys_socket(family, type, protocol);
1312 if (ret < 0)
1313 goto out;
1315 sys_setsockopt(ret, SOL_SOCKET, SO_BSDCOMPAT,
1316 (char *)&one, sizeof(one));
1317 out:
1318 unlock_kernel();
1319 return ret;
1322 asmlinkage int sunos_accept(int fd, u32 sa, u32 addrlen)
1324 int ret, one = 1;
1326 lock_kernel();
1327 while (1) {
1328 ret = check_nonblock(sys_accept(fd, (struct sockaddr *)A(sa),
1329 (int *)A(addrlen)), fd);
1330 if (ret != -ENETUNREACH && ret != -EHOSTUNREACH)
1331 break;
1333 if (ret < 0)
1334 goto out;
1336 sys_setsockopt(ret, SOL_SOCKET, SO_BSDCOMPAT,
1337 (char *)&one, sizeof(one));
1338 out:
1339 unlock_kernel();
1340 return ret;
1343 #define SUNOS_SV_INTERRUPT 2
1345 asmlinkage int sunos_sigaction (int sig, u32 act, u32 oact)
1347 struct k_sigaction new_ka, old_ka;
1348 int ret;
1350 if (act) {
1351 old_sigset_t32 mask;
1353 if (get_user((long)new_ka.sa.sa_handler, &((struct old_sigaction32 *)A(act))->sa_handler) ||
1354 __get_user(new_ka.sa.sa_flags, &((struct old_sigaction32 *)A(act))->sa_flags))
1355 return -EFAULT;
1356 __get_user(mask, &((struct old_sigaction32 *)A(act))->sa_mask);
1357 new_ka.sa.sa_restorer = NULL;
1358 new_ka.ka_restorer = NULL;
1359 siginitset(&new_ka.sa.sa_mask, mask);
1360 new_ka.sa.sa_flags ^= SUNOS_SV_INTERRUPT;
1363 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
1365 if (!ret && oact) {
1366 old_ka.sa.sa_flags ^= SUNOS_SV_INTERRUPT;
1367 if (put_user((long)old_ka.sa.sa_handler, &((struct old_sigaction32 *)A(oact))->sa_handler) ||
1368 __put_user(old_ka.sa.sa_flags, &((struct old_sigaction32 *)A(oact))->sa_flags))
1369 return -EFAULT;
1370 __put_user(old_ka.sa.sa_mask.sig[0], &((struct old_sigaction32 *)A(oact))->sa_mask);
1373 return ret;
1376 extern asmlinkage int sys_setsockopt(int fd, int level, int optname,
1377 char *optval, int optlen);
1378 extern asmlinkage int sys32_getsockopt(int fd, int level, int optname,
1379 u32 optval, u32 optlen);
1381 asmlinkage int sunos_setsockopt(int fd, int level, int optname, u32 optval,
1382 int optlen)
1384 int tr_opt = optname;
1385 int ret;
1387 lock_kernel();
1388 if (level == SOL_IP) {
1389 /* Multicast socketopts (ttl, membership) */
1390 if (tr_opt >=2 && tr_opt <= 6)
1391 tr_opt += 30;
1393 ret = sys_setsockopt(fd, level, tr_opt, (char *)A(optval), optlen);
1394 unlock_kernel();
1395 return ret;
1398 asmlinkage int sunos_getsockopt(int fd, int level, int optname,
1399 u32 optval, u32 optlen)
1401 int tr_opt = optname;
1402 int ret;
1404 lock_kernel();
1405 if (level == SOL_IP) {
1406 /* Multicast socketopts (ttl, membership) */
1407 if (tr_opt >=2 && tr_opt <= 6)
1408 tr_opt += 30;
1410 ret = sys32_getsockopt(fd, level, tr_opt, optval, optlen);
1411 unlock_kernel();
1412 return ret;