aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfsctl.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /fs/nfsctl.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'fs/nfsctl.c')
-rw-r--r--fs/nfsctl.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/fs/nfsctl.c b/fs/nfsctl.c
new file mode 100644
index 000000000000..0b14938b5b62
--- /dev/null
+++ b/fs/nfsctl.c
@@ -0,0 +1,118 @@
1/*
2 * fs/nfsctl.c
3 *
4 * This should eventually move to userland.
5 *
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 <linux/syscalls.h>
17#include <asm/uaccess.h>
18
19/*
20 * open a file on nfsd fs
21 */
22
23static struct file *do_open(char *name, int flags)
24{
25 struct nameidata nd;
26 int error;
27
28 nd.mnt = do_kern_mount("nfsd", 0, "nfsd", NULL);
29
30 if (IS_ERR(nd.mnt))
31 return (struct file *)nd.mnt;
32
33 nd.dentry = dget(nd.mnt->mnt_root);
34 nd.last_type = LAST_ROOT;
35 nd.flags = 0;
36 nd.depth = 0;
37
38 error = path_walk(name, &nd);
39 if (error)
40 return ERR_PTR(error);
41
42 if (flags == O_RDWR)
43 error = may_open(&nd,MAY_READ|MAY_WRITE,FMODE_READ|FMODE_WRITE);
44 else
45 error = may_open(&nd, MAY_WRITE, FMODE_WRITE);
46
47 if (!error)
48 return dentry_open(nd.dentry, nd.mnt, flags);
49
50 path_release(&nd);
51 return ERR_PTR(error);
52}
53
54static struct {
55 char *name; int wsize; int rsize;
56} map[] = {
57 [NFSCTL_SVC] = {
58 .name = ".svc",
59 .wsize = sizeof(struct nfsctl_svc)
60 },
61 [NFSCTL_ADDCLIENT] = {
62 .name = ".add",
63 .wsize = sizeof(struct nfsctl_client)
64 },
65 [NFSCTL_DELCLIENT] = {
66 .name = ".del",
67 .wsize = sizeof(struct nfsctl_client)
68 },
69 [NFSCTL_EXPORT] = {
70 .name = ".export",
71 .wsize = sizeof(struct nfsctl_export)
72 },
73 [NFSCTL_UNEXPORT] = {
74 .name = ".unexport",
75 .wsize = sizeof(struct nfsctl_export)
76 },
77 [NFSCTL_GETFD] = {
78 .name = ".getfd",
79 .wsize = sizeof(struct nfsctl_fdparm),
80 .rsize = NFS_FHSIZE
81 },
82 [NFSCTL_GETFS] = {
83 .name = ".getfs",
84 .wsize = sizeof(struct nfsctl_fsparm),
85 .rsize = sizeof(struct knfsd_fh)
86 },
87};
88
89long
90asmlinkage sys_nfsservctl(int cmd, struct nfsctl_arg __user *arg, void __user *res)
91{
92 struct file *file;
93 void __user *p = &arg->u;
94 int version;
95 int err;
96
97 if (copy_from_user(&version, &arg->ca_version, sizeof(int)))
98 return -EFAULT;
99
100 if (version != NFSCTL_VERSION) {
101 printk(KERN_WARNING "nfsd: incompatible version in syscall.\n");
102 return -EINVAL;
103 }
104
105 if (cmd < 0 || cmd >= sizeof(map)/sizeof(map[0]) || !map[cmd].name)
106 return -EINVAL;
107
108 file = do_open(map[cmd].name, map[cmd].rsize ? O_RDWR : O_WRONLY);
109 if (IS_ERR(file))
110 return PTR_ERR(file);
111 err = file->f_op->write(file, p, map[cmd].wsize, &file->f_pos);
112 if (err >= 0 && map[cmd].rsize)
113 err = file->f_op->read(file, res, map[cmd].rsize, &file->f_pos);
114 if (err >= 0)
115 err = 0;
116 fput(file);
117 return err;
118}