]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fallocate: use O_CREAT only for the default behavior
authorKarel Zak <kzak@redhat.com>
Thu, 26 Jun 2014 12:45:02 +0000 (14:45 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 26 Jun 2014 12:45:02 +0000 (14:45 +0200)
Reported-by: Bernhard Voelker <mail@bernhard-voelker.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/fallocate.c

index 4e8cef263393dd7f248add874dde3f39955fbcaa..93fd3b48e2508c2624ae6b0d37a4bbb45671149b 100644 (file)
@@ -364,7 +364,9 @@ int main(int argc, char **argv)
        if (offset < 0)
                errx(EXIT_FAILURE, _("invalid offset value specified"));
 
-       fd = open(filename, O_RDWR|O_CREAT, 0644);
+       /* 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), 0644);
        if (fd < 0)
                err(EXIT_FAILURE, _("cannot open %s"), filename);