pioctl.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 <linux/uaccess.h>
  19. #include <linux/coda.h>
  20. #include <linux/coda_psdev.h>
  21. #include "coda_linux.h"
  22. /* pioctl ops */
  23. static int coda_ioctl_permission(struct inode *inode, int mask);
  24. static long coda_pioctl(struct file *filp, unsigned int cmd,
  25. unsigned long user_data);
  26. /* exported from this file */
  27. const struct inode_operations coda_ioctl_inode_operations = {
  28. .permission = coda_ioctl_permission,
  29. .setattr = coda_setattr,
  30. };
  31. const struct file_operations coda_ioctl_operations = {
  32. .owner = THIS_MODULE,
  33. .unlocked_ioctl = coda_pioctl,
  34. .llseek = noop_llseek,
  35. };
  36. /* the coda pioctl inode ops */
  37. static int coda_ioctl_permission(struct inode *inode, int mask)
  38. {
  39. return (mask & MAY_EXEC) ? -EACCES : 0;
  40. }
  41. static long coda_pioctl(struct file *filp, unsigned int cmd,
  42. unsigned long user_data)
  43. {
  44. struct path path;
  45. int error;
  46. struct PioctlData data;
  47. struct inode *inode = file_inode(filp);
  48. struct inode *target_inode = NULL;
  49. struct coda_inode_info *cnp;
  50. /* get the Pioctl data arguments from user space */
  51. if (copy_from_user(&data, (void __user *)user_data, sizeof(data)))
  52. return -EINVAL;
  53. /*
  54. * Look up the pathname. Note that the pathname is in
  55. * user memory, and namei takes care of this
  56. */
  57. if (data.follow)
  58. error = user_path(data.path, &path);
  59. else
  60. error = user_lpath(data.path, &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. }