patch-2.6.6-vs1.9.0
[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                 !vx_vmpages_avail(mm, (newbrk-oldbrk) >> PAGE_SHIFT)) {
582                 ret = -ENOMEM;
583                 goto out;
584         }
585
586         /*
587          * Ok, looks good - let it rip.
588          */
589         mm->brk = brk;
590         do_brk(oldbrk, newbrk-oldbrk);
591         ret = 0;
592
593 out:
594         up_write(&mm->mmap_sem);
595         return ret;
596 }
597
598 asmlinkage int irix_getpid(struct pt_regs *regs)
599 {
600         regs->regs[3] = current->real_parent->pid;
601         return current->pid;
602 }
603
604 asmlinkage int irix_getuid(struct pt_regs *regs)
605 {
606         regs->regs[3] = current->euid;
607         return current->uid;
608 }
609
610 asmlinkage int irix_getgid(struct pt_regs *regs)
611 {
612         regs->regs[3] = current->egid;
613         return current->gid;
614 }
615
616 asmlinkage int irix_stime(int value)
617 {
618         if (!capable(CAP_SYS_TIME))
619                 return -EPERM;
620
621         write_seqlock_irq(&xtime_lock);
622         xtime.tv_sec = value;
623         xtime.tv_nsec = 0;
624         time_adjust = 0;                        /* stop active adjtime() */
625         time_status |= STA_UNSYNC;
626         time_maxerror = NTP_PHASE_LIMIT;
627         time_esterror = NTP_PHASE_LIMIT;
628         write_sequnlock_irq(&xtime_lock);
629
630         return 0;
631 }
632
633 static inline void jiffiestotv(unsigned long jiffies, struct timeval *value)
634 {
635         value->tv_usec = (jiffies % HZ) * (1000000 / HZ);
636         value->tv_sec = jiffies / HZ;
637 }
638
639 static inline void getitimer_real(struct itimerval *value)
640 {
641         register unsigned long val, interval;
642
643         interval = current->it_real_incr;
644         val = 0;
645         if (del_timer(&current->real_timer)) {
646                 unsigned long now = jiffies;
647                 val = current->real_timer.expires;
648                 add_timer(&current->real_timer);
649                 /* look out for negative/zero itimer.. */
650                 if (val <= now)
651                         val = now+1;
652                 val -= now;
653         }
654         jiffiestotv(val, &value->it_value);
655         jiffiestotv(interval, &value->it_interval);
656 }
657
658 asmlinkage unsigned int irix_alarm(unsigned int seconds)
659 {
660         struct itimerval it_new, it_old;
661         unsigned int oldalarm;
662
663         if (!seconds) {
664                 getitimer_real(&it_old);
665                 del_timer(&current->real_timer);
666         } else {
667                 it_new.it_interval.tv_sec = it_new.it_interval.tv_usec = 0;
668                 it_new.it_value.tv_sec = seconds;
669                 it_new.it_value.tv_usec = 0;
670                 do_setitimer(ITIMER_REAL, &it_new, &it_old);
671         }
672         oldalarm = it_old.it_value.tv_sec;
673         /*
674          * ehhh.. We can't return 0 if we have an alarm pending ...
675          * And we'd better return too much than too little anyway
676          */
677         if (it_old.it_value.tv_usec)
678                 oldalarm++;
679
680         return oldalarm;
681 }
682
683 asmlinkage int irix_pause(void)
684 {
685         current->state = TASK_INTERRUPTIBLE;
686         schedule();
687
688         return -EINTR;
689 }
690
691 /* XXX need more than this... */
692 asmlinkage int irix_mount(char *dev_name, char *dir_name, unsigned long flags,
693                           char *type, void *data, int datalen)
694 {
695         printk("[%s:%d] irix_mount(%p,%p,%08lx,%p,%p,%d)\n",
696                current->comm, current->pid,
697                dev_name, dir_name, flags, type, data, datalen);
698
699         return sys_mount(dev_name, dir_name, type, flags, data);
700 }
701
702 struct irix_statfs {
703         short f_type;
704         long  f_bsize, f_frsize, f_blocks, f_bfree, f_files, f_ffree;
705         char  f_fname[6], f_fpack[6];
706 };
707
708 asmlinkage int irix_statfs(const char *path, struct irix_statfs *buf,
709                            int len, int fs_type)
710 {
711         struct nameidata nd;
712         struct kstatfs kbuf;
713         int error, i;
714
715         /* We don't support this feature yet. */
716         if (fs_type) {
717                 error = -EINVAL;
718                 goto out;
719         }
720         error = verify_area(VERIFY_WRITE, buf, sizeof(struct irix_statfs));
721         if (error)
722                 goto out;
723         error = user_path_walk(path, &nd);
724         if (error)
725                 goto out;
726
727         error = vfs_statfs(nd.dentry->d_inode->i_sb, &kbuf);
728         if (error)
729                 goto dput_and_out;
730
731         __put_user(kbuf.f_type, &buf->f_type);
732         __put_user(kbuf.f_bsize, &buf->f_bsize);
733         __put_user(kbuf.f_frsize, &buf->f_frsize);
734         __put_user(kbuf.f_blocks, &buf->f_blocks);
735         __put_user(kbuf.f_bfree, &buf->f_bfree);
736         __put_user(kbuf.f_files, &buf->f_files);
737         __put_user(kbuf.f_ffree, &buf->f_ffree);
738         for (i = 0; i < 6; i++) {
739                 __put_user(0, &buf->f_fname[i]);
740                 __put_user(0, &buf->f_fpack[i]);
741         }
742         error = 0;
743
744 dput_and_out:
745         path_release(&nd);
746 out:
747         return error;
748 }
749
750 asmlinkage int irix_fstatfs(unsigned int fd, struct irix_statfs *buf)
751 {
752         struct kstatfs kbuf;
753         struct file *file;
754         int error, i;
755
756         error = verify_area(VERIFY_WRITE, buf, sizeof(struct irix_statfs));
757         if (error)
758                 goto out;
759         if (!(file = fget(fd))) {
760                 error = -EBADF;
761                 goto out;
762         }
763
764         error = vfs_statfs(file->f_dentry->d_inode->i_sb, &kbuf);
765         if (error)
766                 goto out_f;
767
768         __put_user(kbuf.f_type, &buf->f_type);
769         __put_user(kbuf.f_bsize, &buf->f_bsize);
770         __put_user(kbuf.f_frsize, &buf->f_frsize);
771         __put_user(kbuf.f_blocks, &buf->f_blocks);
772         __put_user(kbuf.f_bfree, &buf->f_bfree);
773         __put_user(kbuf.f_files, &buf->f_files);
774         __put_user(kbuf.f_ffree, &buf->f_ffree);
775         for(i = 0; i < 6; i++) {
776                 __put_user(0, &buf->f_fname[i]);
777                 __put_user(0, &buf->f_fpack[i]);
778         }
779
780 out_f:
781         fput(file);
782 out:
783         return error;
784 }
785
786 asmlinkage int irix_setpgrp(int flags)
787 {
788         int error;
789
790 #ifdef DEBUG_PROCGRPS
791         printk("[%s:%d] setpgrp(%d) ", current->comm, current->pid, flags);
792 #endif
793         if(!flags)
794                 error = process_group(current);
795         else
796                 error = sys_setsid();
797 #ifdef DEBUG_PROCGRPS
798         printk("returning %d\n", process_group(current));
799 #endif
800
801         return error;
802 }
803
804 asmlinkage int irix_times(struct tms * tbuf)
805 {
806         int err = 0;
807
808         if (tbuf) {
809                 err = verify_area(VERIFY_WRITE,tbuf,sizeof *tbuf);
810                 if (err)
811                         return err;
812                 err |= __put_user(current->utime, &tbuf->tms_utime);
813                 err |= __put_user(current->stime, &tbuf->tms_stime);
814                 err |= __put_user(current->cutime, &tbuf->tms_cutime);
815                 err |= __put_user(current->cstime, &tbuf->tms_cstime);
816         }
817
818         return err;
819 }
820
821 asmlinkage int irix_exec(struct pt_regs *regs)
822 {
823         int error, base = 0;
824         char *filename;
825
826         if(regs->regs[2] == 1000)
827                 base = 1;
828         filename = getname((char *) (long)regs->regs[base + 4]);
829         error = PTR_ERR(filename);
830         if (IS_ERR(filename))
831                 return error;
832
833         error = do_execve(filename, (char **) (long)regs->regs[base + 5],
834                           (char **) 0, regs);
835         putname(filename);
836
837         return error;
838 }
839
840 asmlinkage int irix_exece(struct pt_regs *regs)
841 {
842         int error, base = 0;
843         char *filename;
844
845         if (regs->regs[2] == 1000)
846                 base = 1;
847         filename = getname((char *) (long)regs->regs[base + 4]);
848         error = PTR_ERR(filename);
849         if (IS_ERR(filename))
850                 return error;
851         error = do_execve(filename, (char **) (long)regs->regs[base + 5],
852                           (char **) (long)regs->regs[base + 6], regs);
853         putname(filename);
854
855         return error;
856 }
857
858 asmlinkage unsigned long irix_gethostid(void)
859 {
860         printk("[%s:%d]: irix_gethostid() called...\n",
861                current->comm, current->pid);
862
863         return -EINVAL;
864 }
865
866 asmlinkage unsigned long irix_sethostid(unsigned long val)
867 {
868         printk("[%s:%d]: irix_sethostid(%08lx) called...\n",
869                current->comm, current->pid, val);
870
871         return -EINVAL;
872 }
873
874 asmlinkage int irix_socket(int family, int type, int protocol)
875 {
876         switch(type) {
877         case 1:
878                 type = SOCK_DGRAM;
879                 break;
880
881         case 2:
882                 type = SOCK_STREAM;
883                 break;
884
885         case 3:
886                 type = 9; /* Invalid... */
887                 break;
888
889         case 4:
890                 type = SOCK_RAW;
891                 break;
892
893         case 5:
894                 type = SOCK_RDM;
895                 break;
896
897         case 6:
898                 type = SOCK_SEQPACKET;
899                 break;
900
901         default:
902                 break;
903         }
904
905         return sys_socket(family, type, protocol);
906 }
907
908 asmlinkage int irix_getdomainname(char *name, int len)
909 {
910         int error;
911
912         error = verify_area(VERIFY_WRITE, name, len);
913         if (error)
914                 return error;
915
916         down_read(&uts_sem);
917         if(len > (__NEW_UTS_LEN - 1))
918                 len = __NEW_UTS_LEN - 1;
919         error = 0;
920         if (copy_to_user(name, system_utsname.domainname, len))
921                 error = -EFAULT;
922         up_read(&uts_sem);
923
924         return error;
925 }
926
927 asmlinkage unsigned long irix_getpagesize(void)
928 {
929         return PAGE_SIZE;
930 }
931
932 asmlinkage int irix_msgsys(int opcode, unsigned long arg0, unsigned long arg1,
933                            unsigned long arg2, unsigned long arg3,
934                            unsigned long arg4)
935 {
936         switch (opcode) {
937         case 0:
938                 return sys_msgget((key_t) arg0, (int) arg1);
939         case 1:
940                 return sys_msgctl((int) arg0, (int) arg1, (struct msqid_ds *)arg2);
941         case 2:
942                 return sys_msgrcv((int) arg0, (struct msgbuf *) arg1,
943                                   (size_t) arg2, (long) arg3, (int) arg4);
944         case 3:
945                 return sys_msgsnd((int) arg0, (struct msgbuf *) arg1,
946                                   (size_t) arg2, (int) arg3);
947         default:
948                 return -EINVAL;
949         }
950 }
951
952 asmlinkage int irix_shmsys(int opcode, unsigned long arg0, unsigned long arg1,
953                            unsigned long arg2, unsigned long arg3)
954 {
955         switch (opcode) {
956         case 0:
957                 return do_shmat((int) arg0, (char *)arg1, (int) arg2,
958                                  (unsigned long *) arg3);
959         case 1:
960                 return sys_shmctl((int)arg0, (int)arg1, (struct shmid_ds *)arg2);
961         case 2:
962                 return sys_shmdt((char *)arg0);
963         case 3:
964                 return sys_shmget((key_t) arg0, (int) arg1, (int) arg2);
965         default:
966                 return -EINVAL;
967         }
968 }
969
970 asmlinkage int irix_semsys(int opcode, unsigned long arg0, unsigned long arg1,
971                            unsigned long arg2, int arg3)
972 {
973         switch (opcode) {
974         case 0:
975                 return sys_semctl((int) arg0, (int) arg1, (int) arg2,
976                                   (union semun) arg3);
977         case 1:
978                 return sys_semget((key_t) arg0, (int) arg1, (int) arg2);
979         case 2:
980                 return sys_semop((int) arg0, (struct sembuf *)arg1,
981                                  (unsigned int) arg2);
982         default:
983                 return -EINVAL;
984         }
985 }
986
987 static inline loff_t llseek(struct file *file, loff_t offset, int origin)
988 {
989         loff_t (*fn)(struct file *, loff_t, int);
990         loff_t retval;
991
992         fn = default_llseek;
993         if (file->f_op && file->f_op->llseek)
994         fn = file->f_op->llseek;
995         lock_kernel();
996         retval = fn(file, offset, origin);
997         unlock_kernel();
998         return retval;
999 }
1000
1001 asmlinkage int irix_lseek64(int fd, int _unused, int offhi, int offlow,
1002                             int origin)
1003 {
1004         int retval;
1005         struct file * file;
1006         loff_t offset;
1007
1008         retval = -EBADF;
1009         file = fget(fd);
1010         if (!file)
1011                 goto bad;
1012         retval = -EINVAL;
1013         if (origin > 2)
1014                 goto out_putf;
1015
1016         offset = llseek(file, ((loff_t) offhi << 32) | offlow, origin);
1017         retval = (int) offset;
1018
1019 out_putf:
1020         fput(file);
1021 bad:
1022         return retval;
1023 }
1024
1025 asmlinkage int irix_sginap(int ticks)
1026 {
1027         current->state = TASK_INTERRUPTIBLE;
1028         schedule_timeout(ticks);
1029         return 0;
1030 }
1031
1032 asmlinkage int irix_sgikopt(char *istring, char *ostring, int len)
1033 {
1034         return -EINVAL;
1035 }
1036
1037 asmlinkage int irix_gettimeofday(struct timeval *tv)
1038 {
1039         time_t sec;
1040         long nsec, seq;
1041         int err;
1042
1043         if (verify_area(VERIFY_WRITE, tv, sizeof(struct timeval)))
1044                 return -EFAULT;
1045
1046         do {
1047                 seq = read_seqbegin(&xtime_lock);
1048                 sec = xtime.tv_sec;
1049                 nsec = xtime.tv_nsec;
1050         } while (read_seqretry(&xtime_lock, seq));
1051
1052         err = __put_user(sec, &tv->tv_sec);
1053         err |= __put_user((nsec / 1000), &tv->tv_usec);
1054
1055         return err;
1056 }
1057
1058 #define IRIX_MAP_AUTOGROW 0x40
1059
1060 asmlinkage unsigned long irix_mmap32(unsigned long addr, size_t len, int prot,
1061                                      int flags, int fd, off_t offset)
1062 {
1063         struct file *file = NULL;
1064         unsigned long retval;
1065
1066         if (!(flags & MAP_ANONYMOUS)) {
1067                 if (!(file = fget(fd)))
1068                         return -EBADF;
1069
1070                 /* Ok, bad taste hack follows, try to think in something else
1071                  * when reading this.  */
1072                 if (flags & IRIX_MAP_AUTOGROW) {
1073                         unsigned long old_pos;
1074                         long max_size = offset + len;
1075
1076                         if (max_size > file->f_dentry->d_inode->i_size) {
1077                                 old_pos = sys_lseek (fd, max_size - 1, 0);
1078                                 sys_write (fd, "", 1);
1079                                 sys_lseek (fd, old_pos, 0);
1080                         }
1081                 }
1082         }
1083
1084         flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
1085
1086         down_write(&current->mm->mmap_sem);
1087         retval = do_mmap(file, addr, len, prot, flags, offset);
1088         up_write(&current->mm->mmap_sem);
1089         if (file)
1090                 fput(file);
1091
1092         return retval;
1093 }
1094
1095 asmlinkage int irix_madvise(unsigned long addr, int len, int behavior)
1096 {
1097         printk("[%s:%d] Wheee.. irix_madvise(%08lx,%d,%d)\n",
1098                current->comm, current->pid, addr, len, behavior);
1099
1100         return -EINVAL;
1101 }
1102
1103 asmlinkage int irix_pagelock(char *addr, int len, int op)
1104 {
1105         printk("[%s:%d] Wheee.. irix_pagelock(%p,%d,%d)\n",
1106                current->comm, current->pid, addr, len, op);
1107
1108         return -EINVAL;
1109 }
1110
1111 asmlinkage int irix_quotactl(struct pt_regs *regs)
1112 {
1113         printk("[%s:%d] Wheee.. irix_quotactl()\n",
1114                current->comm, current->pid);
1115
1116         return -EINVAL;
1117 }
1118
1119 asmlinkage int irix_BSDsetpgrp(int pid, int pgrp)
1120 {
1121         int error;
1122
1123 #ifdef DEBUG_PROCGRPS
1124         printk("[%s:%d] BSDsetpgrp(%d, %d) ", current->comm, current->pid,
1125                pid, pgrp);
1126 #endif
1127         if(!pid)
1128                 pid = current->pid;
1129
1130         /* Wheee, weird sysv thing... */
1131         if ((pgrp == 0) && (pid == current->pid))
1132                 error = sys_setsid();
1133         else
1134                 error = sys_setpgid(pid, pgrp);
1135
1136 #ifdef DEBUG_PROCGRPS
1137         printk("error = %d\n", error);
1138 #endif
1139
1140         return error;
1141 }
1142
1143 asmlinkage int irix_systeminfo(int cmd, char *buf, int cnt)
1144 {
1145         printk("[%s:%d] Wheee.. irix_systeminfo(%d,%p,%d)\n",
1146                current->comm, current->pid, cmd, buf, cnt);
1147
1148         return -EINVAL;
1149 }
1150
1151 struct iuname {
1152         char sysname[257], nodename[257], release[257];
1153         char version[257], machine[257];
1154         char m_type[257], base_rel[257];
1155         char _unused0[257], _unused1[257], _unused2[257];
1156         char _unused3[257], _unused4[257], _unused5[257];
1157 };
1158
1159 asmlinkage int irix_uname(struct iuname *buf)
1160 {
1161         down_read(&uts_sem);
1162         if (copy_to_user(system_utsname.sysname, buf->sysname, 65)
1163             || copy_to_user(system_utsname.nodename, buf->nodename, 65)
1164             || copy_to_user(system_utsname.release, buf->release, 65)
1165             || copy_to_user(system_utsname.version, buf->version, 65)
1166             || copy_to_user(system_utsname.machine, buf->machine, 65)) {
1167                 return -EFAULT;
1168         }
1169         up_read(&uts_sem);
1170
1171         return 1;
1172 }
1173
1174 #undef DEBUG_XSTAT
1175
1176 static int irix_xstat32_xlate(struct kstat *stat, void *ubuf)
1177 {
1178         struct xstat32 {
1179                 u32 st_dev, st_pad1[3], st_ino, st_mode, st_nlink, st_uid, st_gid;
1180                 u32 st_rdev, st_pad2[2], st_size, st_pad3;
1181                 u32 st_atime0, st_atime1;
1182                 u32 st_mtime0, st_mtime1;
1183                 u32 st_ctime0, st_ctime1;
1184                 u32 st_blksize, st_blocks;
1185                 char st_fstype[16];
1186                 u32 st_pad4[8];
1187         } ub;
1188
1189         if (!sysv_valid_dev(stat->dev) || !sysv_valid_dev(stat->rdev))
1190                 return -EOVERFLOW;
1191         ub.st_dev     = sysv_encode_dev(stat->dev);
1192         ub.st_ino     = stat->ino;
1193         ub.st_mode    = stat->mode;
1194         ub.st_nlink   = stat->nlink;
1195         SET_UID(ub.st_uid, stat->uid);
1196         SET_GID(ub.st_gid, stat->gid);
1197         ub.st_rdev    = sysv_encode_dev(stat->rdev);
1198 #if BITS_PER_LONG == 32
1199         if (stat->size > MAX_NON_LFS)
1200                 return -EOVERFLOW;
1201 #endif
1202         ub.st_size    = stat->size;
1203         ub.st_atime0  = stat->atime.tv_sec;
1204         ub.st_atime1  = stat->atime.tv_nsec;
1205         ub.st_mtime0  = stat->mtime.tv_sec;
1206         ub.st_mtime1  = stat->atime.tv_nsec;
1207         ub.st_ctime0  = stat->ctime.tv_sec;
1208         ub.st_ctime1  = stat->atime.tv_nsec;
1209         ub.st_blksize = stat->blksize;
1210         ub.st_blocks  = stat->blocks;
1211         strcpy (ub.st_fstype, "efs");
1212
1213         return copy_to_user(ubuf, &ub, sizeof(ub)) ? -EFAULT : 0;
1214 }
1215
1216 static int irix_xstat64_xlate(struct kstat *stat, void *ubuf)
1217 {
1218         struct xstat64 {
1219                 u32 st_dev; s32 st_pad1[3];
1220                 unsigned long long st_ino;
1221                 u32 st_mode;
1222                 u32 st_nlink; s32 st_uid; s32 st_gid; u32 st_rdev;
1223                 s32 st_pad2[2];
1224                 long long st_size;
1225                 s32 st_pad3;
1226                 struct { s32 tv_sec, tv_nsec; } st_atime, st_mtime, st_ctime;
1227                 s32 st_blksize;
1228                 long long  st_blocks;
1229                 char st_fstype[16];
1230                 s32 st_pad4[8];
1231         } ks;
1232
1233         if (!sysv_valid_dev(stat->dev) || !sysv_valid_dev(stat->rdev))
1234                 return -EOVERFLOW;
1235
1236         ks.st_dev = sysv_encode_dev(stat->dev);
1237         ks.st_pad1[0] = ks.st_pad1[1] = ks.st_pad1[2] = 0;
1238         ks.st_ino = (unsigned long long) stat->ino;
1239         ks.st_mode = (u32) stat->mode;
1240         ks.st_nlink = (u32) stat->nlink;
1241         ks.st_uid = (s32) stat->uid;
1242         ks.st_gid = (s32) stat->gid;
1243         ks.st_rdev = sysv_encode_dev (stat->rdev);
1244         ks.st_pad2[0] = ks.st_pad2[1] = 0;
1245         ks.st_size = (long long) stat->size;
1246         ks.st_pad3 = 0;
1247
1248         /* XXX hackety hack... */
1249         ks.st_atime.tv_sec = (s32) stat->atime.tv_sec;
1250         ks.st_atime.tv_nsec = stat->atime.tv_nsec;
1251         ks.st_mtime.tv_sec = (s32) stat->mtime.tv_sec;
1252         ks.st_mtime.tv_nsec = stat->mtime.tv_nsec;
1253         ks.st_ctime.tv_sec = (s32) stat->ctime.tv_sec;
1254         ks.st_ctime.tv_nsec = stat->ctime.tv_nsec;
1255
1256         ks.st_blksize = (s32) stat->blksize;
1257         ks.st_blocks = (long long) stat->blocks;
1258         memset(ks.st_fstype, 0, 16);
1259         ks.st_pad4[0] = ks.st_pad4[1] = ks.st_pad4[2] = ks.st_pad4[3] = 0;
1260         ks.st_pad4[4] = ks.st_pad4[5] = ks.st_pad4[6] = ks.st_pad4[7] = 0;
1261
1262         /* Now write it all back. */
1263         return copy_to_user(ubuf, &ks, sizeof(ks)) ? -EFAULT : 0;
1264 }
1265
1266 asmlinkage int irix_xstat(int version, char *filename, struct stat *statbuf)
1267 {
1268         int retval;
1269         struct kstat stat;
1270
1271 #ifdef DEBUG_XSTAT
1272         printk("[%s:%d] Wheee.. irix_xstat(%d,%s,%p) ",
1273                current->comm, current->pid, version, filename, statbuf);
1274 #endif
1275
1276         retval = vfs_stat(filename, &stat);
1277         if (!retval) {
1278                 switch(version) {
1279                         case 2:
1280                                 retval = irix_xstat32_xlate(&stat, statbuf);
1281                                 break;
1282                         case 3:
1283                                 retval = irix_xstat64_xlate(&stat, statbuf);
1284                                 break;
1285                         default:
1286                                 retval = -EINVAL;
1287                 }
1288         }
1289         return retval;
1290 }
1291
1292 asmlinkage int irix_lxstat(int version, char *filename, struct stat *statbuf)
1293 {
1294         int error;
1295         struct kstat stat;
1296
1297 #ifdef DEBUG_XSTAT
1298         printk("[%s:%d] Wheee.. irix_lxstat(%d,%s,%p) ",
1299                current->comm, current->pid, version, filename, statbuf);
1300 #endif
1301
1302         error = vfs_lstat(filename, &stat);
1303
1304         if (!error) {
1305                 switch (version) {
1306                         case 2:
1307                                 error = irix_xstat32_xlate(&stat, statbuf);
1308                                 break;
1309                         case 3:
1310                                 error = irix_xstat64_xlate(&stat, statbuf);
1311                                 break;
1312                         default:
1313                                 error = -EINVAL;
1314                 }
1315         }
1316         return error;
1317 }
1318
1319 asmlinkage int irix_fxstat(int version, int fd, struct stat *statbuf)
1320 {
1321         int error;
1322         struct kstat stat;
1323
1324 #ifdef DEBUG_XSTAT
1325         printk("[%s:%d] Wheee.. irix_fxstat(%d,%d,%p) ",
1326                current->comm, current->pid, version, fd, statbuf);
1327 #endif
1328
1329         error = vfs_fstat(fd, &stat);
1330         if (!error) {
1331                 switch (version) {
1332                         case 2:
1333                                 error = irix_xstat32_xlate(&stat, statbuf);
1334                                 break;
1335                         case 3:
1336                                 error = irix_xstat64_xlate(&stat, statbuf);
1337                                 break;
1338                         default:
1339                                 error = -EINVAL;
1340                 }
1341         }
1342         return error;
1343 }
1344
1345 asmlinkage int irix_xmknod(int ver, char *filename, int mode, unsigned dev)
1346 {
1347         int retval;
1348         printk("[%s:%d] Wheee.. irix_xmknod(%d,%s,%x,%x)\n",
1349                current->comm, current->pid, ver, filename, mode, dev);
1350
1351         switch(ver) {
1352         case 2:
1353                 /* shouldn't we convert here as well as on stat()? */
1354                 retval = sys_mknod(filename, mode, dev);
1355                 break;
1356
1357         default:
1358                 retval = -EINVAL;
1359                 break;
1360         };
1361
1362         return retval;
1363 }
1364
1365 asmlinkage int irix_swapctl(int cmd, char *arg)
1366 {
1367         printk("[%s:%d] Wheee.. irix_swapctl(%d,%p)\n",
1368                current->comm, current->pid, cmd, arg);
1369
1370         return -EINVAL;
1371 }
1372
1373 struct irix_statvfs {
1374         u32 f_bsize; u32 f_frsize; u32 f_blocks;
1375         u32 f_bfree; u32 f_bavail; u32 f_files; u32 f_ffree; u32 f_favail;
1376         u32 f_fsid; char f_basetype[16];
1377         u32 f_flag; u32 f_namemax;
1378         char    f_fstr[32]; u32 f_filler[16];
1379 };
1380
1381 asmlinkage int irix_statvfs(char *fname, struct irix_statvfs *buf)
1382 {
1383         struct nameidata nd;
1384         struct kstatfs kbuf;
1385         int error, i;
1386
1387         printk("[%s:%d] Wheee.. irix_statvfs(%s,%p)\n",
1388                current->comm, current->pid, fname, buf);
1389         error = verify_area(VERIFY_WRITE, buf, sizeof(struct irix_statvfs));
1390         if (error)
1391                 goto out;
1392         error = user_path_walk(fname, &nd);
1393         if (error)
1394                 goto out;
1395         error = vfs_statfs(nd.dentry->d_inode->i_sb, &kbuf);
1396         if (error)
1397                 goto dput_and_out;
1398
1399         __put_user(kbuf.f_bsize, &buf->f_bsize);
1400         __put_user(kbuf.f_frsize, &buf->f_frsize);
1401         __put_user(kbuf.f_blocks, &buf->f_blocks);
1402         __put_user(kbuf.f_bfree, &buf->f_bfree);
1403         __put_user(kbuf.f_bfree, &buf->f_bavail);  /* XXX hackety hack... */
1404         __put_user(kbuf.f_files, &buf->f_files);
1405         __put_user(kbuf.f_ffree, &buf->f_ffree);
1406         __put_user(kbuf.f_ffree, &buf->f_favail);  /* XXX hackety hack... */
1407 #ifdef __MIPSEB__
1408         __put_user(kbuf.f_fsid.val[1], &buf->f_fsid);
1409 #else
1410         __put_user(kbuf.f_fsid.val[0], &buf->f_fsid);
1411 #endif
1412         for (i = 0; i < 16; i++)
1413                 __put_user(0, &buf->f_basetype[i]);
1414         __put_user(0, &buf->f_flag);
1415         __put_user(kbuf.f_namelen, &buf->f_namemax);
1416         for (i = 0; i < 32; i++)
1417                 __put_user(0, &buf->f_fstr[i]);
1418
1419         error = 0;
1420
1421 dput_and_out:
1422         path_release(&nd);
1423 out:
1424         return error;
1425 }
1426
1427 asmlinkage int irix_fstatvfs(int fd, struct irix_statvfs *buf)
1428 {
1429         struct kstatfs kbuf;
1430         struct file *file;
1431         int error, i;
1432
1433         printk("[%s:%d] Wheee.. irix_fstatvfs(%d,%p)\n",
1434                current->comm, current->pid, fd, buf);
1435
1436         error = verify_area(VERIFY_WRITE, buf, sizeof(struct irix_statvfs));
1437         if (error)
1438                 goto out;
1439         if (!(file = fget(fd))) {
1440                 error = -EBADF;
1441                 goto out;
1442         }
1443         error = vfs_statfs(file->f_dentry->d_inode->i_sb, &kbuf);
1444         if (error)
1445                 goto out_f;
1446
1447         __put_user(kbuf.f_bsize, &buf->f_bsize);
1448         __put_user(kbuf.f_frsize, &buf->f_frsize);
1449         __put_user(kbuf.f_blocks, &buf->f_blocks);
1450         __put_user(kbuf.f_bfree, &buf->f_bfree);
1451         __put_user(kbuf.f_bfree, &buf->f_bavail); /* XXX hackety hack... */
1452         __put_user(kbuf.f_files, &buf->f_files);
1453         __put_user(kbuf.f_ffree, &buf->f_ffree);
1454         __put_user(kbuf.f_ffree, &buf->f_favail); /* XXX hackety hack... */
1455 #ifdef __MIPSEB__
1456         __put_user(kbuf.f_fsid.val[1], &buf->f_fsid);
1457 #else
1458         __put_user(kbuf.f_fsid.val[0], &buf->f_fsid);
1459 #endif
1460         for(i = 0; i < 16; i++)
1461                 __put_user(0, &buf->f_basetype[i]);
1462         __put_user(0, &buf->f_flag);
1463         __put_user(kbuf.f_namelen, &buf->f_namemax);
1464         __clear_user(&buf->f_fstr, sizeof(buf->f_fstr));
1465
1466 out_f:
1467         fput(file);
1468 out:
1469         return error;
1470 }
1471
1472 asmlinkage int irix_priocntl(struct pt_regs *regs)
1473 {
1474         printk("[%s:%d] Wheee.. irix_priocntl()\n",
1475                current->comm, current->pid);
1476
1477         return -EINVAL;
1478 }
1479
1480 asmlinkage int irix_sigqueue(int pid, int sig, int code, int val)
1481 {
1482         printk("[%s:%d] Wheee.. irix_sigqueue(%d,%d,%d,%d)\n",
1483                current->comm, current->pid, pid, sig, code, val);
1484
1485         return -EINVAL;
1486 }
1487
1488 asmlinkage int irix_truncate64(char *name, int pad, int size1, int size2)
1489 {
1490         int retval;
1491
1492         if (size1) {
1493                 retval = -EINVAL;
1494                 goto out;
1495         }
1496         retval = sys_truncate(name, size2);
1497
1498 out:
1499         return retval;
1500 }
1501
1502 asmlinkage int irix_ftruncate64(int fd, int pad, int size1, int size2)
1503 {
1504         int retval;
1505
1506         if (size1) {
1507                 retval = -EINVAL;
1508                 goto out;
1509         }
1510         retval = sys_ftruncate(fd, size2);
1511
1512 out:
1513         return retval;
1514 }
1515
1516 asmlinkage int irix_mmap64(struct pt_regs *regs)
1517 {
1518         int len, prot, flags, fd, off1, off2, error, base = 0;
1519         unsigned long addr, pgoff, *sp;
1520         struct file *file = NULL;
1521
1522         if (regs->regs[2] == 1000)
1523                 base = 1;
1524         sp = (unsigned long *) (regs->regs[29] + 16);
1525         addr = regs->regs[base + 4];
1526         len = regs->regs[base + 5];
1527         prot = regs->regs[base + 6];
1528         if (!base) {
1529                 flags = regs->regs[base + 7];
1530                 error = verify_area(VERIFY_READ, sp, (4 * sizeof(unsigned long)));
1531                 if(error)
1532                         goto out;
1533                 fd = sp[0];
1534                 __get_user(off1, &sp[1]);
1535                 __get_user(off2, &sp[2]);
1536         } else {
1537                 error = verify_area(VERIFY_READ, sp, (5 * sizeof(unsigned long)));
1538                 if(error)
1539                         goto out;
1540                 __get_user(flags, &sp[0]);
1541                 __get_user(fd, &sp[1]);
1542                 __get_user(off1, &sp[2]);
1543                 __get_user(off2, &sp[3]);
1544         }
1545
1546         if (off1 & PAGE_MASK) {
1547                 error = -EOVERFLOW;
1548                 goto out;
1549         }
1550
1551         pgoff = (off1 << (32 - PAGE_SHIFT)) | (off2 >> PAGE_SHIFT);
1552
1553         if (!(flags & MAP_ANONYMOUS)) {
1554                 if (!(file = fget(fd))) {
1555                         error = -EBADF;
1556                         goto out;
1557                 }
1558
1559                 /* Ok, bad taste hack follows, try to think in something else
1560                    when reading this */
1561                 if (flags & IRIX_MAP_AUTOGROW) {
1562                         unsigned long old_pos;
1563                         long max_size = off2 + len;
1564
1565                         if (max_size > file->f_dentry->d_inode->i_size) {
1566                                 old_pos = sys_lseek (fd, max_size - 1, 0);
1567                                 sys_write (fd, "", 1);
1568                                 sys_lseek (fd, old_pos, 0);
1569                         }
1570                 }
1571         }
1572
1573         flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
1574
1575         down_write(&current->mm->mmap_sem);
1576         error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
1577         up_write(&current->mm->mmap_sem);
1578
1579         if (file)
1580                 fput(file);
1581
1582 out:
1583         return error;
1584 }
1585
1586 asmlinkage int irix_dmi(struct pt_regs *regs)
1587 {
1588         printk("[%s:%d] Wheee.. irix_dmi()\n",
1589                current->comm, current->pid);
1590
1591         return -EINVAL;
1592 }
1593
1594 asmlinkage int irix_pread(int fd, char *buf, int cnt, int off64,
1595                           int off1, int off2)
1596 {
1597         printk("[%s:%d] Wheee.. irix_pread(%d,%p,%d,%d,%d,%d)\n",
1598                current->comm, current->pid, fd, buf, cnt, off64, off1, off2);
1599
1600         return -EINVAL;
1601 }
1602
1603 asmlinkage int irix_pwrite(int fd, char *buf, int cnt, int off64,
1604                            int off1, int off2)
1605 {
1606         printk("[%s:%d] Wheee.. irix_pwrite(%d,%p,%d,%d,%d,%d)\n",
1607                current->comm, current->pid, fd, buf, cnt, off64, off1, off2);
1608
1609         return -EINVAL;
1610 }
1611
1612 asmlinkage int irix_sgifastpath(int cmd, unsigned long arg0, unsigned long arg1,
1613                                 unsigned long arg2, unsigned long arg3,
1614                                 unsigned long arg4, unsigned long arg5)
1615 {
1616         printk("[%s:%d] Wheee.. irix_fastpath(%d,%08lx,%08lx,%08lx,%08lx,"
1617                "%08lx,%08lx)\n",
1618                current->comm, current->pid, cmd, arg0, arg1, arg2,
1619                arg3, arg4, arg5);
1620
1621         return -EINVAL;
1622 }
1623
1624 struct irix_statvfs64 {
1625         u32  f_bsize; u32 f_frsize;
1626         u64  f_blocks; u64 f_bfree; u64 f_bavail;
1627         u64  f_files; u64 f_ffree; u64 f_favail;
1628         u32  f_fsid;
1629         char f_basetype[16];
1630         u32  f_flag; u32 f_namemax;
1631         char f_fstr[32];
1632         u32  f_filler[16];
1633 };
1634
1635 asmlinkage int irix_statvfs64(char *fname, struct irix_statvfs64 *buf)
1636 {
1637         struct nameidata nd;
1638         struct kstatfs kbuf;
1639         int error, i;
1640
1641         printk("[%s:%d] Wheee.. irix_statvfs(%s,%p)\n",
1642                current->comm, current->pid, fname, buf);
1643         error = verify_area(VERIFY_WRITE, buf, sizeof(struct irix_statvfs));
1644         if(error)
1645                 goto out;
1646         error = user_path_walk(fname, &nd);
1647         if (error)
1648                 goto out;
1649         error = vfs_statfs(nd.dentry->d_inode->i_sb, &kbuf);
1650         if (error)
1651                 goto dput_and_out;
1652
1653         __put_user(kbuf.f_bsize, &buf->f_bsize);
1654         __put_user(kbuf.f_frsize, &buf->f_frsize);
1655         __put_user(kbuf.f_blocks, &buf->f_blocks);
1656         __put_user(kbuf.f_bfree, &buf->f_bfree);
1657         __put_user(kbuf.f_bfree, &buf->f_bavail);  /* XXX hackety hack... */
1658         __put_user(kbuf.f_files, &buf->f_files);
1659         __put_user(kbuf.f_ffree, &buf->f_ffree);
1660         __put_user(kbuf.f_ffree, &buf->f_favail);  /* XXX hackety hack... */
1661 #ifdef __MIPSEB__
1662         __put_user(kbuf.f_fsid.val[1], &buf->f_fsid);
1663 #else
1664         __put_user(kbuf.f_fsid.val[0], &buf->f_fsid);
1665 #endif
1666         for(i = 0; i < 16; i++)
1667                 __put_user(0, &buf->f_basetype[i]);
1668         __put_user(0, &buf->f_flag);
1669         __put_user(kbuf.f_namelen, &buf->f_namemax);
1670         for(i = 0; i < 32; i++)
1671                 __put_user(0, &buf->f_fstr[i]);
1672
1673         error = 0;
1674
1675 dput_and_out:
1676         path_release(&nd);
1677 out:
1678         return error;
1679 }
1680
1681 asmlinkage int irix_fstatvfs64(int fd, struct irix_statvfs *buf)
1682 {
1683         struct kstatfs kbuf;
1684         struct file *file;
1685         int error, i;
1686
1687         printk("[%s:%d] Wheee.. irix_fstatvfs(%d,%p)\n",
1688                current->comm, current->pid, fd, buf);
1689
1690         error = verify_area(VERIFY_WRITE, buf, sizeof(struct irix_statvfs));
1691         if (error)
1692                 goto out;
1693         if (!(file = fget(fd))) {
1694                 error = -EBADF;
1695                 goto out;
1696         }
1697         error = vfs_statfs(file->f_dentry->d_inode->i_sb, &kbuf);
1698         if (error)
1699                 goto out_f;
1700
1701         __put_user(kbuf.f_bsize, &buf->f_bsize);
1702         __put_user(kbuf.f_frsize, &buf->f_frsize);
1703         __put_user(kbuf.f_blocks, &buf->f_blocks);
1704         __put_user(kbuf.f_bfree, &buf->f_bfree);
1705         __put_user(kbuf.f_bfree, &buf->f_bavail);  /* XXX hackety hack... */
1706         __put_user(kbuf.f_files, &buf->f_files);
1707         __put_user(kbuf.f_ffree, &buf->f_ffree);
1708         __put_user(kbuf.f_ffree, &buf->f_favail);  /* XXX hackety hack... */
1709 #ifdef __MIPSEB__
1710         __put_user(kbuf.f_fsid.val[1], &buf->f_fsid);
1711 #else
1712         __put_user(kbuf.f_fsid.val[0], &buf->f_fsid);
1713 #endif
1714         for(i = 0; i < 16; i++)
1715                 __put_user(0, &buf->f_basetype[i]);
1716         __put_user(0, &buf->f_flag);
1717         __put_user(kbuf.f_namelen, &buf->f_namemax);
1718         __clear_user(buf->f_fstr, sizeof(buf->f_fstr[i]));
1719
1720 out_f:
1721         fput(file);
1722 out:
1723         return error;
1724 }
1725
1726 asmlinkage int irix_getmountid(char *fname, unsigned long *midbuf)
1727 {
1728         int err;
1729
1730         printk("[%s:%d] irix_getmountid(%s, %p)\n",
1731                current->comm, current->pid, fname, midbuf);
1732         err = verify_area(VERIFY_WRITE, midbuf, (sizeof(unsigned long) * 4));
1733         if (err)
1734                 return err;
1735
1736         /*
1737          * The idea with this system call is that when trying to determine
1738          * 'pwd' and it's a toss-up for some reason, userland can use the
1739          * fsid of the filesystem to try and make the right decision, but
1740          * we don't have this so for now. XXX
1741          */
1742         err |= __put_user(0, &midbuf[0]);
1743         err |= __put_user(0, &midbuf[1]);
1744         err |= __put_user(0, &midbuf[2]);
1745         err |= __put_user(0, &midbuf[3]);
1746
1747         return err;
1748 }
1749
1750 asmlinkage int irix_nsproc(unsigned long entry, unsigned long mask,
1751                            unsigned long arg, unsigned long sp, int slen)
1752 {
1753         printk("[%s:%d] Wheee.. irix_nsproc(%08lx,%08lx,%08lx,%08lx,%d)\n",
1754                current->comm, current->pid, entry, mask, arg, sp, slen);
1755
1756         return -EINVAL;
1757 }
1758
1759 #undef DEBUG_GETDENTS
1760
1761 struct irix_dirent32 {
1762         u32  d_ino;
1763         u32  d_off;
1764         unsigned short  d_reclen;
1765         char d_name[1];
1766 };
1767
1768 struct irix_dirent32_callback {
1769         struct irix_dirent32 *current_dir;
1770         struct irix_dirent32 *previous;
1771         int count;
1772         int error;
1773 };
1774
1775 #define NAME_OFFSET32(de) ((int) ((de)->d_name - (char *) (de)))
1776 #define ROUND_UP32(x) (((x)+sizeof(u32)-1) & ~(sizeof(u32)-1))
1777
1778 static int irix_filldir32(void *__buf, const char *name, int namlen,
1779                           loff_t offset, ino_t ino, unsigned int d_type)
1780 {
1781         struct irix_dirent32 *dirent;
1782         struct irix_dirent32_callback *buf =
1783                  (struct irix_dirent32_callback *)__buf;
1784         unsigned short reclen = ROUND_UP32(NAME_OFFSET32(dirent) + namlen + 1);
1785
1786 #ifdef DEBUG_GETDENTS
1787         printk("\nirix_filldir32[reclen<%d>namlen<%d>count<%d>]",
1788                reclen, namlen, buf->count);
1789 #endif
1790         buf->error = -EINVAL;   /* only used if we fail.. */
1791         if (reclen > buf->count)
1792                 return -EINVAL;
1793         dirent = buf->previous;
1794         if (dirent)
1795                 __put_user(offset, &dirent->d_off);
1796         dirent = buf->current_dir;
1797         buf->previous = dirent;
1798         __put_user(ino, &dirent->d_ino);
1799         __put_user(reclen, &dirent->d_reclen);
1800         copy_to_user(dirent->d_name, name, namlen);
1801         __put_user(0, &dirent->d_name[namlen]);
1802         ((char *) dirent) += reclen;
1803         buf->current_dir = dirent;
1804         buf->count -= reclen;
1805
1806         return 0;
1807 }
1808
1809 asmlinkage int irix_ngetdents(unsigned int fd, void * dirent,
1810         unsigned int count, int *eob)
1811 {
1812         struct file *file;
1813         struct irix_dirent32 *lastdirent;
1814         struct irix_dirent32_callback buf;
1815         int error;
1816
1817 #ifdef DEBUG_GETDENTS
1818         printk("[%s:%d] ngetdents(%d, %p, %d, %p) ", current->comm,
1819                current->pid, fd, dirent, count, eob);
1820 #endif
1821         error = -EBADF;
1822         file = fget(fd);
1823         if (!file)
1824                 goto out;
1825
1826         buf.current_dir = (struct irix_dirent32 *) dirent;
1827         buf.previous = NULL;
1828         buf.count = count;
1829         buf.error = 0;
1830
1831         error = vfs_readdir(file, irix_filldir32, &buf);
1832         if (error < 0)
1833                 goto out_putf;
1834
1835         error = buf.error;
1836         lastdirent = buf.previous;
1837         if (lastdirent) {
1838                 put_user(file->f_pos, &lastdirent->d_off);
1839                 error = count - buf.count;
1840         }
1841
1842         if (put_user(0, eob) < 0) {
1843                 error = -EFAULT;
1844                 goto out_putf;
1845         }
1846
1847 #ifdef DEBUG_GETDENTS
1848         printk("eob=%d returning %d\n", *eob, count - buf.count);
1849 #endif
1850         error = count - buf.count;
1851
1852 out_putf:
1853         fput(file);
1854 out:
1855         return error;
1856 }
1857
1858 struct irix_dirent64 {
1859         u64            d_ino;
1860         u64            d_off;
1861         unsigned short d_reclen;
1862         char           d_name[1];
1863 };
1864
1865 struct irix_dirent64_callback {
1866         struct irix_dirent64 *curr;
1867         struct irix_dirent64 *previous;
1868         int count;
1869         int error;
1870 };
1871
1872 #define NAME_OFFSET64(de) ((int) ((de)->d_name - (char *) (de)))
1873 #define ROUND_UP64(x) (((x)+sizeof(u64)-1) & ~(sizeof(u64)-1))
1874
1875 static int irix_filldir64(void * __buf, const char * name, int namlen,
1876                           loff_t offset, ino_t ino, unsigned int d_type)
1877 {
1878         struct irix_dirent64 *dirent;
1879         struct irix_dirent64_callback * buf =
1880                 (struct irix_dirent64_callback *) __buf;
1881         unsigned short reclen = ROUND_UP64(NAME_OFFSET64(dirent) + namlen + 1);
1882
1883         buf->error = -EINVAL;   /* only used if we fail.. */
1884         if (reclen > buf->count)
1885                 return -EINVAL;
1886         dirent = buf->previous;
1887         if (dirent)
1888                 __put_user(offset, &dirent->d_off);
1889         dirent = buf->curr;
1890         buf->previous = dirent;
1891         __put_user(ino, &dirent->d_ino);
1892         __put_user(reclen, &dirent->d_reclen);
1893         __copy_to_user(dirent->d_name, name, namlen);
1894         __put_user(0, &dirent->d_name[namlen]);
1895         ((char *) dirent) += reclen;
1896         buf->curr = dirent;
1897         buf->count -= reclen;
1898
1899         return 0;
1900 }
1901
1902 asmlinkage int irix_getdents64(int fd, void *dirent, int cnt)
1903 {
1904         struct file *file;
1905         struct irix_dirent64 *lastdirent;
1906         struct irix_dirent64_callback buf;
1907         int error;
1908
1909 #ifdef DEBUG_GETDENTS
1910         printk("[%s:%d] getdents64(%d, %p, %d) ", current->comm,
1911                current->pid, fd, dirent, cnt);
1912 #endif
1913         error = -EBADF;
1914         if (!(file = fget(fd)))
1915                 goto out;
1916
1917         error = -EFAULT;
1918         if (!access_ok(VERIFY_WRITE, dirent, cnt))
1919                 goto out_f;
1920
1921         error = -EINVAL;
1922         if (cnt < (sizeof(struct irix_dirent64) + 255))
1923                 goto out_f;
1924
1925         buf.curr = (struct irix_dirent64 *) dirent;
1926         buf.previous = NULL;
1927         buf.count = cnt;
1928         buf.error = 0;
1929         error = vfs_readdir(file, irix_filldir64, &buf);
1930         if (error < 0)
1931                 goto out_f;
1932         lastdirent = buf.previous;
1933         if (!lastdirent) {
1934                 error = buf.error;
1935                 goto out_f;
1936         }
1937         lastdirent->d_off = (u64) file->f_pos;
1938 #ifdef DEBUG_GETDENTS
1939         printk("returning %d\n", cnt - buf.count);
1940 #endif
1941         error = cnt - buf.count;
1942
1943 out_f:
1944         fput(file);
1945 out:
1946         return error;
1947 }
1948
1949 asmlinkage int irix_ngetdents64(int fd, void *dirent, int cnt, int *eob)
1950 {
1951         struct file *file;
1952         struct irix_dirent64 *lastdirent;
1953         struct irix_dirent64_callback buf;
1954         int error;
1955
1956 #ifdef DEBUG_GETDENTS
1957         printk("[%s:%d] ngetdents64(%d, %p, %d) ", current->comm,
1958                current->pid, fd, dirent, cnt);
1959 #endif
1960         error = -EBADF;
1961         if (!(file = fget(fd)))
1962                 goto out;
1963
1964         error = -EFAULT;
1965         if (!access_ok(VERIFY_WRITE, dirent, cnt) ||
1966             !access_ok(VERIFY_WRITE, eob, sizeof(*eob)))
1967                 goto out_f;
1968
1969         error = -EINVAL;
1970         if (cnt < (sizeof(struct irix_dirent64) + 255))
1971                 goto out_f;
1972
1973         *eob = 0;
1974         buf.curr = (struct irix_dirent64 *) dirent;
1975         buf.previous = NULL;
1976         buf.count = cnt;
1977         buf.error = 0;
1978         error = vfs_readdir(file, irix_filldir64, &buf);
1979         if (error < 0)
1980                 goto out_f;
1981         lastdirent = buf.previous;
1982         if (!lastdirent) {
1983                 error = buf.error;
1984                 goto out_f;
1985         }
1986         lastdirent->d_off = (u64) file->f_pos;
1987 #ifdef DEBUG_GETDENTS
1988         printk("eob=%d returning %d\n", *eob, cnt - buf.count);
1989 #endif
1990         error = cnt - buf.count;
1991
1992 out_f:
1993         fput(file);
1994 out:
1995         return error;
1996 }
1997
1998 asmlinkage int irix_uadmin(unsigned long op, unsigned long func, unsigned long arg)
1999 {
2000         int retval;
2001
2002         switch (op) {
2003         case 1:
2004                 /* Reboot */
2005                 printk("[%s:%d] irix_uadmin: Wants to reboot...\n",
2006                        current->comm, current->pid);
2007                 retval = -EINVAL;
2008                 goto out;
2009
2010         case 2:
2011                 /* Shutdown */
2012                 printk("[%s:%d] irix_uadmin: Wants to shutdown...\n",
2013                        current->comm, current->pid);
2014                 retval = -EINVAL;
2015                 goto out;
2016
2017         case 4:
2018                 /* Remount-root */
2019                 printk("[%s:%d] irix_uadmin: Wants to remount root...\n",
2020                        current->comm, current->pid);
2021                 retval = -EINVAL;
2022                 goto out;
2023
2024         case 8:
2025                 /* Kill all tasks. */
2026                 printk("[%s:%d] irix_uadmin: Wants to kill all tasks...\n",
2027                        current->comm, current->pid);
2028                 retval = -EINVAL;
2029                 goto out;
2030
2031         case 256:
2032                 /* Set magic mushrooms... */
2033                 printk("[%s:%d] irix_uadmin: Wants to set magic mushroom[%d]...\n",
2034                        current->comm, current->pid, (int) func);
2035                 retval = -EINVAL;
2036                 goto out;
2037
2038         default:
2039                 printk("[%s:%d] irix_uadmin: Unknown operation [%d]...\n",
2040                        current->comm, current->pid, (int) op);
2041                 retval = -EINVAL;
2042                 goto out;
2043         };
2044
2045 out:
2046         return retval;
2047 }
2048
2049 asmlinkage int irix_utssys(char *inbuf, int arg, int type, char *outbuf)
2050 {
2051         int retval;
2052
2053         switch(type) {
2054         case 0:
2055                 /* uname() */
2056                 retval = irix_uname((struct iuname *)inbuf);
2057                 goto out;
2058
2059         case 2:
2060                 /* ustat() */
2061                 printk("[%s:%d] irix_utssys: Wants to do ustat()\n",
2062                        current->comm, current->pid);
2063                 retval = -EINVAL;
2064                 goto out;
2065
2066         case 3:
2067                 /* fusers() */
2068                 printk("[%s:%d] irix_utssys: Wants to do fusers()\n",
2069                        current->comm, current->pid);
2070                 retval = -EINVAL;
2071                 goto out;
2072
2073         default:
2074                 printk("[%s:%d] irix_utssys: Wants to do unknown type[%d]\n",
2075                        current->comm, current->pid, (int) type);
2076                 retval = -EINVAL;
2077                 goto out;
2078         }
2079
2080 out:
2081         return retval;
2082 }
2083
2084 #undef DEBUG_FCNTL
2085
2086 #define IRIX_F_ALLOCSP 10
2087
2088 asmlinkage int irix_fcntl(int fd, int cmd, int arg)
2089 {
2090         int retval;
2091
2092 #ifdef DEBUG_FCNTL
2093         printk("[%s:%d] irix_fcntl(%d, %d, %d) ", current->comm,
2094                current->pid, fd, cmd, arg);
2095 #endif
2096         if (cmd == IRIX_F_ALLOCSP){
2097                 return 0;
2098         }
2099         retval = sys_fcntl(fd, cmd, arg);
2100 #ifdef DEBUG_FCNTL
2101         printk("%d\n", retval);
2102 #endif
2103         return retval;
2104 }
2105
2106 asmlinkage int irix_ulimit(int cmd, int arg)
2107 {
2108         int retval;
2109
2110         switch(cmd) {
2111         case 1:
2112                 printk("[%s:%d] irix_ulimit: Wants to get file size limit.\n",
2113                        current->comm, current->pid);
2114                 retval = -EINVAL;
2115                 goto out;
2116
2117         case 2:
2118                 printk("[%s:%d] irix_ulimit: Wants to set file size limit.\n",
2119                        current->comm, current->pid);
2120                 retval = -EINVAL;
2121                 goto out;
2122
2123         case 3:
2124                 printk("[%s:%d] irix_ulimit: Wants to get brk limit.\n",
2125                        current->comm, current->pid);
2126                 retval = -EINVAL;
2127                 goto out;
2128
2129         case 4:
2130 #if 0
2131                 printk("[%s:%d] irix_ulimit: Wants to get fd limit.\n",
2132                        current->comm, current->pid);
2133                 retval = -EINVAL;
2134                 goto out;
2135 #endif
2136                 retval = current->rlim[RLIMIT_NOFILE].rlim_cur;
2137                 goto out;
2138
2139         case 5:
2140                 printk("[%s:%d] irix_ulimit: Wants to get txt offset.\n",
2141                        current->comm, current->pid);
2142                 retval = -EINVAL;
2143                 goto out;
2144
2145         default:
2146                 printk("[%s:%d] irix_ulimit: Unknown command [%d].\n",
2147                        current->comm, current->pid, cmd);
2148                 retval = -EINVAL;
2149                 goto out;
2150         }
2151 out:
2152         return retval;
2153 }
2154
2155 asmlinkage int irix_unimp(struct pt_regs *regs)
2156 {
2157         printk("irix_unimp [%s:%d] v0=%d v1=%d a0=%08lx a1=%08lx a2=%08lx "
2158                "a3=%08lx\n", current->comm, current->pid,
2159                (int) regs->regs[2], (int) regs->regs[3],
2160                regs->regs[4], regs->regs[5], regs->regs[6], regs->regs[7]);
2161
2162         return -ENOSYS;
2163 }