4 * This should eventually move to userland.
7 #include <linux/config.h>
8 #include <linux/file.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>
20 * open a file on nfsd fs
23 static struct file
*do_open(char *name
, int flags
)
28 nd
.mnt
= do_kern_mount("nfsd", 0, "nfsd", NULL
);
31 return (struct file
*)nd
.mnt
;
33 nd
.dentry
= dget(nd
.mnt
->mnt_root
);
34 nd
.last_type
= LAST_ROOT
;
38 error
= path_walk(name
, &nd
);
40 return ERR_PTR(error
);
43 error
= may_open(&nd
,MAY_READ
|MAY_WRITE
,FMODE_READ
|FMODE_WRITE
);
45 error
= may_open(&nd
, MAY_WRITE
, FMODE_WRITE
);
48 return dentry_open(nd
.dentry
, nd
.mnt
, flags
);
51 return ERR_PTR(error
);
55 char *name
; int wsize
; int rsize
;
59 .wsize
= sizeof(struct nfsctl_svc
)
61 [NFSCTL_ADDCLIENT
] = {
63 .wsize
= sizeof(struct nfsctl_client
)
65 [NFSCTL_DELCLIENT
] = {
67 .wsize
= sizeof(struct nfsctl_client
)
71 .wsize
= sizeof(struct nfsctl_export
)
75 .wsize
= sizeof(struct nfsctl_export
)
79 .wsize
= sizeof(struct nfsctl_fdparm
),
84 .wsize
= sizeof(struct nfsctl_fsparm
),
85 .rsize
= sizeof(struct knfsd_fh
)
90 asmlinkage
sys_nfsservctl(int cmd
, struct nfsctl_arg __user
*arg
, void __user
*res
)
93 void __user
*p
= &arg
->u
;
97 if (copy_from_user(&version
, &arg
->ca_version
, sizeof(int)))
100 if (version
!= NFSCTL_VERSION
) {
101 printk(KERN_WARNING
"nfsd: incompatible version in syscall.\n");
105 if (cmd
< 0 || cmd
>= sizeof(map
)/sizeof(map
[0]) || !map
[cmd
].name
)
108 file
= do_open(map
[cmd
].name
, map
[cmd
].rsize
? O_RDWR
: O_WRONLY
);
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
);