diff --git a/src/cryptsetup.c b/src/cryptsetup.c index 515da01a..bb48a9d9 100644 --- a/src/cryptsetup.c +++ b/src/cryptsetup.c @@ -3105,6 +3105,15 @@ static void basic_options_cb(poptContext popt_context, } } +static void cryptsetup_init_arg_aliases(void) +{ + unsigned i; + + for (i = 1; i < ARRAY_SIZE(tool_core_args); i++) + if (tool_core_args[i].type == CRYPT_ARG_ALIAS) + ARG_INIT_ALIAS(i); +} + int main(int argc, const char **argv) { static struct poptOption popt_help_options[] = { @@ -3131,6 +3140,9 @@ int main(int argc, const char **argv) const char *aname, *error_message; int r; + /* initialize aliases */ + cryptsetup_init_arg_aliases(); + crypt_set_log_callback(NULL, tool_log, &log_parms); setlocale(LC_ALL, ""); diff --git a/src/cryptsetup.h b/src/cryptsetup.h index f7f89586..b571b44f 100644 --- a/src/cryptsetup.h +++ b/src/cryptsetup.h @@ -132,7 +132,8 @@ typedef enum { CRYPT_ARG_INT32, CRYPT_ARG_UINT32, CRYPT_ARG_INT64, - CRYPT_ARG_UINT64 + CRYPT_ARG_UINT64, + CRYPT_ARG_ALIAS } crypt_arg_type_info; struct tools_arg { @@ -145,6 +146,10 @@ struct tools_arg { uint32_t u32_value; int32_t i32_value; int64_t i64_value; + union { + unsigned id; + struct tools_arg *ptr; + } o; } u; const char *actions_array[MAX_ACTIONS]; }; diff --git a/src/utils_arg_macros.h b/src/utils_arg_macros.h index be828a0c..fb84041f 100644 --- a/src/utils_arg_macros.h +++ b/src/utils_arg_macros.h @@ -93,4 +93,11 @@ do { \ tool_core_args[(X)].set = true; \ } while (0) + +#define ARG_INIT_ALIAS(X) \ +do { \ + assert(tool_core_args[(X)].type == CRYPT_ARG_ALIAS); \ + tool_core_args[(X)].u.o.ptr = &tool_core_args[tool_core_args[(X)].u.o.id]; \ +} while (0) + #endif diff --git a/src/utils_args.c b/src/utils_args.c index b7971922..8ffddec6 100644 --- a/src/utils_args.c +++ b/src/utils_args.c @@ -75,6 +75,9 @@ void tools_parse_arg_value(poptContext popt_context, crypt_arg_type_info type, s arg->u.u64_value = ull; } break; + case CRYPT_ARG_ALIAS: + tools_parse_arg_value(popt_context, arg->u.o.ptr->type, arg->u.o.ptr, popt_arg, arg->u.o.id, needs_size_conv_fn); + break; default: /* this signals internal tools coding mistake */ abort();