diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM index 78275ebf1..f4c870f5c 100644 --- a/WHATS_NEW_DM +++ b/WHATS_NEW_DM @@ -1,5 +1,6 @@ Version 1.02.197 - =================================== + Add dmsetup --headings none|abbrev|full to set report headings type. Add DM_REPORT_OUTPUT_FIELD_IDS_IN_HEADINGS to provide alternative headings. Version 1.02.196 - 02nd August 2023 diff --git a/libdm/dm-tools/dmsetup.c b/libdm/dm-tools/dmsetup.c index 6fb09f865..ddee74a14 100644 --- a/libdm/dm-tools/dmsetup.c +++ b/libdm/dm-tools/dmsetup.c @@ -178,6 +178,7 @@ enum { GID_ARG, GROUP_ARG, GROUP_ID_ARG, + HEADINGS_ARG, HELP_ARG, HISTOGRAM_ARG, INACTIVE_ARG, @@ -4775,6 +4776,11 @@ static int _report_init(const struct command *cmd, const char *subcommand) _report_type |= DR_STATS_META; } + if (_switches[NOHEADINGS_ARG] && _switches[HEADINGS_ARG]) { + log_error("Only one of --headings and --noheadings permitted."); + return 0; + } + /* emulate old dmsetup behaviour */ if (_switches[NOHEADINGS_ARG]) { separator = ":"; @@ -4782,6 +4788,9 @@ static int _report_init(const struct command *cmd, const char *subcommand) headings = 0; } + if (_switches[HEADINGS_ARG]) + headings = _int_args[HEADINGS_ARG]; + if (_switches[UNBUFFERED_ARG]) buffered = 0; @@ -4848,8 +4857,11 @@ static int _report_init(const struct command *cmd, const char *subcommand) if (buffered) flags |= DM_REPORT_OUTPUT_BUFFERED; - if (headings) + if (headings) { flags |= DM_REPORT_OUTPUT_HEADINGS; + if (headings == 2) + flags |= DM_REPORT_OUTPUT_FIELD_IDS_IN_HEADINGS; + } if (field_prefixes) flags |= DM_REPORT_OUTPUT_FIELD_NAME_PREFIX; @@ -6166,7 +6178,8 @@ static int _stats_help(CMD_ARGS); * [--units ] [--programid ] [--regionid ] * [-o ] [-O|--sort ] * [-S|--select ] [--nameprefixes] - * [--noheadings] [--separator ] + * [--noheadings|--headings none|abbrev|full|0|1|2] + * [--separator ] * [--allprograms|--programid id] [...] * ungroup --groupid [--allprograms|--programid id] * [--alldevices|...] @@ -6336,7 +6349,8 @@ static void _dmsetup_usage(FILE *out) " [--udevcookie ] [--noudevrules] [--noudevsync] [--verifyudev]\n" " [-y|--yes] [--readahead {[+]|auto|none}] [--retry]\n" " [-c|-C|--columns] [-o ] [-O|--sort ]\n" - " [-S|--select ] [--nameprefixes] [--noheadings]\n" + " [-S|--select ] [--nameprefixes]\n" + " [--noheadings|--headings none|abbrev|full|0|1|2]\n" " [--separator ]\n\n", _base_commands[_base_command].name); @@ -6866,6 +6880,7 @@ static int _process_switches(int *argcp, char ***argvp, const char *dev_dir) {"gid", 1, &ind, GID_ARG}, {"group", 0, &ind, GROUP_ARG}, {"groupid", 1, &ind, GROUP_ID_ARG}, + {"headings", 1, &ind, HEADINGS_ARG}, {"help", 0, &ind, HELP_ARG}, {"histogram", 0, &ind, HISTOGRAM_ARG}, {"inactive", 0, &ind, INACTIVE_ARG}, @@ -7170,6 +7185,19 @@ static int _process_switches(int *argcp, char ***argvp, const char *dev_dir) _switches[EXEC_ARG]++; _command_to_exec = optarg; } + if (ind == HEADINGS_ARG) { + _switches[HEADINGS_ARG]++; + if (!strcasecmp(optarg, "none") || !strcmp(optarg, "0")) + _int_args[HEADINGS_ARG] = 0; + else if (!strcasecmp(optarg, "abbrev") || !strcmp(optarg, "1")) + _int_args[HEADINGS_ARG] = 1; + else if (!strcasecmp(optarg, "full") || !strcmp(optarg, "2")) + _int_args[HEADINGS_ARG] = 2; + else { + log_error("Unknown headings type."); + return 0; + } + } if (ind == TARGET_ARG) { _switches[TARGET_ARG]++; _target = optarg; diff --git a/man/dmsetup.8_main b/man/dmsetup.8_main index 0c53e39b0..176c01a01 100644 --- a/man/dmsetup.8_main +++ b/man/dmsetup.8_main @@ -91,6 +91,7 @@ dmsetup \(em low level logical volume management . IR fields ] . RB [ -O | --sort . IR sort_fields ] +. RB [ --idsinheadings ] . RB [ --nameprefixes ] . RB [ --separator . IR separator ] @@ -502,6 +503,10 @@ Specify the minor number. When creating a device, don't load any table. . .TP +.B --idsinheadings +Show column identifiers instead of names in report output headings. +. +.TP .B --nameprefixes Add a "DM_" prefix plus the field name to the output. Useful with \fB--noheadings\fP to produce a list of