Whamcloud - gitweb
ChangeLog, badblocks.8.in, badblocks.c:
authorTheodore Ts'o <tytso@mit.edu>
Thu, 6 Jul 2000 13:19:43 +0000 (13:19 +0000)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 6 Jul 2000 13:19:43 +0000 (13:19 +0000)
  badblocks.8.in: Update manual page to reflect that the blocks-count
   parameter is now optional.  Also properly document the start-block
   parameter.
  badblocks.c (main): Allow the blocks-count parameter to be optional.
   If it's not specified, use the size of the device as a default.

misc/ChangeLog
misc/badblocks.8.in
misc/badblocks.c

index 4d6490f..16b0950 100644 (file)
@@ -1,3 +1,13 @@
+2000-07-06  Theodore Ts'o  <tytso@valinux.com>
+
+       * badblocks.8.in: Update manual page to reflect that the
+               blocks-count parameter is now optional.  Also properly
+               document the start-block parameter.
+
+       * badblocks.c (main): Allow the blocks-count parameter to be
+               optional.   If it's not specified, use the size of the
+               device as a default.
+
 2000-07-05  Theodore Ts'o  <tytso@valinux.com>
 
        * badblocks.c (test_nd): Significantly simplify the logic so that
index c08b6be..bbc4a08 100644 (file)
@@ -28,7 +28,11 @@ badblocks \- search a device for bad blocks
 .I num_passes
 ]
 .I device
-.IR blocks-count [ start-block ]
+[
+.I blocks-count
+] [
+.I start-block 
+]
 .SH DESCRIPTION
 .B badblocks
 is used to search for bad blocks on a device (usually a disk partition).
@@ -36,7 +40,10 @@ is used to search for bad blocks on a device (usually a disk partition).
 is the special file corresponding to the device (e.g
 .IR /dev/hdc1 ).
 .I blocks-count
-is the number of blocks on the device.
+is the number of blocks on the device; if it is not specified, the size
+of the device is used as a default.
+.I start-block is an optional parameter specifying the starting block number
+for the test, which allows the testing to start in the middle of the disk.
 .SH OPTIONS
 .TP
 .BI \-b " block-size"
index cc1cae9..c7f1d46 100644 (file)
@@ -70,7 +70,7 @@ static char *blkbuf;          /* Allocation array for bad block testing */
 
 static void usage(void)
 {
-       fprintf(stderr, _("Usage: %s [-b block_size] [-i input_file] [-o output_file] [-svwn]\n [-c blocks_at_once] [-p num_passes] device blocks_count [start_count]\n"),
+       fprintf(stderr, _("Usage: %s [-b block_size] [-i input_file] [-o output_file] [-svwn]\n [-c blocks_at_once] [-p num_passes] device [blocks_count] [start_count]\n"),
                 program_name);
        exit (1);
 }
@@ -624,7 +624,7 @@ int main (int argc, char ** argv)
        FILE * in = NULL;
        int block_size = 1024;
        unsigned long blocks_at_once = 16;
-       unsigned long blocks_count, from_count;
+       blk_t blocks_count, from_count;
        int num_passes = 0;
        int passes_clean = 0;
        int dev;
@@ -705,16 +705,31 @@ int main (int argc, char ** argv)
        if (optind > argc - 1)
                usage();
        device_name = argv[optind++];
-       if (optind > argc - 1)
-               usage();
-       blocks_count = strtoul (argv[optind], &tmp, 0);
-       if (*tmp)
-       {
-               com_err (program_name, 0, _("bad blocks count - %s"),
-                        argv[optind]);
-               exit (1);
+       if (optind > argc - 1) {
+               errcode = ext2fs_get_device_size(device_name,
+                                                block_size,
+                                                &blocks_count);
+               if (errcode == EXT2_ET_UNIMPLEMENTED) {
+                       com_err(program_name, 0,
+                               _("Couldn't determine device size; you "
+                                 "must specify\nthe size manually\n"));
+                       exit(1);
+               }
+               if (errcode) {
+                       com_err(program_name, errcode,
+                               _("while trying to determine device size"));
+                       exit(1);
+               }
+       } else {
+               blocks_count = strtoul (argv[optind], &tmp, 0);
+               if (*tmp) {
+                       com_err (program_name, 0, _("bad blocks count - %s"),
+                                argv[optind]);
+                       exit (1);
+               }
+               optind++;
        }
-       if (++optind <= argc-1) {
+       if (optind <= argc-1) {
                from_count = strtoul (argv[optind], &tmp, 0);
        } else from_count = 0;
        if (from_count >= blocks_count) {