]> git.ipfire.org Git - thirdparty/util-linux.git/commit
mkswap: Fix --file chmod(2) check when file exists
authorJohannes Wüller <johanneswueller@gmail.com>
Sat, 4 Apr 2026 18:03:06 +0000 (20:03 +0200)
committerJohannes Wüller <johanneswueller@gmail.com>
Tue, 7 Apr 2026 06:52:53 +0000 (08:52 +0200)
commit6d87ff51568c017a6d08043d554bf0ea8dee5457
tree59039a691f14eefd17b2e8a880fc1faed8351933
parent699d086fa5f24651b375e5909c27e14a16ceb4b9
mkswap: Fix --file chmod(2) check when file exists

The documentation claims that `--size` will resize the `--file`, but
it ends up failing like this:

    # mkswap --file /swapfile --size 4G
    Setting up swapspace version 1, size = 4 GiB (4294963200 bytes)
    no label, UUID=1523588e-412a-4f25-8fac-aeaf638101aa
    # mkswap --file /swapfile --size 4G
    mkswap: cannot set permissions on swap file /swapfile: Success

There seems to have been a typo in the chmod(2) return value comparison.
It checked for `< 9` rather than `< 0`, which would usually indicate
failure. After the fix:

    # mkswap --file /swapfile --size 4G
    Setting up swapspace version 1, size = 4 GiB (4294963200 bytes)
    no label, UUID=6be7c450-761c-442d-8d9a-3e8cd93506b5
    # mkswap --file /swapfile --size 4G
    mkswap: /swapfile: warning: wiping old swap signature.
    Setting up swapspace version 1, size = 4 GiB (4294963200 bytes)
    no label, UUID=617a793e-84b1-471d-96c5-c099f8b157db

The operation no longer fails, as validated by the added test.
disk-utils/mkswap.c
tests/ts/mkswap/mkswap