1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#ifndef __F2FS_XATTR_H__
18#define __F2FS_XATTR_H__
19
20#include <linux/init.h>
21#include <linux/xattr.h>
22
23
24#define F2FS_XATTR_MAGIC 0xF2F52011
25
26
27#define F2FS_XATTR_REFCOUNT_MAX 1024
28
29
30#define F2FS_SYSTEM_ADVISE_PREFIX "system.advise"
31#define F2FS_XATTR_INDEX_USER 1
32#define F2FS_XATTR_INDEX_POSIX_ACL_ACCESS 2
33#define F2FS_XATTR_INDEX_POSIX_ACL_DEFAULT 3
34#define F2FS_XATTR_INDEX_TRUSTED 4
35#define F2FS_XATTR_INDEX_LUSTRE 5
36#define F2FS_XATTR_INDEX_SECURITY 6
37#define F2FS_XATTR_INDEX_ADVISE 7
38
39struct f2fs_xattr_header {
40 __le32 h_magic;
41 __le32 h_refcount;
42 __u32 h_reserved[4];
43};
44
45struct f2fs_xattr_entry {
46 __u8 e_name_index;
47 __u8 e_name_len;
48 __le16 e_value_size;
49 char e_name[0];
50};
51
52#define XATTR_HDR(ptr) ((struct f2fs_xattr_header *)(ptr))
53#define XATTR_ENTRY(ptr) ((struct f2fs_xattr_entry *)(ptr))
54#define XATTR_FIRST_ENTRY(ptr) (XATTR_ENTRY(XATTR_HDR(ptr)+1))
55#define XATTR_ROUND (3)
56
57#define XATTR_ALIGN(size) ((size + XATTR_ROUND) & ~XATTR_ROUND)
58
59#define ENTRY_SIZE(entry) (XATTR_ALIGN(sizeof(struct f2fs_xattr_entry) + \
60 entry->e_name_len + le16_to_cpu(entry->e_value_size)))
61
62#define XATTR_NEXT_ENTRY(entry) ((struct f2fs_xattr_entry *)((char *)(entry) +\
63 ENTRY_SIZE(entry)))
64
65#define IS_XATTR_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0)
66
67#define list_for_each_xattr(entry, addr) \
68 for (entry = XATTR_FIRST_ENTRY(addr);\
69 !IS_XATTR_LAST_ENTRY(entry);\
70 entry = XATTR_NEXT_ENTRY(entry))
71
72
73#define MIN_OFFSET XATTR_ALIGN(PAGE_SIZE - \
74 sizeof(struct node_footer) - \
75 sizeof(__u32))
76
77#define MAX_VALUE_LEN (MIN_OFFSET - sizeof(struct f2fs_xattr_header) - \
78 sizeof(struct f2fs_xattr_entry))
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109#ifdef CONFIG_F2FS_FS_XATTR
110extern const struct xattr_handler f2fs_xattr_user_handler;
111extern const struct xattr_handler f2fs_xattr_trusted_handler;
112extern const struct xattr_handler f2fs_xattr_acl_access_handler;
113extern const struct xattr_handler f2fs_xattr_acl_default_handler;
114extern const struct xattr_handler f2fs_xattr_advise_handler;
115extern const struct xattr_handler f2fs_xattr_security_handler;
116
117extern const struct xattr_handler *f2fs_xattr_handlers[];
118
119extern int f2fs_setxattr(struct inode *, int, const char *,
120 const void *, size_t, struct page *);
121extern int f2fs_getxattr(struct inode *, int, const char *, void *, size_t);
122extern ssize_t f2fs_listxattr(struct dentry *, char *, size_t);
123#else
124
125#define f2fs_xattr_handlers NULL
126static inline int f2fs_setxattr(struct inode *inode, int name_index,
127 const char *name, const void *value, size_t value_len)
128{
129 return -EOPNOTSUPP;
130}
131static inline int f2fs_getxattr(struct inode *inode, int name_index,
132 const char *name, void *buffer, size_t buffer_size)
133{
134 return -EOPNOTSUPP;
135}
136static inline ssize_t f2fs_listxattr(struct dentry *dentry, char *buffer,
137 size_t buffer_size)
138{
139 return -EOPNOTSUPP;
140}
141#endif
142
143#ifdef CONFIG_F2FS_FS_SECURITY
144extern int f2fs_init_security(struct inode *, struct inode *,
145 const struct qstr *, struct page *);
146#else
147static inline int f2fs_init_security(struct inode *inode, struct inode *dir,
148 const struct qstr *qstr, struct page *ipage)
149{
150 return 0;
151}
152#endif
153#endif
154