ioctl.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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/time.h>
  11. #include <linux/sched.h>
  12. #include <asm/current.h>
  13. #include <asm/uaccess.h>
  14. int ext2_ioctl (struct inode * inode, struct file * filp, unsigned int cmd,
  15. unsigned long arg)
  16. {
  17. struct ext2_inode_info *ei = EXT2_I(inode);
  18. unsigned int flags;
  19. ext2_debug ("cmd = %u, arg = %lu\n", cmd, arg);
  20. switch (cmd) {
  21. case EXT2_IOC_GETFLAGS:
  22. flags = ei->i_flags & EXT2_FL_USER_VISIBLE;
  23. return put_user(flags, (int __user *) arg);
  24. case EXT2_IOC_SETFLAGS: {
  25. unsigned int oldflags;
  26. if (IS_RDONLY(inode))
  27. return -EROFS;
  28. if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
  29. return -EACCES;
  30. if (get_user(flags, (int __user *) arg))
  31. return -EFAULT;
  32. if (!S_ISDIR(inode->i_mode))
  33. flags &= ~EXT2_DIRSYNC_FL;
  34. oldflags = ei->i_flags;
  35. /*
  36. * The IMMUTABLE and APPEND_ONLY flags can only be changed by
  37. * the relevant capability.
  38. *
  39. * This test looks nicer. Thanks to Pauline Middelink
  40. */
  41. if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
  42. if (!capable(CAP_LINUX_IMMUTABLE))
  43. return -EPERM;
  44. }
  45. flags = flags & EXT2_FL_USER_MODIFIABLE;
  46. flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
  47. ei->i_flags = flags;
  48. ext2_set_inode_flags(inode);
  49. inode->i_ctime = CURRENT_TIME_SEC;
  50. mark_inode_dirty(inode);
  51. return 0;
  52. }
  53. case EXT2_IOC_GETVERSION:
  54. return put_user(inode->i_generation, (int __user *) arg);
  55. case EXT2_IOC_SETVERSION:
  56. if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
  57. return -EPERM;
  58. if (IS_RDONLY(inode))
  59. return -EROFS;
  60. if (get_user(inode->i_generation, (int __user *) arg))
  61. return -EFAULT;
  62. inode->i_ctime = CURRENT_TIME_SEC;
  63. mark_inode_dirty(inode);
  64. return 0;
  65. default:
  66. return -ENOTTY;
  67. }
  68. }