reiserfs_xattr.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. File: linux/reiserfs_xattr.h
  3. */
  4. #ifndef _LINUX_REISERFS_XATTR_H
  5. #define _LINUX_REISERFS_XATTR_H
  6. #include <linux/types.h>
  7. /* Magic value in header */
  8. #define REISERFS_XATTR_MAGIC 0x52465841 /* "RFXA" */
  9. struct reiserfs_xattr_header {
  10. __le32 h_magic; /* magic number for identification */
  11. __le32 h_hash; /* hash of the value */
  12. };
  13. struct reiserfs_security_handle {
  14. char *name;
  15. void *value;
  16. size_t length;
  17. };
  18. #ifdef __KERNEL__
  19. #include <linux/init.h>
  20. #include <linux/list.h>
  21. #include <linux/rwsem.h>
  22. #include <linux/reiserfs_fs_i.h>
  23. #include <linux/reiserfs_fs.h>
  24. struct inode;
  25. struct dentry;
  26. struct iattr;
  27. struct super_block;
  28. struct nameidata;
  29. int reiserfs_xattr_register_handlers(void) __init;
  30. void reiserfs_xattr_unregister_handlers(void);
  31. int reiserfs_xattr_init(struct super_block *sb, int mount_flags);
  32. int reiserfs_lookup_privroot(struct super_block *sb);
  33. int reiserfs_delete_xattrs(struct inode *inode);
  34. int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs);
  35. int reiserfs_permission(struct inode *inode, int mask);
  36. #ifdef CONFIG_REISERFS_FS_XATTR
  37. #define has_xattr_dir(inode) (REISERFS_I(inode)->i_flags & i_has_xattr_dir)
  38. ssize_t reiserfs_getxattr(struct dentry *dentry, const char *name,
  39. void *buffer, size_t size);
  40. int reiserfs_setxattr(struct dentry *dentry, const char *name,
  41. const void *value, size_t size, int flags);
  42. ssize_t reiserfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
  43. int reiserfs_removexattr(struct dentry *dentry, const char *name);
  44. int reiserfs_xattr_get(struct inode *, const char *, void *, size_t);
  45. int reiserfs_xattr_set(struct inode *, const char *, const void *, size_t, int);
  46. int reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *,
  47. struct inode *, const char *, const void *,
  48. size_t, int);
  49. extern const struct xattr_handler reiserfs_xattr_user_handler;
  50. extern const struct xattr_handler reiserfs_xattr_trusted_handler;
  51. extern const struct xattr_handler reiserfs_xattr_security_handler;
  52. #ifdef CONFIG_REISERFS_FS_SECURITY
  53. int reiserfs_security_init(struct inode *dir, struct inode *inode,
  54. struct reiserfs_security_handle *sec);
  55. int reiserfs_security_write(struct reiserfs_transaction_handle *th,
  56. struct inode *inode,
  57. struct reiserfs_security_handle *sec);
  58. void reiserfs_security_free(struct reiserfs_security_handle *sec);
  59. #endif
  60. static inline int reiserfs_xattrs_initialized(struct super_block *sb)
  61. {
  62. return REISERFS_SB(sb)->priv_root != NULL;
  63. }
  64. #define xattr_size(size) ((size) + sizeof(struct reiserfs_xattr_header))
  65. static inline loff_t reiserfs_xattr_nblocks(struct inode *inode, loff_t size)
  66. {
  67. loff_t ret = 0;
  68. if (reiserfs_file_data_log(inode)) {
  69. ret = _ROUND_UP(xattr_size(size), inode->i_sb->s_blocksize);
  70. ret >>= inode->i_sb->s_blocksize_bits;
  71. }
  72. return ret;
  73. }
  74. /* We may have to create up to 3 objects: xattr root, xattr dir, xattr file.
  75. * Let's try to be smart about it.
  76. * xattr root: We cache it. If it's not cached, we may need to create it.
  77. * xattr dir: If anything has been loaded for this inode, we can set a flag
  78. * saying so.
  79. * xattr file: Since we don't cache xattrs, we can't tell. We always include
  80. * blocks for it.
  81. *
  82. * However, since root and dir can be created between calls - YOU MUST SAVE
  83. * THIS VALUE.
  84. */
  85. static inline size_t reiserfs_xattr_jcreate_nblocks(struct inode *inode)
  86. {
  87. size_t nblocks = JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
  88. if ((REISERFS_I(inode)->i_flags & i_has_xattr_dir) == 0) {
  89. nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
  90. if (!REISERFS_SB(inode->i_sb)->xattr_root->d_inode)
  91. nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb);
  92. }
  93. return nblocks;
  94. }
  95. static inline void reiserfs_init_xattr_rwsem(struct inode *inode)
  96. {
  97. init_rwsem(&REISERFS_I(inode)->i_xattr_sem);
  98. }
  99. #else
  100. #define reiserfs_getxattr NULL
  101. #define reiserfs_setxattr NULL
  102. #define reiserfs_listxattr NULL
  103. #define reiserfs_removexattr NULL
  104. static inline void reiserfs_init_xattr_rwsem(struct inode *inode)
  105. {
  106. }
  107. #endif /* CONFIG_REISERFS_FS_XATTR */
  108. #ifndef CONFIG_REISERFS_FS_SECURITY
  109. static inline int reiserfs_security_init(struct inode *dir,
  110. struct inode *inode,
  111. struct reiserfs_security_handle *sec)
  112. {
  113. return 0;
  114. }
  115. static inline int
  116. reiserfs_security_write(struct reiserfs_transaction_handle *th,
  117. struct inode *inode,
  118. struct reiserfs_security_handle *sec)
  119. {
  120. return 0;
  121. }
  122. static inline void reiserfs_security_free(struct reiserfs_security_handle *sec)
  123. {}
  124. #endif
  125. #endif /* __KERNEL__ */
  126. #endif /* _LINUX_REISERFS_XATTR_H */