summaryrefslogtreecommitdiffstats
path: root/misc-utils/lsblk.c
diff options
context:
space:
mode:
authorSami Kerola2012-06-14 21:46:16 +0200
committerSami Kerola2012-06-17 17:59:59 +0200
commit05187653478c279eff70b40cfabe50211c2d7793 (patch)
treef762556e17d147fb31f2ea4bcf8af8eb7fba5e0c /misc-utils/lsblk.c
parentfindmnt: use exclusive_option() (diff)
downloadkernel-qcow2-util-linux-05187653478c279eff70b40cfabe50211c2d7793.tar.gz
kernel-qcow2-util-linux-05187653478c279eff70b40cfabe50211c2d7793.tar.xz
kernel-qcow2-util-linux-05187653478c279eff70b40cfabe50211c2d7793.zip
lsblk: use exclusive_option()
This commit fixes exclusions which where meant to happen, but where not successful. For example lsblk -r -l # did exclude lsblk -l -r # did not exclude Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'misc-utils/lsblk.c')
-rw-r--r--misc-utils/lsblk.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c
index 24fb44f6d..ec1ca37d9 100644
--- a/misc-utils/lsblk.c
+++ b/misc-utils/lsblk.c
@@ -60,6 +60,7 @@
#include "sysfs.h"
#include "closestream.h"
#include "mangle.h"
+#include "optutils.h"
/* column IDs */
enum {
@@ -1140,12 +1141,6 @@ static void __attribute__((__noreturn__)) help(FILE *out)
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
-static void __attribute__((__noreturn__))
-errx_mutually_exclusive(const char *opts)
-{
- errx(EXIT_FAILURE, "%s %s", opts, _("options are mutually exclusive"));
-}
-
static void check_sysdevblock(void)
{
if (access(_PATH_SYS_DEVBLOCK, R_OK) != 0)
@@ -1159,6 +1154,19 @@ int main(int argc, char *argv[])
int tt_flags = TT_FL_TREE;
int i, c, status = EXIT_FAILURE;
+ enum {
+ EXCL_NONE,
+
+ EXCL_RAW,
+ EXCL_LIST,
+ EXCL_PAIRS,
+
+ EXCL_ALL,
+ EXCL_EXCLUDE
+ };
+ int excl_rlP = EXCL_NONE;
+ int excl_ae = EXCL_NONE;
+
static const struct option longopts[] = {
{ "all", 0, 0, 'a' },
{ "bytes", 0, 0, 'b' },
@@ -1191,6 +1199,7 @@ int main(int argc, char *argv[])
while((c = getopt_long(argc, argv, "abdDe:fhlnmo:PirstV", longopts, NULL)) != -1) {
switch(c) {
case 'a':
+ exclusive_option(&excl_ae, EXCL_ALL, "--{all,exclude}");
lsblk->all_devices = 1;
break;
case 'b':
@@ -1207,15 +1216,14 @@ int main(int argc, char *argv[])
columns[ncolumns++] = COL_DZERO;
break;
case 'e':
+ exclusive_option(&excl_ae, EXCL_EXCLUDE, "--{all,exclude}");
parse_excludes(optarg);
break;
case 'h':
help(stdout);
break;
case 'l':
- if ((tt_flags & TT_FL_RAW)|| (tt_flags & TT_FL_EXPORT))
- errx_mutually_exclusive("--{raw,list,export}");
-
+ exclusive_option(&excl_rlP, EXCL_LIST, "--{raw,list,pairs}");
tt_flags &= ~TT_FL_TREE; /* disable the default */
break;
case 'n':
@@ -1229,6 +1237,7 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
break;
case 'P':
+ exclusive_option(&excl_rlP, EXCL_PAIRS, "--{raw,list,pairs}");
tt_flags |= TT_FL_EXPORT;
tt_flags &= ~TT_FL_TREE; /* disable the default */
break;
@@ -1236,6 +1245,7 @@ int main(int argc, char *argv[])
tt_flags |= TT_FL_ASCII;
break;
case 'r':
+ exclusive_option(&excl_rlP, EXCL_RAW, "--{raw,list,pairs}");
tt_flags &= ~TT_FL_TREE; /* disable the default */
tt_flags |= TT_FL_RAW; /* enable raw */
break;
@@ -1288,9 +1298,7 @@ int main(int argc, char *argv[])
columns[ncolumns++] = COL_TARGET;
}
- if (nexcludes && lsblk->all_devices)
- errx_mutually_exclusive("--{all,exclude}");
- else if (!nexcludes)
+ if (!nexcludes)
excludes[nexcludes++] = 1; /* default: ignore RAM disks */
mnt_init_debug(0);