| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Pioctl operations for Coda. | 
| John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 3 | * Original version: (C) 1996 Peter Braam | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Rewritten for Linux 2.1: (C) 1997 Carnegie Mellon University | 
|  | 5 | * | 
|  | 6 | * Carnegie Mellon encourages users of this code to contribute improvements | 
|  | 7 | * to the Coda project. Contact Peter Braam <coda@cs.cmu.edu>. | 
|  | 8 | */ | 
|  | 9 |  | 
|  | 10 | #include <linux/types.h> | 
|  | 11 | #include <linux/kernel.h> | 
|  | 12 | #include <linux/time.h> | 
|  | 13 | #include <linux/fs.h> | 
|  | 14 | #include <linux/stat.h> | 
|  | 15 | #include <linux/errno.h> | 
|  | 16 | #include <linux/string.h> | 
|  | 17 | #include <linux/namei.h> | 
|  | 18 | #include <linux/module.h> | 
|  | 19 | #include <asm/uaccess.h> | 
|  | 20 |  | 
|  | 21 | #include <linux/coda.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/coda_psdev.h> | 
|  | 23 |  | 
| Al Viro | 31a203d | 2011-01-12 16:36:09 -0500 | [diff] [blame] | 24 | #include "coda_linux.h" | 
|  | 25 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | /* pioctl ops */ | 
| Nick Piggin | b74c79e | 2011-01-07 17:49:58 +1100 | [diff] [blame] | 27 | static int coda_ioctl_permission(struct inode *inode, int mask, unsigned int flags); | 
| John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 28 | static long coda_pioctl(struct file *filp, unsigned int cmd, | 
|  | 29 | unsigned long user_data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 |  | 
|  | 31 | /* exported from this file */ | 
| John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 32 | const struct inode_operations coda_ioctl_inode_operations = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | .permission	= coda_ioctl_permission, | 
|  | 34 | .setattr	= coda_setattr, | 
|  | 35 | }; | 
|  | 36 |  | 
| Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 37 | const struct file_operations coda_ioctl_operations = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | .owner		= THIS_MODULE, | 
| John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 39 | .unlocked_ioctl	= coda_pioctl, | 
| Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 40 | .llseek		= noop_llseek, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | }; | 
|  | 42 |  | 
|  | 43 | /* the coda pioctl inode ops */ | 
| Nick Piggin | b74c79e | 2011-01-07 17:49:58 +1100 | [diff] [blame] | 44 | static int coda_ioctl_permission(struct inode *inode, int mask, unsigned int flags) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | { | 
| Nick Piggin | b74c79e | 2011-01-07 17:49:58 +1100 | [diff] [blame] | 46 | if (flags & IPERM_FLAG_RCU) | 
|  | 47 | return -ECHILD; | 
| Miklos Szeredi | f696a36 | 2008-07-31 13:41:58 +0200 | [diff] [blame] | 48 | return (mask & MAY_EXEC) ? -EACCES : 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | } | 
|  | 50 |  | 
| John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 51 | static long coda_pioctl(struct file *filp, unsigned int cmd, | 
|  | 52 | unsigned long user_data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | { | 
| Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 54 | struct path path; | 
| John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 55 | int error; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | struct PioctlData data; | 
| John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 57 | struct inode *inode = filp->f_dentry->d_inode; | 
| John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 58 | struct inode *target_inode = NULL; | 
|  | 59 | struct coda_inode_info *cnp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 |  | 
| John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 61 | /* get the Pioctl data arguments from user space */ | 
| Yoshihisa Abe | f7cc02b | 2010-10-25 02:03:45 -0400 | [diff] [blame] | 62 | if (copy_from_user(&data, (void __user *)user_data, sizeof(data))) | 
|  | 63 | return -EINVAL; | 
| John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 64 |  | 
|  | 65 | /* | 
|  | 66 | * Look up the pathname. Note that the pathname is in | 
|  | 67 | * user memory, and namei takes care of this | 
|  | 68 | */ | 
| John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 69 | if (data.follow) | 
| John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 70 | error = user_path(data.path, &path); | 
| John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 71 | else | 
| John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 72 | error = user_lpath(data.path, &path); | 
| John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 73 |  | 
|  | 74 | if (error) | 
| Yoshihisa Abe | f7cc02b | 2010-10-25 02:03:45 -0400 | [diff] [blame] | 75 | return error; | 
|  | 76 |  | 
|  | 77 | target_inode = path.dentry->d_inode; | 
| John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 78 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | /* return if it is not a Coda inode */ | 
| John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 80 | if (target_inode->i_sb != inode->i_sb) { | 
| John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 81 | error = -EINVAL; | 
|  | 82 | goto out; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | } | 
|  | 84 |  | 
|  | 85 | /* now proceed to make the upcall */ | 
| John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 86 | cnp = ITOC(target_inode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 |  | 
|  | 88 | error = venus_pioctl(inode->i_sb, &(cnp->c_fid), cmd, &data); | 
| John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 89 | out: | 
| Yoshihisa Abe | f7cc02b | 2010-10-25 02:03:45 -0400 | [diff] [blame] | 90 | path_put(&path); | 
| John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 91 | return error; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | } |