diff options
author | Karel Zak | 2014-06-26 14:45:02 +0200 |
---|---|---|
committer | Karel Zak | 2014-06-26 14:45:02 +0200 |
commit | 575718a04aa0c053875041dc387e360f2dcaa70d (patch) | |
tree | a3856fed19a29c18b8938a5fa8c312437a0c1d3f /sys-utils/fallocate.c | |
parent | fallocate: fix check of number of arguments (diff) | |
download | kernel-qcow2-util-linux-575718a04aa0c053875041dc387e360f2dcaa70d.tar.gz kernel-qcow2-util-linux-575718a04aa0c053875041dc387e360f2dcaa70d.tar.xz kernel-qcow2-util-linux-575718a04aa0c053875041dc387e360f2dcaa70d.zip |
fallocate: use O_CREAT only for the default behavior
Reported-by: Bernhard Voelker <mail@bernhard-voelker.de>
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/fallocate.c')
-rw-r--r-- | sys-utils/fallocate.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/sys-utils/fallocate.c b/sys-utils/fallocate.c index 4e8cef263..93fd3b48e 100644 --- a/sys-utils/fallocate.c +++ b/sys-utils/fallocate.c @@ -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); |