aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sparc/kernel/sys_sunos.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/sparc/kernel/sys_sunos.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'arch/sparc/kernel/sys_sunos.c')
-rw-r--r--arch/sparc/kernel/sys_sunos.c1194
1 files changed, 1194 insertions, 0 deletions
diff --git a/arch/sparc/kernel/sys_sunos.c b/arch/sparc/kernel/sys_sunos.c
new file mode 100644
index 000000000000..81c894acd0db
--- /dev/null
+++ b/arch/sparc/kernel/sys_sunos.c
@@ -0,0 +1,1194 @@
1/* $Id: sys_sunos.c,v 1.137 2002/02/08 03:57:14 davem Exp $
2 * sys_sunos.c: SunOS specific syscall compatibility support.
3 *
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx)
6 *
7 * Based upon preliminary work which is:
8 *
9 * Copyright (C) 1995 Adrian M. Rodriguez (adrian@remus.rutgers.edu)
10 *
11 */
12
13#include <linux/kernel.h>
14#include <linux/sched.h>
15#include <linux/types.h>
16#include <linux/mman.h>
17#include <linux/mm.h>
18#include <linux/swap.h>
19#include <linux/fs.h>
20#include <linux/file.h>
21#include <linux/resource.h>
22#include <linux/ipc.h>
23#include <linux/shm.h>
24#include <linux/msg.h>
25#include <linux/sem.h>
26#include <linux/signal.h>
27#include <linux/uio.h>
28#include <linux/utsname.h>
29#include <linux/major.h>
30#include <linux/stat.h>
31#include <linux/slab.h>
32#include <linux/pagemap.h>
33#include <linux/errno.h>
34#include <linux/smp.h>
35#include <linux/smp_lock.h>
36#include <linux/syscalls.h>
37
38#include <net/sock.h>
39
40#include <asm/uaccess.h>
41#ifndef KERNEL_DS
42#include <linux/segment.h>
43#endif
44
45#include <asm/page.h>
46#include <asm/pgtable.h>
47#include <asm/pconf.h>
48#include <asm/idprom.h> /* for gethostid() */
49#include <asm/unistd.h>
50#include <asm/system.h>
51
52/* For the nfs mount emulation */
53#include <linux/socket.h>
54#include <linux/in.h>
55#include <linux/nfs.h>
56#include <linux/nfs2.h>
57#include <linux/nfs_mount.h>
58
59/* for sunos_select */
60#include <linux/time.h>
61#include <linux/personality.h>
62
63/* NR_OPEN is now larger and dynamic in recent kernels. */
64#define SUNOS_NR_OPEN 256
65
66/* We use the SunOS mmap() semantics. */
67asmlinkage unsigned long sunos_mmap(unsigned long addr, unsigned long len,
68 unsigned long prot, unsigned long flags,
69 unsigned long fd, unsigned long off)
70{
71 struct file * file = NULL;
72 unsigned long retval, ret_type;
73
74 if (flags & MAP_NORESERVE) {
75 static int cnt;
76 if (cnt++ < 10)
77 printk("%s: unimplemented SunOS MAP_NORESERVE mmap() flag\n",
78 current->comm);
79 flags &= ~MAP_NORESERVE;
80 }
81 retval = -EBADF;
82 if (!(flags & MAP_ANONYMOUS)) {
83 if (fd >= SUNOS_NR_OPEN)
84 goto out;
85 file = fget(fd);
86 if (!file)
87 goto out;
88 }
89
90 retval = -EINVAL;
91 /* If this is ld.so or a shared library doing an mmap
92 * of /dev/zero, transform it into an anonymous mapping.
93 * SunOS is so stupid some times... hmph!
94 */
95 if (file) {
96 if (imajor(file->f_dentry->d_inode) == MEM_MAJOR &&
97 iminor(file->f_dentry->d_inode) == 5) {
98 flags |= MAP_ANONYMOUS;
99 fput(file);
100 file = NULL;
101 }
102 }
103 ret_type = flags & _MAP_NEW;
104 flags &= ~_MAP_NEW;
105
106 if (!(flags & MAP_FIXED))
107 addr = 0;
108 else {
109 if (ARCH_SUN4C_SUN4 &&
110 (len > 0x20000000 ||
111 ((flags & MAP_FIXED) &&
112 addr < 0xe0000000 && addr + len > 0x20000000)))
113 goto out_putf;
114
115 /* See asm-sparc/uaccess.h */
116 if (len > TASK_SIZE - PAGE_SIZE ||
117 addr + len > TASK_SIZE - PAGE_SIZE)
118 goto out_putf;
119 }
120
121 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
122 down_write(&current->mm->mmap_sem);
123 retval = do_mmap(file, addr, len, prot, flags, off);
124 up_write(&current->mm->mmap_sem);
125 if (!ret_type)
126 retval = ((retval < PAGE_OFFSET) ? 0 : retval);
127
128out_putf:
129 if (file)
130 fput(file);
131out:
132 return retval;
133}
134
135/* lmbench calls this, just say "yeah, ok" */
136asmlinkage int sunos_mctl(unsigned long addr, unsigned long len, int function, char *arg)
137{
138 return 0;
139}
140
141/* SunOS is completely broken... it returns 0 on success, otherwise
142 * ENOMEM. For sys_sbrk() it wants the old brk value as a return
143 * on success and ENOMEM as before on failure.
144 */
145asmlinkage int sunos_brk(unsigned long brk)
146{
147 int freepages, retval = -ENOMEM;
148 unsigned long rlim;
149 unsigned long newbrk, oldbrk;
150
151 down_write(&current->mm->mmap_sem);
152 if (ARCH_SUN4C_SUN4) {
153 if (brk >= 0x20000000 && brk < 0xe0000000) {
154 goto out;
155 }
156 }
157
158 if (brk < current->mm->end_code)
159 goto out;
160
161 newbrk = PAGE_ALIGN(brk);
162 oldbrk = PAGE_ALIGN(current->mm->brk);
163 retval = 0;
164 if (oldbrk == newbrk) {
165 current->mm->brk = brk;
166 goto out;
167 }
168
169 /*
170 * Always allow shrinking brk
171 */
172 if (brk <= current->mm->brk) {
173 current->mm->brk = brk;
174 do_munmap(current->mm, newbrk, oldbrk-newbrk);
175 goto out;
176 }
177 /*
178 * Check against rlimit and stack..
179 */
180 retval = -ENOMEM;
181 rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
182 if (rlim >= RLIM_INFINITY)
183 rlim = ~0;
184 if (brk - current->mm->end_code > rlim)
185 goto out;
186
187 /*
188 * Check against existing mmap mappings.
189 */
190 if (find_vma_intersection(current->mm, oldbrk, newbrk+PAGE_SIZE))
191 goto out;
192
193 /*
194 * stupid algorithm to decide if we have enough memory: while
195 * simple, it hopefully works in most obvious cases.. Easy to
196 * fool it, but this should catch most mistakes.
197 */
198 freepages = get_page_cache_size();
199 freepages >>= 1;
200 freepages += nr_free_pages();
201 freepages += nr_swap_pages;
202 freepages -= num_physpages >> 4;
203 freepages -= (newbrk-oldbrk) >> PAGE_SHIFT;
204 if (freepages < 0)
205 goto out;
206 /*
207 * Ok, we have probably got enough memory - let it rip.
208 */
209 current->mm->brk = brk;
210 do_brk(oldbrk, newbrk-oldbrk);
211 retval = 0;
212out:
213 up_write(&current->mm->mmap_sem);
214 return retval;
215}
216
217asmlinkage unsigned long sunos_sbrk(int increment)
218{
219 int error;
220 unsigned long oldbrk;
221
222 /* This should do it hopefully... */
223 lock_kernel();
224 oldbrk = current->mm->brk;
225 error = sunos_brk(((int) current->mm->brk) + increment);
226 if (!error)
227 error = oldbrk;
228 unlock_kernel();
229 return error;
230}
231
232/* XXX Completely undocumented, and completely magic...
233 * XXX I believe it is to increase the size of the stack by
234 * XXX argument 'increment' and return the new end of stack
235 * XXX area. Wheee...
236 */
237asmlinkage unsigned long sunos_sstk(int increment)
238{
239 lock_kernel();
240 printk("%s: Call to sunos_sstk(increment<%d>) is unsupported\n",
241 current->comm, increment);
242 unlock_kernel();
243 return -1;
244}
245
246/* Give hints to the kernel as to what paging strategy to use...
247 * Completely bogus, don't remind me.
248 */
249#define VA_NORMAL 0 /* Normal vm usage expected */
250#define VA_ABNORMAL 1 /* Abnormal/random vm usage probable */
251#define VA_SEQUENTIAL 2 /* Accesses will be of a sequential nature */
252#define VA_INVALIDATE 3 /* Page table entries should be flushed ??? */
253static char *vstrings[] = {
254 "VA_NORMAL",
255 "VA_ABNORMAL",
256 "VA_SEQUENTIAL",
257 "VA_INVALIDATE",
258};
259
260asmlinkage void sunos_vadvise(unsigned long strategy)
261{
262 /* I wanna see who uses this... */
263 lock_kernel();
264 printk("%s: Advises us to use %s paging strategy\n",
265 current->comm,
266 strategy <= 3 ? vstrings[strategy] : "BOGUS");
267 unlock_kernel();
268}
269
270/* This just wants the soft limit (ie. rlim_cur element) of the RLIMIT_NOFILE
271 * resource limit and is for backwards compatibility with older sunos
272 * revs.
273 */
274asmlinkage long sunos_getdtablesize(void)
275{
276 return SUNOS_NR_OPEN;
277}
278
279#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
280
281asmlinkage unsigned long sunos_sigblock(unsigned long blk_mask)
282{
283 unsigned long old;
284
285 spin_lock_irq(&current->sighand->siglock);
286 old = current->blocked.sig[0];
287 current->blocked.sig[0] |= (blk_mask & _BLOCKABLE);
288 recalc_sigpending();
289 spin_unlock_irq(&current->sighand->siglock);
290 return old;
291}
292
293asmlinkage unsigned long sunos_sigsetmask(unsigned long newmask)
294{
295 unsigned long retval;
296
297 spin_lock_irq(&current->sighand->siglock);
298 retval = current->blocked.sig[0];
299 current->blocked.sig[0] = (newmask & _BLOCKABLE);
300 recalc_sigpending();
301 spin_unlock_irq(&current->sighand->siglock);
302 return retval;
303}
304
305/* SunOS getdents is very similar to the newer Linux (iBCS2 compliant) */
306/* getdents system call, the format of the structure just has a different */
307/* layout (d_off+d_ino instead of d_ino+d_off) */
308struct sunos_dirent {
309 long d_off;
310 unsigned long d_ino;
311 unsigned short d_reclen;
312 unsigned short d_namlen;
313 char d_name[1];
314};
315
316struct sunos_dirent_callback {
317 struct sunos_dirent __user *curr;
318 struct sunos_dirent __user *previous;
319 int count;
320 int error;
321};
322
323#define NAME_OFFSET(de) ((int) ((de)->d_name - (char __user *) (de)))
324#define ROUND_UP(x) (((x)+sizeof(long)-1) & ~(sizeof(long)-1))
325
326static int sunos_filldir(void * __buf, const char * name, int namlen,
327 loff_t offset, ino_t ino, unsigned int d_type)
328{
329 struct sunos_dirent __user *dirent;
330 struct sunos_dirent_callback * buf = __buf;
331 int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 1);
332
333 buf->error = -EINVAL; /* only used if we fail.. */
334 if (reclen > buf->count)
335 return -EINVAL;
336 dirent = buf->previous;
337 if (dirent)
338 put_user(offset, &dirent->d_off);
339 dirent = buf->curr;
340 buf->previous = dirent;
341 put_user(ino, &dirent->d_ino);
342 put_user(namlen, &dirent->d_namlen);
343 put_user(reclen, &dirent->d_reclen);
344 copy_to_user(dirent->d_name, name, namlen);
345 put_user(0, dirent->d_name + namlen);
346 dirent = (void __user *) dirent + reclen;
347 buf->curr = dirent;
348 buf->count -= reclen;
349 return 0;
350}
351
352asmlinkage int sunos_getdents(unsigned int fd, void __user *dirent, int cnt)
353{
354 struct file * file;
355 struct sunos_dirent __user *lastdirent;
356 struct sunos_dirent_callback buf;
357 int error = -EBADF;
358
359 if (fd >= SUNOS_NR_OPEN)
360 goto out;
361
362 file = fget(fd);
363 if (!file)
364 goto out;
365
366 error = -EINVAL;
367 if (cnt < (sizeof(struct sunos_dirent) + 255))
368 goto out_putf;
369
370 buf.curr = (struct sunos_dirent __user *) dirent;
371 buf.previous = NULL;
372 buf.count = cnt;
373 buf.error = 0;
374
375 error = vfs_readdir(file, sunos_filldir, &buf);
376 if (error < 0)
377 goto out_putf;
378
379 lastdirent = buf.previous;
380 error = buf.error;
381 if (lastdirent) {
382 put_user(file->f_pos, &lastdirent->d_off);
383 error = cnt - buf.count;
384 }
385
386out_putf:
387 fput(file);
388out:
389 return error;
390}
391
392/* Old sunos getdirentries, severely broken compatibility stuff here. */
393struct sunos_direntry {
394 unsigned long d_ino;
395 unsigned short d_reclen;
396 unsigned short d_namlen;
397 char d_name[1];
398};
399
400struct sunos_direntry_callback {
401 struct sunos_direntry __user *curr;
402 struct sunos_direntry __user *previous;
403 int count;
404 int error;
405};
406
407static int sunos_filldirentry(void * __buf, const char * name, int namlen,
408 loff_t offset, ino_t ino, unsigned int d_type)
409{
410 struct sunos_direntry __user *dirent;
411 struct sunos_direntry_callback *buf = __buf;
412 int reclen = ROUND_UP(NAME_OFFSET(dirent) + namlen + 1);
413
414 buf->error = -EINVAL; /* only used if we fail.. */
415 if (reclen > buf->count)
416 return -EINVAL;
417 dirent = buf->previous;
418 dirent = buf->curr;
419 buf->previous = dirent;
420 put_user(ino, &dirent->d_ino);
421 put_user(namlen, &dirent->d_namlen);
422 put_user(reclen, &dirent->d_reclen);
423 copy_to_user(dirent->d_name, name, namlen);
424 put_user(0, dirent->d_name + namlen);
425 dirent = (void __user *) dirent + reclen;
426 buf->curr = dirent;
427 buf->count -= reclen;
428 return 0;
429}
430
431asmlinkage int sunos_getdirentries(unsigned int fd, void __user *dirent,
432 int cnt, unsigned int __user *basep)
433{
434 struct file * file;
435 struct sunos_direntry __user *lastdirent;
436 struct sunos_direntry_callback buf;
437 int error = -EBADF;
438
439 if (fd >= SUNOS_NR_OPEN)
440 goto out;
441
442 file = fget(fd);
443 if (!file)
444 goto out;
445
446 error = -EINVAL;
447 if (cnt < (sizeof(struct sunos_direntry) + 255))
448 goto out_putf;
449
450 buf.curr = (struct sunos_direntry __user *) dirent;
451 buf.previous = NULL;
452 buf.count = cnt;
453 buf.error = 0;
454
455 error = vfs_readdir(file, sunos_filldirentry, &buf);
456 if (error < 0)
457 goto out_putf;
458
459 lastdirent = buf.previous;
460 error = buf.error;
461 if (lastdirent) {
462 put_user(file->f_pos, basep);
463 error = cnt - buf.count;
464 }
465
466out_putf:
467 fput(file);
468out:
469 return error;
470}
471
472struct sunos_utsname {
473 char sname[9];
474 char nname[9];
475 char nnext[56];
476 char rel[9];
477 char ver[9];
478 char mach[9];
479};
480
481asmlinkage int sunos_uname(struct sunos_utsname __user *name)
482{
483 int ret;
484 down_read(&uts_sem);
485 ret = copy_to_user(&name->sname[0], &system_utsname.sysname[0], sizeof(name->sname) - 1);
486 if (!ret) {
487 ret |= __copy_to_user(&name->nname[0], &system_utsname.nodename[0], sizeof(name->nname) - 1);
488 ret |= __put_user('\0', &name->nname[8]);
489 ret |= __copy_to_user(&name->rel[0], &system_utsname.release[0], sizeof(name->rel) - 1);
490 ret |= __copy_to_user(&name->ver[0], &system_utsname.version[0], sizeof(name->ver) - 1);
491 ret |= __copy_to_user(&name->mach[0], &system_utsname.machine[0], sizeof(name->mach) - 1);
492 }
493 up_read(&uts_sem);
494 return ret ? -EFAULT : 0;
495}
496
497asmlinkage int sunos_nosys(void)
498{
499 struct pt_regs *regs;
500 siginfo_t info;
501 static int cnt;
502
503 lock_kernel();
504 regs = current->thread.kregs;
505 info.si_signo = SIGSYS;
506 info.si_errno = 0;
507 info.si_code = __SI_FAULT|0x100;
508 info.si_addr = (void __user *)regs->pc;
509 info.si_trapno = regs->u_regs[UREG_G1];
510 send_sig_info(SIGSYS, &info, current);
511 if (cnt++ < 4) {
512 printk("Process makes ni_syscall number %d, register dump:\n",
513 (int) regs->u_regs[UREG_G1]);
514 show_regs(regs);
515 }
516 unlock_kernel();
517 return -ENOSYS;
518}
519
520/* This is not a real and complete implementation yet, just to keep
521 * the easy SunOS binaries happy.
522 */
523asmlinkage int sunos_fpathconf(int fd, int name)
524{
525 int ret;
526
527 switch(name) {
528 case _PCONF_LINK:
529 ret = LINK_MAX;
530 break;
531 case _PCONF_CANON:
532 ret = MAX_CANON;
533 break;
534 case _PCONF_INPUT:
535 ret = MAX_INPUT;
536 break;
537 case _PCONF_NAME:
538 ret = NAME_MAX;
539 break;
540 case _PCONF_PATH:
541 ret = PATH_MAX;
542 break;
543 case _PCONF_PIPE:
544 ret = PIPE_BUF;
545 break;
546 case _PCONF_CHRESTRICT: /* XXX Investigate XXX */
547 ret = 1;
548 break;
549 case _PCONF_NOTRUNC: /* XXX Investigate XXX */
550 case _PCONF_VDISABLE:
551 ret = 0;
552 break;
553 default:
554 ret = -EINVAL;
555 break;
556 }
557 return ret;
558}
559
560asmlinkage int sunos_pathconf(char __user *path, int name)
561{
562 int ret;
563
564 ret = sunos_fpathconf(0, name); /* XXX cheese XXX */
565 return ret;
566}
567
568/* SunOS mount system call emulation */
569
570asmlinkage int sunos_select(int width, fd_set __user *inp, fd_set __user *outp,
571 fd_set __user *exp, struct timeval __user *tvp)
572{
573 int ret;
574
575 /* SunOS binaries expect that select won't change the tvp contents */
576 ret = sys_select (width, inp, outp, exp, tvp);
577 if (ret == -EINTR && tvp) {
578 time_t sec, usec;
579
580 __get_user(sec, &tvp->tv_sec);
581 __get_user(usec, &tvp->tv_usec);
582
583 if (sec == 0 && usec == 0)
584 ret = 0;
585 }
586 return ret;
587}
588
589asmlinkage void sunos_nop(void)
590{
591 return;
592}
593
594/* SunOS mount/umount. */
595#define SMNT_RDONLY 1
596#define SMNT_NOSUID 2
597#define SMNT_NEWTYPE 4
598#define SMNT_GRPID 8
599#define SMNT_REMOUNT 16
600#define SMNT_NOSUB 32
601#define SMNT_MULTI 64
602#define SMNT_SYS5 128
603
604struct sunos_fh_t {
605 char fh_data [NFS_FHSIZE];
606};
607
608struct sunos_nfs_mount_args {
609 struct sockaddr_in __user *addr; /* file server address */
610 struct nfs_fh __user *fh; /* File handle to be mounted */
611 int flags; /* flags */
612 int wsize; /* write size in bytes */
613 int rsize; /* read size in bytes */
614 int timeo; /* initial timeout in .1 secs */
615 int retrans; /* times to retry send */
616 char __user *hostname; /* server's hostname */
617 int acregmin; /* attr cache file min secs */
618 int acregmax; /* attr cache file max secs */
619 int acdirmin; /* attr cache dir min secs */
620 int acdirmax; /* attr cache dir max secs */
621 char __user *netname; /* server's netname */
622};
623
624
625/* Bind the socket on a local reserved port and connect it to the
626 * remote server. This on Linux/i386 is done by the mount program,
627 * not by the kernel.
628 */
629static int
630sunos_nfs_get_server_fd (int fd, struct sockaddr_in *addr)
631{
632 struct sockaddr_in local;
633 struct sockaddr_in server;
634 int try_port;
635 struct socket *socket;
636 struct inode *inode;
637 struct file *file;
638 int ret, result = 0;
639
640 file = fget(fd);
641 if (!file)
642 goto out;
643
644 inode = file->f_dentry->d_inode;
645
646 socket = SOCKET_I(inode);
647 local.sin_family = AF_INET;
648 local.sin_addr.s_addr = INADDR_ANY;
649
650 /* IPPORT_RESERVED = 1024, can't find the definition in the kernel */
651 try_port = 1024;
652 do {
653 local.sin_port = htons (--try_port);
654 ret = socket->ops->bind(socket, (struct sockaddr*)&local,
655 sizeof(local));
656 } while (ret && try_port > (1024 / 2));
657
658 if (ret)
659 goto out_putf;
660
661 server.sin_family = AF_INET;
662 server.sin_addr = addr->sin_addr;
663 server.sin_port = NFS_PORT;
664
665 /* Call sys_connect */
666 ret = socket->ops->connect (socket, (struct sockaddr *) &server,
667 sizeof (server), file->f_flags);
668 if (ret >= 0)
669 result = 1;
670
671out_putf:
672 fput(file);
673out:
674 return result;
675}
676
677static int get_default (int value, int def_value)
678{
679 if (value)
680 return value;
681 else
682 return def_value;
683}
684
685static int sunos_nfs_mount(char *dir_name, int linux_flags, void __user *data)
686{
687 int server_fd, err;
688 char *the_name, *mount_page;
689 struct nfs_mount_data linux_nfs_mount;
690 struct sunos_nfs_mount_args sunos_mount;
691
692 /* Ok, here comes the fun part: Linux's nfs mount needs a
693 * socket connection to the server, but SunOS mount does not
694 * require this, so we use the information on the destination
695 * address to create a socket and bind it to a reserved
696 * port on this system
697 */
698 if (copy_from_user(&sunos_mount, data, sizeof(sunos_mount)))
699 return -EFAULT;
700
701 server_fd = sys_socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP);
702 if (server_fd < 0)
703 return -ENXIO;
704
705 if (copy_from_user(&linux_nfs_mount.addr,sunos_mount.addr,
706 sizeof(*sunos_mount.addr)) ||
707 copy_from_user(&linux_nfs_mount.root,sunos_mount.fh,
708 sizeof(*sunos_mount.fh))) {
709 sys_close (server_fd);
710 return -EFAULT;
711 }
712
713 if (!sunos_nfs_get_server_fd (server_fd, &linux_nfs_mount.addr)){
714 sys_close (server_fd);
715 return -ENXIO;
716 }
717
718 /* Now, bind it to a locally reserved port */
719 linux_nfs_mount.version = NFS_MOUNT_VERSION;
720 linux_nfs_mount.flags = sunos_mount.flags;
721 linux_nfs_mount.fd = server_fd;
722
723 linux_nfs_mount.rsize = get_default (sunos_mount.rsize, 8192);
724 linux_nfs_mount.wsize = get_default (sunos_mount.wsize, 8192);
725 linux_nfs_mount.timeo = get_default (sunos_mount.timeo, 10);
726 linux_nfs_mount.retrans = sunos_mount.retrans;
727
728 linux_nfs_mount.acregmin = sunos_mount.acregmin;
729 linux_nfs_mount.acregmax = sunos_mount.acregmax;
730 linux_nfs_mount.acdirmin = sunos_mount.acdirmin;
731 linux_nfs_mount.acdirmax = sunos_mount.acdirmax;
732
733 the_name = getname(sunos_mount.hostname);
734 if (IS_ERR(the_name))
735 return PTR_ERR(the_name);
736
737 strlcpy(linux_nfs_mount.hostname, the_name,
738 sizeof(linux_nfs_mount.hostname));
739 putname (the_name);
740
741 mount_page = (char *) get_zeroed_page(GFP_KERNEL);
742 if (!mount_page)
743 return -ENOMEM;
744
745 memcpy(mount_page, &linux_nfs_mount, sizeof(linux_nfs_mount));
746
747 err = do_mount("", dir_name, "nfs", linux_flags, mount_page);
748
749 free_page((unsigned long) mount_page);
750 return err;
751}
752
753asmlinkage int
754sunos_mount(char __user *type, char __user *dir, int flags, void __user *data)
755{
756 int linux_flags = 0;
757 int ret = -EINVAL;
758 char *dev_fname = NULL;
759 char *dir_page, *type_page;
760
761 if (!capable (CAP_SYS_ADMIN))
762 return -EPERM;
763
764 lock_kernel();
765 /* We don't handle the integer fs type */
766 if ((flags & SMNT_NEWTYPE) == 0)
767 goto out;
768
769 /* Do not allow for those flags we don't support */
770 if (flags & (SMNT_GRPID|SMNT_NOSUB|SMNT_MULTI|SMNT_SYS5))
771 goto out;
772
773 if (flags & SMNT_REMOUNT)
774 linux_flags |= MS_REMOUNT;
775 if (flags & SMNT_RDONLY)
776 linux_flags |= MS_RDONLY;
777 if (flags & SMNT_NOSUID)
778 linux_flags |= MS_NOSUID;
779
780 dir_page = getname(dir);
781 ret = PTR_ERR(dir_page);
782 if (IS_ERR(dir_page))
783 goto out;
784
785 type_page = getname(type);
786 ret = PTR_ERR(type_page);
787 if (IS_ERR(type_page))
788 goto out1;
789
790 if (strcmp(type_page, "ext2") == 0) {
791 dev_fname = getname(data);
792 } else if (strcmp(type_page, "iso9660") == 0) {
793 dev_fname = getname(data);
794 } else if (strcmp(type_page, "minix") == 0) {
795 dev_fname = getname(data);
796 } else if (strcmp(type_page, "nfs") == 0) {
797 ret = sunos_nfs_mount (dir_page, flags, data);
798 goto out2;
799 } else if (strcmp(type_page, "ufs") == 0) {
800 printk("Warning: UFS filesystem mounts unsupported.\n");
801 ret = -ENODEV;
802 goto out2;
803 } else if (strcmp(type_page, "proc")) {
804 ret = -ENODEV;
805 goto out2;
806 }
807 ret = PTR_ERR(dev_fname);
808 if (IS_ERR(dev_fname))
809 goto out2;
810 ret = do_mount(dev_fname, dir_page, type_page, linux_flags, NULL);
811 if (dev_fname)
812 putname(dev_fname);
813out2:
814 putname(type_page);
815out1:
816 putname(dir_page);
817out:
818 unlock_kernel();
819 return ret;
820}
821
822
823asmlinkage int sunos_setpgrp(pid_t pid, pid_t pgid)
824{
825 int ret;
826
827 /* So stupid... */
828 if ((!pid || pid == current->pid) &&
829 !pgid) {
830 sys_setsid();
831 ret = 0;
832 } else {
833 ret = sys_setpgid(pid, pgid);
834 }
835 return ret;
836}
837
838/* So stupid... */
839asmlinkage int sunos_wait4(pid_t pid, unsigned int __user *stat_addr,
840 int options, struct rusage __user*ru)
841{
842 int ret;
843
844 ret = sys_wait4((pid ? pid : -1), stat_addr, options, ru);
845 return ret;
846}
847
848extern int kill_pg(int, int, int);
849asmlinkage int sunos_killpg(int pgrp, int sig)
850{
851 int ret;
852
853 lock_kernel();
854 ret = kill_pg(pgrp, sig, 0);
855 unlock_kernel();
856 return ret;
857}
858
859asmlinkage int sunos_audit(void)
860{
861 lock_kernel();
862 printk ("sys_audit\n");
863 unlock_kernel();
864 return -1;
865}
866
867asmlinkage unsigned long sunos_gethostid(void)
868{
869 unsigned long ret;
870
871 lock_kernel();
872 ret = ((unsigned long)idprom->id_machtype << 24) |
873 (unsigned long)idprom->id_sernum;
874 unlock_kernel();
875 return ret;
876}
877
878/* sysconf options, for SunOS compatibility */
879#define _SC_ARG_MAX 1
880#define _SC_CHILD_MAX 2
881#define _SC_CLK_TCK 3
882#define _SC_NGROUPS_MAX 4
883#define _SC_OPEN_MAX 5
884#define _SC_JOB_CONTROL 6
885#define _SC_SAVED_IDS 7
886#define _SC_VERSION 8
887
888asmlinkage long sunos_sysconf (int name)
889{
890 long ret;
891
892 switch (name){
893 case _SC_ARG_MAX:
894 ret = ARG_MAX;
895 break;
896 case _SC_CHILD_MAX:
897 ret = CHILD_MAX;
898 break;
899 case _SC_CLK_TCK:
900 ret = HZ;
901 break;
902 case _SC_NGROUPS_MAX:
903 ret = NGROUPS_MAX;
904 break;
905 case _SC_OPEN_MAX:
906 ret = OPEN_MAX;
907 break;
908 case _SC_JOB_CONTROL:
909 ret = 1; /* yes, we do support job control */
910 break;
911 case _SC_SAVED_IDS:
912 ret = 1; /* yes, we do support saved uids */
913 break;
914 case _SC_VERSION:
915 /* mhm, POSIX_VERSION is in /usr/include/unistd.h
916 * should it go on /usr/include/linux?
917 */
918 ret = 199009L;
919 break;
920 default:
921 ret = -1;
922 break;
923 };
924 return ret;
925}
926
927asmlinkage int sunos_semsys(int op, unsigned long arg1, unsigned long arg2,
928 unsigned long arg3, void *ptr)
929{
930 union semun arg4;
931 int ret;
932
933 switch (op) {
934 case 0:
935 /* Most arguments match on a 1:1 basis but cmd doesn't */
936 switch(arg3) {
937 case 4:
938 arg3=GETPID; break;
939 case 5:
940 arg3=GETVAL; break;
941 case 6:
942 arg3=GETALL; break;
943 case 3:
944 arg3=GETNCNT; break;
945 case 7:
946 arg3=GETZCNT; break;
947 case 8:
948 arg3=SETVAL; break;
949 case 9:
950 arg3=SETALL; break;
951 }
952 /* sys_semctl(): */
953 /* value to modify semaphore to */
954 arg4.__pad = (void __user *) ptr;
955 ret = sys_semctl((int)arg1, (int)arg2, (int)arg3, arg4 );
956 break;
957 case 1:
958 /* sys_semget(): */
959 ret = sys_semget((key_t)arg1, (int)arg2, (int)arg3);
960 break;
961 case 2:
962 /* sys_semop(): */
963 ret = sys_semop((int)arg1, (struct sembuf __user *)arg2, (unsigned)arg3);
964 break;
965 default:
966 ret = -EINVAL;
967 break;
968 };
969 return ret;
970}
971
972asmlinkage int sunos_msgsys(int op, unsigned long arg1, unsigned long arg2,
973 unsigned long arg3, unsigned long arg4)
974{
975 struct sparc_stackf *sp;
976 unsigned long arg5;
977 int rval;
978
979 switch(op) {
980 case 0:
981 rval = sys_msgget((key_t)arg1, (int)arg2);
982 break;
983 case 1:
984 rval = sys_msgctl((int)arg1, (int)arg2,
985 (struct msqid_ds __user *)arg3);
986 break;
987 case 2:
988 lock_kernel();
989 sp = (struct sparc_stackf *)current->thread.kregs->u_regs[UREG_FP];
990 arg5 = sp->xxargs[0];
991 unlock_kernel();
992 rval = sys_msgrcv((int)arg1, (struct msgbuf __user *)arg2,
993 (size_t)arg3, (long)arg4, (int)arg5);
994 break;
995 case 3:
996 rval = sys_msgsnd((int)arg1, (struct msgbuf __user *)arg2,
997 (size_t)arg3, (int)arg4);
998 break;
999 default:
1000 rval = -EINVAL;
1001 break;
1002 }
1003 return rval;
1004}
1005
1006asmlinkage int sunos_shmsys(int op, unsigned long arg1, unsigned long arg2,
1007 unsigned long arg3)
1008{
1009 unsigned long raddr;
1010 int rval;
1011
1012 switch(op) {
1013 case 0:
1014 /* do_shmat(): attach a shared memory area */
1015 rval = do_shmat((int)arg1,(char __user *)arg2,(int)arg3,&raddr);
1016 if (!rval)
1017 rval = (int) raddr;
1018 break;
1019 case 1:
1020 /* sys_shmctl(): modify shared memory area attr. */
1021 rval = sys_shmctl((int)arg1,(int)arg2,(struct shmid_ds __user *)arg3);
1022 break;
1023 case 2:
1024 /* sys_shmdt(): detach a shared memory area */
1025 rval = sys_shmdt((char __user *)arg1);
1026 break;
1027 case 3:
1028 /* sys_shmget(): get a shared memory area */
1029 rval = sys_shmget((key_t)arg1,(int)arg2,(int)arg3);
1030 break;
1031 default:
1032 rval = -EINVAL;
1033 break;
1034 };
1035 return rval;
1036}
1037
1038#define SUNOS_EWOULDBLOCK 35
1039
1040/* see the sunos man page read(2v) for an explanation
1041 of this garbage. We use O_NDELAY to mark
1042 file descriptors that have been set non-blocking
1043 using 4.2BSD style calls. (tridge) */
1044
1045static inline int check_nonblock(int ret, int fd)
1046{
1047 if (ret == -EAGAIN) {
1048 struct file * file = fget(fd);
1049 if (file) {
1050 if (file->f_flags & O_NDELAY)
1051 ret = -SUNOS_EWOULDBLOCK;
1052 fput(file);
1053 }
1054 }
1055 return ret;
1056}
1057
1058asmlinkage int sunos_read(unsigned int fd, char __user *buf, int count)
1059{
1060 int ret;
1061
1062 ret = check_nonblock(sys_read(fd,buf,count),fd);
1063 return ret;
1064}
1065
1066asmlinkage int sunos_readv(unsigned long fd, const struct iovec __user *vector,
1067 long count)
1068{
1069 int ret;
1070
1071 ret = check_nonblock(sys_readv(fd,vector,count),fd);
1072 return ret;
1073}
1074
1075asmlinkage int sunos_write(unsigned int fd, char __user *buf, int count)
1076{
1077 int ret;
1078
1079 ret = check_nonblock(sys_write(fd,buf,count),fd);
1080 return ret;
1081}
1082
1083asmlinkage int sunos_writev(unsigned long fd,
1084 const struct iovec __user *vector, long count)
1085{
1086 int ret;
1087
1088 ret = check_nonblock(sys_writev(fd,vector,count),fd);
1089 return ret;
1090}
1091
1092asmlinkage int sunos_recv(int fd, void __user *ubuf, int size, unsigned flags)
1093{
1094 int ret;
1095
1096 ret = check_nonblock(sys_recv(fd,ubuf,size,flags),fd);
1097 return ret;
1098}
1099
1100asmlinkage int sunos_send(int fd, void __user *buff, int len, unsigned flags)
1101{
1102 int ret;
1103
1104 ret = check_nonblock(sys_send(fd,buff,len,flags),fd);
1105 return ret;
1106}
1107
1108asmlinkage int sunos_accept(int fd, struct sockaddr __user *sa,
1109 int __user *addrlen)
1110{
1111 int ret;
1112
1113 while (1) {
1114 ret = check_nonblock(sys_accept(fd,sa,addrlen),fd);
1115 if (ret != -ENETUNREACH && ret != -EHOSTUNREACH)
1116 break;
1117 }
1118
1119 return ret;
1120}
1121
1122#define SUNOS_SV_INTERRUPT 2
1123
1124asmlinkage int
1125sunos_sigaction(int sig, const struct old_sigaction __user *act,
1126 struct old_sigaction __user *oact)
1127{
1128 struct k_sigaction new_ka, old_ka;
1129 int ret;
1130
1131 if (act) {
1132 old_sigset_t mask;
1133
1134 if (!access_ok(VERIFY_READ, act, sizeof(*act)) ||
1135 __get_user(new_ka.sa.sa_handler, &act->sa_handler) ||
1136 __get_user(new_ka.sa.sa_flags, &act->sa_flags))
1137 return -EFAULT;
1138 __get_user(mask, &act->sa_mask);
1139 new_ka.sa.sa_restorer = NULL;
1140 new_ka.ka_restorer = NULL;
1141 siginitset(&new_ka.sa.sa_mask, mask);
1142 new_ka.sa.sa_flags ^= SUNOS_SV_INTERRUPT;
1143 }
1144
1145 ret = do_sigaction(sig, act ? &new_ka : NULL, oact ? &old_ka : NULL);
1146
1147 if (!ret && oact) {
1148 /* In the clone() case we could copy half consistent
1149 * state to the user, however this could sleep and
1150 * deadlock us if we held the signal lock on SMP. So for
1151 * now I take the easy way out and do no locking.
1152 * But then again we don't support SunOS lwp's anyways ;-)
1153 */
1154 old_ka.sa.sa_flags ^= SUNOS_SV_INTERRUPT;
1155 if (!access_ok(VERIFY_WRITE, oact, sizeof(*oact)) ||
1156 __put_user(old_ka.sa.sa_handler, &oact->sa_handler) ||
1157 __put_user(old_ka.sa.sa_flags, &oact->sa_flags))
1158 return -EFAULT;
1159 __put_user(old_ka.sa.sa_mask.sig[0], &oact->sa_mask);
1160 }
1161
1162 return ret;
1163}
1164
1165
1166asmlinkage int sunos_setsockopt(int fd, int level, int optname,
1167 char __user *optval, int optlen)
1168{
1169 int tr_opt = optname;
1170 int ret;
1171
1172 if (level == SOL_IP) {
1173 /* Multicast socketopts (ttl, membership) */
1174 if (tr_opt >=2 && tr_opt <= 6)
1175 tr_opt += 30;
1176 }
1177 ret = sys_setsockopt(fd, level, tr_opt, optval, optlen);
1178 return ret;
1179}
1180
1181asmlinkage int sunos_getsockopt(int fd, int level, int optname,
1182 char __user *optval, int __user *optlen)
1183{
1184 int tr_opt = optname;
1185 int ret;
1186
1187 if (level == SOL_IP) {
1188 /* Multicast socketopts (ttl, membership) */
1189 if (tr_opt >=2 && tr_opt <= 6)
1190 tr_opt += 30;
1191 }
1192 ret = sys_getsockopt(fd, level, tr_opt, optval, optlen);
1193 return ret;
1194}