Home | History | Annotate | Download | only in resize

Lines Matching refs:fs

49 static errcode_t fix_resize_inode(ext2_filsys fs);
50 static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs);
55 #define FS_BLOCK_BM(fs, i) ((fs)->group_desc[(i)].bg_block_bitmap)
56 #define FS_INODE_BM(fs, i) ((fs)->group_desc[(i)].bg_inode_bitmap)
57 #define FS_INODE_TB(fs, i) ((fs)->group_desc[(i)].bg_inode_table)
59 #define IS_BLOCK_BM(fs, i, blk) ((blk) == FS_BLOCK_BM((fs),(i)))
60 #define IS_INODE_BM(fs, i, blk) ((blk) == FS_INODE_BM((fs),(i)))
62 #define IS_INODE_TB(fs, i, blk) (((blk) >= FS_INODE_TB((fs), (i))) && \
63 ((blk) < (FS_INODE_TB((fs), (i)) + \
64 (fs)->inode_blocks_per_group)))
71 errcode_t resize_fs(ext2_filsys fs, blk_t *new_size, int flags,
79 retval = ext2fs_read_bitmaps(fs);
91 rfs->old_fs = fs;
95 retval = ext2fs_dup_handle(fs, &rfs->new_fs);
179 errcode_t adjust_fs_info(ext2_filsys fs, ext2_filsys old_fs, blk_t new_size)
192 fs->super->s_blocks_count = new_size;
195 fs->group_desc_count = ext2fs_div_ceil(fs->super->s_blocks_count -
196 fs->super->s_first_data_block,
197 EXT2_BLOCKS_PER_GROUP(fs->super));
198 if (fs->group_desc_count == 0)
200 fs->desc_blocks = ext2fs_div_ceil(fs->group_desc_count,
201 EXT2_DESC_PER_BLOCK(fs->super));
209 overhead = (int) (2 + fs->inode_blocks_per_group);
211 if (ext2fs_bg_has_super(fs, fs->group_desc_count - 1))
212 overhead += 1 + fs->desc_blocks +
213 fs->super->s_reserved_gdt_blocks;
220 rem = (fs->super->s_blocks_count - fs->super->s_first_data_block) %
221 fs->super->s_blocks_per_group;
222 if ((fs->group_desc_count == 1) && rem && (rem < overhead))
225 fs->super->s_blocks_count -= rem;
231 new_inodes =(unsigned long long) fs->super->s_inodes_per_group * fs->group_desc_count;
237 fs->super->s_inodes_count = fs->super->s_inodes_per_group *
238 fs->group_desc_count;
244 if (blk > fs->super->s_blocks_count)
245 fs->super->s_free_blocks_count -=
246 (blk - fs->super->s_blocks_count);
248 fs->super->s_free_blocks_count +=
249 (fs->super->s_blocks_count - blk);
256 fs->super->s_r_blocks_count = e2p_percent(blk,
257 fs->super->s_blocks_count);
262 retval = ext2fs_resize_inode_bitmap(fs->super->s_inodes_count,
263 fs->super->s_inodes_count,
264 fs->inode_map);
267 real_end = ((EXT2_BLOCKS_PER_GROUP(fs->super)
268 * fs->group_desc_count)) - 1 +
269 fs->super->s_first_data_block;
270 retval = ext2fs_resize_block_bitmap(fs->super->s_blocks_count-1,
271 real_end, fs->block_map);
278 if (old_fs->desc_blocks != fs->desc_blocks) {
280 fs->blocksize,
281 fs->desc_blocks * fs->blocksize,
282 &fs->group_desc);
285 if (fs->desc_blocks > old_fs->desc_blocks)
286 memset((char *) fs->group_desc +
287 (old_fs->desc_blocks * fs->blocksize), 0,
288 (fs->desc_blocks - old_fs->desc_blocks) *
289 fs->blocksize);
298 if ((fs->super->s_feature_compat &
300 (old_fs->desc_blocks != fs->desc_blocks)) {
303 new = ((int) fs->super->s_reserved_gdt_blocks) +
304 (old_fs->desc_blocks - fs->desc_blocks);
307 if (new > (int) fs->blocksize/4)
308 new = fs->blocksize/4;
309 fs->super->s_reserved_gdt_blocks = new;
311 fs->super->s_feature_compat &=
319 if (old_fs->group_desc_count > fs->group_desc_count) {
332 if (old_fs->group_desc_count == fs->group_desc_count) {
333 numblocks = (fs->super->s_blocks_count -
334 fs->super->s_first_data_block) %
335 fs->super->s_blocks_per_group;
337 numblocks = fs->super->s_blocks_per_group;
339 numblocks = fs->super->s_blocks_per_group;
341 fs->group_desc[i].bg_free_blocks_count += (numblocks-old_numblocks);
348 if (old_fs->group_desc_count >= fs->group_desc_count) {
356 group_block = fs->super->s_first_data_block +
357 old_fs->group_desc_count * fs->super->s_blocks_per_group;
360 max_group = fs->group_desc_count - adj;
361 if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG)
362 old_desc_blocks = fs->super->s_first_meta_bg;
364 old_desc_blocks = fs->desc_blocks +
365 fs->super->s_reserved_gdt_blocks;
367 i < fs->group_desc_count; i++) {
368 memset(&fs->group_desc[i], 0,
372 if (i == fs->group_desc_count-1) {
373 numblocks = (fs->super->s_blocks_count -
374 fs->super->s_first_data_block) %
375 fs->super->s_blocks_per_group;
377 numblocks = fs->super->s_blocks_per_group;
379 numblocks = fs->super->s_blocks_per_group;
381 has_super = ext2fs_bg_has_super(fs, i);
383 ext2fs_mark_block_bitmap(fs->block_map, group_block);
386 meta_bg_size = (fs->blocksize /
389 if (!(fs->super->s_feature_incompat &
391 (meta_bg < fs->super->s_first_meta_bg)) {
394 ext2fs_mark_block_bitmap(fs->block_map,
404 ext2fs_mark_block_bitmap(fs->block_map,
408 adjblocks += 2 + fs->inode_blocks_per_group;
411 fs->super->s_free_blocks_count -= adjblocks;
412 fs->super->s_free_inodes_count +=
413 fs->super->s_inodes_per_group;
414 fs->group_desc[i].bg_free_blocks_count = numblocks;
415 fs->group_desc[i].bg_free_inodes_count =
416 fs->super->s_inodes_per_group;
417 fs->group_desc[i].bg_used_dirs_count = 0;
419 retval = ext2fs_allocate_group_table(fs, i, 0);
422 group_block += fs->super->s_blocks_per_group;
436 ext2_filsys fs;
443 fs = rfs->new_fs;
444 ext2fs_mark_super_dirty(fs);
445 ext2fs_mark_bb_dirty(fs);
446 ext2fs_mark_ib_dirty(fs);
448 retval = adjust_fs_info(fs, rfs->old_fs, new_size);
466 if (rfs->old_fs->group_desc_count > fs->group_desc_count) {
476 if (rfs->old_fs->group_desc_count >= fs->group_desc_count) {
484 retval = ext2fs_get_array(fs->blocksize, fs->inode_blocks_per_group,
489 memset(rfs->itable_buf, 0, fs->blocksize * fs->inode_blocks_per_group);
490 group_block = fs->super->s_first_data_block +
491 rfs->old_fs->group_desc_count * fs->super->s_blocks_per_group;
494 max_group = fs->group_desc_count - adj;
502 i < fs->group_desc_count; i++) {
506 retval = io_channel_write_blk(fs->io,
507 fs->group_desc[i].bg_inode_table,
508 fs->inode_blocks_per_group,
512 io_channel_flush(fs->io);
519 group_block += fs->super->s_blocks_per_group;
521 io_channel_flush(fs->io);
544 static errcode_t mark_table_blocks(ext2_filsys fs,
553 meta_bg_size = (fs->blocksize / sizeof (struct ext2_group_desc));
554 if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG)
555 old_desc_blocks = fs->super->s_first_meta_bg;
557 old_desc_blocks = fs->desc_blocks +
558 fs->super->s_reserved_gdt_blocks;
559 for (i = 0; i < fs->group_desc_count; i++) {
560 ext2fs_reserve_super_and_bgd(fs, i, bmap);
565 for (j = 0, b = fs->group_desc[i].bg_inode_table;
566 j < (unsigned int) fs->inode_blocks_per_group;
574 fs->group_desc[i].bg_block_bitmap);
580 fs->group_desc[i].bg_inode_bitmap);
594 ext2_filsys fs = rfs->new_fs;
597 ext2fs_mark_block_bitmap(fs->block_map, blk);
604 if (IS_BLOCK_BM(fs, group, blk)) {
605 FS_BLOCK_BM(fs, group) = 0;
607 } else if (IS_INODE_BM(fs, group, blk)) {
608 FS_INODE_BM(fs, group) = 0;
610 } else if (IS_INODE_TB(fs, group, blk)) {
611 FS_INODE_TB(fs, group) = 0;
634 ext2_filsys fs, old_fs;
637 fs = rfs->new_fs;
639 if (old_fs->super->s_blocks_count > fs->super->s_blocks_count)
640 fs = rfs->old_fs;
642 retval = ext2fs_allocate_block_bitmap(fs, _("reserved blocks"),
647 retval = ext2fs_allocate_block_bitmap(fs, _("blocks to be moved"),
652 retval = ext2fs_allocate_block_bitmap(fs, _("meta-data blocks"),
661 fs = rfs->new_fs;
667 for (blk = fs->super->s_blocks_count;
677 if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) {
679 new_blocks = fs->super->s_first_meta_bg;
682 new_blocks = fs->desc_blocks + fs->super->s_reserved_gdt_blocks;
690 max_groups = fs->group_desc_count;
701 if (!ext2fs_bg_has_super(fs, i)) {
702 group_blk += fs->super->s_blocks_per_group;
707 ext2fs_unmark_block_bitmap(fs->block_map,
711 group_blk += fs->super->s_blocks_per_group;
720 meta_bg_size = (fs->blocksize / sizeof (struct ext2_group_desc));
722 has_super = ext2fs_bg_has_super(fs, i);
727 if (!(fs->super->s_feature_incompat &
729 (meta_bg < fs->super->s_first_meta_bg)) {
746 if (fs->group_desc[i].bg_inode_table &&
747 fs->group_desc[i].bg_inode_bitmap &&
748 fs->group_desc[i].bg_block_bitmap)
755 if (fs->group_desc[i].bg_block_bitmap)
757 fs->group_desc[i].bg_block_bitmap);
758 if (fs->group_desc[i].bg_inode_bitmap)
760 fs->group_desc[i].bg_inode_bitmap);
761 if (fs->group_desc[i].bg_inode_table)
762 for (blk = fs->group_desc[i].bg_inode_table, j=0;
763 j < fs->inode_blocks_per_group ; j++, blk++)
770 retval = ext2fs_allocate_group_table(fs, i,
780 (blk = FS_BLOCK_BM(fs, i))) {
781 ext2fs_mark_block_bitmap(fs->block_map, blk);
788 (blk = FS_INODE_BM(fs, i))) {
789 ext2fs_mark_block_bitmap(fs->block_map, blk);
803 if (FS_INODE_TB(fs, i) == FS_INODE_TB(old_fs, i))
806 rfs->needed_blocks += fs->inode_blocks_per_group;
813 for (blk = fs->group_desc[i].bg_inode_table, j=0;
814 j < fs->inode_blocks_per_group ; j++, blk++) {
815 ext2fs_mark_block_bitmap(fs->block_map, blk);
827 j < fs->inode_blocks_per_group ; j++, blk++)
873 ext2_filsys fs = rfs->new_fs;
876 if (rfs->new_blk >= fs->super->s_blocks_count) {
886 rfs->new_blk = fs->super->s_first_data_block;
889 if (ext2fs_test_block_bitmap(fs->block_map, rfs->new_blk) ||
906 ext2_filsys fs = rfs->new_fs;
918 new_blk = fs->super->s_first_data_block;
920 retval = ext2fs_get_array(fs->blocksize,
921 fs->inode_blocks_per_group,
953 ext2fs_mark_block_bitmap(fs->block_map, new_blk);
991 if (c > fs->inode_blocks_per_group)
992 c = fs->inode_blocks_per_group;
993 retval = io_channel_read_blk(fs->io, old_blk, c,
996 retval = io_channel_write_blk(fs->io, new_blk, c,
1004 io_channel_flush(fs->io);
1012 io_channel_flush(fs->io);
1043 static int process_block(ext2_filsys fs, blk_t *block_nr,
1070 retval = ext2fs_add_dir_block(fs->dblist, pb->ino,
1083 static errcode_t progress_callback(ext2_filsys fs,
1098 io_channel_flush(fs->io);
1100 group+1, fs->group_desc_count);
1394 ext2_filsys fs = rfs->new_fs;
1400 max_groups = fs->group_desc_count;
1404 size = fs->blocksize * fs->inode_blocks_per_group;
1417 fs->group_desc[i].bg_inode_table)
1434 new_blk = fs->group_desc[i].bg_inode_table;
1446 retval = io_channel_read_blk(fs->io, old_blk,
1447 fs->inode_blocks_per_group,
1461 n = n >> EXT2_BLOCK_SIZE_BITS(fs->super);
1466 num = fs->inode_blocks_per_group;
1470 retval = io_channel_write_blk(fs->io, new_blk,
1473 io_channel_write_blk(fs->io, old_blk,
1478 retval = io_channel_write_blk(fs->io,
1479 old_blk + fs->inode_blocks_per_group,
1481 (fs->inode_blocks_per_group - diff) *
1482 fs->blocksize));
1488 j < fs->inode_blocks_per_group ; j++, blk++)
1489 ext2fs_unmark_block_bitmap(fs->block_map, blk);
1502 mark_table_blocks(fs, fs->block_map);
1503 ext2fs_flush(fs);
1517 static errcode_t fix_resize_inode(ext2_filsys fs)
1523 if (!(fs->super->s_feature_compat &
1527 retval = ext2fs_get_mem(fs->blocksize, &block_buf);
1530 retval = ext2fs_read_inode(fs, EXT2_RESIZE_INO, &inode);
1533 inode.i_blocks = fs->blocksize/512;
1535 retval = ext2fs_write_inode(fs, EXT2_RESIZE_INO, &inode);
1549 memset(block_buf, 0, fs->blocksize);
1551 retval = io_channel_write_blk(fs->io, inode.i_block[EXT2_DIND_BLOCK],
1555 retval = ext2fs_create_resize_inode(fs);
1568 static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs)
1580 for (blk = fs->super->s_first_data_block;
1581 blk < fs->super->s_blocks_count; blk++) {
1582 if (!ext2fs_fast_test_block_bitmap(fs->block_map, blk)) {
1587 if ((count == fs->super->s_blocks_per_group) ||
1588 (blk == fs->super->s_blocks_count-1)) {
1589 fs->group_desc[group++].bg_free_blocks_count =
1595 fs->super->s_free_blocks_count = total_free;
1606 for (ino = 1; ino <= fs->super->s_inodes_count && ino > 0; ino++) {
1607 if (!ext2fs_fast_test_inode_bitmap(fs->inode_map, ino)) {
1612 if ((count == fs->super->s_inodes_per_group) ||
1613 (ino == fs->super->s_inodes_count)) {
1614 fs->group_desc[group++].bg_free_inodes_count =
1620 fs->super->s_free_inodes_count = total_free;
1621 ext2fs_mark_super_dirty(fs);