0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef __EROFS_FS_H
0010 #define __EROFS_FS_H
0011
0012 #define EROFS_SUPER_OFFSET 1024
0013
0014 #define EROFS_FEATURE_COMPAT_SB_CHKSUM 0x00000001
0015 #define EROFS_FEATURE_COMPAT_MTIME 0x00000002
0016
0017
0018
0019
0020
0021 #define EROFS_FEATURE_INCOMPAT_ZERO_PADDING 0x00000001
0022 #define EROFS_FEATURE_INCOMPAT_COMPR_CFGS 0x00000002
0023 #define EROFS_FEATURE_INCOMPAT_BIG_PCLUSTER 0x00000002
0024 #define EROFS_FEATURE_INCOMPAT_CHUNKED_FILE 0x00000004
0025 #define EROFS_FEATURE_INCOMPAT_DEVICE_TABLE 0x00000008
0026 #define EROFS_FEATURE_INCOMPAT_COMPR_HEAD2 0x00000008
0027 #define EROFS_FEATURE_INCOMPAT_ZTAILPACKING 0x00000010
0028 #define EROFS_ALL_FEATURE_INCOMPAT \
0029 (EROFS_FEATURE_INCOMPAT_ZERO_PADDING | \
0030 EROFS_FEATURE_INCOMPAT_COMPR_CFGS | \
0031 EROFS_FEATURE_INCOMPAT_BIG_PCLUSTER | \
0032 EROFS_FEATURE_INCOMPAT_CHUNKED_FILE | \
0033 EROFS_FEATURE_INCOMPAT_DEVICE_TABLE | \
0034 EROFS_FEATURE_INCOMPAT_COMPR_HEAD2 | \
0035 EROFS_FEATURE_INCOMPAT_ZTAILPACKING)
0036
0037 #define EROFS_SB_EXTSLOT_SIZE 16
0038
0039 struct erofs_deviceslot {
0040 u8 tag[64];
0041 __le32 blocks;
0042 __le32 mapped_blkaddr;
0043 u8 reserved[56];
0044 };
0045 #define EROFS_DEVT_SLOT_SIZE sizeof(struct erofs_deviceslot)
0046
0047
0048 struct erofs_super_block {
0049 __le32 magic;
0050 __le32 checksum;
0051 __le32 feature_compat;
0052 __u8 blkszbits;
0053 __u8 sb_extslots;
0054
0055 __le16 root_nid;
0056 __le64 inos;
0057
0058 __le64 build_time;
0059 __le32 build_time_nsec;
0060 __le32 blocks;
0061 __le32 meta_blkaddr;
0062 __le32 xattr_blkaddr;
0063 __u8 uuid[16];
0064 __u8 volume_name[16];
0065 __le32 feature_incompat;
0066 union {
0067
0068 __le16 available_compr_algs;
0069
0070 __le16 lz4_max_distance;
0071 } __packed u1;
0072 __le16 extra_devices;
0073 __le16 devt_slotoff;
0074 __u8 reserved2[38];
0075 };
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091 enum {
0092 EROFS_INODE_FLAT_PLAIN = 0,
0093 EROFS_INODE_FLAT_COMPRESSION_LEGACY = 1,
0094 EROFS_INODE_FLAT_INLINE = 2,
0095 EROFS_INODE_FLAT_COMPRESSION = 3,
0096 EROFS_INODE_CHUNK_BASED = 4,
0097 EROFS_INODE_DATALAYOUT_MAX
0098 };
0099
0100 static inline bool erofs_inode_is_data_compressed(unsigned int datamode)
0101 {
0102 return datamode == EROFS_INODE_FLAT_COMPRESSION ||
0103 datamode == EROFS_INODE_FLAT_COMPRESSION_LEGACY;
0104 }
0105
0106
0107 #define EROFS_I_VERSION_BITS 1
0108 #define EROFS_I_DATALAYOUT_BITS 3
0109
0110 #define EROFS_I_VERSION_BIT 0
0111 #define EROFS_I_DATALAYOUT_BIT 1
0112
0113 #define EROFS_I_ALL \
0114 ((1 << (EROFS_I_DATALAYOUT_BIT + EROFS_I_DATALAYOUT_BITS)) - 1)
0115
0116
0117 #define EROFS_CHUNK_FORMAT_BLKBITS_MASK 0x001F
0118
0119 #define EROFS_CHUNK_FORMAT_INDEXES 0x0020
0120
0121 #define EROFS_CHUNK_FORMAT_ALL \
0122 (EROFS_CHUNK_FORMAT_BLKBITS_MASK | EROFS_CHUNK_FORMAT_INDEXES)
0123
0124 struct erofs_inode_chunk_info {
0125 __le16 format;
0126 __le16 reserved;
0127 };
0128
0129
0130 struct erofs_inode_compact {
0131 __le16 i_format;
0132
0133
0134 __le16 i_xattr_icount;
0135 __le16 i_mode;
0136 __le16 i_nlink;
0137 __le32 i_size;
0138 __le32 i_reserved;
0139 union {
0140
0141 __le32 compressed_blocks;
0142
0143 __le32 raw_blkaddr;
0144
0145
0146 __le32 rdev;
0147
0148
0149 struct erofs_inode_chunk_info c;
0150 } i_u;
0151 __le32 i_ino;
0152 __le16 i_uid;
0153 __le16 i_gid;
0154 __le32 i_reserved2;
0155 };
0156
0157
0158 #define EROFS_INODE_LAYOUT_COMPACT 0
0159
0160 #define EROFS_INODE_LAYOUT_EXTENDED 1
0161
0162
0163 struct erofs_inode_extended {
0164 __le16 i_format;
0165
0166
0167 __le16 i_xattr_icount;
0168 __le16 i_mode;
0169 __le16 i_reserved;
0170 __le64 i_size;
0171 union {
0172
0173 __le32 compressed_blocks;
0174
0175 __le32 raw_blkaddr;
0176
0177
0178 __le32 rdev;
0179
0180
0181 struct erofs_inode_chunk_info c;
0182 } i_u;
0183
0184
0185 __le32 i_ino;
0186
0187 __le32 i_uid;
0188 __le32 i_gid;
0189 __le64 i_mtime;
0190 __le32 i_mtime_nsec;
0191 __le32 i_nlink;
0192 __u8 i_reserved2[16];
0193 };
0194
0195 #define EROFS_MAX_SHARED_XATTRS (128)
0196
0197 #define EROFS_SHARED_XATTR_EXTENT (255)
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210 struct erofs_xattr_ibody_header {
0211 __le32 h_reserved;
0212 __u8 h_shared_count;
0213 __u8 h_reserved2[7];
0214 __le32 h_shared_xattrs[];
0215 };
0216
0217
0218 #define EROFS_XATTR_INDEX_USER 1
0219 #define EROFS_XATTR_INDEX_POSIX_ACL_ACCESS 2
0220 #define EROFS_XATTR_INDEX_POSIX_ACL_DEFAULT 3
0221 #define EROFS_XATTR_INDEX_TRUSTED 4
0222 #define EROFS_XATTR_INDEX_LUSTRE 5
0223 #define EROFS_XATTR_INDEX_SECURITY 6
0224
0225
0226 struct erofs_xattr_entry {
0227 __u8 e_name_len;
0228 __u8 e_name_index;
0229 __le16 e_value_size;
0230
0231 char e_name[];
0232 };
0233
0234 static inline unsigned int erofs_xattr_ibody_size(__le16 i_xattr_icount)
0235 {
0236 if (!i_xattr_icount)
0237 return 0;
0238
0239 return sizeof(struct erofs_xattr_ibody_header) +
0240 sizeof(__u32) * (le16_to_cpu(i_xattr_icount) - 1);
0241 }
0242
0243 #define EROFS_XATTR_ALIGN(size) round_up(size, sizeof(struct erofs_xattr_entry))
0244
0245 static inline unsigned int erofs_xattr_entry_size(struct erofs_xattr_entry *e)
0246 {
0247 return EROFS_XATTR_ALIGN(sizeof(struct erofs_xattr_entry) +
0248 e->e_name_len + le16_to_cpu(e->e_value_size));
0249 }
0250
0251
0252 #define EROFS_NULL_ADDR -1
0253
0254
0255 #define EROFS_BLOCK_MAP_ENTRY_SIZE sizeof(__le32)
0256
0257
0258 struct erofs_inode_chunk_index {
0259 __le16 advise;
0260 __le16 device_id;
0261 __le32 blkaddr;
0262 };
0263
0264
0265 #define Z_EROFS_PCLUSTER_MAX_SIZE (1024 * 1024)
0266
0267
0268 enum {
0269 Z_EROFS_COMPRESSION_LZ4 = 0,
0270 Z_EROFS_COMPRESSION_LZMA = 1,
0271 Z_EROFS_COMPRESSION_MAX
0272 };
0273 #define Z_EROFS_ALL_COMPR_ALGS ((1 << Z_EROFS_COMPRESSION_MAX) - 1)
0274
0275
0276 struct z_erofs_lz4_cfgs {
0277 __le16 max_distance;
0278 __le16 max_pclusterblks;
0279 u8 reserved[10];
0280 } __packed;
0281
0282
0283 struct z_erofs_lzma_cfgs {
0284 __le32 dict_size;
0285 __le16 format;
0286 u8 reserved[8];
0287 } __packed;
0288
0289 #define Z_EROFS_LZMA_MAX_DICT_SIZE (8 * Z_EROFS_PCLUSTER_MAX_SIZE)
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299 #define Z_EROFS_ADVISE_COMPACTED_2B 0x0001
0300 #define Z_EROFS_ADVISE_BIG_PCLUSTER_1 0x0002
0301 #define Z_EROFS_ADVISE_BIG_PCLUSTER_2 0x0004
0302 #define Z_EROFS_ADVISE_INLINE_PCLUSTER 0x0008
0303
0304 struct z_erofs_map_header {
0305 __le16 h_reserved1;
0306
0307 __le16 h_idata_size;
0308 __le16 h_advise;
0309
0310
0311
0312
0313 __u8 h_algorithmtype;
0314
0315
0316
0317
0318 __u8 h_clusterbits;
0319 };
0320
0321 #define Z_EROFS_VLE_LEGACY_HEADER_PADDING 8
0322
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346
0347 enum {
0348 Z_EROFS_VLE_CLUSTER_TYPE_PLAIN = 0,
0349 Z_EROFS_VLE_CLUSTER_TYPE_HEAD1 = 1,
0350 Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD = 2,
0351 Z_EROFS_VLE_CLUSTER_TYPE_HEAD2 = 3,
0352 Z_EROFS_VLE_CLUSTER_TYPE_MAX
0353 };
0354
0355 #define Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS 2
0356 #define Z_EROFS_VLE_DI_CLUSTER_TYPE_BIT 0
0357
0358
0359
0360
0361
0362
0363 #define Z_EROFS_VLE_DI_D0_CBLKCNT (1 << 11)
0364
0365 struct z_erofs_vle_decompressed_index {
0366 __le16 di_advise;
0367
0368 __le16 di_clusterofs;
0369
0370 union {
0371
0372 __le32 blkaddr;
0373
0374
0375
0376
0377
0378 __le16 delta[2];
0379 } di_u;
0380 };
0381
0382 #define Z_EROFS_VLE_LEGACY_INDEX_ALIGN(size) \
0383 (round_up(size, sizeof(struct z_erofs_vle_decompressed_index)) + \
0384 sizeof(struct z_erofs_map_header) + Z_EROFS_VLE_LEGACY_HEADER_PADDING)
0385
0386
0387 struct erofs_dirent {
0388 __le64 nid;
0389 __le16 nameoff;
0390 __u8 file_type;
0391 __u8 reserved;
0392 } __packed;
0393
0394
0395
0396
0397
0398
0399
0400 #define EROFS_NAME_LEN 255
0401
0402
0403 static inline void erofs_check_ondisk_layout_definitions(void)
0404 {
0405 BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128);
0406 BUILD_BUG_ON(sizeof(struct erofs_inode_compact) != 32);
0407 BUILD_BUG_ON(sizeof(struct erofs_inode_extended) != 64);
0408 BUILD_BUG_ON(sizeof(struct erofs_xattr_ibody_header) != 12);
0409 BUILD_BUG_ON(sizeof(struct erofs_xattr_entry) != 4);
0410 BUILD_BUG_ON(sizeof(struct erofs_inode_chunk_info) != 4);
0411 BUILD_BUG_ON(sizeof(struct erofs_inode_chunk_index) != 8);
0412 BUILD_BUG_ON(sizeof(struct z_erofs_map_header) != 8);
0413 BUILD_BUG_ON(sizeof(struct z_erofs_vle_decompressed_index) != 8);
0414 BUILD_BUG_ON(sizeof(struct erofs_dirent) != 12);
0415
0416 BUILD_BUG_ON(sizeof(struct erofs_inode_chunk_index) !=
0417 sizeof(struct z_erofs_vle_decompressed_index));
0418 BUILD_BUG_ON(sizeof(struct erofs_deviceslot) != 128);
0419
0420 BUILD_BUG_ON(BIT(Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS) <
0421 Z_EROFS_VLE_CLUSTER_TYPE_MAX - 1);
0422 }
0423
0424 #endif