From 2568ce89ea5c26225e8984733adc2ea7559d853a Mon Sep 17 00:00:00 2001 From: Mateusz Kusiak Date: Mon, 2 Jan 2023 09:35:15 +0100 Subject: mdadm: Add option validation for --update-subarray Subset of options available for "--update" is not same as for "--update-subarray". Define maps and enum for update options and use them instead of direct comparisons. Add proper error message. Signed-off-by: Mateusz Kusiak Signed-off-by: Jes Sorensen --- ReadMe.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'ReadMe.c') diff --git a/ReadMe.c b/ReadMe.c index 50a5e36d..bd8d50d2 100644 --- a/ReadMe.c +++ b/ReadMe.c @@ -655,3 +655,34 @@ char *mode_help[mode_count] = { [GROW] = Help_grow, [INCREMENTAL] = Help_incr, }; + +/** + * fprint_update_options() - Print valid update options depending on the mode. + * @outf: File (output stream) + * @update_mode: Used to distinguish update and update_subarray + */ +void fprint_update_options(FILE *outf, enum update_opt update_mode) +{ + int counter = UOPT_NAME, breakpoint = UOPT_HELP; + mapping_t *map = update_options; + + if (!outf) + return; + if (update_mode == UOPT_SUBARRAY_ONLY) { + breakpoint = UOPT_SUBARRAY_ONLY; + fprintf(outf, "Valid --update options for update-subarray are:\n\t"); + } else + fprintf(outf, "Valid --update options are:\n\t"); + while (map->num) { + if (map->num >= breakpoint) + break; + fprintf(outf, "'%s', ", map->name); + if (counter % 5 == 0) + fprintf(outf, "\n\t"); + counter++; + map++; + } + if ((counter - 1) % 5) + fprintf(outf, "\n"); + fprintf(outf, "\r"); +} -- cgit v1.2.3