pioctl.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:3k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  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/sched.h>
  12. #include <linux/fs.h>
  13. #include <linux/stat.h>
  14. #include <linux/errno.h>
  15. #include <linux/locks.h>
  16. #include <asm/segment.h>
  17. #include <linux/string.h>
  18. #define __NO_VERSION__
  19. #include <linux/module.h>
  20. #include <asm/uaccess.h>
  21. #include <linux/coda.h>
  22. #include <linux/coda_linux.h>
  23. #include <linux/coda_fs_i.h>
  24. #include <linux/coda_psdev.h>
  25. /* pioctl ops */
  26. static int coda_ioctl_permission(struct inode *inode, int mask);
  27. static int coda_pioctl(struct inode * inode, struct file * filp, 
  28.                        unsigned int cmd, unsigned long user_data);
  29. /* exported from this file */
  30. struct inode_operations coda_ioctl_inode_operations =
  31. {
  32. permission: coda_ioctl_permission,
  33. setattr: coda_notify_change,
  34. };
  35. struct file_operations coda_ioctl_operations = {
  36. owner: THIS_MODULE,
  37. ioctl: coda_pioctl,
  38. };
  39. /* the coda pioctl inode ops */
  40. static int coda_ioctl_permission(struct inode *inode, int mask)
  41. {
  42.         return 0;
  43. }
  44. static int coda_pioctl(struct inode * inode, struct file * filp, 
  45.                        unsigned int cmd, unsigned long user_data)
  46. {
  47. struct nameidata nd;
  48.         int error;
  49. struct PioctlData data;
  50.         struct inode *target_inode = NULL;
  51.         struct coda_inode_info *cnp;
  52.         /* get the Pioctl data arguments from user space */
  53.         if (copy_from_user(&data, (int *)user_data, sizeof(data))) {
  54.     return -EINVAL;
  55. }
  56.        
  57.         /* 
  58.          * Look up the pathname. Note that the pathname is in 
  59.          * user memory, and namei takes care of this
  60.          */
  61. CDEBUG(D_PIOCTL, "namei, data.follow = %dn", 
  62.        data.follow);
  63.         if ( data.follow ) {
  64.                 error = user_path_walk(data.path, &nd);
  65. } else {
  66.         error = user_path_walk_link(data.path, &nd);
  67. }
  68. if ( error ) {
  69.                 CDEBUG(D_PIOCTL, "error: lookup fails.n");
  70. return error;
  71.         } else {
  72.         target_inode = nd.dentry->d_inode;
  73. }
  74. CDEBUG(D_PIOCTL, "target ino: 0x%ld, dev: 0x%xn",
  75.        target_inode->i_ino, target_inode->i_dev);
  76. /* return if it is not a Coda inode */
  77. if ( target_inode->i_sb != inode->i_sb ) {
  78. path_release(&nd);
  79.         return  -EINVAL;
  80. }
  81. /* now proceed to make the upcall */
  82.         cnp = ITOC(target_inode);
  83. error = venus_pioctl(inode->i_sb, &(cnp->c_fid), cmd, &data);
  84.         CDEBUG(D_PIOCTL, "ioctl on inode %ldn", target_inode->i_ino);
  85. CDEBUG(D_DOWNCALL, "dput on ino: %ld, icount %d, dcount %dn", target_inode->i_ino, 
  86.        atomic_read(&target_inode->i_count), atomic_read(&nd.dentry->d_count));
  87. path_release(&nd);
  88.         return error;
  89. }