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