erofs: remove all the byte offset comments
[linux/fpc-iii.git] / fs / erofs / erofs_fs.h
blob49335fff9d656d6532e14e91541b2ef678d97aa5
1 /* SPDX-License-Identifier: GPL-2.0-only OR Apache-2.0 */
2 /*
3 * Copyright (C) 2017-2018 HUAWEI, Inc.
4 * http://www.huawei.com/
5 * Created by Gao Xiang <gaoxiang25@huawei.com>
6 */
7 #ifndef __EROFS_FS_H
8 #define __EROFS_FS_H
10 /* Enhanced(Extended) ROM File System */
11 #define EROFS_SUPER_OFFSET 1024
14 * Any bits that aren't in EROFS_ALL_REQUIREMENTS should be
15 * incompatible with this kernel version.
17 #define EROFS_REQUIREMENT_LZ4_0PADDING 0x00000001
18 #define EROFS_ALL_REQUIREMENTS EROFS_REQUIREMENT_LZ4_0PADDING
20 /* 128-byte erofs on-disk super block */
21 struct erofs_super_block {
22 __le32 magic; /* file system magic number */
23 __le32 checksum; /* crc32c(super_block) */
24 __le32 features; /* (aka. feature_compat) */
25 __u8 blkszbits; /* support block_size == PAGE_SIZE only */
26 __u8 reserved;
28 __le16 root_nid; /* nid of root directory */
29 __le64 inos; /* total valid ino # (== f_files - f_favail) */
31 __le64 build_time; /* inode v1 time derivation */
32 __le32 build_time_nsec; /* inode v1 time derivation in nano scale */
33 __le32 blocks; /* used for statfs */
34 __le32 meta_blkaddr; /* start block address of metadata area */
35 __le32 xattr_blkaddr; /* start block address of shared xattr area */
36 __u8 uuid[16]; /* 128-bit uuid for volume */
37 __u8 volume_name[16]; /* volume name */
38 __le32 requirements; /* (aka. feature_incompat) */
40 __u8 reserved2[44];
41 } __packed;
44 * erofs inode data mapping:
45 * 0 - inode plain without inline data A:
46 * inode, [xattrs], ... | ... | no-holed data
47 * 1 - inode VLE compression B (legacy):
48 * inode, [xattrs], extents ... | ...
49 * 2 - inode plain with inline data C:
50 * inode, [xattrs], last_inline_data, ... | ... | no-holed data
51 * 3 - inode compression D:
52 * inode, [xattrs], map_header, extents ... | ...
53 * 4~7 - reserved
55 enum {
56 EROFS_INODE_FLAT_PLAIN,
57 EROFS_INODE_FLAT_COMPRESSION_LEGACY,
58 EROFS_INODE_FLAT_INLINE,
59 EROFS_INODE_FLAT_COMPRESSION,
60 EROFS_INODE_LAYOUT_MAX
63 static inline bool erofs_inode_is_data_compressed(unsigned int datamode)
65 if (datamode == EROFS_INODE_FLAT_COMPRESSION)
66 return true;
67 return datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY;
70 /* bit definitions of inode i_advise */
71 #define EROFS_I_VERSION_BITS 1
72 #define EROFS_I_DATA_MAPPING_BITS 3
74 #define EROFS_I_VERSION_BIT 0
75 #define EROFS_I_DATA_MAPPING_BIT 1
77 /* 32-byte reduced form of an ondisk inode */
78 struct erofs_inode_v1 {
79 __le16 i_advise; /* inode hints */
81 /* 1 header + n-1 * 4 bytes inline xattr to keep continuity */
82 __le16 i_xattr_icount;
83 __le16 i_mode;
84 __le16 i_nlink;
85 __le32 i_size;
86 __le32 i_reserved;
87 union {
88 /* file total compressed blocks for data mapping 1 */
89 __le32 compressed_blocks;
90 __le32 raw_blkaddr;
92 /* for device files, used to indicate old/new device # */
93 __le32 rdev;
94 } i_u __packed;
95 __le32 i_ino; /* only used for 32-bit stat compatibility */
96 __le16 i_uid;
97 __le16 i_gid;
98 __le32 i_reserved2;
99 } __packed;
101 /* 32 bytes on-disk inode */
102 #define EROFS_INODE_LAYOUT_V1 0
103 /* 64 bytes on-disk inode */
104 #define EROFS_INODE_LAYOUT_V2 1
106 /* 64-byte complete form of an ondisk inode */
107 struct erofs_inode_v2 {
108 __le16 i_advise; /* inode hints */
110 /* 1 header + n-1 * 4 bytes inline xattr to keep continuity */
111 __le16 i_xattr_icount;
112 __le16 i_mode;
113 __le16 i_reserved;
114 __le64 i_size;
115 union {
116 /* file total compressed blocks for data mapping 1 */
117 __le32 compressed_blocks;
118 __le32 raw_blkaddr;
120 /* for device files, used to indicate old/new device # */
121 __le32 rdev;
122 } i_u __packed;
124 /* only used for 32-bit stat compatibility */
125 __le32 i_ino;
127 __le32 i_uid;
128 __le32 i_gid;
129 __le64 i_ctime;
130 __le32 i_ctime_nsec;
131 __le32 i_nlink;
132 __u8 i_reserved2[16];
133 } __packed;
135 #define EROFS_MAX_SHARED_XATTRS (128)
136 /* h_shared_count between 129 ... 255 are special # */
137 #define EROFS_SHARED_XATTR_EXTENT (255)
140 * inline xattrs (n == i_xattr_icount):
141 * erofs_xattr_ibody_header(1) + (n - 1) * 4 bytes
142 * 12 bytes / \
143 * / \
144 * /-----------------------\
145 * | erofs_xattr_entries+ |
146 * +-----------------------+
147 * inline xattrs must starts in erofs_xattr_ibody_header,
148 * for read-only fs, no need to introduce h_refcount
150 struct erofs_xattr_ibody_header {
151 __le32 h_reserved;
152 __u8 h_shared_count;
153 __u8 h_reserved2[7];
154 __le32 h_shared_xattrs[0]; /* shared xattr id array */
155 } __packed;
157 /* Name indexes */
158 #define EROFS_XATTR_INDEX_USER 1
159 #define EROFS_XATTR_INDEX_POSIX_ACL_ACCESS 2
160 #define EROFS_XATTR_INDEX_POSIX_ACL_DEFAULT 3
161 #define EROFS_XATTR_INDEX_TRUSTED 4
162 #define EROFS_XATTR_INDEX_LUSTRE 5
163 #define EROFS_XATTR_INDEX_SECURITY 6
165 /* xattr entry (for both inline & shared xattrs) */
166 struct erofs_xattr_entry {
167 __u8 e_name_len; /* length of name */
168 __u8 e_name_index; /* attribute name index */
169 __le16 e_value_size; /* size of attribute value */
170 /* followed by e_name and e_value */
171 char e_name[0]; /* attribute name */
172 } __packed;
174 #define ondisk_xattr_ibody_size(count) ({\
175 u32 __count = le16_to_cpu(count); \
176 ((__count) == 0) ? 0 : \
177 sizeof(struct erofs_xattr_ibody_header) + \
178 sizeof(__u32) * ((__count) - 1); })
180 #define EROFS_XATTR_ALIGN(size) round_up(size, sizeof(struct erofs_xattr_entry))
181 #define EROFS_XATTR_ENTRY_SIZE(entry) EROFS_XATTR_ALIGN( \
182 sizeof(struct erofs_xattr_entry) + \
183 (entry)->e_name_len + le16_to_cpu((entry)->e_value_size))
185 /* available compression algorithm types */
186 enum {
187 Z_EROFS_COMPRESSION_LZ4,
188 Z_EROFS_COMPRESSION_MAX
192 * bit 0 : COMPACTED_2B indexes (0 - off; 1 - on)
193 * e.g. for 4k logical cluster size, 4B if compacted 2B is off;
194 * (4B) + 2B + (4B) if compacted 2B is on.
196 #define Z_EROFS_ADVISE_COMPACTED_2B_BIT 0
198 #define Z_EROFS_ADVISE_COMPACTED_2B (1 << Z_EROFS_ADVISE_COMPACTED_2B_BIT)
200 struct z_erofs_map_header {
201 __le32 h_reserved1;
202 __le16 h_advise;
204 * bit 0-3 : algorithm type of head 1 (logical cluster type 01);
205 * bit 4-7 : algorithm type of head 2 (logical cluster type 11).
207 __u8 h_algorithmtype;
209 * bit 0-2 : logical cluster bits - 12, e.g. 0 for 4096;
210 * bit 3-4 : (physical - logical) cluster bits of head 1:
211 * For example, if logical clustersize = 4096, 1 for 8192.
212 * bit 5-7 : (physical - logical) cluster bits of head 2.
214 __u8 h_clusterbits;
217 #define Z_EROFS_VLE_LEGACY_HEADER_PADDING 8
220 * Z_EROFS Variable-sized Logical Extent cluster type:
221 * 0 - literal (uncompressed) cluster
222 * 1 - compressed cluster (for the head logical cluster)
223 * 2 - compressed cluster (for the other logical clusters)
225 * In detail,
226 * 0 - literal (uncompressed) cluster,
227 * di_advise = 0
228 * di_clusterofs = the literal data offset of the cluster
229 * di_blkaddr = the blkaddr of the literal cluster
231 * 1 - compressed cluster (for the head logical cluster)
232 * di_advise = 1
233 * di_clusterofs = the decompressed data offset of the cluster
234 * di_blkaddr = the blkaddr of the compressed cluster
236 * 2 - compressed cluster (for the other logical clusters)
237 * di_advise = 2
238 * di_clusterofs =
239 * the decompressed data offset in its own head cluster
240 * di_u.delta[0] = distance to its corresponding head cluster
241 * di_u.delta[1] = distance to its corresponding tail cluster
242 * (di_advise could be 0, 1 or 2)
244 enum {
245 Z_EROFS_VLE_CLUSTER_TYPE_PLAIN,
246 Z_EROFS_VLE_CLUSTER_TYPE_HEAD,
247 Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD,
248 Z_EROFS_VLE_CLUSTER_TYPE_RESERVED,
249 Z_EROFS_VLE_CLUSTER_TYPE_MAX
252 #define Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS 2
253 #define Z_EROFS_VLE_DI_CLUSTER_TYPE_BIT 0
255 struct z_erofs_vle_decompressed_index {
256 __le16 di_advise;
257 /* where to decompress in the head cluster */
258 __le16 di_clusterofs;
260 union {
261 /* for the head cluster */
262 __le32 blkaddr;
264 * for the rest clusters
265 * eg. for 4k page-sized cluster, maximum 4K*64k = 256M)
266 * [0] - pointing to the head cluster
267 * [1] - pointing to the tail cluster
269 __le16 delta[2];
270 } di_u __packed;
271 } __packed;
273 #define Z_EROFS_VLE_LEGACY_INDEX_ALIGN(size) \
274 (round_up(size, sizeof(struct z_erofs_vle_decompressed_index)) + \
275 sizeof(struct z_erofs_map_header) + Z_EROFS_VLE_LEGACY_HEADER_PADDING)
277 /* dirent sorts in alphabet order, thus we can do binary search */
278 struct erofs_dirent {
279 __le64 nid; /* node number */
280 __le16 nameoff; /* start offset of file name */
281 __u8 file_type; /* file type */
282 __u8 reserved; /* reserved */
283 } __packed;
286 * EROFS file types should match generic FT_* types and
287 * it seems no need to add BUILD_BUG_ONs since potential
288 * unmatchness will break other fses as well...
291 #define EROFS_NAME_LEN 255
293 /* check the EROFS on-disk layout strictly at compile time */
294 static inline void erofs_check_ondisk_layout_definitions(void)
296 BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128);
297 BUILD_BUG_ON(sizeof(struct erofs_inode_v1) != 32);
298 BUILD_BUG_ON(sizeof(struct erofs_inode_v2) != 64);
299 BUILD_BUG_ON(sizeof(struct erofs_xattr_ibody_header) != 12);
300 BUILD_BUG_ON(sizeof(struct erofs_xattr_entry) != 4);
301 BUILD_BUG_ON(sizeof(struct z_erofs_map_header) != 8);
302 BUILD_BUG_ON(sizeof(struct z_erofs_vle_decompressed_index) != 8);
303 BUILD_BUG_ON(sizeof(struct erofs_dirent) != 12);
305 BUILD_BUG_ON(BIT(Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS) <
306 Z_EROFS_VLE_CLUSTER_TYPE_MAX - 1);
309 #endif