summaryrefslogtreecommitdiffstats
path: root/sys-utils/losetup.c
diff options
context:
space:
mode:
authorSami Kerola2012-06-15 22:56:45 +0200
committerSami Kerola2012-06-17 17:59:59 +0200
commit96801c4826238b2db665910ef57c4811e1a7d21b (patch)
tree95f5baa3ffcfebb6a7bf5ace6c7df78e6392dc32 /sys-utils/losetup.c
parentchcpu: use exclusive_option() (diff)
downloadkernel-qcow2-util-linux-96801c4826238b2db665910ef57c4811e1a7d21b.tar.gz
kernel-qcow2-util-linux-96801c4826238b2db665910ef57c4811e1a7d21b.tar.xz
kernel-qcow2-util-linux-96801c4826238b2db665910ef57c4811e1a7d21b.zip
losetup: use exclusive_option()
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'sys-utils/losetup.c')
-rw-r--r--sys-utils/losetup.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c
index 3c3229989..bc9e6c68a 100644
--- a/sys-utils/losetup.c
+++ b/sys-utils/losetup.c
@@ -20,6 +20,9 @@
#include "loopdev.h"
#include "xgetpass.h"
#include "closestream.h"
+#include "optutils.h"
+
+#define EXCL_ERROR "--{all,associated,set-capacity,detach,detach-all,find}"
enum {
A_CREATE = 1, /* setup a new device */
@@ -212,6 +215,17 @@ int main(int argc, char **argv)
int res = 0, showdev = 0, lo_flags = 0;
enum {
+ EXCL_NONE,
+ EXCL_ALL,
+ EXCL_ASSOCIATED,
+ EXCL_SET_CAPACITY,
+ EXCL_DETACH,
+ EXCL_DETACH_ALL,
+ EXCL_FIND
+ };
+ int excl_any = EXCL_NONE;
+
+ enum {
OPT_SIZELIMIT = CHAR_MAX + 1,
OPT_SHOW
};
@@ -245,17 +259,13 @@ int main(int argc, char **argv)
while ((c = getopt_long(argc, argv, "ac:d:De:E:fhj:o:p:PrvV",
longopts, NULL)) != -1) {
-
- if (act && strchr("acdDfj", c))
- errx(EXIT_FAILURE,
- _("the options %s are mutually exclusive"),
- "--{all,associated,set-capacity,detach,detach-all,find}");
-
switch (c) {
case 'a':
+ exclusive_option(&excl_any, EXCL_ALL, EXCL_ERROR);
act = A_SHOW;
break;
case 'c':
+ exclusive_option(&excl_any, EXCL_SET_CAPACITY, EXCL_ERROR);
act = A_SET_CAPACITY;
loopcxt_set_device(&lc, optarg);
break;
@@ -263,10 +273,12 @@ int main(int argc, char **argv)
lo_flags |= LO_FLAGS_READ_ONLY;
break;
case 'd':
+ exclusive_option(&excl_any, EXCL_DETACH, EXCL_ERROR);
act = A_DELETE;
loopcxt_set_device(&lc, optarg);
break;
case 'D':
+ exclusive_option(&excl_any, EXCL_DETACH_ALL, EXCL_ERROR);
act = A_DELETE_ALL;
break;
case 'E':
@@ -274,12 +286,14 @@ int main(int argc, char **argv)
encryption = optarg;
break;
case 'f':
+ exclusive_option(&excl_any, EXCL_FIND, EXCL_ERROR);
act = A_FIND_FREE;
break;
case 'h':
usage(stdout);
break;
case 'j':
+ exclusive_option(&excl_any, EXCL_ASSOCIATED, EXCL_ERROR);
act = A_SHOW;
file = optarg;
break;