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. .unlocked_ioctl = coda_pioctl,
  33. .llseek = noop_llseek,
  34. };
  35. /* the coda pioctl inode ops */
  36. static int coda_ioctl_permission(struct inode *inode, int mask)
  37. {
  38. return (mask & MAY_EXEC) ? -EACCES : 0;
  39. }
  40. static long coda_pioctl(struct file *filp, unsigned int cmd,
  41. unsigned long user_data)
  42. {
  43. struct path path;
  44. int error;
  45. struct PioctlData data;
  46. struct inode *inode = file_inode(filp);
  47. struct inode *target_inode = NULL;
  48. struct coda_inode_info *cnp;
  49. /* get the Pioctl data arguments from user space */
  50. if (copy_from_user(&data, (void __user *)user_data, sizeof(data)))
  51. return -EINVAL;
  52. /*
  53. * Look up the pathname. Note that the pathname is in
  54. * user memory, and namei takes care of this
  55. */
  56. if (data.follow)
  57. error = user_path(data.path, &path);
  58. else
  59. error = user_lpath(data.path, &path);
  60. if (error)
  61. return error;
  62. target_inode = d_inode(path.dentry);
  63. /* return if it is not a Coda inode */
  64. if (target_inode->i_sb != inode->i_sb) {
  65. error = -EINVAL;
  66. goto out;
  67. }
  68. /* now proceed to make the upcall */
  69. cnp = ITOC(target_inode);
  70. error = venus_pioctl(inode->i_sb, &(cnp->c_fid), cmd, &data);
  71. out:
  72. path_put(&path);
  73. return error;
  74. }