4 * This should eventually move to userland.
7 #include <linux/config.h>
8 #include <linux/types.h>
9 #include <linux/file.h>
11 #include <linux/sunrpc/svc.h>
12 #include <linux/nfsd/nfsd.h>
13 #include <linux/nfsd/syscall.h>
14 #include <linux/linkage.h>
15 #include <linux/namei.h>
16 #include <linux/mount.h>
17 #include <linux/syscalls.h>
18 #include <asm/uaccess.h>
21 * open a file on nfsd fs
24 static struct file *do_open(char *name, int flags)
29 nd.mnt = do_kern_mount("nfsd", 0, "nfsd", NULL);
32 return (struct file *)nd.mnt;
34 nd.dentry = dget(nd.mnt->mnt_root);
35 nd.last_type = LAST_ROOT;
39 error = path_walk(name, &nd);
41 return ERR_PTR(error);
44 error = may_open(&nd,MAY_READ|MAY_WRITE,FMODE_READ|FMODE_WRITE);
46 error = may_open(&nd, MAY_WRITE, FMODE_WRITE);
49 return dentry_open(nd.dentry, nd.mnt, flags);
52 return ERR_PTR(error);
56 char *name; int wsize; int rsize;
60 .wsize = sizeof(struct nfsctl_svc)
62 [NFSCTL_ADDCLIENT] = {
64 .wsize = sizeof(struct nfsctl_client)
66 [NFSCTL_DELCLIENT] = {
68 .wsize = sizeof(struct nfsctl_client)
72 .wsize = sizeof(struct nfsctl_export)
76 .wsize = sizeof(struct nfsctl_export)
80 .wsize = sizeof(struct nfsctl_fdparm),
85 .wsize = sizeof(struct nfsctl_fsparm),
86 .rsize = sizeof(struct knfsd_fh)
91 asmlinkage sys_nfsservctl(int cmd, struct nfsctl_arg __user *arg, void __user *res)
94 void __user *p = &arg->u;
98 if (copy_from_user(&version, &arg->ca_version, sizeof(int)))
101 if (version != NFSCTL_VERSION)
104 if (cmd < 0 || cmd >= ARRAY_SIZE(map) || !map[cmd].name)
107 file = do_open(map[cmd].name, map[cmd].rsize ? O_RDWR : O_WRONLY);
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);