~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/nfsctl.c

Version: ~ [ linux-6.6-rc1 ] ~ [ linux-6.5.2 ] ~ [ linux-6.4.15 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.52 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.131 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.194 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.256 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.294 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.325 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *      fs/nfsctl.c
  3  *
  4  *      This should eventually move to userland.
  5  *
  6  */
  7 #include <linux/types.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/cred.h>
 14 #include <linux/sched.h>
 15 #include <linux/linkage.h>
 16 #include <linux/namei.h>
 17 #include <linux/mount.h>
 18 #include <linux/syscalls.h>
 19 #include <asm/uaccess.h>
 20 
 21 /*
 22  * open a file on nfsd fs
 23  */
 24 
 25 static struct file *do_open(char *name, int flags)
 26 {
 27         struct nameidata nd;
 28         struct vfsmount *mnt;
 29         int error;
 30 
 31         mnt = do_kern_mount("nfsd", 0, "nfsd", NULL);
 32         if (IS_ERR(mnt))
 33                 return (struct file *)mnt;
 34 
 35         error = vfs_path_lookup(mnt->mnt_root, mnt, name, 0, &nd);
 36         mntput(mnt);    /* drop do_kern_mount reference */
 37         if (error)
 38                 return ERR_PTR(error);
 39 
 40         if (flags == O_RDWR)
 41                 error = may_open(&nd.path, MAY_READ|MAY_WRITE,
 42                                            FMODE_READ|FMODE_WRITE);
 43         else
 44                 error = may_open(&nd.path, MAY_WRITE, FMODE_WRITE);
 45 
 46         if (!error)
 47                 return dentry_open(nd.path.dentry, nd.path.mnt, flags,
 48                                    current_cred());
 49 
 50         path_put(&nd.path);
 51         return ERR_PTR(error);
 52 }
 53 
 54 static 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 
 89 SYSCALL_DEFINE3(nfsservctl, int, cmd, struct nfsctl_arg __user *, arg,
 90                 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                 return -EINVAL;
102 
103         if (cmd < 0 || cmd >= ARRAY_SIZE(map) || !map[cmd].name)
104                 return -EINVAL;
105 
106         file = do_open(map[cmd].name, map[cmd].rsize ? O_RDWR : O_WRONLY);      
107         if (IS_ERR(file))
108                 return PTR_ERR(file);
109         err = file->f_op->write(file, p, map[cmd].wsize, &file->f_pos);
110         if (err >= 0 && map[cmd].rsize)
111                 err = file->f_op->read(file, res, map[cmd].rsize, &file->f_pos);
112         if (err >= 0)
113                 err = 0;
114         fput(file);
115         return err;
116 }
117 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp