pioctl.c 2.3 KB

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