Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / arch / mips / kernel / sysirix.c
blob8cf63c8c04b5fba0ca0d4f1daba9af0714285ead
1 /*
2 * sysirix.c: IRIX system call emulation.
4 * Copyright (C) 1996 David S. Miller
5 * Copyright (C) 1997 Miguel de Icaza
6 * Copyright (C) 1997, 1998, 1999, 2000 Ralf Baechle
7 */
8 #include <linux/kernel.h>
9 #include <linux/sched.h>
10 #include <linux/binfmts.h>
11 #include <linux/capability.h>
12 #include <linux/highuid.h>
13 #include <linux/pagemap.h>
14 #include <linux/mm.h>
15 #include <linux/mman.h>
16 #include <linux/slab.h>
17 #include <linux/swap.h>
18 #include <linux/errno.h>
19 #include <linux/time.h>
20 #include <linux/timex.h>
21 #include <linux/times.h>
22 #include <linux/elf.h>
23 #include <linux/msg.h>
24 #include <linux/shm.h>
25 #include <linux/smp.h>
26 #include <linux/smp_lock.h>
27 #include <linux/utsname.h>
28 #include <linux/file.h>
29 #include <linux/vfs.h>
30 #include <linux/namei.h>
31 #include <linux/socket.h>
32 #include <linux/security.h>
33 #include <linux/syscalls.h>
34 #include <linux/resource.h>
36 #include <asm/ptrace.h>
37 #include <asm/page.h>
38 #include <asm/uaccess.h>
39 #include <asm/inventory.h>
41 /* 2,191 lines of complete and utter shit coming up... */
43 extern int max_threads;
45 /* The sysmp commands supported thus far. */
46 #define MP_NPROCS 1 /* # processor in complex */
47 #define MP_NAPROCS 2 /* # active processors in complex */
48 #define MP_PGSIZE 14 /* Return system page size in v1. */
50 asmlinkage int irix_sysmp(struct pt_regs *regs)
52 unsigned long cmd;
53 int base = 0;
54 int error = 0;
56 if(regs->regs[2] == 1000)
57 base = 1;
58 cmd = regs->regs[base + 4];
59 switch(cmd) {
60 case MP_PGSIZE:
61 error = PAGE_SIZE;
62 break;
63 case MP_NPROCS:
64 case MP_NAPROCS:
65 error = num_online_cpus();
66 break;
67 default:
68 printk("SYSMP[%s:%d]: Unsupported opcode %d\n",
69 current->comm, current->pid, (int)cmd);
70 error = -EINVAL;
71 break;
74 return error;
77 /* The prctl commands. */
78 #define PR_MAXPROCS 1 /* Tasks/user. */
79 #define PR_ISBLOCKED 2 /* If blocked, return 1. */
80 #define PR_SETSTACKSIZE 3 /* Set largest task stack size. */
81 #define PR_GETSTACKSIZE 4 /* Get largest task stack size. */
82 #define PR_MAXPPROCS 5 /* Num parallel tasks. */
83 #define PR_UNBLKONEXEC 6 /* When task exec/exit's, unblock. */
84 #define PR_SETEXITSIG 8 /* When task exit's, set signal. */
85 #define PR_RESIDENT 9 /* Make task unswappable. */
86 #define PR_ATTACHADDR 10 /* (Re-)Connect a vma to a task. */
87 #define PR_DETACHADDR 11 /* Disconnect a vma from a task. */
88 #define PR_TERMCHILD 12 /* Kill child if the parent dies. */
89 #define PR_GETSHMASK 13 /* Get the sproc() share mask. */
90 #define PR_GETNSHARE 14 /* Number of share group members. */
91 #define PR_COREPID 15 /* Add task pid to name when it core. */
92 #define PR_ATTACHADDRPERM 16 /* (Re-)Connect vma, with specified prot. */
93 #define PR_PTHREADEXIT 17 /* Kill a pthread, only for IRIX 6.[234] */
95 asmlinkage int irix_prctl(unsigned option, ...)
97 va_list args;
98 int error = 0;
100 va_start(args, option);
101 switch (option) {
102 case PR_MAXPROCS:
103 printk("irix_prctl[%s:%d]: Wants PR_MAXPROCS\n",
104 current->comm, current->pid);
105 error = max_threads;
106 break;
108 case PR_ISBLOCKED: {
109 struct task_struct *task;
111 printk("irix_prctl[%s:%d]: Wants PR_ISBLOCKED\n",
112 current->comm, current->pid);
113 read_lock(&tasklist_lock);
114 <<<<<<< HEAD:arch/mips/kernel/sysirix.c
115 task = find_task_by_pid(va_arg(args, pid_t));
116 =======
117 task = find_task_by_vpid(va_arg(args, pid_t));
118 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/mips/kernel/sysirix.c
119 error = -ESRCH;
120 if (error)
121 error = (task->run_list.next != NULL);
122 read_unlock(&tasklist_lock);
123 /* Can _your_ OS find this out that fast? */
124 break;
127 case PR_SETSTACKSIZE: {
128 long value = va_arg(args, long);
130 printk("irix_prctl[%s:%d]: Wants PR_SETSTACKSIZE<%08lx>\n",
131 current->comm, current->pid, (unsigned long) value);
132 if (value > RLIM_INFINITY)
133 value = RLIM_INFINITY;
134 if (capable(CAP_SYS_ADMIN)) {
135 task_lock(current->group_leader);
136 current->signal->rlim[RLIMIT_STACK].rlim_max =
137 current->signal->rlim[RLIMIT_STACK].rlim_cur = value;
138 task_unlock(current->group_leader);
139 error = value;
140 break;
142 task_lock(current->group_leader);
143 if (value > current->signal->rlim[RLIMIT_STACK].rlim_max) {
144 error = -EINVAL;
145 task_unlock(current->group_leader);
146 break;
148 current->signal->rlim[RLIMIT_STACK].rlim_cur = value;
149 task_unlock(current->group_leader);
150 error = value;
151 break;
154 case PR_GETSTACKSIZE:
155 printk("irix_prctl[%s:%d]: Wants PR_GETSTACKSIZE\n",
156 current->comm, current->pid);
157 error = current->signal->rlim[RLIMIT_STACK].rlim_cur;
158 break;
160 case PR_MAXPPROCS:
161 printk("irix_prctl[%s:%d]: Wants PR_MAXPROCS\n",
162 current->comm, current->pid);
163 error = 1;
164 break;
166 case PR_UNBLKONEXEC:
167 printk("irix_prctl[%s:%d]: Wants PR_UNBLKONEXEC\n",
168 current->comm, current->pid);
169 error = -EINVAL;
170 break;
172 case PR_SETEXITSIG:
173 printk("irix_prctl[%s:%d]: Wants PR_SETEXITSIG\n",
174 current->comm, current->pid);
176 /* We can probably play some game where we set the task
177 * exit_code to some non-zero value when this is requested,
178 * and check whether exit_code is already set in do_exit().
180 error = -EINVAL;
181 break;
183 case PR_RESIDENT:
184 printk("irix_prctl[%s:%d]: Wants PR_RESIDENT\n",
185 current->comm, current->pid);
186 error = 0; /* Compatibility indeed. */
187 break;
189 case PR_ATTACHADDR:
190 printk("irix_prctl[%s:%d]: Wants PR_ATTACHADDR\n",
191 current->comm, current->pid);
192 error = -EINVAL;
193 break;
195 case PR_DETACHADDR:
196 printk("irix_prctl[%s:%d]: Wants PR_DETACHADDR\n",
197 current->comm, current->pid);
198 error = -EINVAL;
199 break;
201 case PR_TERMCHILD:
202 printk("irix_prctl[%s:%d]: Wants PR_TERMCHILD\n",
203 current->comm, current->pid);
204 error = -EINVAL;
205 break;
207 case PR_GETSHMASK:
208 printk("irix_prctl[%s:%d]: Wants PR_GETSHMASK\n",
209 current->comm, current->pid);
210 error = -EINVAL; /* Until I have the sproc() stuff in. */
211 break;
213 case PR_GETNSHARE:
214 error = 0; /* Until I have the sproc() stuff in. */
215 break;
217 case PR_COREPID:
218 printk("irix_prctl[%s:%d]: Wants PR_COREPID\n",
219 current->comm, current->pid);
220 error = -EINVAL;
221 break;
223 case PR_ATTACHADDRPERM:
224 printk("irix_prctl[%s:%d]: Wants PR_ATTACHADDRPERM\n",
225 current->comm, current->pid);
226 error = -EINVAL;
227 break;
229 default:
230 printk("irix_prctl[%s:%d]: Non-existant opcode %d\n",
231 current->comm, current->pid, option);
232 error = -EINVAL;
233 break;
235 va_end(args);
237 return error;
240 #undef DEBUG_PROCGRPS
242 extern unsigned long irix_mapelf(int fd, struct elf_phdr __user *user_phdrp, int cnt);
243 extern char *prom_getenv(char *name);
244 extern long prom_setenv(char *name, char *value);
246 /* The syssgi commands supported thus far. */
247 #define SGI_SYSID 1 /* Return unique per-machine identifier. */
248 #define SGI_INVENT 5 /* Fetch inventory */
249 # define SGI_INV_SIZEOF 1
250 # define SGI_INV_READ 2
251 #define SGI_RDNAME 6 /* Return string name of a process. */
252 #define SGI_SETNVRAM 8 /* Set PROM variable. */
253 #define SGI_GETNVRAM 9 /* Get PROM variable. */
254 #define SGI_SETPGID 21 /* Set process group id. */
255 #define SGI_SYSCONF 22 /* POSIX sysconf garbage. */
256 #define SGI_PATHCONF 24 /* POSIX sysconf garbage. */
257 #define SGI_SETGROUPS 40 /* POSIX sysconf garbage. */
258 #define SGI_GETGROUPS 41 /* POSIX sysconf garbage. */
259 #define SGI_RUSAGE 56 /* BSD style rusage(). */
260 #define SGI_SSYNC 62 /* Synchronous fs sync. */
261 #define SGI_GETSID 65 /* SysVr4 get session id. */
262 #define SGI_ELFMAP 68 /* Map an elf image. */
263 #define SGI_TOSSTSAVE 108 /* Toss saved vma's. */
264 #define SGI_FP_BCOPY 129 /* Should FPU bcopy be used on this machine? */
265 #define SGI_PHYSP 1011 /* Translate virtual into physical page. */
267 asmlinkage int irix_syssgi(struct pt_regs *regs)
269 unsigned long cmd;
270 int retval, base = 0;
272 if (regs->regs[2] == 1000)
273 base = 1;
275 cmd = regs->regs[base + 4];
276 switch(cmd) {
277 case SGI_SYSID: {
278 char __user *buf = (char __user *) regs->regs[base + 5];
280 /* XXX Use ethernet addr.... */
281 retval = clear_user(buf, 64) ? -EFAULT : 0;
282 break;
284 #if 0
285 case SGI_RDNAME: {
286 int pid = (int) regs->regs[base + 5];
287 char __user *buf = (char __user *) regs->regs[base + 6];
288 struct task_struct *p;
289 char tcomm[sizeof(current->comm)];
291 read_lock(&tasklist_lock);
292 p = find_task_by_pid(pid);
293 if (!p) {
294 read_unlock(&tasklist_lock);
295 retval = -ESRCH;
296 break;
298 get_task_comm(tcomm, p);
299 read_unlock(&tasklist_lock);
301 /* XXX Need to check sizes. */
302 retval = copy_to_user(buf, tcomm, sizeof(tcomm)) ? -EFAULT : 0;
303 break;
306 case SGI_GETNVRAM: {
307 char __user *name = (char __user *) regs->regs[base+5];
308 char __user *buf = (char __user *) regs->regs[base+6];
309 char *value;
310 return -EINVAL; /* til I fix it */
311 value = prom_getenv(name); /* PROM lock? */
312 if (!value) {
313 retval = -EINVAL;
314 break;
316 /* Do I strlen() for the length? */
317 retval = copy_to_user(buf, value, 128) ? -EFAULT : 0;
318 break;
321 case SGI_SETNVRAM: {
322 char __user *name = (char __user *) regs->regs[base+5];
323 char __user *value = (char __user *) regs->regs[base+6];
324 return -EINVAL; /* til I fix it */
325 retval = prom_setenv(name, value);
326 /* XXX make sure retval conforms to syssgi(2) */
327 printk("[%s:%d] setnvram(\"%s\", \"%s\"): retval %d",
328 current->comm, current->pid, name, value, retval);
329 /* if (retval == PROM_ENOENT)
330 retval = -ENOENT; */
331 break;
333 #endif
335 case SGI_SETPGID: {
336 #ifdef DEBUG_PROCGRPS
337 printk("[%s:%d] setpgid(%d, %d) ",
338 current->comm, current->pid,
339 (int) regs->regs[base + 5], (int)regs->regs[base + 6]);
340 #endif
341 retval = sys_setpgid(regs->regs[base + 5], regs->regs[base + 6]);
343 #ifdef DEBUG_PROCGRPS
344 printk("retval=%d\n", retval);
345 #endif
348 case SGI_SYSCONF: {
349 switch(regs->regs[base + 5]) {
350 case 1:
351 retval = (MAX_ARG_PAGES >> 4); /* XXX estimate... */
352 goto out;
353 case 2:
354 retval = max_threads;
355 goto out;
356 case 3:
357 retval = HZ;
358 goto out;
359 case 4:
360 retval = NGROUPS_MAX;
361 goto out;
362 case 5:
363 retval = sysctl_nr_open;
364 goto out;
365 case 6:
366 retval = 1;
367 goto out;
368 case 7:
369 retval = 1;
370 goto out;
371 case 8:
372 retval = 199009;
373 goto out;
374 case 11:
375 retval = PAGE_SIZE;
376 goto out;
377 case 12:
378 retval = 4;
379 goto out;
380 case 25:
381 case 26:
382 case 27:
383 case 28:
384 case 29:
385 case 30:
386 retval = 0;
387 goto out;
388 case 31:
389 retval = 32;
390 goto out;
391 default:
392 retval = -EINVAL;
393 goto out;
397 case SGI_SETGROUPS:
398 retval = sys_setgroups((int) regs->regs[base + 5],
399 (gid_t __user *) regs->regs[base + 6]);
400 break;
402 case SGI_GETGROUPS:
403 retval = sys_getgroups((int) regs->regs[base + 5],
404 (gid_t __user *) regs->regs[base + 6]);
405 break;
407 case SGI_RUSAGE: {
408 struct rusage __user *ru = (struct rusage __user *) regs->regs[base + 6];
410 switch((int) regs->regs[base + 5]) {
411 case 0:
412 /* rusage self */
413 retval = getrusage(current, RUSAGE_SELF, ru);
414 goto out;
416 case -1:
417 /* rusage children */
418 retval = getrusage(current, RUSAGE_CHILDREN, ru);
419 goto out;
421 default:
422 retval = -EINVAL;
423 goto out;
427 case SGI_SSYNC:
428 sys_sync();
429 retval = 0;
430 break;
432 case SGI_GETSID:
433 #ifdef DEBUG_PROCGRPS
434 printk("[%s:%d] getsid(%d) ", current->comm, current->pid,
435 (int) regs->regs[base + 5]);
436 #endif
437 retval = sys_getsid(regs->regs[base + 5]);
438 #ifdef DEBUG_PROCGRPS
439 printk("retval=%d\n", retval);
440 #endif
441 break;
443 case SGI_ELFMAP:
444 retval = irix_mapelf((int) regs->regs[base + 5],
445 (struct elf_phdr __user *) regs->regs[base + 6],
446 (int) regs->regs[base + 7]);
447 break;
449 case SGI_TOSSTSAVE:
450 /* XXX We don't need to do anything? */
451 retval = 0;
452 break;
454 case SGI_FP_BCOPY:
455 retval = 0;
456 break;
458 case SGI_PHYSP: {
459 unsigned long addr = regs->regs[base + 5];
460 int __user *pageno = (int __user *) (regs->regs[base + 6]);
461 struct mm_struct *mm = current->mm;
462 pgd_t *pgdp;
463 pud_t *pudp;
464 pmd_t *pmdp;
465 pte_t *ptep;
467 down_read(&mm->mmap_sem);
468 pgdp = pgd_offset(mm, addr);
469 pudp = pud_offset(pgdp, addr);
470 pmdp = pmd_offset(pudp, addr);
471 ptep = pte_offset(pmdp, addr);
472 retval = -EINVAL;
473 if (ptep) {
474 pte_t pte = *ptep;
476 if (pte_val(pte) & (_PAGE_VALID | _PAGE_PRESENT)) {
477 /* b0rked on 64-bit */
478 retval = put_user((pte_val(pte) & PAGE_MASK) >>
479 PAGE_SHIFT, pageno);
482 up_read(&mm->mmap_sem);
483 break;
486 case SGI_INVENT: {
487 int arg1 = (int) regs->regs [base + 5];
488 void __user *buffer = (void __user *) regs->regs [base + 6];
489 int count = (int) regs->regs [base + 7];
491 switch (arg1) {
492 case SGI_INV_SIZEOF:
493 retval = sizeof(inventory_t);
494 break;
495 case SGI_INV_READ:
496 retval = dump_inventory_to_user(buffer, count);
497 break;
498 default:
499 retval = -EINVAL;
501 break;
504 default:
505 printk("irix_syssgi: Unsupported command %d\n", (int)cmd);
506 retval = -EINVAL;
507 break;
510 out:
511 return retval;
514 asmlinkage int irix_gtime(struct pt_regs *regs)
516 return get_seconds();
520 * IRIX is completely broken... it returns 0 on success, otherwise
521 * ENOMEM.
523 asmlinkage int irix_brk(unsigned long brk)
525 unsigned long rlim;
526 unsigned long newbrk, oldbrk;
527 struct mm_struct *mm = current->mm;
528 int ret;
530 down_write(&mm->mmap_sem);
531 if (brk < mm->end_code) {
532 ret = -ENOMEM;
533 goto out;
536 newbrk = PAGE_ALIGN(brk);
537 oldbrk = PAGE_ALIGN(mm->brk);
538 if (oldbrk == newbrk) {
539 mm->brk = brk;
540 ret = 0;
541 goto out;
545 * Always allow shrinking brk
547 if (brk <= mm->brk) {
548 mm->brk = brk;
549 do_munmap(mm, newbrk, oldbrk-newbrk);
550 ret = 0;
551 goto out;
554 * Check against rlimit and stack..
556 rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
557 if (rlim >= RLIM_INFINITY)
558 rlim = ~0;
559 if (brk - mm->end_code > rlim) {
560 ret = -ENOMEM;
561 goto out;
565 * Check against existing mmap mappings.
567 if (find_vma_intersection(mm, oldbrk, newbrk+PAGE_SIZE)) {
568 ret = -ENOMEM;
569 goto out;
573 * Ok, looks good - let it rip.
575 if (do_brk(oldbrk, newbrk-oldbrk) != oldbrk) {
576 ret = -ENOMEM;
577 goto out;
579 mm->brk = brk;
580 ret = 0;
582 out:
583 up_write(&mm->mmap_sem);
584 return ret;
587 asmlinkage int irix_getpid(struct pt_regs *regs)
589 regs->regs[3] = task_pid_vnr(current->real_parent);
590 return task_pid_vnr(current);
593 asmlinkage int irix_getuid(struct pt_regs *regs)
595 regs->regs[3] = current->euid;
596 return current->uid;
599 asmlinkage int irix_getgid(struct pt_regs *regs)
601 regs->regs[3] = current->egid;
602 return current->gid;
605 asmlinkage int irix_stime(int value)
607 int err;
608 struct timespec tv;
610 tv.tv_sec = value;
611 tv.tv_nsec = 0;
612 err = security_settime(&tv, NULL);
613 if (err)
614 return err;
616 write_seqlock_irq(&xtime_lock);
617 xtime.tv_sec = value;
618 xtime.tv_nsec = 0;
619 ntp_clear();
620 write_sequnlock_irq(&xtime_lock);
622 return 0;
625 static inline void jiffiestotv(unsigned long jiffies, struct timeval *value)
627 value->tv_usec = (jiffies % HZ) * (1000000 / HZ);
628 value->tv_sec = jiffies / HZ;
631 static inline void getitimer_real(struct itimerval *value)
633 register unsigned long val, interval;
635 interval = current->it_real_incr;
636 val = 0;
637 if (del_timer(&current->real_timer)) {
638 unsigned long now = jiffies;
639 val = current->real_timer.expires;
640 add_timer(&current->real_timer);
641 /* look out for negative/zero itimer.. */
642 if (val <= now)
643 val = now+1;
644 val -= now;
646 jiffiestotv(val, &value->it_value);
647 jiffiestotv(interval, &value->it_interval);
650 asmlinkage unsigned int irix_alarm(unsigned int seconds)
652 return alarm_setitimer(seconds);
655 asmlinkage int irix_pause(void)
657 current->state = TASK_INTERRUPTIBLE;
658 schedule();
660 return -EINTR;
663 /* XXX need more than this... */
664 asmlinkage int irix_mount(char __user *dev_name, char __user *dir_name,
665 unsigned long flags, char __user *type, void __user *data, int datalen)
667 printk("[%s:%d] irix_mount(%p,%p,%08lx,%p,%p,%d)\n",
668 current->comm, current->pid,
669 dev_name, dir_name, flags, type, data, datalen);
671 return sys_mount(dev_name, dir_name, type, flags, data);
674 struct irix_statfs {
675 short f_type;
676 long f_bsize, f_frsize, f_blocks, f_bfree, f_files, f_ffree;
677 char f_fname[6], f_fpack[6];
680 asmlinkage int irix_statfs(const char __user *path,
681 struct irix_statfs __user *buf, int len, int fs_type)
683 struct nameidata nd;
684 struct kstatfs kbuf;
685 int error, i;
687 /* We don't support this feature yet. */
688 if (fs_type) {
689 error = -EINVAL;
690 goto out;
692 if (!access_ok(VERIFY_WRITE, buf, sizeof(struct irix_statfs))) {
693 error = -EFAULT;
694 goto out;
697 error = user_path_walk(path, &nd);
698 if (error)
699 goto out;
701 error = vfs_statfs(nd.path.dentry, &kbuf);
702 if (error)
703 goto dput_and_out;
705 error = __put_user(kbuf.f_type, &buf->f_type);
706 error |= __put_user(kbuf.f_bsize, &buf->f_bsize);
707 error |= __put_user(kbuf.f_frsize, &buf->f_frsize);
708 error |= __put_user(kbuf.f_blocks, &buf->f_blocks);
709 error |= __put_user(kbuf.f_bfree, &buf->f_bfree);
710 error |= __put_user(kbuf.f_files, &buf->f_files);
711 error |= __put_user(kbuf.f_ffree, &buf->f_ffree);
712 for (i = 0; i < 6; i++) {
713 error |= __put_user(0, &buf->f_fname[i]);
714 error |= __put_user(0, &buf->f_fpack[i]);
717 dput_and_out:
718 path_put(&nd.path);
719 out:
720 return error;
723 asmlinkage int irix_fstatfs(unsigned int fd, struct irix_statfs __user *buf)
725 struct kstatfs kbuf;
726 struct file *file;
727 int error, i;
729 if (!access_ok(VERIFY_WRITE, buf, sizeof(struct irix_statfs))) {
730 error = -EFAULT;
731 goto out;
734 if (!(file = fget(fd))) {
735 error = -EBADF;
736 goto out;
739 error = vfs_statfs(file->f_path.dentry, &kbuf);
740 if (error)
741 goto out_f;
743 error = __put_user(kbuf.f_type, &buf->f_type);
744 error |= __put_user(kbuf.f_bsize, &buf->f_bsize);
745 error |= __put_user(kbuf.f_frsize, &buf->f_frsize);
746 error |= __put_user(kbuf.f_blocks, &buf->f_blocks);
747 error |= __put_user(kbuf.f_bfree, &buf->f_bfree);
748 error |= __put_user(kbuf.f_files, &buf->f_files);
749 error |= __put_user(kbuf.f_ffree, &buf->f_ffree);
751 for (i = 0; i < 6; i++) {
752 error |= __put_user(0, &buf->f_fname[i]);
753 error |= __put_user(0, &buf->f_fpack[i]);
756 out_f:
757 fput(file);
758 out:
759 return error;
762 asmlinkage int irix_setpgrp(int flags)
764 int error;
766 #ifdef DEBUG_PROCGRPS
767 printk("[%s:%d] setpgrp(%d) ", current->comm, current->pid, flags);
768 #endif
769 if(!flags)
770 error = task_pgrp_vnr(current);
771 else
772 error = sys_setsid();
773 #ifdef DEBUG_PROCGRPS
774 printk("returning %d\n", error);
775 #endif
777 return error;
780 asmlinkage int irix_times(struct tms __user *tbuf)
782 int err = 0;
784 if (tbuf) {
785 if (!access_ok(VERIFY_WRITE, tbuf, sizeof *tbuf))
786 return -EFAULT;
788 err = __put_user(current->utime, &tbuf->tms_utime);
789 err |= __put_user(current->stime, &tbuf->tms_stime);
790 err |= __put_user(current->signal->cutime, &tbuf->tms_cutime);
791 err |= __put_user(current->signal->cstime, &tbuf->tms_cstime);
794 return err;
797 asmlinkage int irix_exec(struct pt_regs *regs)
799 int error, base = 0;
800 char *filename;
802 if(regs->regs[2] == 1000)
803 base = 1;
804 filename = getname((char __user *) (long)regs->regs[base + 4]);
805 error = PTR_ERR(filename);
806 if (IS_ERR(filename))
807 return error;
809 error = do_execve(filename, (char __user * __user *) (long)regs->regs[base + 5],
810 NULL, regs);
811 putname(filename);
813 return error;
816 asmlinkage int irix_exece(struct pt_regs *regs)
818 int error, base = 0;
819 char *filename;
821 if (regs->regs[2] == 1000)
822 base = 1;
823 filename = getname((char __user *) (long)regs->regs[base + 4]);
824 error = PTR_ERR(filename);
825 if (IS_ERR(filename))
826 return error;
827 error = do_execve(filename, (char __user * __user *) (long)regs->regs[base + 5],
828 (char __user * __user *) (long)regs->regs[base + 6], regs);
829 putname(filename);
831 return error;
834 asmlinkage unsigned long irix_gethostid(void)
836 printk("[%s:%d]: irix_gethostid() called...\n",
837 current->comm, current->pid);
839 return -EINVAL;
842 asmlinkage unsigned long irix_sethostid(unsigned long val)
844 printk("[%s:%d]: irix_sethostid(%08lx) called...\n",
845 current->comm, current->pid, val);
847 return -EINVAL;
850 asmlinkage int irix_socket(int family, int type, int protocol)
852 switch(type) {
853 case 1:
854 type = SOCK_DGRAM;
855 break;
857 case 2:
858 type = SOCK_STREAM;
859 break;
861 case 3:
862 type = 9; /* Invalid... */
863 break;
865 case 4:
866 type = SOCK_RAW;
867 break;
869 case 5:
870 type = SOCK_RDM;
871 break;
873 case 6:
874 type = SOCK_SEQPACKET;
875 break;
877 default:
878 break;
881 return sys_socket(family, type, protocol);
884 asmlinkage int irix_getdomainname(char __user *name, int len)
886 int err;
888 down_read(&uts_sem);
889 if (len > __NEW_UTS_LEN)
890 len = __NEW_UTS_LEN;
891 err = copy_to_user(name, utsname()->domainname, len) ? -EFAULT : 0;
892 up_read(&uts_sem);
894 return err;
897 asmlinkage unsigned long irix_getpagesize(void)
899 return PAGE_SIZE;
902 asmlinkage int irix_msgsys(int opcode, unsigned long arg0, unsigned long arg1,
903 unsigned long arg2, unsigned long arg3,
904 unsigned long arg4)
906 switch (opcode) {
907 case 0:
908 return sys_msgget((key_t) arg0, (int) arg1);
909 case 1:
910 return sys_msgctl((int) arg0, (int) arg1,
911 (struct msqid_ds __user *)arg2);
912 case 2:
913 return sys_msgrcv((int) arg0, (struct msgbuf __user *) arg1,
914 (size_t) arg2, (long) arg3, (int) arg4);
915 case 3:
916 return sys_msgsnd((int) arg0, (struct msgbuf __user *) arg1,
917 (size_t) arg2, (int) arg3);
918 default:
919 return -EINVAL;
923 asmlinkage int irix_shmsys(int opcode, unsigned long arg0, unsigned long arg1,
924 unsigned long arg2, unsigned long arg3)
926 switch (opcode) {
927 case 0:
928 return do_shmat((int) arg0, (char __user *) arg1, (int) arg2,
929 (unsigned long *) arg3);
930 case 1:
931 return sys_shmctl((int)arg0, (int)arg1,
932 (struct shmid_ds __user *)arg2);
933 case 2:
934 return sys_shmdt((char __user *)arg0);
935 case 3:
936 return sys_shmget((key_t) arg0, (int) arg1, (int) arg2);
937 default:
938 return -EINVAL;
942 asmlinkage int irix_semsys(int opcode, unsigned long arg0, unsigned long arg1,
943 unsigned long arg2, int arg3)
945 switch (opcode) {
946 case 0:
947 return sys_semctl((int) arg0, (int) arg1, (int) arg2,
948 (union semun) arg3);
949 case 1:
950 return sys_semget((key_t) arg0, (int) arg1, (int) arg2);
951 case 2:
952 return sys_semop((int) arg0, (struct sembuf __user *)arg1,
953 (unsigned int) arg2);
954 default:
955 return -EINVAL;
959 static inline loff_t llseek(struct file *file, loff_t offset, int origin)
961 loff_t (*fn)(struct file *, loff_t, int);
962 loff_t retval;
964 fn = default_llseek;
965 if (file->f_op && file->f_op->llseek)
966 fn = file->f_op->llseek;
967 lock_kernel();
968 retval = fn(file, offset, origin);
969 unlock_kernel();
971 return retval;
974 asmlinkage int irix_lseek64(int fd, int _unused, int offhi, int offlow,
975 int origin)
977 struct file * file;
978 loff_t offset;
979 int retval;
981 retval = -EBADF;
982 file = fget(fd);
983 if (!file)
984 goto bad;
985 retval = -EINVAL;
986 if (origin > 2)
987 goto out_putf;
989 offset = llseek(file, ((loff_t) offhi << 32) | offlow, origin);
990 retval = (int) offset;
992 out_putf:
993 fput(file);
994 bad:
995 return retval;
998 asmlinkage int irix_sginap(int ticks)
1000 schedule_timeout_interruptible(ticks);
1001 return 0;
1004 asmlinkage int irix_sgikopt(char __user *istring, char __user *ostring, int len)
1006 return -EINVAL;
1009 asmlinkage int irix_gettimeofday(struct timeval __user *tv)
1011 time_t sec;
1012 long nsec, seq;
1013 int err;
1015 if (!access_ok(VERIFY_WRITE, tv, sizeof(struct timeval)))
1016 return -EFAULT;
1018 do {
1019 seq = read_seqbegin(&xtime_lock);
1020 sec = xtime.tv_sec;
1021 nsec = xtime.tv_nsec;
1022 } while (read_seqretry(&xtime_lock, seq));
1024 err = __put_user(sec, &tv->tv_sec);
1025 err |= __put_user((nsec / 1000), &tv->tv_usec);
1027 return err;
1030 #define IRIX_MAP_AUTOGROW 0x40
1032 asmlinkage unsigned long irix_mmap32(unsigned long addr, size_t len, int prot,
1033 int flags, int fd, off_t offset)
1035 struct file *file = NULL;
1036 unsigned long retval;
1038 if (!(flags & MAP_ANONYMOUS)) {
1039 if (!(file = fget(fd)))
1040 return -EBADF;
1042 /* Ok, bad taste hack follows, try to think in something else
1043 * when reading this. */
1044 if (flags & IRIX_MAP_AUTOGROW) {
1045 unsigned long old_pos;
1046 long max_size = offset + len;
1048 if (max_size > file->f_path.dentry->d_inode->i_size) {
1049 old_pos = sys_lseek(fd, max_size - 1, 0);
1050 sys_write(fd, (void __user *) "", 1);
1051 sys_lseek(fd, old_pos, 0);
1056 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
1058 down_write(&current->mm->mmap_sem);
1059 retval = do_mmap(file, addr, len, prot, flags, offset);
1060 up_write(&current->mm->mmap_sem);
1061 if (file)
1062 fput(file);
1064 return retval;
1067 asmlinkage int irix_madvise(unsigned long addr, int len, int behavior)
1069 printk("[%s:%d] Wheee.. irix_madvise(%08lx,%d,%d)\n",
1070 current->comm, current->pid, addr, len, behavior);
1072 return -EINVAL;
1075 asmlinkage int irix_pagelock(char __user *addr, int len, int op)
1077 printk("[%s:%d] Wheee.. irix_pagelock(%p,%d,%d)\n",
1078 current->comm, current->pid, addr, len, op);
1080 return -EINVAL;
1083 asmlinkage int irix_quotactl(struct pt_regs *regs)
1085 printk("[%s:%d] Wheee.. irix_quotactl()\n",
1086 current->comm, current->pid);
1088 return -EINVAL;
1091 asmlinkage int irix_BSDsetpgrp(int pid, int pgrp)
1093 int error;
1095 #ifdef DEBUG_PROCGRPS
1096 printk("[%s:%d] BSDsetpgrp(%d, %d) ", current->comm, current->pid,
1097 pid, pgrp);
1098 #endif
1099 if(!pid)
1100 pid = task_pid_vnr(current);
1102 /* Wheee, weird sysv thing... */
1103 if ((pgrp == 0) && (pid == task_pid_vnr(current)))
1104 error = sys_setsid();
1105 else
1106 error = sys_setpgid(pid, pgrp);
1108 #ifdef DEBUG_PROCGRPS
1109 printk("error = %d\n", error);
1110 #endif
1112 return error;
1115 asmlinkage int irix_systeminfo(int cmd, char __user *buf, int cnt)
1117 printk("[%s:%d] Wheee.. irix_systeminfo(%d,%p,%d)\n",
1118 current->comm, current->pid, cmd, buf, cnt);
1120 return -EINVAL;
1123 struct iuname {
1124 char sysname[257], nodename[257], release[257];
1125 char version[257], machine[257];
1126 char m_type[257], base_rel[257];
1127 char _unused0[257], _unused1[257], _unused2[257];
1128 char _unused3[257], _unused4[257], _unused5[257];
1131 asmlinkage int irix_uname(struct iuname __user *buf)
1133 down_read(&uts_sem);
1134 if (copy_from_user(utsname()->sysname, buf->sysname, 65)
1135 || copy_from_user(utsname()->nodename, buf->nodename, 65)
1136 || copy_from_user(utsname()->release, buf->release, 65)
1137 || copy_from_user(utsname()->version, buf->version, 65)
1138 || copy_from_user(utsname()->machine, buf->machine, 65)) {
1139 return -EFAULT;
1141 up_read(&uts_sem);
1143 return 1;
1146 #undef DEBUG_XSTAT
1148 static int irix_xstat32_xlate(struct kstat *stat, void __user *ubuf)
1150 struct xstat32 {
1151 u32 st_dev, st_pad1[3], st_ino, st_mode, st_nlink, st_uid, st_gid;
1152 u32 st_rdev, st_pad2[2], st_size, st_pad3;
1153 u32 st_atime0, st_atime1;
1154 u32 st_mtime0, st_mtime1;
1155 u32 st_ctime0, st_ctime1;
1156 u32 st_blksize, st_blocks;
1157 char st_fstype[16];
1158 u32 st_pad4[8];
1159 } ub;
1161 if (!sysv_valid_dev(stat->dev) || !sysv_valid_dev(stat->rdev))
1162 return -EOVERFLOW;
1163 ub.st_dev = sysv_encode_dev(stat->dev);
1164 ub.st_ino = stat->ino;
1165 ub.st_mode = stat->mode;
1166 ub.st_nlink = stat->nlink;
1167 SET_UID(ub.st_uid, stat->uid);
1168 SET_GID(ub.st_gid, stat->gid);
1169 ub.st_rdev = sysv_encode_dev(stat->rdev);
1170 #if BITS_PER_LONG == 32
1171 if (stat->size > MAX_NON_LFS)
1172 return -EOVERFLOW;
1173 #endif
1174 ub.st_size = stat->size;
1175 ub.st_atime0 = stat->atime.tv_sec;
1176 ub.st_atime1 = stat->atime.tv_nsec;
1177 ub.st_mtime0 = stat->mtime.tv_sec;
1178 ub.st_mtime1 = stat->atime.tv_nsec;
1179 ub.st_ctime0 = stat->ctime.tv_sec;
1180 ub.st_ctime1 = stat->atime.tv_nsec;
1181 ub.st_blksize = stat->blksize;
1182 ub.st_blocks = stat->blocks;
1183 strcpy(ub.st_fstype, "efs");
1185 return copy_to_user(ubuf, &ub, sizeof(ub)) ? -EFAULT : 0;
1188 static int irix_xstat64_xlate(struct kstat *stat, void __user *ubuf)
1190 struct xstat64 {
1191 u32 st_dev; s32 st_pad1[3];
1192 unsigned long long st_ino;
1193 u32 st_mode;
1194 u32 st_nlink; s32 st_uid; s32 st_gid; u32 st_rdev;
1195 s32 st_pad2[2];
1196 long long st_size;
1197 s32 st_pad3;
1198 struct { s32 tv_sec, tv_nsec; } st_atime, st_mtime, st_ctime;
1199 s32 st_blksize;
1200 long long st_blocks;
1201 char st_fstype[16];
1202 s32 st_pad4[8];
1203 } ks;
1205 if (!sysv_valid_dev(stat->dev) || !sysv_valid_dev(stat->rdev))
1206 return -EOVERFLOW;
1208 ks.st_dev = sysv_encode_dev(stat->dev);
1209 ks.st_pad1[0] = ks.st_pad1[1] = ks.st_pad1[2] = 0;
1210 ks.st_ino = (unsigned long long) stat->ino;
1211 ks.st_mode = (u32) stat->mode;
1212 ks.st_nlink = (u32) stat->nlink;
1213 ks.st_uid = (s32) stat->uid;
1214 ks.st_gid = (s32) stat->gid;
1215 ks.st_rdev = sysv_encode_dev(stat->rdev);
1216 ks.st_pad2[0] = ks.st_pad2[1] = 0;
1217 ks.st_size = (long long) stat->size;
1218 ks.st_pad3 = 0;
1220 /* XXX hackety hack... */
1221 ks.st_atime.tv_sec = (s32) stat->atime.tv_sec;
1222 ks.st_atime.tv_nsec = stat->atime.tv_nsec;
1223 ks.st_mtime.tv_sec = (s32) stat->mtime.tv_sec;
1224 ks.st_mtime.tv_nsec = stat->mtime.tv_nsec;
1225 ks.st_ctime.tv_sec = (s32) stat->ctime.tv_sec;
1226 ks.st_ctime.tv_nsec = stat->ctime.tv_nsec;
1228 ks.st_blksize = (s32) stat->blksize;
1229 ks.st_blocks = (long long) stat->blocks;
1230 memset(ks.st_fstype, 0, 16);
1231 ks.st_pad4[0] = ks.st_pad4[1] = ks.st_pad4[2] = ks.st_pad4[3] = 0;
1232 ks.st_pad4[4] = ks.st_pad4[5] = ks.st_pad4[6] = ks.st_pad4[7] = 0;
1234 /* Now write it all back. */
1235 return copy_to_user(ubuf, &ks, sizeof(ks)) ? -EFAULT : 0;
1238 asmlinkage int irix_xstat(int version, char __user *filename, struct stat __user *statbuf)
1240 int retval;
1241 struct kstat stat;
1243 #ifdef DEBUG_XSTAT
1244 printk("[%s:%d] Wheee.. irix_xstat(%d,%s,%p) ",
1245 current->comm, current->pid, version, filename, statbuf);
1246 #endif
1248 retval = vfs_stat(filename, &stat);
1249 if (!retval) {
1250 switch(version) {
1251 case 2:
1252 retval = irix_xstat32_xlate(&stat, statbuf);
1253 break;
1254 case 3:
1255 retval = irix_xstat64_xlate(&stat, statbuf);
1256 break;
1257 default:
1258 retval = -EINVAL;
1261 return retval;
1264 asmlinkage int irix_lxstat(int version, char __user *filename, struct stat __user *statbuf)
1266 int error;
1267 struct kstat stat;
1269 #ifdef DEBUG_XSTAT
1270 printk("[%s:%d] Wheee.. irix_lxstat(%d,%s,%p) ",
1271 current->comm, current->pid, version, filename, statbuf);
1272 #endif
1274 error = vfs_lstat(filename, &stat);
1276 if (!error) {
1277 switch (version) {
1278 case 2:
1279 error = irix_xstat32_xlate(&stat, statbuf);
1280 break;
1281 case 3:
1282 error = irix_xstat64_xlate(&stat, statbuf);
1283 break;
1284 default:
1285 error = -EINVAL;
1288 return error;
1291 asmlinkage int irix_fxstat(int version, int fd, struct stat __user *statbuf)
1293 int error;
1294 struct kstat stat;
1296 #ifdef DEBUG_XSTAT
1297 printk("[%s:%d] Wheee.. irix_fxstat(%d,%d,%p) ",
1298 current->comm, current->pid, version, fd, statbuf);
1299 #endif
1301 error = vfs_fstat(fd, &stat);
1302 if (!error) {
1303 switch (version) {
1304 case 2:
1305 error = irix_xstat32_xlate(&stat, statbuf);
1306 break;
1307 case 3:
1308 error = irix_xstat64_xlate(&stat, statbuf);
1309 break;
1310 default:
1311 error = -EINVAL;
1314 return error;
1317 asmlinkage int irix_xmknod(int ver, char __user *filename, int mode, unsigned dev)
1319 int retval;
1320 printk("[%s:%d] Wheee.. irix_xmknod(%d,%s,%x,%x)\n",
1321 current->comm, current->pid, ver, filename, mode, dev);
1323 switch(ver) {
1324 case 2:
1325 /* shouldn't we convert here as well as on stat()? */
1326 retval = sys_mknod(filename, mode, dev);
1327 break;
1329 default:
1330 retval = -EINVAL;
1331 break;
1334 return retval;
1337 asmlinkage int irix_swapctl(int cmd, char __user *arg)
1339 printk("[%s:%d] Wheee.. irix_swapctl(%d,%p)\n",
1340 current->comm, current->pid, cmd, arg);
1342 return -EINVAL;
1345 struct irix_statvfs {
1346 u32 f_bsize; u32 f_frsize; u32 f_blocks;
1347 u32 f_bfree; u32 f_bavail; u32 f_files; u32 f_ffree; u32 f_favail;
1348 u32 f_fsid; char f_basetype[16];
1349 u32 f_flag; u32 f_namemax;
1350 char f_fstr[32]; u32 f_filler[16];
1353 asmlinkage int irix_statvfs(char __user *fname, struct irix_statvfs __user *buf)
1355 struct nameidata nd;
1356 struct kstatfs kbuf;
1357 int error, i;
1359 printk("[%s:%d] Wheee.. irix_statvfs(%s,%p)\n",
1360 current->comm, current->pid, fname, buf);
1361 if (!access_ok(VERIFY_WRITE, buf, sizeof(struct irix_statvfs)))
1362 return -EFAULT;
1364 error = user_path_walk(fname, &nd);
1365 if (error)
1366 goto out;
1367 error = vfs_statfs(nd.path.dentry, &kbuf);
1368 if (error)
1369 goto dput_and_out;
1371 error |= __put_user(kbuf.f_bsize, &buf->f_bsize);
1372 error |= __put_user(kbuf.f_frsize, &buf->f_frsize);
1373 error |= __put_user(kbuf.f_blocks, &buf->f_blocks);
1374 error |= __put_user(kbuf.f_bfree, &buf->f_bfree);
1375 error |= __put_user(kbuf.f_bfree, &buf->f_bavail); /* XXX hackety hack... */
1376 error |= __put_user(kbuf.f_files, &buf->f_files);
1377 error |= __put_user(kbuf.f_ffree, &buf->f_ffree);
1378 error |= __put_user(kbuf.f_ffree, &buf->f_favail); /* XXX hackety hack... */
1379 #ifdef __MIPSEB__
1380 error |= __put_user(kbuf.f_fsid.val[1], &buf->f_fsid);
1381 #else
1382 error |= __put_user(kbuf.f_fsid.val[0], &buf->f_fsid);
1383 #endif
1384 for (i = 0; i < 16; i++)
1385 error |= __put_user(0, &buf->f_basetype[i]);
1386 error |= __put_user(0, &buf->f_flag);
1387 error |= __put_user(kbuf.f_namelen, &buf->f_namemax);
1388 for (i = 0; i < 32; i++)
1389 error |= __put_user(0, &buf->f_fstr[i]);
1391 dput_and_out:
1392 path_put(&nd.path);
1393 out:
1394 return error;
1397 asmlinkage int irix_fstatvfs(int fd, struct irix_statvfs __user *buf)
1399 struct kstatfs kbuf;
1400 struct file *file;
1401 int error, i;
1403 printk("[%s:%d] Wheee.. irix_fstatvfs(%d,%p)\n",
1404 current->comm, current->pid, fd, buf);
1406 if (!access_ok(VERIFY_WRITE, buf, sizeof(struct irix_statvfs)))
1407 return -EFAULT;
1409 if (!(file = fget(fd))) {
1410 error = -EBADF;
1411 goto out;
1413 error = vfs_statfs(file->f_path.dentry, &kbuf);
1414 if (error)
1415 goto out_f;
1417 error = __put_user(kbuf.f_bsize, &buf->f_bsize);
1418 error |= __put_user(kbuf.f_frsize, &buf->f_frsize);
1419 error |= __put_user(kbuf.f_blocks, &buf->f_blocks);
1420 error |= __put_user(kbuf.f_bfree, &buf->f_bfree);
1421 error |= __put_user(kbuf.f_bfree, &buf->f_bavail); /* XXX hackety hack... */
1422 error |= __put_user(kbuf.f_files, &buf->f_files);
1423 error |= __put_user(kbuf.f_ffree, &buf->f_ffree);
1424 error |= __put_user(kbuf.f_ffree, &buf->f_favail); /* XXX hackety hack... */
1425 #ifdef __MIPSEB__
1426 error |= __put_user(kbuf.f_fsid.val[1], &buf->f_fsid);
1427 #else
1428 error |= __put_user(kbuf.f_fsid.val[0], &buf->f_fsid);
1429 #endif
1430 for(i = 0; i < 16; i++)
1431 error |= __put_user(0, &buf->f_basetype[i]);
1432 error |= __put_user(0, &buf->f_flag);
1433 error |= __put_user(kbuf.f_namelen, &buf->f_namemax);
1434 error |= __clear_user(&buf->f_fstr, sizeof(buf->f_fstr)) ? -EFAULT : 0;
1436 out_f:
1437 fput(file);
1438 out:
1439 return error;
1442 asmlinkage int irix_priocntl(struct pt_regs *regs)
1444 printk("[%s:%d] Wheee.. irix_priocntl()\n",
1445 current->comm, current->pid);
1447 return -EINVAL;
1450 asmlinkage int irix_sigqueue(int pid, int sig, int code, int val)
1452 printk("[%s:%d] Wheee.. irix_sigqueue(%d,%d,%d,%d)\n",
1453 current->comm, current->pid, pid, sig, code, val);
1455 return -EINVAL;
1458 asmlinkage int irix_truncate64(char __user *name, int pad, int size1, int size2)
1460 int retval;
1462 if (size1) {
1463 retval = -EINVAL;
1464 goto out;
1466 retval = sys_truncate(name, size2);
1468 out:
1469 return retval;
1472 asmlinkage int irix_ftruncate64(int fd, int pad, int size1, int size2)
1474 int retval;
1476 if (size1) {
1477 retval = -EINVAL;
1478 goto out;
1480 retval = sys_ftruncate(fd, size2);
1482 out:
1483 return retval;
1486 asmlinkage int irix_mmap64(struct pt_regs *regs)
1488 int len, prot, flags, fd, off1, off2, error, base = 0;
1489 unsigned long addr, pgoff, *sp;
1490 struct file *file = NULL;
1491 int err;
1493 if (regs->regs[2] == 1000)
1494 base = 1;
1495 sp = (unsigned long *) (regs->regs[29] + 16);
1496 addr = regs->regs[base + 4];
1497 len = regs->regs[base + 5];
1498 prot = regs->regs[base + 6];
1499 if (!base) {
1500 flags = regs->regs[base + 7];
1501 if (!access_ok(VERIFY_READ, sp, (4 * sizeof(unsigned long))))
1502 return -EFAULT;
1503 fd = sp[0];
1504 err = __get_user(off1, &sp[1]);
1505 err |= __get_user(off2, &sp[2]);
1506 } else {
1507 if (!access_ok(VERIFY_READ, sp, (5 * sizeof(unsigned long))))
1508 return -EFAULT;
1509 err = __get_user(flags, &sp[0]);
1510 err |= __get_user(fd, &sp[1]);
1511 err |= __get_user(off1, &sp[2]);
1512 err |= __get_user(off2, &sp[3]);
1515 if (err)
1516 return err;
1518 if (off1 & PAGE_MASK)
1519 return -EOVERFLOW;
1521 pgoff = (off1 << (32 - PAGE_SHIFT)) | (off2 >> PAGE_SHIFT);
1523 if (!(flags & MAP_ANONYMOUS)) {
1524 if (!(file = fget(fd)))
1525 return -EBADF;
1527 /* Ok, bad taste hack follows, try to think in something else
1528 when reading this */
1529 if (flags & IRIX_MAP_AUTOGROW) {
1530 unsigned long old_pos;
1531 long max_size = off2 + len;
1533 if (max_size > file->f_path.dentry->d_inode->i_size) {
1534 old_pos = sys_lseek(fd, max_size - 1, 0);
1535 sys_write(fd, (void __user *) "", 1);
1536 sys_lseek(fd, old_pos, 0);
1541 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
1543 down_write(&current->mm->mmap_sem);
1544 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
1545 up_write(&current->mm->mmap_sem);
1547 if (file)
1548 fput(file);
1550 return error;
1553 asmlinkage int irix_dmi(struct pt_regs *regs)
1555 printk("[%s:%d] Wheee.. irix_dmi()\n",
1556 current->comm, current->pid);
1558 return -EINVAL;
1561 asmlinkage int irix_pread(int fd, char __user *buf, int cnt, int off64,
1562 int off1, int off2)
1564 printk("[%s:%d] Wheee.. irix_pread(%d,%p,%d,%d,%d,%d)\n",
1565 current->comm, current->pid, fd, buf, cnt, off64, off1, off2);
1567 return -EINVAL;
1570 asmlinkage int irix_pwrite(int fd, char __user *buf, int cnt, int off64,
1571 int off1, int off2)
1573 printk("[%s:%d] Wheee.. irix_pwrite(%d,%p,%d,%d,%d,%d)\n",
1574 current->comm, current->pid, fd, buf, cnt, off64, off1, off2);
1576 return -EINVAL;
1579 asmlinkage int irix_sgifastpath(int cmd, unsigned long arg0, unsigned long arg1,
1580 unsigned long arg2, unsigned long arg3,
1581 unsigned long arg4, unsigned long arg5)
1583 printk("[%s:%d] Wheee.. irix_fastpath(%d,%08lx,%08lx,%08lx,%08lx,"
1584 "%08lx,%08lx)\n",
1585 current->comm, current->pid, cmd, arg0, arg1, arg2,
1586 arg3, arg4, arg5);
1588 return -EINVAL;
1591 struct irix_statvfs64 {
1592 u32 f_bsize; u32 f_frsize;
1593 u64 f_blocks; u64 f_bfree; u64 f_bavail;
1594 u64 f_files; u64 f_ffree; u64 f_favail;
1595 u32 f_fsid;
1596 char f_basetype[16];
1597 u32 f_flag; u32 f_namemax;
1598 char f_fstr[32];
1599 u32 f_filler[16];
1602 asmlinkage int irix_statvfs64(char __user *fname, struct irix_statvfs64 __user *buf)
1604 struct nameidata nd;
1605 struct kstatfs kbuf;
1606 int error, i;
1608 printk("[%s:%d] Wheee.. irix_statvfs64(%s,%p)\n",
1609 current->comm, current->pid, fname, buf);
1610 if (!access_ok(VERIFY_WRITE, buf, sizeof(struct irix_statvfs64))) {
1611 error = -EFAULT;
1612 goto out;
1615 error = user_path_walk(fname, &nd);
1616 if (error)
1617 goto out;
1618 error = vfs_statfs(nd.path.dentry, &kbuf);
1619 if (error)
1620 goto dput_and_out;
1622 error = __put_user(kbuf.f_bsize, &buf->f_bsize);
1623 error |= __put_user(kbuf.f_frsize, &buf->f_frsize);
1624 error |= __put_user(kbuf.f_blocks, &buf->f_blocks);
1625 error |= __put_user(kbuf.f_bfree, &buf->f_bfree);
1626 error |= __put_user(kbuf.f_bfree, &buf->f_bavail); /* XXX hackety hack... */
1627 error |= __put_user(kbuf.f_files, &buf->f_files);
1628 error |= __put_user(kbuf.f_ffree, &buf->f_ffree);
1629 error |= __put_user(kbuf.f_ffree, &buf->f_favail); /* XXX hackety hack... */
1630 #ifdef __MIPSEB__
1631 error |= __put_user(kbuf.f_fsid.val[1], &buf->f_fsid);
1632 #else
1633 error |= __put_user(kbuf.f_fsid.val[0], &buf->f_fsid);
1634 #endif
1635 for(i = 0; i < 16; i++)
1636 error |= __put_user(0, &buf->f_basetype[i]);
1637 error |= __put_user(0, &buf->f_flag);
1638 error |= __put_user(kbuf.f_namelen, &buf->f_namemax);
1639 for(i = 0; i < 32; i++)
1640 error |= __put_user(0, &buf->f_fstr[i]);
1642 dput_and_out:
1643 path_put(&nd.path);
1644 out:
1645 return error;
1648 asmlinkage int irix_fstatvfs64(int fd, struct irix_statvfs __user *buf)
1650 struct kstatfs kbuf;
1651 struct file *file;
1652 int error, i;
1654 printk("[%s:%d] Wheee.. irix_fstatvfs64(%d,%p)\n",
1655 current->comm, current->pid, fd, buf);
1657 if (!access_ok(VERIFY_WRITE, buf, sizeof(struct irix_statvfs))) {
1658 error = -EFAULT;
1659 goto out;
1661 if (!(file = fget(fd))) {
1662 error = -EBADF;
1663 goto out;
1665 error = vfs_statfs(file->f_path.dentry, &kbuf);
1666 if (error)
1667 goto out_f;
1669 error = __put_user(kbuf.f_bsize, &buf->f_bsize);
1670 error |= __put_user(kbuf.f_frsize, &buf->f_frsize);
1671 error |= __put_user(kbuf.f_blocks, &buf->f_blocks);
1672 error |= __put_user(kbuf.f_bfree, &buf->f_bfree);
1673 error |= __put_user(kbuf.f_bfree, &buf->f_bavail); /* XXX hackety hack... */
1674 error |= __put_user(kbuf.f_files, &buf->f_files);
1675 error |= __put_user(kbuf.f_ffree, &buf->f_ffree);
1676 error |= __put_user(kbuf.f_ffree, &buf->f_favail); /* XXX hackety hack... */
1677 #ifdef __MIPSEB__
1678 error |= __put_user(kbuf.f_fsid.val[1], &buf->f_fsid);
1679 #else
1680 error |= __put_user(kbuf.f_fsid.val[0], &buf->f_fsid);
1681 #endif
1682 for(i = 0; i < 16; i++)
1683 error |= __put_user(0, &buf->f_basetype[i]);
1684 error |= __put_user(0, &buf->f_flag);
1685 error |= __put_user(kbuf.f_namelen, &buf->f_namemax);
1686 error |= __clear_user(buf->f_fstr, sizeof(buf->f_fstr[i])) ? -EFAULT : 0;
1688 out_f:
1689 fput(file);
1690 out:
1691 return error;
1694 asmlinkage int irix_getmountid(char __user *fname, unsigned long __user *midbuf)
1696 int err;
1698 printk("[%s:%d] irix_getmountid(%s, %p)\n",
1699 current->comm, current->pid, fname, midbuf);
1700 if (!access_ok(VERIFY_WRITE, midbuf, (sizeof(unsigned long) * 4)))
1701 return -EFAULT;
1704 * The idea with this system call is that when trying to determine
1705 * 'pwd' and it's a toss-up for some reason, userland can use the
1706 * fsid of the filesystem to try and make the right decision, but
1707 * we don't have this so for now. XXX
1709 err = __put_user(0, &midbuf[0]);
1710 err |= __put_user(0, &midbuf[1]);
1711 err |= __put_user(0, &midbuf[2]);
1712 err |= __put_user(0, &midbuf[3]);
1714 return err;
1717 asmlinkage int irix_nsproc(unsigned long entry, unsigned long mask,
1718 unsigned long arg, unsigned long sp, int slen)
1720 printk("[%s:%d] Wheee.. irix_nsproc(%08lx,%08lx,%08lx,%08lx,%d)\n",
1721 current->comm, current->pid, entry, mask, arg, sp, slen);
1723 return -EINVAL;
1726 #undef DEBUG_GETDENTS
1728 struct irix_dirent32 {
1729 u32 d_ino;
1730 u32 d_off;
1731 unsigned short d_reclen;
1732 char d_name[1];
1735 struct irix_dirent32_callback {
1736 struct irix_dirent32 __user *current_dir;
1737 struct irix_dirent32 __user *previous;
1738 int count;
1739 int error;
1742 #define NAME_OFFSET32(de) ((int) ((de)->d_name - (char *) (de)))
1743 #define ROUND_UP32(x) (((x)+sizeof(u32)-1) & ~(sizeof(u32)-1))
1745 static int irix_filldir32(void *__buf, const char *name,
1746 int namlen, loff_t offset, u64 ino, unsigned int d_type)
1748 struct irix_dirent32 __user *dirent;
1749 struct irix_dirent32_callback *buf = __buf;
1750 unsigned short reclen = ROUND_UP32(NAME_OFFSET32(dirent) + namlen + 1);
1751 int err = 0;
1752 u32 d_ino;
1754 #ifdef DEBUG_GETDENTS
1755 printk("\nirix_filldir32[reclen<%d>namlen<%d>count<%d>]",
1756 reclen, namlen, buf->count);
1757 #endif
1758 buf->error = -EINVAL; /* only used if we fail.. */
1759 if (reclen > buf->count)
1760 return -EINVAL;
1761 d_ino = ino;
1762 if (sizeof(d_ino) < sizeof(ino) && d_ino != ino)
1763 return -EOVERFLOW;
1764 dirent = buf->previous;
1765 if (dirent)
1766 err = __put_user(offset, &dirent->d_off);
1767 dirent = buf->current_dir;
1768 err |= __put_user(dirent, &buf->previous);
1769 err |= __put_user(d_ino, &dirent->d_ino);
1770 err |= __put_user(reclen, &dirent->d_reclen);
1771 err |= copy_to_user((char __user *)dirent->d_name, name, namlen) ? -EFAULT : 0;
1772 err |= __put_user(0, &dirent->d_name[namlen]);
1773 dirent = (struct irix_dirent32 __user *) ((char __user *) dirent + reclen);
1775 buf->current_dir = dirent;
1776 buf->count -= reclen;
1778 return err;
1781 asmlinkage int irix_ngetdents(unsigned int fd, void __user * dirent,
1782 unsigned int count, int __user *eob)
1784 struct file *file;
1785 struct irix_dirent32 __user *lastdirent;
1786 struct irix_dirent32_callback buf;
1787 int error;
1789 #ifdef DEBUG_GETDENTS
1790 printk("[%s:%d] ngetdents(%d, %p, %d, %p) ", current->comm,
1791 current->pid, fd, dirent, count, eob);
1792 #endif
1793 error = -EBADF;
1794 file = fget(fd);
1795 if (!file)
1796 goto out;
1798 buf.current_dir = (struct irix_dirent32 __user *) dirent;
1799 buf.previous = NULL;
1800 buf.count = count;
1801 buf.error = 0;
1803 error = vfs_readdir(file, irix_filldir32, &buf);
1804 if (error < 0)
1805 goto out_putf;
1807 error = buf.error;
1808 lastdirent = buf.previous;
1809 if (lastdirent) {
1810 put_user(file->f_pos, &lastdirent->d_off);
1811 error = count - buf.count;
1814 if (put_user(0, eob) < 0) {
1815 error = -EFAULT;
1816 goto out_putf;
1819 #ifdef DEBUG_GETDENTS
1820 printk("eob=%d returning %d\n", *eob, count - buf.count);
1821 #endif
1822 error = count - buf.count;
1824 out_putf:
1825 fput(file);
1826 out:
1827 return error;
1830 struct irix_dirent64 {
1831 u64 d_ino;
1832 u64 d_off;
1833 unsigned short d_reclen;
1834 char d_name[1];
1837 struct irix_dirent64_callback {
1838 struct irix_dirent64 __user *curr;
1839 struct irix_dirent64 __user *previous;
1840 int count;
1841 int error;
1844 #define NAME_OFFSET64(de) ((int) ((de)->d_name - (char *) (de)))
1845 #define ROUND_UP64(x) (((x)+sizeof(u64)-1) & ~(sizeof(u64)-1))
1847 static int irix_filldir64(void *__buf, const char *name,
1848 int namlen, loff_t offset, u64 ino, unsigned int d_type)
1850 struct irix_dirent64 __user *dirent;
1851 struct irix_dirent64_callback * buf = __buf;
1852 unsigned short reclen = ROUND_UP64(NAME_OFFSET64(dirent) + namlen + 1);
1853 int err = 0;
1855 if (!access_ok(VERIFY_WRITE, buf, sizeof(*buf)))
1856 return -EFAULT;
1858 if (__put_user(-EINVAL, &buf->error)) /* only used if we fail.. */
1859 return -EFAULT;
1860 if (reclen > buf->count)
1861 return -EINVAL;
1862 dirent = buf->previous;
1863 if (dirent)
1864 err = __put_user(offset, &dirent->d_off);
1865 dirent = buf->curr;
1866 buf->previous = dirent;
1867 err |= __put_user(ino, &dirent->d_ino);
1868 err |= __put_user(reclen, &dirent->d_reclen);
1869 err |= __copy_to_user((char __user *)dirent->d_name, name, namlen)
1870 ? -EFAULT : 0;
1871 err |= __put_user(0, &dirent->d_name[namlen]);
1873 dirent = (struct irix_dirent64 __user *) ((char __user *) dirent + reclen);
1875 buf->curr = dirent;
1876 buf->count -= reclen;
1878 return err;
1881 asmlinkage int irix_getdents64(int fd, void __user *dirent, int cnt)
1883 struct file *file;
1884 struct irix_dirent64 __user *lastdirent;
1885 struct irix_dirent64_callback buf;
1886 int error;
1888 #ifdef DEBUG_GETDENTS
1889 printk("[%s:%d] getdents64(%d, %p, %d) ", current->comm,
1890 current->pid, fd, dirent, cnt);
1891 #endif
1892 error = -EBADF;
1893 if (!(file = fget(fd)))
1894 goto out;
1896 error = -EFAULT;
1897 if (!access_ok(VERIFY_WRITE, dirent, cnt))
1898 goto out_f;
1900 error = -EINVAL;
1901 if (cnt < (sizeof(struct irix_dirent64) + 255))
1902 goto out_f;
1904 buf.curr = (struct irix_dirent64 __user *) dirent;
1905 buf.previous = NULL;
1906 buf.count = cnt;
1907 buf.error = 0;
1908 error = vfs_readdir(file, irix_filldir64, &buf);
1909 if (error < 0)
1910 goto out_f;
1911 lastdirent = buf.previous;
1912 if (!lastdirent) {
1913 error = buf.error;
1914 goto out_f;
1916 if (put_user(file->f_pos, &lastdirent->d_off))
1917 return -EFAULT;
1918 #ifdef DEBUG_GETDENTS
1919 printk("returning %d\n", cnt - buf.count);
1920 #endif
1921 error = cnt - buf.count;
1923 out_f:
1924 fput(file);
1925 out:
1926 return error;
1929 asmlinkage int irix_ngetdents64(int fd, void __user *dirent, int cnt, int *eob)
1931 struct file *file;
1932 struct irix_dirent64 __user *lastdirent;
1933 struct irix_dirent64_callback buf;
1934 int error;
1936 #ifdef DEBUG_GETDENTS
1937 printk("[%s:%d] ngetdents64(%d, %p, %d) ", current->comm,
1938 current->pid, fd, dirent, cnt);
1939 #endif
1940 error = -EBADF;
1941 if (!(file = fget(fd)))
1942 goto out;
1944 error = -EFAULT;
1945 if (!access_ok(VERIFY_WRITE, dirent, cnt) ||
1946 !access_ok(VERIFY_WRITE, eob, sizeof(*eob)))
1947 goto out_f;
1949 error = -EINVAL;
1950 if (cnt < (sizeof(struct irix_dirent64) + 255))
1951 goto out_f;
1953 *eob = 0;
1954 buf.curr = (struct irix_dirent64 __user *) dirent;
1955 buf.previous = NULL;
1956 buf.count = cnt;
1957 buf.error = 0;
1958 error = vfs_readdir(file, irix_filldir64, &buf);
1959 if (error < 0)
1960 goto out_f;
1961 lastdirent = buf.previous;
1962 if (!lastdirent) {
1963 error = buf.error;
1964 goto out_f;
1966 if (put_user(file->f_pos, &lastdirent->d_off))
1967 return -EFAULT;
1968 #ifdef DEBUG_GETDENTS
1969 printk("eob=%d returning %d\n", *eob, cnt - buf.count);
1970 #endif
1971 error = cnt - buf.count;
1973 out_f:
1974 fput(file);
1975 out:
1976 return error;
1979 asmlinkage int irix_uadmin(unsigned long op, unsigned long func, unsigned long arg)
1981 int retval;
1983 switch (op) {
1984 case 1:
1985 /* Reboot */
1986 printk("[%s:%d] irix_uadmin: Wants to reboot...\n",
1987 current->comm, current->pid);
1988 retval = -EINVAL;
1989 goto out;
1991 case 2:
1992 /* Shutdown */
1993 printk("[%s:%d] irix_uadmin: Wants to shutdown...\n",
1994 current->comm, current->pid);
1995 retval = -EINVAL;
1996 goto out;
1998 case 4:
1999 /* Remount-root */
2000 printk("[%s:%d] irix_uadmin: Wants to remount root...\n",
2001 current->comm, current->pid);
2002 retval = -EINVAL;
2003 goto out;
2005 case 8:
2006 /* Kill all tasks. */
2007 printk("[%s:%d] irix_uadmin: Wants to kill all tasks...\n",
2008 current->comm, current->pid);
2009 retval = -EINVAL;
2010 goto out;
2012 case 256:
2013 /* Set magic mushrooms... */
2014 printk("[%s:%d] irix_uadmin: Wants to set magic mushroom[%d]...\n",
2015 current->comm, current->pid, (int) func);
2016 retval = -EINVAL;
2017 goto out;
2019 default:
2020 printk("[%s:%d] irix_uadmin: Unknown operation [%d]...\n",
2021 current->comm, current->pid, (int) op);
2022 retval = -EINVAL;
2023 goto out;
2026 out:
2027 return retval;
2030 asmlinkage int irix_utssys(char __user *inbuf, int arg, int type, char __user *outbuf)
2032 int retval;
2034 switch(type) {
2035 case 0:
2036 /* uname() */
2037 retval = irix_uname((struct iuname __user *)inbuf);
2038 goto out;
2040 case 2:
2041 /* ustat() */
2042 printk("[%s:%d] irix_utssys: Wants to do ustat()\n",
2043 current->comm, current->pid);
2044 retval = -EINVAL;
2045 goto out;
2047 case 3:
2048 /* fusers() */
2049 printk("[%s:%d] irix_utssys: Wants to do fusers()\n",
2050 current->comm, current->pid);
2051 retval = -EINVAL;
2052 goto out;
2054 default:
2055 printk("[%s:%d] irix_utssys: Wants to do unknown type[%d]\n",
2056 current->comm, current->pid, (int) type);
2057 retval = -EINVAL;
2058 goto out;
2061 out:
2062 return retval;
2065 #undef DEBUG_FCNTL
2067 #define IRIX_F_ALLOCSP 10
2069 asmlinkage int irix_fcntl(int fd, int cmd, int arg)
2071 int retval;
2073 #ifdef DEBUG_FCNTL
2074 printk("[%s:%d] irix_fcntl(%d, %d, %d) ", current->comm,
2075 current->pid, fd, cmd, arg);
2076 #endif
2077 if (cmd == IRIX_F_ALLOCSP){
2078 return 0;
2080 retval = sys_fcntl(fd, cmd, arg);
2081 #ifdef DEBUG_FCNTL
2082 printk("%d\n", retval);
2083 #endif
2084 return retval;
2087 asmlinkage int irix_ulimit(int cmd, int arg)
2089 int retval;
2091 switch(cmd) {
2092 case 1:
2093 printk("[%s:%d] irix_ulimit: Wants to get file size limit.\n",
2094 current->comm, current->pid);
2095 retval = -EINVAL;
2096 goto out;
2098 case 2:
2099 printk("[%s:%d] irix_ulimit: Wants to set file size limit.\n",
2100 current->comm, current->pid);
2101 retval = -EINVAL;
2102 goto out;
2104 case 3:
2105 printk("[%s:%d] irix_ulimit: Wants to get brk limit.\n",
2106 current->comm, current->pid);
2107 retval = -EINVAL;
2108 goto out;
2110 case 4:
2111 #if 0
2112 printk("[%s:%d] irix_ulimit: Wants to get fd limit.\n",
2113 current->comm, current->pid);
2114 retval = -EINVAL;
2115 goto out;
2116 #endif
2117 retval = current->signal->rlim[RLIMIT_NOFILE].rlim_cur;
2118 goto out;
2120 case 5:
2121 printk("[%s:%d] irix_ulimit: Wants to get txt offset.\n",
2122 current->comm, current->pid);
2123 retval = -EINVAL;
2124 goto out;
2126 default:
2127 printk("[%s:%d] irix_ulimit: Unknown command [%d].\n",
2128 current->comm, current->pid, cmd);
2129 retval = -EINVAL;
2130 goto out;
2132 out:
2133 return retval;
2136 asmlinkage int irix_unimp(struct pt_regs *regs)
2138 printk("irix_unimp [%s:%d] v0=%d v1=%d a0=%08lx a1=%08lx a2=%08lx "
2139 "a3=%08lx\n", current->comm, current->pid,
2140 (int) regs->regs[2], (int) regs->regs[3],
2141 regs->regs[4], regs->regs[5], regs->regs[6], regs->regs[7]);
2143 return -ENOSYS;