This source file includes following definitions.
- erofs_inode_is_data_compressed
- erofs_xattr_ibody_size
- erofs_check_ondisk_layout_definitions
1
2
3
4
5
6
7
8
9 #ifndef __EROFS_FS_H
10 #define __EROFS_FS_H
11
12 #define EROFS_SUPER_OFFSET 1024
13
14
15
16
17
18 #define EROFS_FEATURE_INCOMPAT_LZ4_0PADDING 0x00000001
19 #define EROFS_ALL_FEATURE_INCOMPAT EROFS_FEATURE_INCOMPAT_LZ4_0PADDING
20
21
22 struct erofs_super_block {
23 __le32 magic;
24 __le32 checksum;
25 __le32 feature_compat;
26 __u8 blkszbits;
27 __u8 reserved;
28
29 __le16 root_nid;
30 __le64 inos;
31
32 __le64 build_time;
33 __le32 build_time_nsec;
34 __le32 blocks;
35 __le32 meta_blkaddr;
36 __le32 xattr_blkaddr;
37 __u8 uuid[16];
38 __u8 volume_name[16];
39 __le32 feature_incompat;
40
41 __u8 reserved2[44];
42 };
43
44
45
46
47
48
49
50
51
52
53
54
55
56 enum {
57 EROFS_INODE_FLAT_PLAIN = 0,
58 EROFS_INODE_FLAT_COMPRESSION_LEGACY = 1,
59 EROFS_INODE_FLAT_INLINE = 2,
60 EROFS_INODE_FLAT_COMPRESSION = 3,
61 EROFS_INODE_DATALAYOUT_MAX
62 };
63
64 static inline bool erofs_inode_is_data_compressed(unsigned int datamode)
65 {
66 return datamode == EROFS_INODE_FLAT_COMPRESSION ||
67 datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY;
68 }
69
70
71 #define EROFS_I_VERSION_BITS 1
72 #define EROFS_I_DATALAYOUT_BITS 3
73
74 #define EROFS_I_VERSION_BIT 0
75 #define EROFS_I_DATALAYOUT_BIT 1
76
77
78 struct erofs_inode_compact {
79 __le16 i_format;
80
81
82 __le16 i_xattr_icount;
83 __le16 i_mode;
84 __le16 i_nlink;
85 __le32 i_size;
86 __le32 i_reserved;
87 union {
88
89 __le32 compressed_blocks;
90 __le32 raw_blkaddr;
91
92
93 __le32 rdev;
94 } i_u;
95 __le32 i_ino;
96 __le16 i_uid;
97 __le16 i_gid;
98 __le32 i_reserved2;
99 };
100
101
102 #define EROFS_INODE_LAYOUT_COMPACT 0
103
104 #define EROFS_INODE_LAYOUT_EXTENDED 1
105
106
107 struct erofs_inode_extended {
108 __le16 i_format;
109
110
111 __le16 i_xattr_icount;
112 __le16 i_mode;
113 __le16 i_reserved;
114 __le64 i_size;
115 union {
116
117 __le32 compressed_blocks;
118 __le32 raw_blkaddr;
119
120
121 __le32 rdev;
122 } i_u;
123
124
125 __le32 i_ino;
126
127 __le32 i_uid;
128 __le32 i_gid;
129 __le64 i_ctime;
130 __le32 i_ctime_nsec;
131 __le32 i_nlink;
132 __u8 i_reserved2[16];
133 };
134
135 #define EROFS_MAX_SHARED_XATTRS (128)
136
137 #define EROFS_SHARED_XATTR_EXTENT (255)
138
139
140
141
142
143
144
145
146
147
148
149
150 struct erofs_xattr_ibody_header {
151 __le32 h_reserved;
152 __u8 h_shared_count;
153 __u8 h_reserved2[7];
154 __le32 h_shared_xattrs[0];
155 };
156
157
158 #define EROFS_XATTR_INDEX_USER 1
159 #define EROFS_XATTR_INDEX_POSIX_ACL_ACCESS 2
160 #define EROFS_XATTR_INDEX_POSIX_ACL_DEFAULT 3
161 #define EROFS_XATTR_INDEX_TRUSTED 4
162 #define EROFS_XATTR_INDEX_LUSTRE 5
163 #define EROFS_XATTR_INDEX_SECURITY 6
164
165
166 struct erofs_xattr_entry {
167 __u8 e_name_len;
168 __u8 e_name_index;
169 __le16 e_value_size;
170
171 char e_name[0];
172 };
173
174 static inline unsigned int erofs_xattr_ibody_size(__le16 i_xattr_icount)
175 {
176 if (!i_xattr_icount)
177 return 0;
178
179 return sizeof(struct erofs_xattr_ibody_header) +
180 sizeof(__u32) * (le16_to_cpu(i_xattr_icount) - 1);
181 }
182
183 #define EROFS_XATTR_ALIGN(size) round_up(size, sizeof(struct erofs_xattr_entry))
184
185 static inline unsigned int erofs_xattr_entry_size(struct erofs_xattr_entry *e)
186 {
187 return EROFS_XATTR_ALIGN(sizeof(struct erofs_xattr_entry) +
188 e->e_name_len + le16_to_cpu(e->e_value_size));
189 }
190
191
192 enum {
193 Z_EROFS_COMPRESSION_LZ4 = 0,
194 Z_EROFS_COMPRESSION_MAX
195 };
196
197
198
199
200
201
202 #define Z_EROFS_ADVISE_COMPACTED_2B_BIT 0
203
204 #define Z_EROFS_ADVISE_COMPACTED_2B (1 << Z_EROFS_ADVISE_COMPACTED_2B_BIT)
205
206 struct z_erofs_map_header {
207 __le32 h_reserved1;
208 __le16 h_advise;
209
210
211
212
213 __u8 h_algorithmtype;
214
215
216
217
218
219
220 __u8 h_clusterbits;
221 };
222
223 #define Z_EROFS_VLE_LEGACY_HEADER_PADDING 8
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250 enum {
251 Z_EROFS_VLE_CLUSTER_TYPE_PLAIN = 0,
252 Z_EROFS_VLE_CLUSTER_TYPE_HEAD = 1,
253 Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD = 2,
254 Z_EROFS_VLE_CLUSTER_TYPE_RESERVED = 3,
255 Z_EROFS_VLE_CLUSTER_TYPE_MAX
256 };
257
258 #define Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS 2
259 #define Z_EROFS_VLE_DI_CLUSTER_TYPE_BIT 0
260
261 struct z_erofs_vle_decompressed_index {
262 __le16 di_advise;
263
264 __le16 di_clusterofs;
265
266 union {
267
268 __le32 blkaddr;
269
270
271
272
273
274
275 __le16 delta[2];
276 } di_u;
277 };
278
279 #define Z_EROFS_VLE_LEGACY_INDEX_ALIGN(size) \
280 (round_up(size, sizeof(struct z_erofs_vle_decompressed_index)) + \
281 sizeof(struct z_erofs_map_header) + Z_EROFS_VLE_LEGACY_HEADER_PADDING)
282
283
284 struct erofs_dirent {
285 __le64 nid;
286 __le16 nameoff;
287 __u8 file_type;
288 __u8 reserved;
289 } __packed;
290
291
292
293
294
295
296
297 #define EROFS_NAME_LEN 255
298
299
300 static inline void erofs_check_ondisk_layout_definitions(void)
301 {
302 BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128);
303 BUILD_BUG_ON(sizeof(struct erofs_inode_compact) != 32);
304 BUILD_BUG_ON(sizeof(struct erofs_inode_extended) != 64);
305 BUILD_BUG_ON(sizeof(struct erofs_xattr_ibody_header) != 12);
306 BUILD_BUG_ON(sizeof(struct erofs_xattr_entry) != 4);
307 BUILD_BUG_ON(sizeof(struct z_erofs_map_header) != 8);
308 BUILD_BUG_ON(sizeof(struct z_erofs_vle_decompressed_index) != 8);
309 BUILD_BUG_ON(sizeof(struct erofs_dirent) != 12);
310
311 BUILD_BUG_ON(BIT(Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS) <
312 Z_EROFS_VLE_CLUSTER_TYPE_MAX - 1);
313 }
314
315 #endif
316