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 | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 7 | */ |
| 8 | #ifndef __EROFS_FS_H |
| 9 | #define __EROFS_FS_H |
| 10 | |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 11 | #define EROFS_SUPER_OFFSET 1024 |
| 12 | |
Pratik Shinde | b858a48 | 2019-11-04 10:49:37 +0800 | [diff] [blame] | 13 | #define EROFS_FEATURE_COMPAT_SB_CHKSUM 0x00000001 |
| 14 | |
Gao Xiang | 5efe513 | 2019-06-13 16:35:41 +0800 | [diff] [blame] | 15 | /* |
Gao Xiang | 426a930 | 2019-09-04 10:08:53 +0800 | [diff] [blame] | 16 | * Any bits that aren't in EROFS_ALL_FEATURE_INCOMPAT should |
| 17 | * be incompatible with this kernel version. |
Gao Xiang | 5efe513 | 2019-06-13 16:35:41 +0800 | [diff] [blame] | 18 | */ |
Gao Xiang | 426a930 | 2019-09-04 10:08:53 +0800 | [diff] [blame] | 19 | #define EROFS_FEATURE_INCOMPAT_LZ4_0PADDING 0x00000001 |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 20 | #define EROFS_FEATURE_INCOMPAT_COMPR_CFGS 0x00000002 |
Gao Xiang | 5404c3301 | 2021-04-07 12:39:22 +0800 | [diff] [blame] | 21 | #define EROFS_FEATURE_INCOMPAT_BIG_PCLUSTER 0x00000002 |
Gao Xiang | 8e6c8fa | 2021-04-07 12:39:27 +0800 | [diff] [blame] | 22 | #define EROFS_ALL_FEATURE_INCOMPAT \ |
| 23 | (EROFS_FEATURE_INCOMPAT_LZ4_0PADDING | \ |
| 24 | EROFS_FEATURE_INCOMPAT_COMPR_CFGS | \ |
| 25 | EROFS_FEATURE_INCOMPAT_BIG_PCLUSTER) |
Gao Xiang | 5efe513 | 2019-06-13 16:35:41 +0800 | [diff] [blame] | 26 | |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 27 | #define EROFS_SB_EXTSLOT_SIZE 16 |
| 28 | |
| 29 | /* erofs on-disk super block (currently 128 bytes) */ |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 30 | struct erofs_super_block { |
Gao Xiang | 4b66eb5 | 2019-09-04 10:08:48 +0800 | [diff] [blame] | 31 | __le32 magic; /* file system magic number */ |
| 32 | __le32 checksum; /* crc32c(super_block) */ |
Gao Xiang | 426a930 | 2019-09-04 10:08:53 +0800 | [diff] [blame] | 33 | __le32 feature_compat; |
Gao Xiang | 4b66eb5 | 2019-09-04 10:08:48 +0800 | [diff] [blame] | 34 | __u8 blkszbits; /* support block_size == PAGE_SIZE only */ |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 35 | __u8 sb_extslots; /* superblock size = 128 + sb_extslots * 16 */ |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 36 | |
Gao Xiang | 4b66eb5 | 2019-09-04 10:08:48 +0800 | [diff] [blame] | 37 | __le16 root_nid; /* nid of root directory */ |
| 38 | __le64 inos; /* total valid ino # (== f_files - f_favail) */ |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 39 | |
Gao Xiang | 4b66eb5 | 2019-09-04 10:08:48 +0800 | [diff] [blame] | 40 | __le64 build_time; /* inode v1 time derivation */ |
| 41 | __le32 build_time_nsec; /* inode v1 time derivation in nano scale */ |
| 42 | __le32 blocks; /* used for statfs */ |
| 43 | __le32 meta_blkaddr; /* start block address of metadata area */ |
| 44 | __le32 xattr_blkaddr; /* start block address of shared xattr area */ |
| 45 | __u8 uuid[16]; /* 128-bit uuid for volume */ |
| 46 | __u8 volume_name[16]; /* volume name */ |
Gao Xiang | 426a930 | 2019-09-04 10:08:53 +0800 | [diff] [blame] | 47 | __le32 feature_incompat; |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 48 | union { |
| 49 | /* bitmap for available compression algorithms */ |
| 50 | __le16 available_compr_algs; |
| 51 | /* customized sliding window size instead of 64k by default */ |
| 52 | __le16 lz4_max_distance; |
| 53 | } __packed u1; |
Huang Jianan | 5d50538 | 2021-03-29 09:23:06 +0800 | [diff] [blame] | 54 | __u8 reserved2[42]; |
Gao Xiang | ed34aa4 | 2019-09-04 10:08:51 +0800 | [diff] [blame] | 55 | }; |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 56 | |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 57 | /* |
Gao Xiang | ea559e7 | 2019-09-04 10:08:57 +0800 | [diff] [blame] | 58 | * erofs inode datalayout (i_format in on-disk inode): |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 59 | * 0 - inode plain without inline data A: |
| 60 | * inode, [xattrs], ... | ... | no-holed data |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 61 | * 1 - inode VLE compression B (legacy): |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 62 | * inode, [xattrs], extents ... | ... |
| 63 | * 2 - inode plain with inline data C: |
| 64 | * inode, [xattrs], last_inline_data, ... | ... | no-holed data |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 65 | * 3 - inode compression D: |
| 66 | * inode, [xattrs], map_header, extents ... | ... |
| 67 | * 4~7 - reserved |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 68 | */ |
| 69 | enum { |
Gao Xiang | 60a49ba | 2019-09-04 10:08:49 +0800 | [diff] [blame] | 70 | EROFS_INODE_FLAT_PLAIN = 0, |
| 71 | EROFS_INODE_FLAT_COMPRESSION_LEGACY = 1, |
| 72 | EROFS_INODE_FLAT_INLINE = 2, |
| 73 | EROFS_INODE_FLAT_COMPRESSION = 3, |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 74 | EROFS_INODE_DATALAYOUT_MAX |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 75 | }; |
Gao Xiang | ccd9c19 | 2018-12-12 01:57:30 +0800 | [diff] [blame] | 76 | |
Gao Xiang | 3d2969f | 2019-08-13 10:30:52 +0800 | [diff] [blame] | 77 | static inline bool erofs_inode_is_data_compressed(unsigned int datamode) |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 78 | { |
Gao Xiang | c39747f | 2019-09-04 10:08:52 +0800 | [diff] [blame] | 79 | return datamode == EROFS_INODE_FLAT_COMPRESSION || |
| 80 | datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY; |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 81 | } |
| 82 | |
Gao Xiang | ccd9c19 | 2018-12-12 01:57:30 +0800 | [diff] [blame] | 83 | /* bit definitions of inode i_advise */ |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 84 | #define EROFS_I_VERSION_BITS 1 |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 85 | #define EROFS_I_DATALAYOUT_BITS 3 |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 86 | |
| 87 | #define EROFS_I_VERSION_BIT 0 |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 88 | #define EROFS_I_DATALAYOUT_BIT 1 |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 89 | |
Gao Xiang | 24a806d | 2021-03-29 08:36:14 +0800 | [diff] [blame] | 90 | #define EROFS_I_ALL \ |
| 91 | ((1 << (EROFS_I_DATALAYOUT_BIT + EROFS_I_DATALAYOUT_BITS)) - 1) |
| 92 | |
Gao Xiang | 4b66eb5 | 2019-09-04 10:08:48 +0800 | [diff] [blame] | 93 | /* 32-byte reduced form of an ondisk inode */ |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 94 | struct erofs_inode_compact { |
| 95 | __le16 i_format; /* inode format hints */ |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 96 | |
| 97 | /* 1 header + n-1 * 4 bytes inline xattr to keep continuity */ |
Gao Xiang | 4b66eb5 | 2019-09-04 10:08:48 +0800 | [diff] [blame] | 98 | __le16 i_xattr_icount; |
| 99 | __le16 i_mode; |
| 100 | __le16 i_nlink; |
| 101 | __le32 i_size; |
| 102 | __le32 i_reserved; |
| 103 | union { |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 104 | /* file total compressed blocks for data mapping 1 */ |
| 105 | __le32 compressed_blocks; |
| 106 | __le32 raw_blkaddr; |
| 107 | |
| 108 | /* for device files, used to indicate old/new device # */ |
| 109 | __le32 rdev; |
Gao Xiang | ed34aa4 | 2019-09-04 10:08:51 +0800 | [diff] [blame] | 110 | } i_u; |
Gao Xiang | 4b66eb5 | 2019-09-04 10:08:48 +0800 | [diff] [blame] | 111 | __le32 i_ino; /* only used for 32-bit stat compatibility */ |
| 112 | __le16 i_uid; |
| 113 | __le16 i_gid; |
| 114 | __le32 i_reserved2; |
Gao Xiang | ed34aa4 | 2019-09-04 10:08:51 +0800 | [diff] [blame] | 115 | }; |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 116 | |
| 117 | /* 32 bytes on-disk inode */ |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 118 | #define EROFS_INODE_LAYOUT_COMPACT 0 |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 119 | /* 64 bytes on-disk inode */ |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 120 | #define EROFS_INODE_LAYOUT_EXTENDED 1 |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 121 | |
Gao Xiang | 4b66eb5 | 2019-09-04 10:08:48 +0800 | [diff] [blame] | 122 | /* 64-byte complete form of an ondisk inode */ |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 123 | struct erofs_inode_extended { |
| 124 | __le16 i_format; /* inode format hints */ |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 125 | |
Gao Xiang | cead56f | 2019-07-31 23:57:34 +0800 | [diff] [blame] | 126 | /* 1 header + n-1 * 4 bytes inline xattr to keep continuity */ |
Gao Xiang | 4b66eb5 | 2019-09-04 10:08:48 +0800 | [diff] [blame] | 127 | __le16 i_xattr_icount; |
| 128 | __le16 i_mode; |
| 129 | __le16 i_reserved; |
| 130 | __le64 i_size; |
| 131 | union { |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 132 | /* file total compressed blocks for data mapping 1 */ |
| 133 | __le32 compressed_blocks; |
| 134 | __le32 raw_blkaddr; |
| 135 | |
| 136 | /* for device files, used to indicate old/new device # */ |
| 137 | __le32 rdev; |
Gao Xiang | ed34aa4 | 2019-09-04 10:08:51 +0800 | [diff] [blame] | 138 | } i_u; |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 139 | |
| 140 | /* only used for 32-bit stat compatibility */ |
Gao Xiang | 4b66eb5 | 2019-09-04 10:08:48 +0800 | [diff] [blame] | 141 | __le32 i_ino; |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 142 | |
Gao Xiang | 4b66eb5 | 2019-09-04 10:08:48 +0800 | [diff] [blame] | 143 | __le32 i_uid; |
| 144 | __le32 i_gid; |
| 145 | __le64 i_ctime; |
| 146 | __le32 i_ctime_nsec; |
| 147 | __le32 i_nlink; |
| 148 | __u8 i_reserved2[16]; |
Gao Xiang | ed34aa4 | 2019-09-04 10:08:51 +0800 | [diff] [blame] | 149 | }; |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 150 | |
| 151 | #define EROFS_MAX_SHARED_XATTRS (128) |
| 152 | /* h_shared_count between 129 ... 255 are special # */ |
| 153 | #define EROFS_SHARED_XATTR_EXTENT (255) |
| 154 | |
| 155 | /* |
| 156 | * inline xattrs (n == i_xattr_icount): |
| 157 | * erofs_xattr_ibody_header(1) + (n - 1) * 4 bytes |
| 158 | * 12 bytes / \ |
| 159 | * / \ |
| 160 | * /-----------------------\ |
| 161 | * | erofs_xattr_entries+ | |
| 162 | * +-----------------------+ |
| 163 | * inline xattrs must starts in erofs_xattr_ibody_header, |
| 164 | * for read-only fs, no need to introduce h_refcount |
| 165 | */ |
| 166 | struct erofs_xattr_ibody_header { |
Gao Xiang | cead56f | 2019-07-31 23:57:34 +0800 | [diff] [blame] | 167 | __le32 h_reserved; |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 168 | __u8 h_shared_count; |
Gao Xiang | cead56f | 2019-07-31 23:57:34 +0800 | [diff] [blame] | 169 | __u8 h_reserved2[7]; |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 170 | __le32 h_shared_xattrs[0]; /* shared xattr id array */ |
Gao Xiang | ed34aa4 | 2019-09-04 10:08:51 +0800 | [diff] [blame] | 171 | }; |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 172 | |
| 173 | /* Name indexes */ |
| 174 | #define EROFS_XATTR_INDEX_USER 1 |
| 175 | #define EROFS_XATTR_INDEX_POSIX_ACL_ACCESS 2 |
| 176 | #define EROFS_XATTR_INDEX_POSIX_ACL_DEFAULT 3 |
| 177 | #define EROFS_XATTR_INDEX_TRUSTED 4 |
| 178 | #define EROFS_XATTR_INDEX_LUSTRE 5 |
| 179 | #define EROFS_XATTR_INDEX_SECURITY 6 |
| 180 | |
| 181 | /* xattr entry (for both inline & shared xattrs) */ |
| 182 | struct erofs_xattr_entry { |
| 183 | __u8 e_name_len; /* length of name */ |
| 184 | __u8 e_name_index; /* attribute name index */ |
| 185 | __le16 e_value_size; /* size of attribute value */ |
| 186 | /* followed by e_name and e_value */ |
| 187 | char e_name[0]; /* attribute name */ |
Gao Xiang | ed34aa4 | 2019-09-04 10:08:51 +0800 | [diff] [blame] | 188 | }; |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 189 | |
Gao Xiang | b6796ab | 2019-09-04 10:08:50 +0800 | [diff] [blame] | 190 | static inline unsigned int erofs_xattr_ibody_size(__le16 i_xattr_icount) |
| 191 | { |
| 192 | if (!i_xattr_icount) |
| 193 | return 0; |
| 194 | |
| 195 | return sizeof(struct erofs_xattr_ibody_header) + |
| 196 | sizeof(__u32) * (le16_to_cpu(i_xattr_icount) - 1); |
| 197 | } |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 198 | |
| 199 | #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] | 200 | |
| 201 | static inline unsigned int erofs_xattr_entry_size(struct erofs_xattr_entry *e) |
| 202 | { |
| 203 | return EROFS_XATTR_ALIGN(sizeof(struct erofs_xattr_entry) + |
| 204 | e->e_name_len + le16_to_cpu(e->e_value_size)); |
| 205 | } |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 206 | |
Gao Xiang | 9f6cc76 | 2021-04-07 12:39:20 +0800 | [diff] [blame] | 207 | /* maximum supported size of a physical compression cluster */ |
| 208 | #define Z_EROFS_PCLUSTER_MAX_SIZE (1024 * 1024) |
| 209 | |
Gao Xiang | ea559e7 | 2019-09-04 10:08:57 +0800 | [diff] [blame] | 210 | /* available compression algorithm types (for h_algorithmtype) */ |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 211 | enum { |
Gao Xiang | 60a49ba | 2019-09-04 10:08:49 +0800 | [diff] [blame] | 212 | Z_EROFS_COMPRESSION_LZ4 = 0, |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 213 | Z_EROFS_COMPRESSION_MAX |
| 214 | }; |
Gao Xiang | 1437371 | 2021-03-29 18:00:12 +0800 | [diff] [blame] | 215 | #define Z_EROFS_ALL_COMPR_ALGS (1 << (Z_EROFS_COMPRESSION_MAX - 1)) |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 216 | |
Gao Xiang | 46249cd | 2021-03-29 09:23:07 +0800 | [diff] [blame] | 217 | /* 14 bytes (+ length field = 16 bytes) */ |
| 218 | struct z_erofs_lz4_cfgs { |
| 219 | __le16 max_distance; |
Gao Xiang | 5404c3301 | 2021-04-07 12:39:22 +0800 | [diff] [blame] | 220 | __le16 max_pclusterblks; |
| 221 | u8 reserved[10]; |
Gao Xiang | 46249cd | 2021-03-29 09:23:07 +0800 | [diff] [blame] | 222 | } __packed; |
| 223 | |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 224 | /* |
| 225 | * bit 0 : COMPACTED_2B indexes (0 - off; 1 - on) |
| 226 | * e.g. for 4k logical cluster size, 4B if compacted 2B is off; |
| 227 | * (4B) + 2B + (4B) if compacted 2B is on. |
Gao Xiang | 5404c3301 | 2021-04-07 12:39:22 +0800 | [diff] [blame] | 228 | * bit 1 : HEAD1 big pcluster (0 - off; 1 - on) |
| 229 | * bit 2 : HEAD2 big pcluster (0 - off; 1 - on) |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 230 | */ |
Gao Xiang | 5404c3301 | 2021-04-07 12:39:22 +0800 | [diff] [blame] | 231 | #define Z_EROFS_ADVISE_COMPACTED_2B 0x0001 |
| 232 | #define Z_EROFS_ADVISE_BIG_PCLUSTER_1 0x0002 |
| 233 | #define Z_EROFS_ADVISE_BIG_PCLUSTER_2 0x0004 |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 234 | |
| 235 | struct z_erofs_map_header { |
| 236 | __le32 h_reserved1; |
| 237 | __le16 h_advise; |
| 238 | /* |
| 239 | * bit 0-3 : algorithm type of head 1 (logical cluster type 01); |
| 240 | * bit 4-7 : algorithm type of head 2 (logical cluster type 11). |
| 241 | */ |
| 242 | __u8 h_algorithmtype; |
| 243 | /* |
| 244 | * bit 0-2 : logical cluster bits - 12, e.g. 0 for 4096; |
Gao Xiang | 54e0b6c | 2021-04-07 12:39:18 +0800 | [diff] [blame] | 245 | * bit 3-7 : reserved. |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 246 | */ |
| 247 | __u8 h_clusterbits; |
| 248 | }; |
| 249 | |
| 250 | #define Z_EROFS_VLE_LEGACY_HEADER_PADDING 8 |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 251 | |
| 252 | /* |
Gao Xiang | ea559e7 | 2019-09-04 10:08:57 +0800 | [diff] [blame] | 253 | * Fixed-sized output compression ondisk Logical Extent cluster type: |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 254 | * 0 - literal (uncompressed) cluster |
| 255 | * 1 - compressed cluster (for the head logical cluster) |
| 256 | * 2 - compressed cluster (for the other logical clusters) |
| 257 | * |
| 258 | * In detail, |
| 259 | * 0 - literal (uncompressed) cluster, |
| 260 | * di_advise = 0 |
| 261 | * di_clusterofs = the literal data offset of the cluster |
| 262 | * di_blkaddr = the blkaddr of the literal cluster |
| 263 | * |
| 264 | * 1 - compressed cluster (for the head logical cluster) |
| 265 | * di_advise = 1 |
| 266 | * di_clusterofs = the decompressed data offset of the cluster |
| 267 | * di_blkaddr = the blkaddr of the compressed cluster |
| 268 | * |
| 269 | * 2 - compressed cluster (for the other logical clusters) |
| 270 | * di_advise = 2 |
| 271 | * di_clusterofs = |
| 272 | * the decompressed data offset in its own head cluster |
| 273 | * di_u.delta[0] = distance to its corresponding head cluster |
| 274 | * di_u.delta[1] = distance to its corresponding tail cluster |
| 275 | * (di_advise could be 0, 1 or 2) |
| 276 | */ |
Gao Xiang | 99691b4 | 2018-08-21 22:49:33 +0800 | [diff] [blame] | 277 | enum { |
Gao Xiang | 60a49ba | 2019-09-04 10:08:49 +0800 | [diff] [blame] | 278 | Z_EROFS_VLE_CLUSTER_TYPE_PLAIN = 0, |
| 279 | Z_EROFS_VLE_CLUSTER_TYPE_HEAD = 1, |
| 280 | Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD = 2, |
| 281 | Z_EROFS_VLE_CLUSTER_TYPE_RESERVED = 3, |
Gao Xiang | 99691b4 | 2018-08-21 22:49:33 +0800 | [diff] [blame] | 282 | Z_EROFS_VLE_CLUSTER_TYPE_MAX |
| 283 | }; |
| 284 | |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 285 | #define Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS 2 |
| 286 | #define Z_EROFS_VLE_DI_CLUSTER_TYPE_BIT 0 |
| 287 | |
Gao Xiang | 5404c3301 | 2021-04-07 12:39:22 +0800 | [diff] [blame] | 288 | /* |
| 289 | * D0_CBLKCNT will be marked _only_ at the 1st non-head lcluster to store the |
| 290 | * compressed block count of a compressed extent (in logical clusters, aka. |
| 291 | * block count of a pcluster). |
| 292 | */ |
| 293 | #define Z_EROFS_VLE_DI_D0_CBLKCNT (1 << 11) |
| 294 | |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 295 | struct z_erofs_vle_decompressed_index { |
| 296 | __le16 di_advise; |
| 297 | /* where to decompress in the head cluster */ |
| 298 | __le16 di_clusterofs; |
| 299 | |
| 300 | union { |
| 301 | /* for the head cluster */ |
| 302 | __le32 blkaddr; |
| 303 | /* |
| 304 | * for the rest clusters |
| 305 | * eg. for 4k page-sized cluster, maximum 4K*64k = 256M) |
| 306 | * [0] - pointing to the head cluster |
| 307 | * [1] - pointing to the tail cluster |
| 308 | */ |
| 309 | __le16 delta[2]; |
Gao Xiang | ed34aa4 | 2019-09-04 10:08:51 +0800 | [diff] [blame] | 310 | } di_u; |
| 311 | }; |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 312 | |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 313 | #define Z_EROFS_VLE_LEGACY_INDEX_ALIGN(size) \ |
| 314 | (round_up(size, sizeof(struct z_erofs_vle_decompressed_index)) + \ |
| 315 | sizeof(struct z_erofs_map_header) + Z_EROFS_VLE_LEGACY_HEADER_PADDING) |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 316 | |
| 317 | /* dirent sorts in alphabet order, thus we can do binary search */ |
| 318 | struct erofs_dirent { |
Gao Xiang | 4b66eb5 | 2019-09-04 10:08:48 +0800 | [diff] [blame] | 319 | __le64 nid; /* node number */ |
| 320 | __le16 nameoff; /* start offset of file name */ |
| 321 | __u8 file_type; /* file type */ |
| 322 | __u8 reserved; /* reserved */ |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 323 | } __packed; |
| 324 | |
Gao Xiang | 1d819c5 | 2019-08-16 15:11:42 +0800 | [diff] [blame] | 325 | /* |
| 326 | * EROFS file types should match generic FT_* types and |
| 327 | * it seems no need to add BUILD_BUG_ONs since potential |
| 328 | * unmatchness will break other fses as well... |
| 329 | */ |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 330 | |
| 331 | #define EROFS_NAME_LEN 255 |
| 332 | |
| 333 | /* check the EROFS on-disk layout strictly at compile time */ |
| 334 | static inline void erofs_check_ondisk_layout_definitions(void) |
| 335 | { |
| 336 | BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128); |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 337 | BUILD_BUG_ON(sizeof(struct erofs_inode_compact) != 32); |
| 338 | BUILD_BUG_ON(sizeof(struct erofs_inode_extended) != 64); |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 339 | BUILD_BUG_ON(sizeof(struct erofs_xattr_ibody_header) != 12); |
| 340 | BUILD_BUG_ON(sizeof(struct erofs_xattr_entry) != 4); |
Gao Xiang | ec8c244 | 2019-06-24 15:22:51 +0800 | [diff] [blame] | 341 | BUILD_BUG_ON(sizeof(struct z_erofs_map_header) != 8); |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 342 | BUILD_BUG_ON(sizeof(struct z_erofs_vle_decompressed_index) != 8); |
| 343 | BUILD_BUG_ON(sizeof(struct erofs_dirent) != 12); |
Gao Xiang | 99691b4 | 2018-08-21 22:49:33 +0800 | [diff] [blame] | 344 | |
| 345 | BUILD_BUG_ON(BIT(Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS) < |
| 346 | Z_EROFS_VLE_CLUSTER_TYPE_MAX - 1); |
Gao Xiang | aea1286 | 2018-07-26 20:21:44 +0800 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | #endif |