diff options
Diffstat (limited to 'e2fsprogs/e2fsck/badblocks.c')
-rw-r--r-- | e2fsprogs/e2fsck/badblocks.c | 135 |
1 files changed, 0 insertions, 135 deletions
diff --git a/e2fsprogs/e2fsck/badblocks.c b/e2fsprogs/e2fsck/badblocks.c deleted file mode 100644 index 1ab76a091..000000000 --- a/e2fsprogs/e2fsck/badblocks.c +++ /dev/null | |||
@@ -1,135 +0,0 @@ | |||
1 | /* | ||
2 | * badblocks.c --- replace/append bad blocks to the bad block inode | ||
3 | * | ||
4 | * Copyright (C) 1993, 1994 Theodore Ts'o. This file may be | ||
5 | * redistributed under the terms of the GNU Public License. | ||
6 | */ | ||
7 | |||
8 | #include <time.h> | ||
9 | #ifdef HAVE_ERRNO_H | ||
10 | #include <errno.h> | ||
11 | #endif | ||
12 | |||
13 | #include "e2fsck.h" | ||
14 | |||
15 | static int check_bb_inode_blocks(ext2_filsys fs, blk_t *block_nr, int blockcnt, | ||
16 | void *priv_data); | ||
17 | |||
18 | |||
19 | static void invalid_block(ext2_filsys fs EXT2FS_ATTR((unused)), blk_t blk) | ||
20 | { | ||
21 | printf(_("Bad block %u out of range; ignored.\n"), blk); | ||
22 | return; | ||
23 | } | ||
24 | |||
25 | void read_bad_blocks_file(e2fsck_t ctx, const char *bad_blocks_file, | ||
26 | int replace_bad_blocks) | ||
27 | { | ||
28 | ext2_filsys fs = ctx->fs; | ||
29 | errcode_t retval; | ||
30 | badblocks_list bb_list = 0; | ||
31 | FILE *f; | ||
32 | char buf[1024]; | ||
33 | |||
34 | e2fsck_read_bitmaps(ctx); | ||
35 | |||
36 | /* | ||
37 | * Make sure the bad block inode is sane. If there are any | ||
38 | * illegal blocks, clear them. | ||
39 | */ | ||
40 | retval = ext2fs_block_iterate(fs, EXT2_BAD_INO, 0, 0, | ||
41 | check_bb_inode_blocks, 0); | ||
42 | if (retval) { | ||
43 | com_err("ext2fs_block_iterate", retval, | ||
44 | _("while sanity checking the bad blocks inode")); | ||
45 | goto fatal; | ||
46 | } | ||
47 | |||
48 | /* | ||
49 | * If we're appending to the bad blocks inode, read in the | ||
50 | * current bad blocks. | ||
51 | */ | ||
52 | if (!replace_bad_blocks) { | ||
53 | retval = ext2fs_read_bb_inode(fs, &bb_list); | ||
54 | if (retval) { | ||
55 | com_err("ext2fs_read_bb_inode", retval, | ||
56 | _("while reading the bad blocks inode")); | ||
57 | goto fatal; | ||
58 | } | ||
59 | } | ||
60 | |||
61 | /* | ||
62 | * Now read in the bad blocks from the file; if | ||
63 | * bad_blocks_file is null, then try to run the badblocks | ||
64 | * command. | ||
65 | */ | ||
66 | if (bad_blocks_file) { | ||
67 | f = fopen(bad_blocks_file, "r"); | ||
68 | if (!f) { | ||
69 | com_err("read_bad_blocks_file", errno, | ||
70 | _("while trying to open %s"), bad_blocks_file); | ||
71 | goto fatal; | ||
72 | } | ||
73 | } else { | ||
74 | sprintf(buf, "badblocks -b %d %s%s%s %d", fs->blocksize, | ||
75 | (ctx->options & E2F_OPT_PREEN) ? "" : "-s ", | ||
76 | (ctx->options & E2F_OPT_WRITECHECK) ? "-n " : "", | ||
77 | fs->device_name, fs->super->s_blocks_count); | ||
78 | f = popen(buf, "r"); | ||
79 | if (!f) { | ||
80 | com_err("read_bad_blocks_file", errno, | ||
81 | _("while trying popen '%s'"), buf); | ||
82 | goto fatal; | ||
83 | } | ||
84 | } | ||
85 | retval = ext2fs_read_bb_FILE(fs, f, &bb_list, invalid_block); | ||
86 | if (bad_blocks_file) | ||
87 | fclose(f); | ||
88 | else | ||
89 | pclose(f); | ||
90 | if (retval) { | ||
91 | com_err("ext2fs_read_bb_FILE", retval, | ||
92 | _("while reading in list of bad blocks from file")); | ||
93 | goto fatal; | ||
94 | } | ||
95 | |||
96 | /* | ||
97 | * Finally, update the bad blocks from the bad_block_map | ||
98 | */ | ||
99 | retval = ext2fs_update_bb_inode(fs, bb_list); | ||
100 | if (retval) { | ||
101 | com_err("ext2fs_update_bb_inode", retval, | ||
102 | _("while updating bad block inode")); | ||
103 | goto fatal; | ||
104 | } | ||
105 | |||
106 | ext2fs_badblocks_list_free(bb_list); | ||
107 | return; | ||
108 | |||
109 | fatal: | ||
110 | ctx->flags |= E2F_FLAG_ABORT; | ||
111 | return; | ||
112 | |||
113 | } | ||
114 | |||
115 | static int check_bb_inode_blocks(ext2_filsys fs, | ||
116 | blk_t *block_nr, | ||
117 | int blockcnt EXT2FS_ATTR((unused)), | ||
118 | void *priv_data EXT2FS_ATTR((unused))) | ||
119 | { | ||
120 | if (!*block_nr) | ||
121 | return 0; | ||
122 | |||
123 | /* | ||
124 | * If the block number is outrageous, clear it and ignore it. | ||
125 | */ | ||
126 | if (*block_nr >= fs->super->s_blocks_count || | ||
127 | *block_nr < fs->super->s_first_data_block) { | ||
128 | printf(_("Warning illegal block %u found in bad block inode. Cleared.\n"), *block_nr); | ||
129 | *block_nr = 0; | ||
130 | return BLOCK_CHANGED; | ||
131 | } | ||
132 | |||
133 | return 0; | ||
134 | } | ||
135 | |||