Home | History | Annotate | Download | only in ext2fs

Lines Matching refs:fs

30 static errcode_t write_bitmaps(ext2_filsys fs, int do_inode, int do_block)
40 blk64_t blk_itr = EXT2FS_B2C(fs, 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_CLUSTERS_PER_GROUP(fs->super) / 8;
55 retval = io_channel_alloc_buf(fs->io, 0, &block_buf);
58 memset(block_buf, 0xff, fs->blocksize);
62 ((EXT2_INODES_PER_GROUP(fs->super)+7) / 8);
63 retval = io_channel_alloc_buf(fs->io, 0, &inode_buf);
66 memset(inode_buf, 0xff, fs->blocksize);
69 for (i = 0; i < fs->group_desc_count; i++) {
73 if (csum_flag && ext2fs_bg_flags_test(fs, i, EXT2_BG_BLOCK_UNINIT)
77 retval = ext2fs_get_block_bitmap_range2(fs->block_map,
82 if (i == fs->group_desc_count - 1) {
84 nbits = EXT2FS_NUM_B2C(fs,
85 ((ext2fs_blocks_count(fs->super)
86 - (__u64) fs->super->s_first_data_block)
87 % (__u64) EXT2_BLOCKS_PER_GROUP(fs->super)));
89 for (j = nbits; j < fs->blocksize * 8; j++)
92 blk = ext2fs_block_bitmap_loc(fs, i);
94 retval = io_channel_write_blk64(fs->io, blk, 1,
108 if (csum_flag && ext2fs_bg_flags_test(fs, i, EXT2_BG_INODE_UNINIT)
112 retval = ext2fs_get_inode_bitmap_range2(fs->inode_map,
117 blk = ext2fs_inode_bitmap_loc(fs, i);
119 retval = io_channel_write_blk64(fs->io, blk, 1,
131 fs->flags &= ~EXT2_FLAG_BB_DIRTY;
135 fs->flags &= ~EXT2_FLAG_IB_DIRTY;
147 static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block)
153 int block_nbytes = EXT2_CLUSTERS_PER_GROUP(fs->super) / 8;
154 int inode_nbytes = EXT2_INODES_PER_GROUP(fs->super) / 8;
158 blk64_t blk_itr = EXT2FS_B2C(fs, fs->super->s_first_data_block);
163 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
165 if ((block_nbytes > (int) fs->blocksize) ||
166 (inode_nbytes > (int) fs->blocksize))
169 fs->write_bitmaps = ext2fs_write_bitmaps;
171 if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
175 retval = ext2fs_get_mem(strlen(fs->device_name) + 80, &buf);
179 if (fs->block_map)
180 ext2fs_free_block_bitmap(fs->block_map);
182 strcat(buf, fs->device_name);
183 retval = ext2fs_allocate_block_bitmap(fs, buf, &fs->block_map);
186 retval = io_channel_alloc_buf(fs->io, 0, &block_bitmap);
192 if (fs->inode_map)
193 ext2fs_free_inode_bitmap(fs->inode_map);
195 strcat(buf, fs->device_name);
196 retval = ext2fs_allocate_inode_bitmap(fs, buf, &fs->inode_map);
199 retval = io_channel_alloc_buf(fs->io, 0, &inode_bitmap);
206 if (fs->flags & EXT2_FLAG_IMAGE_FILE) {
207 blk = (fs->image_header->offset_inodemap / fs->blocksize);
208 ino_cnt = fs->super->s_inodes_count;
210 retval = io_channel_read_blk64(fs->image_io, blk++,
214 cnt = fs->blocksize << 3;
217 retval = ext2fs_set_inode_bitmap_range2(fs->inode_map,
221 ino_itr += fs->blocksize << 3;
222 ino_cnt -= fs->blocksize << 3;
223 inode_nbytes -= fs->blocksize;
225 blk = (fs->image_header->offset_blockmap /
226 fs->blocksize);
227 blk_cnt = (blk64_t)EXT2_CLUSTERS_PER_GROUP(fs->super) *
228 fs->group_desc_count;
230 retval = io_channel_read_blk64(fs->image_io, blk++,
234 cnt = fs->blocksize << 3;
237 retval = ext2fs_set_block_bitmap_range2(fs->block_map,
241 blk_itr += fs->blocksize << 3;
242 blk_cnt -= fs->blocksize << 3;
243 block_nbytes -= fs->blocksize;
248 for (i = 0; i < fs->group_desc_count; i++) {
250 blk = ext2fs_block_bitmap_loc(fs, i);
252 ext2fs_bg_flags_test(fs, i, EXT2_BG_BLOCK_UNINIT) &&
253 ext2fs_group_desc_csum_verify(fs, i))
256 retval = io_channel_read_blk64(fs->io, blk,
265 retval = ext2fs_set_block_bitmap_range2(fs->block_map,
272 blk = ext2fs_inode_bitmap_loc(fs, i);
274 ext2fs_bg_flags_test(fs, i, EXT2_BG_INODE_UNINIT) &&
275 ext2fs_group_desc_csum_verify(fs, i))
278 retval = io_channel_read_blk64(fs->io, blk,
287 retval = ext2fs_set_inode_bitmap_range2(fs->inode_map,
303 ext2fs_free_mem(&fs->block_map);
304 fs->block_map = 0;
307 ext2fs_free_mem(&fs->inode_map);
308 fs->inode_map = 0;
319 errcode_t ext2fs_read_inode_bitmap(ext2_filsys fs)
321 return read_bitmaps(fs, 1, 0);
324 errcode_t ext2fs_read_block_bitmap(ext2_filsys fs)
326 return read_bitmaps(fs, 0, 1);
329 errcode_t ext2fs_write_inode_bitmap(ext2_filsys fs)
331 return write_bitmaps(fs, 1, 0);
334 errcode_t ext2fs_write_block_bitmap (ext2_filsys fs)
336 return write_bitmaps(fs, 0, 1);
339 errcode_t ext2fs_read_bitmaps(ext2_filsys fs)
341 if (fs->inode_map && fs->block_map)
344 return read_bitmaps(fs, !fs->inode_map, !fs->block_map);
347 errcode_t ext2fs_write_bitmaps(ext2_filsys fs)
349 int do_inode = fs->inode_map && ext2fs_test_ib_dirty(fs);
350 int do_block = fs->block_map && ext2fs_test_bb_dirty(fs);
355 return write_bitmaps(fs, do_inode, do_block);