aboutsummaryrefslogtreecommitdiff
path: root/e2fsprogs/ext2fs/bb_inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'e2fsprogs/ext2fs/bb_inode.c')
-rw-r--r--e2fsprogs/ext2fs/bb_inode.c42
1 files changed, 21 insertions, 21 deletions
diff --git a/e2fsprogs/ext2fs/bb_inode.c b/e2fsprogs/ext2fs/bb_inode.c
index dd8e7c319..9af117d8f 100644
--- a/e2fsprogs/ext2fs/bb_inode.c
+++ b/e2fsprogs/ext2fs/bb_inode.c
@@ -1,12 +1,12 @@
1/* 1/*
2 * bb_inode.c --- routines to update the bad block inode. 2 * bb_inode.c --- routines to update the bad block inode.
3 * 3 *
4 * WARNING: This routine modifies a lot of state in the filesystem; if 4 * WARNING: This routine modifies a lot of state in the filesystem; if
5 * this routine returns an error, the bad block inode may be in an 5 * this routine returns an error, the bad block inode may be in an
6 * inconsistent state. 6 * inconsistent state.
7 * 7 *
8 * Copyright (C) 1994, 1995 Theodore Ts'o. 8 * Copyright (C) 1994, 1995 Theodore Ts'o.
9 * 9 *
10 * %Begin-Header% 10 * %Begin-Header%
11 * This file may be redistributed under the terms of the GNU Public 11 * This file may be redistributed under the terms of the GNU Public
12 * License. 12 * License.
@@ -49,7 +49,7 @@ static int clear_bad_block_proc(ext2_filsys fs, blk_t *block_nr,
49 e2_blkcnt_t blockcnt, 49 e2_blkcnt_t blockcnt,
50 blk_t ref_block, int ref_offset, 50 blk_t ref_block, int ref_offset,
51 void *priv_data); 51 void *priv_data);
52 52
53/* 53/*
54 * Given a bad blocks bitmap, update the bad blocks inode to reflect 54 * Given a bad blocks bitmap, update the bad blocks inode to reflect
55 * the map. 55 * the map.
@@ -57,14 +57,14 @@ static int clear_bad_block_proc(ext2_filsys fs, blk_t *block_nr,
57errcode_t ext2fs_update_bb_inode(ext2_filsys fs, ext2_badblocks_list bb_list) 57errcode_t ext2fs_update_bb_inode(ext2_filsys fs, ext2_badblocks_list bb_list)
58{ 58{
59 errcode_t retval; 59 errcode_t retval;
60 struct set_badblock_record rec; 60 struct set_badblock_record rec;
61 struct ext2_inode inode; 61 struct ext2_inode inode;
62 62
63 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); 63 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
64 64
65 if (!fs->block_map) 65 if (!fs->block_map)
66 return EXT2_ET_NO_BLOCK_BITMAP; 66 return EXT2_ET_NO_BLOCK_BITMAP;
67 67
68 rec.bad_block_count = 0; 68 rec.bad_block_count = 0;
69 rec.ind_blocks_size = rec.ind_blocks_ptr = 0; 69 rec.ind_blocks_size = rec.ind_blocks_ptr = 0;
70 rec.max_ind_blocks = 10; 70 rec.max_ind_blocks = 10;
@@ -78,9 +78,9 @@ errcode_t ext2fs_update_bb_inode(ext2_filsys fs, ext2_badblocks_list bb_list)
78 goto cleanup; 78 goto cleanup;
79 memset(rec.block_buf, 0, fs->blocksize); 79 memset(rec.block_buf, 0, fs->blocksize);
80 rec.err = 0; 80 rec.err = 0;
81 81
82 /* 82 /*
83 * First clear the old bad blocks (while saving the indirect blocks) 83 * First clear the old bad blocks (while saving the indirect blocks)
84 */ 84 */
85 retval = ext2fs_block_iterate2(fs, EXT2_BAD_INO, 85 retval = ext2fs_block_iterate2(fs, EXT2_BAD_INO,
86 BLOCK_FLAG_DEPTH_TRAVERSE, 0, 86 BLOCK_FLAG_DEPTH_TRAVERSE, 0,
@@ -91,7 +91,7 @@ errcode_t ext2fs_update_bb_inode(ext2_filsys fs, ext2_badblocks_list bb_list)
91 retval = rec.err; 91 retval = rec.err;
92 goto cleanup; 92 goto cleanup;
93 } 93 }
94 94
95 /* 95 /*
96 * Now set the bad blocks! 96 * Now set the bad blocks!
97 * 97 *
@@ -108,22 +108,22 @@ errcode_t ext2fs_update_bb_inode(ext2_filsys fs, ext2_badblocks_list bb_list)
108 BLOCK_FLAG_APPEND, 0, 108 BLOCK_FLAG_APPEND, 0,
109 set_bad_block_proc, &rec); 109 set_bad_block_proc, &rec);
110 ext2fs_badblocks_list_iterate_end(rec.bb_iter); 110 ext2fs_badblocks_list_iterate_end(rec.bb_iter);
111 if (retval) 111 if (retval)
112 goto cleanup; 112 goto cleanup;
113 if (rec.err) { 113 if (rec.err) {
114 retval = rec.err; 114 retval = rec.err;
115 goto cleanup; 115 goto cleanup;
116 } 116 }
117 } 117 }
118 118
119 /* 119 /*
120 * Update the bad block inode's mod time and block count 120 * Update the bad block inode's mod time and block count
121 * field. 121 * field.
122 */ 122 */
123 retval = ext2fs_read_inode(fs, EXT2_BAD_INO, &inode); 123 retval = ext2fs_read_inode(fs, EXT2_BAD_INO, &inode);
124 if (retval) 124 if (retval)
125 goto cleanup; 125 goto cleanup;
126 126
127 inode.i_atime = inode.i_mtime = time(0); 127 inode.i_atime = inode.i_mtime = time(0);
128 if (!inode.i_ctime) 128 if (!inode.i_ctime)
129 inode.i_ctime = time(0); 129 inode.i_ctime = time(0);
@@ -133,7 +133,7 @@ errcode_t ext2fs_update_bb_inode(ext2_filsys fs, ext2_badblocks_list bb_list)
133 retval = ext2fs_write_inode(fs, EXT2_BAD_INO, &inode); 133 retval = ext2fs_write_inode(fs, EXT2_BAD_INO, &inode);
134 if (retval) 134 if (retval)
135 goto cleanup; 135 goto cleanup;
136 136
137cleanup: 137cleanup:
138 ext2fs_free_mem(&rec.ind_blocks); 138 ext2fs_free_mem(&rec.ind_blocks);
139 ext2fs_free_mem(&rec.block_buf); 139 ext2fs_free_mem(&rec.block_buf);
@@ -158,7 +158,7 @@ static int clear_bad_block_proc(ext2_filsys fs, blk_t *block_nr,
158 struct set_badblock_record *rec = (struct set_badblock_record *) 158 struct set_badblock_record *rec = (struct set_badblock_record *)
159 priv_data; 159 priv_data;
160 errcode_t retval; 160 errcode_t retval;
161 unsigned long old_size; 161 unsigned long old_size;
162 162
163 if (!*block_nr) 163 if (!*block_nr)
164 return 0; 164 return 0;
@@ -176,7 +176,7 @@ static int clear_bad_block_proc(ext2_filsys fs, blk_t *block_nr,
176 if (rec->ind_blocks_size >= rec->max_ind_blocks) { 176 if (rec->ind_blocks_size >= rec->max_ind_blocks) {
177 old_size = rec->max_ind_blocks * sizeof(blk_t); 177 old_size = rec->max_ind_blocks * sizeof(blk_t);
178 rec->max_ind_blocks += 10; 178 rec->max_ind_blocks += 10;
179 retval = ext2fs_resize_mem(old_size, 179 retval = ext2fs_resize_mem(old_size,
180 rec->max_ind_blocks * sizeof(blk_t), 180 rec->max_ind_blocks * sizeof(blk_t),
181 &rec->ind_blocks); 181 &rec->ind_blocks);
182 if (retval) { 182 if (retval) {
@@ -192,12 +192,12 @@ static int clear_bad_block_proc(ext2_filsys fs, blk_t *block_nr,
192 * Mark the block as unused, and update accounting information 192 * Mark the block as unused, and update accounting information
193 */ 193 */
194 ext2fs_block_alloc_stats(fs, *block_nr, -1); 194 ext2fs_block_alloc_stats(fs, *block_nr, -1);
195 195
196 *block_nr = 0; 196 *block_nr = 0;
197 return BLOCK_CHANGED; 197 return BLOCK_CHANGED;
198} 198}
199 199
200 200
201/* 201/*
202 * Helper function for update_bb_inode() 202 * Helper function for update_bb_inode()
203 * 203 *
@@ -250,12 +250,12 @@ static int set_bad_block_proc(ext2_filsys fs, blk_t *block_nr,
250 return BLOCK_ABORT; 250 return BLOCK_ABORT;
251 } 251 }
252 } 252 }
253 253
254 /* 254 /*
255 * Update block counts 255 * Update block counts
256 */ 256 */
257 ext2fs_block_alloc_stats(fs, blk, +1); 257 ext2fs_block_alloc_stats(fs, blk, +1);
258 258
259 *block_nr = blk; 259 *block_nr = blk;
260 return BLOCK_CHANGED; 260 return BLOCK_CHANGED;
261} 261}