]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
blkpr: cleanup --help output and man page
authorKarel Zak <kzak@redhat.com>
Wed, 6 Apr 2022 10:14:12 +0000 (12:14 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 6 Apr 2022 10:14:12 +0000 (12:14 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/blkpr.8.adoc
sys-utils/blkpr.c

index dc8bb38932b4c79107329ded30a5384168d5828f..482bdec18892eda0160e85e45a23399e4694d306 100644 (file)
@@ -23,7 +23,8 @@ The _device_ argument is the pathname of the block device.
 == OPTIONS
 
 *-o*, *--operation* _operation_::
-The operation of persistent reservations, supported [register|reserve|release|preempt|preempt-abort|clear].
+The operation of persistent reservations, supported operations are *register*, *reserve*, *release*, *preempt*,
+*preempt-abort*, and *clear*.
 
 *-k*, *--key* _key_::
 The key the operation should operate on.
@@ -32,10 +33,11 @@ The key the operation should operate on.
 The old key the operation should operate on.
 
 *-f*, *--flag* _flag_::
-Supported flag [ignore-key].
+Supported flag is *ignore-key*.
 
-*-t*, *--type*::
-Supported type [write-exclusive|exclusive-access|write-exclusive-reg-only|exclusive-access-reg-only|write-exclusive-all-regs|exclusive-access-all-regs]
+*-t*, *--type* _type_::
+Supported types are *write-exclusive*, *exclusive-access*, *write-exclusive-reg-only*,
+*exclusive-access-reg-only*, *write-exclusive-all-regs*, and *exclusive-access-all-regs*.
 
 *-V*, *--version*::
 Display version information and exit.
index 3f8c19343f893dfd290ef28099e87523dd882704..02e5037fec50f4419f6b2e0c4092e5dcf26e16a0 100644 (file)
@@ -19,8 +19,6 @@
  * This program uses IOC_PR_XXX ioctl to do persistent reservations
  * operation on a block device if the device supports it.
  */
-
-
 #include <string.h>
 #include <unistd.h>
 #include <stdlib.h>
@@ -64,31 +62,18 @@ static struct type_string pr_flag[] = {
        {PR_FL_IGNORE_KEY, "ignore-key"}
 };
 
-static char *all_type_string(struct type_string *ts, int nmem)
+static void print_type(FILE *out, struct type_string *ts, size_t nmem)
 {
-       char *prtypes, *tmp;
-       size_t total = 0, length;
-       int i;
-
-       for (i = 0; i < nmem; i++) {
-               total += (strlen(ts[i].str) + 1);
-       }
+       size_t i;
 
-       tmp = prtypes = xmalloc(total);
        for (i = 0; i < nmem; i++) {
-               strcpy(tmp, ts[i].str);
-               length = strlen(ts[i].str);
-
-               tmp[length++] = '|';
-               tmp += length;
+               fprintf(out, "%s", ts[i].str);
+               fputs(i + 2 < nmem ? ", " :
+                     i + 1 < nmem ? _(", and ") : "\n", out);
        }
-
-       /* strip the last '|' */
-       prtypes[total - 1] = '\0';
-
-       return prtypes;
 }
 
+
 static int parse_type_by_str(struct type_string *ts, int nmem, char *pattern)
 {
        int i;
@@ -102,17 +87,18 @@ static int parse_type_by_str(struct type_string *ts, int nmem, char *pattern)
        return -1;
 }
 
-#define SUPPORTED(XX) \
-       static char *supported_##XX(void) \
-       { return all_type_string(XX, ARRAY_SIZE(XX)); }
+
+#define PRINT_SUPPORTED(XX) \
+       static void print_##XX(FILE *out) \
+       { print_type(out, XX, ARRAY_SIZE(XX)); }
 
 #define PARSE(XX) \
        static int parse_##XX(char *pattern) \
        { return parse_type_by_str(XX, ARRAY_SIZE(XX), pattern); }
 
-SUPPORTED(pr_type);
-SUPPORTED(pr_operation);
-SUPPORTED(pr_flag);
+PRINT_SUPPORTED(pr_type);
+PRINT_SUPPORTED(pr_operation);
+PRINT_SUPPORTED(pr_flag);
 
 PARSE(pr_type);
 PARSE(pr_operation);
@@ -176,6 +162,7 @@ static int do_pr(char *path, uint64_t key, uint64_t oldkey, int op, int type, in
 static void __attribute__((__noreturn__)) usage(void)
 {
        FILE *out = stdout;
+
        fputs(USAGE_HEADER, out);
        fprintf(out,
              _(" %s [options] <device>\n"), program_invocation_short_name);
@@ -184,17 +171,29 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_("Persistent reservations on a device.\n"), out);
 
        fputs(USAGE_OPTIONS, out);
-       fprintf(out, _(" -o, --operation <string>  supported operation [%s]\n"), supported_pr_operation());
-       fputs(_(" -k, --key <num>           key to operate\n"), out);
-       fputs(_(" -K, --oldkey <num>        old key to operate\n"), out);
-       fprintf(out, _(" -f, --flag <string>       supported flag [%s]\n"), supported_pr_flag());
-       fprintf(out, _(" -t, --type <string>       supported type [%s]\n"), supported_pr_type());
+       fputs(_(" -o, --operation <oper>   operation of persistent reservations\n"), out);
+       fputs(_(" -k, --key <num>          key to operate\n"), out);
+       fputs(_(" -K, --oldkey <num>       old key to operate\n"), out);
+       fputs(_(" -f, --flag <flag>        operation flag\n"), out);
+       fputs(_(" -t, --type <type>        operation type\n"), out);
 
        fputs(USAGE_SEPARATOR, out);
-       printf(USAGE_HELP_OPTIONS(21));
+       printf(USAGE_HELP_OPTIONS(26));
 
        fputs(USAGE_ARGUMENTS, out);
 
+       fputs(_(" <oper> is an operation, available operations:\n"), out);
+       fputs("        ", out);
+       print_pr_operation(out);
+
+       fputs(_(" <flag> is an operation flag, available flags:\n"), out);
+       fputs("        ", out);
+       print_pr_flag(out);
+
+       fputs(_(" <type> is an operation type, available types:\n"), out);
+       fputs("        ", out);
+       print_pr_type(out);
+
        printf(USAGE_MAN_TAIL("blkpr(8)"));
        exit(EXIT_SUCCESS);
 }