Blame view

fs/coda/pioctl.c 2.23 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
  /*
   * Pioctl operations for Coda.
1977bb2ed   John Kacur   coda: Clean-up wh...
3
   * Original version: (C) 1996 Peter Braam
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
   * 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>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
22
  #include <linux/coda_psdev.h>
31a203df9   Al Viro   take coda-private...
23
  #include "coda_linux.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24
  /* pioctl ops */
b74c79e99   Nick Piggin   fs: provide rcu-w...
25
  static int coda_ioctl_permission(struct inode *inode, int mask, unsigned int flags);
2ff82f852   John Kacur   coda: BKL ioctl p...
26
27
  static long coda_pioctl(struct file *filp, unsigned int cmd,
  			unsigned long user_data);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
28
29
  
  /* exported from this file */
1977bb2ed   John Kacur   coda: Clean-up wh...
30
  const struct inode_operations coda_ioctl_inode_operations = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
31
32
33
  	.permission	= coda_ioctl_permission,
  	.setattr	= coda_setattr,
  };
4b6f5d20b   Arjan van de Ven   [PATCH] Make most...
34
  const struct file_operations coda_ioctl_operations = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35
  	.owner		= THIS_MODULE,
2ff82f852   John Kacur   coda: BKL ioctl p...
36
  	.unlocked_ioctl	= coda_pioctl,
6038f373a   Arnd Bergmann   llseek: automatic...
37
  	.llseek		= noop_llseek,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
38
39
40
  };
  
  /* the coda pioctl inode ops */
b74c79e99   Nick Piggin   fs: provide rcu-w...
41
  static int coda_ioctl_permission(struct inode *inode, int mask, unsigned int flags)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
  {
b74c79e99   Nick Piggin   fs: provide rcu-w...
43
44
  	if (flags & IPERM_FLAG_RCU)
  		return -ECHILD;
f696a3659   Miklos Szeredi   [PATCH] move exec...
45
  	return (mask & MAY_EXEC) ? -EACCES : 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
46
  }
2ff82f852   John Kacur   coda: BKL ioctl p...
47
48
  static long coda_pioctl(struct file *filp, unsigned int cmd,
  			unsigned long user_data)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
49
  {
2d8f30380   Al Viro   [PATCH] sanitize ...
50
  	struct path path;
1977bb2ed   John Kacur   coda: Clean-up wh...
51
  	int error;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
52
  	struct PioctlData data;
2ff82f852   John Kacur   coda: BKL ioctl p...
53
  	struct inode *inode = filp->f_dentry->d_inode;
1977bb2ed   John Kacur   coda: Clean-up wh...
54
55
  	struct inode *target_inode = NULL;
  	struct coda_inode_info *cnp;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
56

1977bb2ed   John Kacur   coda: Clean-up wh...
57
  	/* get the Pioctl data arguments from user space */
f7cc02b87   Yoshihisa Abe   Coda: push BKL re...
58
59
  	if (copy_from_user(&data, (void __user *)user_data, sizeof(data)))
  		return -EINVAL;
1977bb2ed   John Kacur   coda: Clean-up wh...
60
61
62
63
64
  
  	/*
  	 * Look up the pathname. Note that the pathname is in
  	 * user memory, and namei takes care of this
  	 */
2ff82f852   John Kacur   coda: BKL ioctl p...
65
  	if (data.follow)
1977bb2ed   John Kacur   coda: Clean-up wh...
66
  		error = user_path(data.path, &path);
2ff82f852   John Kacur   coda: BKL ioctl p...
67
  	else
1977bb2ed   John Kacur   coda: Clean-up wh...
68
  		error = user_lpath(data.path, &path);
2ff82f852   John Kacur   coda: BKL ioctl p...
69
70
  
  	if (error)
f7cc02b87   Yoshihisa Abe   Coda: push BKL re...
71
72
73
  		return error;
  
  	target_inode = path.dentry->d_inode;
2ff82f852   John Kacur   coda: BKL ioctl p...
74

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
75
  	/* return if it is not a Coda inode */
1977bb2ed   John Kacur   coda: Clean-up wh...
76
  	if (target_inode->i_sb != inode->i_sb) {
2ff82f852   John Kacur   coda: BKL ioctl p...
77
78
  		error = -EINVAL;
  		goto out;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
79
80
81
  	}
  
  	/* now proceed to make the upcall */
1977bb2ed   John Kacur   coda: Clean-up wh...
82
  	cnp = ITOC(target_inode);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
83
84
  
  	error = venus_pioctl(inode->i_sb, &(cnp->c_fid), cmd, &data);
2ff82f852   John Kacur   coda: BKL ioctl p...
85
  out:
f7cc02b87   Yoshihisa Abe   Coda: push BKL re...
86
  	path_put(&path);
1977bb2ed   John Kacur   coda: Clean-up wh...
87
  	return error;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
88
  }