blob: ca25d96d45c9a51caa6d63d33f6670eaa769fcbc [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,
Linus Torvalds1da177e2005-04-16 15:20:36 -070042};
43
44/* the coda pioctl inode ops */
Al Viroe6305c42008-07-15 21:03:57 -040045static int coda_ioctl_permission(struct inode *inode, int mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -070046{
Miklos Szeredif696a362008-07-31 13:41:58 +020047 return (mask & MAY_EXEC) ? -EACCES : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048}
49
John Kacur2ff82f82010-05-05 15:15:34 +020050static long coda_pioctl(struct file *filp, unsigned int cmd,
51 unsigned long user_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052{
Al Viro2d8f3032008-07-22 09:59:21 -040053 struct path path;
John Kacur1977bb22010-05-05 15:15:35 +020054 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 struct PioctlData data;
John Kacur2ff82f82010-05-05 15:15:34 +020056 struct inode *inode = filp->f_dentry->d_inode;
John Kacur1977bb22010-05-05 15:15:35 +020057 struct inode *target_inode = NULL;
58 struct coda_inode_info *cnp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
John Kacur2ff82f82010-05-05 15:15:34 +020060 lock_kernel();
61
John Kacur1977bb22010-05-05 15:15:35 +020062 /* get the Pioctl data arguments from user space */
63 if (copy_from_user(&data, (void __user *)user_data, sizeof(data))) {
John Kacur2ff82f82010-05-05 15:15:34 +020064 error = -EINVAL;
65 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 }
John Kacur1977bb22010-05-05 15:15:35 +020067
68 /*
69 * Look up the pathname. Note that the pathname is in
70 * user memory, and namei takes care of this
71 */
John Kacur2ff82f82010-05-05 15:15:34 +020072 if (data.follow)
John Kacur1977bb22010-05-05 15:15:35 +020073 error = user_path(data.path, &path);
John Kacur2ff82f82010-05-05 15:15:34 +020074 else
John Kacur1977bb22010-05-05 15:15:35 +020075 error = user_lpath(data.path, &path);
John Kacur2ff82f82010-05-05 15:15:34 +020076
77 if (error)
78 goto out;
79 else
Al Viro2d8f3032008-07-22 09:59:21 -040080 target_inode = path.dentry->d_inode;
John Kacur2ff82f82010-05-05 15:15:34 +020081
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 /* return if it is not a Coda inode */
John Kacur1977bb22010-05-05 15:15:35 +020083 if (target_inode->i_sb != inode->i_sb) {
Al Viro2d8f3032008-07-22 09:59:21 -040084 path_put(&path);
John Kacur2ff82f82010-05-05 15:15:34 +020085 error = -EINVAL;
86 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 }
88
89 /* now proceed to make the upcall */
John Kacur1977bb22010-05-05 15:15:35 +020090 cnp = ITOC(target_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92 error = venus_pioctl(inode->i_sb, &(cnp->c_fid), cmd, &data);
93
Al Viro2d8f3032008-07-22 09:59:21 -040094 path_put(&path);
John Kacur2ff82f82010-05-05 15:15:34 +020095
96out:
97 unlock_kernel();
John Kacur1977bb22010-05-05 15:15:35 +020098 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099}