From 971e2ef0cb500865692afc3bde6277e53e37a99a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 7 Dec 2016 15:26:11 -0500 Subject: [PATCH] dissect: add DISSECT_IMAGE_DISCARD_ANY mask This makes the code to set arg_flags much more readable. --- src/dissect/dissect.c | 14 +++++++++----- src/shared/dissect-image.h | 5 ++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/dissect/dissect.c b/src/dissect/dissect.c index e3c96b7..f2f1e13 100644 --- a/src/dissect/dissect.c +++ b/src/dissect/dissect.c @@ -95,21 +95,25 @@ static int parse_argv(int argc, char *argv[]) { arg_flags |= DISSECT_IMAGE_READ_ONLY; break; - case ARG_DISCARD: + case ARG_DISCARD: { + DissectImageFlags flags; + if (streq(optarg, "disabled")) - arg_flags &= ~(DISSECT_IMAGE_DISCARD_ON_LOOP|DISSECT_IMAGE_DISCARD|DISSECT_IMAGE_DISCARD_ON_CRYPTO); + flags = 0; else if (streq(optarg, "loop")) - arg_flags = (arg_flags & ~(DISSECT_IMAGE_DISCARD|DISSECT_IMAGE_DISCARD_ON_CRYPTO)) | DISSECT_IMAGE_DISCARD_ON_LOOP; + flags = DISSECT_IMAGE_DISCARD_ON_LOOP; else if (streq(optarg, "all")) - arg_flags = (arg_flags & ~(DISSECT_IMAGE_DISCARD_ON_CRYPTO)) | DISSECT_IMAGE_DISCARD_ON_LOOP | DISSECT_IMAGE_DISCARD; + flags = DISSECT_IMAGE_DISCARD_ON_LOOP | DISSECT_IMAGE_DISCARD; else if (streq(optarg, "crypt")) - arg_flags |= DISSECT_IMAGE_DISCARD_ON_LOOP | DISSECT_IMAGE_DISCARD | DISSECT_IMAGE_DISCARD_ON_CRYPTO; + flags = DISSECT_IMAGE_DISCARD_ANY; else { log_error("Unknown --discard= parameter: %s", optarg); return -EINVAL; } + arg_flags = (arg_flags & ~DISSECT_IMAGE_DISCARD_ANY) | flags; break; + } case ARG_ROOT_HASH: { void *p; diff --git a/src/shared/dissect-image.h b/src/shared/dissect-image.h index 902c8d4..175ddd8 100644 --- a/src/shared/dissect-image.h +++ b/src/shared/dissect-image.h @@ -61,9 +61,12 @@ static inline int PARTITION_VERITY_OF(int p) { typedef enum DissectImageFlags { DISSECT_IMAGE_READ_ONLY = 1, - DISSECT_IMAGE_DISCARD_ON_LOOP = 2, /* Turn on "discard" if on loop device and file system supports it */ + DISSECT_IMAGE_DISCARD_ON_LOOP = 2, /* Turn on "discard" if on a loop device and file system supports it */ DISSECT_IMAGE_DISCARD = 4, /* Turn on "discard" if file system supports it, on all block devices */ DISSECT_IMAGE_DISCARD_ON_CRYPTO = 8, /* Turn on "discard" also on crypto devices */ + DISSECT_IMAGE_DISCARD_ANY = DISSECT_IMAGE_DISCARD_ON_LOOP | + DISSECT_IMAGE_DISCARD | + DISSECT_IMAGE_DISCARD_ON_CRYPTO, } DissectImageFlags; struct DissectedImage { -- 2.7.4