blob: 6cbb3afb36dc2b28b9aa3f2b585c195330894699 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/coda_psdev.h>
23
Al Viro31a203d2011-01-12 16:36:09 -050024#include "coda_linux.h"
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026/* pioctl ops */
Nick Pigginb74c79e2011-01-07 17:49:58 +110027static int coda_ioctl_permission(struct inode *inode, int mask, unsigned int flags);
John Kacur2ff82f82010-05-05 15:15:34 +020028static long coda_pioctl(struct file *filp, unsigned int cmd,
29 unsigned long user_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31/* exported from this file */
John Kacur1977bb22010-05-05 15:15:35 +020032const struct inode_operations coda_ioctl_inode_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 .permission = coda_ioctl_permission,
34 .setattr = coda_setattr,
35};
36
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -080037const struct file_operations coda_ioctl_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 .owner = THIS_MODULE,
John Kacur2ff82f82010-05-05 15:15:34 +020039 .unlocked_ioctl = coda_pioctl,
Arnd Bergmann6038f372010-08-15 18:52:59 +020040 .llseek = noop_llseek,
Linus Torvalds1da177e2005-04-16 15:20:36 -070041};
42
43/* the coda pioctl inode ops */
Nick Pigginb74c79e2011-01-07 17:49:58 +110044static int coda_ioctl_permission(struct inode *inode, int mask, unsigned int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045{
Nick Pigginb74c79e2011-01-07 17:49:58 +110046 if (flags & IPERM_FLAG_RCU)
47 return -ECHILD;
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 Kacur1977bb22010-05-05 15:15:35 +020061 /* get the Pioctl data arguments from user space */
Yoshihisa Abef7cc02b2010-10-25 02:03:45 -040062 if (copy_from_user(&data, (void __user *)user_data, sizeof(data)))
63 return -EINVAL;
John Kacur1977bb22010-05-05 15:15:35 +020064
65 /*
66 * Look up the pathname. Note that the pathname is in
67 * user memory, and namei takes care of this
68 */
John Kacur2ff82f82010-05-05 15:15:34 +020069 if (data.follow)
John Kacur1977bb22010-05-05 15:15:35 +020070 error = user_path(data.path, &path);
John Kacur2ff82f82010-05-05 15:15:34 +020071 else
John Kacur1977bb22010-05-05 15:15:35 +020072 error = user_lpath(data.path, &path);
John Kacur2ff82f82010-05-05 15:15:34 +020073
74 if (error)
Yoshihisa Abef7cc02b2010-10-25 02:03:45 -040075 return error;
76
77 target_inode = path.dentry->d_inode;
John Kacur2ff82f82010-05-05 15:15:34 +020078
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 /* return if it is not a Coda inode */
John Kacur1977bb22010-05-05 15:15:35 +020080 if (target_inode->i_sb != inode->i_sb) {
John Kacur2ff82f82010-05-05 15:15:34 +020081 error = -EINVAL;
82 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 }
84
85 /* now proceed to make the upcall */
John Kacur1977bb22010-05-05 15:15:35 +020086 cnp = ITOC(target_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88 error = venus_pioctl(inode->i_sb, &(cnp->c_fid), cmd, &data);
John Kacur2ff82f82010-05-05 15:15:34 +020089out:
Yoshihisa Abef7cc02b2010-10-25 02:03:45 -040090 path_put(&path);
John Kacur1977bb22010-05-05 15:15:35 +020091 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092}