From: Eric Biggers Date: Mon, 30 Sep 2019 19:27:22 +0000 (-0400) Subject: xfs_io/encrypt: generate encryption modes for 'help set_encpolicy' X-Git-Tag: v5.3.0-rc2~98 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eb6c66e650185b9a42f40d862f2eb0d2adb89201;p=thirdparty%2Fxfsprogs-dev.git xfs_io/encrypt: generate encryption modes for 'help set_encpolicy' Print all encryption modes that are defined in the code, rather than hardcoding the modes in the help text. Signed-off-by: Eric Biggers Reviewed-by: Eric Sandeen Signed-off-by: Eric Sandeen --- diff --git a/io/encrypt.c b/io/encrypt.c index 011a64109..7d3e3b736 100644 --- a/io/encrypt.c +++ b/io/encrypt.c @@ -136,12 +136,22 @@ struct fscrypt_get_key_status_arg { #endif /* !FS_IOC_GET_ENCRYPTION_POLICY_EX */ +static const struct { + __u8 mode; + const char *name; +} available_modes[] = { + {FSCRYPT_MODE_AES_256_XTS, "AES-256-XTS"}, + {FSCRYPT_MODE_AES_256_CTS, "AES-256-CTS"}, +}; + static cmdinfo_t get_encpolicy_cmd; static cmdinfo_t set_encpolicy_cmd; static void set_encpolicy_help(void) { + int i; + printf(_( "\n" " assign an encryption policy to the currently open file\n" @@ -155,8 +165,15 @@ set_encpolicy_help(void) " -f FLAGS -- policy flags\n" " -v VERSION -- version of policy structure\n" "\n" -" MODE can be numeric or one of the following predefined values:\n" -" AES-256-XTS, AES-256-CTS\n" +" MODE can be numeric or one of the following predefined values:\n")); + printf(" "); + for (i = 0; i < ARRAY_SIZE(available_modes); i++) { + printf("%s", available_modes[i].name); + if (i != ARRAY_SIZE(available_modes) - 1) + printf(", "); + } + printf("\n"); + printf(_( " FLAGS and VERSION must be numeric.\n" "\n" " Note that it's only possible to set an encryption policy on an empty\n" @@ -164,14 +181,6 @@ set_encpolicy_help(void) "\n")); } -static const struct { - __u8 mode; - const char *name; -} available_modes[] = { - {FSCRYPT_MODE_AES_256_XTS, "AES-256-XTS"}, - {FSCRYPT_MODE_AES_256_CTS, "AES-256-CTS"}, -}; - static bool parse_byte_value(const char *arg, __u8 *value_ret) {