patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / arch / mips / kernel / sysirix.c
1 /*
2  * sysirix.c: IRIX system call emulation.
3  *
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/highuid.h>
12 #include <linux/pagemap.h>
13 #include <linux/mm.h>
14 #include <linux/mman.h>
15 #include <linux/slab.h>
16 #include <linux/swap.h>
17 #include <linux/errno.h>
18 #include <linux/time.h>
19 #include <linux/timex.h>
20 #include <linux/times.h>
21 #include <linux/elf.h>
22 #include <linux/msg.h>
23 #include <linux/shm.h>
24 #include <linux/smp.h>
25 #include <linux/smp_lock.h>
26 #include <linux/utsname.h>
27 #include <linux/file.h>
28 #include <linux/vfs.h>
29 #include <linux/namei.h>
30 #include <linux/socket.h>
31 #include <linux/security.h>
32 #include <linux/syscalls.h>
33 #include <linux/vs_cvirt.h>
34
35 #include <asm/ptrace.h>
36 #include <asm/page.h>
37 #include <asm/uaccess.h>
38 #include <asm/inventory.h>
39
40 /* 2,191 lines of complete and utter shit coming up... */
41
42 extern int max_threads;
43
44 /* The sysmp commands supported thus far. */
45 #define MP_NPROCS               1 /* # processor in complex */
46 #define MP_NAPROCS              2 /* # active processors in complex */
47 #define MP_PGSIZE               14 /* Return system page size in v1. */
48
49 asmlinkage int irix_sysmp(struct pt_regs *regs)
50 {
51         unsigned long cmd;
52         int base = 0;
53         int error = 0;
54
55         if(regs->regs[2] == 1000)
56                 base = 1;
57         cmd = regs->regs[base + 4];
58         switch(cmd) {
59         case MP_PGSIZE:
60                 error = PAGE_SIZE;
61                 break;
62         case MP_NPROCS:
63         case MP_NAPROCS:
64                 error = num_online_cpus();
65                 break;
66         default:
67                 printk("SYSMP[%s:%d]: Unsupported opcode %d\n",
68                        current->comm, current->pid, (int)cmd);
69                 error = -EINVAL;
70                 break;
71         }
72
73         return error;
74 }
75
76 /* The prctl commands. */
77 #define PR_MAXPROCS          1 /* Tasks/user. */
78 #define PR_ISBLOCKED         2 /* If blocked, return 1. */
79 #define PR_SETSTACKSIZE      3 /* Set largest task stack size. */
80 #define PR_GETSTACKSIZE      4 /* Get largest task stack size. */
81 #define PR_MAXPPROCS         5 /* Num parallel tasks. */
82 #define PR_UNBLKONEXEC       6 /* When task exec/exit's, unblock. */
83 #define PR_SETEXITSIG        8 /* When task exit's, set signal. */
84 #define PR_RESIDENT          9 /* Make task unswappable. */
85 #define PR_ATTACHADDR       10 /* (Re-)Connect a vma to a task. */
86 #define PR_DETACHADDR       11 /* Disconnect a vma from a task. */
87 #define PR_TERMCHILD        12 /* When parent sleeps with fishes, kill child. */
88 #define PR_GETSHMASK        13 /* Get the sproc() share mask. */
89 #define PR_GETNSHARE        14 /* Number of share group members. */
90 #define PR_COREPID          15 /* Add task pid to name when it core. */
91 #define PR_ATTACHADDRPERM   16 /* (Re-)Connect vma, with specified prot. */
92 #define PR_PTHREADEXIT      17 /* Kill a pthread without prejudice. */
93
94 asmlinkage int irix_prctl(struct pt_regs *regs)
95 {
96         unsigned long cmd;
97         int error = 0, base = 0;
98
99         if (regs->regs[2] == 1000)
100                 base = 1;
101         cmd = regs->regs[base + 4];
102         switch (cmd) {
103         case PR_MAXPROCS:
104                 printk("irix_prctl[%s:%d]: Wants PR_MAXPROCS\n",
105                        current->comm, current->pid);
106                 error = max_threads;
107                 break;
108
109         case PR_ISBLOCKED: {
110                 struct task_struct *task;
111
112                 printk("irix_prctl[%s:%d]: Wants PR_ISBLOCKED\n",
113                        current->comm, current->pid);
114                 read_lock(&tasklist_lock);
115                 task = find_task_by_pid(regs->regs[base + 5]);
116                 error = -ESRCH;
117                 if (error)
118                         error = (task->run_list.next != NULL);
119                 read_unlock(&tasklist_lock);
120                 /* Can _your_ OS find this out that fast? */
121                 break;
122         }
123
124         case PR_SETSTACKSIZE: {
125                 long value = regs->regs[base + 5];
126
127                 printk("irix_prctl[%s:%d]: Wants PR_SETSTACKSIZE<%08lx>\n",
128                        current->comm, current->pid, (unsigned long) value);
129                 if (value > RLIM_INFINITY)
130                         value = RLIM_INFINITY;
131                 if (capable(CAP_SYS_ADMIN)) {
132                         current->rlim[RLIMIT_STACK].rlim_max =
133                                 current->rlim[RLIMIT_STACK].rlim_cur = value;
134                         error = value;
135                         break;
136                 }
137                 if (value > current->rlim[RLIMIT_STACK].rlim_max) {
138                         error = -EINVAL;
139                         break;
140                 }
141                 current->rlim[RLIMIT_STACK].rlim_cur = value;
142                 error = value;
143                 break;
144         }
145
146         case PR_GETSTACKSIZE:
147                 printk("irix_prctl[%s:%d]: Wants PR_GETSTACKSIZE\n",
148                        current->comm, current->pid);
149                 error = current->rlim[RLIMIT_STACK].rlim_cur;
150                 break;
151
152         case PR_MAXPPROCS:
153                 printk("irix_prctl[%s:%d]: Wants PR_MAXPROCS\n",
154                        current->comm, current->pid);
155                 error = 1;
156                 break;
157
158         case PR_UNBLKONEXEC:
159                 printk("irix_prctl[%s:%d]: Wants PR_UNBLKONEXEC\n",
160                        current->comm, current->pid);
161                 error = -EINVAL;
162                 break;
163
164         case PR_SETEXITSIG:
165                 printk("irix_prctl[%s:%d]: Wants PR_SETEXITSIG\n",
166                        current->comm, current->pid);
167
168                 /* We can probably play some game where we set the task
169                  * exit_code to some non-zero value when this is requested,
170                  * and check whether exit_code is already set in do_exit().
171                  */
172                 error = -EINVAL;
173                 break;
174
175         case PR_RESIDENT:
176                 printk("irix_prctl[%s:%d]: Wants PR_RESIDENT\n",
177                        current->comm, current->pid);
178                 error = 0; /* Compatibility indeed. */
179                 break;
180
181         case PR_ATTACHADDR:
182                 printk("irix_prctl[%s:%d]: Wants PR_ATTACHADDR\n",
183                        current->comm, current->pid);
184                 error = -EINVAL;
185                 break;
186
187         case PR_DETACHADDR:
188                 printk("irix_prctl[%s:%d]: Wants PR_DETACHADDR\n",
189                        current->comm, current->pid);
190                 error = -EINVAL;
191                 break;
192
193         case PR_TERMCHILD:
194                 printk("irix_prctl[%s:%d]: Wants PR_TERMCHILD\n",
195                        current->comm, current->pid);
196                 error = -EINVAL;
197                 break;
198
199         case PR_GETSHMASK:
200                 printk("irix_prctl[%s:%d]: Wants PR_GETSHMASK\n",
201                        current->comm, current->pid);
202                 error = -EINVAL; /* Until I have the sproc() stuff in. */
203                 break;
204
205         case PR_GETNSHARE:
206                 error = 0;       /* Until I have the sproc() stuff in. */
207                 break;
208
209         case PR_COREPID:
210                 printk("irix_prctl[%s:%d]: Wants PR_COREPID\n",
211                        current->comm, current->pid);
212                 error = -EINVAL;
213                 break;
214
215         case PR_ATTACHADDRPERM:
216                 printk("irix_prctl[%s:%d]: Wants PR_ATTACHADDRPERM\n",
217                        current->comm, current->pid);
218                 error = -EINVAL;
219                 break;
220
221         case PR_PTHREADEXIT:
222                 printk("irix_prctl[%s:%d]: Wants PR_PTHREADEXIT\n",
223                        current->comm, current->pid);
224                 do_exit(regs->regs[base + 5]);
225
226         default:
227                 printk("irix_prctl[%s:%d]: Non-existant opcode %d\n",
228                        current->comm, current->pid, (int)cmd);
229                 error = -EINVAL;
230                 break;
231         }
232
233         return error;
234 }
235
236 #undef DEBUG_PROCGRPS
237
238 extern unsigned long irix_mapelf(int fd, struct elf_phdr *user_phdrp, int cnt);
239 extern int getrusage(struct task_struct *p, int who, struct rusage __user *ru);
240 extern char *prom_getenv(char *name);
241 extern long prom_setenv(char *name, char *value);
242
243 /* The syssgi commands supported thus far. */
244 #define SGI_SYSID         1       /* Return unique per-machine identifier. */
245 #define SGI_INVENT        5       /* Fetch inventory  */
246 #   define SGI_INV_SIZEOF 1
247 #   define SGI_INV_READ   2
248 #define SGI_RDNAME        6       /* Return string name of a process. */
249 #define SGI_SETNVRAM      8       /* Set PROM variable. */
250 #define SGI_GETNVRAM      9       /* Get PROM variable. */
251 #define SGI_SETPGID      21       /* Set process group id. */
252 #define SGI_SYSCONF      22       /* POSIX sysconf garbage. */
253 #define SGI_PATHCONF     24       /* POSIX sysconf garbage. */
254 #define SGI_SETGROUPS    40       /* POSIX sysconf garbage. */
255 #define SGI_GETGROUPS    41       /* POSIX sysconf garbage. */
256 #define SGI_RUSAGE       56       /* BSD style rusage(). */
257 #define SGI_SSYNC        62       /* Synchronous fs sync. */
258 #define SGI_GETSID       65       /* SysVr4 get session id. */
259 #define SGI_ELFMAP       68       /* Map an elf image. */
260 #define SGI_TOSSTSAVE   108       /* Toss saved vma's. */
261 #define SGI_FP_BCOPY    129       /* Should FPU bcopy be used on this machine? */
262 #define SGI_PHYSP      1011       /* Translate virtual into physical page. */
263
264 asmlinkage int irix_syssgi(struct pt_regs *regs)
265 {
266         unsigned long cmd;
267         int retval, base = 0;
268
269         if (regs->regs[2] == 1000)
270                 base = 1;
271
272         cmd = regs->regs[base + 4];
273         switch(cmd) {
274         case SGI_SYSID: {
275                 char *buf = (char *) regs->regs[base + 5];
276
277                 /* XXX Use ethernet addr.... */
278                 retval = clear_user(buf, 64);
279                 break;
280         }
281 #if 0
282         case SGI_RDNAME: {
283                 int pid = (int) regs->regs[base + 5];
284                 char *buf = (char *) regs->regs[base + 6];
285                 struct task_struct *p;
286                 char comm[16];
287
288                 retval = verify_area(VERIFY_WRITE, buf, 16);
289                 if (retval)
290                         break;
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;
297                 }
298                 memcpy(comm, p->comm, 16);
299                 read_unlock(&tasklist_lock);
300
301                 /* XXX Need to check sizes. */
302                 copy_to_user(buf, p->comm, 16);
303                 retval = 0;
304                 break;
305         }
306
307         case SGI_GETNVRAM: {
308                 char *name = (char *) regs->regs[base+5];
309                 char *buf = (char *) regs->regs[base+6];
310                 char *value;
311                 return -EINVAL; /* til I fix it */
312                 retval = verify_area(VERIFY_WRITE, buf, 128);
313                 if (retval)
314                         break;
315                 value = prom_getenv(name);      /* PROM lock?  */
316                 if (!value) {
317                         retval = -EINVAL;
318                         break;
319                 }
320                 /* Do I strlen() for the length? */
321                 copy_to_user(buf, value, 128);
322                 retval = 0;
323                 break;
324         }
325
326         case SGI_SETNVRAM: {
327                 char *name = (char *) regs->regs[base+5];
328                 char *value = (char *) regs->regs[base+6];
329                 return -EINVAL; /* til I fix it */
330                 retval = prom_setenv(name, value);
331                 /* XXX make sure retval conforms to syssgi(2) */
332                 printk("[%s:%d] setnvram(\"%s\", \"%s\"): retval %d",
333                        current->comm, current->pid, name, value, retval);
334 /*              if (retval == PROM_ENOENT)
335                         retval = -ENOENT; */
336                 break;
337         }
338 #endif
339
340         case SGI_SETPGID: {
341 #ifdef DEBUG_PROCGRPS
342                 printk("[%s:%d] setpgid(%d, %d) ",
343                        current->comm, current->pid,
344                        (int) regs->regs[base + 5], (int)regs->regs[base + 6]);
345 #endif
346                 retval = sys_setpgid(regs->regs[base + 5], regs->regs[base + 6]);
347
348 #ifdef DEBUG_PROCGRPS
349                 printk("retval=%d\n", retval);
350 #endif
351         }
352
353         case SGI_SYSCONF: {
354                 switch(regs->regs[base + 5]) {
355                 case 1:
356                         retval = (MAX_ARG_PAGES >> 4); /* XXX estimate... */
357                         goto out;
358                 case 2:
359                         retval = max_threads;
360                         goto out;
361                 case 3:
362                         retval = HZ;
363                         goto out;
364                 case 4:
365                         retval = NGROUPS_MAX;
366                         goto out;
367                 case 5:
368                         retval = NR_OPEN;
369                         goto out;
370                 case 6:
371                         retval = 1;
372                         goto out;
373                 case 7:
374                         retval = 1;
375                         goto out;
376                 case 8:
377                         retval = 199009;
378                         goto out;
379                 case 11:
380                         retval = PAGE_SIZE;
381                         goto out;
382                 case 12:
383                         retval = 4;
384                         goto out;
385                 case 25:
386                 case 26:
387                 case 27:
388                 case 28:
389                 case 29:
390                 case 30:
391                         retval = 0;
392                         goto out;
393                 case 31:
394                         retval = 32;
395                         goto out;
396                 default:
397                         retval = -EINVAL;
398                         goto out;
399                 };
400         }
401
402         case SGI_SETGROUPS:
403                 retval = sys_setgroups((int) regs->regs[base + 5],
404                                        (gid_t *) regs->regs[base + 6]);
405                 break;
406
407         case SGI_GETGROUPS:
408                 retval = sys_getgroups((int) regs->regs[base + 5],
409                                        (gid_t *) regs->regs[base + 6]);
410                 break;
411
412         case SGI_RUSAGE: {
413                 struct rusage *ru = (struct rusage *) regs->regs[base + 6];
414
415                 switch((int) regs->regs[base + 5]) {
416                 case 0:
417                         /* rusage self */
418                         retval = getrusage(current, RUSAGE_SELF, ru);
419                         goto out;
420
421                 case -1:
422                         /* rusage children */
423                         retval = getrusage(current, RUSAGE_CHILDREN, ru);
424                         goto out;
425
426                 default:
427                         retval = -EINVAL;
428                         goto out;
429                 };
430         }
431
432         case SGI_SSYNC:
433                 sys_sync();
434                 retval = 0;
435                 break;
436
437         case SGI_GETSID:
438 #ifdef DEBUG_PROCGRPS
439                 printk("[%s:%d] getsid(%d) ", current->comm, current->pid,
440                        (int) regs->regs[base + 5]);
441 #endif
442                 retval = sys_getsid(regs->regs[base + 5]);
443 #ifdef DEBUG_PROCGRPS
444                 printk("retval=%d\n", retval);
445 #endif
446                 break;
447
448         case SGI_ELFMAP:
449                 retval = irix_mapelf((int) regs->regs[base + 5],
450                                      (struct elf_phdr *) regs->regs[base + 6],
451                                      (int) regs->regs[base + 7]);
452                 break;
453
454         case SGI_TOSSTSAVE:
455                 /* XXX We don't need to do anything? */
456                 retval = 0;
457                 break;
458
459         case SGI_FP_BCOPY:
460                 retval = 0;
461                 break;
462
463         case SGI_PHYSP: {
464                 unsigned long addr = regs->regs[base + 5];
465                 int *pageno = (int *) (regs->regs[base + 6]);
466                 struct mm_struct *mm = current->mm;
467                 pgd_t *pgdp;
468                 pmd_t *pmdp;
469                 pte_t *ptep;
470
471                 retval = verify_area(VERIFY_WRITE, pageno, sizeof(int));
472                 if (retval)
473                         return retval;
474
475                 down_read(&mm->mmap_sem);
476                 pgdp = pgd_offset(mm, addr);
477                 pmdp = pmd_offset(pgdp, addr);
478                 ptep = pte_offset(pmdp, addr);
479                 retval = -EINVAL;
480                 if (ptep) {
481                         pte_t pte = *ptep;
482
483                         if (pte_val(pte) & (_PAGE_VALID | _PAGE_PRESENT)) {
484                                 retval =  put_user((pte_val(pte) & PAGE_MASK) >>
485                                                    PAGE_SHIFT, pageno);
486                         }
487                 }
488                 up_read(&mm->mmap_sem);
489                 break;
490         }
491
492         case SGI_INVENT: {
493                 int  arg1    = (int)    regs->regs [base + 5];
494                 void *buffer = (void *) regs->regs [base + 6];
495                 int  count   = (int)    regs->regs [base + 7];
496
497                 switch (arg1) {
498                 case SGI_INV_SIZEOF:
499                         retval = sizeof (inventory_t);
500                         break;
501                 case SGI_INV_READ:
502                         retval = dump_inventory_to_user (buffer, count);
503                         break;
504                 default:
505                         retval = -EINVAL;
506                 }
507                 break;
508         }
509
510         default:
511                 printk("irix_syssgi: Unsupported command %d\n", (int)cmd);
512                 retval = -EINVAL;
513                 break;
514         };
515
516 out:
517         return retval;
518 }
519
520 asmlinkage int irix_gtime(struct pt_regs *regs)
521 {
522         return get_seconds();
523 }
524
525 /*
526  * IRIX is completely broken... it returns 0 on success, otherwise
527  * ENOMEM.
528  */
529 asmlinkage int irix_brk(unsigned long brk)
530 {
531         unsigned long rlim;
532         unsigned long newbrk, oldbrk;
533         struct mm_struct *mm = current->mm;
534         int ret;
535
536         down_write(&mm->mmap_sem);
537         if (brk < mm->end_code) {
538                 ret = -ENOMEM;
539                 goto out;
540         }
541
542         newbrk = PAGE_ALIGN(brk);
543         oldbrk = PAGE_ALIGN(mm->brk);
544         if (oldbrk == newbrk) {
545                 mm->brk = brk;
546                 ret = 0;
547                 goto out;
548         }
549
550         /*
551          * Always allow shrinking brk
552          */
553         if (brk <= mm->brk) {
554                 mm->brk = brk;
555                 do_munmap(mm, newbrk, oldbrk-newbrk);
556                 ret = 0;
557                 goto out;
558         }
559         /*
560          * Check against rlimit and stack..
561          */
562         rlim = current->rlim[RLIMIT_DATA].rlim_cur;
563         if (rlim >= RLIM_INFINITY)
564                 rlim = ~0;
565         if (brk - mm->end_code > rlim) {
566                 ret = -ENOMEM;
567                 goto out;
568         }
569
570         /*
571          * Check against existing mmap mappings.
572          */
573         if (find_vma_intersection(mm, oldbrk, newbrk+PAGE_SIZE)) {
574                 ret = -ENOMEM;
575                 goto out;
576         }
577
578         /*
579          * Check if we have enough memory..
580          */
581         if (security_vm_enough_memory((newbrk-oldbrk) >> PAGE_SHIFT) ||
582                 !vx_vmpages_avail(mm, (newbrk-oldbrk) >> PAGE_SHIFT)) {
583                 ret = -ENOMEM;
584                 goto out;
585         }
586
587         /*
588          * Ok, looks good - let it rip.
589          */
590         mm->brk = brk;
591         do_brk(oldbrk, newbrk-oldbrk);
592         ret = 0;
593
594 out:
595         up_write(&mm->mmap_sem);
596         return ret;
597 }
598
599 asmlinkage int irix_getpid(struct pt_regs *regs)
600 {
601         regs->regs[3] = current->real_parent->pid;
602         return current->pid;
603 }
604
605 asmlinkage int irix_getuid(struct pt_regs *regs)
606 {
607         regs->regs[3] = current->euid;
608         return current->uid;
609 }
610
611 asmlinkage int irix_getgid(struct pt_regs *regs)
612 {
613         regs->regs[3] = current->egid;
614         return current->gid;
615 }
616
617 asmlinkage int irix_stime(int value)
618 {
619         if (!capable(CAP_SYS_TIME))
620                 return -EPERM;
621
622         write_seqlock_irq(&xtime_lock);
623         xtime.tv_sec = value;
624         xtime.tv_nsec = 0;
625         time_adjust = 0;                        /* stop active adjtime() */
626         time_status |= STA_UNSYNC;
627         time_maxerror = NTP_PHASE_LIMIT;
628         time_esterror = NTP_PHASE_LIMIT;
629         write_sequnlock_irq(&xtime_lock);
630
631         return 0;
632 }
633
634 static inline void jiffiestotv(unsigned long jiffies, struct timeval *value)
635 {
636         value->tv_usec = (jiffies % HZ) * (1000000 / HZ);
637         value->tv_sec = jiffies / HZ;
638 }
639
640 static inline void getitimer_real(struct itimerval *value)
641 {
642         register unsigned long val, interval;
643
644         interval = current->it_real_incr;
645         val = 0;
646         if (del_timer(&current->real_timer)) {
647                 unsigned long now = jiffies;
648                 val = current->real_timer.expires;
649                 add_timer(&current->real_timer);
650                 /* look out for negative/zero itimer.. */
651                 if (val <= now)
652                         val = now+1;
653                 val -= now;
654         }
655         jiffiestotv(val, &value->it_value);
656         jiffiestotv(interval, &value->it_interval);
657 }
658
659 asmlinkage unsigned int irix_alarm(unsigned int seconds)
660 {
661         struct itimerval it_new, it_old;
662         unsigned int oldalarm;
663
664         if (!seconds) {
665                 getitimer_real(&it_old);
666                 del_timer(&current->real_timer);
667         } else {
668                 it_new.it_interval.tv_sec = it_new.it_interval.tv_usec = 0;
669                 it_new.it_value.tv_sec = seconds;
670                 it_new.it_value.tv_usec = 0;
671                 do_setitimer(ITIMER_REAL, &it_new, &it_old);
672         }
673         oldalarm = it_old.it_value.tv_sec;
674         /*
675          * ehhh.. We can't return 0 if we have an alarm pending ...
676          * And we'd better return too much than too little anyway
677          */
678         if (it_old.it_value.tv_usec)
679                 oldalarm++;
680
681         return oldalarm;
682 }
683
684 asmlinkage int irix_pause(void)
685 {
686         current->state = TASK_INTERRUPTIBLE;
687         schedule();
688
689         return -EINTR;
690 }
691
692 /* XXX need more than this... */
693 asmlinkage int irix_mount(char *dev_name, char *dir_name, unsigned long flags,
694                           char *type, void *data, int datalen)
695 {
696         printk("[%s:%d] irix_mount(%p,%p,%08lx,%p,%p,%d)\n",
697                current->comm, current->pid,
698                dev_name, dir_name, flags, type, data, datalen);
699
700         return sys_mount(dev_name, dir_name, type, flags, data);
701 }
702
703 struct irix_statfs {
704         short f_type;
705         long  f_bsize, f_frsize, f_blocks, f_bfree, f_files, f_ffree;
706         char  f_fname[6], f_fpack[6];
707 };
708
709 asmlinkage int irix_statfs(const char *path, struct irix_statfs *buf,
710                            int len, int fs_type)
711 {
712         struct nameidata nd;
713         struct kstatfs kbuf;
714         int error, i;
715
716         /* We don't support this feature yet. */
717         if (fs_type) {
718                 error = -EINVAL;
719                 goto out;
720         }
721         error = verify_area(VERIFY_WRITE, buf, sizeof(struct irix_statfs));
722         if (error)
723                 goto out;
724         error = user_path_walk(path, &nd);
725         if (error)
726                 goto out;
727
728         error = vfs_statfs(nd.dentry->d_inode->i_sb, &kbuf);
729         if (error)
730                 goto dput_and_out;
731
732         __put_user(kbuf.f_type, &buf->f_type);
733         __put_user(kbuf.f_bsize, &buf->f_bsize);
734         __put_user(kbuf.f_frsize, &buf->f_frsize);
735         __put_user(kbuf.f_blocks, &buf->f_blocks);
736         __put_user(kbuf.f_bfree, &buf->f_bfree);
737         __put_user(kbuf.f_files, &buf->f_files);
738         __put_user(kbuf.f_ffree, &buf->f_ffree);
739         for (i = 0; i < 6; i++) {
740                 __put_user(0, &buf->f_fname[i]);
741                 __put_user(0, &buf->f_fpack[i]);
742         }
743         error = 0;
744
745 dput_and_out:
746         path_release(&nd);
747 out:
748         return error;
749 }
750
751 asmlinkage int irix_fstatfs(unsigned int fd, struct irix_statfs *buf)
752 {
753         struct kstatfs kbuf;
754         struct file *file;
755         int error, i;
756
757         error = verify_area(VERIFY_WRITE, buf, sizeof(struct irix_statfs));
758         if (error)
759                 goto out;
760         if (!(file = fget(fd))) {
761                 error = -EBADF;
762                 goto out;
763         }
764
765         error = vfs_statfs(file->f_dentry->d_inode->i_sb, &kbuf);
766         if (error)
767                 goto out_f;
768
769         __put_user(kbuf.f_type, &buf->f_type);
770         __put_user(kbuf.f_bsize, &buf->f_bsize);
771         __put_user(kbuf.f_frsize, &buf->f_frsize);
772         __put_user(kbuf.f_blocks, &buf->f_blocks);
773         __put_user(kbuf.f_bfree, &buf->f_bfree);
774         __put_user(kbuf.f_files, &buf->f_files);
775         __put_user(kbuf.f_ffree, &buf->f_ffree);
776         for(i = 0; i < 6; i++) {
777                 __put_user(0, &buf->f_fname[i]);
778                 __put_user(0, &buf->f_fpack[i]);
779         }
780
781 out_f:
782         fput(file);
783 out:
784         return error;
785 }
786
787 asmlinkage int irix_setpgrp(int flags)
788 {
789         int error;
790
791 #ifdef DEBUG_PROCGRPS
792         printk("[%s:%d] setpgrp(%d) ", current->comm, current->pid, flags);
793 #endif
794         if(!flags)
795                 error = process_group(current);
796         else
797                 error = sys_setsid();
798 #ifdef DEBUG_PROCGRPS
799         printk("returning %d\n", process_group(current));
800 #endif
801
802         return error;
803 }
804
805 asmlinkage int irix_times(struct tms * tbuf)
806 {
807         int err = 0;
808
809         if (tbuf) {
810                 err = verify_area(VERIFY_WRITE,tbuf,sizeof *tbuf);
811                 if (err)
812                         return err;
813                 err |= __put_user(current->utime, &tbuf->tms_utime);
814                 err |= __put_user(current->stime, &tbuf->tms_stime);
815                 err |= __put_user(current->cutime, &tbuf->tms_cutime);
816                 err |= __put_user(current->cstime, &tbuf->tms_cstime);
817         }
818
819         return err;
820 }
821
822 asmlinkage int irix_exec(struct pt_regs *regs)
823 {
824         int error, base = 0;
825         char *filename;
826
827         if(regs->regs[2] == 1000)
828                 base = 1;
829         filename = getname((char *) (long)regs->regs[base + 4]);
830         error = PTR_ERR(filename);
831         if (IS_ERR(filename))
832                 return error;
833
834         error = do_execve(filename, (char **) (long)regs->regs[base + 5],
835                           (char **) 0, regs);
836         putname(filename);
837
838         return error;
839 }
840
841 asmlinkage int irix_exece(struct pt_regs *regs)
842 {
843         int error, base = 0;
844         char *filename;
845
846         if (regs->regs[2] == 1000)
847                 base = 1;
848         filename = getname((char *) (long)regs->regs[base + 4]);
849         error = PTR_ERR(filename);
850         if (IS_ERR(filename))
851                 return error;
852         error = do_execve(filename, (char **) (long)regs->regs[base + 5],
853                           (char **) (long)regs->regs[base + 6], regs);
854         putname(filename);
855
856         return error;
857 }
858
859 asmlinkage unsigned long irix_gethostid(void)
860 {
861         printk("[%s:%d]: irix_gethostid() called...\n",
862                current->comm, current->pid);
863
864         return -EINVAL;
865 }
866
867 asmlinkage unsigned long irix_sethostid(unsigned long val)
868 {
869         printk("[%s:%d]: irix_sethostid(%08lx) called...\n",
870                current->comm, current->pid, val);
871
872         return -EINVAL;
873 }
874
875 asmlinkage int irix_socket(int family, int type, int protocol)
876 {
877         switch(type) {
878         case 1:
879                 type = SOCK_DGRAM;
880                 break;
881
882         case 2:
883                 type = SOCK_STREAM;
884                 break;
885
886         case 3:
887                 type = 9; /* Invalid... */
888                 break;
889
890         case 4:
891                 type = SOCK_RAW;
892                 break;
893
894         case 5:
895                 type = SOCK_RDM;
896                 break;
897
898         case 6:
899                 type = SOCK_SEQPACKET;
900                 break;
901
902         default:
903                 break;
904         }
905
906         return sys_socket(family, type, protocol);
907 }
908
909 asmlinkage int irix_getdomainname(char *name, int len)
910 {
911         int error;
912
913         error = verify_area(VERIFY_WRITE, name, len);
914         if (error)
915                 return error;
916
917         down_read(&uts_sem);
918         if(len > (__NEW_UTS_LEN - 1))
919                 len = __NEW_UTS_LEN - 1;
920         error = 0;
921         if (copy_to_user(name, system_utsname.domainname, len))
922                 error = -EFAULT;
923         up_read(&uts_sem);
924
925         return error;
926 }
927
928 asmlinkage unsigned long irix_getpagesize(void)
929 {
930         return PAGE_SIZE;
931 }
932
933 asmlinkage int irix_msgsys(int opcode, unsigned long arg0, unsigned long arg1,
934                            unsigned long arg2, unsigned long arg3,
935                            unsigned long arg4)
936 {
937         switch (opcode) {
938         case 0:
939                 return sys_msgget((key_t) arg0, (int) arg1);
940         case 1:
941                 return sys_msgctl((int) arg0, (int) arg1, (struct msqid_ds *)arg2);
942         case 2:
943                 return sys_msgrcv((int) arg0, (struct msgbuf *) arg1,
944                                   (size_t) arg2, (long) arg3, (int) arg4);
945         case 3:
946                 return sys_msgsnd((int) arg0, (struct msgbuf *) arg1,
947                                   (size_t) arg2, (int) arg3);
948         default:
949                 return -EINVAL;
950         }
951 }
952
953 asmlinkage int irix_shmsys(int opcode, unsigned long arg0, unsigned long arg1,
954                            unsigned long arg2, unsigned long arg3)
955 {
956         switch (opcode) {
957         case 0:
958                 return do_shmat((int) arg0, (char *)arg1, (int) arg2,
959                                  (unsigned long *) arg3);
960         case 1:
961                 return sys_shmctl((int)arg0, (int)arg1, (struct shmid_ds *)arg2);
962         case 2:
963                 return sys_shmdt((char *)arg0);
964         case 3:
965                 return sys_shmget((key_t) arg0, (int) arg1, (int) arg2);
966         default:
967                 return -EINVAL;
968         }
969 }
970
971 asmlinkage int irix_semsys(int opcode, unsigned long arg0, unsigned long arg1,
972                            unsigned long arg2, int arg3)
973 {
974         switch (opcode) {
975         case 0:
976                 return sys_semctl((int) arg0, (int) arg1, (int) arg2,
977                                   (union semun) arg3);
978         case 1:
979                 return sys_semget((key_t) arg0, (int) arg1, (int) arg2);
980         case 2:
981                 return sys_semop((int) arg0, (struct sembuf *)arg1,
982                                  (unsigned int) arg2);
983         default:
984                 return -EINVAL;
985         }
986 }
987
988 static inline loff_t llseek(struct file *file, loff_t offset, int origin)
989 {
990         loff_t (*fn)(struct file *, loff_t, int);
991         loff_t retval;
992
993         fn = default_llseek;
994         if (file->f_op && file->f_op->llseek)
995         fn = file->f_op->llseek;
996         lock_kernel();
997         retval = fn(file, offset, origin);
998         unlock_kernel();
999         return retval;
1000 }
1001
1002 asmlinkage int irix_lseek64(int fd, int _unused, int offhi, int offlow,
1003                             int origin)
1004 {
1005         int retval;
1006         struct file * file;
1007         loff_t offset;
1008
1009         retval = -EBADF;
1010         file = fget(fd);
1011         if (!file)
1012                 goto bad;
1013         retval = -EINVAL;
1014         if (origin > 2)
1015                 goto out_putf;
1016
1017         offset = llseek(file, ((loff_t) offhi << 32) | offlow, origin);
1018         retval = (int) offset;
1019
1020 out_putf:
1021         fput(file);
1022 bad:
1023         return retval;
1024 }
1025
1026 asmlinkage int irix_sginap(int ticks)
1027 {
1028         current->state = TASK_INTERRUPTIBLE;
1029         schedule_timeout(ticks);
1030         return 0;
1031 }
1032
1033 asmlinkage int irix_sgikopt(char *istring, char *ostring, int len)
1034 {
1035         return -EINVAL;
1036 }
1037
1038 asmlinkage int irix_gettimeofday(struct timeval *tv)
1039 {
1040         time_t sec;
1041         long nsec, seq;
1042         int err;
1043
1044         if (verify_area(VERIFY_WRITE, tv, sizeof(struct timeval)))
1045                 return -EFAULT;
1046
1047         do {
1048                 seq = read_seqbegin(&xtime_lock);
1049                 sec = xtime.tv_sec;
1050                 nsec = xtime.tv_nsec;
1051         } while (read_seqretry(&xtime_lock, seq));
1052
1053         err = __put_user(sec, &tv->tv_sec);
1054         err |= __put_user((nsec / 1000), &tv->tv_usec);
1055
1056         return err;
1057 }
1058
1059 #define IRIX_MAP_AUTOGROW 0x40
1060
1061 asmlinkage unsigned long irix_mmap32(unsigned long addr, size_t len, int prot,
1062                                      int flags, int fd, off_t offset)
1063 {
1064         struct file *file = NULL;
1065         unsigned long retval;
1066
1067         if (!(flags & MAP_ANONYMOUS)) {
1068                 if (!(file = fget(fd)))
1069                         return -EBADF;
1070
1071                 /* Ok, bad taste hack follows, try to think in something else
1072                  * when reading this.  */
1073                 if (flags & IRIX_MAP_AUTOGROW) {
1074                         unsigned long old_pos;
1075                         long max_size = offset + len;
1076
1077                         if (max_size > file->f_dentry->d_inode->i_size) {
1078                                 old_pos = sys_lseek (fd, max_size - 1, 0);
1079                                 sys_write (fd, "", 1);
1080                                 sys_lseek (fd, old_pos, 0);
1081                         }
1082                 }
1083         }
1084
1085         flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
1086
1087         down_write(&current->mm->mmap_sem);
1088         retval = do_mmap(file, addr, len, prot, flags, offset);
1089         up_write(&current->mm->mmap_sem);
1090         if (file)
1091                 fput(file);
1092
1093         return retval;
1094 }
1095
1096 asmlinkage int irix_madvise(unsigned long addr, int len, int behavior)
1097 {
1098         printk("[%s:%d] Wheee.. irix_madvise(%08lx,%d,%d)\n",
1099                current->comm, current->pid, addr, len, behavior);
1100
1101         return -EINVAL;
1102 }
1103
1104 asmlinkage int irix_pagelock(char *addr, int len, int op)
1105 {
1106         printk("[%s:%d] Wheee.. irix_pagelock(%p,%d,%d)\n",
1107                current->comm, current->pid, addr, len, op);
1108
1109         return -EINVAL;
1110 }
1111
1112 asmlinkage int irix_quotactl(struct pt_regs *regs)
1113 {
1114         printk("[%s:%d] Wheee.. irix_quotactl()\n",
1115                current->comm, current->pid);
1116
1117         return -EINVAL;
1118 }
1119
1120 asmlinkage int irix_BSDsetpgrp(int pid, int pgrp)
1121 {
1122         int error;
1123
1124 #ifdef DEBUG_PROCGRPS
1125         printk("[%s:%d] BSDsetpgrp(%d, %d) ", current->comm, current->pid,
1126                pid, pgrp);
1127 #endif
1128         if(!pid)
1129                 pid = current->pid;
1130
1131         /* Wheee, weird sysv thing... */
1132         if ((pgrp == 0) && (pid == current->pid))
1133                 error = sys_setsid();
1134         else
1135                 error = sys_setpgid(pid, pgrp);
1136
1137 #ifdef DEBUG_PROCGRPS
1138         printk("error = %d\n", error);
1139 #endif
1140
1141         return error;
1142 }
1143
1144 asmlinkage int irix_systeminfo(int cmd, char *buf, int cnt)
1145 {
1146         printk("[%s:%d] Wheee.. irix_systeminfo(%d,%p,%d)\n",
1147                current->comm, current->pid, cmd, buf, cnt);
1148
1149         return -EINVAL;
1150 }
1151
1152 struct iuname {
1153         char sysname[257], nodename[257], release[257];
1154         char version[257], machine[257];
1155         char m_type[257], base_rel[257];
1156         char _unused0[257], _unused1[257], _unused2[257];
1157         char _unused3[257], _unused4[257], _unused5[257];
1158 };
1159
1160 asmlinkage int irix_uname(struct iuname *buf)
1161 {
1162         down_read(&uts_sem);
1163         if (copy_to_user(system_utsname.sysname, buf->sysname, 65)
1164             || copy_to_user(system_utsname.nodename, buf->nodename, 65)
1165             || copy_to_user(system_utsname.release, buf->release, 65)
1166             || copy_to_user(system_utsname.version, buf->version, 65)
1167             || copy_to_user(system_utsname.machine, buf->machine, 65)) {
1168                 return -EFAULT;
1169         }
1170         up_read(&uts_sem);
1171
1172         return 1;
1173 }
1174
1175 #undef DEBUG_XSTAT
1176
1177 static int irix_xstat32_xlate(struct kstat *stat, void *ubuf)
1178 {
1179         struct xstat32 {
1180                 u32 st_dev, st_pad1[3], st_ino, st_mode, st_nlink, st_uid, st_gid;
1181                 u32 st_rdev, st_pad2[2], st_size, st_pad3;
1182                 u32 st_atime0, st_atime1;
1183                 u32 st_mtime0, st_mtime1;
1184                 u32 st_ctime0, st_ctime1;
1185                 u32 st_blksize, st_blocks;
1186                 char st_fstype[16];
1187                 u32 st_pad4[8];
1188         } ub;
1189
1190         if (!sysv_valid_dev(stat->dev) || !sysv_valid_dev(stat->rdev))
1191                 return -EOVERFLOW;
1192         ub.st_dev     = sysv_encode_dev(stat->dev);
1193         ub.st_ino     = stat->ino;
1194         ub.st_mode    = stat->mode;
1195         ub.st_nlink   = stat->nlink;
1196         SET_UID(ub.st_uid, stat->uid);
1197         SET_GID(ub.st_gid, stat->gid);
1198         ub.st_rdev    = sysv_encode_dev(stat->rdev);
1199 #if BITS_PER_LONG == 32
1200         if (stat->size > MAX_NON_LFS)
1201                 return -EOVERFLOW;
1202 #endif
1203         ub.st_size    = stat->size;
1204         ub.st_atime0  = stat->atime.tv_sec;
1205         ub.st_atime1  = stat->atime.tv_nsec;
1206         ub.st_mtime0  = stat->mtime.tv_sec;
1207         ub.st_mtime1  = stat->atime.tv_nsec;
1208         ub.st_ctime0  = stat->ctime.tv_sec;
1209         ub.st_ctime1  = stat->atime.tv_nsec;
1210         ub.st_blksize = stat->blksize;
1211         ub.st_blocks  = stat->blocks;
1212         strcpy (ub.st_fstype, "efs");
1213
1214         return copy_to_user(ubuf, &ub, sizeof(ub)) ? -EFAULT : 0;
1215 }
1216
1217 static int irix_xstat64_xlate(struct kstat *stat, void *ubuf)
1218 {
1219         struct xstat64 {
1220                 u32 st_dev; s32 st_pad1[3];
1221                 unsigned long long st_ino;
1222                 u32 st_mode;
1223                 u32 st_nlink; s32 st_uid; s32 st_gid; u32 st_rdev;
1224                 s32 st_pad2[2];
1225                 long long st_size;
1226                 s32 st_pad3;
1227                 struct { s32 tv_sec, tv_nsec; } st_atime, st_mtime, st_ctime;
1228                 s32 st_blksize;
1229                 long long  st_blocks;
1230                 char st_fstype[16];
1231                 s32 st_pad4[8];
1232         } ks;
1233
1234         if (!sysv_valid_dev(stat->dev) || !sysv_valid_dev(stat->rdev))
1235                 return -EOVERFLOW;
1236
1237         ks.st_dev = sysv_encode_dev(stat->dev);
1238         ks.st_pad1[0] = ks.st_pad1[1] = ks.st_pad1[2] = 0;
1239         ks.st_ino = (unsigned long long) stat->ino;
1240         ks.st_mode = (u32) stat->mode;
1241         ks.st_nlink = (u32) stat->nlink;
1242         ks.st_uid = (s32) stat->uid;
1243         ks.st_gid = (s32) stat->gid;
1244         ks.st_rdev = sysv_encode_dev (stat->rdev);
1245         ks.st_pad2[0] = ks.st_pad2[1] = 0;
1246         ks.st_size = (long long) stat->size;
1247         ks.st_pad3 = 0;
1248
1249         /* XXX hackety hack... */
1250         ks.st_atime.tv_sec = (s32) stat->atime.tv_sec;
1251         ks.st_atime.tv_nsec = stat->atime.tv_nsec;
1252         ks.st_mtime.tv_sec = (s32) stat->mtime.tv_sec;
1253         ks.st_mtime.tv_nsec = stat->mtime.tv_nsec;
1254         ks.st_ctime.tv_sec = (s32) stat->ctime.tv_sec;
1255         ks.st_ctime.tv_nsec = stat->ctime.tv_nsec;
1256
1257         ks.st_blksize = (s32) stat->blksize;
1258         ks.st_blocks = (long long) stat->blocks;
1259         memset(ks.st_fstype, 0, 16);
1260         ks.st_pad4[0] = ks.st_pad4[1] = ks.st_pad4[2] = ks.st_pad4[3] = 0;
1261         ks.st_pad4[4] = ks.st_pad4[5] = ks.st_pad4[6] = ks.st_pad4[7] = 0;
1262
1263         /* Now write it all back. */
1264         return copy_to_user(ubuf, &ks, sizeof(ks)) ? -EFAULT : 0;
1265 }
1266
1267 asmlinkage int irix_xstat(int version, char *filename, struct stat *statbuf)
1268 {
1269         int retval;
1270         struct kstat stat;
1271
1272 #ifdef DEBUG_XSTAT
1273         printk("[%s:%d] Wheee.. irix_xstat(%d,%s,%p) ",
1274                current->comm, current->pid, version, filename, statbuf);
1275 #endif
1276
1277         retval = vfs_stat(filename, &stat);
1278         if (!retval) {
1279                 switch(version) {
1280                         case 2:
1281                                 retval = irix_xstat32_xlate(&stat, statbuf);
1282                                 break;
1283                         case 3:
1284                                 retval = irix_xstat64_xlate(&stat, statbuf);
1285                                 break;
1286                         default:
1287                                 retval = -EINVAL;
1288                 }
1289         }
1290         return retval;
1291 }
1292
1293 asmlinkage int irix_lxstat(int version, char *filename, struct stat *statbuf)
1294 {
1295         int error;
1296         struct kstat stat;
1297
1298 #ifdef DEBUG_XSTAT
1299         printk("[%s:%d] Wheee.. irix_lxstat(%d,%s,%p) ",
1300                current->comm, current->pid, version, filename, statbuf);
1301 #endif
1302
1303         error = vfs_lstat(filename, &stat);
1304
1305         if (!error) {
1306                 switch (version) {
1307                         case 2:
1308                                 error = irix_xstat32_xlate(&stat, statbuf);
1309                                 break;
1310                         case 3:
1311                                 error = irix_xstat64_xlate(&stat, statbuf);
1312                                 break;
1313                         default:
1314                                 error = -EINVAL;
1315                 }
1316         }
1317         return error;
1318 }
1319
1320 asmlinkage int irix_fxstat(int version, int fd, struct stat *statbuf)
1321 {
1322         int error;
1323         struct kstat stat;
1324
1325 #ifdef DEBUG_XSTAT
1326         printk("[%s:%d] Wheee.. irix_fxstat(%d,%d,%p) ",
1327                current->comm, current->pid, version, fd, statbuf);
1328 #endif
1329
1330         error = vfs_fstat(fd, &stat);
1331         if (!error) {
1332                 switch (version) {
1333                         case 2:
1334                                 error = irix_xstat32_xlate(&stat, statbuf);
1335                                 break;
1336                         case 3:
1337                                 error = irix_xstat64_xlate(&stat, statbuf);
1338                                 break;
1339                         default:
1340                                 error = -EINVAL;
1341                 }
1342         }
1343         return error;
1344 }
1345
1346 asmlinkage int irix_xmknod(int ver, char *filename, int mode, unsigned dev)
1347 {
1348         int retval;
1349         printk("[%s:%d] Wheee.. irix_xmknod(%d,%s,%x,%x)\n",
1350                current->comm, current->pid, ver, filename, mode, dev);
1351
1352         switch(ver) {
1353         case 2:
1354                 /* shouldn't we convert here as well as on stat()? */
1355                 retval = sys_mknod(filename, mode, dev);
1356                 break;
1357
1358         default:
1359                 retval = -EINVAL;
1360                 break;
1361         };
1362
1363         return retval;
1364 }
1365
1366 asmlinkage int irix_swapctl(int cmd, char *arg)
1367 {
1368         printk("[%s:%d] Wheee.. irix_swapctl(%d,%p)\n",
1369                current->comm, current->pid, cmd, arg);
1370
1371         return -EINVAL;
1372 }
1373
1374 struct irix_statvfs {
1375         u32 f_bsize; u32 f_frsize; u32 f_blocks;
1376         u32 f_bfree; u32 f_bavail; u32 f_files; u32 f_ffree; u32 f_favail;
1377         u32 f_fsid; char f_basetype[16];
1378         u32 f_flag; u32 f_namemax;
1379         char    f_fstr[32]; u32 f_filler[16];
1380 };
1381
1382 asmlinkage int irix_statvfs(char *fname, struct irix_statvfs *buf)
1383 {
1384         struct nameidata nd;
1385         struct kstatfs kbuf;
1386         int error, i;
1387
1388         printk("[%s:%d] Wheee.. irix_statvfs(%s,%p)\n",
1389                current->comm, current->pid, fname, buf);
1390         error = verify_area(VERIFY_WRITE, buf, sizeof(struct irix_statvfs));
1391         if (error)
1392                 goto out;
1393         error = user_path_walk(fname, &nd);
1394         if (error)
1395                 goto out;
1396         error = vfs_statfs(nd.dentry->d_inode->i_sb, &kbuf);
1397         if (error)
1398                 goto dput_and_out;
1399
1400         __put_user(kbuf.f_bsize, &buf->f_bsize);
1401         __put_user(kbuf.f_frsize, &buf->f_frsize);
1402         __put_user(kbuf.f_blocks, &buf->f_blocks);
1403         __put_user(kbuf.f_bfree, &buf->f_bfree);
1404         __put_user(kbuf.f_bfree, &buf->f_bavail);  /* XXX hackety hack... */
1405         __put_user(kbuf.f_files, &buf->f_files);
1406         __put_user(kbuf.f_ffree, &buf->f_ffree);
1407         __put_user(kbuf.f_ffree, &buf->f_favail);  /* XXX hackety hack... */
1408 #ifdef __MIPSEB__
1409         __put_user(kbuf.f_fsid.val[1], &buf->f_fsid);
1410 #else
1411         __put_user(kbuf.f_fsid.val[0], &buf->f_fsid);
1412 #endif
1413         for (i = 0; i < 16; i++)
1414                 __put_user(0, &buf->f_basetype[i]);
1415         __put_user(0, &buf->f_flag);
1416         __put_user(kbuf.f_namelen, &buf->f_namemax);
1417         for (i = 0; i < 32; i++)
1418                 __put_user(0, &buf->f_fstr[i]);
1419
1420         error = 0;
1421
1422 dput_and_out:
1423         path_release(&nd);
1424 out:
1425         return error;
1426 }
1427
1428 asmlinkage int irix_fstatvfs(int fd, struct irix_statvfs *buf)
1429 {
1430         struct kstatfs kbuf;
1431         struct file *file;
1432         int error, i;
1433
1434         printk("[%s:%d] Wheee.. irix_fstatvfs(%d,%p)\n",
1435                current->comm, current->pid, fd, buf);
1436
1437         error = verify_area(VERIFY_WRITE, buf, sizeof(struct irix_statvfs));
1438         if (error)
1439                 goto out;
1440         if (!(file = fget(fd))) {
1441                 error = -EBADF;
1442                 goto out;
1443         }
1444         error = vfs_statfs(file->f_dentry->d_inode->i_sb, &kbuf);
1445         if (error)
1446                 goto out_f;
1447
1448         __put_user(kbuf.f_bsize, &buf->f_bsize);
1449         __put_user(kbuf.f_frsize, &buf->f_frsize);
1450         __put_user(kbuf.f_blocks, &buf->f_blocks);
1451         __put_user(kbuf.f_bfree, &buf->f_bfree);
1452         __put_user(kbuf.f_bfree, &buf->f_bavail); /* XXX hackety hack... */
1453         __put_user(kbuf.f_files, &buf->f_files);
1454         __put_user(kbuf.f_ffree, &buf->f_ffree);
1455         __put_user(kbuf.f_ffree, &buf->f_favail); /* XXX hackety hack... */
1456 #ifdef __MIPSEB__
1457         __put_user(kbuf.f_fsid.val[1], &buf->f_fsid);
1458 #else
1459         __put_user(kbuf.f_fsid.val[0], &buf->f_fsid);
1460 #endif
1461         for(i = 0; i < 16; i++)
1462                 __put_user(0, &buf->f_basetype[i]);
1463         __put_user(0, &buf->f_flag);
1464         __put_user(kbuf.f_namelen, &buf->f_namemax);
1465         __clear_user(&buf->f_fstr, sizeof(buf->f_fstr));
1466
1467 out_f:
1468         fput(file);
1469 out:
1470         return error;
1471 }
1472
1473 asmlinkage int irix_priocntl(struct pt_regs *regs)
1474 {
1475         printk("[%s:%d] Wheee.. irix_priocntl()\n",
1476                current->comm, current->pid);
1477
1478         return -EINVAL;
1479 }
1480
1481 asmlinkage int irix_sigqueue(int pid, int sig, int code, int val)
1482 {
1483         printk("[%s:%d] Wheee.. irix_sigqueue(%d,%d,%d,%d)\n",
1484                current->comm, current->pid, pid, sig, code, val);
1485
1486         return -EINVAL;
1487 }
1488
1489 asmlinkage int irix_truncate64(char *name, int pad, int size1, int size2)
1490 {
1491         int retval;
1492
1493         if (size1) {
1494                 retval = -EINVAL;
1495                 goto out;
1496         }
1497         retval = sys_truncate(name, size2);
1498
1499 out:
1500         return retval;
1501 }
1502
1503 asmlinkage int irix_ftruncate64(int fd, int pad, int size1, int size2)
1504 {
1505         int retval;
1506
1507         if (size1) {
1508                 retval = -EINVAL;
1509                 goto out;
1510         }
1511         retval = sys_ftruncate(fd, size2);
1512
1513 out:
1514         return retval;
1515 }
1516
1517 asmlinkage int irix_mmap64(struct pt_regs *regs)
1518 {
1519         int len, prot, flags, fd, off1, off2, error, base = 0;
1520         unsigned long addr, pgoff, *sp;
1521         struct file *file = NULL;
1522
1523         if (regs->regs[2] == 1000)
1524                 base = 1;
1525         sp = (unsigned long *) (regs->regs[29] + 16);
1526         addr = regs->regs[base + 4];
1527         len = regs->regs[base + 5];
1528         prot = regs->regs[base + 6];
1529         if (!base) {
1530                 flags = regs->regs[base + 7];
1531                 error = verify_area(VERIFY_READ, sp, (4 * sizeof(unsigned long)));
1532                 if(error)
1533                         goto out;
1534                 fd = sp[0];
1535                 __get_user(off1, &sp[1]);
1536                 __get_user(off2, &sp[2]);
1537         } else {
1538                 error = verify_area(VERIFY_READ, sp, (5 * sizeof(unsigned long)));
1539                 if(error)
1540                         goto out;
1541                 __get_user(flags, &sp[0]);
1542                 __get_user(fd, &sp[1]);
1543                 __get_user(off1, &sp[2]);
1544                 __get_user(off2, &sp[3]);
1545         }
1546
1547         if (off1 & PAGE_MASK) {
1548                 error = -EOVERFLOW;
1549                 goto out;
1550         }
1551
1552         pgoff = (off1 << (32 - PAGE_SHIFT)) | (off2 >> PAGE_SHIFT);
1553
1554         if (!(flags & MAP_ANONYMOUS)) {
1555                 if (!(file = fget(fd))) {
1556                         error = -EBADF;
1557                         goto out;
1558                 }
1559
1560                 /* Ok, bad taste hack follows, try to think in something else
1561                    when reading this */
1562                 if (flags & IRIX_MAP_AUTOGROW) {
1563                         unsigned long old_pos;
1564                         long max_size = off2 + len;
1565
1566                         if (max_size > file->f_dentry->d_inode->i_size) {
1567                                 old_pos = sys_lseek (fd, max_size - 1, 0);
1568                                 sys_write (fd, "", 1);
1569                                 sys_lseek (fd, old_pos, 0);
1570                         }
1571                 }
1572         }
1573
1574         flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
1575
1576         down_write(&current->mm->mmap_sem);
1577         error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
1578         up_write(&current->mm->mmap_sem);
1579
1580         if (file)
1581                 fput(file);
1582
1583 out:
1584         return error;
1585 }
1586
1587 asmlinkage int irix_dmi(struct pt_regs *regs)
1588 {
1589         printk("[%s:%d] Wheee.. irix_dmi()\n",
1590                current->comm, current->pid);
1591
1592         return -EINVAL;
1593 }
1594
1595 asmlinkage int irix_pread(int fd, char *buf, int cnt, int off64,
1596                           int off1, int off2)
1597 {
1598         printk("[%s:%d] Wheee.. irix_pread(%d,%p,%d,%d,%d,%d)\n",
1599                current->comm, current->pid, fd, buf, cnt, off64, off1, off2);
1600
1601         return -EINVAL;
1602 }
1603
1604 asmlinkage int irix_pwrite(int fd, char *buf, int cnt, int off64,
1605                            int off1, int off2)
1606 {
1607         printk("[%s:%d] Wheee.. irix_pwrite(%d,%p,%d,%d,%d,%d)\n",
1608                current->comm, current->pid, fd, buf, cnt, off64, off1, off2);
1609
1610         return -EINVAL;
1611 }
1612
1613 asmlinkage int irix_sgifastpath(int cmd, unsigned long arg0, unsigned long arg1,
1614                                 unsigned long arg2, unsigned long arg3,
1615                                 unsigned long arg4, unsigned long arg5)
1616 {
1617         printk("[%s:%d] Wheee.. irix_fastpath(%d,%08lx,%08lx,%08lx,%08lx,"
1618                "%08lx,%08lx)\n",
1619                current->comm, current->pid, cmd, arg0, arg1, arg2,
1620                arg3, arg4, arg5);
1621
1622         return -EINVAL;
1623 }
1624
1625 struct irix_statvfs64 {
1626         u32  f_bsize; u32 f_frsize;
1627         u64  f_blocks; u64 f_bfree; u64 f_bavail;
1628         u64  f_files; u64 f_ffree; u64 f_favail;
1629         u32  f_fsid;
1630         char f_basetype[16];
1631         u32  f_flag; u32 f_namemax;
1632         char f_fstr[32];
1633         u32  f_filler[16];
1634 };
1635
1636 asmlinkage int irix_statvfs64(char *fname, struct irix_statvfs64 *buf)
1637 {
1638         struct nameidata nd;
1639         struct kstatfs kbuf;
1640         int error, i;
1641
1642         printk("[%s:%d] Wheee.. irix_statvfs(%s,%p)\n",
1643                current->comm, current->pid, fname, buf);
1644         error = verify_area(VERIFY_WRITE, buf, sizeof(struct irix_statvfs));
1645         if(error)
1646                 goto out;
1647         error = user_path_walk(fname, &nd);
1648         if (error)
1649                 goto out;
1650         error = vfs_statfs(nd.dentry->d_inode->i_sb, &kbuf);
1651         if (error)
1652                 goto dput_and_out;
1653
1654         __put_user(kbuf.f_bsize, &buf->f_bsize);
1655         __put_user(kbuf.f_frsize, &buf->f_frsize);
1656         __put_user(kbuf.f_blocks, &buf->f_blocks);
1657         __put_user(kbuf.f_bfree, &buf->f_bfree);
1658         __put_user(kbuf.f_bfree, &buf->f_bavail);  /* XXX hackety hack... */
1659         __put_user(kbuf.f_files, &buf->f_files);
1660         __put_user(kbuf.f_ffree, &buf->f_ffree);
1661         __put_user(kbuf.f_ffree, &buf->f_favail);  /* XXX hackety hack... */
1662 #ifdef __MIPSEB__
1663         __put_user(kbuf.f_fsid.val[1], &buf->f_fsid);
1664 #else
1665         __put_user(kbuf.f_fsid.val[0], &buf->f_fsid);
1666 #endif
1667         for(i = 0; i < 16; i++)
1668                 __put_user(0, &buf->f_basetype[i]);
1669         __put_user(0, &buf->f_flag);
1670         __put_user(kbuf.f_namelen, &buf->f_namemax);
1671         for(i = 0; i < 32; i++)
1672                 __put_user(0, &buf->f_fstr[i]);
1673
1674         error = 0;
1675
1676 dput_and_out:
1677         path_release(&nd);
1678 out:
1679         return error;
1680 }
1681
1682 asmlinkage int irix_fstatvfs64(int fd, struct irix_statvfs *buf)
1683 {
1684         struct kstatfs kbuf;
1685         struct file *file;
1686         int error, i;
1687
1688         printk("[%s:%d] Wheee.. irix_fstatvfs(%d,%p)\n",
1689                current->comm, current->pid, fd, buf);
1690
1691         error = verify_area(VERIFY_WRITE, buf, sizeof(struct irix_statvfs));
1692         if (error)
1693                 goto out;
1694         if (!(file = fget(fd))) {
1695                 error = -EBADF;
1696                 goto out;
1697         }
1698         error = vfs_statfs(file->f_dentry->d_inode->i_sb, &kbuf);
1699         if (error)
1700                 goto out_f;
1701
1702         __put_user(kbuf.f_bsize, &buf->f_bsize);
1703         __put_user(kbuf.f_frsize, &buf->f_frsize);
1704         __put_user(kbuf.f_blocks, &buf->f_blocks);
1705         __put_user(kbuf.f_bfree, &buf->f_bfree);
1706         __put_user(kbuf.f_bfree, &buf->f_bavail);  /* XXX hackety hack... */
1707         __put_user(kbuf.f_files, &buf->f_files);
1708         __put_user(kbuf.f_ffree, &buf->f_ffree);
1709         __put_user(kbuf.f_ffree, &buf->f_favail);  /* XXX hackety hack... */
1710 #ifdef __MIPSEB__
1711         __put_user(kbuf.f_fsid.val[1], &buf->f_fsid);
1712 #else
1713         __put_user(kbuf.f_fsid.val[0], &buf->f_fsid);
1714 #endif
1715         for(i = 0; i < 16; i++)
1716                 __put_user(0, &buf->f_basetype[i]);
1717         __put_user(0, &buf->f_flag);
1718         __put_user(kbuf.f_namelen, &buf->f_namemax);
1719         __clear_user(buf->f_fstr, sizeof(buf->f_fstr[i]));
1720
1721 out_f:
1722         fput(file);
1723 out:
1724         return error;
1725 }
1726
1727 asmlinkage int irix_getmountid(char *fname, unsigned long *midbuf)
1728 {
1729         int err;
1730
1731         printk("[%s:%d] irix_getmountid(%s, %p)\n",
1732                current->comm, current->pid, fname, midbuf);
1733         err = verify_area(VERIFY_WRITE, midbuf, (sizeof(unsigned long) * 4));
1734         if (err)
1735                 return err;
1736
1737         /*
1738          * The idea with this system call is that when trying to determine
1739          * 'pwd' and it's a toss-up for some reason, userland can use the
1740          * fsid of the filesystem to try and make the right decision, but
1741          * we don't have this so for now. XXX
1742          */
1743         err |= __put_user(0, &midbuf[0]);
1744         err |= __put_user(0, &midbuf[1]);
1745         err |= __put_user(0, &midbuf[2]);
1746         err |= __put_user(0, &midbuf[3]);
1747
1748         return err;
1749 }
1750
1751 asmlinkage int irix_nsproc(unsigned long entry, unsigned long mask,
1752                            unsigned long arg, unsigned long sp, int slen)
1753 {
1754         printk("[%s:%d] Wheee.. irix_nsproc(%08lx,%08lx,%08lx,%08lx,%d)\n",
1755                current->comm, current->pid, entry, mask, arg, sp, slen);
1756
1757         return -EINVAL;
1758 }
1759
1760 #undef DEBUG_GETDENTS
1761
1762 struct irix_dirent32 {
1763         u32  d_ino;
1764         u32  d_off;
1765         unsigned short  d_reclen;
1766         char d_name[1];
1767 };
1768
1769 struct irix_dirent32_callback {
1770         struct irix_dirent32 *current_dir;
1771         struct irix_dirent32 *previous;
1772         int count;
1773         int error;
1774 };
1775
1776 #define NAME_OFFSET32(de) ((int) ((de)->d_name - (char *) (de)))
1777 #define ROUND_UP32(x) (((x)+sizeof(u32)-1) & ~(sizeof(u32)-1))
1778
1779 static int irix_filldir32(void *__buf, const char *name, int namlen,
1780                           loff_t offset, ino_t ino, unsigned int d_type)
1781 {
1782         struct irix_dirent32 *dirent;
1783         struct irix_dirent32_callback *buf =
1784                  (struct irix_dirent32_callback *)__buf;
1785         unsigned short reclen = ROUND_UP32(NAME_OFFSET32(dirent) + namlen + 1);
1786
1787 #ifdef DEBUG_GETDENTS
1788         printk("\nirix_filldir32[reclen<%d>namlen<%d>count<%d>]",
1789                reclen, namlen, buf->count);
1790 #endif
1791         buf->error = -EINVAL;   /* only used if we fail.. */
1792         if (reclen > buf->count)
1793                 return -EINVAL;
1794         dirent = buf->previous;
1795         if (dirent)
1796                 __put_user(offset, &dirent->d_off);
1797         dirent = buf->current_dir;
1798         buf->previous = dirent;
1799         __put_user(ino, &dirent->d_ino);
1800         __put_user(reclen, &dirent->d_reclen);
1801         copy_to_user(dirent->d_name, name, namlen);
1802         __put_user(0, &dirent->d_name[namlen]);
1803         ((char *) dirent) += reclen;
1804         buf->current_dir = dirent;
1805         buf->count -= reclen;
1806
1807         return 0;
1808 }
1809
1810 asmlinkage int irix_ngetdents(unsigned int fd, void * dirent,
1811         unsigned int count, int *eob)
1812 {
1813         struct file *file;
1814         struct irix_dirent32 *lastdirent;
1815         struct irix_dirent32_callback buf;
1816         int error;
1817
1818 #ifdef DEBUG_GETDENTS
1819         printk("[%s:%d] ngetdents(%d, %p, %d, %p) ", current->comm,
1820                current->pid, fd, dirent, count, eob);
1821 #endif
1822         error = -EBADF;
1823         file = fget(fd);
1824         if (!file)
1825                 goto out;
1826
1827         buf.current_dir = (struct irix_dirent32 *) dirent;
1828         buf.previous = NULL;
1829         buf.count = count;
1830         buf.error = 0;
1831
1832         error = vfs_readdir(file, irix_filldir32, &buf);
1833         if (error < 0)
1834                 goto out_putf;
1835
1836         error = buf.error;
1837         lastdirent = buf.previous;
1838         if (lastdirent) {
1839                 put_user(file->f_pos, &lastdirent->d_off);
1840                 error = count - buf.count;
1841         }
1842
1843         if (put_user(0, eob) < 0) {
1844                 error = -EFAULT;
1845                 goto out_putf;
1846         }
1847
1848 #ifdef DEBUG_GETDENTS
1849         printk("eob=%d returning %d\n", *eob, count - buf.count);
1850 #endif
1851         error = count - buf.count;
1852
1853 out_putf:
1854         fput(file);
1855 out:
1856         return error;
1857 }
1858
1859 struct irix_dirent64 {
1860         u64            d_ino;
1861         u64            d_off;
1862         unsigned short d_reclen;
1863         char           d_name[1];
1864 };
1865
1866 struct irix_dirent64_callback {
1867         struct irix_dirent64 *curr;
1868         struct irix_dirent64 *previous;
1869         int count;
1870         int error;
1871 };
1872
1873 #define NAME_OFFSET64(de) ((int) ((de)->d_name - (char *) (de)))
1874 #define ROUND_UP64(x) (((x)+sizeof(u64)-1) & ~(sizeof(u64)-1))
1875
1876 static int irix_filldir64(void * __buf, const char * name, int namlen,
1877                           loff_t offset, ino_t ino, unsigned int d_type)
1878 {
1879         struct irix_dirent64 *dirent;
1880         struct irix_dirent64_callback * buf =
1881                 (struct irix_dirent64_callback *) __buf;
1882         unsigned short reclen = ROUND_UP64(NAME_OFFSET64(dirent) + namlen + 1);
1883
1884         buf->error = -EINVAL;   /* only used if we fail.. */
1885         if (reclen > buf->count)
1886                 return -EINVAL;
1887         dirent = buf->previous;
1888         if (dirent)
1889                 __put_user(offset, &dirent->d_off);
1890         dirent = buf->curr;
1891         buf->previous = dirent;
1892         __put_user(ino, &dirent->d_ino);
1893         __put_user(reclen, &dirent->d_reclen);
1894         __copy_to_user(dirent->d_name, name, namlen);
1895         __put_user(0, &dirent->d_name[namlen]);
1896         ((char *) dirent) += reclen;
1897         buf->curr = dirent;
1898         buf->count -= reclen;
1899
1900         return 0;
1901 }
1902
1903 asmlinkage int irix_getdents64(int fd, void *dirent, int cnt)
1904 {
1905         struct file *file;
1906         struct irix_dirent64 *lastdirent;
1907         struct irix_dirent64_callback buf;
1908         int error;
1909
1910 #ifdef DEBUG_GETDENTS
1911         printk("[%s:%d] getdents64(%d, %p, %d) ", current->comm,
1912                current->pid, fd, dirent, cnt);
1913 #endif
1914         error = -EBADF;
1915         if (!(file = fget(fd)))
1916                 goto out;
1917
1918         error = -EFAULT;
1919         if (!access_ok(VERIFY_WRITE, dirent, cnt))
1920                 goto out_f;
1921
1922         error = -EINVAL;
1923         if (cnt < (sizeof(struct irix_dirent64) + 255))
1924                 goto out_f;
1925
1926         buf.curr = (struct irix_dirent64 *) dirent;
1927         buf.previous = NULL;
1928         buf.count = cnt;
1929         buf.error = 0;
1930         error = vfs_readdir(file, irix_filldir64, &buf);
1931         if (error < 0)
1932                 goto out_f;
1933         lastdirent = buf.previous;
1934         if (!lastdirent) {
1935                 error = buf.error;
1936                 goto out_f;
1937         }
1938         lastdirent->d_off = (u64) file->f_pos;
1939 #ifdef DEBUG_GETDENTS
1940         printk("returning %d\n", cnt - buf.count);
1941 #endif
1942         error = cnt - buf.count;
1943
1944 out_f:
1945         fput(file);
1946 out:
1947         return error;
1948 }
1949
1950 asmlinkage int irix_ngetdents64(int fd, void *dirent, int cnt, int *eob)
1951 {
1952         struct file *file;
1953         struct irix_dirent64 *lastdirent;
1954         struct irix_dirent64_callback buf;
1955         int error;
1956
1957 #ifdef DEBUG_GETDENTS
1958         printk("[%s:%d] ngetdents64(%d, %p, %d) ", current->comm,
1959                current->pid, fd, dirent, cnt);
1960 #endif
1961         error = -EBADF;
1962         if (!(file = fget(fd)))
1963                 goto out;
1964
1965         error = -EFAULT;
1966         if (!access_ok(VERIFY_WRITE, dirent, cnt) ||
1967             !access_ok(VERIFY_WRITE, eob, sizeof(*eob)))
1968                 goto out_f;
1969
1970         error = -EINVAL;
1971         if (cnt < (sizeof(struct irix_dirent64) + 255))
1972                 goto out_f;
1973
1974         *eob = 0;
1975         buf.curr = (struct irix_dirent64 *) dirent;
1976         buf.previous = NULL;
1977         buf.count = cnt;
1978         buf.error = 0;
1979         error = vfs_readdir(file, irix_filldir64, &buf);
1980         if (error < 0)
1981                 goto out_f;
1982         lastdirent = buf.previous;
1983         if (!lastdirent) {
1984                 error = buf.error;
1985                 goto out_f;
1986         }
1987         lastdirent->d_off = (u64) file->f_pos;
1988 #ifdef DEBUG_GETDENTS
1989         printk("eob=%d returning %d\n", *eob, cnt - buf.count);
1990 #endif
1991         error = cnt - buf.count;
1992
1993 out_f:
1994         fput(file);
1995 out:
1996         return error;
1997 }
1998
1999 asmlinkage int irix_uadmin(unsigned long op, unsigned long func, unsigned long arg)
2000 {
2001         int retval;
2002
2003         switch (op) {
2004         case 1:
2005                 /* Reboot */
2006                 printk("[%s:%d] irix_uadmin: Wants to reboot...\n",
2007                        current->comm, current->pid);
2008                 retval = -EINVAL;
2009                 goto out;
2010
2011         case 2:
2012                 /* Shutdown */
2013                 printk("[%s:%d] irix_uadmin: Wants to shutdown...\n",
2014                        current->comm, current->pid);
2015                 retval = -EINVAL;
2016                 goto out;
2017
2018         case 4:
2019                 /* Remount-root */
2020                 printk("[%s:%d] irix_uadmin: Wants to remount root...\n",
2021                        current->comm, current->pid);
2022                 retval = -EINVAL;
2023                 goto out;
2024
2025         case 8:
2026                 /* Kill all tasks. */
2027                 printk("[%s:%d] irix_uadmin: Wants to kill all tasks...\n",
2028                        current->comm, current->pid);
2029                 retval = -EINVAL;
2030                 goto out;
2031
2032         case 256:
2033                 /* Set magic mushrooms... */
2034                 printk("[%s:%d] irix_uadmin: Wants to set magic mushroom[%d]...\n",
2035                        current->comm, current->pid, (int) func);
2036                 retval = -EINVAL;
2037                 goto out;
2038
2039         default:
2040                 printk("[%s:%d] irix_uadmin: Unknown operation [%d]...\n",
2041                        current->comm, current->pid, (int) op);
2042                 retval = -EINVAL;
2043                 goto out;
2044         };
2045
2046 out:
2047         return retval;
2048 }
2049
2050 asmlinkage int irix_utssys(char *inbuf, int arg, int type, char *outbuf)
2051 {
2052         int retval;
2053
2054         switch(type) {
2055         case 0:
2056                 /* uname() */
2057                 retval = irix_uname((struct iuname *)inbuf);
2058                 goto out;
2059
2060         case 2:
2061                 /* ustat() */
2062                 printk("[%s:%d] irix_utssys: Wants to do ustat()\n",
2063                        current->comm, current->pid);
2064                 retval = -EINVAL;
2065                 goto out;
2066
2067         case 3:
2068                 /* fusers() */
2069                 printk("[%s:%d] irix_utssys: Wants to do fusers()\n",
2070                        current->comm, current->pid);
2071                 retval = -EINVAL;
2072                 goto out;
2073
2074         default:
2075                 printk("[%s:%d] irix_utssys: Wants to do unknown type[%d]\n",
2076                        current->comm, current->pid, (int) type);
2077                 retval = -EINVAL;
2078                 goto out;
2079         }
2080
2081 out:
2082         return retval;
2083 }
2084
2085 #undef DEBUG_FCNTL
2086
2087 #define IRIX_F_ALLOCSP 10
2088
2089 asmlinkage int irix_fcntl(int fd, int cmd, int arg)
2090 {
2091         int retval;
2092
2093 #ifdef DEBUG_FCNTL
2094         printk("[%s:%d] irix_fcntl(%d, %d, %d) ", current->comm,
2095                current->pid, fd, cmd, arg);
2096 #endif
2097         if (cmd == IRIX_F_ALLOCSP){
2098                 return 0;
2099         }
2100         retval = sys_fcntl(fd, cmd, arg);
2101 #ifdef DEBUG_FCNTL
2102         printk("%d\n", retval);
2103 #endif
2104         return retval;
2105 }
2106
2107 asmlinkage int irix_ulimit(int cmd, int arg)
2108 {
2109         int retval;
2110
2111         switch(cmd) {
2112         case 1:
2113                 printk("[%s:%d] irix_ulimit: Wants to get file size limit.\n",
2114                        current->comm, current->pid);
2115                 retval = -EINVAL;
2116                 goto out;
2117
2118         case 2:
2119                 printk("[%s:%d] irix_ulimit: Wants to set file size limit.\n",
2120                        current->comm, current->pid);
2121                 retval = -EINVAL;
2122                 goto out;
2123
2124         case 3:
2125                 printk("[%s:%d] irix_ulimit: Wants to get brk limit.\n",
2126                        current->comm, current->pid);
2127                 retval = -EINVAL;
2128                 goto out;
2129
2130         case 4:
2131 #if 0
2132                 printk("[%s:%d] irix_ulimit: Wants to get fd limit.\n",
2133                        current->comm, current->pid);
2134                 retval = -EINVAL;
2135                 goto out;
2136 #endif
2137                 retval = current->rlim[RLIMIT_NOFILE].rlim_cur;
2138                 goto out;
2139
2140         case 5:
2141                 printk("[%s:%d] irix_ulimit: Wants to get txt offset.\n",
2142                        current->comm, current->pid);
2143                 retval = -EINVAL;
2144                 goto out;
2145
2146         default:
2147                 printk("[%s:%d] irix_ulimit: Unknown command [%d].\n",
2148                        current->comm, current->pid, cmd);
2149                 retval = -EINVAL;
2150                 goto out;
2151         }
2152 out:
2153         return retval;
2154 }
2155
2156 asmlinkage int irix_unimp(struct pt_regs *regs)
2157 {
2158         printk("irix_unimp [%s:%d] v0=%d v1=%d a0=%08lx a1=%08lx a2=%08lx "
2159                "a3=%08lx\n", current->comm, current->pid,
2160                (int) regs->regs[2], (int) regs->regs[3],
2161                regs->regs[4], regs->regs[5], regs->regs[6], regs->regs[7]);
2162
2163         return -ENOSYS;
2164 }