more changes on original files
[linux-2.4.git] / fs / coda / pioctl.c
1 /*
2  * Pioctl operations for Coda.
3  * Original version: (C) 1996 Peter Braam 
4  * 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/sched.h>
13 #include <linux/fs.h>
14 #include <linux/stat.h>
15 #include <linux/errno.h>
16 #include <linux/locks.h>
17 #include <linux/string.h>
18 #define __NO_VERSION__
19 #include <linux/module.h>
20 #include <asm/uaccess.h>
21
22 #include <linux/coda.h>
23 #include <linux/coda_linux.h>
24 #include <linux/coda_fs_i.h>
25 #include <linux/coda_psdev.h>
26
27 /* pioctl ops */
28 static int coda_ioctl_permission(struct inode *inode, int mask);
29 static int coda_pioctl(struct inode * inode, struct file * filp, 
30                        unsigned int cmd, unsigned long user_data);
31
32 /* exported from this file */
33 struct inode_operations coda_ioctl_inode_operations =
34 {
35         permission:     coda_ioctl_permission,
36         setattr:        coda_notify_change,
37 };
38
39 struct file_operations coda_ioctl_operations = {
40         owner:          THIS_MODULE,
41         ioctl:          coda_pioctl,
42 };
43
44 /* the coda pioctl inode ops */
45 static int coda_ioctl_permission(struct inode *inode, int mask)
46 {
47         return 0;
48 }
49
50 static int coda_pioctl(struct inode * inode, struct file * filp, 
51                        unsigned int cmd, unsigned long user_data)
52 {
53         struct nameidata nd;
54         int error;
55         struct PioctlData data;
56         struct inode *target_inode = NULL;
57         struct coda_inode_info *cnp;
58
59         /* get the Pioctl data arguments from user space */
60         if (copy_from_user(&data, (int *)user_data, sizeof(data))) {
61             return -EINVAL;
62         }
63        
64         /* 
65          * Look up the pathname. Note that the pathname is in 
66          * user memory, and namei takes care of this
67          */
68         CDEBUG(D_PIOCTL, "namei, data.follow = %d\n", 
69                data.follow);
70         if ( data.follow ) {
71                 error = user_path_walk(data.path, &nd);
72         } else {
73                 error = user_path_walk_link(data.path, &nd);
74         }
75                 
76         if ( error ) {
77                 CDEBUG(D_PIOCTL, "error: lookup fails.\n");
78                 return error;
79         } else {
80                 target_inode = nd.dentry->d_inode;
81         }
82         
83         CDEBUG(D_PIOCTL, "target ino: 0x%ld, dev: 0x%x\n",
84                target_inode->i_ino, target_inode->i_dev);
85
86         /* return if it is not a Coda inode */
87         if ( target_inode->i_sb != inode->i_sb ) {
88                 path_release(&nd);
89                 return  -EINVAL;
90         }
91
92         /* now proceed to make the upcall */
93         cnp = ITOC(target_inode);
94
95         error = venus_pioctl(inode->i_sb, &(cnp->c_fid), cmd, &data);
96
97         CDEBUG(D_PIOCTL, "ioctl on inode %ld\n", target_inode->i_ino);
98         CDEBUG(D_DOWNCALL, "dput on ino: %ld, icount %d, dcount %d\n", target_inode->i_ino, 
99                atomic_read(&target_inode->i_count), atomic_read(&nd.dentry->d_count));
100         path_release(&nd);
101         return error;
102 }
103