blob: 028a9a0f588b2664cee7ab65a3a7f8ccc88af61c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Pioctl operations for Coda.
John Kacur1977bb22010-05-05 15:15:35 +02003 * Original version: (C) 1996 Peter Braam
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * 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 Kacur2ff82f82010-05-05 15:15:34 +020026#include <linux/smp_lock.h>
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028/* pioctl ops */
Al Viroe6305c42008-07-15 21:03:57 -040029static int coda_ioctl_permission(struct inode *inode, int mask);
John Kacur2ff82f82010-05-05 15:15:34 +020030static long coda_pioctl(struct file *filp, unsigned int cmd,
31 unsigned long user_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33/* exported from this file */
John Kacur1977bb22010-05-05 15:15:35 +020034const struct inode_operations coda_ioctl_inode_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 .permission = coda_ioctl_permission,
36 .setattr = coda_setattr,
37};
38
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -080039const struct file_operations coda_ioctl_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 .owner = THIS_MODULE,
John Kacur2ff82f82010-05-05 15:15:34 +020041 .unlocked_ioctl = coda_pioctl,
Arnd Bergmann6038f372010-08-15 18:52:59 +020042 .llseek = noop_llseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -070043};
44
45/* the coda pioctl inode ops */
Al Viroe6305c42008-07-15 21:03:57 -040046static int coda_ioctl_permission(struct inode *inode, int mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -070047{
Miklos Szeredif696a362008-07-31 13:41:58 +020048 return (mask & MAY_EXEC) ? -EACCES : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049}
50
John Kacur2ff82f82010-05-05 15:15:34 +020051static long coda_pioctl(struct file *filp, unsigned int cmd,
52 unsigned long user_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
Al Viro2d8f3032008-07-22 09:59:21 -040054 struct path path;
John Kacur1977bb22010-05-05 15:15:35 +020055 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 struct PioctlData data;
John Kacur2ff82f82010-05-05 15:15:34 +020057 struct inode *inode = filp->f_dentry->d_inode;
John Kacur1977bb22010-05-05 15:15:35 +020058 struct inode *target_inode = NULL;
59 struct coda_inode_info *cnp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
John Kacur2ff82f82010-05-05 15:15:34 +020061 lock_kernel();
62
John Kacur1977bb22010-05-05 15:15:35 +020063 /* get the Pioctl data arguments from user space */
64 if (copy_from_user(&data, (void __user *)user_data, sizeof(data))) {
John Kacur2ff82f82010-05-05 15:15:34 +020065 error = -EINVAL;
66 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 }
John Kacur1977bb22010-05-05 15:15:35 +020068
69 /*
70 * Look up the pathname. Note that the pathname is in
71 * user memory, and namei takes care of this
72 */
John Kacur2ff82f82010-05-05 15:15:34 +020073 if (data.follow)
John Kacur1977bb22010-05-05 15:15:35 +020074 error = user_path(data.path, &path);
John Kacur2ff82f82010-05-05 15:15:34 +020075 else
John Kacur1977bb22010-05-05 15:15:35 +020076 error = user_lpath(data.path, &path);
John Kacur2ff82f82010-05-05 15:15:34 +020077
78 if (error)
79 goto out;
80 else
Al Viro2d8f3032008-07-22 09:59:21 -040081 target_inode = path.dentry->d_inode;
John Kacur2ff82f82010-05-05 15:15:34 +020082
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 /* return if it is not a Coda inode */
John Kacur1977bb22010-05-05 15:15:35 +020084 if (target_inode->i_sb != inode->i_sb) {
Al Viro2d8f3032008-07-22 09:59:21 -040085 path_put(&path);
John Kacur2ff82f82010-05-05 15:15:34 +020086 error = -EINVAL;
87 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 }
89
90 /* now proceed to make the upcall */
John Kacur1977bb22010-05-05 15:15:35 +020091 cnp = ITOC(target_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93 error = venus_pioctl(inode->i_sb, &(cnp->c_fid), cmd, &data);
94
Al Viro2d8f3032008-07-22 09:59:21 -040095 path_put(&path);
John Kacur2ff82f82010-05-05 15:15:34 +020096
97out:
98 unlock_kernel();
John Kacur1977bb22010-05-05 15:15:35 +020099 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100}