From f63978aff759325b542de7134ab659c79dc47496 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sat, 13 May 2006 09:25:47 -0400 Subject: [PATCH] Fix read/write badblocks testing in mke2fs and e2fsck The exlcusive device safety check that was added inadvertently broke e2fsck -cc and mke2fs -cc since e2fsck and mke2fs hold the device in exclusive access when badblocks is run. So we add a private option to badblocks, -X, which is passed by e2fsck and mke2fs to badblocks to indicate that it is OK to skip the EXT2_MF_BUSY checks. Addresses Debian Bug: #366017 Signed-off-by: "Theodore Ts'o" --- e2fsck/ChangeLog | 5 +++++ e2fsck/badblocks.c | 2 +- misc/ChangeLog | 12 ++++++++++++ misc/badblocks.c | 10 +++++++--- misc/mke2fs.c | 2 +- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog index 545dafcc..2107b71e 100644 --- a/e2fsck/ChangeLog +++ b/e2fsck/ChangeLog @@ -1,3 +1,8 @@ +2006-05-13 Theodore Tso + + * badblocks.c (read_bad_blocks_file): Pass the private option -X + to badblocks so that e2fsck -cc will work correctly. + 2006-05-08 Theodore Tso * pass5.c (check_block_bitmaps, check_inode_bitmaps): Add support diff --git a/e2fsck/badblocks.c b/e2fsck/badblocks.c index 9ac51177..68c320bd 100644 --- a/e2fsck/badblocks.c +++ b/e2fsck/badblocks.c @@ -72,7 +72,7 @@ void read_bad_blocks_file(e2fsck_t ctx, const char *bad_blocks_file, goto fatal; } } else { - sprintf(buf, "badblocks -b %d %s%s%s %d", fs->blocksize, + sprintf(buf, "badblocks -b %d -X %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); diff --git a/misc/ChangeLog b/misc/ChangeLog index 0cb03895..36ec5c7d 100644 --- a/misc/ChangeLog +++ b/misc/ChangeLog @@ -1,3 +1,15 @@ +2006-05-13 Theodore Tso + + * mke2fs.c (test_disk): Pass the private option -X to badblocks so + that mke2fs -cc works again. (Addresses Debian bug: + #366017) + + * badblocks.c (main, check_mount): Add a private option, -X, which + is only intended for use by mke2fs and e2fsck to signal + that it's OK to skip the EXT2_MF_BUSY test since mke2fs + and e2fsck already have the block device opened + exclusively (and therefore no one else does). + 2006-05-08 Theodore Tso * mke2fs.c (write_inode_tables, setup_lazy_bg, main): Add support diff --git a/misc/badblocks.c b/misc/badblocks.c index 2e831332..5c895265 100644 --- a/misc/badblocks.c +++ b/misc/badblocks.c @@ -57,7 +57,7 @@ extern int optind; #include "nls-enable.h" const char * program_name = "badblocks"; -const char * done_string = N_("done \n"); +const char * done_string = N_("done \n"); static int v_flag = 0; /* verbose */ static int w_flag = 0; /* do r/w test: 0=no, 1=yes, @@ -68,6 +68,7 @@ static int t_flag = 0; /* number of test patterns */ static int t_max = 0; /* allocated test patterns */ static unsigned long *t_patts = NULL; /* test patterns */ static int current_O_DIRECT = 0; /* Current status of O_DIRECT flag */ +static int exclusive_ok = 0; #define T_INC 32 @@ -792,7 +793,7 @@ static void check_mount(char *device_name) exit(1); } - if (mount_flags & EXT2_MF_BUSY) { + if ((mount_flags & EXT2_MF_BUSY) && !exclusive_ok) { fprintf(stderr, _("%s is apparently in use by the system; "), device_name); if (force) @@ -852,7 +853,7 @@ int main (int argc, char ** argv) if (argc && *argv) program_name = *argv; - while ((c = getopt (argc, argv, "b:fi:o:svwnc:p:h:t:")) != EOF) { + while ((c = getopt (argc, argv, "b:fi:o:svwnc:p:h:t:X")) != EOF) { switch (c) { case 'b': block_size = strtoul (optarg, &tmp, 0); @@ -938,6 +939,9 @@ int main (int argc, char ** argv) t_patts[t_flag++] = pattern; } break; + case 'X': + exclusive_ok++; + break; default: usage(); } diff --git a/misc/mke2fs.c b/misc/mke2fs.c index 9f23ea5d..5c59b488 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -188,7 +188,7 @@ static void test_disk(ext2_filsys fs, badblocks_list *bb_list) errcode_t retval; char buf[1024]; - sprintf(buf, "badblocks -b %d %s%s%s %d", fs->blocksize, + sprintf(buf, "badblocks -b %d -X %s%s%s %d", fs->blocksize, quiet ? "" : "-s ", (cflag > 1) ? "-w " : "", fs->device_name, fs->super->s_blocks_count); if (verbose)