Gao Xiang | 29b24f6 | 2019-07-31 23:57:31 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only OR Apache-2.0 */ |
| 2 | /* |
Gao Xiang | ea559e7 | 2019-09-04 10:08:57 +0800 | [diff] [blame] | 3 | * EROFS (Enhanced ROM File System) on-disk format definition |
| 4 | * |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 5 | * Copyright (C) 2017-2018 HUAWEI, Inc. |
Alexander A. Klimov | 592e7cd | 2020-07-13 15:09:44 +0200 | [diff] [blame] | 6 | * https://www.huawei.com/ |
Gao Xiang | 2a9dc7a | 2021-08-20 18:00:18 +0800 | [diff] [blame] | 7 | * Copyright (C) 2021, Alibaba Cloud |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 8 | */ |
| 9 | #ifndef __EROFS_FS_H |
| 10 | #define __EROFS_FS_H |
| 11 | |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 12 | #define EROFS_SUPER_OFFSET 1024 |
| 13 | |
Pratik Shinde | b858a48 | 2019-11-04 10:49:37 +0800 | [diff] [blame] | 14 | #define EROFS_FEATURE_COMPAT_SB_CHKSUM 0x00000001 |
| 15 | |
Gao Xiang | 5efe513 | 2019-06-13 16:35:41 +0800 | [diff] [blame] | 16 | /* |
Gao Xiang | 426a930 | 2019-09-04 10:08:53 +0800 | [diff] [blame] | 17 | * Any bits that aren't in EROFS_ALL_FEATURE_INCOMPAT should |
| 18 | * be incompatible with this kernel version. |
Gao Xiang | 5efe513 | 2019-06-13 16:35:41 +0800 | [diff] [blame] | 19 | */ |
Huang Jianan | 7e508f2 | 2021-11-13 00:09:33 +0800 | [diff] [blame] | 20 | #define EROFS_FEATURE_INCOMPAT_ZERO_PADDING 0x00000001 |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 21 | #define EROFS_FEATURE_INCOMPAT_COMPR_CFGS 0x00000002 |
Gao Xiang | 5404c3301 | 2021-04-07 12:39:22 +0800 | [diff] [blame] | 22 | #define EROFS_FEATURE_INCOMPAT_BIG_PCLUSTER 0x00000002 |
Gao Xiang | 2a9dc7a | 2021-08-20 18:00:18 +0800 | [diff] [blame] | 23 | #define EROFS_FEATURE_INCOMPAT_CHUNKED_FILE 0x00000004 |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 24 | #define EROFS_FEATURE_INCOMPAT_DEVICE_TABLE 0x00000008 |
Gao Xiang | 72bb526 | 2021-10-18 00:57:21 +0800 | [diff] [blame] | 25 | #define EROFS_FEATURE_INCOMPAT_COMPR_HEAD2 0x00000008 |
Yue Hu | ab92184 | 2021-12-28 13:46:04 +0800 | [diff] [blame] | 26 | #define EROFS_FEATURE_INCOMPAT_ZTAILPACKING 0x00000010 |
Gao Xiang | 8e6c8fa | 2021-04-07 12:39:27 +0800 | [diff] [blame] | 27 | #define EROFS_ALL_FEATURE_INCOMPAT \ |
Huang Jianan | 7e508f2 | 2021-11-13 00:09:33 +0800 | [diff] [blame] | 28 | (EROFS_FEATURE_INCOMPAT_ZERO_PADDING | \ |
Gao Xiang | 8e6c8fa | 2021-04-07 12:39:27 +0800 | [diff] [blame] | 29 | EROFS_FEATURE_INCOMPAT_COMPR_CFGS | \ |
Gao Xiang | 2a9dc7a | 2021-08-20 18:00:18 +0800 | [diff] [blame] | 30 | EROFS_FEATURE_INCOMPAT_BIG_PCLUSTER | \ |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 31 | EROFS_FEATURE_INCOMPAT_CHUNKED_FILE | \ |
Gao Xiang | 72bb526 | 2021-10-18 00:57:21 +0800 | [diff] [blame] | 32 | EROFS_FEATURE_INCOMPAT_DEVICE_TABLE | \ |
Yue Hu | ab92184 | 2021-12-28 13:46:04 +0800 | [diff] [blame] | 33 | EROFS_FEATURE_INCOMPAT_COMPR_HEAD2 | \ |
| 34 | EROFS_FEATURE_INCOMPAT_ZTAILPACKING) |
Gao Xiang | 5efe513 | 2019-06-13 16:35:41 +0800 | [diff] [blame] | 35 | |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 36 | #define EROFS_SB_EXTSLOT_SIZE 16 |
| 37 | |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 38 | struct erofs_deviceslot { |
| 39 | union { |
| 40 | u8 uuid[16]; /* used for device manager later */ |
| 41 | u8 userdata[64]; /* digest(sha256), etc. */ |
| 42 | } u; |
| 43 | __le32 blocks; /* total fs blocks of this device */ |
| 44 | __le32 mapped_blkaddr; /* map starting at mapped_blkaddr */ |
| 45 | u8 reserved[56]; |
| 46 | }; |
| 47 | #define EROFS_DEVT_SLOT_SIZE sizeof(struct erofs_deviceslot) |
| 48 | |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 49 | /* erofs on-disk super block (currently 128 bytes) */ |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 50 | struct erofs_super_block { |
Gao Xiang | 4b66eb5 | 2019-09-04 10:08:48 +0800 | [diff] [blame] | 51 | __le32 magic; /* file system magic number */ |
| 52 | __le32 checksum; /* crc32c(super_block) */ |
Gao Xiang | 426a930 | 2019-09-04 10:08:53 +0800 | [diff] [blame] | 53 | __le32 feature_compat; |
Gao Xiang | 4b66eb5 | 2019-09-04 10:08:48 +0800 | [diff] [blame] | 54 | __u8 blkszbits; /* support block_size == PAGE_SIZE only */ |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 55 | __u8 sb_extslots; /* superblock size = 128 + sb_extslots * 16 */ |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 56 | |
Gao Xiang | 4b66eb5 | 2019-09-04 10:08:48 +0800 | [diff] [blame] | 57 | __le16 root_nid; /* nid of root directory */ |
| 58 | __le64 inos; /* total valid ino # (== f_files - f_favail) */ |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 59 | |
Gao Xiang | 4b66eb5 | 2019-09-04 10:08:48 +0800 | [diff] [blame] | 60 | __le64 build_time; /* inode v1 time derivation */ |
| 61 | __le32 build_time_nsec; /* inode v1 time derivation in nano scale */ |
| 62 | __le32 blocks; /* used for statfs */ |
| 63 | __le32 meta_blkaddr; /* start block address of metadata area */ |
| 64 | __le32 xattr_blkaddr; /* start block address of shared xattr area */ |
| 65 | __u8 uuid[16]; /* 128-bit uuid for volume */ |
| 66 | __u8 volume_name[16]; /* volume name */ |
Gao Xiang | 426a930 | 2019-09-04 10:08:53 +0800 | [diff] [blame] | 67 | __le32 feature_incompat; |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 68 | union { |
| 69 | /* bitmap for available compression algorithms */ |
| 70 | __le16 available_compr_algs; |
| 71 | /* customized sliding window size instead of 64k by default */ |
| 72 | __le16 lz4_max_distance; |
| 73 | } __packed u1; |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 74 | __le16 extra_devices; /* # of devices besides the primary device */ |
| 75 | __le16 devt_slotoff; /* startoff = devt_slotoff * devt_slotsize */ |
| 76 | __u8 reserved2[38]; |
Gao Xiang | ed34aa4 | 2019-09-04 10:08:51 +0800 | [diff] [blame] | 77 | }; |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 78 | |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 79 | /* |
Gao Xiang | ea559e7 | 2019-09-04 10:08:57 +0800 | [diff] [blame] | 80 | * erofs inode datalayout (i_format in on-disk inode): |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 81 | * 0 - inode plain without inline data A: |
| 82 | * inode, [xattrs], ... | ... | no-holed data |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 83 | * 1 - inode VLE compression B (legacy): |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 84 | * inode, [xattrs], extents ... | ... |
| 85 | * 2 - inode plain with inline data C: |
| 86 | * inode, [xattrs], last_inline_data, ... | ... | no-holed data |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 87 | * 3 - inode compression D: |
| 88 | * inode, [xattrs], map_header, extents ... | ... |
Gao Xiang | 2a9dc7a | 2021-08-20 18:00:18 +0800 | [diff] [blame] | 89 | * 4 - inode chunk-based E: |
| 90 | * inode, [xattrs], chunk indexes ... | ... |
| 91 | * 5~7 - reserved |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 92 | */ |
| 93 | enum { |
Gao Xiang | 60a49ba | 2019-09-04 10:08:49 +0800 | [diff] [blame] | 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, |
Gao Xiang | 2a9dc7a | 2021-08-20 18:00:18 +0800 | [diff] [blame] | 98 | EROFS_INODE_CHUNK_BASED = 4, |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 99 | EROFS_INODE_DATALAYOUT_MAX |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 100 | }; |
Gao Xiang | ccd9c19 | 2018-12-12 01:57:30 +0800 | [diff] [blame] | 101 | |
Gao Xiang | 3d2969f | 2019-08-13 10:30:52 +0800 | [diff] [blame] | 102 | static inline bool erofs_inode_is_data_compressed(unsigned int datamode) |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 103 | { |
Gao Xiang | c39747f | 2019-09-04 10:08:52 +0800 | [diff] [blame] | 104 | return datamode == EROFS_INODE_FLAT_COMPRESSION || |
| 105 | datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY; |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 106 | } |
| 107 | |
Gao Xiang | ccd9c19 | 2018-12-12 01:57:30 +0800 | [diff] [blame] | 108 | /* bit definitions of inode i_advise */ |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 109 | #define EROFS_I_VERSION_BITS 1 |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 110 | #define EROFS_I_DATALAYOUT_BITS 3 |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 111 | |
| 112 | #define EROFS_I_VERSION_BIT 0 |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 113 | #define EROFS_I_DATALAYOUT_BIT 1 |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 114 | |
Gao Xiang | 24a806d | 2021-03-29 08:36:14 +0800 | [diff] [blame] | 115 | #define EROFS_I_ALL \ |
| 116 | ((1 << (EROFS_I_DATALAYOUT_BIT + EROFS_I_DATALAYOUT_BITS)) - 1) |
| 117 | |
Gao Xiang | 2a9dc7a | 2021-08-20 18:00:18 +0800 | [diff] [blame] | 118 | /* indicate chunk blkbits, thus 'chunksize = blocksize << chunk blkbits' */ |
| 119 | #define EROFS_CHUNK_FORMAT_BLKBITS_MASK 0x001F |
| 120 | /* with chunk indexes or just a 4-byte blkaddr array */ |
| 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 | |
| 126 | struct erofs_inode_chunk_info { |
| 127 | __le16 format; /* chunk blkbits, etc. */ |
| 128 | __le16 reserved; |
| 129 | }; |
| 130 | |
Gao Xiang | 4b66eb5 | 2019-09-04 10:08:48 +0800 | [diff] [blame] | 131 | /* 32-byte reduced form of an ondisk inode */ |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 132 | struct erofs_inode_compact { |
| 133 | __le16 i_format; /* inode format hints */ |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 134 | |
| 135 | /* 1 header + n-1 * 4 bytes inline xattr to keep continuity */ |
Gao Xiang | 4b66eb5 | 2019-09-04 10:08:48 +0800 | [diff] [blame] | 136 | __le16 i_xattr_icount; |
| 137 | __le16 i_mode; |
| 138 | __le16 i_nlink; |
| 139 | __le32 i_size; |
| 140 | __le32 i_reserved; |
| 141 | union { |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 142 | /* file total compressed blocks for data mapping 1 */ |
| 143 | __le32 compressed_blocks; |
| 144 | __le32 raw_blkaddr; |
| 145 | |
| 146 | /* for device files, used to indicate old/new device # */ |
| 147 | __le32 rdev; |
Gao Xiang | 2a9dc7a | 2021-08-20 18:00:18 +0800 | [diff] [blame] | 148 | |
| 149 | /* for chunk-based files, it contains the summary info */ |
| 150 | struct erofs_inode_chunk_info c; |
Gao Xiang | ed34aa4 | 2019-09-04 10:08:51 +0800 | [diff] [blame] | 151 | } i_u; |
Gao Xiang | 4b66eb5 | 2019-09-04 10:08:48 +0800 | [diff] [blame] | 152 | __le32 i_ino; /* only used for 32-bit stat compatibility */ |
| 153 | __le16 i_uid; |
| 154 | __le16 i_gid; |
| 155 | __le32 i_reserved2; |
Gao Xiang | ed34aa4 | 2019-09-04 10:08:51 +0800 | [diff] [blame] | 156 | }; |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 157 | |
| 158 | /* 32 bytes on-disk inode */ |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 159 | #define EROFS_INODE_LAYOUT_COMPACT 0 |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 160 | /* 64 bytes on-disk inode */ |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 161 | #define EROFS_INODE_LAYOUT_EXTENDED 1 |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 162 | |
Gao Xiang | 4b66eb5 | 2019-09-04 10:08:48 +0800 | [diff] [blame] | 163 | /* 64-byte complete form of an ondisk inode */ |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 164 | struct erofs_inode_extended { |
| 165 | __le16 i_format; /* inode format hints */ |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 166 | |
Gao Xiang | cead56f | 2019-07-31 23:57:34 +0800 | [diff] [blame] | 167 | /* 1 header + n-1 * 4 bytes inline xattr to keep continuity */ |
Gao Xiang | 4b66eb5 | 2019-09-04 10:08:48 +0800 | [diff] [blame] | 168 | __le16 i_xattr_icount; |
| 169 | __le16 i_mode; |
| 170 | __le16 i_reserved; |
| 171 | __le64 i_size; |
| 172 | union { |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 173 | /* file total compressed blocks for data mapping 1 */ |
| 174 | __le32 compressed_blocks; |
| 175 | __le32 raw_blkaddr; |
| 176 | |
| 177 | /* for device files, used to indicate old/new device # */ |
| 178 | __le32 rdev; |
Gao Xiang | 2a9dc7a | 2021-08-20 18:00:18 +0800 | [diff] [blame] | 179 | |
| 180 | /* for chunk-based files, it contains the summary info */ |
| 181 | struct erofs_inode_chunk_info c; |
Gao Xiang | ed34aa4 | 2019-09-04 10:08:51 +0800 | [diff] [blame] | 182 | } i_u; |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 183 | |
| 184 | /* only used for 32-bit stat compatibility */ |
Gao Xiang | 4b66eb5 | 2019-09-04 10:08:48 +0800 | [diff] [blame] | 185 | __le32 i_ino; |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 186 | |
Gao Xiang | 4b66eb5 | 2019-09-04 10:08:48 +0800 | [diff] [blame] | 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]; |
Gao Xiang | ed34aa4 | 2019-09-04 10:08:51 +0800 | [diff] [blame] | 193 | }; |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 194 | |
| 195 | #define EROFS_MAX_SHARED_XATTRS (128) |
| 196 | /* h_shared_count between 129 ... 255 are special # */ |
| 197 | #define EROFS_SHARED_XATTR_EXTENT (255) |
| 198 | |
| 199 | /* |
| 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 | */ |
| 210 | struct erofs_xattr_ibody_header { |
Gao Xiang | cead56f | 2019-07-31 23:57:34 +0800 | [diff] [blame] | 211 | __le32 h_reserved; |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 212 | __u8 h_shared_count; |
Gao Xiang | cead56f | 2019-07-31 23:57:34 +0800 | [diff] [blame] | 213 | __u8 h_reserved2[7]; |
Gao Xiang | 7acc3d1 | 2021-12-06 20:17:02 +0800 | [diff] [blame] | 214 | __le32 h_shared_xattrs[]; /* shared xattr id array */ |
Gao Xiang | ed34aa4 | 2019-09-04 10:08:51 +0800 | [diff] [blame] | 215 | }; |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 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 | |
| 225 | /* xattr entry (for both inline & shared xattrs) */ |
| 226 | struct erofs_xattr_entry { |
| 227 | __u8 e_name_len; /* length of name */ |
| 228 | __u8 e_name_index; /* attribute name index */ |
| 229 | __le16 e_value_size; /* size of attribute value */ |
| 230 | /* followed by e_name and e_value */ |
Gao Xiang | 7acc3d1 | 2021-12-06 20:17:02 +0800 | [diff] [blame] | 231 | char e_name[]; /* attribute name */ |
Gao Xiang | ed34aa4 | 2019-09-04 10:08:51 +0800 | [diff] [blame] | 232 | }; |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 233 | |
Gao Xiang | b6796ab | 2019-09-04 10:08:50 +0800 | [diff] [blame] | 234 | static 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 | } |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 242 | |
| 243 | #define EROFS_XATTR_ALIGN(size) round_up(size, sizeof(struct erofs_xattr_entry)) |
Gao Xiang | b6796ab | 2019-09-04 10:08:50 +0800 | [diff] [blame] | 244 | |
| 245 | static 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 | } |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 250 | |
Gao Xiang | 2a9dc7a | 2021-08-20 18:00:18 +0800 | [diff] [blame] | 251 | /* represent a zeroed chunk (hole) */ |
| 252 | #define EROFS_NULL_ADDR -1 |
| 253 | |
| 254 | /* 4-byte block address array */ |
| 255 | #define EROFS_BLOCK_MAP_ENTRY_SIZE sizeof(__le32) |
| 256 | |
| 257 | /* 8-byte inode chunk indexes */ |
| 258 | struct erofs_inode_chunk_index { |
| 259 | __le16 advise; /* always 0, don't care for now */ |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 260 | __le16 device_id; /* back-end storage id (with bits masked) */ |
Gao Xiang | 2a9dc7a | 2021-08-20 18:00:18 +0800 | [diff] [blame] | 261 | __le32 blkaddr; /* start block address of this inode chunk */ |
| 262 | }; |
| 263 | |
Gao Xiang | 9f6cc76 | 2021-04-07 12:39:20 +0800 | [diff] [blame] | 264 | /* maximum supported size of a physical compression cluster */ |
| 265 | #define Z_EROFS_PCLUSTER_MAX_SIZE (1024 * 1024) |
| 266 | |
Gao Xiang | ea559e7 | 2019-09-04 10:08:57 +0800 | [diff] [blame] | 267 | /* available compression algorithm types (for h_algorithmtype) */ |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 268 | enum { |
Gao Xiang | 622cead | 2021-10-11 05:31:45 +0800 | [diff] [blame] | 269 | Z_EROFS_COMPRESSION_LZ4 = 0, |
| 270 | Z_EROFS_COMPRESSION_LZMA = 1, |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 271 | Z_EROFS_COMPRESSION_MAX |
| 272 | }; |
Gao Xiang | 622cead | 2021-10-11 05:31:45 +0800 | [diff] [blame] | 273 | #define Z_EROFS_ALL_COMPR_ALGS ((1 << Z_EROFS_COMPRESSION_MAX) - 1) |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 274 | |
Gao Xiang | 46249cd | 2021-03-29 09:23:07 +0800 | [diff] [blame] | 275 | /* 14 bytes (+ length field = 16 bytes) */ |
| 276 | struct z_erofs_lz4_cfgs { |
| 277 | __le16 max_distance; |
Gao Xiang | 5404c3301 | 2021-04-07 12:39:22 +0800 | [diff] [blame] | 278 | __le16 max_pclusterblks; |
| 279 | u8 reserved[10]; |
Gao Xiang | 46249cd | 2021-03-29 09:23:07 +0800 | [diff] [blame] | 280 | } __packed; |
| 281 | |
Gao Xiang | 622cead | 2021-10-11 05:31:45 +0800 | [diff] [blame] | 282 | /* 14 bytes (+ length field = 16 bytes) */ |
| 283 | struct 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 | |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 291 | /* |
| 292 | * bit 0 : COMPACTED_2B indexes (0 - off; 1 - on) |
| 293 | * e.g. for 4k logical cluster size, 4B if compacted 2B is off; |
| 294 | * (4B) + 2B + (4B) if compacted 2B is on. |
Gao Xiang | 5404c3301 | 2021-04-07 12:39:22 +0800 | [diff] [blame] | 295 | * bit 1 : HEAD1 big pcluster (0 - off; 1 - on) |
| 296 | * bit 2 : HEAD2 big pcluster (0 - off; 1 - on) |
Yue Hu | ab92184 | 2021-12-28 13:46:04 +0800 | [diff] [blame] | 297 | * bit 3 : tailpacking inline pcluster (0 - off; 1 - on) |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 298 | */ |
Gao Xiang | 5404c3301 | 2021-04-07 12:39:22 +0800 | [diff] [blame] | 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 |
Yue Hu | ab92184 | 2021-12-28 13:46:04 +0800 | [diff] [blame] | 302 | #define Z_EROFS_ADVISE_INLINE_PCLUSTER 0x0008 |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 303 | |
| 304 | struct z_erofs_map_header { |
Yue Hu | ab92184 | 2021-12-28 13:46:04 +0800 | [diff] [blame] | 305 | __le16 h_reserved1; |
| 306 | /* indicates the encoded size of tailpacking data */ |
| 307 | __le16 h_idata_size; |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 308 | __le16 h_advise; |
| 309 | /* |
| 310 | * bit 0-3 : algorithm type of head 1 (logical cluster type 01); |
| 311 | * bit 4-7 : algorithm type of head 2 (logical cluster type 11). |
| 312 | */ |
| 313 | __u8 h_algorithmtype; |
| 314 | /* |
| 315 | * bit 0-2 : logical cluster bits - 12, e.g. 0 for 4096; |
Gao Xiang | 54e0b6c | 2021-04-07 12:39:18 +0800 | [diff] [blame] | 316 | * bit 3-7 : reserved. |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 317 | */ |
| 318 | __u8 h_clusterbits; |
| 319 | }; |
| 320 | |
| 321 | #define Z_EROFS_VLE_LEGACY_HEADER_PADDING 8 |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 322 | |
| 323 | /* |
Gao Xiang | 72bb526 | 2021-10-18 00:57:21 +0800 | [diff] [blame] | 324 | * Fixed-sized output compression on-disk logical cluster type: |
| 325 | * 0 - literal (uncompressed) lcluster |
| 326 | * 1,3 - compressed lcluster (for HEAD lclusters) |
| 327 | * 2 - compressed lcluster (for NONHEAD lclusters) |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 328 | * |
| 329 | * In detail, |
Gao Xiang | 72bb526 | 2021-10-18 00:57:21 +0800 | [diff] [blame] | 330 | * 0 - literal (uncompressed) lcluster, |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 331 | * di_advise = 0 |
Gao Xiang | 72bb526 | 2021-10-18 00:57:21 +0800 | [diff] [blame] | 332 | * di_clusterofs = the literal data offset of the lcluster |
| 333 | * di_blkaddr = the blkaddr of the literal pcluster |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 334 | * |
Gao Xiang | 72bb526 | 2021-10-18 00:57:21 +0800 | [diff] [blame] | 335 | * 1,3 - compressed lcluster (for HEAD lclusters) |
| 336 | * di_advise = 1 or 3 |
| 337 | * di_clusterofs = the decompressed data offset of the lcluster |
| 338 | * di_blkaddr = the blkaddr of the compressed pcluster |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 339 | * |
Gao Xiang | 72bb526 | 2021-10-18 00:57:21 +0800 | [diff] [blame] | 340 | * 2 - compressed lcluster (for NONHEAD lclusters) |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 341 | * di_advise = 2 |
| 342 | * di_clusterofs = |
Gao Xiang | 72bb526 | 2021-10-18 00:57:21 +0800 | [diff] [blame] | 343 | * the decompressed data offset in its own HEAD lcluster |
| 344 | * di_u.delta[0] = distance to this HEAD lcluster |
| 345 | * di_u.delta[1] = distance to the next HEAD lcluster |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 346 | */ |
Gao Xiang | 99691b4 | 2018-08-21 22:49:33 +0800 | [diff] [blame] | 347 | enum { |
Gao Xiang | 60a49ba | 2019-09-04 10:08:49 +0800 | [diff] [blame] | 348 | Z_EROFS_VLE_CLUSTER_TYPE_PLAIN = 0, |
Gao Xiang | 72bb526 | 2021-10-18 00:57:21 +0800 | [diff] [blame] | 349 | Z_EROFS_VLE_CLUSTER_TYPE_HEAD1 = 1, |
Gao Xiang | 60a49ba | 2019-09-04 10:08:49 +0800 | [diff] [blame] | 350 | Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD = 2, |
Gao Xiang | 72bb526 | 2021-10-18 00:57:21 +0800 | [diff] [blame] | 351 | Z_EROFS_VLE_CLUSTER_TYPE_HEAD2 = 3, |
Gao Xiang | 99691b4 | 2018-08-21 22:49:33 +0800 | [diff] [blame] | 352 | Z_EROFS_VLE_CLUSTER_TYPE_MAX |
| 353 | }; |
| 354 | |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 355 | #define Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS 2 |
| 356 | #define Z_EROFS_VLE_DI_CLUSTER_TYPE_BIT 0 |
| 357 | |
Gao Xiang | 5404c3301 | 2021-04-07 12:39:22 +0800 | [diff] [blame] | 358 | /* |
| 359 | * D0_CBLKCNT will be marked _only_ at the 1st non-head lcluster to store the |
| 360 | * compressed block count of a compressed extent (in logical clusters, aka. |
| 361 | * block count of a pcluster). |
| 362 | */ |
| 363 | #define Z_EROFS_VLE_DI_D0_CBLKCNT (1 << 11) |
| 364 | |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 365 | struct z_erofs_vle_decompressed_index { |
| 366 | __le16 di_advise; |
| 367 | /* where to decompress in the head cluster */ |
| 368 | __le16 di_clusterofs; |
| 369 | |
| 370 | union { |
| 371 | /* for the head cluster */ |
| 372 | __le32 blkaddr; |
| 373 | /* |
| 374 | * for the rest clusters |
| 375 | * eg. for 4k page-sized cluster, maximum 4K*64k = 256M) |
| 376 | * [0] - pointing to the head cluster |
| 377 | * [1] - pointing to the tail cluster |
| 378 | */ |
| 379 | __le16 delta[2]; |
Gao Xiang | ed34aa4 | 2019-09-04 10:08:51 +0800 | [diff] [blame] | 380 | } di_u; |
| 381 | }; |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 382 | |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 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) |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 386 | |
| 387 | /* dirent sorts in alphabet order, thus we can do binary search */ |
| 388 | struct erofs_dirent { |
Gao Xiang | 4b66eb5 | 2019-09-04 10:08:48 +0800 | [diff] [blame] | 389 | __le64 nid; /* node number */ |
| 390 | __le16 nameoff; /* start offset of file name */ |
| 391 | __u8 file_type; /* file type */ |
| 392 | __u8 reserved; /* reserved */ |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 393 | } __packed; |
| 394 | |
Gao Xiang | 1d819c5 | 2019-08-16 15:11:42 +0800 | [diff] [blame] | 395 | /* |
| 396 | * EROFS file types should match generic FT_* types and |
| 397 | * it seems no need to add BUILD_BUG_ONs since potential |
| 398 | * unmatchness will break other fses as well... |
| 399 | */ |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 400 | |
| 401 | #define EROFS_NAME_LEN 255 |
| 402 | |
| 403 | /* check the EROFS on-disk layout strictly at compile time */ |
| 404 | static inline void erofs_check_ondisk_layout_definitions(void) |
| 405 | { |
| 406 | BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128); |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 407 | BUILD_BUG_ON(sizeof(struct erofs_inode_compact) != 32); |
| 408 | BUILD_BUG_ON(sizeof(struct erofs_inode_extended) != 64); |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 409 | BUILD_BUG_ON(sizeof(struct erofs_xattr_ibody_header) != 12); |
| 410 | BUILD_BUG_ON(sizeof(struct erofs_xattr_entry) != 4); |
Gao Xiang | 2a9dc7a | 2021-08-20 18:00:18 +0800 | [diff] [blame] | 411 | BUILD_BUG_ON(sizeof(struct erofs_inode_chunk_info) != 4); |
| 412 | BUILD_BUG_ON(sizeof(struct erofs_inode_chunk_index) != 8); |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 413 | BUILD_BUG_ON(sizeof(struct z_erofs_map_header) != 8); |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 414 | BUILD_BUG_ON(sizeof(struct z_erofs_vle_decompressed_index) != 8); |
| 415 | BUILD_BUG_ON(sizeof(struct erofs_dirent) != 12); |
Gao Xiang | 2a9dc7a | 2021-08-20 18:00:18 +0800 | [diff] [blame] | 416 | /* keep in sync between 2 index structures for better extendibility */ |
| 417 | BUILD_BUG_ON(sizeof(struct erofs_inode_chunk_index) != |
| 418 | sizeof(struct z_erofs_vle_decompressed_index)); |
Gao Xiang | dfeab2e | 2021-10-14 16:10:10 +0800 | [diff] [blame] | 419 | BUILD_BUG_ON(sizeof(struct erofs_deviceslot) != 128); |
Gao Xiang | 99691b4 | 2018-08-21 22:49:33 +0800 | [diff] [blame] | 420 | |
| 421 | BUILD_BUG_ON(BIT(Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS) < |
| 422 | Z_EROFS_VLE_CLUSTER_TYPE_MAX - 1); |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | #endif |