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