summaryrefslogtreecommitdiffstats
path: root/ReadMe.c
diff options
context:
space:
mode:
authorMateusz Kusiak <mateusz.kusiak@intel.com>2023-01-02 09:35:15 +0100
committerJes Sorensen <jes@trained-monkey.org>2023-01-04 16:20:58 +0100
commit2568ce89ea5c26225e8984733adc2ea7559d853a (patch)
treeff1429fa3379e0a974d34d68aaa1721814bf8c2d /ReadMe.c
parentmdadm: create ident_init() (diff)
downloadmdadm-2568ce89ea5c26225e8984733adc2ea7559d853a.tar.xz
mdadm-2568ce89ea5c26225e8984733adc2ea7559d853a.zip
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 <mateusz.kusiak@intel.com> Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
Diffstat (limited to 'ReadMe.c')
-rw-r--r--ReadMe.c31
1 files changed, 31 insertions, 0 deletions
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");
+}