summaryrefslogtreecommitdiffstats
path: root/sys-utils/fallocate.c
diff options
context:
space:
mode:
authorKarel Zak2014-06-26 12:38:04 +0200
committerKarel Zak2014-06-26 12:38:04 +0200
commitb7f3f147f24f377c63c80f3aca38e2881774fa08 (patch)
tree20b039ec0c9d2109d0585c0fa1c7e6d1acecef34 /sys-utils/fallocate.c
parentfallocate: make man page readable for humans (diff)
downloadkernel-qcow2-util-linux-b7f3f147f24f377c63c80f3aca38e2881774fa08.tar.gz
kernel-qcow2-util-linux-b7f3f147f24f377c63c80f3aca38e2881774fa08.tar.xz
kernel-qcow2-util-linux-b7f3f147f24f377c63c80f3aca38e2881774fa08.zip
fallocate: use err_exclusive_options(), cleanup getopt_long() stuff
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/fallocate.c')
-rw-r--r--sys-utils/fallocate.c44
1 files changed, 24 insertions, 20 deletions
diff --git a/sys-utils/fallocate.c b/sys-utils/fallocate.c
index d950f9c57..512757f70 100644
--- a/sys-utils/fallocate.c
+++ b/sys-utils/fallocate.c
@@ -44,6 +44,7 @@
# include <linux/falloc.h> /* non-libc fallback for FALLOC_FL_* flags */
#endif
+
#ifndef FALLOC_FL_KEEP_SIZE
# define FALLOC_FL_KEEP_SIZE 0x1
#endif
@@ -65,6 +66,7 @@
#include "c.h"
#include "closestream.h"
#include "xalloc.h"
+#include "optutils.h"
static int verbose;
static char *filename;
@@ -282,6 +284,13 @@ int main(int argc, char **argv)
{ NULL, 0, 0, 0 }
};
+ static const ul_excl_t excl[] = { /* rows and cols in in ASCII order */
+ { 'c', 'd', 'p', 'z' },
+ { 'c', 'n' },
+ { 0 }
+ };
+ int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;
+
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
@@ -289,37 +298,40 @@ int main(int argc, char **argv)
while ((c = getopt_long(argc, argv, "hvVncpdzl:o:", longopts, NULL))
!= -1) {
+
+ err_exclusive_options(c, longopts, excl, excl_st);
+
switch(c) {
case 'h':
usage(stdout);
break;
- case 'V':
- printf(UTIL_LINUX_VERSION);
- return EXIT_SUCCESS;
case 'c':
mode |= FALLOC_FL_COLLAPSE_RANGE;
break;
- case 'p':
- mode |= FALLOC_FL_PUNCH_HOLE;
- /* fall through */
- case 'n':
- mode |= FALLOC_FL_KEEP_SIZE;
- break;
case 'd':
dig = 1;
break;
- case 'z':
- mode |= FALLOC_FL_ZERO_RANGE;
- break;
case 'l':
length = cvtnum(optarg);
break;
+ case 'n':
+ mode |= FALLOC_FL_KEEP_SIZE;
+ break;
case 'o':
offset = cvtnum(optarg);
break;
+ case 'p':
+ mode |= FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
+ break;
+ case 'z':
+ mode |= FALLOC_FL_ZERO_RANGE;
+ break;
case 'v':
verbose++;
break;
+ case 'V':
+ printf(UTIL_LINUX_VERSION);
+ return EXIT_SUCCESS;
default:
usage(stderr);
break;
@@ -327,9 +339,6 @@ 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"));
if (length == -2LL)
length = 0;
if (length < 0)
@@ -346,11 +355,6 @@ int main(int argc, char **argv)
if (optind == argc)
errx(EXIT_FAILURE, _("no filename specified."));
- 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++];
if (optind != argc) {