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 <asm/uaccess.h>
18 * open a file on nfsd fs
21 struct vfsmount
*do_kern_mount(const char *type
, int flags
, char *name
, void *data
);
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
;
37 error
= path_walk(name
, &nd
);
39 return ERR_PTR(error
);
42 error
= may_open(&nd
,MAY_READ
|MAY_WRITE
,FMODE_READ
|FMODE_WRITE
);
44 error
= may_open(&nd
, MAY_WRITE
, FMODE_WRITE
);
47 return dentry_open(nd
.dentry
, nd
.mnt
, flags
);
50 return ERR_PTR(error
);
54 char *name
; int wsize
; int rsize
;
56 [NFSCTL_SVC
]={"svc", sizeof(struct nfsctl_svc
)},
57 [NFSCTL_ADDCLIENT
]={"add", sizeof(struct nfsctl_client
)},
58 [NFSCTL_DELCLIENT
]={"del", sizeof(struct nfsctl_client
)},
59 [NFSCTL_EXPORT
]={"export", sizeof(struct nfsctl_export
)},
60 [NFSCTL_UNEXPORT
]={"unexport", sizeof(struct nfsctl_export
)},
62 [NFSCTL_UGIDUPDATE
]={"ugid", sizeof(struct nfsctl_uidmap
)},
64 [NFSCTL_GETFD
]={"getfd", sizeof(struct nfsctl_fdparm
), NFS_FHSIZE
},
65 [NFSCTL_GETFS
]={"getfs", sizeof(struct nfsctl_fsparm
), sizeof(struct knfsd_fh
)},
69 asmlinkage
sys_nfsservctl(int cmd
, struct nfsctl_arg
*arg
, void *res
)
76 if (copy_from_user(&version
, &arg
->ca_version
, sizeof(int)))
79 if (version
!= NFSCTL_VERSION
) {
80 printk(KERN_WARNING
"nfsd: incompatible version in syscall.\n");
84 if (cmd
< 0 || cmd
>= sizeof(map
)/sizeof(map
[0]) || !map
[cmd
].name
)
87 file
= do_open(map
[cmd
].name
, map
[cmd
].rsize
? O_RDWR
: O_WRONLY
);
90 err
= file
->f_op
->write(file
, p
, map
[cmd
].wsize
, &file
->f_pos
);
91 if (err
>= 0 && map
[cmd
].rsize
)
92 err
= file
->f_op
->read(file
, res
, map
[cmd
].rsize
, &file
->f_pos
);