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