ioctl.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * linux/fs/ext2/ioctl.c
  3. *
  4. * Copyright (C) 1993, 1994, 1995
  5. * Remy Card (card@masi.ibp.fr)
  6. * Laboratoire MASI - Institut Blaise Pascal
  7. * Universite Pierre et Marie Curie (Paris VI)
  8. */
  9. #include "ext2.h"
  10. #include <linux/capability.h>
  11. #include <linux/time.h>
  12. #include <linux/sched.h>
  13. #include <asm/current.h>
  14. #include <asm/uaccess.h>
  15. int ext2_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
  16. unsigned long arg)
  17. {
  18. struct ext2_inode_info *ei = EXT2_I(inode);
  19. unsigned int flags;
  20. ext2_debug ("cmd = %u, arg = %lu\n", cmd, arg);
  21. switch (cmd) {
  22. case EXT2_IOC_GETFLAGS:
  23. flags = ei->i_flags & EXT2_FL_USER_VISIBLE;
  24. return put_user(flags, (int __user *) arg);
  25. case EXT2_IOC_SETFLAGS: {
  26. unsigned int oldflags;
  27. if (IS_RDONLY(inode))
  28. return -EROFS;
  29. if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
  30. return -EACCES;
  31. if (get_user(flags, (int __user *) arg))
  32. return -EFAULT;
  33. if (!S_ISDIR(inode->i_mode))
  34. flags &= ~EXT2_DIRSYNC_FL;
  35. oldflags = ei->i_flags;
  36. /*
  37. * The IMMUTABLE and APPEND_ONLY flags can only be changed by
  38. * the relevant capability.
  39. *
  40. * This test looks nicer. Thanks to Pauline Middelink
  41. */
  42. if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
  43. if (!capable(CAP_LINUX_IMMUTABLE))
  44. return -EPERM;
  45. }
  46. flags = flags & EXT2_FL_USER_MODIFIABLE;
  47. flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
  48. ei->i_flags = flags;
  49. ext2_set_inode_flags(inode);
  50. inode->i_ctime = CURRENT_TIME_SEC;
  51. mark_inode_dirty(inode);
  52. return 0;
  53. }
  54. case EXT2_IOC_GETVERSION:
  55. return put_user(inode->i_generation, (int __user *) arg);
  56. case EXT2_IOC_SETVERSION:
  57. if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
  58. return -EPERM;
  59. if (IS_RDONLY(inode))
  60. return -EROFS;
  61. if (get_user(inode->i_generation, (int __user *) arg))
  62. return -EFAULT;
  63. inode->i_ctime = CURRENT_TIME_SEC;
  64. mark_inode_dirty(inode);
  65. return 0;
  66. default:
  67. return -ENOTTY;
  68. }
  69. }