xattr.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * fs/f2fs/xattr.h
  4. *
  5. * Copyright (c) 2012 Samsung Electronics Co., Ltd.
  6. * http://www.samsung.com/
  7. *
  8. * Portions of this code from linux/fs/ext2/xattr.h
  9. *
  10. * On-disk format of extended attributes for the ext2 filesystem.
  11. *
  12. * (C) 2001 Andreas Gruenbacher, <a.gruenbacher@computer.org>
  13. */
  14. #ifndef __F2FS_XATTR_H__
  15. #define __F2FS_XATTR_H__
  16. #include <linux/init.h>
  17. #include <linux/xattr.h>
  18. /* Magic value in attribute blocks */
  19. #define F2FS_XATTR_MAGIC 0xF2F52011
  20. /* Maximum number of references to one attribute block */
  21. #define F2FS_XATTR_REFCOUNT_MAX 1024
  22. /* Name indexes */
  23. #define F2FS_SYSTEM_ADVISE_NAME "system.advise"
  24. #define F2FS_XATTR_INDEX_USER 1
  25. #define F2FS_XATTR_INDEX_POSIX_ACL_ACCESS 2
  26. #define F2FS_XATTR_INDEX_POSIX_ACL_DEFAULT 3
  27. #define F2FS_XATTR_INDEX_TRUSTED 4
  28. #define F2FS_XATTR_INDEX_LUSTRE 5
  29. #define F2FS_XATTR_INDEX_SECURITY 6
  30. #define F2FS_XATTR_INDEX_ADVISE 7
  31. /* Should be same as EXT4_XATTR_INDEX_ENCRYPTION */
  32. #define F2FS_XATTR_INDEX_ENCRYPTION 9
  33. #define F2FS_XATTR_INDEX_VERITY 11
  34. #define F2FS_XATTR_NAME_ENCRYPTION_CONTEXT "c"
  35. #define F2FS_XATTR_NAME_VERITY "v"
  36. struct f2fs_xattr_header {
  37. __le32 h_magic; /* magic number for identification */
  38. __le32 h_refcount; /* reference count */
  39. __u32 h_reserved[4]; /* zero right now */
  40. };
  41. struct f2fs_xattr_entry {
  42. __u8 e_name_index;
  43. __u8 e_name_len;
  44. __le16 e_value_size; /* size of attribute value */
  45. char e_name[]; /* attribute name */
  46. };
  47. #define XATTR_HDR(ptr) ((struct f2fs_xattr_header *)(ptr))
  48. #define XATTR_ENTRY(ptr) ((struct f2fs_xattr_entry *)(ptr))
  49. #define XATTR_FIRST_ENTRY(ptr) (XATTR_ENTRY(XATTR_HDR(ptr) + 1))
  50. #define XATTR_ROUND (3)
  51. #define XATTR_ALIGN(size) (((size) + XATTR_ROUND) & ~XATTR_ROUND)
  52. #define ENTRY_SIZE(entry) (XATTR_ALIGN(sizeof(struct f2fs_xattr_entry) + \
  53. (entry)->e_name_len + le16_to_cpu((entry)->e_value_size)))
  54. #define XATTR_NEXT_ENTRY(entry) ((struct f2fs_xattr_entry *)((char *)(entry) +\
  55. ENTRY_SIZE(entry)))
  56. #define IS_XATTR_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
  57. #define list_for_each_xattr(entry, addr) \
  58. for (entry = XATTR_FIRST_ENTRY(addr);\
  59. !IS_XATTR_LAST_ENTRY(entry);\
  60. entry = XATTR_NEXT_ENTRY(entry))
  61. #define VALID_XATTR_BLOCK_SIZE (PAGE_SIZE - sizeof(struct node_footer))
  62. #define XATTR_PADDING_SIZE (sizeof(__u32))
  63. #define XATTR_SIZE(i) ((F2FS_I(i)->i_xattr_nid ? \
  64. VALID_XATTR_BLOCK_SIZE : 0) + \
  65. (inline_xattr_size(i)))
  66. #define MIN_OFFSET(i) XATTR_ALIGN(inline_xattr_size(i) + \
  67. VALID_XATTR_BLOCK_SIZE)
  68. #define MAX_VALUE_LEN(i) (MIN_OFFSET(i) - \
  69. sizeof(struct f2fs_xattr_header) - \
  70. sizeof(struct f2fs_xattr_entry))
  71. #define MAX_INLINE_XATTR_SIZE \
  72. (DEF_ADDRS_PER_INODE - \
  73. F2FS_TOTAL_EXTRA_ATTR_SIZE / sizeof(__le32) - \
  74. DEF_INLINE_RESERVED_SIZE - \
  75. MIN_INLINE_DENTRY_SIZE / sizeof(__le32))
  76. /*
  77. * On-disk structure of f2fs_xattr
  78. * We use inline xattrs space + 1 block for xattr.
  79. *
  80. * +--------------------+
  81. * | f2fs_xattr_header |
  82. * | |
  83. * +--------------------+
  84. * | f2fs_xattr_entry |
  85. * | .e_name_index = 1 |
  86. * | .e_name_len = 3 |
  87. * | .e_value_size = 14 |
  88. * | .e_name = "foo" |
  89. * | "value_of_xattr" |<- value_offs = e_name + e_name_len
  90. * +--------------------+
  91. * | f2fs_xattr_entry |
  92. * | .e_name_index = 4 |
  93. * | .e_name = "bar" |
  94. * +--------------------+
  95. * | |
  96. * | Free |
  97. * | |
  98. * +--------------------+<- MIN_OFFSET
  99. * | node_footer |
  100. * | (nid, ino, offset) |
  101. * +--------------------+
  102. *
  103. **/
  104. #ifdef CONFIG_F2FS_FS_XATTR
  105. extern const struct xattr_handler f2fs_xattr_user_handler;
  106. extern const struct xattr_handler f2fs_xattr_trusted_handler;
  107. extern const struct xattr_handler f2fs_xattr_advise_handler;
  108. extern const struct xattr_handler f2fs_xattr_security_handler;
  109. extern const struct xattr_handler *f2fs_xattr_handlers[];
  110. extern int f2fs_setxattr(struct inode *, int, const char *,
  111. const void *, size_t, struct page *, int);
  112. extern int f2fs_getxattr(struct inode *, int, const char *, void *,
  113. size_t, struct page *);
  114. extern ssize_t f2fs_listxattr(struct dentry *, char *, size_t);
  115. extern int f2fs_init_xattr_caches(struct f2fs_sb_info *);
  116. extern void f2fs_destroy_xattr_caches(struct f2fs_sb_info *);
  117. #else
  118. #define f2fs_xattr_handlers NULL
  119. #define f2fs_listxattr NULL
  120. static inline int f2fs_setxattr(struct inode *inode, int index,
  121. const char *name, const void *value, size_t size,
  122. struct page *page, int flags)
  123. {
  124. return -EOPNOTSUPP;
  125. }
  126. static inline int f2fs_getxattr(struct inode *inode, int index,
  127. const char *name, void *buffer,
  128. size_t buffer_size, struct page *dpage)
  129. {
  130. return -EOPNOTSUPP;
  131. }
  132. static inline int f2fs_init_xattr_caches(struct f2fs_sb_info *sbi) { return 0; }
  133. static inline void f2fs_destroy_xattr_caches(struct f2fs_sb_info *sbi) { }
  134. #endif
  135. #ifdef CONFIG_F2FS_FS_SECURITY
  136. extern int f2fs_init_security(struct inode *, struct inode *,
  137. const struct qstr *, struct page *);
  138. #else
  139. static inline int f2fs_init_security(struct inode *inode, struct inode *dir,
  140. const struct qstr *qstr, struct page *ipage)
  141. {
  142. return 0;
  143. }
  144. #endif
  145. #endif /* __F2FS_XATTR_H__ */