xattr.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #include <linux/reiserfs_xattr.h>
  3. #include <linux/init.h>
  4. #include <linux/list.h>
  5. #include <linux/rwsem.h>
  6. #include <linux/xattr.h>
  7. struct inode;
  8. struct dentry;
  9. struct iattr;
  10. struct super_block;
  11. int reiserfs_xattr_register_handlers(void) __init;
  12. void reiserfs_xattr_unregister_handlers(void);
  13. int reiserfs_xattr_init(struct super_block *sb, int mount_flags);
  14. int reiserfs_lookup_privroot(struct super_block *sb);
  15. int reiserfs_delete_xattrs(struct inode *inode);
  16. int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs);
  17. int reiserfs_permission(struct user_namespace *mnt_userns,
  18. struct inode *inode, int mask);
  19. #ifdef CONFIG_REISERFS_FS_XATTR
  20. #define has_xattr_dir(inode) (REISERFS_I(inode)->i_flags & i_has_xattr_dir)
  21. ssize_t reiserfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
  22. int reiserfs_xattr_get(struct inode *, const char *, void *, size_t);
  23. int reiserfs_xattr_set(struct inode *, const char *, const void *, size_t, int);
  24. int reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *,
  25. struct inode *, const char *, const void *,
  26. size_t, int);
  27. extern const struct xattr_handler reiserfs_xattr_user_handler;
  28. extern const struct xattr_handler reiserfs_xattr_trusted_handler;
  29. extern const struct xattr_handler reiserfs_xattr_security_handler;
  30. #ifdef CONFIG_REISERFS_FS_SECURITY
  31. int reiserfs_security_init(struct inode *dir, struct inode *inode,
  32. const struct qstr *qstr,
  33. struct reiserfs_security_handle *sec);
  34. int reiserfs_security_write(struct reiserfs_transaction_handle *th,
  35. struct inode *inode,
  36. struct reiserfs_security_handle *sec);
  37. void reiserfs_security_free(struct reiserfs_security_handle *sec);
  38. #endif
  39. static inline int reiserfs_xattrs_initialized(struct super_block *sb)
  40. {
  41. return REISERFS_SB(sb)->priv_root && REISERFS_SB(sb)->xattr_root;
  42. }
  43. #define xattr_size(size) ((size) + sizeof(struct reiserfs_xattr_header))
  44. static inline loff_t reiserfs_xattr_nblocks(struct inode *inode, loff_t size)
  45. {
  46. loff_t ret = 0;
  47. if (reiserfs_file_data_log(inode)) {
  48. ret = _ROUND_UP(xattr_size(size), inode->i_sb->s_blocksize);
  49. ret >>= inode->i_sb->s_blocksize_bits;
  50. }
  51. return ret;
  52. }
  53. /*
  54. * We may have to create up to 3 objects: xattr root, xattr dir, xattr file.
  55. * Let's try to be smart about it.
  56. * xattr root: We cache it. If it's not cached, we may need to create it.
  57. * xattr dir: If anything has been loaded for this inode, we can set a flag
  58. * saying so.
  59. * xattr file: Since we don't cache xattrs, we can't tell. We always include
  60. * blocks for it.
  61. *
  62. * However, since root and dir can be created between calls - YOU MUST SAVE
  63. * THIS VALUE.
  64. */
  65. static inline size_t reiserfs_xattr_jcreate_nblocks(struct inode *inode)
  66. {
  67. size_t nblocks = JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
  68. if ((REISERFS_I(inode)->i_flags & i_has_xattr_dir) == 0) {
  69. nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
  70. if (d_really_is_negative(REISERFS_SB(inode->i_sb)->xattr_root))
  71. nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
  72. }
  73. return nblocks;
  74. }
  75. static inline void reiserfs_init_xattr_rwsem(struct inode *inode)
  76. {
  77. init_rwsem(&REISERFS_I(inode)->i_xattr_sem);
  78. }
  79. #else
  80. #define reiserfs_listxattr NULL
  81. static inline void reiserfs_init_xattr_rwsem(struct inode *inode)
  82. {
  83. }
  84. #endif /* CONFIG_REISERFS_FS_XATTR */
  85. #ifndef CONFIG_REISERFS_FS_SECURITY
  86. static inline int reiserfs_security_init(struct inode *dir,
  87. struct inode *inode,
  88. const struct qstr *qstr,
  89. struct reiserfs_security_handle *sec)
  90. {
  91. return 0;
  92. }
  93. static inline int
  94. reiserfs_security_write(struct reiserfs_transaction_handle *th,
  95. struct inode *inode,
  96. struct reiserfs_security_handle *sec)
  97. {
  98. return 0;
  99. }
  100. static inline void reiserfs_security_free(struct reiserfs_security_handle *sec)
  101. {}
  102. #endif