From: Christian Goeschel Ndjomouo Date: Fri, 1 May 2026 22:25:21 +0000 (-0400) Subject: tests: (fallocate) --insert-range test X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6ff677d1dd51261e58a79fae8c9185a3d5b032b5;p=thirdparty%2Futil-linux.git tests: (fallocate) --insert-range test Signed-off-by: Christian Goeschel Ndjomouo --- diff --git a/tests/expected/fallocate/insert-range b/tests/expected/fallocate/insert-range new file mode 100644 index 000000000..15f38246e --- /dev/null +++ b/tests/expected/fallocate/insert-range @@ -0,0 +1,7 @@ +aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa |................| +* +00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +* +ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| +* + diff --git a/tests/ts/fallocate/insert-range b/tests/ts/fallocate/insert-range new file mode 100755 index 000000000..36a28e088 --- /dev/null +++ b/tests/ts/fallocate/insert-range @@ -0,0 +1,69 @@ +#!/usr/bin/env bash + +# This file is part of util-linux. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This file is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# Copyright (C) 2026 Christian Goeschel Ndjomouo + +TS_TOPDIR="${0%/*}/../.." +TS_DESC="insert-range" + +. "$TS_TOPDIR"/functions.sh +ts_init "$*" + +ts_check_test_command "$TS_CMD_FALLOCATE" +ts_check_test_command "$TS_CMD_HEXDUMP" +ts_check_test_command "$TS_CMD_FINDMNT" +ts_check_prog "stat" + +TEST_FILE="${TS_OUTDIR}/${TS_TESTNAME}.data" +# We have to properly align the different data blocks +# to the logical filesystem block size otherwise fallocate +# will fail with EINVAL. +BLKSIZE="$(stat --file-system --format=%s "$TS_OUTDIR")" + +# The two patterns are used to create distinct data blocks of size $BLKSIZE +# and will help to verify the data block shift. +# +# Our test file's data block patterns will look like this: +# +# bs bytes bs bytes +# |aaaaaaaa...|ffffffff...| +# insert here ------^ +# +# to obtain this +# bs bytes bs bytes bs bytes +# |aaaaaaaa...|00000000...|ffffffff...| +# +{ + printf '%*s' "$BLKSIZE" '' | tr ' ' '\252' + printf '%*s' "$BLKSIZE" '' | tr ' ' '\377' +} >"$TEST_FILE" + +# After this command the block with 'ff' should be shifted +# $BLKSIZE +"$TS_CMD_FALLOCATE" --insert-range --offset "$BLKSIZE" --length "$BLKSIZE" \ + "$TEST_FILE" >>"$TS_OUTPUT" 2>>"$TS_ERRLOG" + +size_after="$(stat --format=%s "$TEST_FILE")" + +if (( size_after != (BLKSIZE * 3) )); then + rm -f "$TEST_FILE" + ts_failed "file not properly resized (size: $size_after, block size: $BLKSIZE)" +fi + +"$TS_CMD_HEXDUMP" --canonical "$TEST_FILE" | sed -e 's/^[[:alnum:]]*[[:space:]]*//g' \ + >>"$TS_OUTPUT" 2>>"$TS_ERRLOG" + +rm -f "$TEST_FILE" + +ts_finalize