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