pioctl.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. .llseek = noop_llseek,
  37. };
  38. /* the coda pioctl inode ops */
  39. static int coda_ioctl_permission(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 = filp->f_dentry->d_inode;
  50. struct inode *target_inode = NULL;
  51. struct coda_inode_info *cnp;
  52. lock_kernel();
  53. /* get the Pioctl data arguments from user space */
  54. if (copy_from_user(&data, (void __user *)user_data, sizeof(data))) {
  55. error = -EINVAL;
  56. goto out;
  57. }
  58. /*
  59. * Look up the pathname. Note that the pathname is in
  60. * user memory, and namei takes care of this
  61. */
  62. if (data.follow)
  63. error = user_path(data.path, &path);
  64. else
  65. error = user_lpath(data.path, &path);
  66. if (error)
  67. goto out;
  68. else
  69. target_inode = path.dentry->d_inode;
  70. /* return if it is not a Coda inode */
  71. if (target_inode->i_sb != inode->i_sb) {
  72. path_put(&path);
  73. error = -EINVAL;
  74. goto out;
  75. }
  76. /* now proceed to make the upcall */
  77. cnp = ITOC(target_inode);
  78. error = venus_pioctl(inode->i_sb, &(cnp->c_fid), cmd, &data);
  79. path_put(&path);
  80. out:
  81. unlock_kernel();
  82. return error;
  83. }