blob: 5bac4fe1a1d2b126e7f34fb5276a0be266f65869 [file] [log] [blame]
Huang Jianan024fb2f2022-02-26 15:05:47 +08001/* SPDX-License-Identifier: GPL-2.0-only OR Apache-2.0 */
2/*
3 * EROFS (Enhanced ROM File System) on-disk format definition
4 *
5 * Copyright (C) 2017-2018 HUAWEI, Inc.
Yifan Zhao39ace5c2023-07-07 23:52:12 +08006 * https://www.huawei.com/
Huang Jianan024fb2f2022-02-26 15:05:47 +08007 * Copyright (C) 2021, Alibaba Cloud
8 */
9#ifndef __EROFS_FS_H
10#define __EROFS_FS_H
11
12#include <asm/unaligned.h>
13#include <fs.h>
14#include <part.h>
15#include <stdint.h>
16#include <compiler.h>
17
18#define EROFS_SUPER_MAGIC_V1 0xE0F5E1E2
19#define EROFS_SUPER_OFFSET 1024
20
Yifan Zhao39ace5c2023-07-07 23:52:12 +080021#define EROFS_FEATURE_COMPAT_SB_CHKSUM 0x00000001
22#define EROFS_FEATURE_COMPAT_MTIME 0x00000002
Huang Jianan024fb2f2022-02-26 15:05:47 +080023
24/*
25 * Any bits that aren't in EROFS_ALL_FEATURE_INCOMPAT should
26 * be incompatible with this kernel version.
27 */
Yifan Zhao39ace5c2023-07-07 23:52:12 +080028#define EROFS_FEATURE_INCOMPAT_ZERO_PADDING 0x00000001
Huang Jianan024fb2f2022-02-26 15:05:47 +080029#define EROFS_FEATURE_INCOMPAT_COMPR_CFGS 0x00000002
30#define EROFS_FEATURE_INCOMPAT_BIG_PCLUSTER 0x00000002
31#define EROFS_FEATURE_INCOMPAT_CHUNKED_FILE 0x00000004
32#define EROFS_FEATURE_INCOMPAT_DEVICE_TABLE 0x00000008
Yifan Zhao39ace5c2023-07-07 23:52:12 +080033#define EROFS_FEATURE_INCOMPAT_COMPR_HEAD2 0x00000008
34#define EROFS_FEATURE_INCOMPAT_ZTAILPACKING 0x00000010
35#define EROFS_FEATURE_INCOMPAT_FRAGMENTS 0x00000020
36#define EROFS_FEATURE_INCOMPAT_DEDUPE 0x00000020
37#define EROFS_FEATURE_INCOMPAT_XATTR_PREFIXES 0x00000040
Huang Jianan024fb2f2022-02-26 15:05:47 +080038#define EROFS_ALL_FEATURE_INCOMPAT \
Yifan Zhao39ace5c2023-07-07 23:52:12 +080039 (EROFS_FEATURE_INCOMPAT_ZERO_PADDING | \
Huang Jianan024fb2f2022-02-26 15:05:47 +080040 EROFS_FEATURE_INCOMPAT_COMPR_CFGS | \
41 EROFS_FEATURE_INCOMPAT_BIG_PCLUSTER | \
42 EROFS_FEATURE_INCOMPAT_CHUNKED_FILE | \
Yifan Zhao39ace5c2023-07-07 23:52:12 +080043 EROFS_FEATURE_INCOMPAT_DEVICE_TABLE | \
44 EROFS_FEATURE_INCOMPAT_COMPR_HEAD2 | \
45 EROFS_FEATURE_INCOMPAT_ZTAILPACKING | \
46 EROFS_FEATURE_INCOMPAT_FRAGMENTS | \
47 EROFS_FEATURE_INCOMPAT_DEDUPE | \
48 EROFS_FEATURE_INCOMPAT_XATTR_PREFIXES)
Huang Jianan024fb2f2022-02-26 15:05:47 +080049
50#define EROFS_SB_EXTSLOT_SIZE 16
51
52struct erofs_deviceslot {
Yifan Zhao39ace5c2023-07-07 23:52:12 +080053 u8 tag[64]; /* digest(sha256), etc. */
54 __le32 blocks; /* total fs blocks of this device */
55 __le32 mapped_blkaddr; /* map starting at mapped_blkaddr */
Huang Jianan024fb2f2022-02-26 15:05:47 +080056 u8 reserved[56];
57};
58
59#define EROFS_DEVT_SLOT_SIZE sizeof(struct erofs_deviceslot)
60
61/* erofs on-disk super block (currently 128 bytes) */
62struct erofs_super_block {
63 __le32 magic; /* file system magic number */
64 __le32 checksum; /* crc32c(super_block) */
65 __le32 feature_compat;
Yifan Zhao39ace5c2023-07-07 23:52:12 +080066 __u8 blkszbits; /* filesystem block size in bit shift */
Huang Jianan024fb2f2022-02-26 15:05:47 +080067 __u8 sb_extslots; /* superblock size = 128 + sb_extslots * 16 */
68
69 __le16 root_nid; /* nid of root directory */
70 __le64 inos; /* total valid ino # (== f_files - f_favail) */
71
Yifan Zhao39ace5c2023-07-07 23:52:12 +080072 __le64 build_time; /* compact inode time derivation */
73 __le32 build_time_nsec; /* compact inode time derivation in ns scale */
Huang Jianan024fb2f2022-02-26 15:05:47 +080074 __le32 blocks; /* used for statfs */
75 __le32 meta_blkaddr; /* start block address of metadata area */
76 __le32 xattr_blkaddr; /* start block address of shared xattr area */
77 __u8 uuid[16]; /* 128-bit uuid for volume */
78 __u8 volume_name[16]; /* volume name */
79 __le32 feature_incompat;
80 union {
81 /* bitmap for available compression algorithms */
82 __le16 available_compr_algs;
83 /* customized sliding window size instead of 64k by default */
84 __le16 lz4_max_distance;
85 } __packed u1;
86 __le16 extra_devices; /* # of devices besides the primary device */
87 __le16 devt_slotoff; /* startoff = devt_slotoff * devt_slotsize */
Yifan Zhao39ace5c2023-07-07 23:52:12 +080088 __u8 dirblkbits; /* directory block size in bit shift */
89 __u8 xattr_prefix_count; /* # of long xattr name prefixes */
90 __le32 xattr_prefix_start; /* start of long xattr prefixes */
91 __le64 packed_nid; /* nid of the special packed inode */
92 __u8 reserved2[24];
Huang Jianan024fb2f2022-02-26 15:05:47 +080093};
94
95/*
Yifan Zhao39ace5c2023-07-07 23:52:12 +080096 * EROFS inode datalayout (i_format in on-disk inode):
97 * 0 - uncompressed flat inode without tail-packing inline data:
98 * 1 - compressed inode with non-compact indexes:
99 * 2 - uncompressed flat inode with tail-packing inline data:
100 * 3 - compressed inode with compact indexes:
101 * 4 - chunk-based inode with (optional) multi-device support:
Huang Jianan024fb2f2022-02-26 15:05:47 +0800102 * 5~7 - reserved
103 */
104enum {
105 EROFS_INODE_FLAT_PLAIN = 0,
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800106 EROFS_INODE_COMPRESSED_FULL = 1,
Huang Jianan024fb2f2022-02-26 15:05:47 +0800107 EROFS_INODE_FLAT_INLINE = 2,
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800108 EROFS_INODE_COMPRESSED_COMPACT = 3,
Huang Jianan024fb2f2022-02-26 15:05:47 +0800109 EROFS_INODE_CHUNK_BASED = 4,
110 EROFS_INODE_DATALAYOUT_MAX
111};
112
113static inline bool erofs_inode_is_data_compressed(unsigned int datamode)
114{
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800115 return datamode == EROFS_INODE_COMPRESSED_COMPACT ||
116 datamode == EROFS_INODE_COMPRESSED_FULL;
Huang Jianan024fb2f2022-02-26 15:05:47 +0800117}
118
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800119/* bit definitions of inode i_format */
Huang Jianan024fb2f2022-02-26 15:05:47 +0800120#define EROFS_I_VERSION_BITS 1
121#define EROFS_I_DATALAYOUT_BITS 3
122
123#define EROFS_I_VERSION_BIT 0
124#define EROFS_I_DATALAYOUT_BIT 1
125
126#define EROFS_I_ALL \
127 ((1 << (EROFS_I_DATALAYOUT_BIT + EROFS_I_DATALAYOUT_BITS)) - 1)
128
129/* indicate chunk blkbits, thus 'chunksize = blocksize << chunk blkbits' */
130#define EROFS_CHUNK_FORMAT_BLKBITS_MASK 0x001F
131/* with chunk indexes or just a 4-byte blkaddr array */
132#define EROFS_CHUNK_FORMAT_INDEXES 0x0020
133
134#define EROFS_CHUNK_FORMAT_ALL \
135 (EROFS_CHUNK_FORMAT_BLKBITS_MASK | EROFS_CHUNK_FORMAT_INDEXES)
136
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800137/* 32-byte on-disk inode */
138#define EROFS_INODE_LAYOUT_COMPACT 0
139/* 64-byte on-disk inode */
140#define EROFS_INODE_LAYOUT_EXTENDED 1
141
Huang Jianan024fb2f2022-02-26 15:05:47 +0800142struct erofs_inode_chunk_info {
143 __le16 format; /* chunk blkbits, etc. */
144 __le16 reserved;
145};
146
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800147union erofs_inode_i_u {
148 /* total compressed blocks for compressed inodes */
149 __le32 compressed_blocks;
150
151 /* block address for uncompressed flat inodes */
152 __le32 raw_blkaddr;
153
154 /* for device files, used to indicate old/new device # */
155 __le32 rdev;
156
157 /* for chunk-based files, it contains the summary info */
158 struct erofs_inode_chunk_info c;
159};
160
Huang Jianan024fb2f2022-02-26 15:05:47 +0800161/* 32-byte reduced form of an ondisk inode */
162struct erofs_inode_compact {
163 __le16 i_format; /* inode format hints */
164
165/* 1 header + n-1 * 4 bytes inline xattr to keep continuity */
166 __le16 i_xattr_icount;
167 __le16 i_mode;
168 __le16 i_nlink;
169 __le32 i_size;
170 __le32 i_reserved;
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800171 union erofs_inode_i_u i_u;
Huang Jianan024fb2f2022-02-26 15:05:47 +0800172
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800173 __le32 i_ino; /* only used for 32-bit stat compatibility */
Huang Jianan024fb2f2022-02-26 15:05:47 +0800174 __le16 i_uid;
175 __le16 i_gid;
176 __le32 i_reserved2;
177};
178
Huang Jianan024fb2f2022-02-26 15:05:47 +0800179/* 64-byte complete form of an ondisk inode */
180struct erofs_inode_extended {
181 __le16 i_format; /* inode format hints */
182
183/* 1 header + n-1 * 4 bytes inline xattr to keep continuity */
184 __le16 i_xattr_icount;
185 __le16 i_mode;
186 __le16 i_reserved;
187 __le64 i_size;
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800188 union erofs_inode_i_u i_u;
Huang Jianan024fb2f2022-02-26 15:05:47 +0800189
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800190 __le32 i_ino; /* only used for 32-bit stat compatibility */
Huang Jianan024fb2f2022-02-26 15:05:47 +0800191 __le32 i_uid;
192 __le32 i_gid;
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800193 __le64 i_mtime;
194 __le32 i_mtime_nsec;
Huang Jianan024fb2f2022-02-26 15:05:47 +0800195 __le32 i_nlink;
196 __u8 i_reserved2[16];
197};
198
Huang Jianan024fb2f2022-02-26 15:05:47 +0800199/*
200 * inline xattrs (n == i_xattr_icount):
201 * erofs_xattr_ibody_header(1) + (n - 1) * 4 bytes
202 * 12 bytes / \
203 * / \
204 * /-----------------------\
205 * | erofs_xattr_entries+ |
206 * +-----------------------+
207 * inline xattrs must starts in erofs_xattr_ibody_header,
208 * for read-only fs, no need to introduce h_refcount
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[0]; /* shared xattr id array */
215};
216
217/* Name indexes */
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
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800225/*
226 * bit 7 of e_name_index is set when it refers to a long xattr name prefix,
227 * while the remained lower bits represent the index of the prefix.
228 */
229#define EROFS_XATTR_LONG_PREFIX 0x80
230#define EROFS_XATTR_LONG_PREFIX_MASK 0x7f
231
Huang Jianan024fb2f2022-02-26 15:05:47 +0800232/* xattr entry (for both inline & shared xattrs) */
233struct erofs_xattr_entry {
234 __u8 e_name_len; /* length of name */
235 __u8 e_name_index; /* attribute name index */
236 __le16 e_value_size; /* size of attribute value */
237 /* followed by e_name and e_value */
238 char e_name[0]; /* attribute name */
239};
240
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800241/* long xattr name prefix */
242struct erofs_xattr_long_prefix {
243 __u8 base_index; /* short xattr name prefix index */
244 char infix[0]; /* infix apart from short prefix */
245};
246
Huang Jianan024fb2f2022-02-26 15:05:47 +0800247static inline unsigned int erofs_xattr_ibody_size(__le16 i_xattr_icount)
248{
249 if (!i_xattr_icount)
250 return 0;
251
252 return sizeof(struct erofs_xattr_ibody_header) +
253 sizeof(__u32) * (le16_to_cpu(i_xattr_icount) - 1);
254}
255
256#define EROFS_XATTR_ALIGN(size) round_up(size, sizeof(struct erofs_xattr_entry))
257
258static inline unsigned int erofs_xattr_entry_size(struct erofs_xattr_entry *e)
259{
260 return EROFS_XATTR_ALIGN(sizeof(struct erofs_xattr_entry) +
261 e->e_name_len + le16_to_cpu(e->e_value_size));
262}
263
264/* represent a zeroed chunk (hole) */
265#define EROFS_NULL_ADDR -1
266
267/* 4-byte block address array */
268#define EROFS_BLOCK_MAP_ENTRY_SIZE sizeof(__le32)
269
270/* 8-byte inode chunk indexes */
271struct erofs_inode_chunk_index {
272 __le16 advise; /* always 0, don't care for now */
273 __le16 device_id; /* back-end storage id (with bits masked) */
274 __le32 blkaddr; /* start block address of this inode chunk */
275};
276
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800277/* dirent sorts in alphabet order, thus we can do binary search */
278struct erofs_dirent {
279 __le64 nid; /* node number */
280 __le16 nameoff; /* start offset of file name */
281 __u8 file_type; /* file type */
282 __u8 reserved; /* reserved */
283} __packed;
284
285/* file types used in inode_info->flags */
286enum {
287 EROFS_FT_UNKNOWN,
288 EROFS_FT_REG_FILE,
289 EROFS_FT_DIR,
290 EROFS_FT_CHRDEV,
291 EROFS_FT_BLKDEV,
292 EROFS_FT_FIFO,
293 EROFS_FT_SOCK,
294 EROFS_FT_SYMLINK,
295 EROFS_FT_MAX
296};
297
298#define EROFS_NAME_LEN 255
299
Huang Jianan024fb2f2022-02-26 15:05:47 +0800300/* maximum supported size of a physical compression cluster */
301#define Z_EROFS_PCLUSTER_MAX_SIZE (1024 * 1024)
302
303/* available compression algorithm types (for h_algorithmtype) */
304enum {
305 Z_EROFS_COMPRESSION_LZ4 = 0,
306 Z_EROFS_COMPRESSION_LZMA = 1,
Jianan Huang4f831f22024-04-14 23:04:14 +0800307 Z_EROFS_COMPRESSION_DEFLATE = 2,
Huang Jianan024fb2f2022-02-26 15:05:47 +0800308 Z_EROFS_COMPRESSION_MAX
309};
310
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800311#define Z_EROFS_ALL_COMPR_ALGS ((1 << Z_EROFS_COMPRESSION_MAX) - 1)
Huang Jianan024fb2f2022-02-26 15:05:47 +0800312
313/* 14 bytes (+ length field = 16 bytes) */
314struct z_erofs_lz4_cfgs {
315 __le16 max_distance;
316 __le16 max_pclusterblks;
317 u8 reserved[10];
318} __packed;
319
320/* 14 bytes (+ length field = 16 bytes) */
321struct z_erofs_lzma_cfgs {
322 __le32 dict_size;
323 __le16 format;
324 u8 reserved[8];
325} __packed;
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800326
Huang Jianan024fb2f2022-02-26 15:05:47 +0800327#define Z_EROFS_LZMA_MAX_DICT_SIZE (8 * Z_EROFS_PCLUSTER_MAX_SIZE)
328
329/*
330 * bit 0 : COMPACTED_2B indexes (0 - off; 1 - on)
331 * e.g. for 4k logical cluster size, 4B if compacted 2B is off;
332 * (4B) + 2B + (4B) if compacted 2B is on.
333 * bit 1 : HEAD1 big pcluster (0 - off; 1 - on)
334 * bit 2 : HEAD2 big pcluster (0 - off; 1 - on)
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800335 * bit 3 : tailpacking inline pcluster (0 - off; 1 - on)
336 * bit 4 : interlaced plain pcluster (0 - off; 1 - on)
337 * bit 5 : fragment pcluster (0 - off; 1 - on)
Huang Jianan024fb2f2022-02-26 15:05:47 +0800338 */
339#define Z_EROFS_ADVISE_COMPACTED_2B 0x0001
340#define Z_EROFS_ADVISE_BIG_PCLUSTER_1 0x0002
341#define Z_EROFS_ADVISE_BIG_PCLUSTER_2 0x0004
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800342#define Z_EROFS_ADVISE_INLINE_PCLUSTER 0x0008
343#define Z_EROFS_ADVISE_INTERLACED_PCLUSTER 0x0010
344#define Z_EROFS_ADVISE_FRAGMENT_PCLUSTER 0x0020
Huang Jianan024fb2f2022-02-26 15:05:47 +0800345
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800346#define Z_EROFS_FRAGMENT_INODE_BIT 7
Huang Jianan024fb2f2022-02-26 15:05:47 +0800347struct z_erofs_map_header {
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800348 union {
349 /* fragment data offset in the packed inode */
350 __le32 h_fragmentoff;
351 struct {
352 __le16 h_reserved1;
353 /* indicates the encoded size of tailpacking data */
354 __le16 h_idata_size;
355 };
356 };
Huang Jianan024fb2f2022-02-26 15:05:47 +0800357 __le16 h_advise;
358 /*
359 * bit 0-3 : algorithm type of head 1 (logical cluster type 01);
360 * bit 4-7 : algorithm type of head 2 (logical cluster type 11).
361 */
362 __u8 h_algorithmtype;
363 /*
364 * bit 0-2 : logical cluster bits - 12, e.g. 0 for 4096;
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800365 * bit 3-6 : reserved;
366 * bit 7 : move the whole file into packed inode or not.
Huang Jianan024fb2f2022-02-26 15:05:47 +0800367 */
368 __u8 h_clusterbits;
369};
370
Huang Jianan024fb2f2022-02-26 15:05:47 +0800371/*
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800372 * On-disk logical cluster type:
373 * 0 - literal (uncompressed) lcluster
374 * 1,3 - compressed lcluster (for HEAD lclusters)
375 * 2 - compressed lcluster (for NONHEAD lclusters)
Huang Jianan024fb2f2022-02-26 15:05:47 +0800376 *
377 * In detail,
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800378 * 0 - literal (uncompressed) lcluster,
Huang Jianan024fb2f2022-02-26 15:05:47 +0800379 * di_advise = 0
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800380 * di_clusterofs = the literal data offset of the lcluster
381 * di_blkaddr = the blkaddr of the literal pcluster
Huang Jianan024fb2f2022-02-26 15:05:47 +0800382 *
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800383 * 1,3 - compressed lcluster (for HEAD lclusters)
384 * di_advise = 1 or 3
385 * di_clusterofs = the decompressed data offset of the lcluster
386 * di_blkaddr = the blkaddr of the compressed pcluster
Huang Jianan024fb2f2022-02-26 15:05:47 +0800387 *
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800388 * 2 - compressed lcluster (for NONHEAD lclusters)
Huang Jianan024fb2f2022-02-26 15:05:47 +0800389 * di_advise = 2
390 * di_clusterofs =
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800391 * the decompressed data offset in its own HEAD lcluster
392 * di_u.delta[0] = distance to this HEAD lcluster
393 * di_u.delta[1] = distance to the next HEAD lcluster
Huang Jianan024fb2f2022-02-26 15:05:47 +0800394 */
395enum {
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800396 Z_EROFS_LCLUSTER_TYPE_PLAIN = 0,
397 Z_EROFS_LCLUSTER_TYPE_HEAD1 = 1,
398 Z_EROFS_LCLUSTER_TYPE_NONHEAD = 2,
399 Z_EROFS_LCLUSTER_TYPE_HEAD2 = 3,
400 Z_EROFS_LCLUSTER_TYPE_MAX
Huang Jianan024fb2f2022-02-26 15:05:47 +0800401};
402
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800403#define Z_EROFS_LI_LCLUSTER_TYPE_BITS 2
404#define Z_EROFS_LI_LCLUSTER_TYPE_BIT 0
405
406/* (noncompact only, HEAD) This pcluster refers to partial decompressed data */
407#define Z_EROFS_LI_PARTIAL_REF (1 << 15)
Huang Jianan024fb2f2022-02-26 15:05:47 +0800408
409/*
410 * D0_CBLKCNT will be marked _only_ at the 1st non-head lcluster to store the
411 * compressed block count of a compressed extent (in logical clusters, aka.
412 * block count of a pcluster).
413 */
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800414#define Z_EROFS_LI_D0_CBLKCNT (1 << 11)
Huang Jianan024fb2f2022-02-26 15:05:47 +0800415
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800416struct z_erofs_lcluster_index {
Huang Jianan024fb2f2022-02-26 15:05:47 +0800417 __le16 di_advise;
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800418 /* where to decompress in the head lcluster */
Huang Jianan024fb2f2022-02-26 15:05:47 +0800419 __le16 di_clusterofs;
420
421 union {
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800422 /* for the HEAD lclusters */
Huang Jianan024fb2f2022-02-26 15:05:47 +0800423 __le32 blkaddr;
424 /*
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800425 * for the NONHEAD lclusters
426 * [0] - distance to its HEAD lcluster
427 * [1] - distance to the next HEAD lcluster
Huang Jianan024fb2f2022-02-26 15:05:47 +0800428 */
429 __le16 delta[2];
430 } di_u;
431};
432
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800433#define Z_EROFS_FULL_INDEX_ALIGN(end) \
434 (round_up(end, 8) + sizeof(struct z_erofs_map_header) + 8)
Huang Jianan024fb2f2022-02-26 15:05:47 +0800435
436/* check the EROFS on-disk layout strictly at compile time */
437static inline void erofs_check_ondisk_layout_definitions(void)
438{
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800439 const __le64 fmh __maybe_unused =
440 *(__le64 *)&(struct z_erofs_map_header) {
441 .h_clusterbits = 1 << Z_EROFS_FRAGMENT_INODE_BIT
442 };
443
Huang Jianan024fb2f2022-02-26 15:05:47 +0800444 BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128);
445 BUILD_BUG_ON(sizeof(struct erofs_inode_compact) != 32);
446 BUILD_BUG_ON(sizeof(struct erofs_inode_extended) != 64);
447 BUILD_BUG_ON(sizeof(struct erofs_xattr_ibody_header) != 12);
448 BUILD_BUG_ON(sizeof(struct erofs_xattr_entry) != 4);
449 BUILD_BUG_ON(sizeof(struct erofs_inode_chunk_info) != 4);
450 BUILD_BUG_ON(sizeof(struct erofs_inode_chunk_index) != 8);
451 BUILD_BUG_ON(sizeof(struct z_erofs_map_header) != 8);
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800452 BUILD_BUG_ON(sizeof(struct z_erofs_lcluster_index) != 8);
Huang Jianan024fb2f2022-02-26 15:05:47 +0800453 BUILD_BUG_ON(sizeof(struct erofs_dirent) != 12);
454 /* keep in sync between 2 index structures for better extendibility */
455 BUILD_BUG_ON(sizeof(struct erofs_inode_chunk_index) !=
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800456 sizeof(struct z_erofs_lcluster_index));
Huang Jianan024fb2f2022-02-26 15:05:47 +0800457 BUILD_BUG_ON(sizeof(struct erofs_deviceslot) != 128);
458
Yifan Zhao39ace5c2023-07-07 23:52:12 +0800459 BUILD_BUG_ON(BIT(Z_EROFS_LI_LCLUSTER_TYPE_BITS) <
460 Z_EROFS_LCLUSTER_TYPE_MAX - 1);
461 /* exclude old compiler versions like gcc 7.5.0 */
462 BUILD_BUG_ON(__builtin_constant_p(fmh) ?
463 fmh != cpu_to_le64(1ULL << 63) : 0);
Huang Jianan024fb2f2022-02-26 15:05:47 +0800464}
465
466#endif