In mke2fs and e2fsck, specifying the -c option twice will now do
a read/write test on the disk. Update the man pages to encourage
using the -c option, and to discouraging running badblocks separately,
since users tend to forget to set the blocksize when running
badblocks.
diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog
index 9748f65..41734f4 100644
--- a/e2fsck/ChangeLog
+++ b/e2fsck/ChangeLog
@@ -1,3 +1,17 @@
+2001-12-24 Theodore Tso <tytso@valinux.com>
+
+ * unix.c (PRS): Don't allow the -c and -l/-L options to be
+ specified at the same time.
+
+ * e2fsck.h (E2F_OPT_WRITECHECK), unix.c (PRS),
+ badblocks.c (read_bad_blocks_file): If two -c options are
+ specified, then perform a non-destructive read/write scan
+ of the disk.
+
+ * e2fsck.8.in: Document the double -c option; also encourage users
+ to use -c instead of the -l/-L options since it's too hard
+ for users to get things like the blocksize parameter correct.
+
2001-12-23 Theodore Tso <tytso@valinux.com>
* util.c (get_backup_sb): This function now searches for the
diff --git a/e2fsck/badblocks.c b/e2fsck/badblocks.c
index c7cc8cc..92aa3c1 100644
--- a/e2fsck/badblocks.c
+++ b/e2fsck/badblocks.c
@@ -72,8 +72,9 @@
goto fatal;
}
} else {
- sprintf(buf, "badblocks -b %d %s%s %d", fs->blocksize,
+ sprintf(buf, "badblocks -b %d %s%s%s %d", fs->blocksize,
(ctx->options & E2F_OPT_PREEN) ? "" : "-s ",
+ (ctx->options & E2F_OPT_WRITECHECK) ? "-n " : "",
fs->device_name, fs->super->s_blocks_count);
f = popen(buf, "r");
if (!f) {
diff --git a/e2fsck/e2fsck.8.in b/e2fsck/e2fsck.8.in
index 8701af7..ad517c1 100644
--- a/e2fsck/e2fsck.8.in
+++ b/e2fsck/e2fsck.8.in
@@ -95,6 +95,8 @@
.BR badblocks (8)
program to find any blocks which are bad on the filesystem,
and then marks them as bad by adding them to the bad block inode.
+If this option is specified twice, then the bad block scan will be done
+using a non-destructive read-write test.
.TP
.B \-C
This option causes
@@ -127,11 +129,21 @@
@JDEV@found.
.TP
.BI \-l " filename"
-Add the blocks listed in the file specified by
+Add the block numbers listed in the file specified by
.I filename
to the list of bad blocks. The format of this file is the same as the
one generated by the
.BR badblocks (8)
+program. Note that the block numbers are based on the blocksize
+of the filesystem. Hence,
+.BR badblocks (8)
+must be given the blocksize of the filesystem in order to obtain correct
+results. As a result, it is much simpler and safer to use the
+.B -c
+option to
+.BR e2fsck ,
+since it will assure that the correct parameters are passed to the
+.B badblocks
program.
.TP
.BI \-L " filename"
diff --git a/e2fsck/e2fsck.h b/e2fsck/e2fsck.h
index d3eeedf..e1e92ba 100644
--- a/e2fsck/e2fsck.h
+++ b/e2fsck/e2fsck.h
@@ -102,6 +102,7 @@
#define E2F_OPT_CHECKBLOCKS 0x0040
#define E2F_OPT_DEBUG 0x0080
#define E2F_OPT_FORCE 0x0100
+#define E2F_OPT_WRITECHECK 0x0200
/*
* E2fsck flags
diff --git a/e2fsck/unix.c b/e2fsck/unix.c
index 43a235f..cbedd5d 100644
--- a/e2fsck/unix.c
+++ b/e2fsck/unix.c
@@ -511,7 +511,8 @@
#endif
break;
case 'c':
- cflag++;
+ if (cflag++)
+ ctx->options |= E2F_OPT_WRITECHECK;
ctx->options |= E2F_OPT_CHECKBLOCKS;
break;
case 'r':
@@ -610,11 +611,16 @@
if (swapfs) {
if (cflag || bad_blocks_file) {
fprintf(stderr, _("Incompatible options not "
- "allowed when byte-swapping.\n"));
+ "allowed when byte-swapping.\n"));
exit(FSCK_USAGE);
}
}
#endif
+ if (cflag && bad_blocks_file) {
+ fprintf(stderr, _("The -c and the -l/-L options may "
+ "not be both used at the same time.\n"));
+ exit(FSCK_USAGE);
+ }
#ifdef HAVE_SIGNAL_H
/*
* Set up signal action
diff --git a/misc/ChangeLog b/misc/ChangeLog
index bcdeefe..8f8ff02 100644
--- a/misc/ChangeLog
+++ b/misc/ChangeLog
@@ -1,5 +1,16 @@
2001-12-24 Theodore Tso <tytso@valinux.com>
+ * mke2fs.c (main, test_disk): If two -c options are
+ specified, then perform a destructive read/write test
+ of the disk.
+
+ * mke2fs.8.in: Document the double -c option; also encourage users
+ to use -c instead of the -l/-L options since it's too hard
+ for users to get things like the blocksize parameter correct.
+
+ * badblocks.8.in: Encourage users to use the -c option in mke2fs
+ and e2fsck instead of running badblocks directly.
+
* mke2fs.c (create_lost_and_found): The lost+found directory is
now created with 0700 permissions, since files which get
dropped into that directory may have come from a protected
diff --git a/misc/badblocks.8.in b/misc/badblocks.8.in
index 868b30a..44517b3 100644
--- a/misc/badblocks.8.in
+++ b/misc/badblocks.8.in
@@ -46,6 +46,28 @@
is an optional parameter specifying the starting block number
for the test, which allows the testing to start in the middle of the
disk. If it is not specified the first block on the disk is used as a default.
+.PP
+.B Important note:
+If the output of
+.B badblocks
+is going to be fed to the
+.B e2fsck
+or
+.B mke2fs
+programs, it is important that the block size is properly specified,
+since the block numbers which are generated is very dependent on the
+block size in use. For this reason, it is strongly recommended that
+users
+.B not
+run
+.B badblocks
+directly, but rather use the
+.B \-c
+option of the
+.B e2fsck
+and
+.B mke2fs
+programs.
.SH OPTIONS
.TP
.BI \-b " block-size"
diff --git a/misc/mke2fs.8.in b/misc/mke2fs.8.in
index 32de867..59fa974 100644
--- a/misc/mke2fs.8.in
+++ b/misc/mke2fs.8.in
@@ -141,8 +141,9 @@
option).
.TP
.B \-c
-Check the device for bad blocks before creating the file system, using a
-fast read-only test.
+Check the device for bad blocks before creating the file system. If
+this option is specified twice, then a slower, destructive, read-write
+test is used instead of a fast read-only test.
.TP
.BI \-f " fragment-size"
Specify the size of fragments in bytes.
@@ -225,7 +226,18 @@
.TP
.BI \-l " filename"
Read the bad blocks list from
-.IR filename .
+.IR filename .
+Note that the block numbers in the bad block list must be generated
+using the same block size as used by mke2fs. As a result, the
+.B \-c
+option to
+.B mke2fs
+is a much simpler and less error-prone method of checking a disk for bad
+blocks before formatting it, as
+.B mke2fs
+will automatically pass the correct parameters to the
+.B badblocks
+program.
.TP
.B \-L
Set the volume label for the filesystem.
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
index 92f3463..c55aab0 100644
--- a/misc/mke2fs.c
+++ b/misc/mke2fs.c
@@ -216,9 +216,9 @@
errcode_t retval;
char buf[1024];
- sprintf(buf, "badblocks -b %d %s%s %d", fs->blocksize,
- quiet ? "" : "-s ", fs->device_name,
- fs->super->s_blocks_count);
+ sprintf(buf, "badblocks -b %d %s%s%s %d", fs->blocksize,
+ quiet ? "" : "-s ", (cflag > 1) ? "-w " : "",
+ fs->device_name, fs->super->s_blocks_count);
if (verbose)
printf(_("Running command: %s\n"), buf);
f = popen(buf, "r");
@@ -838,7 +838,7 @@
break;
case 'c': /* Check for bad blocks */
case 't': /* deprecated */
- cflag = 1;
+ cflag++;
break;
case 'f':
size = strtoul(optarg, &tmp, 0);