]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fallocate: allow O_CREATE if mode is FALLOC_FL_WRITE_ZEROES
authorLukas Herbolt <lukas@herbolt.com>
Wed, 1 Oct 2025 11:54:50 +0000 (13:54 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 1 Oct 2025 13:05:32 +0000 (15:05 +0200)
With the new flag we can create the ZEROED allcoated files directly and not
in the two steps. Removing FALLOC_FL_WRITE_ZEROES from the flags of not using
O_CREATE on open().

Signed-off-by: Lukas Herbolt <lukas@herbolt.com>
sys-utils/fallocate.c

index f06009483a4cebb1750702a8429a8047476a5eae..686e4925e240341504d76c7fcde707f8ac459398 100644 (file)
@@ -408,7 +408,7 @@ int main(int argc, char **argv)
 
        /* O_CREAT makes sense only for the default fallocate(2) behavior
         * when mode is no specified and new space is allocated */
-       fd = open(filename, O_RDWR | (!dig && !mode ? O_CREAT : 0),
+       fd = open(filename, O_RDWR | (!dig && !(mode & ~FALLOC_FL_WRITE_ZEROES) ? O_CREAT : 0),
                  S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
        if (fd < 0)
                err(EXIT_FAILURE, _("cannot open %s"), filename);