From 53d3ca006245a1df91f0318ebfe583e305ebc372 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Wed, 15 Jul 2020 15:38:07 +0100 Subject: [PATCH] cryptsetup: add close --cancel-deferred Allows to remove a previously set deferred removal from the command line. [mbroz: ported to new CLI parsing] --- man/cryptsetup.8 | 5 ++++- src/cryptsetup.c | 7 +++++++ src/cryptsetup_arg_list.h | 2 ++ src/utils_arg_names.h | 1 + 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/man/cryptsetup.8 b/man/cryptsetup.8 index 45f793c5..31fe788c 100644 --- a/man/cryptsetup.8 +++ b/man/cryptsetup.8 @@ -101,7 +101,7 @@ For backward compatibility there are \fBclose\fR command aliases: \fBtcryptClose\fR (all behaves exactly the same, device type is determined automatically from active device). -\fB\fR can be [\-\-deferred] +\fB\fR can be [\-\-deferred] or [\-\-cancel\-deferred] .PP \fIstatus\fR @@ -1267,6 +1267,9 @@ for \fBpwquality.conf(5)\fR and \fBpasswdqc.conf(5)\fR. .B "\-\-deferred" Defers device removal in \fIclose\fR command until the last user closes it. .TP +.B "\-\-cancel\-deferred" +Removes a previously configured deferred device removal in \fIclose\fR command. +.TP .B "\-\-disable\-locks" Disable lock protection for metadata on disk. This option is valid only for LUKS2 and ignored for other formats. diff --git a/src/cryptsetup.c b/src/cryptsetup.c index 4e014b8f..e7985b5c 100644 --- a/src/cryptsetup.c +++ b/src/cryptsetup.c @@ -617,6 +617,8 @@ static int action_close(void) if (ARG_SET(OPT_DEFERRED_ID)) flags |= CRYPT_DEACTIVATE_DEFERRED; + if (ARG_SET(OPT_CANCEL_DEFERRED_ID)) + flags |= CRYPT_DEACTIVATE_DEFERRED_CANCEL; r = crypt_init_by_name(&cd, action_argv[0]); if (r == 0) @@ -3679,6 +3681,11 @@ int main(int argc, const char **argv) _("Options --refresh and --test-passphrase are mutually exclusive."), poptGetInvocationName(popt_context)); + if (ARG_SET(OPT_CANCEL_DEFERRED_ID) && ARG_SET(OPT_DEFERRED_ID)) + usage(popt_context, EXIT_FAILURE, + _("Options --cancel-deferred and --deferred cannot be used at the same time."), + poptGetInvocationName(popt_context)); + /* open action specific check */ if (ARG_SET(OPT_SHARED_ID) && strcmp_or_null(device_type, "plain")) usage(popt_context, EXIT_FAILURE, diff --git a/src/cryptsetup_arg_list.h b/src/cryptsetup_arg_list.h index c5bb0913..b61a811b 100644 --- a/src/cryptsetup_arg_list.h +++ b/src/cryptsetup_arg_list.h @@ -29,6 +29,8 @@ ARG(OPT_ALLOW_DISCARDS, '\0', POPT_ARG_NONE, N_("Allow discards (aka TRIM) reque ARG(OPT_BATCH_MODE, 'q', POPT_ARG_NONE, N_("Do not ask for confirmation"), NULL, CRYPT_ARG_BOOL, {}, {}) +ARG(OPT_CANCEL_DEFERRED, '\0', POPT_ARG_NONE, N_("Cancel a previously set deferred device removal"), NULL, CRYPT_ARG_BOOL, {}, OPT_DEFERRED_ACTIONS) + ARG(OPT_CIPHER, 'c', POPT_ARG_STRING, N_("The cipher used to encrypt the disk (see /proc/crypto)"), NULL, CRYPT_ARG_STRING, {}, {}) ARG(OPT_DEBUG, '\0', POPT_ARG_NONE, N_("Show debug messages"), NULL, CRYPT_ARG_BOOL, {}, {}) diff --git a/src/utils_arg_names.h b/src/utils_arg_names.h index 6f1716ae..8c213010 100644 --- a/src/utils_arg_names.h +++ b/src/utils_arg_names.h @@ -30,6 +30,7 @@ #define OPT_BITMAP_SECTORS_PER_BIT "bitmap-sectors-per-bit" #define OPT_BLOCK_SIZE "block-size" #define OPT_BUFFER_SECTORS "buffer-sectors" +#define OPT_CANCEL_DEFERRED "cancel-deferred" #define OPT_CHECK_AT_MOST_ONCE "check-at-most-once" #define OPT_CIPHER "cipher" #define OPT_DATA_BLOCK_SIZE "data-block-size"