⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sysirix.c

📁 LINUX 2.6.17.4的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
	if (!access_ok(VERIFY_WRITE, buf, sizeof(struct irix_statvfs64))) {		error = -EFAULT;		goto out;	}	error = user_path_walk(fname, &nd);	if (error)		goto out;	error = vfs_statfs(nd.dentry->d_inode->i_sb, &kbuf);	if (error)		goto dput_and_out;	error = __put_user(kbuf.f_bsize, &buf->f_bsize);	error |= __put_user(kbuf.f_frsize, &buf->f_frsize);	error |= __put_user(kbuf.f_blocks, &buf->f_blocks);	error |= __put_user(kbuf.f_bfree, &buf->f_bfree);	error |= __put_user(kbuf.f_bfree, &buf->f_bavail);  /* XXX hackety hack... */	error |= __put_user(kbuf.f_files, &buf->f_files);	error |= __put_user(kbuf.f_ffree, &buf->f_ffree);	error |= __put_user(kbuf.f_ffree, &buf->f_favail);  /* XXX hackety hack... */#ifdef __MIPSEB__	error |= __put_user(kbuf.f_fsid.val[1], &buf->f_fsid);#else	error |= __put_user(kbuf.f_fsid.val[0], &buf->f_fsid);#endif	for(i = 0; i < 16; i++)		error |= __put_user(0, &buf->f_basetype[i]);	error |= __put_user(0, &buf->f_flag);	error |= __put_user(kbuf.f_namelen, &buf->f_namemax);	for(i = 0; i < 32; i++)		error |= __put_user(0, &buf->f_fstr[i]);dput_and_out:	path_release(&nd);out:	return error;}asmlinkage int irix_fstatvfs64(int fd, struct irix_statvfs __user *buf){	struct kstatfs kbuf;	struct file *file;	int error, i;	printk("[%s:%d] Wheee.. irix_fstatvfs64(%d,%p)\n",	       current->comm, current->pid, fd, buf);	if (!access_ok(VERIFY_WRITE, buf, sizeof(struct irix_statvfs))) {		error = -EFAULT;		goto out;	}	if (!(file = fget(fd))) {		error = -EBADF;		goto out;	}	error = vfs_statfs(file->f_dentry->d_inode->i_sb, &kbuf);	if (error)		goto out_f;	error = __put_user(kbuf.f_bsize, &buf->f_bsize);	error |= __put_user(kbuf.f_frsize, &buf->f_frsize);	error |= __put_user(kbuf.f_blocks, &buf->f_blocks);	error |= __put_user(kbuf.f_bfree, &buf->f_bfree);	error |= __put_user(kbuf.f_bfree, &buf->f_bavail);  /* XXX hackety hack... */	error |= __put_user(kbuf.f_files, &buf->f_files);	error |= __put_user(kbuf.f_ffree, &buf->f_ffree);	error |= __put_user(kbuf.f_ffree, &buf->f_favail);  /* XXX hackety hack... */#ifdef __MIPSEB__	error |= __put_user(kbuf.f_fsid.val[1], &buf->f_fsid);#else	error |= __put_user(kbuf.f_fsid.val[0], &buf->f_fsid);#endif	for(i = 0; i < 16; i++)		error |= __put_user(0, &buf->f_basetype[i]);	error |= __put_user(0, &buf->f_flag);	error |= __put_user(kbuf.f_namelen, &buf->f_namemax);	error |= __clear_user(buf->f_fstr, sizeof(buf->f_fstr[i])) ? -EFAULT : 0;out_f:	fput(file);out:	return error;}asmlinkage int irix_getmountid(char __user *fname, unsigned long __user *midbuf){	int err;	printk("[%s:%d] irix_getmountid(%s, %p)\n",	       current->comm, current->pid, fname, midbuf);	if (!access_ok(VERIFY_WRITE, midbuf, (sizeof(unsigned long) * 4)))		return -EFAULT;	/*	 * The idea with this system call is that when trying to determine	 * 'pwd' and it's a toss-up for some reason, userland can use the	 * fsid of the filesystem to try and make the right decision, but	 * we don't have this so for now. XXX	 */	err = __put_user(0, &midbuf[0]);	err |= __put_user(0, &midbuf[1]);	err |= __put_user(0, &midbuf[2]);	err |= __put_user(0, &midbuf[3]);	return err;}asmlinkage int irix_nsproc(unsigned long entry, unsigned long mask,			   unsigned long arg, unsigned long sp, int slen){	printk("[%s:%d] Wheee.. irix_nsproc(%08lx,%08lx,%08lx,%08lx,%d)\n",	       current->comm, current->pid, entry, mask, arg, sp, slen);	return -EINVAL;}#undef DEBUG_GETDENTSstruct irix_dirent32 {	u32  d_ino;	u32  d_off;	unsigned short  d_reclen;	char d_name[1];};struct irix_dirent32_callback {	struct irix_dirent32 __user *current_dir;	struct irix_dirent32 __user *previous;	int count;	int error;};#define NAME_OFFSET32(de) ((int) ((de)->d_name - (char *) (de)))#define ROUND_UP32(x) (((x)+sizeof(u32)-1) & ~(sizeof(u32)-1))static int irix_filldir32(void *__buf, const char *name,	int namlen, loff_t offset, ino_t ino, unsigned int d_type){	struct irix_dirent32 __user *dirent;	struct irix_dirent32_callback *buf = __buf;	unsigned short reclen = ROUND_UP32(NAME_OFFSET32(dirent) + namlen + 1);	int err = 0;#ifdef DEBUG_GETDENTS	printk("\nirix_filldir32[reclen<%d>namlen<%d>count<%d>]",	       reclen, namlen, buf->count);#endif	buf->error = -EINVAL;	/* only used if we fail.. */	if (reclen > buf->count)		return -EINVAL;	dirent = buf->previous;	if (dirent)		err = __put_user(offset, &dirent->d_off);	dirent = buf->current_dir;	err |= __put_user(dirent, &buf->previous);	err |= __put_user(ino, &dirent->d_ino);	err |= __put_user(reclen, &dirent->d_reclen);	err |= copy_to_user((char __user *)dirent->d_name, name, namlen) ? -EFAULT : 0;	err |= __put_user(0, &dirent->d_name[namlen]);	dirent = (struct irix_dirent32 __user *) ((char __user *) dirent + reclen);	buf->current_dir = dirent;	buf->count -= reclen;	return err;}asmlinkage int irix_ngetdents(unsigned int fd, void __user * dirent,	unsigned int count, int __user *eob){	struct file *file;	struct irix_dirent32 __user *lastdirent;	struct irix_dirent32_callback buf;	int error;#ifdef DEBUG_GETDENTS	printk("[%s:%d] ngetdents(%d, %p, %d, %p) ", current->comm,	       current->pid, fd, dirent, count, eob);#endif	error = -EBADF;	file = fget(fd);	if (!file)		goto out;	buf.current_dir = (struct irix_dirent32 __user *) dirent;	buf.previous = NULL;	buf.count = count;	buf.error = 0;	error = vfs_readdir(file, irix_filldir32, &buf);	if (error < 0)		goto out_putf;	error = buf.error;	lastdirent = buf.previous;	if (lastdirent) {		put_user(file->f_pos, &lastdirent->d_off);		error = count - buf.count;	}	if (put_user(0, eob) < 0) {		error = -EFAULT;		goto out_putf;	}#ifdef DEBUG_GETDENTS	printk("eob=%d returning %d\n", *eob, count - buf.count);#endif	error = count - buf.count;out_putf:	fput(file);out:	return error;}struct irix_dirent64 {	u64            d_ino;	u64            d_off;	unsigned short d_reclen;	char           d_name[1];};struct irix_dirent64_callback {	struct irix_dirent64 __user *curr;	struct irix_dirent64 __user *previous;	int count;	int error;};#define NAME_OFFSET64(de) ((int) ((de)->d_name - (char *) (de)))#define ROUND_UP64(x) (((x)+sizeof(u64)-1) & ~(sizeof(u64)-1))static int irix_filldir64(void *__buf, const char *name,	int namlen, loff_t offset, ino_t ino, unsigned int d_type){	struct irix_dirent64 __user *dirent;	struct irix_dirent64_callback * buf = __buf;	unsigned short reclen = ROUND_UP64(NAME_OFFSET64(dirent) + namlen + 1);	int err = 0;	if (!access_ok(VERIFY_WRITE, buf, sizeof(*buf)))		return -EFAULT;	if (__put_user(-EINVAL, &buf->error))	/* only used if we fail.. */		return -EFAULT;	if (reclen > buf->count)		return -EINVAL;	dirent = buf->previous;	if (dirent)		err = __put_user(offset, &dirent->d_off);	dirent = buf->curr;	buf->previous = dirent;	err |= __put_user(ino, &dirent->d_ino);	err |= __put_user(reclen, &dirent->d_reclen);	err |= __copy_to_user((char __user *)dirent->d_name, name, namlen)	       ? -EFAULT : 0;	err |= __put_user(0, &dirent->d_name[namlen]);	dirent = (struct irix_dirent64 __user *) ((char __user *) dirent + reclen);	buf->curr = dirent;	buf->count -= reclen;	return err;}asmlinkage int irix_getdents64(int fd, void __user *dirent, int cnt){	struct file *file;	struct irix_dirent64 __user *lastdirent;	struct irix_dirent64_callback buf;	int error;#ifdef DEBUG_GETDENTS	printk("[%s:%d] getdents64(%d, %p, %d) ", current->comm,	       current->pid, fd, dirent, cnt);#endif	error = -EBADF;	if (!(file = fget(fd)))		goto out;	error = -EFAULT;	if (!access_ok(VERIFY_WRITE, dirent, cnt))		goto out_f;	error = -EINVAL;	if (cnt < (sizeof(struct irix_dirent64) + 255))		goto out_f;	buf.curr = (struct irix_dirent64 __user *) dirent;	buf.previous = NULL;	buf.count = cnt;	buf.error = 0;	error = vfs_readdir(file, irix_filldir64, &buf);	if (error < 0)		goto out_f;	lastdirent = buf.previous;	if (!lastdirent) {		error = buf.error;		goto out_f;	}	if (put_user(file->f_pos, &lastdirent->d_off))		return -EFAULT;#ifdef DEBUG_GETDENTS	printk("returning %d\n", cnt - buf.count);#endif	error = cnt - buf.count;out_f:	fput(file);out:	return error;}asmlinkage int irix_ngetdents64(int fd, void __user *dirent, int cnt, int *eob){	struct file *file;	struct irix_dirent64 __user *lastdirent;	struct irix_dirent64_callback buf;	int error;#ifdef DEBUG_GETDENTS	printk("[%s:%d] ngetdents64(%d, %p, %d) ", current->comm,	       current->pid, fd, dirent, cnt);#endif	error = -EBADF;	if (!(file = fget(fd)))		goto out;	error = -EFAULT;	if (!access_ok(VERIFY_WRITE, dirent, cnt) ||	    !access_ok(VERIFY_WRITE, eob, sizeof(*eob)))		goto out_f;	error = -EINVAL;	if (cnt < (sizeof(struct irix_dirent64) + 255))		goto out_f;	*eob = 0;	buf.curr = (struct irix_dirent64 __user *) dirent;	buf.previous = NULL;	buf.count = cnt;	buf.error = 0;	error = vfs_readdir(file, irix_filldir64, &buf);	if (error < 0)		goto out_f;	lastdirent = buf.previous;	if (!lastdirent) {		error = buf.error;		goto out_f;	}	if (put_user(file->f_pos, &lastdirent->d_off))		return -EFAULT;#ifdef DEBUG_GETDENTS	printk("eob=%d returning %d\n", *eob, cnt - buf.count);#endif	error = cnt - buf.count;out_f:	fput(file);out:	return error;}asmlinkage int irix_uadmin(unsigned long op, unsigned long func, unsigned long arg){	int retval;	switch (op) {	case 1:		/* Reboot */		printk("[%s:%d] irix_uadmin: Wants to reboot...\n",		       current->comm, current->pid);		retval = -EINVAL;		goto out;	case 2:		/* Shutdown */		printk("[%s:%d] irix_uadmin: Wants to shutdown...\n",		       current->comm, current->pid);		retval = -EINVAL;		goto out;	case 4:		/* Remount-root */		printk("[%s:%d] irix_uadmin: Wants to remount root...\n",		       current->comm, current->pid);		retval = -EINVAL;		goto out;	case 8:		/* Kill all tasks. */		printk("[%s:%d] irix_uadmin: Wants to kill all tasks...\n",		       current->comm, current->pid);		retval = -EINVAL;		goto out;	case 256:		/* Set magic mushrooms... */		printk("[%s:%d] irix_uadmin: Wants to set magic mushroom[%d]...\n",		       current->comm, current->pid, (int) func);		retval = -EINVAL;		goto out;	default:		printk("[%s:%d] irix_uadmin: Unknown operation [%d]...\n",		       current->comm, current->pid, (int) op);		retval = -EINVAL;		goto out;	};out:	return retval;}asmlinkage int irix_utssys(char __user *inbuf, int arg, int type, char __user *outbuf){	int retval;	switch(type) {	case 0:		/* uname() */		retval = irix_uname((struct iuname __user *)inbuf);		goto out;	case 2:		/* ustat() */		printk("[%s:%d] irix_utssys: Wants to do ustat()\n",		       current->comm, current->pid);		retval = -EINVAL;		goto out;	case 3:		/* fusers() */		printk("[%s:%d] irix_utssys: Wants to do fusers()\n",		       current->comm, current->pid);		retval = -EINVAL;		goto out;	default:		printk("[%s:%d] irix_utssys: Wants to do unknown type[%d]\n",		       current->comm, current->pid, (int) type);		retval = -EINVAL;		goto out;	}out:	return retval;}#undef DEBUG_FCNTL#define IRIX_F_ALLOCSP 10asmlinkage int irix_fcntl(int fd, int cmd, int arg){	int retval;#ifdef DEBUG_FCNTL	printk("[%s:%d] irix_fcntl(%d, %d, %d) ", current->comm,	       current->pid, fd, cmd, arg);#endif	if (cmd == IRIX_F_ALLOCSP){		return 0;	}	retval = sys_fcntl(fd, cmd, arg);#ifdef DEBUG_FCNTL	printk("%d\n", retval);#endif	return retval;}asmlinkage int irix_ulimit(int cmd, int arg){	int retval;	switch(cmd) {	case 1:		printk("[%s:%d] irix_ulimit: Wants to get file size limit.\n",		       current->comm, current->pid);		retval = -EINVAL;		goto out;	case 2:		printk("[%s:%d] irix_ulimit: Wants to set file size limit.\n",		       current->comm, current->pid);		retval = -EINVAL;		goto out;	case 3:		printk("[%s:%d] irix_ulimit: Wants to get brk limit.\n",		       current->comm, current->pid);		retval = -EINVAL;		goto out;	case 4:#if 0		printk("[%s:%d] irix_ulimit: Wants to get fd limit.\n",		       current->comm, current->pid);		retval = -EINVAL;		goto out;#endif		retval = current->signal->rlim[RLIMIT_NOFILE].rlim_cur;		goto out;	case 5:		printk("[%s:%d] irix_ulimit: Wants to get txt offset.\n",		       current->comm, current->pid);		retval = -EINVAL;		goto out;	default:		printk("[%s:%d] irix_ulimit: Unknown command [%d].\n",		       current->comm, current->pid, cmd);		retval = -EINVAL;		goto out;	}out:	return retval;}asmlinkage int irix_unimp(struct pt_regs *regs){	printk("irix_unimp [%s:%d] v0=%d v1=%d a0=%08lx a1=%08lx a2=%08lx "	       "a3=%08lx\n", current->comm, current->pid,	       (int) regs->regs[2], (int) regs->regs[3],	       regs->regs[4], regs->regs[5], regs->regs[6], regs->regs[7]);	return -ENOSYS;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -