# e2fsprogs part 1 -- mke2fs builds an ext2/ext3/ext4 volume inside a plain file, # dumpe2fs reads the superblock back, tune2fs/e2label rewrite it. # # Split across three files (this, -fsck, -resize) because the runner bounds each # suite at 60 s of wall clock and a filesystem toolset does real work per case. . "$BST_LIB" require mke2fs e2fsprogs/present T=${TMPDIR:-/tmp}/bst-e2fs.$$ mkdir -p "$T" || exit 0 trap 'rm -rf "$T"' EXIT IMG=$T/fs.img UUID=3d1a2b4c-5e6f-4a7b-8c9d-0e1f2a3b4c5d NEWU=11111111-2222-4333-8444-555555555555 # one superblock field, by the label dumpe2fs prints it under sb() { dumpe2fs -h "$IMG" 2>/dev/null | sed -n "s/^$1: *//p"; } # rc 0 iff the feature list carries -- usable as a check/check_rc command feat() { case " $(sb 'Filesystem features') " in *" $1 "*) return 0 ;; *) return 1 ;; esac; } # assert on OUTPUT only: several e2fsprogs tools signal through a non-zero rc, so # check_out (which also demands rc 0) would conflate the two. msg() { _i=$1; _n=$2; shift 2; _o=$("$@" 2>&1) case "$_o" in *"$_n"*) bst_ok "$_i" ;; *) bst_notok "$_i" "want:'$_n' got:'$(_bst_1line "$_o")'" ;; esac; } blank() { rm -f "$IMG"; dd if=/dev/zero of="$IMG" bs=1024 count=4096 2>/dev/null; } check_out e2fsprogs/version "EXT2FS Library version" mke2fs -V # mke2fs reads /etc/mke2fs.conf for the feature set of every -t type below; the # recipe's MKE2FS_CONFIG wrapper covers only the native build, so on target the # file itself is the contract. check e2fsprogs/mke2fs-conf test -f /etc/mke2fs.conf # ----------------------------------------------------------- ext4 + superblock blank check e2fsprogs/mke2fs-ext4 mke2fs -q -F -t ext4 -b 1024 -L BSTROOT -U "$UUID" "$IMG" check_eq e2fsprogs/sb-magic "0xEF53" "$(sb 'Filesystem magic number')" check_eq e2fsprogs/sb-label "BSTROOT" "$(sb 'Filesystem volume name')" check_eq e2fsprogs/sb-blocks "4096" "$(sb 'Block count')" check_eq e2fsprogs/sb-blocksize "1024" "$(sb 'Block size')" check_eq e2fsprogs/sb-state "clean" "$(sb 'Filesystem state')" # -U is parsed by libuuid (uuid_parse), so this is the only case on the image that # proves e2fsprogs' -luuid link actually resolves at runtime rather than merely # linking: a stub would not round-trip an exact RFC-4122 string. check_eq e2fsprogs/sb-uuid "$UUID" "$(sb 'Filesystem UUID')" check e2fsprogs/ext4-journal feat has_journal check e2fsprogs/ext4-extent feat extent # ------------------------------------------- the mkfs.* spellings, and a control # mkfs.ext2/3/4 are the same program selecting its default feature set from # argv[0]. Asserting only "it ran" would pass on a program that ignored the name, # so each spelling is paired with the feature that must (or must not) follow from # it: ext3 journals but has no extents, ext2 has neither. blank check e2fsprogs/mkfs-ext3 mkfs.ext3 -q -F -b 1024 "$IMG" check e2fsprogs/ext3-journal feat has_journal check_rc e2fsprogs/ext3-no-extent 1 feat extent blank check e2fsprogs/mkfs-ext4-spelling mkfs.ext4 -q -F -b 1024 "$IMG" check e2fsprogs/ext4-spelling-extent feat extent blank check e2fsprogs/mkfs-ext2 mkfs.ext2 -q -F -b 1024 "$IMG" check_rc e2fsprogs/ext2-no-journal 1 feat has_journal check_rc e2fsprogs/ext2-no-extent 1 feat extent # busybox ships an mkfs.ext2 applet too; update-alternatives priority 100 is what # puts e2fsprogs' at /sbin/mkfs.ext2. -V is the discriminator -- the applet has no # such option and prints usage instead. msg e2fsprogs/mkfs-ext2-is-e2fsprogs "EXT2FS Library version" mkfs.ext2 -V # ------------------------------------------------ tune2fs / e2label round-trips # On the ext2 image just written: ext2 carries no metadata_csum, so tune2fs -U # rewrites the superblock outright instead of prompting to recompute checksums. check e2fsprogs/tune2fs-label tune2fs -L RELABELED "$IMG" check_eq e2fsprogs/tune2fs-label-rb "RELABELED" "$(sb 'Filesystem volume name')" check_eq e2fsprogs/e2label-reads "RELABELED" "$(e2label "$IMG" 2>/dev/null)" check e2fsprogs/e2label-writes e2label "$IMG" VIAE2LABEL check_eq e2fsprogs/e2label-rb "VIAE2LABEL" "$(sb 'Filesystem volume name')" check e2fsprogs/tune2fs-uuid tune2fs -U "$NEWU" "$IMG" check_eq e2fsprogs/tune2fs-uuid-rb "$NEWU" "$(sb 'Filesystem UUID')" check e2fsprogs/tune2fs-maxmount tune2fs -c 25 "$IMG" check_eq e2fsprogs/tune2fs-maxmount-rb "25" "$(sb 'Maximum mount count')" # ------------------------------------------------------------------- a control # Everything above asserts that dumpe2fs FINDS what mke2fs wrote. This asserts it # does not find a filesystem that was never written -- without it a reader that # reported plausible defaults for any input would score a clean sweep. dd if=/dev/zero of="$T/junk.img" bs=1024 count=64 2>/dev/null msg e2fsprogs/dumpe2fs-bad-magic "Bad magic number in super-block" dumpe2fs -h "$T/junk.img"