xattr.h 4.6 KB

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