Skip to content

Commit 6326a3d

Browse files
hsiangkaogregkh
authored andcommitted
erofs: tidy up EROFS on-disk naming
commit 1c7f49a76773bcf95d3c840cff6cd449114ddf56 upstream. - Get rid of all "vle" (variable-length extents) expressions since they only expand overall name lengths unnecessarily; - Rename COMPRESSION_LEGACY to COMPRESSED_FULL; - Move on-disk directory definitions ahead of compression; - Drop unused extended attribute definitions; - Move inode ondisk union `i_u` out as `union erofs_inode_i_u`. No actual logical change. Signed-off-by: Gao Xiang <[email protected]> Reviewed-by: Yue Hu <[email protected]> Reviewed-by: Chao Yu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6e5dbd1 commit 6326a3d

File tree

2 files changed

+119
-142
lines changed

2 files changed

+119
-142
lines changed

fs/erofs/erofs_fs.h

Lines changed: 62 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -82,32 +82,27 @@ struct erofs_super_block {
8282
};
8383

8484
/*
85-
* erofs inode datalayout (i_format in on-disk inode):
85+
* EROFS inode datalayout (i_format in on-disk inode):
8686
* 0 - uncompressed flat inode without tail-packing inline data:
87-
* inode, [xattrs], ... | ... | no-holed data
8887
* 1 - compressed inode with non-compact indexes:
89-
* inode, [xattrs], [map_header], extents ... | ...
9088
* 2 - uncompressed flat inode with tail-packing inline data:
91-
* inode, [xattrs], tailpacking data, ... | ... | no-holed data
9289
* 3 - compressed inode with compact indexes:
93-
* inode, [xattrs], map_header, extents ... | ...
9490
* 4 - chunk-based inode with (optional) multi-device support:
95-
* inode, [xattrs], chunk indexes ... | ...
9691
* 5~7 - reserved
9792
*/
9893
enum {
9994
EROFS_INODE_FLAT_PLAIN = 0,
100-
EROFS_INODE_FLAT_COMPRESSION_LEGACY = 1,
95+
EROFS_INODE_COMPRESSED_FULL = 1,
10196
EROFS_INODE_FLAT_INLINE = 2,
102-
EROFS_INODE_FLAT_COMPRESSION = 3,
97+
EROFS_INODE_COMPRESSED_COMPACT = 3,
10398
EROFS_INODE_CHUNK_BASED = 4,
10499
EROFS_INODE_DATALAYOUT_MAX
105100
};
106101

107102
static inline bool erofs_inode_is_data_compressed(unsigned int datamode)
108103
{
109-
return datamode == EROFS_INODE_FLAT_COMPRESSION ||
110-
datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY;
104+
return datamode == EROFS_INODE_COMPRESSED_COMPACT ||
105+
datamode == EROFS_INODE_COMPRESSED_FULL;
111106
}
112107

113108
/* bit definitions of inode i_format */
@@ -128,11 +123,30 @@ static inline bool erofs_inode_is_data_compressed(unsigned int datamode)
128123
#define EROFS_CHUNK_FORMAT_ALL \
129124
(EROFS_CHUNK_FORMAT_BLKBITS_MASK | EROFS_CHUNK_FORMAT_INDEXES)
130125

126+
/* 32-byte on-disk inode */
127+
#define EROFS_INODE_LAYOUT_COMPACT 0
128+
/* 64-byte on-disk inode */
129+
#define EROFS_INODE_LAYOUT_EXTENDED 1
130+
131131
struct erofs_inode_chunk_info {
132132
__le16 format; /* chunk blkbits, etc. */
133133
__le16 reserved;
134134
};
135135

136+
union erofs_inode_i_u {
137+
/* total compressed blocks for compressed inodes */
138+
__le32 compressed_blocks;
139+
140+
/* block address for uncompressed flat inodes */
141+
__le32 raw_blkaddr;
142+
143+
/* for device files, used to indicate old/new device # */
144+
__le32 rdev;
145+
146+
/* for chunk-based files, it contains the summary info */
147+
struct erofs_inode_chunk_info c;
148+
};
149+
136150
/* 32-byte reduced form of an ondisk inode */
137151
struct erofs_inode_compact {
138152
__le16 i_format; /* inode format hints */
@@ -143,29 +157,14 @@ struct erofs_inode_compact {
143157
__le16 i_nlink;
144158
__le32 i_size;
145159
__le32 i_reserved;
146-
union {
147-
/* total compressed blocks for compressed inodes */
148-
__le32 compressed_blocks;
149-
/* block address for uncompressed flat inodes */
150-
__le32 raw_blkaddr;
151-
152-
/* for device files, used to indicate old/new device # */
153-
__le32 rdev;
154-
155-
/* for chunk-based files, it contains the summary info */
156-
struct erofs_inode_chunk_info c;
157-
} i_u;
158-
__le32 i_ino; /* only used for 32-bit stat compatibility */
160+
union erofs_inode_i_u i_u;
161+
162+
__le32 i_ino; /* only used for 32-bit stat compatibility */
159163
__le16 i_uid;
160164
__le16 i_gid;
161165
__le32 i_reserved2;
162166
};
163167

164-
/* 32-byte on-disk inode */
165-
#define EROFS_INODE_LAYOUT_COMPACT 0
166-
/* 64-byte on-disk inode */
167-
#define EROFS_INODE_LAYOUT_EXTENDED 1
168-
169168
/* 64-byte complete form of an ondisk inode */
170169
struct erofs_inode_extended {
171170
__le16 i_format; /* inode format hints */
@@ -175,22 +174,9 @@ struct erofs_inode_extended {
175174
__le16 i_mode;
176175
__le16 i_reserved;
177176
__le64 i_size;
178-
union {
179-
/* total compressed blocks for compressed inodes */
180-
__le32 compressed_blocks;
181-
/* block address for uncompressed flat inodes */
182-
__le32 raw_blkaddr;
183-
184-
/* for device files, used to indicate old/new device # */
185-
__le32 rdev;
186-
187-
/* for chunk-based files, it contains the summary info */
188-
struct erofs_inode_chunk_info c;
189-
} i_u;
190-
191-
/* only used for 32-bit stat compatibility */
192-
__le32 i_ino;
177+
union erofs_inode_i_u i_u;
193178

179+
__le32 i_ino; /* only used for 32-bit stat compatibility */
194180
__le32 i_uid;
195181
__le32 i_gid;
196182
__le64 i_mtime;
@@ -199,10 +185,6 @@ struct erofs_inode_extended {
199185
__u8 i_reserved2[16];
200186
};
201187

202-
#define EROFS_MAX_SHARED_XATTRS (128)
203-
/* h_shared_count between 129 ... 255 are special # */
204-
#define EROFS_SHARED_XATTR_EXTENT (255)
205-
206188
/*
207189
* inline xattrs (n == i_xattr_icount):
208190
* erofs_xattr_ibody_header(1) + (n - 1) * 4 bytes
@@ -268,6 +250,22 @@ struct erofs_inode_chunk_index {
268250
__le32 blkaddr; /* start block address of this inode chunk */
269251
};
270252

253+
/* dirent sorts in alphabet order, thus we can do binary search */
254+
struct erofs_dirent {
255+
__le64 nid; /* node number */
256+
__le16 nameoff; /* start offset of file name */
257+
__u8 file_type; /* file type */
258+
__u8 reserved; /* reserved */
259+
} __packed;
260+
261+
/*
262+
* EROFS file types should match generic FT_* types and
263+
* it seems no need to add BUILD_BUG_ONs since potential
264+
* unmatchness will break other fses as well...
265+
*/
266+
267+
#define EROFS_NAME_LEN 255
268+
271269
/* maximum supported size of a physical compression cluster */
272270
#define Z_EROFS_PCLUSTER_MAX_SIZE (1024 * 1024)
273271

@@ -337,10 +335,8 @@ struct z_erofs_map_header {
337335
__u8 h_clusterbits;
338336
};
339337

340-
#define Z_EROFS_VLE_LEGACY_HEADER_PADDING 8
341-
342338
/*
343-
* Fixed-sized output compression on-disk logical cluster type:
339+
* On-disk logical cluster type:
344340
* 0 - literal (uncompressed) lcluster
345341
* 1,3 - compressed lcluster (for HEAD lclusters)
346342
* 2 - compressed lcluster (for NONHEAD lclusters)
@@ -364,27 +360,27 @@ struct z_erofs_map_header {
364360
* di_u.delta[1] = distance to the next HEAD lcluster
365361
*/
366362
enum {
367-
Z_EROFS_VLE_CLUSTER_TYPE_PLAIN = 0,
368-
Z_EROFS_VLE_CLUSTER_TYPE_HEAD1 = 1,
369-
Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD = 2,
370-
Z_EROFS_VLE_CLUSTER_TYPE_HEAD2 = 3,
371-
Z_EROFS_VLE_CLUSTER_TYPE_MAX
363+
Z_EROFS_LCLUSTER_TYPE_PLAIN = 0,
364+
Z_EROFS_LCLUSTER_TYPE_HEAD1 = 1,
365+
Z_EROFS_LCLUSTER_TYPE_NONHEAD = 2,
366+
Z_EROFS_LCLUSTER_TYPE_HEAD2 = 3,
367+
Z_EROFS_LCLUSTER_TYPE_MAX
372368
};
373369

374-
#define Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS 2
375-
#define Z_EROFS_VLE_DI_CLUSTER_TYPE_BIT 0
370+
#define Z_EROFS_LI_LCLUSTER_TYPE_BITS 2
371+
#define Z_EROFS_LI_LCLUSTER_TYPE_BIT 0
376372

377373
/* (noncompact only, HEAD) This pcluster refers to partial decompressed data */
378-
#define Z_EROFS_VLE_DI_PARTIAL_REF (1 << 15)
374+
#define Z_EROFS_LI_PARTIAL_REF (1 << 15)
379375

380376
/*
381377
* D0_CBLKCNT will be marked _only_ at the 1st non-head lcluster to store the
382378
* compressed block count of a compressed extent (in logical clusters, aka.
383379
* block count of a pcluster).
384380
*/
385-
#define Z_EROFS_VLE_DI_D0_CBLKCNT (1 << 11)
381+
#define Z_EROFS_LI_D0_CBLKCNT (1 << 11)
386382

387-
struct z_erofs_vle_decompressed_index {
383+
struct z_erofs_lcluster_index {
388384
__le16 di_advise;
389385
/* where to decompress in the head lcluster */
390386
__le16 di_clusterofs;
@@ -401,25 +397,8 @@ struct z_erofs_vle_decompressed_index {
401397
} di_u;
402398
};
403399

404-
#define Z_EROFS_VLE_LEGACY_INDEX_ALIGN(size) \
405-
(round_up(size, sizeof(struct z_erofs_vle_decompressed_index)) + \
406-
sizeof(struct z_erofs_map_header) + Z_EROFS_VLE_LEGACY_HEADER_PADDING)
407-
408-
/* dirent sorts in alphabet order, thus we can do binary search */
409-
struct erofs_dirent {
410-
__le64 nid; /* node number */
411-
__le16 nameoff; /* start offset of file name */
412-
__u8 file_type; /* file type */
413-
__u8 reserved; /* reserved */
414-
} __packed;
415-
416-
/*
417-
* EROFS file types should match generic FT_* types and
418-
* it seems no need to add BUILD_BUG_ONs since potential
419-
* unmatchness will break other fses as well...
420-
*/
421-
422-
#define EROFS_NAME_LEN 255
400+
#define Z_EROFS_FULL_INDEX_ALIGN(end) \
401+
(ALIGN(end, 8) + sizeof(struct z_erofs_map_header) + 8)
423402

424403
/* check the EROFS on-disk layout strictly at compile time */
425404
static inline void erofs_check_ondisk_layout_definitions(void)
@@ -436,15 +415,15 @@ static inline void erofs_check_ondisk_layout_definitions(void)
436415
BUILD_BUG_ON(sizeof(struct erofs_inode_chunk_info) != 4);
437416
BUILD_BUG_ON(sizeof(struct erofs_inode_chunk_index) != 8);
438417
BUILD_BUG_ON(sizeof(struct z_erofs_map_header) != 8);
439-
BUILD_BUG_ON(sizeof(struct z_erofs_vle_decompressed_index) != 8);
418+
BUILD_BUG_ON(sizeof(struct z_erofs_lcluster_index) != 8);
440419
BUILD_BUG_ON(sizeof(struct erofs_dirent) != 12);
441420
/* keep in sync between 2 index structures for better extendibility */
442421
BUILD_BUG_ON(sizeof(struct erofs_inode_chunk_index) !=
443-
sizeof(struct z_erofs_vle_decompressed_index));
422+
sizeof(struct z_erofs_lcluster_index));
444423
BUILD_BUG_ON(sizeof(struct erofs_deviceslot) != 128);
445424

446-
BUILD_BUG_ON(BIT(Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS) <
447-
Z_EROFS_VLE_CLUSTER_TYPE_MAX - 1);
425+
BUILD_BUG_ON(BIT(Z_EROFS_LI_LCLUSTER_TYPE_BITS) <
426+
Z_EROFS_LCLUSTER_TYPE_MAX - 1);
448427
/* exclude old compiler versions like gcc 7.5.0 */
449428
BUILD_BUG_ON(__builtin_constant_p(fmh) ?
450429
fmh != cpu_to_le64(1ULL << 63) : 0);

0 commit comments

Comments
 (0)