Squash another dozen warnings.
[linux-2.6/linux-mips.git] / arch / mips / kernel / sysirix.c
blob620fd87d72bc6a4cc26c31fc6bd0f52ee190b266
1 /*
2 * sysirix.c: IRIX system call emulation.
4 * Copyright (C) 1996 David S. Miller
5 * Copyright (C) 1997 Miguel de Icaza
6 * Copyright (C) 1997, 1998, 1999, 2000 Ralf Baechle
7 */
8 #include <linux/kernel.h>
9 #include <linux/sched.h>
10 #include <linux/binfmts.h>
11 #include <linux/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>
33 #include <asm/ptrace.h>
34 #include <asm/page.h>
35 #include <asm/pgalloc.h>
36 #include <asm/uaccess.h>
37 #include <asm/inventory.h>
39 /* 2,191 lines of complete and utter shit coming up... */
41 extern int max_threads;
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. */
48 asmlinkage int irix_sysmp(struct pt_regs *regs)
50 unsigned long cmd;
51 int base = 0;
52 int error = 0;
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;
72 return error;
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. */
93 asmlinkage int irix_prctl(struct pt_regs *regs)
95 unsigned long cmd;
96 int error = 0, base = 0;
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;
108 case PR_ISBLOCKED: {
109 struct task_struct *task;
111 printk("irix_prctl[%s:%d]: Wants PR_ISBLOCKED\n",
112 current->comm, current->pid);
113 read_lock(&tasklist_lock);
114 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;
123 case PR_SETSTACKSIZE: {
124 long value = regs->regs[base + 5];
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;
136 if (value > current->rlim[RLIMIT_STACK].rlim_max) {
137 error = -EINVAL;
138 break;
140 current->rlim[RLIMIT_STACK].rlim_cur = value;
141 error = value;
142 break;
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;
151 case PR_MAXPPROCS:
152 printk("irix_prctl[%s:%d]: Wants PR_MAXPROCS\n",
153 current->comm, current->pid);
154 error = 1;
155 break;
157 case PR_UNBLKONEXEC:
158 printk("irix_prctl[%s:%d]: Wants PR_UNBLKONEXEC\n",
159 current->comm, current->pid);
160 error = -EINVAL;
161 break;
163 case PR_SETEXITSIG:
164 printk("irix_prctl[%s:%d]: Wants PR_SETEXITSIG\n",
165 current->comm, current->pid);
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().
171 error = -EINVAL;
172 break;
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;
180 case PR_ATTACHADDR:
181 printk("irix_prctl[%s:%d]: Wants PR_ATTACHADDR\n",
182 current->comm, current->pid);
183 error = -EINVAL;
184 break;
186 case PR_DETACHADDR:
187 printk("irix_prctl[%s:%d]: Wants PR_DETACHADDR\n",
188 current->comm, current->pid);
189 error = -EINVAL;
190 break;
192 case PR_TERMCHILD:
193 printk("irix_prctl[%s:%d]: Wants PR_TERMCHILD\n",
194 current->comm, current->pid);
195 error = -EINVAL;
196 break;
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;
204 case PR_GETNSHARE:
205 error = 0; /* Until I have the sproc() stuff in. */
206 break;
208 case PR_COREPID:
209 printk("irix_prctl[%s:%d]: Wants PR_COREPID\n",
210 current->comm, current->pid);
211 error = -EINVAL;
212 break;
214 case PR_ATTACHADDRPERM:
215 printk("irix_prctl[%s:%d]: Wants PR_ATTACHADDRPERM\n",
216 current->comm, current->pid);
217 error = -EINVAL;
218 break;
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]);
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;
232 return error;
235 #undef DEBUG_PROCGRPS
237 extern unsigned long irix_mapelf(int fd, struct elf_phdr *user_phdrp, int cnt);
238 extern asmlinkage int sys_setpgid(pid_t pid, pid_t pgid);
239 extern void sys_sync(void);
240 extern asmlinkage int sys_getsid(pid_t pid);
241 extern asmlinkage long sys_write (unsigned int fd, const char *buf, unsigned long count);
242 extern asmlinkage long sys_lseek (unsigned int fd, off_t offset, unsigned int origin);
243 extern asmlinkage int sys_getgroups(int gidsetsize, gid_t *grouplist);
244 extern asmlinkage int sys_setgroups(int gidsetsize, gid_t *grouplist);
245 extern int getrusage(struct task_struct *p, int who, struct rusage *ru);
246 extern char *prom_getenv(char *name);
247 extern long prom_setenv(char *name, char *value);
249 /* The syssgi commands supported thus far. */
250 #define SGI_SYSID 1 /* Return unique per-machine identifier. */
251 #define SGI_INVENT 5 /* Fetch inventory */
252 # define SGI_INV_SIZEOF 1
253 # define SGI_INV_READ 2
254 #define SGI_RDNAME 6 /* Return string name of a process. */
255 #define SGI_SETNVRAM 8 /* Set PROM variable. */
256 #define SGI_GETNVRAM 9 /* Get PROM variable. */
257 #define SGI_SETPGID 21 /* Set process group id. */
258 #define SGI_SYSCONF 22 /* POSIX sysconf garbage. */
259 #define SGI_PATHCONF 24 /* POSIX sysconf garbage. */
260 #define SGI_SETGROUPS 40 /* POSIX sysconf garbage. */
261 #define SGI_GETGROUPS 41 /* POSIX sysconf garbage. */
262 #define SGI_RUSAGE 56 /* BSD style rusage(). */
263 #define SGI_SSYNC 62 /* Synchronous fs sync. */
264 #define SGI_GETSID 65 /* SysVr4 get session id. */
265 #define SGI_ELFMAP 68 /* Map an elf image. */
266 #define SGI_TOSSTSAVE 108 /* Toss saved vma's. */
267 #define SGI_FP_BCOPY 129 /* Should FPU bcopy be used on this machine? */
268 #define SGI_PHYSP 1011 /* Translate virtual into physical page. */
270 asmlinkage int irix_syssgi(struct pt_regs *regs)
272 unsigned long cmd;
273 int retval, base = 0;
275 if (regs->regs[2] == 1000)
276 base = 1;
278 cmd = regs->regs[base + 4];
279 switch(cmd) {
280 case SGI_SYSID: {
281 char *buf = (char *) regs->regs[base + 5];
283 /* XXX Use ethernet addr.... */
284 retval = clear_user(buf, 64);
285 break;
287 #if 0
288 case SGI_RDNAME: {
289 int pid = (int) regs->regs[base + 5];
290 char *buf = (char *) regs->regs[base + 6];
291 struct task_struct *p;
292 char comm[16];
294 retval = verify_area(VERIFY_WRITE, buf, 16);
295 if (retval)
296 break;
297 read_lock(&tasklist_lock);
298 p = find_task_by_pid(pid);
299 if (!p) {
300 read_unlock(&tasklist_lock);
301 retval = -ESRCH;
302 break;
304 memcpy(comm, p->comm, 16);
305 read_unlock(&tasklist_lock);
307 /* XXX Need to check sizes. */
308 copy_to_user(buf, p->comm, 16);
309 retval = 0;
310 break;
313 case SGI_GETNVRAM: {
314 char *name = (char *) regs->regs[base+5];
315 char *buf = (char *) regs->regs[base+6];
316 char *value;
317 return -EINVAL; /* til I fix it */
318 retval = verify_area(VERIFY_WRITE, buf, 128);
319 if (retval)
320 break;
321 value = prom_getenv(name); /* PROM lock? */
322 if (!value) {
323 retval = -EINVAL;
324 break;
326 /* Do I strlen() for the length? */
327 copy_to_user(buf, value, 128);
328 retval = 0;
329 break;
332 case SGI_SETNVRAM: {
333 char *name = (char *) regs->regs[base+5];
334 char *value = (char *) regs->regs[base+6];
335 return -EINVAL; /* til I fix it */
336 retval = prom_setenv(name, value);
337 /* XXX make sure retval conforms to syssgi(2) */
338 printk("[%s:%d] setnvram(\"%s\", \"%s\"): retval %d",
339 current->comm, current->pid, name, value, retval);
340 /* if (retval == PROM_ENOENT)
341 retval = -ENOENT; */
342 break;
344 #endif
346 case SGI_SETPGID: {
347 #ifdef DEBUG_PROCGRPS
348 printk("[%s:%d] setpgid(%d, %d) ",
349 current->comm, current->pid,
350 (int) regs->regs[base + 5], (int)regs->regs[base + 6]);
351 #endif
352 retval = sys_setpgid(regs->regs[base + 5], regs->regs[base + 6]);
354 #ifdef DEBUG_PROCGRPS
355 printk("retval=%d\n", retval);
356 #endif
359 case SGI_SYSCONF: {
360 switch(regs->regs[base + 5]) {
361 case 1:
362 retval = (MAX_ARG_PAGES >> 4); /* XXX estimate... */
363 goto out;
364 case 2:
365 retval = max_threads;
366 goto out;
367 case 3:
368 retval = HZ;
369 goto out;
370 case 4:
371 retval = NGROUPS;
372 goto out;
373 case 5:
374 retval = NR_OPEN;
375 goto out;
376 case 6:
377 retval = 1;
378 goto out;
379 case 7:
380 retval = 1;
381 goto out;
382 case 8:
383 retval = 199009;
384 goto out;
385 case 11:
386 retval = PAGE_SIZE;
387 goto out;
388 case 12:
389 retval = 4;
390 goto out;
391 case 25:
392 case 26:
393 case 27:
394 case 28:
395 case 29:
396 case 30:
397 retval = 0;
398 goto out;
399 case 31:
400 retval = 32;
401 goto out;
402 default:
403 retval = -EINVAL;
404 goto out;
408 case SGI_SETGROUPS:
409 retval = sys_setgroups((int) regs->regs[base + 5],
410 (gid_t *) regs->regs[base + 6]);
411 break;
413 case SGI_GETGROUPS:
414 retval = sys_getgroups((int) regs->regs[base + 5],
415 (gid_t *) regs->regs[base + 6]);
416 break;
418 case SGI_RUSAGE: {
419 struct rusage *ru = (struct rusage *) regs->regs[base + 6];
421 switch((int) regs->regs[base + 5]) {
422 case 0:
423 /* rusage self */
424 retval = getrusage(current, RUSAGE_SELF, ru);
425 goto out;
427 case -1:
428 /* rusage children */
429 retval = getrusage(current, RUSAGE_CHILDREN, ru);
430 goto out;
432 default:
433 retval = -EINVAL;
434 goto out;
438 case SGI_SSYNC:
439 sys_sync();
440 retval = 0;
441 break;
443 case SGI_GETSID:
444 #ifdef DEBUG_PROCGRPS
445 printk("[%s:%d] getsid(%d) ", current->comm, current->pid,
446 (int) regs->regs[base + 5]);
447 #endif
448 retval = sys_getsid(regs->regs[base + 5]);
449 #ifdef DEBUG_PROCGRPS
450 printk("retval=%d\n", retval);
451 #endif
452 break;
454 case SGI_ELFMAP:
455 retval = irix_mapelf((int) regs->regs[base + 5],
456 (struct elf_phdr *) regs->regs[base + 6],
457 (int) regs->regs[base + 7]);
458 break;
460 case SGI_TOSSTSAVE:
461 /* XXX We don't need to do anything? */
462 retval = 0;
463 break;
465 case SGI_FP_BCOPY:
466 retval = 0;
467 break;
469 case SGI_PHYSP: {
470 unsigned long addr = regs->regs[base + 5];
471 int *pageno = (int *) (regs->regs[base + 6]);
472 struct mm_struct *mm = current->mm;
473 pgd_t *pgdp;
474 pmd_t *pmdp;
475 pte_t *ptep;
477 retval = verify_area(VERIFY_WRITE, pageno, sizeof(int));
478 if (retval)
479 return retval;
481 down_read(&mm->mmap_sem);
482 pgdp = pgd_offset(mm, addr);
483 pmdp = pmd_offset(pgdp, addr);
484 ptep = pte_offset(pmdp, addr);
485 retval = -EINVAL;
486 if (ptep) {
487 pte_t pte = *ptep;
489 if (pte_val(pte) & (_PAGE_VALID | _PAGE_PRESENT)) {
490 retval = put_user((pte_val(pte) & PAGE_MASK) >>
491 PAGE_SHIFT, pageno);
494 up_read(&mm->mmap_sem);
495 break;
498 case SGI_INVENT: {
499 int arg1 = (int) regs->regs [base + 5];
500 void *buffer = (void *) regs->regs [base + 6];
501 int count = (int) regs->regs [base + 7];
503 switch (arg1) {
504 case SGI_INV_SIZEOF:
505 retval = sizeof (inventory_t);
506 break;
507 case SGI_INV_READ:
508 retval = dump_inventory_to_user (buffer, count);
509 break;
510 default:
511 retval = -EINVAL;
513 break;
516 default:
517 printk("irix_syssgi: Unsupported command %d\n", (int)cmd);
518 retval = -EINVAL;
519 break;
522 out:
523 return retval;
526 asmlinkage int irix_gtime(struct pt_regs *regs)
528 return get_seconds();
532 * IRIX is completely broken... it returns 0 on success, otherwise
533 * ENOMEM.
535 asmlinkage int irix_brk(unsigned long brk)
537 unsigned long rlim;
538 unsigned long newbrk, oldbrk;
539 struct mm_struct *mm = current->mm;
540 int ret;
542 down_write(&mm->mmap_sem);
543 if (brk < mm->end_code) {
544 ret = -ENOMEM;
545 goto out;
548 newbrk = PAGE_ALIGN(brk);
549 oldbrk = PAGE_ALIGN(mm->brk);
550 if (oldbrk == newbrk) {
551 mm->brk = brk;
552 ret = 0;
553 goto out;
557 * Always allow shrinking brk
559 if (brk <= mm->brk) {
560 mm->brk = brk;
561 do_munmap(mm, newbrk, oldbrk-newbrk);
562 ret = 0;
563 goto out;
566 * Check against rlimit and stack..
568 rlim = current->rlim[RLIMIT_DATA].rlim_cur;
569 if (rlim >= RLIM_INFINITY)
570 rlim = ~0;
571 if (brk - mm->end_code > rlim) {
572 ret = -ENOMEM;
573 goto out;
577 * Check against existing mmap mappings.
579 if (find_vma_intersection(mm, oldbrk, newbrk+PAGE_SIZE)) {
580 ret = -ENOMEM;
581 goto out;
585 * Check if we have enough memory..
587 if (security_vm_enough_memory((newbrk-oldbrk) >> PAGE_SHIFT)) {
588 ret = -ENOMEM;
589 goto out;
593 * Ok, looks good - let it rip.
595 mm->brk = brk;
596 do_brk(oldbrk, newbrk-oldbrk);
597 ret = 0;
599 out:
600 up_write(&mm->mmap_sem);
601 return ret;
604 asmlinkage int irix_getpid(struct pt_regs *regs)
606 regs->regs[3] = current->real_parent->pid;
607 return current->pid;
610 asmlinkage int irix_getuid(struct pt_regs *regs)
612 regs->regs[3] = current->euid;
613 return current->uid;
616 asmlinkage int irix_getgid(struct pt_regs *regs)
618 regs->regs[3] = current->egid;
619 return current->gid;
622 asmlinkage int irix_stime(int value)
624 if (!capable(CAP_SYS_TIME))
625 return -EPERM;
627 write_seqlock_irq(&xtime_lock);
628 xtime.tv_sec = value;
629 xtime.tv_nsec = 0;
630 time_adjust = 0; /* stop active adjtime() */
631 time_status |= STA_UNSYNC;
632 time_maxerror = NTP_PHASE_LIMIT;
633 time_esterror = NTP_PHASE_LIMIT;
634 write_sequnlock_irq(&xtime_lock);
636 return 0;
639 extern int do_setitimer(int which, struct itimerval *value,
640 struct itimerval *ovalue);
642 static inline void jiffiestotv(unsigned long jiffies, struct timeval *value)
644 value->tv_usec = (jiffies % HZ) * (1000000 / HZ);
645 value->tv_sec = jiffies / HZ;
648 static inline void getitimer_real(struct itimerval *value)
650 register unsigned long val, interval;
652 interval = current->it_real_incr;
653 val = 0;
654 if (del_timer(&current->real_timer)) {
655 unsigned long now = jiffies;
656 val = current->real_timer.expires;
657 add_timer(&current->real_timer);
658 /* look out for negative/zero itimer.. */
659 if (val <= now)
660 val = now+1;
661 val -= now;
663 jiffiestotv(val, &value->it_value);
664 jiffiestotv(interval, &value->it_interval);
667 asmlinkage unsigned int irix_alarm(unsigned int seconds)
669 struct itimerval it_new, it_old;
670 unsigned int oldalarm;
672 if (!seconds) {
673 getitimer_real(&it_old);
674 del_timer(&current->real_timer);
675 } else {
676 it_new.it_interval.tv_sec = it_new.it_interval.tv_usec = 0;
677 it_new.it_value.tv_sec = seconds;
678 it_new.it_value.tv_usec = 0;
679 do_setitimer(ITIMER_REAL, &it_new, &it_old);
681 oldalarm = it_old.it_value.tv_sec;
683 * ehhh.. We can't return 0 if we have an alarm pending ...
684 * And we'd better return too much than too little anyway
686 if (it_old.it_value.tv_usec)
687 oldalarm++;
689 return oldalarm;
692 asmlinkage int irix_pause(void)
694 current->state = TASK_INTERRUPTIBLE;
695 schedule();
697 return -EINTR;
700 extern asmlinkage long sys_mount(char * dev_name, char * dir_name, char * type,
701 unsigned long new_flags, void * data);
703 /* XXX need more than this... */
704 asmlinkage int irix_mount(char *dev_name, char *dir_name, unsigned long flags,
705 char *type, void *data, int datalen)
707 printk("[%s:%d] irix_mount(%p,%p,%08lx,%p,%p,%d)\n",
708 current->comm, current->pid,
709 dev_name, dir_name, flags, type, data, datalen);
711 return sys_mount(dev_name, dir_name, type, flags, data);
714 struct irix_statfs {
715 short f_type;
716 long f_bsize, f_frsize, f_blocks, f_bfree, f_files, f_ffree;
717 char f_fname[6], f_fpack[6];
720 asmlinkage int irix_statfs(const char *path, struct irix_statfs *buf,
721 int len, int fs_type)
723 struct nameidata nd;
724 struct kstatfs kbuf;
725 int error, i;
727 /* We don't support this feature yet. */
728 if (fs_type) {
729 error = -EINVAL;
730 goto out;
732 error = verify_area(VERIFY_WRITE, buf, sizeof(struct irix_statfs));
733 if (error)
734 goto out;
735 error = user_path_walk(path, &nd);
736 if (error)
737 goto out;
739 error = vfs_statfs(nd.dentry->d_inode->i_sb, &kbuf);
740 if (error)
741 goto dput_and_out;
743 __put_user(kbuf.f_type, &buf->f_type);
744 __put_user(kbuf.f_bsize, &buf->f_bsize);
745 __put_user(kbuf.f_frsize, &buf->f_frsize);
746 __put_user(kbuf.f_blocks, &buf->f_blocks);
747 __put_user(kbuf.f_bfree, &buf->f_bfree);
748 __put_user(kbuf.f_files, &buf->f_files);
749 __put_user(kbuf.f_ffree, &buf->f_ffree);
750 for (i = 0; i < 6; i++) {
751 __put_user(0, &buf->f_fname[i]);
752 __put_user(0, &buf->f_fpack[i]);
754 error = 0;
756 dput_and_out:
757 path_release(&nd);
758 out:
759 return error;
762 asmlinkage int irix_fstatfs(unsigned int fd, struct irix_statfs *buf)
764 struct kstatfs kbuf;
765 struct file *file;
766 int error, i;
768 error = verify_area(VERIFY_WRITE, buf, sizeof(struct irix_statfs));
769 if (error)
770 goto out;
771 if (!(file = fget(fd))) {
772 error = -EBADF;
773 goto out;
776 error = vfs_statfs(file->f_dentry->d_inode->i_sb, &kbuf);
777 if (error)
778 goto out_f;
780 __put_user(kbuf.f_type, &buf->f_type);
781 __put_user(kbuf.f_bsize, &buf->f_bsize);
782 __put_user(kbuf.f_frsize, &buf->f_frsize);
783 __put_user(kbuf.f_blocks, &buf->f_blocks);
784 __put_user(kbuf.f_bfree, &buf->f_bfree);
785 __put_user(kbuf.f_files, &buf->f_files);
786 __put_user(kbuf.f_ffree, &buf->f_ffree);
787 for(i = 0; i < 6; i++) {
788 __put_user(0, &buf->f_fname[i]);
789 __put_user(0, &buf->f_fpack[i]);
792 out_f:
793 fput(file);
794 out:
795 return error;
798 extern asmlinkage int sys_setpgid(pid_t pid, pid_t pgid);
799 extern asmlinkage int sys_setsid(void);
801 asmlinkage int irix_setpgrp(int flags)
803 int error;
805 #ifdef DEBUG_PROCGRPS
806 printk("[%s:%d] setpgrp(%d) ", current->comm, current->pid, flags);
807 #endif
808 if(!flags)
809 error = current->pgrp;
810 else
811 error = sys_setsid();
812 #ifdef DEBUG_PROCGRPS
813 printk("returning %d\n", current->pgrp);
814 #endif
816 return error;
819 asmlinkage int irix_times(struct tms * tbuf)
821 int err = 0;
823 if (tbuf) {
824 err = verify_area(VERIFY_WRITE,tbuf,sizeof *tbuf);
825 if (err)
826 return err;
827 err |= __put_user(current->utime, &tbuf->tms_utime);
828 err |= __put_user(current->stime, &tbuf->tms_stime);
829 err |= __put_user(current->cutime, &tbuf->tms_cutime);
830 err |= __put_user(current->cstime, &tbuf->tms_cstime);
833 return err;
836 asmlinkage int irix_exec(struct pt_regs *regs)
838 int error, base = 0;
839 char *filename;
841 if(regs->regs[2] == 1000)
842 base = 1;
843 filename = getname((char *) (long)regs->regs[base + 4]);
844 error = PTR_ERR(filename);
845 if (IS_ERR(filename))
846 return error;
848 error = do_execve(filename, (char **) (long)regs->regs[base + 5],
849 (char **) 0, regs);
850 putname(filename);
852 return error;
855 asmlinkage int irix_exece(struct pt_regs *regs)
857 int error, base = 0;
858 char *filename;
860 if (regs->regs[2] == 1000)
861 base = 1;
862 filename = getname((char *) (long)regs->regs[base + 4]);
863 error = PTR_ERR(filename);
864 if (IS_ERR(filename))
865 return error;
866 error = do_execve(filename, (char **) (long)regs->regs[base + 5],
867 (char **) (long)regs->regs[base + 6], regs);
868 putname(filename);
870 return error;
873 asmlinkage unsigned long irix_gethostid(void)
875 printk("[%s:%d]: irix_gethostid() called...\n",
876 current->comm, current->pid);
878 return -EINVAL;
881 asmlinkage unsigned long irix_sethostid(unsigned long val)
883 printk("[%s:%d]: irix_sethostid(%08lx) called...\n",
884 current->comm, current->pid, val);
886 return -EINVAL;
889 extern asmlinkage int sys_socket(int family, int type, int protocol);
891 asmlinkage int irix_socket(int family, int type, int protocol)
893 switch(type) {
894 case 1:
895 type = SOCK_DGRAM;
896 break;
898 case 2:
899 type = SOCK_STREAM;
900 break;
902 case 3:
903 type = 9; /* Invalid... */
904 break;
906 case 4:
907 type = SOCK_RAW;
908 break;
910 case 5:
911 type = SOCK_RDM;
912 break;
914 case 6:
915 type = SOCK_SEQPACKET;
916 break;
918 default:
919 break;
922 return sys_socket(family, type, protocol);
925 asmlinkage int irix_getdomainname(char *name, int len)
927 int error;
929 error = verify_area(VERIFY_WRITE, name, len);
930 if (error)
931 return error;
933 down_read(&uts_sem);
934 if(len > (__NEW_UTS_LEN - 1))
935 len = __NEW_UTS_LEN - 1;
936 error = 0;
937 if (copy_to_user(name, system_utsname.domainname, len))
938 error = -EFAULT;
939 up_read(&uts_sem);
941 return error;
944 asmlinkage unsigned long irix_getpagesize(void)
946 return PAGE_SIZE;
949 asmlinkage int irix_msgsys(int opcode, unsigned long arg0, unsigned long arg1,
950 unsigned long arg2, unsigned long arg3,
951 unsigned long arg4)
953 switch (opcode) {
954 case 0:
955 return sys_msgget((key_t) arg0, (int) arg1);
956 case 1:
957 return sys_msgctl((int) arg0, (int) arg1, (struct msqid_ds *)arg2);
958 case 2:
959 return sys_msgrcv((int) arg0, (struct msgbuf *) arg1,
960 (size_t) arg2, (long) arg3, (int) arg4);
961 case 3:
962 return sys_msgsnd((int) arg0, (struct msgbuf *) arg1,
963 (size_t) arg2, (int) arg3);
964 default:
965 return -EINVAL;
969 asmlinkage int irix_shmsys(int opcode, unsigned long arg0, unsigned long arg1,
970 unsigned long arg2, unsigned long arg3)
972 switch (opcode) {
973 case 0:
974 return sys_shmat((int) arg0, (char *)arg1, (int) arg2,
975 (unsigned long *) arg3);
976 case 1:
977 return sys_shmctl((int)arg0, (int)arg1, (struct shmid_ds *)arg2);
978 case 2:
979 return sys_shmdt((char *)arg0);
980 case 3:
981 return sys_shmget((key_t) arg0, (int) arg1, (int) arg2);
982 default:
983 return -EINVAL;
987 asmlinkage int irix_semsys(int opcode, unsigned long arg0, unsigned long arg1,
988 unsigned long arg2, int arg3)
990 switch (opcode) {
991 case 0:
992 return sys_semctl((int) arg0, (int) arg1, (int) arg2,
993 (union semun) arg3);
994 case 1:
995 return sys_semget((key_t) arg0, (int) arg1, (int) arg2);
996 case 2:
997 return sys_semop((int) arg0, (struct sembuf *)arg1,
998 (unsigned int) arg2);
999 default:
1000 return -EINVAL;
1004 static inline loff_t llseek(struct file *file, loff_t offset, int origin)
1006 loff_t (*fn)(struct file *, loff_t, int);
1007 loff_t retval;
1009 fn = default_llseek;
1010 if (file->f_op && file->f_op->llseek)
1011 fn = file->f_op->llseek;
1012 lock_kernel();
1013 retval = fn(file, offset, origin);
1014 unlock_kernel();
1015 return retval;
1018 asmlinkage int irix_lseek64(int fd, int _unused, int offhi, int offlow,
1019 int origin)
1021 int retval;
1022 struct file * file;
1023 loff_t offset;
1025 retval = -EBADF;
1026 file = fget(fd);
1027 if (!file)
1028 goto bad;
1029 retval = -EINVAL;
1030 if (origin > 2)
1031 goto out_putf;
1033 offset = llseek(file, ((loff_t) offhi << 32) | offlow, origin);
1034 retval = (int) offset;
1036 out_putf:
1037 fput(file);
1038 bad:
1039 return retval;
1042 asmlinkage int irix_sginap(int ticks)
1044 current->state = TASK_INTERRUPTIBLE;
1045 schedule_timeout(ticks);
1046 return 0;
1049 asmlinkage int irix_sgikopt(char *istring, char *ostring, int len)
1051 return -EINVAL;
1054 asmlinkage int irix_gettimeofday(struct timeval *tv)
1056 time_t sec;
1057 long nsec, seq;
1058 int err;
1060 if (verify_area(VERIFY_WRITE, tv, sizeof(struct timeval)))
1061 return -EFAULT;
1063 do {
1064 seq = read_seqbegin(&xtime_lock);
1065 sec = xtime.tv_sec;
1066 nsec = xtime.tv_nsec;
1067 } while (read_seqretry(&xtime_lock, seq));
1069 err = __put_user(sec, &tv->tv_sec);
1070 err |= __put_user((nsec / 1000), &tv->tv_usec);
1072 return err;
1075 #define IRIX_MAP_AUTOGROW 0x40
1077 asmlinkage unsigned long irix_mmap32(unsigned long addr, size_t len, int prot,
1078 int flags, int fd, off_t offset)
1080 struct file *file = NULL;
1081 unsigned long retval;
1083 if (!(flags & MAP_ANONYMOUS)) {
1084 if (!(file = fget(fd)))
1085 return -EBADF;
1087 /* Ok, bad taste hack follows, try to think in something else
1088 * when reading this. */
1089 if (flags & IRIX_MAP_AUTOGROW) {
1090 unsigned long old_pos;
1091 long max_size = offset + len;
1093 if (max_size > file->f_dentry->d_inode->i_size) {
1094 old_pos = sys_lseek (fd, max_size - 1, 0);
1095 sys_write (fd, "", 1);
1096 sys_lseek (fd, old_pos, 0);
1101 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
1103 down_write(&current->mm->mmap_sem);
1104 retval = do_mmap(file, addr, len, prot, flags, offset);
1105 up_write(&current->mm->mmap_sem);
1106 if (file)
1107 fput(file);
1109 return retval;
1112 asmlinkage int irix_madvise(unsigned long addr, int len, int behavior)
1114 printk("[%s:%d] Wheee.. irix_madvise(%08lx,%d,%d)\n",
1115 current->comm, current->pid, addr, len, behavior);
1117 return -EINVAL;
1120 asmlinkage int irix_pagelock(char *addr, int len, int op)
1122 printk("[%s:%d] Wheee.. irix_pagelock(%p,%d,%d)\n",
1123 current->comm, current->pid, addr, len, op);
1125 return -EINVAL;
1128 asmlinkage int irix_quotactl(struct pt_regs *regs)
1130 printk("[%s:%d] Wheee.. irix_quotactl()\n",
1131 current->comm, current->pid);
1133 return -EINVAL;
1136 asmlinkage int irix_BSDsetpgrp(int pid, int pgrp)
1138 int error;
1140 #ifdef DEBUG_PROCGRPS
1141 printk("[%s:%d] BSDsetpgrp(%d, %d) ", current->comm, current->pid,
1142 pid, pgrp);
1143 #endif
1144 if(!pid)
1145 pid = current->pid;
1147 /* Wheee, weird sysv thing... */
1148 if ((pgrp == 0) && (pid == current->pid))
1149 error = sys_setsid();
1150 else
1151 error = sys_setpgid(pid, pgrp);
1153 #ifdef DEBUG_PROCGRPS
1154 printk("error = %d\n", error);
1155 #endif
1157 return error;
1160 asmlinkage int irix_systeminfo(int cmd, char *buf, int cnt)
1162 printk("[%s:%d] Wheee.. irix_systeminfo(%d,%p,%d)\n",
1163 current->comm, current->pid, cmd, buf, cnt);
1165 return -EINVAL;
1168 struct iuname {
1169 char sysname[257], nodename[257], release[257];
1170 char version[257], machine[257];
1171 char m_type[257], base_rel[257];
1172 char _unused0[257], _unused1[257], _unused2[257];
1173 char _unused3[257], _unused4[257], _unused5[257];
1176 asmlinkage int irix_uname(struct iuname *buf)
1178 down_read(&uts_sem);
1179 if (copy_to_user(system_utsname.sysname, buf->sysname, 65)
1180 || copy_to_user(system_utsname.nodename, buf->nodename, 65)
1181 || copy_to_user(system_utsname.release, buf->release, 65)
1182 || copy_to_user(system_utsname.version, buf->version, 65)
1183 || copy_to_user(system_utsname.machine, buf->machine, 65)) {
1184 return -EFAULT;
1186 up_read(&uts_sem);
1188 return 1;
1191 #undef DEBUG_XSTAT
1193 static inline u32
1194 linux_to_irix_dev_t (dev_t t)
1196 return MAJOR (t) << 18 | MINOR (t);
1199 static inline int irix_xstat32_xlate(struct kstat *stat, void *ubuf)
1201 struct xstat32 {
1202 u32 st_dev, st_pad1[3], st_ino, st_mode, st_nlink, st_uid, st_gid;
1203 u32 st_rdev, st_pad2[2], st_size, st_pad3;
1204 u32 st_atime0, st_atime1;
1205 u32 st_mtime0, st_mtime1;
1206 u32 st_ctime0, st_ctime1;
1207 u32 st_blksize, st_blocks;
1208 char st_fstype[16];
1209 u32 st_pad4[8];
1210 } ub;
1212 ub.st_dev = linux_to_irix_dev_t(stat->dev);
1213 ub.st_ino = stat->ino;
1214 ub.st_mode = stat->mode;
1215 ub.st_nlink = stat->nlink;
1216 SET_STAT_UID(ub, stat->uid);
1217 SET_STAT_GID(ub, stat->gid);
1218 ub.st_rdev = linux_to_irix_dev_t(stat->rdev);
1219 #if BITS_PER_LONG == 32
1220 if (stat->size > MAX_NON_LFS)
1221 return -EOVERFLOW;
1222 #endif
1223 ub.st_size = stat->size;
1224 ub.st_atime0 = stat->atime.tv_sec;
1225 ub.st_atime1 = stat->atime.tv_nsec;
1226 ub.st_mtime0 = stat->mtime.tv_sec;
1227 ub.st_mtime1 = stat->atime.tv_nsec;
1228 ub.st_ctime0 = stat->ctime.tv_sec;
1229 ub.st_ctime1 = stat->atime.tv_nsec;
1230 ub.st_blksize = stat->blksize;
1231 ub.st_blocks = stat->blocks;
1232 strcpy (ub.st_fstype, "efs");
1234 return copy_to_user(ubuf, &ub, sizeof(ub)) ? -EFAULT : 0;
1237 static inline void irix_xstat64_xlate(struct kstat *stat, void *ubuf)
1239 struct xstat64 {
1240 u32 st_dev; s32 st_pad1[3];
1241 unsigned long long st_ino;
1242 u32 st_mode;
1243 u32 st_nlink; s32 st_uid; s32 st_gid; u32 st_rdev;
1244 s32 st_pad2[2];
1245 long long st_size;
1246 s32 st_pad3;
1247 struct { s32 tv_sec, tv_nsec; } st_atime, st_mtime, st_ctime;
1248 s32 st_blksize;
1249 long long st_blocks;
1250 char st_fstype[16];
1251 s32 st_pad4[8];
1252 } ks;
1254 ks.st_dev = linux_to_irix_dev_t(stat->dev);
1255 ks.st_pad1[0] = ks.st_pad1[1] = ks.st_pad1[2] = 0;
1256 ks.st_ino = (unsigned long long) stat->ino;
1257 ks.st_mode = (u32) stat->mode;
1258 ks.st_nlink = (u32) stat->nlink;
1259 ks.st_uid = (s32) stat->uid;
1260 ks.st_gid = (s32) stat->gid;
1261 ks.st_rdev = linux_to_irix_dev_t (stat->rdev);
1262 ks.st_pad2[0] = ks.st_pad2[1] = 0;
1263 ks.st_size = (long long) stat->size;
1264 ks.st_pad3 = 0;
1266 /* XXX hackety hack... */
1267 ks.st_atime.tv_sec = (s32) stat->atime.tv_sec;
1268 ks.st_atime.tv_nsec = stat->atime.tv_nsec;
1269 ks.st_mtime.tv_sec = (s32) stat->mtime.tv_sec;
1270 ks.st_mtime.tv_nsec = stat->mtime.tv_nsec;;
1271 ks.st_ctime.tv_sec = (s32) stat->ctime.tv_sec;
1272 ks.st_ctime.tv_nsec = stat->ctime.tv_nsec;;
1274 ks.st_blksize = (s32) stat->blksize;
1275 ks.st_blocks = (long long) stat->blocks;
1276 memset(ks.st_fstype, 0, 16);
1277 ks.st_pad4[0] = ks.st_pad4[1] = ks.st_pad4[2] = ks.st_pad4[3] = 0;
1278 ks.st_pad4[4] = ks.st_pad4[5] = ks.st_pad4[6] = ks.st_pad4[7] = 0;
1280 /* Now write it all back. */
1281 copy_to_user(ubuf, &ks, sizeof(struct xstat64));
1284 asmlinkage int irix_xstat(int version, char *filename, struct stat *statbuf)
1286 int retval;
1287 struct kstat stat;
1289 #ifdef DEBUG_XSTAT
1290 printk("[%s:%d] Wheee.. irix_xstat(%d,%s,%p) ",
1291 current->comm, current->pid, version, filename, statbuf);
1292 #endif
1294 retval = vfs_stat(filename, &stat);
1295 if (!retval) {
1296 switch(version) {
1297 case 2:
1298 retval = irix_xstat32_xlate(&stat, statbuf);
1299 break;
1300 case 3:
1301 irix_xstat64_xlate(&stat, statbuf);
1302 retval = 0; /* Really? */
1303 break;
1304 default:
1305 retval = -EINVAL;
1308 return retval;
1311 asmlinkage int irix_lxstat(int version, char *filename, struct stat *statbuf)
1313 int error;
1314 struct kstat stat;
1316 #ifdef DEBUG_XSTAT
1317 printk("[%s:%d] Wheee.. irix_lxstat(%d,%s,%p) ",
1318 current->comm, current->pid, version, filename, statbuf);
1319 #endif
1321 error = vfs_lstat(filename, &stat);
1323 if (!error) {
1324 switch (version) {
1325 case 2:
1326 error = irix_xstat32_xlate(&stat, statbuf);
1327 break;
1328 case 3:
1329 irix_xstat64_xlate(&stat, statbuf);
1330 error = 0;
1331 break;
1332 default:
1333 error = -EINVAL;
1336 return error;
1339 asmlinkage int irix_fxstat(int version, int fd, struct stat *statbuf)
1341 int error;
1342 struct kstat stat;
1344 #ifdef DEBUG_XSTAT
1345 printk("[%s:%d] Wheee.. irix_fxstat(%d,%d,%p) ",
1346 current->comm, current->pid, version, fd, statbuf);
1347 #endif
1349 error = vfs_fstat(fd, &stat);
1350 if (!error) {
1351 switch (version) {
1352 case 2:
1353 error = irix_xstat32_xlate(&stat, statbuf);
1354 break;
1355 case 3:
1356 irix_xstat64_xlate(&stat, statbuf);
1357 error = 0;
1358 break;
1359 default:
1360 error = -EINVAL;
1363 return error;
1366 extern asmlinkage int sys_mknod(const char * filename, int mode, dev_t dev);
1368 asmlinkage int irix_xmknod(int ver, char *filename, int mode, dev_t dev)
1370 int retval;
1372 printk("[%s:%d] Wheee.. irix_xmknod(%d,%s,%x,%x)\n",
1373 current->comm, current->pid, ver, filename, mode, (int) dev);
1375 switch(ver) {
1376 case 2:
1377 retval = sys_mknod(filename, mode, dev);
1378 break;
1380 default:
1381 retval = -EINVAL;
1382 break;
1385 return retval;
1388 asmlinkage int irix_swapctl(int cmd, char *arg)
1390 printk("[%s:%d] Wheee.. irix_swapctl(%d,%p)\n",
1391 current->comm, current->pid, cmd, arg);
1393 return -EINVAL;
1396 struct irix_statvfs {
1397 u32 f_bsize; u32 f_frsize; u32 f_blocks;
1398 u32 f_bfree; u32 f_bavail; u32 f_files; u32 f_ffree; u32 f_favail;
1399 u32 f_fsid; char f_basetype[16];
1400 u32 f_flag; u32 f_namemax;
1401 char f_fstr[32]; u32 f_filler[16];
1404 asmlinkage int irix_statvfs(char *fname, struct irix_statvfs *buf)
1406 struct nameidata nd;
1407 struct kstatfs kbuf;
1408 int error, i;
1410 printk("[%s:%d] Wheee.. irix_statvfs(%s,%p)\n",
1411 current->comm, current->pid, fname, buf);
1412 error = verify_area(VERIFY_WRITE, buf, sizeof(struct irix_statvfs));
1413 if (error)
1414 goto out;
1415 error = user_path_walk(fname, &nd);
1416 if (error)
1417 goto out;
1418 error = vfs_statfs(nd.dentry->d_inode->i_sb, &kbuf);
1419 if (error)
1420 goto dput_and_out;
1422 __put_user(kbuf.f_bsize, &buf->f_bsize);
1423 __put_user(kbuf.f_frsize, &buf->f_frsize);
1424 __put_user(kbuf.f_blocks, &buf->f_blocks);
1425 __put_user(kbuf.f_bfree, &buf->f_bfree);
1426 __put_user(kbuf.f_bfree, &buf->f_bavail); /* XXX hackety hack... */
1427 __put_user(kbuf.f_files, &buf->f_files);
1428 __put_user(kbuf.f_ffree, &buf->f_ffree);
1429 __put_user(kbuf.f_ffree, &buf->f_favail); /* XXX hackety hack... */
1430 #ifdef __MIPSEB__
1431 __put_user(kbuf.f_fsid.val[1], &buf->f_fsid);
1432 #else
1433 __put_user(kbuf.f_fsid.val[0], &buf->f_fsid);
1434 #endif
1435 for (i = 0; i < 16; i++)
1436 __put_user(0, &buf->f_basetype[i]);
1437 __put_user(0, &buf->f_flag);
1438 __put_user(kbuf.f_namelen, &buf->f_namemax);
1439 for (i = 0; i < 32; i++)
1440 __put_user(0, &buf->f_fstr[i]);
1442 error = 0;
1444 dput_and_out:
1445 path_release(&nd);
1446 out:
1447 return error;
1450 asmlinkage int irix_fstatvfs(int fd, struct irix_statvfs *buf)
1452 struct kstatfs kbuf;
1453 struct file *file;
1454 int error, i;
1456 printk("[%s:%d] Wheee.. irix_fstatvfs(%d,%p)\n",
1457 current->comm, current->pid, fd, buf);
1459 error = verify_area(VERIFY_WRITE, buf, sizeof(struct irix_statvfs));
1460 if (error)
1461 goto out;
1462 if (!(file = fget(fd))) {
1463 error = -EBADF;
1464 goto out;
1466 error = vfs_statfs(file->f_dentry->d_inode->i_sb, &kbuf);
1467 if (error)
1468 goto out_f;
1470 __put_user(kbuf.f_bsize, &buf->f_bsize);
1471 __put_user(kbuf.f_frsize, &buf->f_frsize);
1472 __put_user(kbuf.f_blocks, &buf->f_blocks);
1473 __put_user(kbuf.f_bfree, &buf->f_bfree);
1474 __put_user(kbuf.f_bfree, &buf->f_bavail); /* XXX hackety hack... */
1475 __put_user(kbuf.f_files, &buf->f_files);
1476 __put_user(kbuf.f_ffree, &buf->f_ffree);
1477 __put_user(kbuf.f_ffree, &buf->f_favail); /* XXX hackety hack... */
1478 #ifdef __MIPSEB__
1479 __put_user(kbuf.f_fsid.val[1], &buf->f_fsid);
1480 #else
1481 __put_user(kbuf.f_fsid.val[0], &buf->f_fsid);
1482 #endif
1483 for(i = 0; i < 16; i++)
1484 __put_user(0, &buf->f_basetype[i]);
1485 __put_user(0, &buf->f_flag);
1486 __put_user(kbuf.f_namelen, &buf->f_namemax);
1487 __clear_user(&buf->f_fstr, sizeof(buf->f_fstr));
1489 out_f:
1490 fput(file);
1491 out:
1492 return error;
1495 asmlinkage int irix_priocntl(struct pt_regs *regs)
1497 printk("[%s:%d] Wheee.. irix_priocntl()\n",
1498 current->comm, current->pid);
1500 return -EINVAL;
1503 asmlinkage int irix_sigqueue(int pid, int sig, int code, int val)
1505 printk("[%s:%d] Wheee.. irix_sigqueue(%d,%d,%d,%d)\n",
1506 current->comm, current->pid, pid, sig, code, val);
1508 return -EINVAL;
1511 extern asmlinkage int sys_truncate(const char * path, unsigned long length);
1512 extern asmlinkage int sys_ftruncate(unsigned int fd, unsigned long length);
1514 asmlinkage int irix_truncate64(char *name, int pad, int size1, int size2)
1516 int retval;
1518 if (size1) {
1519 retval = -EINVAL;
1520 goto out;
1522 retval = sys_truncate(name, size2);
1524 out:
1525 return retval;
1528 asmlinkage int irix_ftruncate64(int fd, int pad, int size1, int size2)
1530 int retval;
1532 if (size1) {
1533 retval = -EINVAL;
1534 goto out;
1536 retval = sys_ftruncate(fd, size2);
1538 out:
1539 return retval;
1542 extern asmlinkage unsigned long
1543 sys_mmap(unsigned long addr, size_t len, int prot, int flags, int fd,
1544 off_t offset);
1546 asmlinkage int irix_mmap64(struct pt_regs *regs)
1548 int len, prot, flags, fd, off1, off2, error, base = 0;
1549 unsigned long addr, pgoff, *sp;
1550 struct file *file = NULL;
1552 if (regs->regs[2] == 1000)
1553 base = 1;
1554 sp = (unsigned long *) (regs->regs[29] + 16);
1555 addr = regs->regs[base + 4];
1556 len = regs->regs[base + 5];
1557 prot = regs->regs[base + 6];
1558 if (!base) {
1559 flags = regs->regs[base + 7];
1560 error = verify_area(VERIFY_READ, sp, (4 * sizeof(unsigned long)));
1561 if(error)
1562 goto out;
1563 fd = sp[0];
1564 __get_user(off1, &sp[1]);
1565 __get_user(off2, &sp[2]);
1566 } else {
1567 error = verify_area(VERIFY_READ, sp, (5 * sizeof(unsigned long)));
1568 if(error)
1569 goto out;
1570 __get_user(flags, &sp[0]);
1571 __get_user(fd, &sp[1]);
1572 __get_user(off1, &sp[2]);
1573 __get_user(off2, &sp[3]);
1576 if (off1 & PAGE_MASK) {
1577 error = -EOVERFLOW;
1578 goto out;
1581 pgoff = (off1 << (32 - PAGE_SHIFT)) | (off2 >> PAGE_SHIFT);
1583 if (!(flags & MAP_ANONYMOUS)) {
1584 if (!(file = fget(fd))) {
1585 error = -EBADF;
1586 goto out;
1589 /* Ok, bad taste hack follows, try to think in something else
1590 when reading this */
1591 if (flags & IRIX_MAP_AUTOGROW) {
1592 unsigned long old_pos;
1593 long max_size = off2 + len;
1595 if (max_size > file->f_dentry->d_inode->i_size) {
1596 old_pos = sys_lseek (fd, max_size - 1, 0);
1597 sys_write (fd, "", 1);
1598 sys_lseek (fd, old_pos, 0);
1603 flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
1605 down_write(&current->mm->mmap_sem);
1606 error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff);
1607 up_write(&current->mm->mmap_sem);
1609 if (file)
1610 fput(file);
1612 out:
1613 return error;
1616 asmlinkage int irix_dmi(struct pt_regs *regs)
1618 printk("[%s:%d] Wheee.. irix_dmi()\n",
1619 current->comm, current->pid);
1621 return -EINVAL;
1624 asmlinkage int irix_pread(int fd, char *buf, int cnt, int off64,
1625 int off1, int off2)
1627 printk("[%s:%d] Wheee.. irix_pread(%d,%p,%d,%d,%d,%d)\n",
1628 current->comm, current->pid, fd, buf, cnt, off64, off1, off2);
1630 return -EINVAL;
1633 asmlinkage int irix_pwrite(int fd, char *buf, int cnt, int off64,
1634 int off1, int off2)
1636 printk("[%s:%d] Wheee.. irix_pwrite(%d,%p,%d,%d,%d,%d)\n",
1637 current->comm, current->pid, fd, buf, cnt, off64, off1, off2);
1639 return -EINVAL;
1642 asmlinkage int irix_sgifastpath(int cmd, unsigned long arg0, unsigned long arg1,
1643 unsigned long arg2, unsigned long arg3,
1644 unsigned long arg4, unsigned long arg5)
1646 printk("[%s:%d] Wheee.. irix_fastpath(%d,%08lx,%08lx,%08lx,%08lx,"
1647 "%08lx,%08lx)\n",
1648 current->comm, current->pid, cmd, arg0, arg1, arg2,
1649 arg3, arg4, arg5);
1651 return -EINVAL;
1654 struct irix_statvfs64 {
1655 u32 f_bsize; u32 f_frsize;
1656 u64 f_blocks; u64 f_bfree; u64 f_bavail;
1657 u64 f_files; u64 f_ffree; u64 f_favail;
1658 u32 f_fsid;
1659 char f_basetype[16];
1660 u32 f_flag; u32 f_namemax;
1661 char f_fstr[32];
1662 u32 f_filler[16];
1665 asmlinkage int irix_statvfs64(char *fname, struct irix_statvfs64 *buf)
1667 struct nameidata nd;
1668 struct kstatfs kbuf;
1669 int error, i;
1671 printk("[%s:%d] Wheee.. irix_statvfs(%s,%p)\n",
1672 current->comm, current->pid, fname, buf);
1673 error = verify_area(VERIFY_WRITE, buf, sizeof(struct irix_statvfs));
1674 if(error)
1675 goto out;
1676 error = user_path_walk(fname, &nd);
1677 if (error)
1678 goto out;
1679 error = vfs_statfs(nd.dentry->d_inode->i_sb, &kbuf);
1680 if (error)
1681 goto dput_and_out;
1683 __put_user(kbuf.f_bsize, &buf->f_bsize);
1684 __put_user(kbuf.f_frsize, &buf->f_frsize);
1685 __put_user(kbuf.f_blocks, &buf->f_blocks);
1686 __put_user(kbuf.f_bfree, &buf->f_bfree);
1687 __put_user(kbuf.f_bfree, &buf->f_bavail); /* XXX hackety hack... */
1688 __put_user(kbuf.f_files, &buf->f_files);
1689 __put_user(kbuf.f_ffree, &buf->f_ffree);
1690 __put_user(kbuf.f_ffree, &buf->f_favail); /* XXX hackety hack... */
1691 #ifdef __MIPSEB__
1692 __put_user(kbuf.f_fsid.val[1], &buf->f_fsid);
1693 #else
1694 __put_user(kbuf.f_fsid.val[0], &buf->f_fsid);
1695 #endif
1696 for(i = 0; i < 16; i++)
1697 __put_user(0, &buf->f_basetype[i]);
1698 __put_user(0, &buf->f_flag);
1699 __put_user(kbuf.f_namelen, &buf->f_namemax);
1700 for(i = 0; i < 32; i++)
1701 __put_user(0, &buf->f_fstr[i]);
1703 error = 0;
1705 dput_and_out:
1706 path_release(&nd);
1707 out:
1708 return error;
1711 asmlinkage int irix_fstatvfs64(int fd, struct irix_statvfs *buf)
1713 struct kstatfs kbuf;
1714 struct file *file;
1715 int error, i;
1717 printk("[%s:%d] Wheee.. irix_fstatvfs(%d,%p)\n",
1718 current->comm, current->pid, fd, buf);
1720 error = verify_area(VERIFY_WRITE, buf, sizeof(struct irix_statvfs));
1721 if (error)
1722 goto out;
1723 if (!(file = fget(fd))) {
1724 error = -EBADF;
1725 goto out;
1727 error = vfs_statfs(file->f_dentry->d_inode->i_sb, &kbuf);
1728 if (error)
1729 goto out_f;
1731 __put_user(kbuf.f_bsize, &buf->f_bsize);
1732 __put_user(kbuf.f_frsize, &buf->f_frsize);
1733 __put_user(kbuf.f_blocks, &buf->f_blocks);
1734 __put_user(kbuf.f_bfree, &buf->f_bfree);
1735 __put_user(kbuf.f_bfree, &buf->f_bavail); /* XXX hackety hack... */
1736 __put_user(kbuf.f_files, &buf->f_files);
1737 __put_user(kbuf.f_ffree, &buf->f_ffree);
1738 __put_user(kbuf.f_ffree, &buf->f_favail); /* XXX hackety hack... */
1739 #ifdef __MIPSEB__
1740 __put_user(kbuf.f_fsid.val[1], &buf->f_fsid);
1741 #else
1742 __put_user(kbuf.f_fsid.val[0], &buf->f_fsid);
1743 #endif
1744 for(i = 0; i < 16; i++)
1745 __put_user(0, &buf->f_basetype[i]);
1746 __put_user(0, &buf->f_flag);
1747 __put_user(kbuf.f_namelen, &buf->f_namemax);
1748 __clear_user(buf->f_fstr, sizeof(buf->f_fstr[i]));
1750 out_f:
1751 fput(file);
1752 out:
1753 return error;
1756 asmlinkage int irix_getmountid(char *fname, unsigned long *midbuf)
1758 int err;
1760 printk("[%s:%d] irix_getmountid(%s, %p)\n",
1761 current->comm, current->pid, fname, midbuf);
1762 err = verify_area(VERIFY_WRITE, midbuf, (sizeof(unsigned long) * 4));
1763 if (err)
1764 return err;
1767 * The idea with this system call is that when trying to determine
1768 * 'pwd' and it's a toss-up for some reason, userland can use the
1769 * fsid of the filesystem to try and make the right decision, but
1770 * we don't have this so for now. XXX
1772 err |= __put_user(0, &midbuf[0]);
1773 err |= __put_user(0, &midbuf[1]);
1774 err |= __put_user(0, &midbuf[2]);
1775 err |= __put_user(0, &midbuf[3]);
1777 return err;
1780 asmlinkage int irix_nsproc(unsigned long entry, unsigned long mask,
1781 unsigned long arg, unsigned long sp, int slen)
1783 printk("[%s:%d] Wheee.. irix_nsproc(%08lx,%08lx,%08lx,%08lx,%d)\n",
1784 current->comm, current->pid, entry, mask, arg, sp, slen);
1786 return -EINVAL;
1789 #undef DEBUG_GETDENTS
1791 struct irix_dirent32 {
1792 u32 d_ino;
1793 u32 d_off;
1794 unsigned short d_reclen;
1795 char d_name[1];
1798 struct irix_dirent32_callback {
1799 struct irix_dirent32 *current_dir;
1800 struct irix_dirent32 *previous;
1801 int count;
1802 int error;
1805 #define NAME_OFFSET32(de) ((int) ((de)->d_name - (char *) (de)))
1806 #define ROUND_UP32(x) (((x)+sizeof(u32)-1) & ~(sizeof(u32)-1))
1808 static int irix_filldir32(void *__buf, const char *name, int namlen,
1809 loff_t offset, ino_t ino, unsigned int d_type)
1811 struct irix_dirent32 *dirent;
1812 struct irix_dirent32_callback *buf =
1813 (struct irix_dirent32_callback *)__buf;
1814 unsigned short reclen = ROUND_UP32(NAME_OFFSET32(dirent) + namlen + 1);
1816 #ifdef DEBUG_GETDENTS
1817 printk("\nirix_filldir32[reclen<%d>namlen<%d>count<%d>]",
1818 reclen, namlen, buf->count);
1819 #endif
1820 buf->error = -EINVAL; /* only used if we fail.. */
1821 if (reclen > buf->count)
1822 return -EINVAL;
1823 dirent = buf->previous;
1824 if (dirent)
1825 __put_user(offset, &dirent->d_off);
1826 dirent = buf->current_dir;
1827 buf->previous = dirent;
1828 __put_user(ino, &dirent->d_ino);
1829 __put_user(reclen, &dirent->d_reclen);
1830 copy_to_user(dirent->d_name, name, namlen);
1831 __put_user(0, &dirent->d_name[namlen]);
1832 ((char *) dirent) += reclen;
1833 buf->current_dir = dirent;
1834 buf->count -= reclen;
1836 return 0;
1839 asmlinkage int irix_ngetdents(unsigned int fd, void * dirent,
1840 unsigned int count, int *eob)
1842 struct file *file;
1843 struct irix_dirent32 *lastdirent;
1844 struct irix_dirent32_callback buf;
1845 int error;
1847 #ifdef DEBUG_GETDENTS
1848 printk("[%s:%d] ngetdents(%d, %p, %d, %p) ", current->comm,
1849 current->pid, fd, dirent, count, eob);
1850 #endif
1851 error = -EBADF;
1852 file = fget(fd);
1853 if (!file)
1854 goto out;
1856 buf.current_dir = (struct irix_dirent32 *) dirent;
1857 buf.previous = NULL;
1858 buf.count = count;
1859 buf.error = 0;
1861 error = vfs_readdir(file, irix_filldir32, &buf);
1862 if (error < 0)
1863 goto out_putf;
1865 error = buf.error;
1866 lastdirent = buf.previous;
1867 if (lastdirent) {
1868 put_user(file->f_pos, &lastdirent->d_off);
1869 error = count - buf.count;
1872 if (put_user(0, eob) < 0) {
1873 error = -EFAULT;
1874 goto out_putf;
1877 #ifdef DEBUG_GETDENTS
1878 printk("eob=%d returning %d\n", *eob, count - buf.count);
1879 #endif
1880 error = count - buf.count;
1882 out_putf:
1883 fput(file);
1884 out:
1885 return error;
1888 struct irix_dirent64 {
1889 u64 d_ino;
1890 u64 d_off;
1891 unsigned short d_reclen;
1892 char d_name[1];
1895 struct irix_dirent64_callback {
1896 struct irix_dirent64 *curr;
1897 struct irix_dirent64 *previous;
1898 int count;
1899 int error;
1902 #define NAME_OFFSET64(de) ((int) ((de)->d_name - (char *) (de)))
1903 #define ROUND_UP64(x) (((x)+sizeof(u64)-1) & ~(sizeof(u64)-1))
1905 static int irix_filldir64(void * __buf, const char * name, int namlen,
1906 loff_t offset, ino_t ino, unsigned int d_type)
1908 struct irix_dirent64 *dirent;
1909 struct irix_dirent64_callback * buf =
1910 (struct irix_dirent64_callback *) __buf;
1911 unsigned short reclen = ROUND_UP64(NAME_OFFSET64(dirent) + namlen + 1);
1913 buf->error = -EINVAL; /* only used if we fail.. */
1914 if (reclen > buf->count)
1915 return -EINVAL;
1916 dirent = buf->previous;
1917 if (dirent)
1918 __put_user(offset, &dirent->d_off);
1919 dirent = buf->curr;
1920 buf->previous = dirent;
1921 __put_user(ino, &dirent->d_ino);
1922 __put_user(reclen, &dirent->d_reclen);
1923 __copy_to_user(dirent->d_name, name, namlen);
1924 __put_user(0, &dirent->d_name[namlen]);
1925 ((char *) dirent) += reclen;
1926 buf->curr = dirent;
1927 buf->count -= reclen;
1929 return 0;
1932 asmlinkage int irix_getdents64(int fd, void *dirent, int cnt)
1934 struct file *file;
1935 struct irix_dirent64 *lastdirent;
1936 struct irix_dirent64_callback buf;
1937 int error;
1939 #ifdef DEBUG_GETDENTS
1940 printk("[%s:%d] getdents64(%d, %p, %d) ", current->comm,
1941 current->pid, fd, dirent, cnt);
1942 #endif
1943 error = -EBADF;
1944 if (!(file = fget(fd)))
1945 goto out;
1947 error = -EFAULT;
1948 if (!access_ok(VERIFY_WRITE, dirent, cnt))
1949 goto out_f;
1951 error = -EINVAL;
1952 if (cnt < (sizeof(struct irix_dirent64) + 255))
1953 goto out_f;
1955 buf.curr = (struct irix_dirent64 *) dirent;
1956 buf.previous = NULL;
1957 buf.count = cnt;
1958 buf.error = 0;
1959 error = vfs_readdir(file, irix_filldir64, &buf);
1960 if (error < 0)
1961 goto out_f;
1962 lastdirent = buf.previous;
1963 if (!lastdirent) {
1964 error = buf.error;
1965 goto out_f;
1967 lastdirent->d_off = (u64) file->f_pos;
1968 #ifdef DEBUG_GETDENTS
1969 printk("returning %d\n", cnt - buf.count);
1970 #endif
1971 error = cnt - buf.count;
1973 out_f:
1974 fput(file);
1975 out:
1976 return error;
1979 asmlinkage int irix_ngetdents64(int fd, void *dirent, int cnt, int *eob)
1981 struct file *file;
1982 struct irix_dirent64 *lastdirent;
1983 struct irix_dirent64_callback buf;
1984 int error;
1986 #ifdef DEBUG_GETDENTS
1987 printk("[%s:%d] ngetdents64(%d, %p, %d) ", current->comm,
1988 current->pid, fd, dirent, cnt);
1989 #endif
1990 error = -EBADF;
1991 if (!(file = fget(fd)))
1992 goto out;
1994 error = -EFAULT;
1995 if (!access_ok(VERIFY_WRITE, dirent, cnt) ||
1996 !access_ok(VERIFY_WRITE, eob, sizeof(*eob)))
1997 goto out_f;
1999 error = -EINVAL;
2000 if (cnt < (sizeof(struct irix_dirent64) + 255))
2001 goto out_f;
2003 *eob = 0;
2004 buf.curr = (struct irix_dirent64 *) dirent;
2005 buf.previous = NULL;
2006 buf.count = cnt;
2007 buf.error = 0;
2008 error = vfs_readdir(file, irix_filldir64, &buf);
2009 if (error < 0)
2010 goto out_f;
2011 lastdirent = buf.previous;
2012 if (!lastdirent) {
2013 error = buf.error;
2014 goto out_f;
2016 lastdirent->d_off = (u64) file->f_pos;
2017 #ifdef DEBUG_GETDENTS
2018 printk("eob=%d returning %d\n", *eob, cnt - buf.count);
2019 #endif
2020 error = cnt - buf.count;
2022 out_f:
2023 fput(file);
2024 out:
2025 return error;
2028 asmlinkage int irix_uadmin(unsigned long op, unsigned long func, unsigned long arg)
2030 int retval;
2032 switch (op) {
2033 case 1:
2034 /* Reboot */
2035 printk("[%s:%d] irix_uadmin: Wants to reboot...\n",
2036 current->comm, current->pid);
2037 retval = -EINVAL;
2038 goto out;
2040 case 2:
2041 /* Shutdown */
2042 printk("[%s:%d] irix_uadmin: Wants to shutdown...\n",
2043 current->comm, current->pid);
2044 retval = -EINVAL;
2045 goto out;
2047 case 4:
2048 /* Remount-root */
2049 printk("[%s:%d] irix_uadmin: Wants to remount root...\n",
2050 current->comm, current->pid);
2051 retval = -EINVAL;
2052 goto out;
2054 case 8:
2055 /* Kill all tasks. */
2056 printk("[%s:%d] irix_uadmin: Wants to kill all tasks...\n",
2057 current->comm, current->pid);
2058 retval = -EINVAL;
2059 goto out;
2061 case 256:
2062 /* Set magic mushrooms... */
2063 printk("[%s:%d] irix_uadmin: Wants to set magic mushroom[%d]...\n",
2064 current->comm, current->pid, (int) func);
2065 retval = -EINVAL;
2066 goto out;
2068 default:
2069 printk("[%s:%d] irix_uadmin: Unknown operation [%d]...\n",
2070 current->comm, current->pid, (int) op);
2071 retval = -EINVAL;
2072 goto out;
2075 out:
2076 return retval;
2079 asmlinkage int irix_utssys(char *inbuf, int arg, int type, char *outbuf)
2081 int retval;
2083 switch(type) {
2084 case 0:
2085 /* uname() */
2086 retval = irix_uname((struct iuname *)inbuf);
2087 goto out;
2089 case 2:
2090 /* ustat() */
2091 printk("[%s:%d] irix_utssys: Wants to do ustat()\n",
2092 current->comm, current->pid);
2093 retval = -EINVAL;
2094 goto out;
2096 case 3:
2097 /* fusers() */
2098 printk("[%s:%d] irix_utssys: Wants to do fusers()\n",
2099 current->comm, current->pid);
2100 retval = -EINVAL;
2101 goto out;
2103 default:
2104 printk("[%s:%d] irix_utssys: Wants to do unknown type[%d]\n",
2105 current->comm, current->pid, (int) type);
2106 retval = -EINVAL;
2107 goto out;
2110 out:
2111 return retval;
2114 #undef DEBUG_FCNTL
2116 extern asmlinkage long sys_fcntl(unsigned int fd, unsigned int cmd,
2117 unsigned long arg);
2119 #define IRIX_F_ALLOCSP 10
2121 asmlinkage int irix_fcntl(int fd, int cmd, int arg)
2123 int retval;
2125 #ifdef DEBUG_FCNTL
2126 printk("[%s:%d] irix_fcntl(%d, %d, %d) ", current->comm,
2127 current->pid, fd, cmd, arg);
2128 #endif
2129 if (cmd == IRIX_F_ALLOCSP){
2130 return 0;
2132 retval = sys_fcntl(fd, cmd, arg);
2133 #ifdef DEBUG_FCNTL
2134 printk("%d\n", retval);
2135 #endif
2136 return retval;
2139 asmlinkage int irix_ulimit(int cmd, int arg)
2141 int retval;
2143 switch(cmd) {
2144 case 1:
2145 printk("[%s:%d] irix_ulimit: Wants to get file size limit.\n",
2146 current->comm, current->pid);
2147 retval = -EINVAL;
2148 goto out;
2150 case 2:
2151 printk("[%s:%d] irix_ulimit: Wants to set file size limit.\n",
2152 current->comm, current->pid);
2153 retval = -EINVAL;
2154 goto out;
2156 case 3:
2157 printk("[%s:%d] irix_ulimit: Wants to get brk limit.\n",
2158 current->comm, current->pid);
2159 retval = -EINVAL;
2160 goto out;
2162 case 4:
2163 #if 0
2164 printk("[%s:%d] irix_ulimit: Wants to get fd limit.\n",
2165 current->comm, current->pid);
2166 retval = -EINVAL;
2167 goto out;
2168 #endif
2169 retval = current->rlim[RLIMIT_NOFILE].rlim_cur;
2170 goto out;
2172 case 5:
2173 printk("[%s:%d] irix_ulimit: Wants to get txt offset.\n",
2174 current->comm, current->pid);
2175 retval = -EINVAL;
2176 goto out;
2178 default:
2179 printk("[%s:%d] irix_ulimit: Unknown command [%d].\n",
2180 current->comm, current->pid, cmd);
2181 retval = -EINVAL;
2182 goto out;
2184 out:
2185 return retval;
2188 asmlinkage int irix_unimp(struct pt_regs *regs)
2190 printk("irix_unimp [%s:%d] v0=%d v1=%d a0=%08lx a1=%08lx a2=%08lx "
2191 "a3=%08lx\n", current->comm, current->pid,
2192 (int) regs->regs[2], (int) regs->regs[3],
2193 regs->regs[4], regs->regs[5], regs->regs[6], regs->regs[7]);
2195 return -ENOSYS;