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#define EROFS_FEATURE_COMPAT_SB_CHKSUM 0x00000001
15
16
17
18
19
20#define EROFS_FEATURE_INCOMPAT_LZ4_0PADDING 0x00000001
21#define EROFS_FEATURE_INCOMPAT_COMPR_CFGS 0x00000002
22#define EROFS_FEATURE_INCOMPAT_BIG_PCLUSTER 0x00000002
23#define EROFS_FEATURE_INCOMPAT_CHUNKED_FILE 0x00000004
24#define EROFS_ALL_FEATURE_INCOMPAT \
25 (EROFS_FEATURE_INCOMPAT_LZ4_0PADDING | \
26 EROFS_FEATURE_INCOMPAT_COMPR_CFGS | \
27 EROFS_FEATURE_INCOMPAT_BIG_PCLUSTER | \
28 EROFS_FEATURE_INCOMPAT_CHUNKED_FILE)
29
30#define EROFS_SB_EXTSLOT_SIZE 16
31
32
33struct erofs_super_block {
34 __le32 magic;
35 __le32 checksum;
36 __le32 feature_compat;
37 __u8 blkszbits;
38 __u8 sb_extslots;
39
40 __le16 root_nid;
41 __le64 inos;
42
43 __le64 build_time;
44 __le32 build_time_nsec;
45 __le32 blocks;
46 __le32 meta_blkaddr;
47 __le32 xattr_blkaddr;
48 __u8 uuid[16];
49 __u8 volume_name[16];
50 __le32 feature_incompat;
51 union {
52
53 __le16 available_compr_algs;
54
55 __le16 lz4_max_distance;
56 } __packed u1;
57 __u8 reserved2[42];
58};
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74enum {
75 EROFS_INODE_FLAT_PLAIN = 0,
76 EROFS_INODE_FLAT_COMPRESSION_LEGACY = 1,
77 EROFS_INODE_FLAT_INLINE = 2,
78 EROFS_INODE_FLAT_COMPRESSION = 3,
79 EROFS_INODE_CHUNK_BASED = 4,
80 EROFS_INODE_DATALAYOUT_MAX
81};
82
83static inline bool erofs_inode_is_data_compressed(unsigned int datamode)
84{
85 return datamode == EROFS_INODE_FLAT_COMPRESSION ||
86 datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY;
87}
88
89
90#define EROFS_I_VERSION_BITS 1
91#define EROFS_I_DATALAYOUT_BITS 3
92
93#define EROFS_I_VERSION_BIT 0
94#define EROFS_I_DATALAYOUT_BIT 1
95
96#define EROFS_I_ALL \
97 ((1 << (EROFS_I_DATALAYOUT_BIT + EROFS_I_DATALAYOUT_BITS)) - 1)
98
99
100#define EROFS_CHUNK_FORMAT_BLKBITS_MASK 0x001F
101
102#define EROFS_CHUNK_FORMAT_INDEXES 0x0020
103
104#define EROFS_CHUNK_FORMAT_ALL \
105 (EROFS_CHUNK_FORMAT_BLKBITS_MASK | EROFS_CHUNK_FORMAT_INDEXES)
106
107struct erofs_inode_chunk_info {
108 __le16 format;
109 __le16 reserved;
110};
111
112
113struct erofs_inode_compact {
114 __le16 i_format;
115
116
117 __le16 i_xattr_icount;
118 __le16 i_mode;
119 __le16 i_nlink;
120 __le32 i_size;
121 __le32 i_reserved;
122 union {
123
124 __le32 compressed_blocks;
125 __le32 raw_blkaddr;
126
127
128 __le32 rdev;
129
130
131 struct erofs_inode_chunk_info c;
132 } i_u;
133 __le32 i_ino;
134 __le16 i_uid;
135 __le16 i_gid;
136 __le32 i_reserved2;
137};
138
139
140#define EROFS_INODE_LAYOUT_COMPACT 0
141
142#define EROFS_INODE_LAYOUT_EXTENDED 1
143
144
145struct erofs_inode_extended {
146 __le16 i_format;
147
148
149 __le16 i_xattr_icount;
150 __le16 i_mode;
151 __le16 i_reserved;
152 __le64 i_size;
153 union {
154
155 __le32 compressed_blocks;
156 __le32 raw_blkaddr;
157
158
159 __le32 rdev;
160
161
162 struct erofs_inode_chunk_info c;
163 } i_u;
164
165
166 __le32 i_ino;
167
168 __le32 i_uid;
169 __le32 i_gid;
170 __le64 i_ctime;
171 __le32 i_ctime_nsec;
172 __le32 i_nlink;
173 __u8 i_reserved2[16];
174};
175
176#define EROFS_MAX_SHARED_XATTRS (128)
177
178#define EROFS_SHARED_XATTR_EXTENT (255)
179
180
181
182
183
184
185
186
187
188
189
190
191struct erofs_xattr_ibody_header {
192 __le32 h_reserved;
193 __u8 h_shared_count;
194 __u8 h_reserved2[7];
195 __le32 h_shared_xattrs[0];
196};
197
198
199#define EROFS_XATTR_INDEX_USER 1
200#define EROFS_XATTR_INDEX_POSIX_ACL_ACCESS 2
201#define EROFS_XATTR_INDEX_POSIX_ACL_DEFAULT 3
202#define EROFS_XATTR_INDEX_TRUSTED 4
203#define EROFS_XATTR_INDEX_LUSTRE 5
204#define EROFS_XATTR_INDEX_SECURITY 6
205
206
207struct erofs_xattr_entry {
208 __u8 e_name_len;
209 __u8 e_name_index;
210 __le16 e_value_size;
211
212 char e_name[0];
213};
214
215static inline unsigned int erofs_xattr_ibody_size(__le16 i_xattr_icount)
216{
217 if (!i_xattr_icount)
218 return 0;
219
220 return sizeof(struct erofs_xattr_ibody_header) +
221 sizeof(__u32) * (le16_to_cpu(i_xattr_icount) - 1);
222}
223
224#define EROFS_XATTR_ALIGN(size) round_up(size, sizeof(struct erofs_xattr_entry))
225
226static inline unsigned int erofs_xattr_entry_size(struct erofs_xattr_entry *e)
227{
228 return EROFS_XATTR_ALIGN(sizeof(struct erofs_xattr_entry) +
229 e->e_name_len + le16_to_cpu(e->e_value_size));
230}
231
232
233#define EROFS_NULL_ADDR -1
234
235
236#define EROFS_BLOCK_MAP_ENTRY_SIZE sizeof(__le32)
237
238
239struct erofs_inode_chunk_index {
240 __le16 advise;
241 __le16 device_id;
242 __le32 blkaddr;
243};
244
245
246#define Z_EROFS_PCLUSTER_MAX_SIZE (1024 * 1024)
247
248
249enum {
250 Z_EROFS_COMPRESSION_LZ4 = 0,
251 Z_EROFS_COMPRESSION_MAX
252};
253#define Z_EROFS_ALL_COMPR_ALGS (1 << (Z_EROFS_COMPRESSION_MAX - 1))
254
255
256struct z_erofs_lz4_cfgs {
257 __le16 max_distance;
258 __le16 max_pclusterblks;
259 u8 reserved[10];
260} __packed;
261
262
263
264
265
266
267
268
269#define Z_EROFS_ADVISE_COMPACTED_2B 0x0001
270#define Z_EROFS_ADVISE_BIG_PCLUSTER_1 0x0002
271#define Z_EROFS_ADVISE_BIG_PCLUSTER_2 0x0004
272
273struct z_erofs_map_header {
274 __le32 h_reserved1;
275 __le16 h_advise;
276
277
278
279
280 __u8 h_algorithmtype;
281
282
283
284
285 __u8 h_clusterbits;
286};
287
288#define Z_EROFS_VLE_LEGACY_HEADER_PADDING 8
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315enum {
316 Z_EROFS_VLE_CLUSTER_TYPE_PLAIN = 0,
317 Z_EROFS_VLE_CLUSTER_TYPE_HEAD = 1,
318 Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD = 2,
319 Z_EROFS_VLE_CLUSTER_TYPE_RESERVED = 3,
320 Z_EROFS_VLE_CLUSTER_TYPE_MAX
321};
322
323#define Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS 2
324#define Z_EROFS_VLE_DI_CLUSTER_TYPE_BIT 0
325
326
327
328
329
330
331#define Z_EROFS_VLE_DI_D0_CBLKCNT (1 << 11)
332
333struct z_erofs_vle_decompressed_index {
334 __le16 di_advise;
335
336 __le16 di_clusterofs;
337
338 union {
339
340 __le32 blkaddr;
341
342
343
344
345
346
347 __le16 delta[2];
348 } di_u;
349};
350
351#define Z_EROFS_VLE_LEGACY_INDEX_ALIGN(size) \
352 (round_up(size, sizeof(struct z_erofs_vle_decompressed_index)) + \
353 sizeof(struct z_erofs_map_header) + Z_EROFS_VLE_LEGACY_HEADER_PADDING)
354
355
356struct erofs_dirent {
357 __le64 nid;
358 __le16 nameoff;
359 __u8 file_type;
360 __u8 reserved;
361} __packed;
362
363
364
365
366
367
368
369#define EROFS_NAME_LEN 255
370
371
372static inline void erofs_check_ondisk_layout_definitions(void)
373{
374 BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128);
375 BUILD_BUG_ON(sizeof(struct erofs_inode_compact) != 32);
376 BUILD_BUG_ON(sizeof(struct erofs_inode_extended) != 64);
377 BUILD_BUG_ON(sizeof(struct erofs_xattr_ibody_header) != 12);
378 BUILD_BUG_ON(sizeof(struct erofs_xattr_entry) != 4);
379 BUILD_BUG_ON(sizeof(struct erofs_inode_chunk_info) != 4);
380 BUILD_BUG_ON(sizeof(struct erofs_inode_chunk_index) != 8);
381 BUILD_BUG_ON(sizeof(struct z_erofs_map_header) != 8);
382 BUILD_BUG_ON(sizeof(struct z_erofs_vle_decompressed_index) != 8);
383 BUILD_BUG_ON(sizeof(struct erofs_dirent) != 12);
384
385 BUILD_BUG_ON(sizeof(struct erofs_inode_chunk_index) !=
386 sizeof(struct z_erofs_vle_decompressed_index));
387
388 BUILD_BUG_ON(BIT(Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS) <
389 Z_EROFS_VLE_CLUSTER_TYPE_MAX - 1);
390}
391
392#endif
393