summaryrefslogtreecommitdiffstats
path: root/sys-utils/fallocate.c
diff options
context:
space:
mode:
authorKarel Zak2014-06-26 12:01:13 +0200
committerKarel Zak2014-06-26 12:01:13 +0200
commitdac1cb536b78e0d004d5735c895c564bd3fd2b25 (patch)
treecd8bed85512a1952a0aa85f04c46fb1fe7cadc64 /sys-utils/fallocate.c
parentdocs: add note about lsblk (diff)
downloadkernel-qcow2-util-linux-dac1cb536b78e0d004d5735c895c564bd3fd2b25.tar.gz
kernel-qcow2-util-linux-dac1cb536b78e0d004d5735c895c564bd3fd2b25.tar.xz
kernel-qcow2-util-linux-dac1cb536b78e0d004d5735c895c564bd3fd2b25.zip
fallocate: fix FALLOC_FL_ZERO_RANGE flag check
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.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/sys-utils/fallocate.c b/sys-utils/fallocate.c
index e5c149bb5..d950f9c57 100644
--- a/sys-utils/fallocate.c
+++ b/sys-utils/fallocate.c
@@ -80,7 +80,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
fputs(_(" -l, --length <num> length of the (de)allocation, in bytes\n"), out);
fputs(_(" -n, --keep-size don't modify the length of the file\n"), out);
fputs(_(" -o, --offset <num> offset of the (de)allocation, in bytes\n"), out);
- fputs(_(" -p, --punch-hole punch holes in the file\n"), out);
+ fputs(_(" -p, --punch-hole punch holes in the file (implies --keep-size)\n"), out);
fputs(_(" -z, --zero-range zeroes a range in the file\n"), out);
fputs(_(" -v, --verbose verbose mode\n"), out);
@@ -326,6 +326,7 @@ int main(int argc, char **argv)
}
}
if (dig) {
+ /* for --dig-holes the default is analyze all file */
if (mode != 0)
errx(EXIT_FAILURE,
_("Can't use other modes with --dig-holes"));
@@ -334,6 +335,7 @@ int main(int argc, char **argv)
if (length < 0)
errx(EXIT_FAILURE, _("invalid length value specified"));
} else {
+ /* it's safer to require the range specification (--length --offset) */
if (length == -2LL)
errx(EXIT_FAILURE, _("no length argument specified"));
if (length <= 0)
@@ -343,8 +345,10 @@ int main(int argc, char **argv)
errx(EXIT_FAILURE, _("invalid offset value specified"));
if (optind == argc)
errx(EXIT_FAILURE, _("no filename specified."));
- if (mode & ~(FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE))
- errx(EXIT_FAILURE, _("only -n mode can be used with "
+
+ if ((mode & FALLOC_FL_ZERO_RANGE) &&
+ (mode & ~(FALLOC_FL_ZERO_RANGE | FALLOC_FL_KEEP_SIZE)))
+ errx(EXIT_FAILURE, _("only --keep-size mode can be used with "
"--zero-range"));
filename = argv[optind++];