ioctl.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 <asm/current.h>
  12. #include <asm/uaccess.h>
  13. #include "jfs_incore.h"
  14. #include "jfs_dinode.h"
  15. #include "jfs_inode.h"
  16. static struct {
  17. long jfs_flag;
  18. long ext2_flag;
  19. } jfs_map[] = {
  20. {JFS_NOATIME_FL, FS_NOATIME_FL},
  21. {JFS_DIRSYNC_FL, FS_DIRSYNC_FL},
  22. {JFS_SYNC_FL, FS_SYNC_FL},
  23. {JFS_SECRM_FL, FS_SECRM_FL},
  24. {JFS_UNRM_FL, FS_UNRM_FL},
  25. {JFS_APPEND_FL, FS_APPEND_FL},
  26. {JFS_IMMUTABLE_FL, FS_IMMUTABLE_FL},
  27. {0, 0},
  28. };
  29. static long jfs_map_ext2(unsigned long flags, int from)
  30. {
  31. int index=0;
  32. long mapped=0;
  33. while (jfs_map[index].jfs_flag) {
  34. if (from) {
  35. if (jfs_map[index].ext2_flag & flags)
  36. mapped |= jfs_map[index].jfs_flag;
  37. } else {
  38. if (jfs_map[index].jfs_flag & flags)
  39. mapped |= jfs_map[index].ext2_flag;
  40. }
  41. index++;
  42. }
  43. return mapped;
  44. }
  45. int jfs_ioctl(struct inode * inode, struct file * filp, unsigned int cmd,
  46. unsigned long arg)
  47. {
  48. struct jfs_inode_info *jfs_inode = JFS_IP(inode);
  49. unsigned int flags;
  50. switch (cmd) {
  51. case JFS_IOC_GETFLAGS:
  52. flags = jfs_inode->mode2 & JFS_FL_USER_VISIBLE;
  53. flags = jfs_map_ext2(flags, 0);
  54. return put_user(flags, (int __user *) arg);
  55. case JFS_IOC_SETFLAGS: {
  56. unsigned int oldflags;
  57. if (IS_RDONLY(inode))
  58. return -EROFS;
  59. if ((current->fsuid != inode->i_uid) && !capable(CAP_FOWNER))
  60. return -EACCES;
  61. if (get_user(flags, (int __user *) arg))
  62. return -EFAULT;
  63. flags = jfs_map_ext2(flags, 1);
  64. if (!S_ISDIR(inode->i_mode))
  65. flags &= ~JFS_DIRSYNC_FL;
  66. oldflags = jfs_inode->mode2;
  67. /*
  68. * The IMMUTABLE and APPEND_ONLY flags can only be changed by
  69. * the relevant capability.
  70. */
  71. if ((oldflags & JFS_IMMUTABLE_FL) ||
  72. ((flags ^ oldflags) &
  73. (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
  74. if (!capable(CAP_LINUX_IMMUTABLE))
  75. return -EPERM;
  76. }
  77. flags = flags & JFS_FL_USER_MODIFIABLE;
  78. flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
  79. jfs_inode->mode2 = flags;
  80. jfs_set_inode_flags(inode);
  81. inode->i_ctime = CURRENT_TIME_SEC;
  82. mark_inode_dirty(inode);
  83. return 0;
  84. }
  85. default:
  86. return -ENOTTY;
  87. }
  88. }