]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: (swaplabel) don't create test image with truncate(1)
authorThomas Weißschuh <thomas@t-8ch.de>
Sat, 1 Nov 2025 15:50:49 +0000 (16:50 +0100)
committerThomas Weißschuh <thomas@t-8ch.de>
Sat, 8 Nov 2025 14:08:27 +0000 (15:08 +0100)
truncate(1) can create holes in the file. These will trigger a warning
in mkswap(1), failing the testsuite. Given that fallocate(1) now alway
supports posix_fallocate() which works on all filesystems, truncate(1)
is unnecessary anyways.

Reported-by: Christian Hesse <mail@eworm.de>
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
tests/ts/misc/swaplabel

index 9db7d2b80f23f6d9e84d2d042ae1fbb735b74265..6e777ac2a970e84f677a10e082037a43b347c39c 100755 (executable)
@@ -21,14 +21,7 @@ ts_init "$*"
 ts_check_test_command "$TS_CMD_MKSWAP"
 ts_check_test_command "$TS_CMD_SWAPLABEL"
 ts_check_test_command "$TS_HELPER_SYSINFO"
-
-# fallocate does not work on most file systems
-function fallocate_or_skip()
-{
-       $TS_CMD_FALLOCATE -x -l $1 $2 2>/dev/null || \
-       truncate -s $1 $2 || \
-       ts_skip "no way to create test image"
-}
+ts_check_test_command "$TS_CMD_FALLOCATE"
 
 IMAGE=${TS_OUTDIR}/${TS_TESTNAME}.file
 
@@ -38,7 +31,7 @@ MIN_SWAP_SIZE=$(( 10 * $PAGE_SIZE ))
 MIN_SWAP_SIZE_KB=$(( MIN_SWAP_SIZE / 1024 ))
 
 rm -f $IMAGE
-fallocate_or_skip $(( $MIN_SWAP_SIZE - 1 )) $IMAGE
+$TS_CMD_FALLOCATE -x -l $(( $MIN_SWAP_SIZE - 1 )) $IMAGE 2> /dev/null
 $TS_CMD_MKSWAP \
        --label 1234567890abcdef \
        --uuid 12345678-abcd-abcd-abcd-1234567890ab \
@@ -50,7 +43,7 @@ sed -i -e "s/ $MIN_SWAP_SIZE_KB KiB/ 10 pages/" \
    $TS_OUTPUT $TS_ERRLOG
 
 rm -f $IMAGE
-fallocate_or_skip $MIN_SWAP_SIZE $IMAGE
+$TS_CMD_FALLOCATE -x -l $MIN_SWAP_SIZE $IMAGE 2> /dev/null
 $TS_CMD_MKSWAP \
        --label 1234567890abcdef \
        --uuid 12345678-abcd-abcd-abcd-1234567890ab \