]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - disk-utils/mkfs.minix.c
agetty: fix output of escaped characters
[thirdparty/util-linux.git] / disk-utils / mkfs.minix.c
index a4118f175dfe0e0de9ec96926345f91c3369236c..54c47da7e5a3aa8dfdf3b9028655b34eb1cd7def 100644 (file)
@@ -77,6 +77,8 @@
 #include "all-io.h"
 #include "closestream.h"
 #include "ismounted.h"
+
+#define XALLOC_EXIT_CODE MKFS_EX_ERROR
 #include "xalloc.h"
 
 #define MINIX_ROOT_INO 1
@@ -90,7 +92,7 @@
 #define DEFAULT_FS_VERSION 1
 
 /*
- * Global variables used in minix_programs.h inline fuctions
+ * Global variables used in minix_programs.h inline functions
  */
 int fs_version = DEFAULT_FS_VERSION;
 char *super_block_buffer;
@@ -129,8 +131,9 @@ static char *zone_map;
 #define mark_zone(x) (setbit(zone_map,(x)-get_first_zone()+1))
 #define unmark_zone(x) (clrbit(zone_map,(x)-get_first_zone()+1))
 
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
 {
+       FILE *out = stdout;
        fputs(USAGE_HEADER, out);
        fprintf(out, _(" %s [options] /dev/name [blocks]\n"), program_invocation_short_name);
        fputs(USAGE_OPTIONS, out);
@@ -142,10 +145,9 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
        fputs(_(" -c, --check             check the device for bad blocks\n"), out);
        fputs(_(" -l, --badblocks <file>  list of bad blocks from file\n"), out);
        fputs(USAGE_SEPARATOR, out);
-       fputs(USAGE_HELP, out);
-       fputs(USAGE_VERSION, out);
-       fprintf(out, USAGE_MAN_TAIL("mkfs.minix(8)"));
-       exit(out == stderr ? MKFS_EX_USAGE : MKFS_EX_OK);
+       printf(USAGE_HELP_OPTIONS(25));
+       printf(USAGE_MAN_TAIL("mkfs.minix(8)"));
+       exit(MKFS_EX_OK);
 }
 
 #ifdef TEST_SCRIPT
@@ -534,9 +536,9 @@ static void setup_tables(const struct fs_control *ctl) {
        if (fs_version == 3)
                Super3.s_ninodes = inodes;
        else {
-               Super.s_ninodes = inodes;
                if (inodes > MINIX_MAX_INODES)
                        inodes = MINIX_MAX_INODES;
+               Super.s_ninodes = inodes;
        }
        super_set_map_blocks(ctl, inodes);
        if (MINIX_MAX_INODES < first_zone_data())
@@ -571,7 +573,7 @@ static void setup_tables(const struct fs_control *ctl) {
 
 /*
  * Perform a test of a block; return the number of
- * blocks readable/writeable.
+ * blocks readable/writable.
  */
 static size_t do_check(const struct fs_control *ctl, char * buffer, int try, unsigned int current_block) {
        ssize_t got;
@@ -669,15 +671,11 @@ static int find_super_magic(const struct fs_control *ctl)
        case 1:
                if (ctl->fs_namelen == 14)
                        return MINIX_SUPER_MAGIC;
-               else
-                       return MINIX_SUPER_MAGIC2;
-               break;
+               return MINIX_SUPER_MAGIC2;
        case 2:
                if (ctl->fs_namelen == 14)
                        return MINIX2_SUPER_MAGIC;
-               else
-                       return MINIX2_SUPER_MAGIC2;
-               break;
+               return MINIX2_SUPER_MAGIC2;
        case 3:
                return MINIX3_SUPER_MAGIC;
        default:
@@ -762,12 +760,14 @@ int main(int argc, char ** argv)
        textdomain(PACKAGE);
        atexit(close_stdout);
 
+       strutils_set_exitcode(MKFS_EX_USAGE);
+
        while ((i = getopt_long(argc, argv, "1v23n:i:cl:Vh", longopts, NULL)) != -1)
                switch (i) {
                case '1':
                        fs_version = 1;
                        break;
-               case 'v': /* kept for backwards compatiblitly */
+               case 'v': /* kept for backwards compatibility */
                        warnx(_("-v is ambiguous, use '-2' instead"));
                        /* fallthrough */
                case '2':
@@ -795,9 +795,9 @@ int main(int argc, char ** argv)
                        printf(UTIL_LINUX_VERSION);
                        return MKFS_EX_OK;
                case 'h':
-                       usage(stdout);
+                       usage();
                default:
-                       usage(stderr);
+                       errtryhelp(MKFS_EX_USAGE);
                }
        argc -= optind;
        argv += optind;
@@ -810,7 +810,8 @@ int main(int argc, char ** argv)
                ctl.fs_blocks = strtoul_or_err(argv[0], _("failed to parse number of blocks"));
 
        if (!ctl.device_name) {
-               usage(stderr);
+               warnx(_("no device specified"));
+               errtryhelp(MKFS_EX_USAGE);
        }
        check_user_instructions(&ctl);
        if (is_mounted(ctl.device_name))