]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - disk-utils/raw.c
wipefs: add --lock and LOCK_BLOCK_DEVICE
[thirdparty/util-linux.git] / disk-utils / raw.c
index 77945bc0fcdbe94d4f850a6b8f1bcc0abd995c16..b44a581a2d9599a59f6d8df300c0b8a76a65a47b 100644 (file)
 
 #define RAW_NR_MINORS 8192
 
-int do_query;
-int do_query_all;
+static int do_query;
+static int do_query_all;
 
-int master_fd;
-int raw_minor;
+static int master_fd;
+static int raw_minor;
 
 void open_raw_ctl(void);
 static int query(int minor_raw, const char *raw_name, int quiet);
 static int bind(int minor_raw, int block_major, int block_minor);
 
-static void __attribute__ ((__noreturn__)) usage(int err)
+static void __attribute__((__noreturn__)) usage(void)
 {
-       FILE *out = err == EXIT_SUCCESS ? stdout : stderr;
-
+       FILE *out = stdout;
        fputs(USAGE_HEADER, out);
        fprintf(out,
                _(" %1$s %2$srawN <major> <minor>\n"
@@ -60,10 +59,9 @@ static void __attribute__ ((__noreturn__)) usage(int err)
        fputs(USAGE_OPTIONS, out);
        fputs(_(" -q, --query    set query mode\n"), out);
        fputs(_(" -a, --all      query all raw devices\n"), out);
-       fputs(USAGE_HELP, out);
-       fputs(USAGE_VERSION, out);
-       fprintf(out, USAGE_MAN_TAIL("raw(8)"));
-       exit(err);
+       printf(USAGE_HELP_OPTIONS(16));
+       printf(USAGE_MAN_TAIL("raw(8)"));
+       exit(EXIT_SUCCESS);
 }
 
 static long strtol_octal_or_err(const char *str, const char *errmesg)
@@ -100,17 +98,17 @@ int main(int argc, char *argv[])
        struct stat statbuf;
 
        static const struct option longopts[] = {
-               {"query", no_argument, 0, 'q'},
-               {"all", no_argument, 0, 'a'},
-               {"version", no_argument, 0, 'V'},
-               {"help", no_argument, 0, 'h'},
-               {NULL, no_argument, 0, '0'},
+               {"query",   no_argument, NULL, 'q'},
+               {"all",     no_argument, NULL, 'a'},
+               {"version", no_argument, NULL, 'V'},
+               {"help",    no_argument, NULL, 'h'},
+               {NULL, 0, NULL, '0'},
        };
 
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
-       atexit(close_stdout);
+       close_stdout_atexit();
 
        while ((c = getopt_long(argc, argv, "qaVh", longopts, NULL)) != -1)
                switch (c) {
@@ -121,10 +119,9 @@ int main(int argc, char *argv[])
                        do_query_all = 1;
                        break;
                case 'V':
-                       printf(UTIL_LINUX_VERSION);
-                       return EXIT_SUCCESS;
+                       print_version(EXIT_SUCCESS);
                case 'h':
-                       usage(EXIT_SUCCESS);
+                       usage();
                default:
                        errtryhelp(EXIT_FAILURE);
                }
@@ -135,8 +132,10 @@ int main(int argc, char *argv[])
        open_raw_ctl();
 
        if (do_query_all) {
-               if (optind < argc)
-                       usage(EXIT_FAILURE);
+               if (optind < argc) {
+                       warnx(_("bad usage"));
+                       errtryhelp(EXIT_FAILURE);
+               }
                for (i = 1; i < RAW_NR_MINORS; i++)
                        query(i, NULL, 1);
                exit(EXIT_SUCCESS);
@@ -146,8 +145,10 @@ int main(int argc, char *argv[])
         * It's a bind or a single query.  Either way we need a raw device.
         */
 
-       if (optind >= argc)
-               usage(EXIT_FAILURE);
+       if (optind >= argc) {
+               warnx(_("bad usage"));
+               errtryhelp(EXIT_FAILURE);
+       }
        raw_name = argv[optind++];
 
        /*
@@ -156,9 +157,10 @@ int main(int argc, char *argv[])
         * causes udev to *remove* /dev/rawctl
         */
        rc = sscanf(raw_name, _PATH_RAWDEVDIR "raw%d", &raw_minor);
-       if (rc != 1)
-               usage(EXIT_FAILURE);
-
+       if (rc != 1) {
+               warnx(_("bad usage"));
+               errtryhelp(EXIT_FAILURE);
+       }
        if (raw_minor == 0)
                errx(EXIT_RAW_ACCESS,
                     _("Device '%s' is the control raw device "
@@ -197,7 +199,8 @@ int main(int argc, char *argv[])
                break;
 
        default:
-               usage(EXIT_FAILURE);
+               warnx(_("bad usage"));
+               errtryhelp(EXIT_FAILURE);
        }
 
        return bind(raw_minor, block_major, block_minor);