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