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> |
Fabian Frederick | 834b46c | 2014-08-08 14:20:33 -0700 | [diff] [blame] | 19 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 */ |
Al Viro | 10556cb | 2011-06-20 19:28:19 -0400 | [diff] [blame] | 27 | static int coda_ioctl_permission(struct inode *inode, int mask); |
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 = { |
John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 38 | .unlocked_ioctl = coda_pioctl, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 39 | .llseek = noop_llseek, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | /* the coda pioctl inode ops */ |
Al Viro | 10556cb | 2011-06-20 19:28:19 -0400 | [diff] [blame] | 43 | static int coda_ioctl_permission(struct inode *inode, int mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | { |
Miklos Szeredi | f696a36 | 2008-07-31 13:41:58 +0200 | [diff] [blame] | 45 | return (mask & MAY_EXEC) ? -EACCES : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | } |
| 47 | |
John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 48 | static long coda_pioctl(struct file *filp, unsigned int cmd, |
| 49 | unsigned long user_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | { |
Al Viro | 2d8f303 | 2008-07-22 09:59:21 -0400 | [diff] [blame] | 51 | struct path path; |
John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 52 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | struct PioctlData data; |
Al Viro | 496ad9a | 2013-01-23 17:07:38 -0500 | [diff] [blame] | 54 | struct inode *inode = file_inode(filp); |
John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 55 | struct inode *target_inode = NULL; |
| 56 | struct coda_inode_info *cnp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 58 | /* get the Pioctl data arguments from user space */ |
Yoshihisa Abe | f7cc02b8 | 2010-10-25 02:03:45 -0400 | [diff] [blame] | 59 | if (copy_from_user(&data, (void __user *)user_data, sizeof(data))) |
| 60 | return -EINVAL; |
John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 61 | |
| 62 | /* |
| 63 | * Look up the pathname. Note that the pathname is in |
| 64 | * user memory, and namei takes care of this |
| 65 | */ |
John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 66 | if (data.follow) |
John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 67 | error = user_path(data.path, &path); |
John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 68 | else |
John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 69 | error = user_lpath(data.path, &path); |
John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 70 | |
| 71 | if (error) |
Yoshihisa Abe | f7cc02b8 | 2010-10-25 02:03:45 -0400 | [diff] [blame] | 72 | return error; |
| 73 | |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 74 | target_inode = d_inode(path.dentry); |
John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | /* return if it is not a Coda inode */ |
John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 77 | if (target_inode->i_sb != inode->i_sb) { |
John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 78 | error = -EINVAL; |
| 79 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | /* now proceed to make the upcall */ |
John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 83 | cnp = ITOC(target_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
| 85 | error = venus_pioctl(inode->i_sb, &(cnp->c_fid), cmd, &data); |
John Kacur | 2ff82f8 | 2010-05-05 15:15:34 +0200 | [diff] [blame] | 86 | out: |
Yoshihisa Abe | f7cc02b8 | 2010-10-25 02:03:45 -0400 | [diff] [blame] | 87 | path_put(&path); |
John Kacur | 1977bb2 | 2010-05-05 15:15:35 +0200 | [diff] [blame] | 88 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | } |