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