1 /*- 2 * modified for EXT2FS support in Lites 1.1 3 * 4 * Aug 1995, Godmar Back (gback@cs.utah.edu) 5 * University of Utah, Department of Computer Science 6 * 7 * $FreeBSD$ 8 */ 9 /*- 10 * SPDX-License-Identifier: BSD-2-Clause 11 * 12 * Copyright (c) 2009 Aditya Sarawgi 13 * All rights reserved. 14 * 15 * Redistribution and use in source and binary forms, with or without 16 * modification, are permitted provided that the following conditions 17 * are met: 18 * 1. Redistributions of source code must retain the above copyright 19 * notice, this list of conditions and the following disclaimer. 20 * 2. Redistributions in binary form must reproduce the above copyright 21 * notice, this list of conditions and the following disclaimer in the 22 * documentation and/or other materials provided with the distribution. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * 37 */ 38 39 #ifndef _FS_EXT2FS_EXT2FS_H_ 40 #define _FS_EXT2FS_EXT2FS_H_ 41 42 #include <sys/types.h> 43 44 /* 45 * Super block for an ext2fs file system. 46 */ 47 struct ext2fs { 48 uint32_t e2fs_icount; /* Inode count */ 49 uint32_t e2fs_bcount; /* blocks count */ 50 uint32_t e2fs_rbcount; /* reserved blocks count */ 51 uint32_t e2fs_fbcount; /* free blocks count */ 52 uint32_t e2fs_ficount; /* free inodes count */ 53 uint32_t e2fs_first_dblock; /* first data block */ 54 uint32_t e2fs_log_bsize; /* block size = 1024*(2^e2fs_log_bsize) */ 55 uint32_t e2fs_log_fsize; /* fragment size */ 56 uint32_t e2fs_bpg; /* blocks per group */ 57 uint32_t e2fs_fpg; /* frags per group */ 58 uint32_t e2fs_ipg; /* inodes per group */ 59 uint32_t e2fs_mtime; /* mount time */ 60 uint32_t e2fs_wtime; /* write time */ 61 uint16_t e2fs_mnt_count; /* mount count */ 62 uint16_t e2fs_max_mnt_count; /* max mount count */ 63 uint16_t e2fs_magic; /* magic number */ 64 uint16_t e2fs_state; /* file system state */ 65 uint16_t e2fs_beh; /* behavior on errors */ 66 uint16_t e2fs_minrev; /* minor revision level */ 67 uint32_t e2fs_lastfsck; /* time of last fsck */ 68 uint32_t e2fs_fsckintv; /* max time between fscks */ 69 uint32_t e2fs_creator; /* creator OS */ 70 uint32_t e2fs_rev; /* revision level */ 71 uint16_t e2fs_ruid; /* default uid for reserved blocks */ 72 uint16_t e2fs_rgid; /* default gid for reserved blocks */ 73 /* EXT2_DYNAMIC_REV superblocks */ 74 uint32_t e2fs_first_ino; /* first non-reserved inode */ 75 uint16_t e2fs_inode_size; /* size of inode structure */ 76 uint16_t e2fs_block_group_nr; /* block grp number of this sblk*/ 77 uint32_t e2fs_features_compat; /* compatible feature set */ 78 uint32_t e2fs_features_incompat; /* incompatible feature set */ 79 uint32_t e2fs_features_rocompat; /* RO-compatible feature set */ 80 uint8_t e2fs_uuid[16]; /* 128-bit uuid for volume */ 81 char e2fs_vname[16]; /* volume name */ 82 char e2fs_fsmnt[64]; /* name mounted on */ 83 uint32_t e2fs_algo; /* For compression */ 84 uint8_t e2fs_prealloc; /* # of blocks for old prealloc */ 85 uint8_t e2fs_dir_prealloc; /* # of blocks for old prealloc dirs */ 86 uint16_t e2fs_reserved_ngdb; /* # of reserved gd blocks for resize */ 87 char e3fs_journal_uuid[16]; /* uuid of journal superblock */ 88 uint32_t e3fs_journal_inum; /* inode number of journal file */ 89 uint32_t e3fs_journal_dev; /* device number of journal file */ 90 uint32_t e3fs_last_orphan; /* start of list of inodes to delete */ 91 uint32_t e3fs_hash_seed[4]; /* HTREE hash seed */ 92 char e3fs_def_hash_version;/* Default hash version to use */ 93 char e3fs_jnl_backup_type; 94 uint16_t e3fs_desc_size; /* size of group descriptor */ 95 uint32_t e3fs_default_mount_opts; 96 uint32_t e3fs_first_meta_bg; /* First metablock block group */ 97 uint32_t e3fs_mkfs_time; /* when the fs was created */ 98 uint32_t e3fs_jnl_blks[17]; /* backup of the journal inode */ 99 uint32_t e4fs_bcount_hi; /* high bits of blocks count */ 100 uint32_t e4fs_rbcount_hi; /* high bits of reserved blocks count */ 101 uint32_t e4fs_fbcount_hi; /* high bits of free blocks count */ 102 uint16_t e4fs_min_extra_isize; /* all inodes have some bytes */ 103 uint16_t e4fs_want_extra_isize;/* inodes must reserve some bytes */ 104 uint32_t e4fs_flags; /* miscellaneous flags */ 105 uint16_t e4fs_raid_stride; /* RAID stride */ 106 uint16_t e4fs_mmpintv; /* seconds to wait in MMP checking */ 107 uint64_t e4fs_mmpblk; /* block for multi-mount protection */ 108 uint32_t e4fs_raid_stripe_wid; /* blocks on data disks (N * stride) */ 109 uint8_t e4fs_log_gpf; /* FLEX_BG group size */ 110 uint8_t e4fs_chksum_type; /* metadata checksum algorithm used */ 111 uint8_t e4fs_encrypt; /* versioning level for encryption */ 112 uint8_t e4fs_reserved_pad; 113 uint64_t e4fs_kbytes_written; /* number of lifetime kilobytes */ 114 uint32_t e4fs_snapinum; /* inode number of active snapshot */ 115 uint32_t e4fs_snapid; /* sequential ID of active snapshot */ 116 uint64_t e4fs_snaprbcount; /* reserved blocks for active snapshot */ 117 uint32_t e4fs_snaplist; /* inode number for on-disk snapshot */ 118 uint32_t e4fs_errcount; /* number of file system errors */ 119 uint32_t e4fs_first_errtime; /* first time an error happened */ 120 uint32_t e4fs_first_errino; /* inode involved in first error */ 121 uint64_t e4fs_first_errblk; /* block involved of first error */ 122 uint8_t e4fs_first_errfunc[32];/* function where error happened */ 123 uint32_t e4fs_first_errline; /* line number where error happened */ 124 uint32_t e4fs_last_errtime; /* most recent time of an error */ 125 uint32_t e4fs_last_errino; /* inode involved in last error */ 126 uint32_t e4fs_last_errline; /* line number where error happened */ 127 uint64_t e4fs_last_errblk; /* block involved of last error */ 128 uint8_t e4fs_last_errfunc[32]; /* function where error happened */ 129 uint8_t e4fs_mount_opts[64]; 130 uint32_t e4fs_usrquota_inum; /* inode for tracking user quota */ 131 uint32_t e4fs_grpquota_inum; /* inode for tracking group quota */ 132 uint32_t e4fs_overhead_clusters;/* overhead blocks/clusters */ 133 uint32_t e4fs_backup_bgs[2]; /* groups with sparse_super2 SBs */ 134 uint8_t e4fs_encrypt_algos[4];/* encryption algorithms in use */ 135 uint8_t e4fs_encrypt_pw_salt[16];/* salt used for string2key */ 136 uint32_t e4fs_lpf_ino; /* location of the lost+found inode */ 137 uint32_t e4fs_proj_quota_inum; /* inode for tracking project quota */ 138 uint32_t e4fs_chksum_seed; /* checksum seed */ 139 uint32_t e4fs_reserved[98]; /* padding to the end of the block */ 140 uint32_t e4fs_sbchksum; /* superblock checksum */ 141 }; 142 143 /* 144 * The path name on which the file system is mounted is maintained 145 * in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in 146 * the super block for this name. 147 */ 148 #define MAXMNTLEN 512 149 150 /* 151 * In-Memory Superblock 152 */ 153 154 struct m_ext2fs { 155 struct ext2fs * e2fs; 156 char e2fs_fsmnt[MAXMNTLEN];/* name mounted on */ 157 char e2fs_ronly; /* mounted read-only flag */ 158 char e2fs_fmod; /* super block modified flag */ 159 uint64_t e2fs_bcount; /* blocks count */ 160 uint64_t e2fs_rbcount; /* reserved blocks count */ 161 uint64_t e2fs_fbcount; /* free blocks count */ 162 uint32_t e2fs_ficount; /* free inodes count */ 163 uint32_t e2fs_bsize; /* Block size */ 164 uint32_t e2fs_bshift; /* calc of logical block no */ 165 uint32_t e2fs_bpg; /* Number of blocks per group */ 166 int64_t e2fs_qbmask; /* = s_blocksize -1 */ 167 uint32_t e2fs_fsbtodb; /* Shift to get disk block */ 168 uint32_t e2fs_ipg; /* Number of inodes per group */ 169 uint32_t e2fs_ipb; /* Number of inodes per block */ 170 uint32_t e2fs_itpg; /* Number of inode table per group */ 171 uint32_t e2fs_fsize; /* Size of fragments per block */ 172 uint32_t e2fs_fpb; /* Number of fragments per block */ 173 uint32_t e2fs_fpg; /* Number of fragments per group */ 174 uint32_t e2fs_gdbcount; /* Number of group descriptors */ 175 uint32_t e2fs_gcount; /* Number of groups */ 176 uint32_t e2fs_isize; /* Size of inode */ 177 uint32_t e2fs_total_dir; /* Total number of directories */ 178 uint8_t *e2fs_contigdirs; /* (u) # of contig. allocated dirs */ 179 char e2fs_wasvalid; /* valid at mount time */ 180 off_t e2fs_maxfilesize; 181 struct ext2_gd *e2fs_gd; /* Group Descriptors */ 182 int32_t e2fs_contigsumsize; /* size of cluster summary array */ 183 int32_t *e2fs_maxcluster; /* max cluster in each cyl group */ 184 struct csum *e2fs_clustersum; /* cluster summary in each cyl group */ 185 int32_t e2fs_uhash; /* 3 if hash should be signed, 0 if not */ 186 uint32_t e2fs_csum_seed; /* sb checksum seed */ 187 uint64_t e2fs_maxsymlinklen; /* max size of short symlink */ 188 }; 189 190 /* cluster summary information */ 191 192 struct csum { 193 int8_t cs_init; /* cluster summary has been initialized */ 194 int32_t *cs_sum; /* cluster summary array */ 195 }; 196 197 /* 198 * The second extended file system magic number 199 */ 200 #define E2FS_MAGIC 0xEF53 201 202 /* 203 * Revision levels 204 */ 205 #define E2FS_REV0 0 /* The good old (original) format */ 206 #define E2FS_REV1 1 /* V2 format w/ dynamic inode sizes */ 207 208 #define E2FS_REV0_INODE_SIZE 128 209 210 /* 211 * Metadata checksum algorithm codes 212 */ 213 #define EXT4_CRC32C_CHKSUM 1 214 215 /* 216 * compatible/incompatible features 217 */ 218 #define EXT2F_COMPAT_PREALLOC 0x0001 219 #define EXT2F_COMPAT_IMAGIC_INODES 0x0002 220 #define EXT2F_COMPAT_HASJOURNAL 0x0004 221 #define EXT2F_COMPAT_EXT_ATTR 0x0008 222 #define EXT2F_COMPAT_RESIZE 0x0010 223 #define EXT2F_COMPAT_DIRHASHINDEX 0x0020 224 #define EXT2F_COMPAT_LAZY_BG 0x0040 225 #define EXT2F_COMPAT_EXCLUDE_BITMAP 0x0100 226 #define EXT2F_COMPAT_SPARSESUPER2 0x0200 227 228 #define EXT2F_ROCOMPAT_SPARSESUPER 0x0001 229 #define EXT2F_ROCOMPAT_LARGEFILE 0x0002 230 #define EXT2F_ROCOMPAT_BTREE_DIR 0x0004 231 #define EXT2F_ROCOMPAT_HUGE_FILE 0x0008 232 #define EXT2F_ROCOMPAT_GDT_CSUM 0x0010 233 #define EXT2F_ROCOMPAT_DIR_NLINK 0x0020 234 #define EXT2F_ROCOMPAT_EXTRA_ISIZE 0x0040 235 #define EXT2F_ROCOMPAT_HAS_SNAPSHOT 0x0080 236 #define EXT2F_ROCOMPAT_QUOTA 0x0100 237 #define EXT2F_ROCOMPAT_BIGALLOC 0x0200 238 #define EXT2F_ROCOMPAT_METADATA_CKSUM 0x0400 239 #define EXT2F_ROCOMPAT_REPLICA 0x0800 240 #define EXT2F_ROCOMPAT_READONLY 0x1000 241 #define EXT2F_ROCOMPAT_PROJECT 0x2000 242 243 #define EXT2F_INCOMPAT_COMP 0x0001 244 #define EXT2F_INCOMPAT_FTYPE 0x0002 245 #define EXT2F_INCOMPAT_RECOVER 0x0004 246 #define EXT2F_INCOMPAT_JOURNAL_DEV 0x0008 247 #define EXT2F_INCOMPAT_META_BG 0x0010 248 #define EXT2F_INCOMPAT_EXTENTS 0x0040 249 #define EXT2F_INCOMPAT_64BIT 0x0080 250 #define EXT2F_INCOMPAT_MMP 0x0100 251 #define EXT2F_INCOMPAT_FLEX_BG 0x0200 252 #define EXT2F_INCOMPAT_EA_INODE 0x0400 253 #define EXT2F_INCOMPAT_DIRDATA 0x1000 254 #define EXT2F_INCOMPAT_CSUM_SEED 0x2000 255 #define EXT2F_INCOMPAT_LARGEDIR 0x4000 256 #define EXT2F_INCOMPAT_INLINE_DATA 0x8000 257 #define EXT2F_INCOMPAT_ENCRYPT 0x10000 258 259 struct ext2_feature 260 { 261 int mask; 262 const char *name; 263 }; 264 265 static const struct ext2_feature compat[] = { 266 { EXT2F_COMPAT_PREALLOC, "dir_prealloc" }, 267 { EXT2F_COMPAT_IMAGIC_INODES, "imagic_inodes" }, 268 { EXT2F_COMPAT_HASJOURNAL, "has_journal" }, 269 { EXT2F_COMPAT_EXT_ATTR, "ext_attr" }, 270 { EXT2F_COMPAT_RESIZE, "resize_inode" }, 271 { EXT2F_COMPAT_DIRHASHINDEX, "dir_index" }, 272 { EXT2F_COMPAT_EXCLUDE_BITMAP, "snapshot_bitmap" }, 273 { EXT2F_COMPAT_SPARSESUPER2, "sparse_super2" } 274 }; 275 276 static const struct ext2_feature ro_compat[] = { 277 { EXT2F_ROCOMPAT_SPARSESUPER, "sparse_super" }, 278 { EXT2F_ROCOMPAT_LARGEFILE, "large_file" }, 279 { EXT2F_ROCOMPAT_BTREE_DIR, "btree_dir" }, 280 { EXT2F_ROCOMPAT_HUGE_FILE, "huge_file" }, 281 { EXT2F_ROCOMPAT_GDT_CSUM, "uninit_groups" }, 282 { EXT2F_ROCOMPAT_DIR_NLINK, "dir_nlink" }, 283 { EXT2F_ROCOMPAT_EXTRA_ISIZE, "extra_isize" }, 284 { EXT2F_ROCOMPAT_HAS_SNAPSHOT, "snapshot" }, 285 { EXT2F_ROCOMPAT_QUOTA, "quota" }, 286 { EXT2F_ROCOMPAT_BIGALLOC, "bigalloc" }, 287 { EXT2F_ROCOMPAT_METADATA_CKSUM, "metadata_csum" }, 288 { EXT2F_ROCOMPAT_REPLICA, "replica" }, 289 { EXT2F_ROCOMPAT_READONLY, "ro" }, 290 { EXT2F_ROCOMPAT_PROJECT, "project" } 291 }; 292 293 static const struct ext2_feature incompat[] = { 294 { EXT2F_INCOMPAT_COMP, "compression" }, 295 { EXT2F_INCOMPAT_FTYPE, "filetype" }, 296 { EXT2F_INCOMPAT_RECOVER, "needs_recovery" }, 297 { EXT2F_INCOMPAT_JOURNAL_DEV, "journal_dev" }, 298 { EXT2F_INCOMPAT_META_BG, "meta_bg" }, 299 { EXT2F_INCOMPAT_EXTENTS, "extents" }, 300 { EXT2F_INCOMPAT_64BIT, "64bit" }, 301 { EXT2F_INCOMPAT_MMP, "mmp" }, 302 { EXT2F_INCOMPAT_FLEX_BG, "flex_bg" }, 303 { EXT2F_INCOMPAT_EA_INODE, "ea_inode" }, 304 { EXT2F_INCOMPAT_DIRDATA, "dirdata" }, 305 { EXT2F_INCOMPAT_CSUM_SEED, "metadata_csum_seed" }, 306 { EXT2F_INCOMPAT_LARGEDIR, "large_dir" }, 307 { EXT2F_INCOMPAT_INLINE_DATA, "inline_data" }, 308 { EXT2F_INCOMPAT_ENCRYPT, "encrypt" } 309 }; 310 311 /* 312 * Features supported in this implementation 313 * 314 * We support the following REV1 features: 315 * - EXT2F_ROCOMPAT_SPARSESUPER 316 * - EXT2F_ROCOMPAT_LARGEFILE 317 * - EXT2F_ROCOMPAT_EXTRA_ISIZE 318 * - EXT2F_INCOMPAT_FTYPE 319 * 320 * We partially (read-only) support the following EXT4 features: 321 * - EXT2F_ROCOMPAT_HUGE_FILE 322 * - EXT2F_INCOMPAT_EXTENTS 323 * 324 */ 325 #define EXT2F_COMPAT_SUPP EXT2F_COMPAT_DIRHASHINDEX 326 #define EXT2F_ROCOMPAT_SUPP (EXT2F_ROCOMPAT_SPARSESUPER | \ 327 EXT2F_ROCOMPAT_LARGEFILE | \ 328 EXT2F_ROCOMPAT_GDT_CSUM | \ 329 EXT2F_ROCOMPAT_METADATA_CKSUM | \ 330 EXT2F_ROCOMPAT_DIR_NLINK | \ 331 EXT2F_ROCOMPAT_HUGE_FILE | \ 332 EXT2F_ROCOMPAT_EXTRA_ISIZE) 333 #define EXT2F_INCOMPAT_SUPP (EXT2F_INCOMPAT_FTYPE | \ 334 EXT2F_INCOMPAT_META_BG | \ 335 EXT2F_INCOMPAT_EXTENTS | \ 336 EXT2F_INCOMPAT_64BIT | \ 337 EXT2F_INCOMPAT_FLEX_BG | \ 338 EXT2F_INCOMPAT_CSUM_SEED) 339 340 /* Assume that user mode programs are passing in an ext2fs superblock, not 341 * a kernel struct super_block. This will allow us to call the feature-test 342 * macros from user land. */ 343 #define EXT2_SB(sb) (sb) 344 345 /* 346 * Feature set definitions 347 */ 348 #define EXT2_HAS_COMPAT_FEATURE(sb,mask) \ 349 ( le32toh(EXT2_SB(sb)->e2fs->e2fs_features_compat) & mask) 350 #define EXT2_HAS_RO_COMPAT_FEATURE(sb,mask) \ 351 ( le32toh(EXT2_SB(sb)->e2fs->e2fs_features_rocompat) & mask) 352 #define EXT2_HAS_INCOMPAT_FEATURE(sb,mask) \ 353 ( le32toh(EXT2_SB(sb)->e2fs->e2fs_features_incompat) & mask) 354 355 /* 356 * File clean flags 357 */ 358 #define E2FS_ISCLEAN 0x0001 /* Unmounted cleanly */ 359 #define E2FS_ERRORS 0x0002 /* Errors detected */ 360 361 /* 362 * Filesystem miscellaneous flags 363 */ 364 #define E2FS_SIGNED_HASH 0x0001 365 #define E2FS_UNSIGNED_HASH 0x0002 366 367 #define EXT2_BG_INODE_UNINIT 0x0001 /* Inode table/bitmap not in use */ 368 #define EXT2_BG_BLOCK_UNINIT 0x0002 /* Block bitmap not in use */ 369 #define EXT2_BG_INODE_ZEROED 0x0004 /* On-disk itable initialized to zero */ 370 371 /* ext2 file system block group descriptor */ 372 373 struct ext2_gd { 374 uint32_t ext2bgd_b_bitmap; /* blocks bitmap block */ 375 uint32_t ext2bgd_i_bitmap; /* inodes bitmap block */ 376 uint32_t ext2bgd_i_tables; /* inodes table block */ 377 uint16_t ext2bgd_nbfree; /* number of free blocks */ 378 uint16_t ext2bgd_nifree; /* number of free inodes */ 379 uint16_t ext2bgd_ndirs; /* number of directories */ 380 uint16_t ext4bgd_flags; /* block group flags */ 381 uint32_t ext4bgd_x_bitmap; /* snapshot exclusion bitmap loc. */ 382 uint16_t ext4bgd_b_bmap_csum; /* block bitmap checksum */ 383 uint16_t ext4bgd_i_bmap_csum; /* inode bitmap checksum */ 384 uint16_t ext4bgd_i_unused; /* unused inode count */ 385 uint16_t ext4bgd_csum; /* group descriptor checksum */ 386 uint32_t ext4bgd_b_bitmap_hi; /* high bits of blocks bitmap block */ 387 uint32_t ext4bgd_i_bitmap_hi; /* high bits of inodes bitmap block */ 388 uint32_t ext4bgd_i_tables_hi; /* high bits of inodes table block */ 389 uint16_t ext4bgd_nbfree_hi; /* high bits of number of free blocks */ 390 uint16_t ext4bgd_nifree_hi; /* high bits of number of free inodes */ 391 uint16_t ext4bgd_ndirs_hi; /* high bits of number of directories */ 392 uint16_t ext4bgd_i_unused_hi; /* high bits of unused inode count */ 393 uint32_t ext4bgd_x_bitmap_hi; /* high bits of snapshot exclusion */ 394 uint16_t ext4bgd_b_bmap_csum_hi;/* high bits of block bitmap checksum */ 395 uint16_t ext4bgd_i_bmap_csum_hi;/* high bits of inode bitmap checksum */ 396 uint32_t ext4bgd_reserved; 397 }; 398 399 #define E2FS_REV0_GD_SIZE (sizeof(struct ext2_gd) / 2) 400 #define E2FS_64BIT_GD_SIZE (sizeof(struct ext2_gd)) 401 402 /* 403 * Macro-instructions used to manage several block sizes 404 */ 405 #define EXT2_MIN_BLOCK_LOG_SIZE 10 406 #define EXT2_BLOCK_SIZE(s) ((s)->e2fs_bsize) 407 #define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof(uint32_t)) 408 #define EXT2_INODE_SIZE(s) (EXT2_SB(s)->e2fs_isize) 409 410 /* 411 * Macro-instructions used to manage fragments 412 */ 413 #define EXT2_MIN_FRAG_SIZE 1024 414 #define EXT2_MIN_FRAG_LOG_SIZE 10 415 #define EXT2_MAX_FRAG_LOG_SIZE 30 416 #define EXT2_FRAG_SIZE(s) (EXT2_SB(s)->e2fs_fsize) 417 #define EXT2_FRAGS_PER_BLOCK(s) (EXT2_SB(s)->e2fs_fpb) 418 419 /* 420 * Macro-instructions used to manage group descriptors 421 */ 422 #define EXT2_BLOCKS_PER_GROUP(s) (EXT2_SB(s)->e2fs_bpg) 423 #define EXT2_DESCS_PER_BLOCK(s) (EXT2_HAS_INCOMPAT_FEATURE((s), \ 424 EXT2F_INCOMPAT_64BIT) ? ((s)->e2fs_bsize / sizeof(struct ext2_gd)) : \ 425 ((s)->e2fs_bsize / E2FS_REV0_GD_SIZE)) 426 427 /* 428 * Macro-instructions used to manage inodes 429 */ 430 #define EXT2_FIRST_INO(s) (le32toh((EXT2_SB(s)->e2fs->e2fs_rev) == \ 431 E2FS_REV0) ? EXT2_FIRSTINO : le32toh(EXT2_SB(s)->e2fs->e2fs_first_ino)) 432 433 /* 434 * Linux major/minor values limits 435 */ 436 #define EXT2_MINORBITS (20) 437 #define EXT2_MAJOR_MAX (0xffffffff >> EXT2_MINORBITS) 438 #define EXT2_MINOR_MAX ((1 << EXT2_MINORBITS) - 1) 439 440 #endif /* !_FS_EXT2FS_EXT2FS_H_ */ 441