1202283Slulf/*- 2202283Slulf * modified for EXT2FS support in Lites 1.1 3202283Slulf * 4202283Slulf * Aug 1995, Godmar Back (gback@cs.utah.edu) 5202283Slulf * University of Utah, Department of Computer Science 6202283Slulf * 7202283Slulf * $FreeBSD: stable/11/sys/fs/ext2fs/ext2fs.h 322814 2017-08-23 15:43:59Z pfg $ 8202283Slulf */ 9202283Slulf/*- 10202283Slulf * Copyright (c) 2009 Aditya Sarawgi 11202283Slulf * All rights reserved. 12202283Slulf * 13202283Slulf * Redistribution and use in source and binary forms, with or without 14202283Slulf * modification, are permitted provided that the following conditions 15202283Slulf * are met: 16202283Slulf * 1. Redistributions of source code must retain the above copyright 17202283Slulf * notice, this list of conditions and the following disclaimer. 18202283Slulf * 2. Redistributions in binary form must reproduce the above copyright 19202283Slulf * notice, this list of conditions and the following disclaimer in the 20202283Slulf * documentation and/or other materials provided with the distribution. 21202283Slulf * 22202283Slulf * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 23202283Slulf * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24202283Slulf * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25202283Slulf * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 26202283Slulf * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27202283Slulf * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28202283Slulf * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29202283Slulf * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30202283Slulf * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31202283Slulf * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32202283Slulf * SUCH DAMAGE. 33202283Slulf * 34311231Spfg * 35202283Slulf */ 36202283Slulf 37228583Spfg#ifndef _FS_EXT2FS_EXT2FS_H_ 38262623Spfg#define _FS_EXT2FS_EXT2FS_H_ 39202283Slulf 40202283Slulf#include <sys/types.h> 41202283Slulf 42202283Slulf/* 43202283Slulf * Super block for an ext2fs file system. 44202283Slulf */ 45202283Slulfstruct ext2fs { 46221126Sjhb uint32_t e2fs_icount; /* Inode count */ 47221126Sjhb uint32_t e2fs_bcount; /* blocks count */ 48221126Sjhb uint32_t e2fs_rbcount; /* reserved blocks count */ 49221126Sjhb uint32_t e2fs_fbcount; /* free blocks count */ 50221126Sjhb uint32_t e2fs_ficount; /* free inodes count */ 51221126Sjhb uint32_t e2fs_first_dblock; /* first data block */ 52221126Sjhb uint32_t e2fs_log_bsize; /* block size = 1024*(2^e2fs_log_bsize) */ 53221126Sjhb uint32_t e2fs_log_fsize; /* fragment size */ 54221126Sjhb uint32_t e2fs_bpg; /* blocks per group */ 55221126Sjhb uint32_t e2fs_fpg; /* frags per group */ 56221126Sjhb uint32_t e2fs_ipg; /* inodes per group */ 57221126Sjhb uint32_t e2fs_mtime; /* mount time */ 58221126Sjhb uint32_t e2fs_wtime; /* write time */ 59221126Sjhb uint16_t e2fs_mnt_count; /* mount count */ 60221126Sjhb uint16_t e2fs_max_mnt_count; /* max mount count */ 61221126Sjhb uint16_t e2fs_magic; /* magic number */ 62221126Sjhb uint16_t e2fs_state; /* file system state */ 63221126Sjhb uint16_t e2fs_beh; /* behavior on errors */ 64221126Sjhb uint16_t e2fs_minrev; /* minor revision level */ 65221126Sjhb uint32_t e2fs_lastfsck; /* time of last fsck */ 66221126Sjhb uint32_t e2fs_fsckintv; /* max time between fscks */ 67221126Sjhb uint32_t e2fs_creator; /* creator OS */ 68221126Sjhb uint32_t e2fs_rev; /* revision level */ 69221126Sjhb uint16_t e2fs_ruid; /* default uid for reserved blocks */ 70221126Sjhb uint16_t e2fs_rgid; /* default gid for reserved blocks */ 71202283Slulf /* EXT2_DYNAMIC_REV superblocks */ 72221126Sjhb uint32_t e2fs_first_ino; /* first non-reserved inode */ 73221126Sjhb uint16_t e2fs_inode_size; /* size of inode structure */ 74221126Sjhb uint16_t e2fs_block_group_nr; /* block grp number of this sblk*/ 75297335Skevlo uint32_t e2fs_features_compat; /* compatible feature set */ 76221126Sjhb uint32_t e2fs_features_incompat; /* incompatible feature set */ 77221126Sjhb uint32_t e2fs_features_rocompat; /* RO-compatible feature set */ 78221126Sjhb uint8_t e2fs_uuid[16]; /* 128-bit uuid for volume */ 79221126Sjhb char e2fs_vname[16]; /* volume name */ 80262623Spfg char e2fs_fsmnt[64]; /* name mounted on */ 81221126Sjhb uint32_t e2fs_algo; /* For compression */ 82221126Sjhb uint8_t e2fs_prealloc; /* # of blocks for old prealloc */ 83221126Sjhb uint8_t e2fs_dir_prealloc; /* # of blocks for old prealloc dirs */ 84221126Sjhb uint16_t e2fs_reserved_ngdb; /* # of reserved gd blocks for resize */ 85221126Sjhb char e3fs_journal_uuid[16]; /* uuid of journal superblock */ 86221126Sjhb uint32_t e3fs_journal_inum; /* inode number of journal file */ 87221126Sjhb uint32_t e3fs_journal_dev; /* device number of journal file */ 88221126Sjhb uint32_t e3fs_last_orphan; /* start of list of inodes to delete */ 89221126Sjhb uint32_t e3fs_hash_seed[4]; /* HTREE hash seed */ 90301559Spfg char e3fs_def_hash_version;/* Default hash version to use */ 91297335Skevlo char e3fs_jnl_backup_type; 92297335Skevlo uint16_t e3fs_desc_size; /* size of group descriptor */ 93221126Sjhb uint32_t e3fs_default_mount_opts; 94221126Sjhb uint32_t e3fs_first_meta_bg; /* First metablock block group */ 95297335Skevlo uint32_t e3fs_mkfs_time; /* when the fs was created */ 96297335Skevlo uint32_t e3fs_jnl_blks[17]; /* backup of the journal inode */ 97297335Skevlo uint32_t e4fs_bcount_hi; /* high bits of blocks count */ 98297335Skevlo uint32_t e4fs_rbcount_hi; /* high bits of reserved blocks count */ 99297335Skevlo uint32_t e4fs_fbcount_hi; /* high bits of free blocks count */ 100301559Spfg uint16_t e4fs_min_extra_isize; /* all inodes have some bytes */ 101301559Spfg uint16_t e4fs_want_extra_isize;/* inodes must reserve some bytes */ 102297335Skevlo uint32_t e4fs_flags; /* miscellaneous flags */ 103297335Skevlo uint16_t e4fs_raid_stride; /* RAID stride */ 104301559Spfg uint16_t e4fs_mmpintv; /* seconds to wait in MMP checking */ 105297335Skevlo uint64_t e4fs_mmpblk; /* block for multi-mount protection */ 106301559Spfg uint32_t e4fs_raid_stripe_wid; /* blocks on data disks (N * stride) */ 107297335Skevlo uint8_t e4fs_log_gpf; /* FLEX_BG group size */ 108297335Skevlo uint8_t e4fs_chksum_type; /* metadata checksum algorithm used */ 109297335Skevlo uint8_t e4fs_encrypt; /* versioning level for encryption */ 110297335Skevlo uint8_t e4fs_reserved_pad; 111297335Skevlo uint64_t e4fs_kbytes_written; /* number of lifetime kilobytes */ 112297335Skevlo uint32_t e4fs_snapinum; /* inode number of active snapshot */ 113297335Skevlo uint32_t e4fs_snapid; /* sequential ID of active snapshot */ 114297335Skevlo uint64_t e4fs_snaprbcount; /* reserved blocks for active snapshot */ 115297335Skevlo uint32_t e4fs_snaplist; /* inode number for on-disk snapshot */ 116297335Skevlo uint32_t e4fs_errcount; /* number of file system errors */ 117297335Skevlo uint32_t e4fs_first_errtime; /* first time an error happened */ 118297335Skevlo uint32_t e4fs_first_errino; /* inode involved in first error */ 119297335Skevlo uint64_t e4fs_first_errblk; /* block involved of first error */ 120301559Spfg uint8_t e4fs_first_errfunc[32];/* function where error happened */ 121297335Skevlo uint32_t e4fs_first_errline; /* line number where error happened */ 122297335Skevlo uint32_t e4fs_last_errtime; /* most recent time of an error */ 123297335Skevlo uint32_t e4fs_last_errino; /* inode involved in last error */ 124297335Skevlo uint32_t e4fs_last_errline; /* line number where error happened */ 125297335Skevlo uint64_t e4fs_last_errblk; /* block involved of last error */ 126297335Skevlo uint8_t e4fs_last_errfunc[32]; /* function where error happened */ 127297335Skevlo uint8_t e4fs_mount_opts[64]; 128297335Skevlo uint32_t e4fs_usrquota_inum; /* inode for tracking user quota */ 129297335Skevlo uint32_t e4fs_grpquota_inum; /* inode for tracking group quota */ 130301559Spfg uint32_t e4fs_overhead_clusters;/* overhead blocks/clusters */ 131297335Skevlo uint32_t e4fs_backup_bgs[2]; /* groups with sparse_super2 SBs */ 132301559Spfg uint8_t e4fs_encrypt_algos[4];/* encryption algorithms in use */ 133301559Spfg uint8_t e4fs_encrypt_pw_salt[16];/* salt used for string2key */ 134297335Skevlo uint32_t e4fs_lpf_ino; /* location of the lost+found inode */ 135297335Skevlo uint32_t e4fs_proj_quota_inum; /* inode for tracking project quota */ 136297335Skevlo uint32_t e4fs_chksum_seed; /* checksum seed */ 137297335Skevlo uint32_t e4fs_reserved[98]; /* padding to the end of the block */ 138297335Skevlo uint32_t e4fs_sbchksum; /* superblock checksum */ 139202283Slulf}; 140202283Slulf 141251952Spfg/* 142251952Spfg * The path name on which the file system is mounted is maintained 143251952Spfg * in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in 144251952Spfg * the super block for this name. 145251952Spfg */ 146262623Spfg#define MAXMNTLEN 512 147202283Slulf 148202283Slulf/* 149202283Slulf * In-Memory Superblock 150202283Slulf */ 151202283Slulf 152202283Slulfstruct m_ext2fs { 153202283Slulf struct ext2fs * e2fs; 154221126Sjhb char e2fs_fsmnt[MAXMNTLEN];/* name mounted on */ 155262623Spfg char e2fs_ronly; /* mounted read-only flag */ 156262623Spfg char e2fs_fmod; /* super block modified flag */ 157262623Spfg uint32_t e2fs_bsize; /* Block size */ 158262623Spfg uint32_t e2fs_bshift; /* calc of logical block no */ 159251562Spfg uint32_t e2fs_bpg; /* Number of blocks per group */ 160262623Spfg int64_t e2fs_qbmask; /* = s_blocksize -1 */ 161262623Spfg uint32_t e2fs_fsbtodb; /* Shift to get disk block */ 162231168Spfg uint32_t e2fs_ipg; /* Number of inodes per group */ 163231168Spfg uint32_t e2fs_ipb; /* Number of inodes per block */ 164262623Spfg uint32_t e2fs_itpg; /* Number of inode table per group */ 165262623Spfg uint32_t e2fs_fsize; /* Size of fragments per block */ 166231168Spfg uint32_t e2fs_fpb; /* Number of fragments per block */ 167231168Spfg uint32_t e2fs_fpg; /* Number of fragments per group */ 168262623Spfg uint32_t e2fs_gdbcount; /* Number of group descriptors */ 169262623Spfg uint32_t e2fs_gcount; /* Number of groups */ 170251562Spfg uint32_t e2fs_isize; /* Size of inode */ 171202283Slulf uint32_t e2fs_total_dir; /* Total number of directories */ 172217703Sjhb uint8_t *e2fs_contigdirs; /* (u) # of contig. allocated dirs */ 173262623Spfg char e2fs_wasvalid; /* valid at mount time */ 174221126Sjhb off_t e2fs_maxfilesize; 175221126Sjhb struct ext2_gd *e2fs_gd; /* Group Descriptors */ 176228539Spfg int32_t e2fs_contigsumsize; /* size of cluster summary array */ 177228539Spfg int32_t *e2fs_maxcluster; /* max cluster in each cyl group */ 178228539Spfg struct csum *e2fs_clustersum; /* cluster summary in each cyl group */ 179294504Spfg int32_t e2fs_uhash; /* 3 if hash should be signed, 0 if not */ 180202283Slulf}; 181202283Slulf 182251809Spfg/* cluster summary information */ 183202283Slulf 184251809Spfgstruct csum { 185251809Spfg int8_t cs_init; /* cluster summary has been initialized */ 186251809Spfg int32_t *cs_sum; /* cluster summary array */ 187251809Spfg}; 188251809Spfg 189202283Slulf/* 190217703Sjhb * The second extended file system magic number 191217703Sjhb */ 192262623Spfg#define E2FS_MAGIC 0xEF53 193217703Sjhb 194217703Sjhb/* 195202283Slulf * Revision levels 196202283Slulf */ 197262623Spfg#define E2FS_REV0 0 /* The good old (original) format */ 198262623Spfg#define E2FS_REV1 1 /* V2 format w/ dynamic inode sizes */ 199202283Slulf 200262623Spfg#define E2FS_REV0_INODE_SIZE 128 201202283Slulf 202202283Slulf/* 203202283Slulf * compatible/incompatible features 204202283Slulf */ 205262623Spfg#define EXT2F_COMPAT_PREALLOC 0x0001 206322738Spfg#define EXT2F_COMPAT_IMAGIC_INODES 0x0002 207262623Spfg#define EXT2F_COMPAT_HASJOURNAL 0x0004 208322711Spfg#define EXT2F_COMPAT_EXT_ATTR 0x0008 209262623Spfg#define EXT2F_COMPAT_RESIZE 0x0010 210262623Spfg#define EXT2F_COMPAT_DIRHASHINDEX 0x0020 211322738Spfg#define EXT2F_COMPAT_LAZY_BG 0x0040 212322738Spfg#define EXT2F_COMPAT_EXCLUDE_BITMAP 0x0100 213305493Spfg#define EXT2F_COMPAT_SPARSESUPER2 0x0200 214202283Slulf 215262623Spfg#define EXT2F_ROCOMPAT_SPARSESUPER 0x0001 216262623Spfg#define EXT2F_ROCOMPAT_LARGEFILE 0x0002 217262623Spfg#define EXT2F_ROCOMPAT_BTREE_DIR 0x0004 218262623Spfg#define EXT2F_ROCOMPAT_HUGE_FILE 0x0008 219262623Spfg#define EXT2F_ROCOMPAT_GDT_CSUM 0x0010 220262623Spfg#define EXT2F_ROCOMPAT_DIR_NLINK 0x0020 221262623Spfg#define EXT2F_ROCOMPAT_EXTRA_ISIZE 0x0040 222322738Spfg#define EXT2F_ROCOMPAT_HAS_SNAPSHOT 0x0080 223305493Spfg#define EXT2F_ROCOMPAT_QUOTA 0x0100 224305493Spfg#define EXT2F_ROCOMPAT_BIGALLOC 0x0200 225305493Spfg#define EXT2F_ROCOMPAT_METADATA_CKSUM 0x0400 226322738Spfg#define EXT2F_ROCOMPAT_REPLICA 0x0800 227305493Spfg#define EXT2F_ROCOMPAT_READONLY 0x1000 228305493Spfg#define EXT2F_ROCOMPAT_PROJECT 0x2000 229202283Slulf 230262623Spfg#define EXT2F_INCOMPAT_COMP 0x0001 231262623Spfg#define EXT2F_INCOMPAT_FTYPE 0x0002 232292872Spfg#define EXT2F_INCOMPAT_RECOVER 0x0004 233322738Spfg#define EXT2F_INCOMPAT_JOURNAL_DEV 0x0008 234262623Spfg#define EXT2F_INCOMPAT_META_BG 0x0010 235262623Spfg#define EXT2F_INCOMPAT_EXTENTS 0x0040 236262623Spfg#define EXT2F_INCOMPAT_64BIT 0x0080 237262623Spfg#define EXT2F_INCOMPAT_MMP 0x0100 238262623Spfg#define EXT2F_INCOMPAT_FLEX_BG 0x0200 239305493Spfg#define EXT2F_INCOMPAT_EA_INODE 0x0400 240305493Spfg#define EXT2F_INCOMPAT_DIRDATA 0x1000 241305493Spfg#define EXT2F_INCOMPAT_CSUM_SEED 0x2000 242305493Spfg#define EXT2F_INCOMPAT_LARGEDIR 0x4000 243305493Spfg#define EXT2F_INCOMPAT_INLINE_DATA 0x8000 244305493Spfg#define EXT2F_INCOMPAT_ENCRYPT 0x10000 245202283Slulf 246322738Spfgstruct ext2_feature 247322738Spfg{ 248322738Spfg int mask; 249322738Spfg const char *name; 250322738Spfg}; 251322738Spfg 252322738Spfgstatic const struct ext2_feature compat[] = { 253322738Spfg { EXT2F_COMPAT_PREALLOC, "dir_prealloc" }, 254322738Spfg { EXT2F_COMPAT_IMAGIC_INODES, "imagic_inodes" }, 255322738Spfg { EXT2F_COMPAT_HASJOURNAL, "has_journal" }, 256322738Spfg { EXT2F_COMPAT_EXT_ATTR, "ext_attr" }, 257322738Spfg { EXT2F_COMPAT_RESIZE, "resize_inode" }, 258322738Spfg { EXT2F_COMPAT_DIRHASHINDEX, "dir_index" }, 259322738Spfg { EXT2F_COMPAT_EXCLUDE_BITMAP, "snapshot_bitmap" }, 260322738Spfg { EXT2F_COMPAT_SPARSESUPER2, "sparse_super2" } 261322738Spfg}; 262322738Spfg 263322738Spfgstatic const struct ext2_feature ro_compat[] = { 264322738Spfg { EXT2F_ROCOMPAT_SPARSESUPER, "sparse_super" }, 265322738Spfg { EXT2F_ROCOMPAT_LARGEFILE, "large_file" }, 266322738Spfg { EXT2F_ROCOMPAT_BTREE_DIR, "btree_dir" }, 267322738Spfg { EXT2F_ROCOMPAT_HUGE_FILE, "huge_file" }, 268322738Spfg { EXT2F_ROCOMPAT_GDT_CSUM, "uninit_groups" }, 269322738Spfg { EXT2F_ROCOMPAT_DIR_NLINK, "dir_nlink" }, 270322738Spfg { EXT2F_ROCOMPAT_EXTRA_ISIZE, "extra_isize" }, 271322738Spfg { EXT2F_ROCOMPAT_HAS_SNAPSHOT, "snapshot" }, 272322738Spfg { EXT2F_ROCOMPAT_QUOTA, "quota" }, 273322738Spfg { EXT2F_ROCOMPAT_BIGALLOC, "bigalloc" }, 274322738Spfg { EXT2F_ROCOMPAT_METADATA_CKSUM, "metadata_csum" }, 275322738Spfg { EXT2F_ROCOMPAT_REPLICA, "replica" }, 276322738Spfg { EXT2F_ROCOMPAT_READONLY, "ro" }, 277322738Spfg { EXT2F_ROCOMPAT_PROJECT, "project" } 278322738Spfg}; 279322738Spfg 280322738Spfgstatic const struct ext2_feature incompat[] = { 281322738Spfg { EXT2F_INCOMPAT_COMP, "compression" }, 282322738Spfg { EXT2F_INCOMPAT_FTYPE, "filetype" }, 283322738Spfg { EXT2F_INCOMPAT_RECOVER, "needs_recovery" }, 284322738Spfg { EXT2F_INCOMPAT_JOURNAL_DEV, "journal_dev" }, 285322738Spfg { EXT2F_INCOMPAT_META_BG, "meta_bg" }, 286322738Spfg { EXT2F_INCOMPAT_EXTENTS, "extents" }, 287322738Spfg { EXT2F_INCOMPAT_64BIT, "64bit" }, 288322738Spfg { EXT2F_INCOMPAT_MMP, "mmp" }, 289322738Spfg { EXT2F_INCOMPAT_FLEX_BG, "flex_bg" }, 290322738Spfg { EXT2F_INCOMPAT_EA_INODE, "ea_inode" }, 291322738Spfg { EXT2F_INCOMPAT_DIRDATA, "dirdata" }, 292322738Spfg { EXT2F_INCOMPAT_CSUM_SEED, "metadata_csum_seed" }, 293322738Spfg { EXT2F_INCOMPAT_LARGEDIR, "large_dir" }, 294322738Spfg { EXT2F_INCOMPAT_INLINE_DATA, "inline_data" }, 295322738Spfg { EXT2F_INCOMPAT_ENCRYPT, "encrypt" } 296322738Spfg}; 297322738Spfg 298202283Slulf/* 299202283Slulf * Features supported in this implementation 300202283Slulf * 301202283Slulf * We support the following REV1 features: 302202283Slulf * - EXT2F_ROCOMPAT_SPARSESUPER 303202283Slulf * - EXT2F_ROCOMPAT_LARGEFILE 304262346Spfg * - EXT2F_ROCOMPAT_EXTRA_ISIZE 305202283Slulf * - EXT2F_INCOMPAT_FTYPE 306254260Spfg * 307254260Spfg * We partially (read-only) support the following EXT4 features: 308254260Spfg * - EXT2F_ROCOMPAT_HUGE_FILE 309254260Spfg * - EXT2F_INCOMPAT_EXTENTS 310262346Spfg * 311262346Spfg * We do not support these EXT4 features but they are irrelevant 312262346Spfg * for read-only support: 313292872Spfg * - EXT2F_INCOMPAT_RECOVER 314262346Spfg * - EXT2F_INCOMPAT_FLEX_BG 315262346Spfg * - EXT2F_INCOMPAT_META_BG 316202283Slulf */ 317294504Spfg#define EXT2F_COMPAT_SUPP EXT2F_COMPAT_DIRHASHINDEX 318262623Spfg#define EXT2F_ROCOMPAT_SUPP (EXT2F_ROCOMPAT_SPARSESUPER | \ 319232703Spfg EXT2F_ROCOMPAT_LARGEFILE | \ 320322712Spfg EXT2F_ROCOMPAT_GDT_CSUM | \ 321320838Spfg EXT2F_ROCOMPAT_HUGE_FILE | \ 322244475Spfg EXT2F_ROCOMPAT_EXTRA_ISIZE) 323262623Spfg#define EXT2F_INCOMPAT_SUPP EXT2F_INCOMPAT_FTYPE 324262623Spfg#define EXT4F_RO_INCOMPAT_SUPP (EXT2F_INCOMPAT_EXTENTS | \ 325292872Spfg EXT2F_INCOMPAT_RECOVER | \ 326262346Spfg EXT2F_INCOMPAT_FLEX_BG | \ 327262346Spfg EXT2F_INCOMPAT_META_BG ) 328202283Slulf 329218273Sjhb/* Assume that user mode programs are passing in an ext2fs superblock, not 330218273Sjhb * a kernel struct super_block. This will allow us to call the feature-test 331218273Sjhb * macros from user land. */ 332262623Spfg#define EXT2_SB(sb) (sb) 333218273Sjhb 334202283Slulf/* 335202283Slulf * Feature set definitions 336202283Slulf */ 337262623Spfg#define EXT2_HAS_COMPAT_FEATURE(sb,mask) \ 338202283Slulf ( EXT2_SB(sb)->e2fs->e2fs_features_compat & htole32(mask) ) 339262623Spfg#define EXT2_HAS_RO_COMPAT_FEATURE(sb,mask) \ 340202283Slulf ( EXT2_SB(sb)->e2fs->e2fs_features_rocompat & htole32(mask) ) 341262623Spfg#define EXT2_HAS_INCOMPAT_FEATURE(sb,mask) \ 342202283Slulf ( EXT2_SB(sb)->e2fs->e2fs_features_incompat & htole32(mask) ) 343202283Slulf 344202283Slulf/* 345202283Slulf * File clean flags 346202283Slulf */ 347202283Slulf#define E2FS_ISCLEAN 0x0001 /* Unmounted cleanly */ 348202283Slulf#define E2FS_ERRORS 0x0002 /* Errors detected */ 349202283Slulf 350294504Spfg/* 351294504Spfg * Filesystem miscellaneous flags 352294504Spfg */ 353294504Spfg#define E2FS_SIGNED_HASH 0x0001 354294504Spfg#define E2FS_UNSIGNED_HASH 0x0002 355294504Spfg 356322712Spfg#define EXT2_BG_INODE_UNINIT 0x0001 /* Inode table/bitmap not in use */ 357322712Spfg#define EXT2_BG_BLOCK_UNINIT 0x0002 /* Block bitmap not in use */ 358322712Spfg#define EXT2_BG_INODE_ZEROED 0x0004 /* On-disk itable initialized to zero */ 359322712Spfg 360202283Slulf/* ext2 file system block group descriptor */ 361202283Slulf 362202283Slulfstruct ext2_gd { 363221126Sjhb uint32_t ext2bgd_b_bitmap; /* blocks bitmap block */ 364221126Sjhb uint32_t ext2bgd_i_bitmap; /* inodes bitmap block */ 365221126Sjhb uint32_t ext2bgd_i_tables; /* inodes table block */ 366221126Sjhb uint16_t ext2bgd_nbfree; /* number of free blocks */ 367221126Sjhb uint16_t ext2bgd_nifree; /* number of free inodes */ 368251336Spfg uint16_t ext2bgd_ndirs; /* number of directories */ 369252012Spfg uint16_t ext4bgd_flags; /* block group flags */ 370252012Spfg uint32_t ext4bgd_x_bitmap; /* snapshot exclusion bitmap loc. */ 371252012Spfg uint16_t ext4bgd_b_bmap_csum; /* block bitmap checksum */ 372252012Spfg uint16_t ext4bgd_i_bmap_csum; /* inode bitmap checksum */ 373252012Spfg uint16_t ext4bgd_i_unused; /* unused inode count */ 374252012Spfg uint16_t ext4bgd_csum; /* group descriptor checksum */ 375202283Slulf}; 376202283Slulf 377322814Spfg/* EXT2FS metadata is stored in little-endian byte order. These macros 378322814Spfg * help reading it. 379202283Slulf */ 380202283Slulf 381262623Spfg#define e2fs_cgload(old, new, size) memcpy((new), (old), (size)); 382262623Spfg#define e2fs_cgsave(old, new, size) memcpy((new), (old), (size)); 383218273Sjhb 384202283Slulf/* 385202283Slulf * Macro-instructions used to manage several block sizes 386202283Slulf */ 387202283Slulf#define EXT2_MAX_BLOCK_SIZE 4096 388262623Spfg#define EXT2_MIN_BLOCK_LOG_SIZE 10 389262623Spfg#define EXT2_BLOCK_SIZE(s) ((s)->e2fs_bsize) 390228583Spfg#define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof(uint32_t)) 391262623Spfg#define EXT2_INODE_SIZE(s) (EXT2_SB(s)->e2fs_isize) 392202283Slulf 393202283Slulf/* 394202283Slulf * Macro-instructions used to manage fragments 395202283Slulf */ 396262623Spfg#define EXT2_MIN_FRAG_SIZE 1024 397202283Slulf#define EXT2_MAX_FRAG_SIZE 4096 398262623Spfg#define EXT2_MIN_FRAG_LOG_SIZE 10 399262623Spfg#define EXT2_FRAG_SIZE(s) (EXT2_SB(s)->e2fs_fsize) 400262623Spfg#define EXT2_FRAGS_PER_BLOCK(s) (EXT2_SB(s)->e2fs_fpb) 401202283Slulf 402202283Slulf/* 403202283Slulf * Macro-instructions used to manage group descriptors 404202283Slulf */ 405262623Spfg#define EXT2_BLOCKS_PER_GROUP(s) (EXT2_SB(s)->e2fs_bpg) 406202283Slulf 407218176Sjhb#endif /* !_FS_EXT2FS_EXT2FS_H_ */ 408