xattr.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. File: linux/ext2_xattr.h
  4. On-disk format of extended attributes for the ext2 filesystem.
  5. (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
  6. */
  7. #include <linux/init.h>
  8. #include <linux/xattr.h>
  9. /* Magic value in attribute blocks */
  10. #define EXT2_XATTR_MAGIC 0xEA020000
  11. /* Maximum number of references to one attribute block */
  12. #define EXT2_XATTR_REFCOUNT_MAX 1024
  13. /* Name indexes */
  14. #define EXT2_XATTR_INDEX_USER 1
  15. #define EXT2_XATTR_INDEX_POSIX_ACL_ACCESS 2
  16. #define EXT2_XATTR_INDEX_POSIX_ACL_DEFAULT 3
  17. #define EXT2_XATTR_INDEX_TRUSTED 4
  18. #define EXT2_XATTR_INDEX_LUSTRE 5
  19. #define EXT2_XATTR_INDEX_SECURITY 6
  20. struct ext2_xattr_header {
  21. __le32 h_magic; /* magic number for identification */
  22. __le32 h_refcount; /* reference count */
  23. __le32 h_blocks; /* number of disk blocks used */
  24. __le32 h_hash; /* hash value of all attributes */
  25. __u32 h_reserved[4]; /* zero right now */
  26. };
  27. struct ext2_xattr_entry {
  28. __u8 e_name_len; /* length of name */
  29. __u8 e_name_index; /* attribute name index */
  30. __le16 e_value_offs; /* offset in disk block of value */
  31. __le32 e_value_block; /* disk block attribute is stored on (n/i) */
  32. __le32 e_value_size; /* size of attribute value */
  33. __le32 e_hash; /* hash value of name and value */
  34. char e_name[]; /* attribute name */
  35. };
  36. #define EXT2_XATTR_PAD_BITS 2
  37. #define EXT2_XATTR_PAD (1<<EXT2_XATTR_PAD_BITS)
  38. #define EXT2_XATTR_ROUND (EXT2_XATTR_PAD-1)
  39. #define EXT2_XATTR_LEN(name_len) \
  40. (((name_len) + EXT2_XATTR_ROUND + \
  41. sizeof(struct ext2_xattr_entry)) & ~EXT2_XATTR_ROUND)
  42. #define EXT2_XATTR_NEXT(entry) \
  43. ( (struct ext2_xattr_entry *)( \
  44. (char *)(entry) + EXT2_XATTR_LEN((entry)->e_name_len)) )
  45. #define EXT2_XATTR_SIZE(size) \
  46. (((size) + EXT2_XATTR_ROUND) & ~EXT2_XATTR_ROUND)
  47. struct mb_cache;
  48. # ifdef CONFIG_EXT2_FS_XATTR
  49. extern const struct xattr_handler ext2_xattr_user_handler;
  50. extern const struct xattr_handler ext2_xattr_trusted_handler;
  51. extern const struct xattr_handler ext2_xattr_security_handler;
  52. extern ssize_t ext2_listxattr(struct dentry *, char *, size_t);
  53. extern int ext2_xattr_get(struct inode *, int, const char *, void *, size_t);
  54. extern int ext2_xattr_set(struct inode *, int, const char *, const void *, size_t, int);
  55. extern void ext2_xattr_delete_inode(struct inode *);
  56. extern struct mb_cache *ext2_xattr_create_cache(void);
  57. extern void ext2_xattr_destroy_cache(struct mb_cache *cache);
  58. extern const struct xattr_handler *ext2_xattr_handlers[];
  59. # else /* CONFIG_EXT2_FS_XATTR */
  60. static inline int
  61. ext2_xattr_get(struct inode *inode, int name_index,
  62. const char *name, void *buffer, size_t size)
  63. {
  64. return -EOPNOTSUPP;
  65. }
  66. static inline int
  67. ext2_xattr_set(struct inode *inode, int name_index, const char *name,
  68. const void *value, size_t size, int flags)
  69. {
  70. return -EOPNOTSUPP;
  71. }
  72. static inline void
  73. ext2_xattr_delete_inode(struct inode *inode)
  74. {
  75. }
  76. static inline void ext2_xattr_destroy_cache(struct mb_cache *cache)
  77. {
  78. }
  79. #define ext2_xattr_handlers NULL
  80. #define ext2_listxattr NULL
  81. # endif /* CONFIG_EXT2_FS_XATTR */
  82. #ifdef CONFIG_EXT2_FS_SECURITY
  83. extern int ext2_init_security(struct inode *inode, struct inode *dir,
  84. const struct qstr *qstr);
  85. #else
  86. static inline int ext2_init_security(struct inode *inode, struct inode *dir,
  87. const struct qstr *qstr)
  88. {
  89. return 0;
  90. }
  91. #endif