Lines Matching refs:fs
30 static errcode_t write_bitmaps(ext2_filsys fs, int do_inode, int do_block)
40 blk_t blk_itr = fs->super->s_first_data_block;
43 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
45 if (!(fs->flags & EXT2_FLAG_RW))
48 if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
54 block_nbytes = EXT2_BLOCKS_PER_GROUP(fs->super) / 8;
55 retval = ext2fs_get_memalign(fs->blocksize, fs->blocksize,
59 memset(block_buf, 0xff, fs->blocksize);
63 ((EXT2_INODES_PER_GROUP(fs->super)+7) / 8);
64 retval = ext2fs_get_memalign(fs->blocksize, fs->blocksize,
68 memset(inode_buf, 0xff, fs->blocksize);
71 for (i = 0; i < fs->group_desc_count; i++) {
75 if (csum_flag && fs->group_desc[i].bg_flags &
79 retval = ext2fs_get_block_bitmap_range(fs->block_map,
84 if (i == fs->group_desc_count - 1) {
86 nbits = ((fs->super->s_blocks_count
87 - fs->super->s_first_data_block)
88 % EXT2_BLOCKS_PER_GROUP(fs->super));
90 for (j = nbits; j < fs->blocksize * 8; j++)
93 blk = fs->group_desc[i].bg_block_bitmap;
95 retval = io_channel_write_blk(fs->io, blk, 1,
107 if (csum_flag && fs->group_desc[i].bg_flags &
111 retval = ext2fs_get_inode_bitmap_range(fs->inode_map,
116 blk = fs->group_desc[i].bg_inode_bitmap;
118 retval = io_channel_write_blk(fs->io, blk, 1,
128 fs->flags &= ~EXT2_FLAG_BB_DIRTY;
132 fs->flags &= ~EXT2_FLAG_IB_DIRTY;
138 static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block)
144 int block_nbytes = EXT2_BLOCKS_PER_GROUP(fs->super) / 8;
145 int inode_nbytes = EXT2_INODES_PER_GROUP(fs->super) / 8;
147 int do_image = fs->flags & EXT2_FLAG_IMAGE_FILE;
150 blk_t blk_itr = fs->super->s_first_data_block;
155 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
157 fs->write_bitmaps = ext2fs_write_bitmaps;
159 if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
163 retval = ext2fs_get_mem(strlen(fs->device_name) + 80, &buf);
167 if (fs->block_map)
168 ext2fs_free_block_bitmap(fs->block_map);
170 strcat(buf, fs->device_name);
171 retval = ext2fs_allocate_block_bitmap(fs, buf, &fs->block_map);
175 retval = ext2fs_get_mem(fs->blocksize, &block_bitmap);
178 fs->blocksize,
186 if (fs->inode_map)
187 ext2fs_free_inode_bitmap(fs->inode_map);
189 strcat(buf, fs->device_name);
190 retval = ext2fs_allocate_inode_bitmap(fs, buf, &fs->inode_map);
193 retval = ext2fs_get_mem(do_image ? fs->blocksize :
201 if (fs->flags & EXT2_FLAG_IMAGE_FILE) {
202 blk = (fs->image_header->offset_inodemap / fs->blocksize);
203 ino_cnt = fs->super->s_inodes_count;
205 retval = io_channel_read_blk(fs->image_io, blk++,
209 cnt = fs->blocksize << 3;
212 retval = ext2fs_set_inode_bitmap_range(fs->inode_map,
216 ino_itr += fs->blocksize << 3;
217 ino_cnt -= fs->blocksize << 3;
218 inode_nbytes -= fs->blocksize;
220 blk = (fs->image_header->offset_blockmap /
221 fs->blocksize);
222 blk_cnt = EXT2_BLOCKS_PER_GROUP(fs->super) *
223 fs->group_desc_count;
225 retval = io_channel_read_blk(fs->image_io, blk++,
229 cnt = fs->blocksize << 3;
232 retval = ext2fs_set_block_bitmap_range(fs->block_map,
236 blk_itr += fs->blocksize << 3;
237 blk_cnt -= fs->blocksize << 3;
238 block_nbytes -= fs->blocksize;
243 for (i = 0; i < fs->group_desc_count; i++) {
245 blk = fs->group_desc[i].bg_block_bitmap;
246 if (csum_flag && fs->group_desc[i].bg_flags &
248 ext2fs_group_desc_csum_verify(fs, i))
251 retval = io_channel_read_blk(fs->io, blk,
260 retval = ext2fs_set_block_bitmap_range(fs->block_map,
267 blk = fs->group_desc[i].bg_inode_bitmap;
268 if (csum_flag && fs->group_desc[i].bg_flags &
270 ext2fs_group_desc_csum_verify(fs, i))
273 retval = io_channel_read_blk(fs->io, blk,
282 retval = ext2fs_set_inode_bitmap_range(fs->inode_map,
298 ext2fs_free_mem(&fs->block_map);
299 fs->block_map = 0;
302 ext2fs_free_mem(&fs->inode_map);
303 fs->inode_map = 0;
314 errcode_t ext2fs_read_inode_bitmap(ext2_filsys fs)
316 return read_bitmaps(fs, 1, 0);
319 errcode_t ext2fs_read_block_bitmap(ext2_filsys fs)
321 return read_bitmaps(fs, 0, 1);
324 errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs)
326 return write_bitmaps(fs, 1, 0);
329 errcode_t ext2fs_write_block_bitmap (ext2_filsys fs)
331 return write_bitmaps(fs, 0, 1);
334 errcode_t ext2fs_read_bitmaps(ext2_filsys fs)
336 if (fs->inode_map && fs->block_map)
339 return read_bitmaps(fs, !fs->inode_map, !fs->block_map);
342 errcode_t ext2fs_write_bitmaps(ext2_filsys fs)
344 int do_inode = fs->inode_map && ext2fs_test_ib_dirty(fs);
345 int do_block = fs->block_map && ext2fs_test_bb_dirty(fs);
350 return write_bitmaps(fs, do_inode, do_block);