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