# e2fsprogs part 3 -- resize2fs grows and shrinks a volume in place; badblocks # reads every block of it. . "$BST_LIB" require resize2fs e2fsprogs-resize/present T=${TMPDIR:-/tmp}/bst-e2fsresize.$$ mkdir -p "$T" || exit 0 trap 'rm -rf "$T"' EXIT IMG=$T/fs.img sb() { dumpe2fs -h "$IMG" 2>/dev/null | sed -n "s/^$1: *//p"; } 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; } dd if=/dev/zero of="$IMG" bs=1024 count=8192 2>/dev/null check e2fsprogs-resize/mke2fs mke2fs -q -F -t ext4 -b 1024 "$IMG" check_eq e2fsprogs-resize/blocks-before "8192" "$(sb 'Block count')" # resize2fs never extends the backing file, only the filesystem inside it, so the # file is grown first and the two assertions are kept separate -- a resize2fs that # silently did nothing would otherwise be hidden by the dd that did. dd if=/dev/zero of="$IMG" bs=1024 seek=16383 count=1 conv=notrunc 2>/dev/null check_eq e2fsprogs-resize/file-grown "16777216" "$(stat -c %s "$IMG")" check e2fsprogs-resize/grow resize2fs "$IMG" check_eq e2fsprogs-resize/blocks-after "16384" "$(sb 'Block count')" check_rc e2fsprogs-resize/fsck-after-grow 0 e2fsck -f -n "$IMG" e2fsck -f -y "$IMG" >/dev/null 2>&1 check e2fsprogs-resize/shrink resize2fs "$IMG" 8192 check_eq e2fsprogs-resize/blocks-after-shrink "8192" "$(sb 'Block count')" check_rc e2fsprogs-resize/fsck-after-shrink 0 e2fsck -f -n "$IMG" msg e2fsprogs-resize/minimum "Estimated minimum size of the filesystem" resize2fs -P "$IMG" # badblocks reads the whole volume; on a file backed by tmpfs there can be none, # so an empty report is the pass and any output at all is a real finding. if command -v badblocks >/dev/null 2>&1; then BB=$(badblocks "$IMG" 2>/dev/null) if [ -z "$BB" ]; then bst_ok e2fsprogs-resize/badblocks else bst_notok e2fsprogs-resize/badblocks "badblocks reported: $(_bst_1line "$BB")"; fi else bst_skip e2fsprogs-resize/badblocks "badblocks not installed on this image" fi