xattr.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 MIN_INLINE_XATTR_SIZE (sizeof(struct f2fs_xattr_header) / sizeof(__le32))
  72. #define MAX_INLINE_XATTR_SIZE \
  73. (DEF_ADDRS_PER_INODE - \
  74. F2FS_TOTAL_EXTRA_ATTR_SIZE / sizeof(__le32) - \
  75. DEF_INLINE_RESERVED_SIZE - \
  76. MIN_INLINE_DENTRY_SIZE / sizeof(__le32))
  77. #define DEFAULT_XATTR_SLAB_SIZE (DEFAULT_INLINE_XATTR_ADDRS * \
  78. sizeof(__le32) + XATTR_PADDING_SIZE)
  79. /*
  80. * On-disk structure of f2fs_xattr
  81. * We use inline xattrs space + 1 block for xattr.
  82. *
  83. * +--------------------+
  84. * | f2fs_xattr_header |
  85. * | |
  86. * +--------------------+
  87. * | f2fs_xattr_entry |
  88. * | .e_name_index = 1 |
  89. * | .e_name_len = 3 |
  90. * | .e_value_size = 14 |
  91. * | .e_name = "foo" |
  92. * | "value_of_xattr" |<- value_offs = e_name + e_name_len
  93. * +--------------------+
  94. * | f2fs_xattr_entry |
  95. * | .e_name_index = 4 |
  96. * | .e_name = "bar" |
  97. * +--------------------+
  98. * | |
  99. * | Free |
  100. * | |
  101. * +--------------------+<- MIN_OFFSET
  102. * | node_footer |
  103. * | (nid, ino, offset) |
  104. * +--------------------+
  105. *
  106. **/
  107. #ifdef CONFIG_F2FS_FS_XATTR
  108. extern const struct xattr_handler f2fs_xattr_user_handler;
  109. extern const struct xattr_handler f2fs_xattr_trusted_handler;
  110. extern const struct xattr_handler f2fs_xattr_advise_handler;
  111. extern const struct xattr_handler f2fs_xattr_security_handler;
  112. extern const struct xattr_handler * const f2fs_xattr_handlers[];
  113. int f2fs_setxattr(struct inode *, int, const char *, const void *,
  114. size_t, struct folio *, int);
  115. int f2fs_getxattr(struct inode *, int, const char *, void *,
  116. size_t, struct folio *);
  117. ssize_t f2fs_listxattr(struct dentry *, char *, size_t);
  118. int __init f2fs_init_xattr_cache(void);
  119. void f2fs_destroy_xattr_cache(void);
  120. #else
  121. #define f2fs_xattr_handlers NULL
  122. #define f2fs_listxattr NULL
  123. static inline int f2fs_setxattr(struct inode *inode, int index,
  124. const char *name, const void *value, size_t size,
  125. struct folio *folio, int flags)
  126. {
  127. return -EOPNOTSUPP;
  128. }
  129. static inline int f2fs_getxattr(struct inode *inode, int index,
  130. const char *name, void *buffer,
  131. size_t buffer_size, struct folio *dfolio)
  132. {
  133. return -EOPNOTSUPP;
  134. }
  135. static inline int __init f2fs_init_xattr_cache(void) { return 0; }
  136. static inline void f2fs_destroy_xattr_cache(void) { }
  137. #endif
  138. #ifdef CONFIG_F2FS_FS_SECURITY
  139. int f2fs_init_security(struct inode *, struct inode *,
  140. const struct qstr *, struct folio *);
  141. #else
  142. static inline int f2fs_init_security(struct inode *inode, struct inode *dir,
  143. const struct qstr *qstr, struct folio *ifolio)
  144. {
  145. return 0;
  146. }
  147. #endif
  148. #endif /* __F2FS_XATTR_H__ */