xattr.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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, <[email protected]>
  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_NAME_ENCRYPTION_CONTEXT "c"
  34. struct f2fs_xattr_header {
  35. __le32 h_magic; /* magic number for identification */
  36. __le32 h_refcount; /* reference count */
  37. __u32 h_reserved[4]; /* zero right now */
  38. };
  39. struct f2fs_xattr_entry {
  40. __u8 e_name_index;
  41. __u8 e_name_len;
  42. __le16 e_value_size; /* size of attribute value */
  43. char e_name[0]; /* attribute name */
  44. };
  45. #define XATTR_HDR(ptr) ((struct f2fs_xattr_header *)(ptr))
  46. #define XATTR_ENTRY(ptr) ((struct f2fs_xattr_entry *)(ptr))
  47. #define XATTR_FIRST_ENTRY(ptr) (XATTR_ENTRY(XATTR_HDR(ptr) + 1))
  48. #define XATTR_ROUND (3)
  49. #define XATTR_ALIGN(size) (((size) + XATTR_ROUND) & ~XATTR_ROUND)
  50. #define ENTRY_SIZE(entry) (XATTR_ALIGN(sizeof(struct f2fs_xattr_entry) + \
  51. (entry)->e_name_len + le16_to_cpu((entry)->e_value_size)))
  52. #define XATTR_NEXT_ENTRY(entry) ((struct f2fs_xattr_entry *)((char *)(entry) +\
  53. ENTRY_SIZE(entry)))
  54. #define IS_XATTR_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
  55. #define list_for_each_xattr(entry, addr) \
  56. for (entry = XATTR_FIRST_ENTRY(addr);\
  57. !IS_XATTR_LAST_ENTRY(entry);\
  58. entry = XATTR_NEXT_ENTRY(entry))
  59. #define VALID_XATTR_BLOCK_SIZE (PAGE_SIZE - sizeof(struct node_footer))
  60. #define XATTR_PADDING_SIZE (sizeof(__u32))
  61. #define MIN_OFFSET(i) XATTR_ALIGN(inline_xattr_size(i) + \
  62. VALID_XATTR_BLOCK_SIZE)
  63. #define MAX_VALUE_LEN(i) (MIN_OFFSET(i) - \
  64. sizeof(struct f2fs_xattr_header) - \
  65. sizeof(struct f2fs_xattr_entry))
  66. #define MAX_INLINE_XATTR_SIZE \
  67. (DEF_ADDRS_PER_INODE - \
  68. F2FS_TOTAL_EXTRA_ATTR_SIZE / sizeof(__le32) - \
  69. DEF_INLINE_RESERVED_SIZE - \
  70. MIN_INLINE_DENTRY_SIZE / sizeof(__le32))
  71. /*
  72. * On-disk structure of f2fs_xattr
  73. * We use inline xattrs space + 1 block for xattr.
  74. *
  75. * +--------------------+
  76. * | f2fs_xattr_header |
  77. * | |
  78. * +--------------------+
  79. * | f2fs_xattr_entry |
  80. * | .e_name_index = 1 |
  81. * | .e_name_len = 3 |
  82. * | .e_value_size = 14 |
  83. * | .e_name = "foo" |
  84. * | "value_of_xattr" |<- value_offs = e_name + e_name_len
  85. * +--------------------+
  86. * | f2fs_xattr_entry |
  87. * | .e_name_index = 4 |
  88. * | .e_name = "bar" |
  89. * +--------------------+
  90. * | |
  91. * | Free |
  92. * | |
  93. * +--------------------+<- MIN_OFFSET
  94. * | node_footer |
  95. * | (nid, ino, offset) |
  96. * +--------------------+
  97. *
  98. **/
  99. #ifdef CONFIG_F2FS_FS_XATTR
  100. extern const struct xattr_handler f2fs_xattr_user_handler;
  101. extern const struct xattr_handler f2fs_xattr_trusted_handler;
  102. extern const struct xattr_handler f2fs_xattr_advise_handler;
  103. extern const struct xattr_handler f2fs_xattr_security_handler;
  104. extern const struct xattr_handler *f2fs_xattr_handlers[];
  105. extern int f2fs_setxattr(struct inode *, int, const char *,
  106. const void *, size_t, struct page *, int);
  107. extern int f2fs_getxattr(struct inode *, int, const char *, void *,
  108. size_t, struct page *);
  109. extern ssize_t f2fs_listxattr(struct dentry *, char *, size_t);
  110. #else
  111. #define f2fs_xattr_handlers NULL
  112. static inline int f2fs_setxattr(struct inode *inode, int index,
  113. const char *name, const void *value, size_t size,
  114. struct page *page, int flags)
  115. {
  116. return -EOPNOTSUPP;
  117. }
  118. static inline int f2fs_getxattr(struct inode *inode, int index,
  119. const char *name, void *buffer,
  120. size_t buffer_size, struct page *dpage)
  121. {
  122. return -EOPNOTSUPP;
  123. }
  124. static inline ssize_t f2fs_listxattr(struct dentry *dentry, char *buffer,
  125. size_t buffer_size)
  126. {
  127. return -EOPNOTSUPP;
  128. }
  129. #endif
  130. #ifdef CONFIG_F2FS_FS_SECURITY
  131. extern int f2fs_init_security(struct inode *, struct inode *,
  132. const struct qstr *, struct page *);
  133. #else
  134. static inline int f2fs_init_security(struct inode *inode, struct inode *dir,
  135. const struct qstr *qstr, struct page *ipage)
  136. {
  137. return 0;
  138. }
  139. #endif
  140. #endif /* __F2FS_XATTR_H__ */