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> |
| 22 | #include <linux/coda_linux.h> |
| 23 | #include <linux/coda_fs_i.h> |
| 24 | #include <linux/coda_psdev.h> |
| 25 | |
John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 26 | #include <linux/smp_lock.h> |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | /* pioctl ops */ |
Al Viro | e6305c4 | 2008-07-15 21:03:57 -0400 | [diff] [blame] | 29 | static int coda_ioctl_permission(struct inode *inode, int mask); |
John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 30 | static long coda_pioctl(struct file *filp, unsigned int cmd, |
| 31 | unsigned long user_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
| 33 | /* exported from this file */ |
John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 34 | const struct inode_operations coda_ioctl_inode_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | .permission = coda_ioctl_permission, |
| 36 | .setattr = coda_setattr, |
| 37 | }; |
| 38 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 39 | const struct file_operations coda_ioctl_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | .owner = THIS_MODULE, |
John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 41 | .unlocked_ioctl = coda_pioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | /* the coda pioctl inode ops */ |
Al Viro | e6305c4 | 2008-07-15 21:03:57 -0400 | [diff] [blame] | 45 | static int coda_ioctl_permission(struct inode *inode, int mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | { |
Miklos Szeredi | f696a36 | 2008-07-31 13:41:58 +0200 | [diff] [blame] | 47 | return (mask & MAY_EXEC) ? -EACCES : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | } |
| 49 | |
John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 50 | static long coda_pioctl(struct file *filp, unsigned int cmd, |
| 51 | unsigned long user_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 53 | struct path path; |
John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 54 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | struct PioctlData data; |
John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 56 | struct inode *inode = filp->f_dentry->d_inode; |
John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 57 | struct inode *target_inode = NULL; |
| 58 | struct coda_inode_info *cnp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 60 | lock_kernel(); |
| 61 | |
John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 62 | /* get the Pioctl data arguments from user space */ |
| 63 | if (copy_from_user(&data, (void __user *)user_data, sizeof(data))) { |
John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 64 | error = -EINVAL; |
| 65 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | } |
John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 67 | |
| 68 | /* |
| 69 | * Look up the pathname. Note that the pathname is in |
| 70 | * user memory, and namei takes care of this |
| 71 | */ |
John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 72 | if (data.follow) |
John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 73 | error = user_path(data.path, &path); |
John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 74 | else |
John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 75 | error = user_lpath(data.path, &path); |
John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 76 | |
| 77 | if (error) |
| 78 | goto out; |
| 79 | else |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 80 | target_inode = path.dentry->d_inode; |
John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | /* return if it is not a Coda inode */ |
John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 83 | if (target_inode->i_sb != inode->i_sb) { |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 84 | path_put(&path); |
John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 85 | error = -EINVAL; |
| 86 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /* now proceed to make the upcall */ |
John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 90 | cnp = ITOC(target_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
| 92 | error = venus_pioctl(inode->i_sb, &(cnp->c_fid), cmd, &data); |
| 93 | |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 94 | path_put(&path); |
John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 95 | |
| 96 | out: |
| 97 | unlock_kernel(); |
John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 98 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | } |