pioctl.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Pioctl operations for Coda.
  4. * Original version: (C) 1996 Peter Braam
  5. * Rewritten for Linux 2.1: (C) 1997 Carnegie Mellon University
  6. *
  7. * Carnegie Mellon encourages users of this code to contribute improvements
  8. * to the Coda project. Contact Peter Braam <[email protected]>.
  9. */
  10. #include <linux/types.h>
  11. #include <linux/kernel.h>
  12. #include <linux/time.h>
  13. #include <linux/fs.h>
  14. #include <linux/stat.h>
  15. #include <linux/errno.h>
  16. #include <linux/string.h>
  17. #include <linux/namei.h>
  18. #include <linux/module.h>
  19. #include <linux/uaccess.h>
  20. #include <linux/coda.h>
  21. #include "coda_psdev.h"
  22. #include "coda_linux.h"
  23. /* pioctl ops */
  24. static int coda_ioctl_permission(struct user_namespace *mnt_userns,
  25. struct inode *inode, int mask);
  26. static long coda_pioctl(struct file *filp, unsigned int cmd,
  27. unsigned long user_data);
  28. /* exported from this file */
  29. const struct inode_operations coda_ioctl_inode_operations = {
  30. .permission = coda_ioctl_permission,
  31. .setattr = coda_setattr,
  32. };
  33. const struct file_operations coda_ioctl_operations = {
  34. .unlocked_ioctl = coda_pioctl,
  35. .llseek = noop_llseek,
  36. };
  37. /* the coda pioctl inode ops */
  38. static int coda_ioctl_permission(struct user_namespace *mnt_userns,
  39. struct inode *inode, int mask)
  40. {
  41. return (mask & MAY_EXEC) ? -EACCES : 0;
  42. }
  43. static long coda_pioctl(struct file *filp, unsigned int cmd,
  44. unsigned long user_data)
  45. {
  46. struct path path;
  47. int error;
  48. struct PioctlData data;
  49. struct inode *inode = file_inode(filp);
  50. struct inode *target_inode = NULL;
  51. struct coda_inode_info *cnp;
  52. /* get the Pioctl data arguments from user space */
  53. if (copy_from_user(&data, (void __user *)user_data, sizeof(data)))
  54. return -EINVAL;
  55. /*
  56. * Look up the pathname. Note that the pathname is in
  57. * user memory, and namei takes care of this
  58. */
  59. error = user_path_at(AT_FDCWD, data.path,
  60. data.follow ? LOOKUP_FOLLOW : 0, &path);
  61. if (error)
  62. return error;
  63. target_inode = d_inode(path.dentry);
  64. /* return if it is not a Coda inode */
  65. if (target_inode->i_sb != inode->i_sb) {
  66. error = -EINVAL;
  67. goto out;
  68. }
  69. /* now proceed to make the upcall */
  70. cnp = ITOC(target_inode);
  71. error = venus_pioctl(inode->i_sb, &(cnp->c_fid), cmd, &data);
  72. out:
  73. path_put(&path);
  74. return error;
  75. }