]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_io/encrypt: generate encryption modes for 'help set_encpolicy'
authorEric Biggers <ebiggers@google.com>
Mon, 30 Sep 2019 19:27:22 +0000 (15:27 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Mon, 30 Sep 2019 19:27:22 +0000 (15:27 -0400)
Print all encryption modes that are defined in the code, rather than
hardcoding the modes in the help text.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
io/encrypt.c

index 011a641099a8c70b95217cd647d9767283500ea1..7d3e3b73632f996fe488291bba2780fc43fcc44f 100644 (file)
@@ -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)
 {