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