/* SPDX-License-Identifier: GPL-2.0-only OR Apache-2.0 */ /* * EROFS (Enhanced ROM File System) on-disk format definition * * Copyright (C) 2017-2018 HUAWEI, Inc. * https://www.huawei.com/ * Copyright (C) 2021, Alibaba Cloud */ #ifndef __EROFS_FS_H #define __EROFS_FS_H #define EROFS_SUPER_OFFSET … #define EROFS_FEATURE_COMPAT_SB_CHKSUM … #define EROFS_FEATURE_COMPAT_MTIME … #define EROFS_FEATURE_COMPAT_XATTR_FILTER … /* * Any bits that aren't in EROFS_ALL_FEATURE_INCOMPAT should * be incompatible with this kernel version. */ #define EROFS_FEATURE_INCOMPAT_ZERO_PADDING … #define EROFS_FEATURE_INCOMPAT_COMPR_CFGS … #define EROFS_FEATURE_INCOMPAT_BIG_PCLUSTER … #define EROFS_FEATURE_INCOMPAT_CHUNKED_FILE … #define EROFS_FEATURE_INCOMPAT_DEVICE_TABLE … #define EROFS_FEATURE_INCOMPAT_COMPR_HEAD2 … #define EROFS_FEATURE_INCOMPAT_ZTAILPACKING … #define EROFS_FEATURE_INCOMPAT_FRAGMENTS … #define EROFS_FEATURE_INCOMPAT_DEDUPE … #define EROFS_FEATURE_INCOMPAT_XATTR_PREFIXES … #define EROFS_ALL_FEATURE_INCOMPAT … #define EROFS_SB_EXTSLOT_SIZE … struct erofs_deviceslot { … }; #define EROFS_DEVT_SLOT_SIZE … /* erofs on-disk super block (currently 128 bytes) */ struct erofs_super_block { … }; /* * EROFS inode datalayout (i_format in on-disk inode): * 0 - uncompressed flat inode without tail-packing inline data: * 1 - compressed inode with non-compact indexes: * 2 - uncompressed flat inode with tail-packing inline data: * 3 - compressed inode with compact indexes: * 4 - chunk-based inode with (optional) multi-device support: * 5~7 - reserved */ enum { … }; static inline bool erofs_inode_is_data_compressed(unsigned int datamode) { … } /* bit definitions of inode i_format */ #define EROFS_I_VERSION_MASK … #define EROFS_I_DATALAYOUT_MASK … #define EROFS_I_VERSION_BIT … #define EROFS_I_DATALAYOUT_BIT … #define EROFS_I_ALL_BIT … #define EROFS_I_ALL … /* indicate chunk blkbits, thus 'chunksize = blocksize << chunk blkbits' */ #define EROFS_CHUNK_FORMAT_BLKBITS_MASK … /* with chunk indexes or just a 4-byte blkaddr array */ #define EROFS_CHUNK_FORMAT_INDEXES … #define EROFS_CHUNK_FORMAT_ALL … /* 32-byte on-disk inode */ #define EROFS_INODE_LAYOUT_COMPACT … /* 64-byte on-disk inode */ #define EROFS_INODE_LAYOUT_EXTENDED … struct erofs_inode_chunk_info { … }; erofs_inode_i_u; /* 32-byte reduced form of an ondisk inode */ struct erofs_inode_compact { … }; /* 64-byte complete form of an ondisk inode */ struct erofs_inode_extended { … }; /* * inline xattrs (n == i_xattr_icount): * erofs_xattr_ibody_header(1) + (n - 1) * 4 bytes * 12 bytes / \ * / \ * /-----------------------\ * | erofs_xattr_entries+ | * +-----------------------+ * inline xattrs must starts in erofs_xattr_ibody_header, * for read-only fs, no need to introduce h_refcount */ struct erofs_xattr_ibody_header { … }; /* Name indexes */ #define EROFS_XATTR_INDEX_USER … #define EROFS_XATTR_INDEX_POSIX_ACL_ACCESS … #define EROFS_XATTR_INDEX_POSIX_ACL_DEFAULT … #define EROFS_XATTR_INDEX_TRUSTED … #define EROFS_XATTR_INDEX_LUSTRE … #define EROFS_XATTR_INDEX_SECURITY … /* * bit 7 of e_name_index is set when it refers to a long xattr name prefix, * while the remained lower bits represent the index of the prefix. */ #define EROFS_XATTR_LONG_PREFIX … #define EROFS_XATTR_LONG_PREFIX_MASK … #define EROFS_XATTR_FILTER_BITS … #define EROFS_XATTR_FILTER_DEFAULT … #define EROFS_XATTR_FILTER_SEED … /* xattr entry (for both inline & shared xattrs) */ struct erofs_xattr_entry { … }; /* long xattr name prefix */ struct erofs_xattr_long_prefix { … }; static inline unsigned int erofs_xattr_ibody_size(__le16 i_xattr_icount) { … } #define EROFS_XATTR_ALIGN(size) … static inline unsigned int erofs_xattr_entry_size(struct erofs_xattr_entry *e) { … } /* represent a zeroed chunk (hole) */ #define EROFS_NULL_ADDR … /* 4-byte block address array */ #define EROFS_BLOCK_MAP_ENTRY_SIZE … /* 8-byte inode chunk indexes */ struct erofs_inode_chunk_index { … }; /* dirent sorts in alphabet order, thus we can do binary search */ struct erofs_dirent { … } __packed; /* * EROFS file types should match generic FT_* types and * it seems no need to add BUILD_BUG_ONs since potential * unmatchness will break other fses as well... */ #define EROFS_NAME_LEN … /* maximum supported size of a physical compression cluster */ #define Z_EROFS_PCLUSTER_MAX_SIZE … /* available compression algorithm types (for h_algorithmtype) */ enum { … }; #define Z_EROFS_ALL_COMPR_ALGS … /* 14 bytes (+ length field = 16 bytes) */ struct z_erofs_lz4_cfgs { … } __packed; /* 14 bytes (+ length field = 16 bytes) */ struct z_erofs_lzma_cfgs { … } __packed; #define Z_EROFS_LZMA_MAX_DICT_SIZE … /* 6 bytes (+ length field = 8 bytes) */ struct z_erofs_deflate_cfgs { … } __packed; /* 6 bytes (+ length field = 8 bytes) */ struct z_erofs_zstd_cfgs { … } __packed; #define Z_EROFS_ZSTD_MAX_DICT_SIZE … /* * bit 0 : COMPACTED_2B indexes (0 - off; 1 - on) * e.g. for 4k logical cluster size, 4B if compacted 2B is off; * (4B) + 2B + (4B) if compacted 2B is on. * bit 1 : HEAD1 big pcluster (0 - off; 1 - on) * bit 2 : HEAD2 big pcluster (0 - off; 1 - on) * bit 3 : tailpacking inline pcluster (0 - off; 1 - on) * bit 4 : interlaced plain pcluster (0 - off; 1 - on) * bit 5 : fragment pcluster (0 - off; 1 - on) */ #define Z_EROFS_ADVISE_COMPACTED_2B … #define Z_EROFS_ADVISE_BIG_PCLUSTER_1 … #define Z_EROFS_ADVISE_BIG_PCLUSTER_2 … #define Z_EROFS_ADVISE_INLINE_PCLUSTER … #define Z_EROFS_ADVISE_INTERLACED_PCLUSTER … #define Z_EROFS_ADVISE_FRAGMENT_PCLUSTER … #define Z_EROFS_FRAGMENT_INODE_BIT … struct z_erofs_map_header { … }; /* * On-disk logical cluster type: * 0 - literal (uncompressed) lcluster * 1,3 - compressed lcluster (for HEAD lclusters) * 2 - compressed lcluster (for NONHEAD lclusters) * * In detail, * 0 - literal (uncompressed) lcluster, * di_advise = 0 * di_clusterofs = the literal data offset of the lcluster * di_blkaddr = the blkaddr of the literal pcluster * * 1,3 - compressed lcluster (for HEAD lclusters) * di_advise = 1 or 3 * di_clusterofs = the decompressed data offset of the lcluster * di_blkaddr = the blkaddr of the compressed pcluster * * 2 - compressed lcluster (for NONHEAD lclusters) * di_advise = 2 * di_clusterofs = * the decompressed data offset in its own HEAD lcluster * di_u.delta[0] = distance to this HEAD lcluster * di_u.delta[1] = distance to the next HEAD lcluster */ enum { … }; #define Z_EROFS_LI_LCLUSTER_TYPE_MASK … /* (noncompact only, HEAD) This pcluster refers to partial decompressed data */ #define Z_EROFS_LI_PARTIAL_REF … /* * D0_CBLKCNT will be marked _only_ at the 1st non-head lcluster to store the * compressed block count of a compressed extent (in logical clusters, aka. * block count of a pcluster). */ #define Z_EROFS_LI_D0_CBLKCNT … struct z_erofs_lcluster_index { … }; #define Z_EROFS_FULL_INDEX_ALIGN(end) … /* check the EROFS on-disk layout strictly at compile time */ static inline void erofs_check_ondisk_layout_definitions(void) { … } #endif