]>
Commit | Line | Data |
---|---|---|
7c1a000d | 1 | // SPDX-License-Identifier: GPL-2.0 |
0a8165d7 | 2 | /* |
af48b85b JK |
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> | |
af48b85b JK |
13 | */ |
14 | #ifndef __F2FS_XATTR_H__ | |
15 | #define __F2FS_XATTR_H__ | |
16 | ||
17 | #include <linux/init.h> | |
18 | #include <linux/xattr.h> | |
19 | ||
20 | /* Magic value in attribute blocks */ | |
21 | #define F2FS_XATTR_MAGIC 0xF2F52011 | |
22 | ||
23 | /* Maximum number of references to one attribute block */ | |
24 | #define F2FS_XATTR_REFCOUNT_MAX 1024 | |
25 | ||
26 | /* Name indexes */ | |
98e9cb57 | 27 | #define F2FS_SYSTEM_ADVISE_NAME "system.advise" |
af48b85b JK |
28 | #define F2FS_XATTR_INDEX_USER 1 |
29 | #define F2FS_XATTR_INDEX_POSIX_ACL_ACCESS 2 | |
30 | #define F2FS_XATTR_INDEX_POSIX_ACL_DEFAULT 3 | |
31 | #define F2FS_XATTR_INDEX_TRUSTED 4 | |
32 | #define F2FS_XATTR_INDEX_LUSTRE 5 | |
33 | #define F2FS_XATTR_INDEX_SECURITY 6 | |
34 | #define F2FS_XATTR_INDEX_ADVISE 7 | |
b93531dd JK |
35 | /* Should be same as EXT4_XATTR_INDEX_ENCRYPTION */ |
36 | #define F2FS_XATTR_INDEX_ENCRYPTION 9 | |
95ae251f | 37 | #define F2FS_XATTR_INDEX_VERITY 11 |
b93531dd JK |
38 | |
39 | #define F2FS_XATTR_NAME_ENCRYPTION_CONTEXT "c" | |
95ae251f | 40 | #define F2FS_XATTR_NAME_VERITY "v" |
af48b85b JK |
41 | |
42 | struct f2fs_xattr_header { | |
43 | __le32 h_magic; /* magic number for identification */ | |
44 | __le32 h_refcount; /* reference count */ | |
45 | __u32 h_reserved[4]; /* zero right now */ | |
46 | }; | |
47 | ||
48 | struct f2fs_xattr_entry { | |
49 | __u8 e_name_index; | |
50 | __u8 e_name_len; | |
51 | __le16 e_value_size; /* size of attribute value */ | |
52 | char e_name[0]; /* attribute name */ | |
53 | }; | |
54 | ||
55 | #define XATTR_HDR(ptr) ((struct f2fs_xattr_header *)(ptr)) | |
56 | #define XATTR_ENTRY(ptr) ((struct f2fs_xattr_entry *)(ptr)) | |
dd9cfe23 | 57 | #define XATTR_FIRST_ENTRY(ptr) (XATTR_ENTRY(XATTR_HDR(ptr) + 1)) |
af48b85b JK |
58 | #define XATTR_ROUND (3) |
59 | ||
68afcf2d | 60 | #define XATTR_ALIGN(size) (((size) + XATTR_ROUND) & ~XATTR_ROUND) |
af48b85b JK |
61 | |
62 | #define ENTRY_SIZE(entry) (XATTR_ALIGN(sizeof(struct f2fs_xattr_entry) + \ | |
68afcf2d | 63 | (entry)->e_name_len + le16_to_cpu((entry)->e_value_size))) |
af48b85b JK |
64 | |
65 | #define XATTR_NEXT_ENTRY(entry) ((struct f2fs_xattr_entry *)((char *)(entry) +\ | |
66 | ENTRY_SIZE(entry))) | |
67 | ||
68 | #define IS_XATTR_LAST_ENTRY(entry) (*(__u32 *)(entry) == 0) | |
69 | ||
70 | #define list_for_each_xattr(entry, addr) \ | |
71 | for (entry = XATTR_FIRST_ENTRY(addr);\ | |
72 | !IS_XATTR_LAST_ENTRY(entry);\ | |
73 | entry = XATTR_NEXT_ENTRY(entry)) | |
22588f87 CY |
74 | #define VALID_XATTR_BLOCK_SIZE (PAGE_SIZE - sizeof(struct node_footer)) |
75 | #define XATTR_PADDING_SIZE (sizeof(__u32)) | |
2777e654 RH |
76 | #define XATTR_SIZE(x,i) (((x) ? VALID_XATTR_BLOCK_SIZE : 0) + \ |
77 | (inline_xattr_size(i))) | |
ba38c27e CY |
78 | #define MIN_OFFSET(i) XATTR_ALIGN(inline_xattr_size(i) + \ |
79 | VALID_XATTR_BLOCK_SIZE) | |
af48b85b | 80 | |
65985d93 JK |
81 | #define MAX_VALUE_LEN(i) (MIN_OFFSET(i) - \ |
82 | sizeof(struct f2fs_xattr_header) - \ | |
83 | sizeof(struct f2fs_xattr_entry)) | |
af48b85b | 84 | |
dd6c89b5 CY |
85 | #define MAX_INLINE_XATTR_SIZE \ |
86 | (DEF_ADDRS_PER_INODE - \ | |
87 | F2FS_TOTAL_EXTRA_ATTR_SIZE / sizeof(__le32) - \ | |
88 | DEF_INLINE_RESERVED_SIZE - \ | |
89 | MIN_INLINE_DENTRY_SIZE / sizeof(__le32)) | |
90 | ||
0a8165d7 | 91 | /* |
af48b85b | 92 | * On-disk structure of f2fs_xattr |
65985d93 | 93 | * We use inline xattrs space + 1 block for xattr. |
af48b85b JK |
94 | * |
95 | * +--------------------+ | |
96 | * | f2fs_xattr_header | | |
97 | * | | | |
98 | * +--------------------+ | |
99 | * | f2fs_xattr_entry | | |
100 | * | .e_name_index = 1 | | |
101 | * | .e_name_len = 3 | | |
102 | * | .e_value_size = 14 | | |
103 | * | .e_name = "foo" | | |
104 | * | "value_of_xattr" |<- value_offs = e_name + e_name_len | |
105 | * +--------------------+ | |
106 | * | f2fs_xattr_entry | | |
107 | * | .e_name_index = 4 | | |
108 | * | .e_name = "bar" | | |
109 | * +--------------------+ | |
110 | * | | | |
111 | * | Free | | |
112 | * | | | |
113 | * +--------------------+<- MIN_OFFSET | |
114 | * | node_footer | | |
115 | * | (nid, ino, offset) | | |
116 | * +--------------------+ | |
117 | * | |
118 | **/ | |
119 | ||
120 | #ifdef CONFIG_F2FS_FS_XATTR | |
121 | extern const struct xattr_handler f2fs_xattr_user_handler; | |
122 | extern const struct xattr_handler f2fs_xattr_trusted_handler; | |
af48b85b | 123 | extern const struct xattr_handler f2fs_xattr_advise_handler; |
8ae8f162 | 124 | extern const struct xattr_handler f2fs_xattr_security_handler; |
af48b85b JK |
125 | |
126 | extern const struct xattr_handler *f2fs_xattr_handlers[]; | |
127 | ||
8ae8f162 | 128 | extern int f2fs_setxattr(struct inode *, int, const char *, |
c02745ef | 129 | const void *, size_t, struct page *, int); |
bce8d112 JK |
130 | extern int f2fs_getxattr(struct inode *, int, const char *, void *, |
131 | size_t, struct page *); | |
8ae8f162 | 132 | extern ssize_t f2fs_listxattr(struct dentry *, char *, size_t); |
af48b85b JK |
133 | #else |
134 | ||
135 | #define f2fs_xattr_handlers NULL | |
e1123268 | 136 | static inline int f2fs_setxattr(struct inode *inode, int index, |
fff4c55d AB |
137 | const char *name, const void *value, size_t size, |
138 | struct page *page, int flags) | |
af48b85b JK |
139 | { |
140 | return -EOPNOTSUPP; | |
141 | } | |
e1123268 | 142 | static inline int f2fs_getxattr(struct inode *inode, int index, |
bce8d112 JK |
143 | const char *name, void *buffer, |
144 | size_t buffer_size, struct page *dpage) | |
af48b85b JK |
145 | { |
146 | return -EOPNOTSUPP; | |
147 | } | |
148 | static inline ssize_t f2fs_listxattr(struct dentry *dentry, char *buffer, | |
149 | size_t buffer_size) | |
150 | { | |
151 | return -EOPNOTSUPP; | |
152 | } | |
153 | #endif | |
154 | ||
8ae8f162 JK |
155 | #ifdef CONFIG_F2FS_FS_SECURITY |
156 | extern int f2fs_init_security(struct inode *, struct inode *, | |
157 | const struct qstr *, struct page *); | |
158 | #else | |
159 | static inline int f2fs_init_security(struct inode *inode, struct inode *dir, | |
160 | const struct qstr *qstr, struct page *ipage) | |
161 | { | |
162 | return 0; | |
163 | } | |
164 | #endif | |
af48b85b | 165 | #endif /* __F2FS_XATTR_H__ */ |