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