xattr.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. File: linux/ext2_xattr.h
  3. On-disk format of extended attributes for the ext2 filesystem.
  4. (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
  5. */
  6. #include <linux/config.h>
  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[0]; /* 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. # ifdef CONFIG_EXT2_FS_XATTR
  48. extern struct xattr_handler ext2_xattr_user_handler;
  49. extern struct xattr_handler ext2_xattr_trusted_handler;
  50. extern struct xattr_handler ext2_xattr_acl_access_handler;
  51. extern struct xattr_handler ext2_xattr_acl_default_handler;
  52. extern struct xattr_handler ext2_xattr_security_handler;
  53. extern ssize_t ext2_listxattr(struct dentry *, char *, size_t);
  54. extern int ext2_xattr_get(struct inode *, int, const char *, void *, size_t);
  55. extern int ext2_xattr_set(struct inode *, int, const char *, const void *, size_t, int);
  56. extern void ext2_xattr_delete_inode(struct inode *);
  57. extern void ext2_xattr_put_super(struct super_block *);
  58. extern int init_ext2_xattr(void);
  59. extern void exit_ext2_xattr(void);
  60. extern struct xattr_handler *ext2_xattr_handlers[];
  61. # else /* CONFIG_EXT2_FS_XATTR */
  62. static inline int
  63. ext2_xattr_get(struct inode *inode, int name_index,
  64. const char *name, void *buffer, size_t size)
  65. {
  66. return -EOPNOTSUPP;
  67. }
  68. static inline int
  69. ext2_xattr_set(struct inode *inode, int name_index, const char *name,
  70. const void *value, size_t size, int flags)
  71. {
  72. return -EOPNOTSUPP;
  73. }
  74. static inline void
  75. ext2_xattr_delete_inode(struct inode *inode)
  76. {
  77. }
  78. static inline void
  79. ext2_xattr_put_super(struct super_block *sb)
  80. {
  81. }
  82. static inline int
  83. init_ext2_xattr(void)
  84. {
  85. return 0;
  86. }
  87. static inline void
  88. exit_ext2_xattr(void)
  89. {
  90. }
  91. #define ext2_xattr_handlers NULL
  92. # endif /* CONFIG_EXT2_FS_XATTR */
  93. #ifdef CONFIG_EXT2_FS_SECURITY
  94. extern int ext2_init_security(struct inode *inode, struct inode *dir);
  95. #else
  96. static inline int ext2_init_security(struct inode *inode, struct inode *dir)
  97. {
  98. return 0;
  99. }
  100. #endif