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