pioctl.c 2.2 KB
Newer Older
L
Linus Torvalds 已提交
1 2
/*
 * Pioctl operations for Coda.
3
 * Original version: (C) 1996 Peter Braam
L
Linus Torvalds 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 * Rewritten for Linux 2.1: (C) 1997 Carnegie Mellon University
 *
 * Carnegie Mellon encourages users of this code to contribute improvements
 * to the Coda project. Contact Peter Braam <coda@cs.cmu.edu>.
 */

#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/time.h>
#include <linux/fs.h>
#include <linux/stat.h>
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/namei.h>
#include <linux/module.h>
#include <asm/uaccess.h>

#include <linux/coda.h>
#include <linux/coda_psdev.h>

24 25
#include "coda_linux.h"

L
Linus Torvalds 已提交
26
/* pioctl ops */
27
static int coda_ioctl_permission(struct inode *inode, int mask, unsigned int flags);
J
John Kacur 已提交
28 29
static long coda_pioctl(struct file *filp, unsigned int cmd,
			unsigned long user_data);
L
Linus Torvalds 已提交
30 31

/* exported from this file */
32
const struct inode_operations coda_ioctl_inode_operations = {
L
Linus Torvalds 已提交
33 34 35 36
	.permission	= coda_ioctl_permission,
	.setattr	= coda_setattr,
};

37
const struct file_operations coda_ioctl_operations = {
L
Linus Torvalds 已提交
38
	.owner		= THIS_MODULE,
J
John Kacur 已提交
39
	.unlocked_ioctl	= coda_pioctl,
40
	.llseek		= noop_llseek,
L
Linus Torvalds 已提交
41 42 43
};

/* the coda pioctl inode ops */
44
static int coda_ioctl_permission(struct inode *inode, int mask, unsigned int flags)
L
Linus Torvalds 已提交
45
{
46 47
	if (flags & IPERM_FLAG_RCU)
		return -ECHILD;
48
	return (mask & MAY_EXEC) ? -EACCES : 0;
L
Linus Torvalds 已提交
49 50
}

J
John Kacur 已提交
51 52
static long coda_pioctl(struct file *filp, unsigned int cmd,
			unsigned long user_data)
L
Linus Torvalds 已提交
53
{
54
	struct path path;
55
	int error;
L
Linus Torvalds 已提交
56
	struct PioctlData data;
J
John Kacur 已提交
57
	struct inode *inode = filp->f_dentry->d_inode;
58 59
	struct inode *target_inode = NULL;
	struct coda_inode_info *cnp;
L
Linus Torvalds 已提交
60

61
	/* get the Pioctl data arguments from user space */
62 63
	if (copy_from_user(&data, (void __user *)user_data, sizeof(data)))
		return -EINVAL;
64 65 66 67 68

	/*
	 * Look up the pathname. Note that the pathname is in
	 * user memory, and namei takes care of this
	 */
J
John Kacur 已提交
69
	if (data.follow)
70
		error = user_path(data.path, &path);
J
John Kacur 已提交
71
	else
72
		error = user_lpath(data.path, &path);
J
John Kacur 已提交
73 74

	if (error)
75 76 77
		return error;

	target_inode = path.dentry->d_inode;
J
John Kacur 已提交
78

L
Linus Torvalds 已提交
79
	/* return if it is not a Coda inode */
80
	if (target_inode->i_sb != inode->i_sb) {
J
John Kacur 已提交
81 82
		error = -EINVAL;
		goto out;
L
Linus Torvalds 已提交
83 84 85
	}

	/* now proceed to make the upcall */
86
	cnp = ITOC(target_inode);
L
Linus Torvalds 已提交
87 88

	error = venus_pioctl(inode->i_sb, &(cnp->c_fid), cmd, &data);
J
John Kacur 已提交
89
out:
90
	path_put(&path);
91
	return error;
L
Linus Torvalds 已提交
92
}