aboutsummaryrefslogtreecommitdiffstats
path: root/e2fsck/badblocks.c
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>1997-04-26 14:37:06 +0000
committerTheodore Ts'o <tytso@mit.edu>1997-04-26 14:37:06 +0000
commit74becf3c0a065f8d64e07ce4d31f9fe53be91d62 (patch)
treedf6573f851195eb5a0beaa0bc540a74fc89cda3d /e2fsck/badblocks.c
parent900e442732393189b8ecfd3bb39176e398b24970 (diff)
downloadplatform_external_e2fsprogs-74becf3c0a065f8d64e07ce4d31f9fe53be91d62.tar.gz
platform_external_e2fsprogs-74becf3c0a065f8d64e07ce4d31f9fe53be91d62.tar.bz2
platform_external_e2fsprogs-74becf3c0a065f8d64e07ce4d31f9fe53be91d62.zip
Many files:
Checkin of e2fsprogs 1.02.
Diffstat (limited to 'e2fsck/badblocks.c')
-rw-r--r--e2fsck/badblocks.c93
1 files changed, 30 insertions, 63 deletions
diff --git a/e2fsck/badblocks.c b/e2fsck/badblocks.c
index f0613d9dc..c81baae80 100644
--- a/e2fsck/badblocks.c
+++ b/e2fsck/badblocks.c
@@ -29,6 +29,7 @@ void read_bad_blocks_file(ext2_filsys fs, const char *bad_blocks_file,
errcode_t retval;
badblocks_list bb_list = 0;
FILE *f;
+ char buf[1024];
read_bitmaps(fs);
@@ -44,7 +45,6 @@ void read_bad_blocks_file(ext2_filsys fs, const char *bad_blocks_file,
fatal_error(0);
}
-
/*
* If we're appending to the bad blocks inode, read in the
* current bad blocks.
@@ -59,16 +59,33 @@ void read_bad_blocks_file(ext2_filsys fs, const char *bad_blocks_file,
}
/*
- * Now read in the bad blocks from the file.
+ * Now read in the bad blocks from the file; if
+ * bad_blocks_file is null, then try to run the badblocks
+ * command.
*/
- f = fopen(bad_blocks_file, "r");
- if (!f) {
- com_err("read_bad_blocks_file", errno,
- "while trying to open %s", bad_blocks_file);
- fatal_error(0);
+ if (bad_blocks_file) {
+ f = fopen(bad_blocks_file, "r");
+ if (!f) {
+ com_err("read_bad_blocks_file", errno,
+ "while trying to open %s", bad_blocks_file);
+ fatal_error(0);
+ }
+ } else {
+ sprintf(buf, "badblocks %s%s %d", preen ? "" : "-s ",
+ fs->device_name,
+ fs->super->s_blocks_count);
+ f = popen(buf, "r");
+ if (!f) {
+ com_err("read_bad_blocks_file", errno,
+ "while trying popen '%s'", buf);
+ fatal_error(0);
+ }
}
retval = ext2fs_read_bb_FILE(fs, f, &bb_list, invalid_block);
- fclose (f);
+ if (bad_blocks_file)
+ fclose(f);
+ else
+ pclose(f);
if (retval) {
com_err("ext2fs_read_bb_FILE", retval,
"while reading in list of bad blocks from file");
@@ -89,6 +106,11 @@ void read_bad_blocks_file(ext2_filsys fs, const char *bad_blocks_file,
return;
}
+void test_disk(ext2_filsys fs)
+{
+ read_bad_blocks_file(fs, 0, 1);
+}
+
static int check_bb_inode_blocks(ext2_filsys fs, blk_t *block_nr, int blockcnt,
void *private)
{
@@ -108,58 +130,3 @@ static int check_bb_inode_blocks(ext2_filsys fs, blk_t *block_nr, int blockcnt,
return 0;
}
-void test_disk(ext2_filsys fs)
-{
- errcode_t retval;
- badblocks_list bb_list = 0;
- FILE *f;
- char buf[1024];
-
- read_bitmaps(fs);
-
- /*
- * Always read in the current list of bad blocks.
- */
- retval = ext2fs_read_bb_inode(fs, &bb_list);
- if (retval) {
- com_err("ext2fs_read_bb_inode", retval,
- "while reading the bad blocks inode");
- fatal_error(0);
- }
-
- /*
- * Now run the bad blocks program
- */
- sprintf(buf, "badblocks %s%s %d", preen ? "" : "-s ",
- fs->device_name,
- fs->super->s_blocks_count);
- if (verbose)
- printf("Running command: %s\n", buf);
- f = popen(buf, "r");
- if (!f) {
- com_err("popen", errno,
- "while trying to run %s", buf);
- fatal_error(0);
- }
- retval = ext2fs_read_bb_FILE(fs, f, &bb_list, invalid_block);
- fclose (f);
- if (retval) {
- com_err("ext2fs_read_bb_FILE", retval,
- "while processing list of bad blocks from program");
- fatal_error(0);
- }
-
- /*
- * Finally, update the bad blocks from the bad_block_map
- */
- retval = ext2fs_update_bb_inode(fs, bb_list);
- if (retval) {
- com_err("ext2fs_update_bb_inode", retval,
- "while updating bad block inode");
- fatal_error(0);
- }
-
- badblocks_list_free(bb_list);
- return;
-}
-