Lines Matching refs:fs
43 static void fix_uninit_block_bitmaps(ext2_filsys fs);
50 static errcode_t fix_resize_inode(ext2_filsys fs);
51 static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs);
52 static errcode_t fix_sb_journal_backup(ext2_filsys fs);
53 static errcode_t mark_table_blocks(ext2_filsys fs,
59 #define IS_BLOCK_BM(fs, i, blk) ((blk) == ext2fs_block_bitmap_loc((fs),(i))) argument
60 #define IS_INODE_BM(fs, i, blk) ((blk) == ext2fs_inode_bitmap_loc((fs),(i))) argument
62 #define IS_INODE_TB(fs, i, blk) (((blk) >= ext2fs_inode_table_loc((fs), (i))) && \ argument
63 ((blk) < (ext2fs_inode_table_loc((fs), (i)) + \
64 (fs)->inode_blocks_per_group)))
67 #define B2C(x) EXT2FS_B2C(fs, (x))
68 #define C2B(x) EXT2FS_C2B(fs, (x))
80 errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags, in resize_fs() argument
97 fs->priv_data = rfs; in resize_fs()
98 rfs->old_fs = fs; in resize_fs()
103 init_resource_track(&overall_track, "overall resize2fs", fs->io); in resize_fs()
104 init_resource_track(&rtrack, "read_bitmaps", fs->io); in resize_fs()
105 retval = ext2fs_read_bitmaps(fs); in resize_fs()
108 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
110 fs->super->s_state |= EXT2_ERROR_FS; in resize_fs()
111 ext2fs_mark_super_dirty(fs); in resize_fs()
112 ext2fs_flush(fs); in resize_fs()
114 init_resource_track(&rtrack, "fix_uninit_block_bitmaps 1", fs->io); in resize_fs()
115 fix_uninit_block_bitmaps(fs); in resize_fs()
116 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
117 retval = ext2fs_dup_handle(fs, &rfs->new_fs); in resize_fs()
121 init_resource_track(&rtrack, "adjust_superblock", fs->io); in resize_fs()
125 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
128 init_resource_track(&rtrack, "fix_uninit_block_bitmaps 2", fs->io); in resize_fs()
130 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
137 init_resource_track(&rtrack, "blocks_to_move", fs->io); in resize_fs()
141 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
151 init_resource_track(&rtrack, "block_mover", fs->io); in resize_fs()
155 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
157 init_resource_track(&rtrack, "inode_scan_and_fix", fs->io); in resize_fs()
161 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
163 init_resource_track(&rtrack, "inode_ref_fix", fs->io); in resize_fs()
167 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
169 init_resource_track(&rtrack, "move_itables", fs->io); in resize_fs()
173 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
175 init_resource_track(&rtrack, "calculate_summary_stats", fs->io); in resize_fs()
179 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
181 init_resource_track(&rtrack, "fix_resize_inode", fs->io); in resize_fs()
185 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
187 init_resource_track(&rtrack, "fix_sb_journal_backup", fs->io); in resize_fs()
191 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
196 print_resource_track(rfs, &overall_track, fs->io); in resize_fs()
226 static void fix_uninit_block_bitmaps(ext2_filsys fs) in fix_uninit_block_bitmaps() argument
232 if (!(EXT2_HAS_RO_COMPAT_FEATURE(fs->super, in fix_uninit_block_bitmaps()
236 for (g=0; g < fs->group_desc_count; g++) { in fix_uninit_block_bitmaps()
237 if (!(ext2fs_bg_flags_test(fs, g, EXT2_BG_BLOCK_UNINIT))) in fix_uninit_block_bitmaps()
240 blk = ext2fs_group_first_block2(fs, g); in fix_uninit_block_bitmaps()
241 lblk = ext2fs_group_last_block2(fs, g); in fix_uninit_block_bitmaps()
242 ext2fs_unmark_block_bitmap_range2(fs->block_map, blk, in fix_uninit_block_bitmaps()
245 ext2fs_reserve_super_and_bgd(fs, g, fs->block_map); in fix_uninit_block_bitmaps()
246 ext2fs_mark_block_bitmap2(fs->block_map, in fix_uninit_block_bitmaps()
247 ext2fs_block_bitmap_loc(fs, g)); in fix_uninit_block_bitmaps()
248 ext2fs_mark_block_bitmap2(fs->block_map, in fix_uninit_block_bitmaps()
249 ext2fs_inode_bitmap_loc(fs, g)); in fix_uninit_block_bitmaps()
250 for (i = 0, blk = ext2fs_inode_table_loc(fs, g); in fix_uninit_block_bitmaps()
251 i < (unsigned int) fs->inode_blocks_per_group; in fix_uninit_block_bitmaps()
253 ext2fs_mark_block_bitmap2(fs->block_map, blk); in fix_uninit_block_bitmaps()
273 static void free_gdp_blocks(ext2_filsys fs, in free_gdp_blocks() argument
283 (blk < ext2fs_blocks_count(fs->super))) { in free_gdp_blocks()
284 ext2fs_block_alloc_stats2(fs, blk, -1); in free_gdp_blocks()
290 (blk < ext2fs_blocks_count(fs->super))) { in free_gdp_blocks()
291 ext2fs_block_alloc_stats2(fs, blk, -1); in free_gdp_blocks()
297 (blk >= ext2fs_blocks_count(fs->super))) in free_gdp_blocks()
301 j < fs->inode_blocks_per_group; j++, blk++) { in free_gdp_blocks()
302 if (blk >= ext2fs_blocks_count(fs->super)) in free_gdp_blocks()
304 ext2fs_block_alloc_stats2(fs, blk, -1); in free_gdp_blocks()
313 errcode_t adjust_fs_info(ext2_filsys fs, ext2_filsys old_fs, in adjust_fs_info() argument
328 ext2fs_blocks_count_set(fs->super, new_size); in adjust_fs_info()
331 fs->group_desc_count = ext2fs_div64_ceil(ext2fs_blocks_count(fs->super) - in adjust_fs_info()
332 fs->super->s_first_data_block, in adjust_fs_info()
333 EXT2_BLOCKS_PER_GROUP(fs->super)); in adjust_fs_info()
334 if (fs->group_desc_count == 0) in adjust_fs_info()
336 fs->desc_blocks = ext2fs_div_ceil(fs->group_desc_count, in adjust_fs_info()
337 EXT2_DESC_PER_BLOCK(fs->super)); in adjust_fs_info()
345 overhead = (int) (2 + fs->inode_blocks_per_group); in adjust_fs_info()
347 if (ext2fs_bg_has_super(fs, fs->group_desc_count - 1)) in adjust_fs_info()
348 overhead += 1 + fs->desc_blocks + in adjust_fs_info()
349 fs->super->s_reserved_gdt_blocks; in adjust_fs_info()
356 rem = (ext2fs_blocks_count(fs->super) - fs->super->s_first_data_block) % in adjust_fs_info()
357 fs->super->s_blocks_per_group; in adjust_fs_info()
358 if ((fs->group_desc_count == 1) && rem && (rem < overhead)) in adjust_fs_info()
360 if ((fs->group_desc_count > 1) && rem && (rem < overhead+50)) { in adjust_fs_info()
361 ext2fs_blocks_count_set(fs->super, in adjust_fs_info()
362 ext2fs_blocks_count(fs->super) - rem); in adjust_fs_info()
368 new_inodes =(unsigned long long) fs->super->s_inodes_per_group * fs->group_desc_count; in adjust_fs_info()
374 fs->super->s_inodes_count = fs->super->s_inodes_per_group * in adjust_fs_info()
375 fs->group_desc_count; in adjust_fs_info()
381 if (blk > ext2fs_blocks_count(fs->super)) in adjust_fs_info()
382 ext2fs_free_blocks_count_set(fs->super, in adjust_fs_info()
383 ext2fs_free_blocks_count(fs->super) - in adjust_fs_info()
384 (blk - ext2fs_blocks_count(fs->super))); in adjust_fs_info()
386 ext2fs_free_blocks_count_set(fs->super, in adjust_fs_info()
387 ext2fs_free_blocks_count(fs->super) + in adjust_fs_info()
388 (ext2fs_blocks_count(fs->super) - blk)); in adjust_fs_info()
395 ext2fs_r_blocks_count_set(fs->super, in adjust_fs_info()
396 (percent * ext2fs_blocks_count(fs->super) / in adjust_fs_info()
402 retval = ext2fs_resize_inode_bitmap2(fs->super->s_inodes_count, in adjust_fs_info()
403 fs->super->s_inodes_count, in adjust_fs_info()
404 fs->inode_map); in adjust_fs_info()
407 real_end = (((blk64_t) EXT2_BLOCKS_PER_GROUP(fs->super) * in adjust_fs_info()
408 fs->group_desc_count)) - 1 + in adjust_fs_info()
409 fs->super->s_first_data_block; in adjust_fs_info()
411 real_end, fs->block_map); in adjust_fs_info()
427 if (old_fs->desc_blocks != fs->desc_blocks) { in adjust_fs_info()
429 fs->blocksize, in adjust_fs_info()
430 fs->desc_blocks * fs->blocksize, in adjust_fs_info()
431 &fs->group_desc); in adjust_fs_info()
434 if (fs->desc_blocks > old_fs->desc_blocks) in adjust_fs_info()
435 memset((char *) fs->group_desc + in adjust_fs_info()
436 (old_fs->desc_blocks * fs->blocksize), 0, in adjust_fs_info()
437 (fs->desc_blocks - old_fs->desc_blocks) * in adjust_fs_info()
438 fs->blocksize); in adjust_fs_info()
447 if ((fs->super->s_feature_compat & in adjust_fs_info()
449 (old_fs->desc_blocks != fs->desc_blocks)) { in adjust_fs_info()
452 new = ((int) fs->super->s_reserved_gdt_blocks) + in adjust_fs_info()
453 (old_fs->desc_blocks - fs->desc_blocks); in adjust_fs_info()
456 if (new > (int) fs->blocksize/4) in adjust_fs_info()
457 new = fs->blocksize/4; in adjust_fs_info()
458 fs->super->s_reserved_gdt_blocks = new; in adjust_fs_info()
465 if (old_fs->group_desc_count > fs->group_desc_count) { in adjust_fs_info()
470 for (i = fs->group_desc_count; in adjust_fs_info()
472 free_gdp_blocks(fs, reserve_blocks, old_fs, i); in adjust_fs_info()
485 if (old_fs->group_desc_count == fs->group_desc_count) { in adjust_fs_info()
486 numblocks = (ext2fs_blocks_count(fs->super) - in adjust_fs_info()
487 fs->super->s_first_data_block) % in adjust_fs_info()
488 fs->super->s_blocks_per_group; in adjust_fs_info()
490 numblocks = fs->super->s_blocks_per_group; in adjust_fs_info()
492 numblocks = fs->super->s_blocks_per_group; in adjust_fs_info()
494 …ext2fs_bg_free_blocks_count_set(fs, i, ext2fs_bg_free_blocks_count(fs, i) + (numblocks - old_numbl… in adjust_fs_info()
495 ext2fs_group_desc_csum_set(fs, i); in adjust_fs_info()
502 if (old_fs->group_desc_count >= fs->group_desc_count) { in adjust_fs_info()
510 group_block = ext2fs_group_first_block2(fs, in adjust_fs_info()
512 csum_flag = EXT2_HAS_RO_COMPAT_FEATURE(fs->super, in adjust_fs_info()
516 if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) in adjust_fs_info()
517 old_desc_blocks = fs->super->s_first_meta_bg; in adjust_fs_info()
519 old_desc_blocks = fs->desc_blocks + in adjust_fs_info()
520 fs->super->s_reserved_gdt_blocks; in adjust_fs_info()
528 ext2fs_reserve_super_and_bgd(fs, i, fs->block_map); in adjust_fs_info()
531 i < fs->group_desc_count; i++) { in adjust_fs_info()
532 memset(ext2fs_group_desc(fs, fs->group_desc, i), 0, in adjust_fs_info()
536 ext2fs_bg_flags_zap(fs, i); in adjust_fs_info()
538 ext2fs_bg_flags_set(fs, i, EXT2_BG_INODE_UNINIT); in adjust_fs_info()
540 ext2fs_bg_flags_set(fs, i, in adjust_fs_info()
542 ext2fs_bg_itable_unused_set(fs, i, in adjust_fs_info()
543 fs->super->s_inodes_per_group); in adjust_fs_info()
546 numblocks = ext2fs_group_blocks_count(fs, i); in adjust_fs_info()
547 if ((i < fs->group_desc_count - 1) && csum_flag) in adjust_fs_info()
548 ext2fs_bg_flags_set(fs, i, EXT2_BG_BLOCK_UNINIT); in adjust_fs_info()
550 has_super = ext2fs_bg_has_super(fs, i); in adjust_fs_info()
552 ext2fs_block_alloc_stats2(fs, group_block, +1); in adjust_fs_info()
555 meta_bg_size = EXT2_DESC_PER_BLOCK(fs->super); in adjust_fs_info()
557 if (!(fs->super->s_feature_incompat & in adjust_fs_info()
559 (meta_bg < fs->super->s_first_meta_bg)) { in adjust_fs_info()
562 ext2fs_block_alloc_stats2(fs, in adjust_fs_info()
572 ext2fs_block_alloc_stats2(fs, in adjust_fs_info()
576 adjblocks += 2 + fs->inode_blocks_per_group; in adjust_fs_info()
579 ext2fs_free_blocks_count_set(fs->super, in adjust_fs_info()
580 ext2fs_free_blocks_count(fs->super) - adjblocks); in adjust_fs_info()
581 fs->super->s_free_inodes_count += in adjust_fs_info()
582 fs->super->s_inodes_per_group; in adjust_fs_info()
583 ext2fs_bg_free_blocks_count_set(fs, i, numblocks); in adjust_fs_info()
584 ext2fs_bg_free_inodes_count_set(fs, i, in adjust_fs_info()
585 fs->super->s_inodes_per_group); in adjust_fs_info()
586 ext2fs_bg_used_dirs_count_set(fs, i, 0); in adjust_fs_info()
587 ext2fs_group_desc_csum_set(fs, i); in adjust_fs_info()
589 retval = ext2fs_allocate_group_table(fs, i, 0); in adjust_fs_info()
592 group_block += fs->super->s_blocks_per_group; in adjust_fs_info()
605 mark_table_blocks(fs, reserve_blocks); in adjust_fs_info()
617 ext2_filsys fs; in adjust_superblock() local
624 fs = rfs->new_fs; in adjust_superblock()
625 ext2fs_mark_super_dirty(fs); in adjust_superblock()
626 ext2fs_mark_bb_dirty(fs); in adjust_superblock()
627 ext2fs_mark_ib_dirty(fs); in adjust_superblock()
629 retval = ext2fs_allocate_block_bitmap(fs, _("reserved blocks"), in adjust_superblock()
634 retval = adjust_fs_info(fs, rfs->old_fs, rfs->reserve_blocks, new_size); in adjust_superblock()
652 if (rfs->old_fs->group_desc_count > fs->group_desc_count) { in adjust_superblock()
662 if (rfs->old_fs->group_desc_count >= fs->group_desc_count) { in adjust_superblock()
673 EXT2_HAS_RO_COMPAT_FEATURE(fs->super, in adjust_superblock()
682 retval = ext2fs_get_array(fs->blocksize, fs->inode_blocks_per_group, in adjust_superblock()
687 memset(rfs->itable_buf, 0, fs->blocksize * fs->inode_blocks_per_group); in adjust_superblock()
688 group_block = ext2fs_group_first_block2(fs, in adjust_superblock()
691 max_group = fs->group_desc_count - adj; in adjust_superblock()
699 i < fs->group_desc_count; i++) { in adjust_superblock()
703 retval = io_channel_write_blk64(fs->io, in adjust_superblock()
704 ext2fs_inode_table_loc(fs, i), in adjust_superblock()
705 fs->inode_blocks_per_group, in adjust_superblock()
709 io_channel_flush(fs->io); in adjust_superblock()
716 group_block += fs->super->s_blocks_per_group; in adjust_superblock()
718 io_channel_flush(fs->io); in adjust_superblock()
741 static errcode_t mark_table_blocks(ext2_filsys fs, in mark_table_blocks() argument
747 for (i = 0; i < fs->group_desc_count; i++) { in mark_table_blocks()
748 ext2fs_reserve_super_and_bgd(fs, i, bmap); in mark_table_blocks()
753 blk = ext2fs_inode_table_loc(fs, i); in mark_table_blocks()
756 fs->inode_blocks_per_group); in mark_table_blocks()
761 blk = ext2fs_block_bitmap_loc(fs, i); in mark_table_blocks()
768 blk = ext2fs_inode_bitmap_loc(fs, i); in mark_table_blocks()
784 ext2_filsys fs = rfs->new_fs; in mark_fs_metablock() local
787 ext2fs_block_alloc_stats2(fs, blk, +1); in mark_fs_metablock()
794 if (IS_BLOCK_BM(fs, group, blk)) { in mark_fs_metablock()
795 ext2fs_block_bitmap_loc_set(fs, group, 0); in mark_fs_metablock()
799 if (IS_INODE_BM(fs, group, blk)) { in mark_fs_metablock()
800 ext2fs_inode_bitmap_loc_set(fs, group, 0); in mark_fs_metablock()
804 if (IS_INODE_TB(fs, group, blk)) { in mark_fs_metablock()
805 ext2fs_inode_table_loc_set(fs, group, 0); in mark_fs_metablock()
809 if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_FLEX_BG) { in mark_fs_metablock()
813 if (IS_BLOCK_BM(fs, i, blk)) { in mark_fs_metablock()
814 ext2fs_block_bitmap_loc_set(fs, i, 0); in mark_fs_metablock()
818 if (IS_INODE_BM(fs, i, blk)) { in mark_fs_metablock()
819 ext2fs_inode_bitmap_loc_set(fs, i, 0); in mark_fs_metablock()
823 if (IS_INODE_TB(fs, i, blk)) { in mark_fs_metablock()
824 ext2fs_inode_table_loc_set(fs, i, 0); in mark_fs_metablock()
830 if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super, in mark_fs_metablock()
832 (ext2fs_bg_flags_test(fs, group, EXT2_BG_BLOCK_UNINIT))) { in mark_fs_metablock()
860 ext2_filsys fs, old_fs; in blocks_to_move() local
864 fs = rfs->new_fs; in blocks_to_move()
866 if (ext2fs_blocks_count(old_fs->super) > ext2fs_blocks_count(fs->super)) in blocks_to_move()
867 fs = rfs->old_fs; in blocks_to_move()
869 retval = ext2fs_allocate_block_bitmap(fs, _("blocks to be moved"), in blocks_to_move()
874 retval = ext2fs_allocate_block_bitmap(fs, _("meta-data blocks"), in blocks_to_move()
883 fs = rfs->new_fs; in blocks_to_move()
891 new_size = ext2fs_blocks_count(fs->super); in blocks_to_move()
893 for (g = 0; g < fs->group_desc_count; g++) { in blocks_to_move()
899 if (ext2fs_block_bitmap_loc(fs, g) >= new_size) { in blocks_to_move()
900 ext2fs_block_bitmap_loc_set(fs, g, 0); in blocks_to_move()
903 if (ext2fs_inode_bitmap_loc(fs, g) >= new_size) { in blocks_to_move()
904 ext2fs_inode_bitmap_loc_set(fs, g, 0); in blocks_to_move()
907 if ((ext2fs_inode_table_loc(fs, g) + in blocks_to_move()
908 fs->inode_blocks_per_group) > new_size) { in blocks_to_move()
909 ext2fs_inode_table_loc_set(fs, g, 0); in blocks_to_move()
914 retval = ext2fs_allocate_group_table(fs, g, 0); in blocks_to_move()
925 for (blk = ext2fs_blocks_count(fs->super); in blocks_to_move()
927 g = ext2fs_group_of_blk2(fs, blk); in blocks_to_move()
928 if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super, in blocks_to_move()
935 blk = ext2fs_group_first_block2(fs, g+1) - 1; in blocks_to_move()
946 if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) { in blocks_to_move()
948 new_blocks = fs->super->s_first_meta_bg; in blocks_to_move()
951 new_blocks = fs->desc_blocks + fs->super->s_reserved_gdt_blocks; in blocks_to_move()
959 max_groups = fs->group_desc_count; in blocks_to_move()
970 if (!ext2fs_bg_has_super(fs, i)) { in blocks_to_move()
971 group_blk += fs->super->s_blocks_per_group; in blocks_to_move()
976 ext2fs_block_alloc_stats2(fs, blk, -1); in blocks_to_move()
979 group_blk += fs->super->s_blocks_per_group; in blocks_to_move()
988 meta_bg_size = EXT2_DESC_PER_BLOCK(fs->super); in blocks_to_move()
989 flex_bg = fs->super->s_feature_incompat & in blocks_to_move()
993 has_super = ext2fs_bg_has_super(fs, i); in blocks_to_move()
998 if (!(fs->super->s_feature_incompat & in blocks_to_move()
1000 (meta_bg < fs->super->s_first_meta_bg)) { in blocks_to_move()
1027 if (ext2fs_block_bitmap_loc(fs, i)) in blocks_to_move()
1029 ext2fs_block_bitmap_loc(fs, i)); in blocks_to_move()
1034 if (ext2fs_inode_bitmap_loc(fs, i)) in blocks_to_move()
1036 ext2fs_inode_bitmap_loc(fs, i)); in blocks_to_move()
1041 if (ext2fs_inode_table_loc(fs, i)) in blocks_to_move()
1043 ext2fs_inode_table_loc(fs, i), in blocks_to_move()
1044 fs->inode_blocks_per_group); in blocks_to_move()
1055 if (ext2fs_inode_table_loc(fs, i) && in blocks_to_move()
1056 ext2fs_inode_bitmap_loc(fs, i) && in blocks_to_move()
1057 ext2fs_block_bitmap_loc(fs, i)) in blocks_to_move()
1060 retval = ext2fs_allocate_group_table(fs, i, in blocks_to_move()
1070 (blk = ext2fs_block_bitmap_loc(fs, i))) { in blocks_to_move()
1071 ext2fs_block_alloc_stats2(fs, blk, +1); in blocks_to_move()
1078 (blk = ext2fs_inode_bitmap_loc(fs, i))) { in blocks_to_move()
1079 ext2fs_block_alloc_stats2(fs, blk, +1); in blocks_to_move()
1093 if (ext2fs_inode_table_loc(fs, i) == ext2fs_inode_table_loc(old_fs, i)) in blocks_to_move()
1096 rfs->needed_blocks += fs->inode_blocks_per_group; in blocks_to_move()
1103 for (blk = ext2fs_inode_table_loc(fs, i), j=0; in blocks_to_move()
1104 j < fs->inode_blocks_per_group ; j++, blk++) { in blocks_to_move()
1105 ext2fs_block_alloc_stats2(fs, blk, +1); in blocks_to_move()
1117 j < fs->inode_blocks_per_group ; j++, blk++) in blocks_to_move()
1160 ext2_filsys fs = rfs->new_fs; in get_new_block() local
1163 if (rfs->new_blk >= ext2fs_blocks_count(fs->super)) { in get_new_block()
1173 rfs->new_blk = fs->super->s_first_data_block; in get_new_block()
1176 if (ext2fs_test_block_bitmap2(fs->block_map, rfs->new_blk) || in get_new_block()
1190 static errcode_t resize2fs_get_alloc_block(ext2_filsys fs, blk64_t goal, in resize2fs_get_alloc_block() argument
1193 ext2_resize_t rfs = (ext2_resize_t) fs->priv_data; in resize2fs_get_alloc_block()
1214 ext2_filsys fs = rfs->new_fs; in block_mover() local
1223 fs->get_alloc_block = resize2fs_get_alloc_block; in block_mover()
1230 new_blk = fs->super->s_first_data_block; in block_mover()
1232 retval = ext2fs_get_array(fs->blocksize, in block_mover()
1233 fs->inode_blocks_per_group, in block_mover()
1250 blk += EXT2FS_CLUSTER_RATIO(fs)) { in block_mover()
1266 ext2fs_block_alloc_stats2(fs, new_blk, +1); in block_mover()
1307 if (c > fs->inode_blocks_per_group) in block_mover()
1308 c = fs->inode_blocks_per_group; in block_mover()
1309 retval = io_channel_read_blk64(fs->io, old_blk, c, in block_mover()
1312 retval = io_channel_write_blk64(fs->io, new_blk, c, in block_mover()
1320 io_channel_flush(fs->io); in block_mover()
1328 io_channel_flush(fs->io); in block_mover()
1355 static __u64 extent_translate(ext2_filsys fs, ext2_extent extent, __u64 old_loc) in extent_translate() argument
1360 new_block += old_loc & (EXT2FS_CLUSTER_RATIO(fs) - 1); in extent_translate()
1373 static int process_block(ext2_filsys fs, blk64_t *block_nr, in process_block() argument
1386 new_block = extent_translate(fs, pb->rfs->bmap, block); in process_block()
1400 retval = ext2fs_add_dir_block2(fs->dblist, pb->ino, in process_block()
1413 static errcode_t progress_callback(ext2_filsys fs, in progress_callback() argument
1428 io_channel_flush(fs->io); in progress_callback()
1430 group+1, fs->group_desc_count); in progress_callback()
1720 ext2_filsys fs = rfs->new_fs; in move_itables() local
1726 max_groups = fs->group_desc_count; in move_itables()
1730 size = fs->blocksize * fs->inode_blocks_per_group; in move_itables()
1743 ext2fs_inode_table_loc(fs, i)) in move_itables()
1760 new_blk = ext2fs_inode_table_loc(fs, i); in move_itables()
1772 retval = io_channel_read_blk64(fs->io, old_blk, in move_itables()
1773 fs->inode_blocks_per_group, in move_itables()
1787 n = n >> EXT2_BLOCK_SIZE_BITS(fs->super); in move_itables()
1792 num = fs->inode_blocks_per_group; in move_itables()
1796 retval = io_channel_write_blk64(fs->io, new_blk, in move_itables()
1799 io_channel_write_blk64(fs->io, old_blk, in move_itables()
1804 retval = io_channel_write_blk64(fs->io, in move_itables()
1805 old_blk + fs->inode_blocks_per_group, in move_itables()
1807 (fs->inode_blocks_per_group - diff) * in move_itables()
1808 fs->blocksize)); in move_itables()
1814 j < fs->inode_blocks_per_group ; j++, blk++) in move_itables()
1815 ext2fs_block_alloc_stats2(fs, blk, -1); in move_itables()
1829 mark_table_blocks(fs, fs->block_map); in move_itables()
1830 ext2fs_flush(fs); in move_itables()
1844 static errcode_t fix_resize_inode(ext2_filsys fs) in fix_resize_inode() argument
1850 if (!(fs->super->s_feature_compat & in fix_resize_inode()
1854 retval = ext2fs_get_mem(fs->blocksize, &block_buf); in fix_resize_inode()
1857 retval = ext2fs_read_inode(fs, EXT2_RESIZE_INO, &inode); in fix_resize_inode()
1860 ext2fs_iblk_set(fs, &inode, 1); in fix_resize_inode()
1862 retval = ext2fs_write_inode(fs, EXT2_RESIZE_INO, &inode); in fix_resize_inode()
1876 memset(block_buf, 0, fs->blocksize); in fix_resize_inode()
1878 retval = io_channel_write_blk64(fs->io, inode.i_block[EXT2_DIND_BLOCK], in fix_resize_inode()
1882 retval = ext2fs_create_resize_inode(fs); in fix_resize_inode()
1895 static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs) in ext2fs_calculate_summary_stats() argument
1911 uninit = ext2fs_bg_flags_test(fs, group, EXT2_BG_BLOCK_UNINIT); in ext2fs_calculate_summary_stats()
1912 ext2fs_super_and_bgd_loc2(fs, group, &super_blk, &old_desc_blk, in ext2fs_calculate_summary_stats()
1914 if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) in ext2fs_calculate_summary_stats()
1915 old_desc_blocks = fs->super->s_first_meta_bg; in ext2fs_calculate_summary_stats()
1917 old_desc_blocks = fs->desc_blocks + in ext2fs_calculate_summary_stats()
1918 fs->super->s_reserved_gdt_blocks; in ext2fs_calculate_summary_stats()
1919 for (blk = B2C(fs->super->s_first_data_block); in ext2fs_calculate_summary_stats()
1920 blk < ext2fs_blocks_count(fs->super); in ext2fs_calculate_summary_stats()
1921 blk += EXT2FS_CLUSTER_RATIO(fs)) { in ext2fs_calculate_summary_stats()
1928 EQ_CLSTR(blk, ext2fs_block_bitmap_loc(fs, group)) || in ext2fs_calculate_summary_stats()
1929 EQ_CLSTR(blk, ext2fs_inode_bitmap_loc(fs, group)) || in ext2fs_calculate_summary_stats()
1930 ((GE_CLSTR(blk, ext2fs_inode_table_loc(fs, group)) && in ext2fs_calculate_summary_stats()
1931 LT_CLSTR(blk, ext2fs_inode_table_loc(fs, group) in ext2fs_calculate_summary_stats()
1932 + fs->inode_blocks_per_group))))) || in ext2fs_calculate_summary_stats()
1933 (!ext2fs_fast_test_block_bitmap2(fs->block_map, blk))) { in ext2fs_calculate_summary_stats()
1938 if ((count == fs->super->s_clusters_per_group) || in ext2fs_calculate_summary_stats()
1939 EQ_CLSTR(blk, ext2fs_blocks_count(fs->super)-1)) { in ext2fs_calculate_summary_stats()
1940 ext2fs_bg_free_blocks_count_set(fs, group, group_free); in ext2fs_calculate_summary_stats()
1941 ext2fs_group_desc_csum_set(fs, group); in ext2fs_calculate_summary_stats()
1943 if (group >= fs->group_desc_count) in ext2fs_calculate_summary_stats()
1947 uninit = ext2fs_bg_flags_test(fs, group, EXT2_BG_BLOCK_UNINIT); in ext2fs_calculate_summary_stats()
1948 ext2fs_super_and_bgd_loc2(fs, group, &super_blk, in ext2fs_calculate_summary_stats()
1951 if (fs->super->s_feature_incompat & in ext2fs_calculate_summary_stats()
1953 old_desc_blocks = fs->super->s_first_meta_bg; in ext2fs_calculate_summary_stats()
1955 old_desc_blocks = fs->desc_blocks + in ext2fs_calculate_summary_stats()
1956 fs->super->s_reserved_gdt_blocks; in ext2fs_calculate_summary_stats()
1960 ext2fs_free_blocks_count_set(fs->super, total_blocks_free); in ext2fs_calculate_summary_stats()
1970 uninit = ext2fs_bg_flags_test(fs, group, EXT2_BG_INODE_UNINIT); in ext2fs_calculate_summary_stats()
1971 for (ino = 1; ino <= fs->super->s_inodes_count && ino > 0; ino++) { in ext2fs_calculate_summary_stats()
1973 !ext2fs_fast_test_inode_bitmap2(fs->inode_map, ino)) { in ext2fs_calculate_summary_stats()
1978 if ((count == fs->super->s_inodes_per_group) || in ext2fs_calculate_summary_stats()
1979 (ino == fs->super->s_inodes_count)) { in ext2fs_calculate_summary_stats()
1980 ext2fs_bg_free_inodes_count_set(fs, group, group_free); in ext2fs_calculate_summary_stats()
1981 ext2fs_group_desc_csum_set(fs, group); in ext2fs_calculate_summary_stats()
1983 if (group >= fs->group_desc_count) in ext2fs_calculate_summary_stats()
1987 uninit = ext2fs_bg_flags_test(fs, group, EXT2_BG_INODE_UNINIT); in ext2fs_calculate_summary_stats()
1990 fs->super->s_free_inodes_count = total_inodes_free; in ext2fs_calculate_summary_stats()
1991 ext2fs_mark_super_dirty(fs); in ext2fs_calculate_summary_stats()
1999 static errcode_t fix_sb_journal_backup(ext2_filsys fs) in fix_sb_journal_backup() argument
2004 if (!(fs->super->s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL)) in fix_sb_journal_backup()
2008 if (fs->super->s_journal_dev && !fs->super->s_journal_inum) in fix_sb_journal_backup()
2011 retval = ext2fs_read_inode(fs, fs->super->s_journal_inum, &inode); in fix_sb_journal_backup()
2014 memcpy(fs->super->s_jnl_blocks, inode.i_block, EXT2_N_BLOCKS*4); in fix_sb_journal_backup()
2015 fs->super->s_jnl_blocks[15] = inode.i_size_high; in fix_sb_journal_backup()
2016 fs->super->s_jnl_blocks[16] = inode.i_size; in fix_sb_journal_backup()
2017 fs->super->s_jnl_backup_type = EXT3_JNL_BACKUP_BLOCKS; in fix_sb_journal_backup()
2018 ext2fs_mark_super_dirty(fs); in fix_sb_journal_backup()
2022 static int calc_group_overhead(ext2_filsys fs, blk64_t grp, in calc_group_overhead() argument
2029 overhead = fs->inode_blocks_per_group + 2; in calc_group_overhead()
2031 ext2fs_super_and_bgd_loc2(fs, grp, &super_blk, in calc_group_overhead()
2046 blk64_t calculate_minimum_resize_size(ext2_filsys fs, int flags) in calculate_minimum_resize_size() argument
2055 int flexbg_size = 1 << fs->super->s_log_groups_per_flex; in calculate_minimum_resize_size()
2061 inode_count = fs->super->s_inodes_count - in calculate_minimum_resize_size()
2062 fs->super->s_free_inodes_count; in calculate_minimum_resize_size()
2064 fs->super->s_inodes_per_group) * in calculate_minimum_resize_size()
2065 EXT2_BLOCKS_PER_GROUP(fs->super); in calculate_minimum_resize_size()
2067 EXT2_BLOCKS_PER_GROUP(fs->super)); in calculate_minimum_resize_size()
2077 if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) in calculate_minimum_resize_size()
2078 old_desc_blocks = fs->super->s_first_meta_bg; in calculate_minimum_resize_size()
2080 old_desc_blocks = fs->desc_blocks + in calculate_minimum_resize_size()
2081 fs->super->s_reserved_gdt_blocks; in calculate_minimum_resize_size()
2084 data_needed = ext2fs_blocks_count(fs->super) - in calculate_minimum_resize_size()
2085 ext2fs_free_blocks_count(fs->super); in calculate_minimum_resize_size()
2087 for (grp = 0; grp < fs->group_desc_count; grp++) in calculate_minimum_resize_size()
2088 data_needed -= calc_group_overhead(fs, grp, old_desc_blocks); in calculate_minimum_resize_size()
2099 if (fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_FLEX_BG) { in calculate_minimum_resize_size()
2101 data_needed += fs->inode_blocks_per_group * extra_groups; in calculate_minimum_resize_size()
2109 data_blocks = groups * EXT2_BLOCKS_PER_GROUP(fs->super); in calculate_minimum_resize_size()
2112 overhead = calc_group_overhead(fs, grp, old_desc_blocks); in calculate_minimum_resize_size()
2120 last_start += EXT2_BLOCKS_PER_GROUP(fs->super) - in calculate_minimum_resize_size()
2141 EXT2_BLOCKS_PER_GROUP(fs->super)); in calculate_minimum_resize_size()
2143 data_blocks += extra_grps * EXT2_BLOCKS_PER_GROUP(fs->super); in calculate_minimum_resize_size()
2146 overhead = calc_group_overhead(fs, groups-1, old_desc_blocks); in calculate_minimum_resize_size()
2147 last_start += EXT2_BLOCKS_PER_GROUP(fs->super) - overhead; in calculate_minimum_resize_size()
2150 overhead = calc_group_overhead(fs, grp, in calculate_minimum_resize_size()
2158 last_start += EXT2_BLOCKS_PER_GROUP(fs->super) in calculate_minimum_resize_size()
2166 if (fs->super->s_feature_incompat in calculate_minimum_resize_size()
2176 data_needed += (fs->inode_blocks_per_group * in calculate_minimum_resize_size()
2191 overhead = calc_group_overhead(fs, groups-1, old_desc_blocks); in calculate_minimum_resize_size()
2222 overhead += fs->super->s_first_data_block; in calculate_minimum_resize_size()
2233 blks_needed = (groups-1) * EXT2_BLOCKS_PER_GROUP(fs->super); in calculate_minimum_resize_size()
2240 overhead = ext2fs_inode_table_loc(fs, groups-1) + in calculate_minimum_resize_size()
2241 fs->inode_blocks_per_group; in calculate_minimum_resize_size()
2254 if (blks_needed >= ext2fs_blocks_count(fs->super)) in calculate_minimum_resize_size()
2255 return ext2fs_blocks_count(fs->super); in calculate_minimum_resize_size()
2261 if (fs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_EXTENTS) { in calculate_minimum_resize_size()
2262 blk64_t safe_margin = (ext2fs_blocks_count(fs->super) - in calculate_minimum_resize_size()