MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / fs / nfsctl.c
blobaaf9f5640eb33e98db6570e4b53f58dfb0153402
1 /*
2 * fs/nfsctl.c
4 * This should eventually move to userland.
6 */
7 #include <linux/config.h>
8 #include <linux/file.h>
9 #include <linux/fs.h>
10 #include <linux/sunrpc/svc.h>
11 #include <linux/nfsd/nfsd.h>
12 #include <linux/nfsd/syscall.h>
13 #include <linux/linkage.h>
14 #include <linux/namei.h>
15 #include <linux/mount.h>
16 #include <asm/uaccess.h>
19 * open a file on nfsd fs
22 static struct file *do_open(char *name, int flags)
24 struct nameidata nd;
25 int error;
27 nd.mnt = do_kern_mount("nfsd", 0, "nfsd", NULL);
29 if (IS_ERR(nd.mnt))
30 return (struct file *)nd.mnt;
32 nd.dentry = dget(nd.mnt->mnt_root);
33 nd.last_type = LAST_ROOT;
34 nd.flags = 0;
35 nd.depth = 0;
37 error = path_walk(name, &nd);
38 if (error)
39 return ERR_PTR(error);
41 if (flags == O_RDWR)
42 error = may_open(&nd,MAY_READ|MAY_WRITE,FMODE_READ|FMODE_WRITE);
43 else
44 error = may_open(&nd, MAY_WRITE, FMODE_WRITE);
46 if (!error)
47 return dentry_open(nd.dentry, nd.mnt, flags);
49 path_release(&nd);
50 return ERR_PTR(error);
53 static struct {
54 char *name; int wsize; int rsize;
55 } map[] = {
56 [NFSCTL_SVC] = {
57 .name = ".svc",
58 .wsize = sizeof(struct nfsctl_svc)
60 [NFSCTL_ADDCLIENT] = {
61 .name = ".add",
62 .wsize = sizeof(struct nfsctl_client)
64 [NFSCTL_DELCLIENT] = {
65 .name = ".del",
66 .wsize = sizeof(struct nfsctl_client)
68 [NFSCTL_EXPORT] = {
69 .name = ".export",
70 .wsize = sizeof(struct nfsctl_export)
72 [NFSCTL_UNEXPORT] = {
73 .name = ".unexport",
74 .wsize = sizeof(struct nfsctl_export)
76 [NFSCTL_GETFD] = {
77 .name = ".getfd",
78 .wsize = sizeof(struct nfsctl_fdparm),
79 .rsize = NFS_FHSIZE
81 [NFSCTL_GETFS] = {
82 .name = ".getfs",
83 .wsize = sizeof(struct nfsctl_fsparm),
84 .rsize = sizeof(struct knfsd_fh)
88 long
89 asmlinkage sys_nfsservctl(int cmd, struct nfsctl_arg __user *arg, void __user *res)
91 struct file *file;
92 void __user *p = &arg->u;
93 int version;
94 int err;
96 if (copy_from_user(&version, &arg->ca_version, sizeof(int)))
97 return -EFAULT;
99 if (version != NFSCTL_VERSION) {
100 printk(KERN_WARNING "nfsd: incompatible version in syscall.\n");
101 return -EINVAL;
104 if (cmd < 0 || cmd >= sizeof(map)/sizeof(map[0]) || !map[cmd].name)
105 return -EINVAL;
107 file = do_open(map[cmd].name, map[cmd].rsize ? O_RDWR : O_WRONLY);
108 if (IS_ERR(file))
109 return PTR_ERR(file);
110 err = file->f_op->write(file, p, map[cmd].wsize, &file->f_pos);
111 if (err >= 0 && map[cmd].rsize)
112 err = file->f_op->read(file, res, map[cmd].rsize, &file->f_pos);
113 if (err >= 0)
114 err = 0;
115 fput(file);
116 return err;