nfsctl.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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/nfsd/syscall.h>
  11. #include <linux/cred.h>
  12. #include <linux/sched.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. * open a file on nfsd fs
  20. */
  21. static struct file *do_open(char *name, int flags)
  22. {
  23. struct vfsmount *mnt;
  24. struct file *file;
  25. mnt = do_kern_mount("nfsd", 0, "nfsd", NULL);
  26. if (IS_ERR(mnt))
  27. return (struct file *)mnt;
  28. file = file_open_root(mnt->mnt_root, mnt, name, flags);
  29. mntput(mnt); /* drop do_kern_mount reference */
  30. return file;
  31. }
  32. static struct {
  33. char *name; int wsize; int rsize;
  34. } map[] = {
  35. [NFSCTL_SVC] = {
  36. .name = ".svc",
  37. .wsize = sizeof(struct nfsctl_svc)
  38. },
  39. [NFSCTL_ADDCLIENT] = {
  40. .name = ".add",
  41. .wsize = sizeof(struct nfsctl_client)
  42. },
  43. [NFSCTL_DELCLIENT] = {
  44. .name = ".del",
  45. .wsize = sizeof(struct nfsctl_client)
  46. },
  47. [NFSCTL_EXPORT] = {
  48. .name = ".export",
  49. .wsize = sizeof(struct nfsctl_export)
  50. },
  51. [NFSCTL_UNEXPORT] = {
  52. .name = ".unexport",
  53. .wsize = sizeof(struct nfsctl_export)
  54. },
  55. [NFSCTL_GETFD] = {
  56. .name = ".getfd",
  57. .wsize = sizeof(struct nfsctl_fdparm),
  58. .rsize = NFS_FHSIZE
  59. },
  60. [NFSCTL_GETFS] = {
  61. .name = ".getfs",
  62. .wsize = sizeof(struct nfsctl_fsparm),
  63. .rsize = sizeof(struct knfsd_fh)
  64. },
  65. };
  66. SYSCALL_DEFINE3(nfsservctl, int, cmd, struct nfsctl_arg __user *, arg,
  67. void __user *, res)
  68. {
  69. struct file *file;
  70. void __user *p = &arg->u;
  71. int version;
  72. int err;
  73. if (copy_from_user(&version, &arg->ca_version, sizeof(int)))
  74. return -EFAULT;
  75. if (version != NFSCTL_VERSION)
  76. return -EINVAL;
  77. if (cmd < 0 || cmd >= ARRAY_SIZE(map) || !map[cmd].name)
  78. return -EINVAL;
  79. file = do_open(map[cmd].name, map[cmd].rsize ? O_RDWR : O_WRONLY);
  80. if (IS_ERR(file))
  81. return PTR_ERR(file);
  82. err = file->f_op->write(file, p, map[cmd].wsize, &file->f_pos);
  83. if (err >= 0 && map[cmd].rsize)
  84. err = file->f_op->read(file, res, map[cmd].rsize, &file->f_pos);
  85. if (err >= 0)
  86. err = 0;
  87. fput(file);
  88. return err;
  89. }