ioctl.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * linux/fs/jfs/ioctl.c
  3. *
  4. * Copyright (C) 2006 Herbert Poetzl
  5. * adapted from Remy Card's ext2/ioctl.c
  6. */
  7. #include <linux/fs.h>
  8. #include <linux/ctype.h>
  9. #include <linux/capability.h>
  10. #include <linux/time.h>
  11. #include <linux/sched.h>
  12. #include <asm/current.h>
  13. #include <asm/uaccess.h>
  14. #include "jfs_incore.h"
  15. #include "jfs_dinode.h"
  16. #include "jfs_inode.h"
  17. static struct {
  18. long jfs_flag;
  19. long ext2_flag;
  20. } jfs_map[] = {
  21. {JFS_NOATIME_FL, FS_NOATIME_FL},
  22. {JFS_DIRSYNC_FL, FS_DIRSYNC_FL},
  23. {JFS_SYNC_FL, FS_SYNC_FL},
  24. {JFS_SECRM_FL, FS_SECRM_FL},
  25. {JFS_UNRM_FL, FS_UNRM_FL},
  26. {JFS_APPEND_FL, FS_APPEND_FL},
  27. {JFS_IMMUTABLE_FL, FS_IMMUTABLE_FL},
  28. {0, 0},
  29. };
  30. static long jfs_map_ext2(unsigned long flags, int from)
  31. {
  32. int index=0;
  33. long mapped=0;
  34. while (jfs_map[index].jfs_flag) {
  35. if (from) {
  36. if (jfs_map[index].ext2_flag & flags)
  37. mapped |= jfs_map[index].jfs_flag;
  38. } else {
  39. if (jfs_map[index].jfs_flag & flags)
  40. mapped |= jfs_map[index].ext2_flag;
  41. }
  42. index++;
  43. }
  44. return mapped;
  45. }
  46. int jfs_ioctl(struct inode * inode, struct file * filp, unsigned int cmd,
  47. unsigned long arg)
  48. {
  49. struct jfs_inode_info *jfs_inode = JFS_IP(inode);
  50. unsigned int flags;
  51. switch (cmd) {
  52. case JFS_IOC_GETFLAGS:
  53. jfs_get_inode_flags(jfs_inode);
  54. flags = jfs_inode->mode2 & JFS_FL_USER_VISIBLE;
  55. flags = jfs_map_ext2(flags, 0);
  56. return put_user(flags, (int __user *) arg);
  57. case JFS_IOC_SETFLAGS: {
  58. unsigned int oldflags;
  59. if (IS_RDONLY(inode))
  60. return -EROFS;
  61. if (!is_owner_or_cap(inode))
  62. return -EACCES;
  63. if (get_user(flags, (int __user *) arg))
  64. return -EFAULT;
  65. flags = jfs_map_ext2(flags, 1);
  66. if (!S_ISDIR(inode->i_mode))
  67. flags &= ~JFS_DIRSYNC_FL;
  68. /* Is it quota file? Do not allow user to mess with it */
  69. if (IS_NOQUOTA(inode))
  70. return -EPERM;
  71. jfs_get_inode_flags(jfs_inode);
  72. oldflags = jfs_inode->mode2;
  73. /*
  74. * The IMMUTABLE and APPEND_ONLY flags can only be changed by
  75. * the relevant capability.
  76. */
  77. if ((oldflags & JFS_IMMUTABLE_FL) ||
  78. ((flags ^ oldflags) &
  79. (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
  80. if (!capable(CAP_LINUX_IMMUTABLE))
  81. return -EPERM;
  82. }
  83. flags = flags & JFS_FL_USER_MODIFIABLE;
  84. flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
  85. jfs_inode->mode2 = flags;
  86. jfs_set_inode_flags(inode);
  87. inode->i_ctime = CURRENT_TIME_SEC;
  88. mark_inode_dirty(inode);
  89. return 0;
  90. }
  91. default:
  92. return -ENOTTY;
  93. }
  94. }