pioctl.c 2.3 KB

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