setpriv: placete "declaration of 'index' shadows a global declaration" warning
[oweals/busybox.git] / util-linux / mkfs_vfat.c
index c57cd9d5a07fa904a0891837e24666500c00edfb..426854b1ef048a93d1d279f2f296ff00f313ece4 100644 (file)
@@ -5,8 +5,44 @@
  *
  * Busybox'ed (2009) by Vladimir Dronnikov <dronnikov@gmail.com>
  *
- * Licensed under GPLv2, see file LICENSE in this tarball for details.
+ * Licensed under GPLv2, see file LICENSE in this source tree.
  */
+//config:config MKDOSFS
+//config:      bool "mkdosfs (6.8 kb)"
+//config:      default y
+//config:      select PLATFORM_LINUX
+//config:      help
+//config:      Utility to create FAT32 filesystems.
+//config:
+//config:config MKFS_VFAT
+//config:      bool "mkfs.vfat (6.8 kb)"
+//config:      default y
+//config:      select PLATFORM_LINUX
+//config:      help
+//config:      Alias to "mkdosfs".
+
+//                    APPLET_ODDNAME:name       main       location     suid_type     help
+//applet:IF_MKDOSFS(  APPLET_ODDNAME(mkdosfs,   mkfs_vfat, BB_DIR_SBIN, BB_SUID_DROP, mkfs_vfat))
+//applet:IF_MKFS_VFAT(APPLET_ODDNAME(mkfs.vfat, mkfs_vfat, BB_DIR_SBIN, BB_SUID_DROP, mkfs_vfat))
+
+//kbuild:lib-$(CONFIG_MKDOSFS) += mkfs_vfat.o
+//kbuild:lib-$(CONFIG_MKFS_VFAT) += mkfs_vfat.o
+
+//usage:#define mkfs_vfat_trivial_usage
+//usage:       "[-v] [-n LABEL] BLOCKDEV [KBYTES]"
+/* Accepted but ignored:
+       "[-c] [-C] [-I] [-l bad-block-file] [-b backup-boot-sector] "
+       "[-m boot-msg-file] [-i volume-id] "
+       "[-s sectors-per-cluster] [-S logical-sector-size] [-f number-of-FATs] "
+       "[-h hidden-sectors] [-F fat-size] [-r root-dir-entries] [-R reserved-sectors] "
+*/
+//usage:#define mkfs_vfat_full_usage "\n\n"
+//usage:       "Make a FAT32 filesystem\n"
+/* //usage:  "\n       -c      Check device for bad blocks" */
+//usage:     "\n       -v      Verbose"
+/* //usage:  "\n       -I      Allow to use entire disk device (e.g. /dev/hda)" */
+//usage:     "\n       -n LBL  Volume label"
+
 #include "libbb.h"
 
 #include <linux/hdreg.h> /* HDIO_GETGEO */
@@ -28,7 +64,7 @@
 
 #define ATTR_VOLUME     8
 
-#define        NUM_FATS        2
+#define NUM_FATS        2
 
 /* FAT32 filesystem looks like this:
  * sector -nn...-1: "hidden" sectors, all sectors before this partition
@@ -233,8 +269,9 @@ int mkfs_vfat_main(int argc UNUSED_PARAM, char **argv)
                OPT_v = 1 << 16, // verbose
        };
 
-       opt_complementary = "-1";//:b+:f+:F+:h+:r+:R+:s+:S+:vv:c--l:l--c";
-       opts = getopt32(argv, "Ab:cCf:F:h:Ii:l:m:n:r:R:s:S:v",
+       opts = getopt32(argv, "^"
+               "Ab:cCf:F:h:Ii:l:m:n:r:R:s:S:v"
+               "\0" "-1", //:b+:f+:F+:h+:r+:R+:s+:S+:vv:c--l:l--c
                NULL, NULL, NULL, NULL, NULL,
                NULL, NULL, &volume_label, NULL, NULL, NULL, NULL);
        argv += optind;
@@ -245,8 +282,7 @@ int mkfs_vfat_main(int argc UNUSED_PARAM, char **argv)
        volume_id = time(NULL);
 
        dev = xopen(device_name, O_RDWR);
-       if (fstat(dev, &st) < 0)
-               bb_simple_perror_msg_and_die(device_name);
+       xfstat(dev, &st, device_name);
 
        //
        // Get image size and sector size
@@ -563,7 +599,7 @@ int mkfs_vfat_main(int argc UNUSED_PARAM, char **argv)
                start_data_sector = (reserved_sect + NUM_FATS * sect_per_fat) * (bytes_per_sect / SECTOR_SIZE);
                start_data_block = (start_data_sector + SECTORS_PER_BLOCK - 1) / SECTORS_PER_BLOCK;
 
-               bb_info_msg("searching for bad blocks ");
+               bb_error_msg("searching for bad blocks");
                currently_testing = 0;
                try = TEST_BUFFER_BLOCKS;
                while (currently_testing < volume_size_blocks) {
@@ -601,7 +637,7 @@ int mkfs_vfat_main(int argc UNUSED_PARAM, char **argv)
                }
                free(blkbuf);
                if (badblocks)
-                       bb_info_msg("%d bad block(s)", badblocks);
+                       bb_error_msg("%d bad block(s)", badblocks);
        }
 #endif