ioctl.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. flags = jfs_inode->mode2 & JFS_FL_USER_VISIBLE;
  54. flags = jfs_map_ext2(flags, 0);
  55. return put_user(flags, (int __user *) arg);
  56. case JFS_IOC_SETFLAGS: {
  57. unsigned int oldflags;
  58. if (IS_RDONLY(inode))
  59. return -EROFS;
  60. if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
  61. return -EACCES;
  62. if (get_user(flags, (int __user *) arg))
  63. return -EFAULT;
  64. flags = jfs_map_ext2(flags, 1);
  65. if (!S_ISDIR(inode->i_mode))
  66. flags &= ~JFS_DIRSYNC_FL;
  67. oldflags = jfs_inode->mode2;
  68. /*
  69. * The IMMUTABLE and APPEND_ONLY flags can only be changed by
  70. * the relevant capability.
  71. */
  72. if ((oldflags & JFS_IMMUTABLE_FL) ||
  73. ((flags ^ oldflags) &
  74. (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
  75. if (!capable(CAP_LINUX_IMMUTABLE))
  76. return -EPERM;
  77. }
  78. flags = flags & JFS_FL_USER_MODIFIABLE;
  79. flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
  80. jfs_inode->mode2 = flags;
  81. jfs_set_inode_flags(inode);
  82. inode->i_ctime = CURRENT_TIME_SEC;
  83. mark_inode_dirty(inode);
  84. return 0;
  85. }
  86. default:
  87. return -ENOTTY;
  88. }
  89. }