pioctl.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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);
  25. static int coda_pioctl(struct inode * inode, struct file * filp,
  26. unsigned int cmd, unsigned long user_data);
  27. /* exported from this file */
  28. const struct inode_operations coda_ioctl_inode_operations =
  29. {
  30. .permission = coda_ioctl_permission,
  31. .setattr = coda_setattr,
  32. };
  33. const struct file_operations coda_ioctl_operations = {
  34. .owner = THIS_MODULE,
  35. .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 int coda_pioctl(struct inode * inode, struct file * filp,
  43. unsigned int cmd, unsigned long user_data)
  44. {
  45. struct path path;
  46. int error;
  47. struct PioctlData data;
  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. /*
  55. * Look up the pathname. Note that the pathname is in
  56. * user memory, and namei takes care of this
  57. */
  58. if (data.follow) {
  59. error = user_path(data.path, &path);
  60. } else {
  61. error = user_lpath(data.path, &path);
  62. }
  63. if ( error ) {
  64. return error;
  65. } else {
  66. target_inode = path.dentry->d_inode;
  67. }
  68. /* return if it is not a Coda inode */
  69. if ( target_inode->i_sb != inode->i_sb ) {
  70. path_put(&path);
  71. return -EINVAL;
  72. }
  73. /* now proceed to make the upcall */
  74. cnp = ITOC(target_inode);
  75. error = venus_pioctl(inode->i_sb, &(cnp->c_fid), cmd, &data);
  76. path_put(&path);
  77. return error;
  78. }