]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - disk-utils/mkfs.minix.c
wipefs: add --lock and LOCK_BLOCK_DEVICE
[thirdparty/util-linux.git] / disk-utils / mkfs.minix.c
index 96d36b034eaba3b03a38c8e7a49cdd0ba5e602b3..d6f5756a6c8a26ac21b0f558835aa35b4fb60fd6 100644 (file)
@@ -34,7 +34,7 @@
  *
  * 30.10.94  -  Added support for v2 filesystem
  *             (Andreas Schwab, schwab@issan.informatik.uni-dortmund.de)
- * 
+ *
  * 09.11.94  - Added test to prevent overwrite of mounted fs adapted
  *             from Theodore Ts'o's (tytso@athena.mit.edu) mke2fs
  *             program.  (Daniel Quinlan, quinlan@yggdrasil.com)
@@ -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
@@ -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
@@ -575,7 +577,7 @@ static void setup_tables(const struct fs_control *ctl) {
  */
 static size_t do_check(const struct fs_control *ctl, char * buffer, int try, unsigned int current_block) {
        ssize_t got;
-       
+
        /* Seek to the correct loc. */
        if (lseek(ctl->device_fd, current_block * MINIX_BLOCK_SIZE, SEEK_SET) !=
                       current_block * MINIX_BLOCK_SIZE )
@@ -584,7 +586,7 @@ static size_t do_check(const struct fs_control *ctl, char * buffer, int try, uns
 
        /* Try the read */
        got = read(ctl->device_fd, buffer, try * MINIX_BLOCK_SIZE);
-       if (got < 0) got = 0;   
+       if (got < 0) got = 0;
        if (got & (MINIX_BLOCK_SIZE - 1 )) {
                printf(_("Weird values in do_check: probably bugs\n"));
        }
@@ -683,7 +685,7 @@ static int find_super_magic(const struct fs_control *ctl)
 
 static void determine_device_blocks(struct fs_control *ctl, const struct stat *statbuf)
 {
-       unsigned long long dev_blocks;
+       unsigned long long dev_blocks = 0;
 
        if (S_ISBLK(statbuf->st_mode)) {
                int sectorsize;
@@ -756,7 +758,7 @@ int main(int argc, char ** argv)
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
-       atexit(close_stdout);
+       close_stdout_atexit();
 
        strutils_set_exitcode(MKFS_EX_USAGE);
 
@@ -790,10 +792,9 @@ int main(int argc, char ** argv)
                        listfile = optarg;
                        break;
                case 'V':
-                       printf(UTIL_LINUX_VERSION);
-                       return MKFS_EX_OK;
+                       print_version(MKFS_EX_OK);
                case 'h':
-                       usage(stdout);
+                       usage();
                default:
                        errtryhelp(MKFS_EX_USAGE);
                }
@@ -808,7 +809,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))