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