• Home
  • Raw
  • Download

Lines Matching +full:- +full:fs

2  * resize2fs.c --- ext2 main routine
9 * %Begin-Header%
12 * %End-Header%
44 static void fix_uninit_block_bitmaps(ext2_filsys fs);
51 static errcode_t fix_resize_inode(ext2_filsys fs);
52 static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs);
53 static errcode_t fix_sb_journal_backup(ext2_filsys fs);
54 static errcode_t mark_table_blocks(ext2_filsys fs,
66 static inline int is_block_bm(ext2_filsys fs, unsigned int grp, blk64_t blk) in is_block_bm() argument
68 return blk == ext2fs_block_bitmap_loc(fs, grp); in is_block_bm()
71 static inline int is_inode_bm(ext2_filsys fs, unsigned int grp, blk64_t blk) in is_inode_bm() argument
73 return blk == ext2fs_inode_bitmap_loc(fs, grp); in is_inode_bm()
76 static int is_inode_tb(ext2_filsys fs, unsigned int grp, blk64_t blk) in is_inode_tb() argument
78 return blk >= ext2fs_inode_table_loc(fs, grp) && in is_inode_tb()
79 blk < (ext2fs_inode_table_loc(fs, grp) + in is_inode_tb()
80 fs->inode_blocks_per_group); in is_inode_tb()
84 #define B2C(x) EXT2FS_B2C(fs, (x))
85 #define C2B(x) EXT2FS_C2B(fs, (x))
95 * This is the top-level routine which does the dirty deed....
97 errcode_t resize_fs(ext2_filsys fs, blk64_t *new_size, int flags, in resize_fs() argument
114 fs->priv_data = rfs; in resize_fs()
115 rfs->old_fs = fs; in resize_fs()
116 rfs->flags = flags; in resize_fs()
117 rfs->itable_buf = 0; in resize_fs()
118 rfs->progress = progress; in resize_fs()
120 init_resource_track(&overall_track, "overall resize2fs", fs->io); in resize_fs()
121 init_resource_track(&rtrack, "read_bitmaps", fs->io); in resize_fs()
122 retval = ext2fs_read_bitmaps(fs); in resize_fs()
125 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
127 fs->super->s_state |= EXT2_ERROR_FS; in resize_fs()
128 ext2fs_mark_super_dirty(fs); in resize_fs()
129 ext2fs_flush(fs); in resize_fs()
131 init_resource_track(&rtrack, "fix_uninit_block_bitmaps 1", fs->io); in resize_fs()
132 fix_uninit_block_bitmaps(fs); in resize_fs()
133 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
134 retval = ext2fs_dup_handle(fs, &rfs->new_fs); in resize_fs()
138 init_resource_track(&rtrack, "resize_group_descriptors", fs->io); in resize_fs()
142 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
144 init_resource_track(&rtrack, "move_bg_metadata", fs->io); in resize_fs()
148 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
150 init_resource_track(&rtrack, "zero_high_bits_in_metadata", fs->io); in resize_fs()
154 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
156 init_resource_track(&rtrack, "adjust_superblock", fs->io); in resize_fs()
160 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
162 init_resource_track(&rtrack, "fix_uninit_block_bitmaps 2", fs->io); in resize_fs()
163 fix_uninit_block_bitmaps(rfs->new_fs); in resize_fs()
164 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
166 ext2fs_bg_flags_clear(rfs->new_fs, rfs->new_fs->group_desc_count - 1, in resize_fs()
169 *new_size = ext2fs_blocks_count(rfs->new_fs->super); in resize_fs()
171 init_resource_track(&rtrack, "blocks_to_move", fs->io); in resize_fs()
175 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
178 if (rfs->flags & RESIZE_DEBUG_BMOVE) in resize_fs()
180 ext2fs_free_blocks_count(rfs->old_fs->super), in resize_fs()
181 ext2fs_free_blocks_count(rfs->new_fs->super), in resize_fs()
182 rfs->needed_blocks); in resize_fs()
185 init_resource_track(&rtrack, "block_mover", fs->io); in resize_fs()
189 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
191 init_resource_track(&rtrack, "inode_scan_and_fix", fs->io); in resize_fs()
195 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
197 init_resource_track(&rtrack, "inode_ref_fix", fs->io); in resize_fs()
201 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
203 init_resource_track(&rtrack, "move_itables", fs->io); in resize_fs()
207 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
213 init_resource_track(&rtrack, "calculate_summary_stats", fs->io); in resize_fs()
214 retval = ext2fs_calculate_summary_stats(rfs->new_fs); in resize_fs()
217 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
219 init_resource_track(&rtrack, "fix_resize_inode", fs->io); in resize_fs()
220 retval = fix_resize_inode(rfs->new_fs); in resize_fs()
223 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
225 init_resource_track(&rtrack, "fix_sb_journal_backup", fs->io); in resize_fs()
226 retval = fix_sb_journal_backup(rfs->new_fs); in resize_fs()
229 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
231 retval = ext2fs_set_gdt_csum(rfs->new_fs); in resize_fs()
235 rfs->new_fs->super->s_state &= ~EXT2_ERROR_FS; in resize_fs()
236 rfs->new_fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY; in resize_fs()
238 print_resource_track(rfs, &overall_track, fs->io); in resize_fs()
239 retval = ext2fs_close_free(&rfs->new_fs); in resize_fs()
243 rfs->flags = flags; in resize_fs()
245 ext2fs_free(rfs->old_fs); in resize_fs()
246 rfs->old_fs = NULL; in resize_fs()
247 if (rfs->itable_buf) in resize_fs()
248 ext2fs_free_mem(&rfs->itable_buf); in resize_fs()
249 if (rfs->reserve_blocks) in resize_fs()
250 ext2fs_free_block_bitmap(rfs->reserve_blocks); in resize_fs()
251 if (rfs->move_blocks) in resize_fs()
252 ext2fs_free_block_bitmap(rfs->move_blocks); in resize_fs()
258 if (rfs->new_fs) { in resize_fs()
259 ext2fs_free(rfs->new_fs); in resize_fs()
260 rfs->new_fs = NULL; in resize_fs()
262 if (rfs->itable_buf) in resize_fs()
263 ext2fs_free_mem(&rfs->itable_buf); in resize_fs()
269 static void adjust_reserved_gdt_blocks(ext2_filsys old_fs, ext2_filsys fs) in adjust_reserved_gdt_blocks() argument
271 if (ext2fs_has_feature_resize_inode(fs->super) && in adjust_reserved_gdt_blocks()
272 (old_fs->desc_blocks != fs->desc_blocks)) { in adjust_reserved_gdt_blocks()
275 new = ((int) fs->super->s_reserved_gdt_blocks) + in adjust_reserved_gdt_blocks()
276 (old_fs->desc_blocks - fs->desc_blocks); in adjust_reserved_gdt_blocks()
279 if (new > (int) fs->blocksize/4) in adjust_reserved_gdt_blocks()
280 new = fs->blocksize/4; in adjust_reserved_gdt_blocks()
281 fs->super->s_reserved_gdt_blocks = new; in adjust_reserved_gdt_blocks()
293 if (!(rfs->flags & (RESIZE_DISABLE_64BIT | RESIZE_ENABLE_64BIT))) in resize_group_descriptors()
296 if (new_size != ext2fs_blocks_count(rfs->new_fs->super) || in resize_group_descriptors()
297 ext2fs_blocks_count(rfs->new_fs->super) >= (1ULL << 32) || in resize_group_descriptors()
298 (rfs->flags & RESIZE_DISABLE_64BIT && in resize_group_descriptors()
299 rfs->flags & RESIZE_ENABLE_64BIT)) in resize_group_descriptors()
302 if (rfs->flags & RESIZE_DISABLE_64BIT) { in resize_group_descriptors()
303 ext2fs_clear_feature_64bit(rfs->new_fs->super); in resize_group_descriptors()
304 rfs->new_fs->super->s_desc_size = EXT2_MIN_DESC_SIZE; in resize_group_descriptors()
305 } else if (rfs->flags & RESIZE_ENABLE_64BIT) { in resize_group_descriptors()
306 ext2fs_set_feature_64bit(rfs->new_fs->super); in resize_group_descriptors()
307 rfs->new_fs->super->s_desc_size = EXT2_MIN_DESC_SIZE_64BIT; in resize_group_descriptors()
310 if (EXT2_DESC_SIZE(rfs->old_fs->super) == in resize_group_descriptors()
311 EXT2_DESC_SIZE(rfs->new_fs->super)) in resize_group_descriptors()
314 o = rfs->new_fs->group_desc; in resize_group_descriptors()
315 rfs->new_fs->desc_blocks = ext2fs_div_ceil( in resize_group_descriptors()
316 rfs->old_fs->group_desc_count, in resize_group_descriptors()
317 EXT2_DESC_PER_BLOCK(rfs->new_fs->super)); in resize_group_descriptors()
318 retval = ext2fs_get_arrayzero(rfs->new_fs->desc_blocks, in resize_group_descriptors()
319 rfs->old_fs->blocksize, &new_group_desc); in resize_group_descriptors()
325 if (EXT2_DESC_SIZE(rfs->old_fs->super) <= in resize_group_descriptors()
326 EXT2_DESC_SIZE(rfs->new_fs->super)) in resize_group_descriptors()
327 copy_size = EXT2_DESC_SIZE(rfs->old_fs->super); in resize_group_descriptors()
329 copy_size = EXT2_DESC_SIZE(rfs->new_fs->super); in resize_group_descriptors()
330 for (i = 0; i < rfs->old_fs->group_desc_count; i++) { in resize_group_descriptors()
332 n = (char *)n + EXT2_DESC_SIZE(rfs->new_fs->super); in resize_group_descriptors()
333 o = (char *)o + EXT2_DESC_SIZE(rfs->old_fs->super); in resize_group_descriptors()
336 ext2fs_free_mem(&rfs->new_fs->group_desc); in resize_group_descriptors()
337 rfs->new_fs->group_desc = new_group_desc; in resize_group_descriptors()
339 for (i = 0; i < rfs->old_fs->group_desc_count; i++) in resize_group_descriptors()
340 ext2fs_group_desc_csum_set(rfs->new_fs, i); in resize_group_descriptors()
342 adjust_reserved_gdt_blocks(rfs->old_fs, rfs->new_fs); in resize_group_descriptors()
357 if (!(rfs->flags & (RESIZE_DISABLE_64BIT | RESIZE_ENABLE_64BIT))) in move_bg_metadata()
360 retval = ext2fs_allocate_block_bitmap(rfs->old_fs, "oldfs", &old_map); in move_bg_metadata()
364 retval = ext2fs_allocate_block_bitmap(rfs->new_fs, "newfs", &new_map); in move_bg_metadata()
368 if (ext2fs_has_feature_meta_bg(rfs->old_fs->super)) { in move_bg_metadata()
369 old_desc_blocks = rfs->old_fs->super->s_first_meta_bg; in move_bg_metadata()
370 new_desc_blocks = rfs->new_fs->super->s_first_meta_bg; in move_bg_metadata()
372 old_desc_blocks = rfs->old_fs->desc_blocks + in move_bg_metadata()
373 rfs->old_fs->super->s_reserved_gdt_blocks; in move_bg_metadata()
374 new_desc_blocks = rfs->new_fs->desc_blocks + in move_bg_metadata()
375 rfs->new_fs->super->s_reserved_gdt_blocks; in move_bg_metadata()
378 /* Construct bitmaps of super/descriptor blocks in old and new fs */ in move_bg_metadata()
379 for (i = 0; i < rfs->old_fs->group_desc_count; i++) { in move_bg_metadata()
380 retval = ext2fs_super_and_bgd_loc2(rfs->old_fs, i, &b, &c, &d, in move_bg_metadata()
391 retval = ext2fs_super_and_bgd_loc2(rfs->new_fs, i, &b, &c, &d, in move_bg_metadata()
403 cluster_ratio = EXT2FS_CLUSTER_RATIO(rfs->new_fs); in move_bg_metadata()
406 for (b = EXT2FS_B2C(rfs->old_fs, in move_bg_metadata()
407 rfs->old_fs->super->s_first_data_block); in move_bg_metadata()
408 b < ext2fs_blocks_count(rfs->new_fs->super); in move_bg_metadata()
417 rfs->new_fs->block_map, b); in move_bg_metadata()
435 for (i = 0; i < rfs->old_fs->group_desc_count; i++) { in move_bg_metadata()
436 b = ext2fs_block_bitmap_loc(rfs->new_fs, i); in move_bg_metadata()
438 ext2fs_block_bitmap_loc_set(rfs->new_fs, i, 0); in move_bg_metadata()
442 b = ext2fs_inode_bitmap_loc(rfs->new_fs, i); in move_bg_metadata()
444 ext2fs_inode_bitmap_loc_set(rfs->new_fs, i, 0); in move_bg_metadata()
448 c = ext2fs_inode_table_loc(rfs->new_fs, i); in move_bg_metadata()
450 b < rfs->new_fs->inode_blocks_per_group; in move_bg_metadata()
453 ext2fs_inode_table_loc_set(rfs->new_fs, i, 0); in move_bg_metadata()
461 cluster_ratio > 1 && b < ext2fs_blocks_count(rfs->new_fs->super); in move_bg_metadata()
464 ext2fs_unmark_block_bitmap2(rfs->new_fs->block_map, b); in move_bg_metadata()
474 static errcode_t zero_high_bits_in_extents(ext2_filsys fs, ext2_ino_t ino, in zero_high_bits_in_extents() argument
482 if (!(inode->i_flags & EXT4_EXTENTS_FL)) in zero_high_bits_in_extents()
485 errcode = ext2fs_extent_open(fs, ino, &handle); in zero_high_bits_in_extents()
497 extent.e_pblk &= (1ULL << 32) - 1; in zero_high_bits_in_extents()
514 ext2_filsys fs = rfs->old_fs; in zero_high_bits_in_inodes() local
515 int length = EXT2_INODE_SIZE(fs->super); in zero_high_bits_in_inodes()
521 if (!(rfs->flags & (RESIZE_DISABLE_64BIT | RESIZE_ENABLE_64BIT))) in zero_high_bits_in_inodes()
524 if (fs->super->s_creator_os == EXT2_OS_HURD) in zero_high_bits_in_inodes()
527 retval = ext2fs_open_inode_scan(fs, 0, &scan); in zero_high_bits_in_inodes()
541 if (!ext2fs_test_inode_bitmap2(fs->inode_map, ino)) in zero_high_bits_in_inodes()
547 * - i_size_high has been been written out with i_size_lo in zero_high_bits_in_inodes()
550 * - i_blocks_hi is guarded by both the huge_file feature and in zero_high_bits_in_inodes()
556 * - i_file_acl_high can be uninitialized, so zero it if in zero_high_bits_in_inodes()
559 if (inode->osd2.linux2.l_i_file_acl_high) { in zero_high_bits_in_inodes()
560 inode->osd2.linux2.l_i_file_acl_high = 0; in zero_high_bits_in_inodes()
561 retval = ext2fs_write_inode_full(fs, ino, inode, in zero_high_bits_in_inodes()
567 retval = zero_high_bits_in_extents(fs, ino, inode); in zero_high_bits_in_inodes()
583 static void fix_uninit_block_bitmaps(ext2_filsys fs) in fix_uninit_block_bitmaps() argument
589 if (!ext2fs_has_group_desc_csum(fs)) in fix_uninit_block_bitmaps()
592 for (g=0; g < fs->group_desc_count; g++) { in fix_uninit_block_bitmaps()
593 if (!(ext2fs_bg_flags_test(fs, g, EXT2_BG_BLOCK_UNINIT))) in fix_uninit_block_bitmaps()
596 blk = ext2fs_group_first_block2(fs, g); in fix_uninit_block_bitmaps()
597 lblk = ext2fs_group_last_block2(fs, g); in fix_uninit_block_bitmaps()
598 ext2fs_unmark_block_bitmap_range2(fs->block_map, blk, in fix_uninit_block_bitmaps()
599 lblk - blk + 1); in fix_uninit_block_bitmaps()
601 ext2fs_reserve_super_and_bgd(fs, g, fs->block_map); in fix_uninit_block_bitmaps()
602 ext2fs_mark_block_bitmap2(fs->block_map, in fix_uninit_block_bitmaps()
603 ext2fs_block_bitmap_loc(fs, g)); in fix_uninit_block_bitmaps()
604 ext2fs_mark_block_bitmap2(fs->block_map, in fix_uninit_block_bitmaps()
605 ext2fs_inode_bitmap_loc(fs, g)); in fix_uninit_block_bitmaps()
606 for (i = 0, blk = ext2fs_inode_table_loc(fs, g); in fix_uninit_block_bitmaps()
607 i < fs->inode_blocks_per_group; in fix_uninit_block_bitmaps()
609 ext2fs_mark_block_bitmap2(fs->block_map, blk); in fix_uninit_block_bitmaps()
613 /* --------------------------------------------------------------------
617 * In this phase we adjust the in-memory superblock information, and
621 * --------------------------------------------------------------------
629 static errcode_t free_gdp_blocks(ext2_filsys fs, in free_gdp_blocks() argument
639 dgrp_t count = old_fs->group_desc_count - fs->group_desc_count; in free_gdp_blocks()
642 if (EXT2FS_CLUSTER_RATIO(fs) > 1) { in free_gdp_blocks()
643 retval = ext2fs_allocate_block_bitmap(fs, "bgdata", &bg_map); in free_gdp_blocks()
647 retval = mark_table_blocks(fs, bg_map); in free_gdp_blocks()
655 (blk < ext2fs_blocks_count(fs->super)) && in free_gdp_blocks()
657 ext2fs_block_alloc_stats2(fs, blk, -1); in free_gdp_blocks()
663 (blk < ext2fs_blocks_count(fs->super)) && in free_gdp_blocks()
665 ext2fs_block_alloc_stats2(fs, blk, -1); in free_gdp_blocks()
671 j < fs->inode_blocks_per_group; j++, blk++) { in free_gdp_blocks()
672 if (blk >= ext2fs_blocks_count(fs->super) || in free_gdp_blocks()
675 ext2fs_block_alloc_stats2(fs, blk, -1); in free_gdp_blocks()
690 errcode_t adjust_fs_info(ext2_filsys fs, ext2_filsys old_fs, in adjust_fs_info() argument
705 ext2fs_blocks_count_set(fs->super, new_size); in adjust_fs_info()
708 fs->group_desc_count = ext2fs_div64_ceil(ext2fs_blocks_count(fs->super) - in adjust_fs_info()
709 fs->super->s_first_data_block, in adjust_fs_info()
710 EXT2_BLOCKS_PER_GROUP(fs->super)); in adjust_fs_info()
711 if (fs->group_desc_count == 0) in adjust_fs_info()
713 fs->desc_blocks = ext2fs_div_ceil(fs->group_desc_count, in adjust_fs_info()
714 EXT2_DESC_PER_BLOCK(fs->super)); in adjust_fs_info()
722 overhead = (int) (2 + fs->inode_blocks_per_group); in adjust_fs_info()
725 if (ext2fs_has_feature_sparse_super2(fs->super)) { in adjust_fs_info()
728 * super->s_backup_bgs hasn't been set up yet. in adjust_fs_info()
730 if (fs->group_desc_count == 2) in adjust_fs_info()
731 has_bg = fs->super->s_backup_bgs[0] != 0; in adjust_fs_info()
733 has_bg = fs->super->s_backup_bgs[1] != 0; in adjust_fs_info()
735 has_bg = ext2fs_bg_has_super(fs, fs->group_desc_count - 1); in adjust_fs_info()
737 overhead += 1 + fs->desc_blocks + in adjust_fs_info()
738 fs->super->s_reserved_gdt_blocks; in adjust_fs_info()
745 rem = (ext2fs_blocks_count(fs->super) - fs->super->s_first_data_block) % in adjust_fs_info()
746 fs->super->s_blocks_per_group; in adjust_fs_info()
747 if ((fs->group_desc_count == 1) && rem && (rem < overhead)) in adjust_fs_info()
749 if ((fs->group_desc_count > 1) && rem && (rem < overhead+50)) { in adjust_fs_info()
750 ext2fs_blocks_count_set(fs->super, in adjust_fs_info()
751 ext2fs_blocks_count(fs->super) - rem); in adjust_fs_info()
757 new_inodes =(unsigned long long) fs->super->s_inodes_per_group * fs->group_desc_count; in adjust_fs_info()
763 fs->super->s_inodes_count = fs->super->s_inodes_per_group * in adjust_fs_info()
764 fs->group_desc_count; in adjust_fs_info()
769 blk = ext2fs_blocks_count(old_fs->super); in adjust_fs_info()
770 if (blk > ext2fs_blocks_count(fs->super)) in adjust_fs_info()
771 ext2fs_free_blocks_count_set(fs->super, in adjust_fs_info()
772 ext2fs_free_blocks_count(fs->super) - in adjust_fs_info()
773 (blk - ext2fs_blocks_count(fs->super))); in adjust_fs_info()
775 ext2fs_free_blocks_count_set(fs->super, in adjust_fs_info()
776 ext2fs_free_blocks_count(fs->super) + in adjust_fs_info()
777 (ext2fs_blocks_count(fs->super) - blk)); in adjust_fs_info()
782 percent = (ext2fs_r_blocks_count(old_fs->super) * 100.0) / in adjust_fs_info()
783 ext2fs_blocks_count(old_fs->super); in adjust_fs_info()
784 ext2fs_r_blocks_count_set(fs->super, in adjust_fs_info()
785 (percent * ext2fs_blocks_count(fs->super) / in adjust_fs_info()
791 retval = ext2fs_resize_inode_bitmap2(fs->super->s_inodes_count, in adjust_fs_info()
792 fs->super->s_inodes_count, in adjust_fs_info()
793 fs->inode_map); in adjust_fs_info()
796 real_end = EXT2_GROUPS_TO_BLOCKS(fs->super, fs->group_desc_count) - 1 + in adjust_fs_info()
797 fs->super->s_first_data_block; in adjust_fs_info()
798 retval = ext2fs_resize_block_bitmap2(new_size - 1, in adjust_fs_info()
799 real_end, fs->block_map); in adjust_fs_info()
806 if (reserve_blocks && new_size > ext2fs_blocks_count(old_fs->super)) { in adjust_fs_info()
807 retval = ext2fs_resize_block_bitmap2(new_size - 1, in adjust_fs_info()
815 if (EXT2_DESC_SIZE(old_fs->super) == EXT2_DESC_SIZE(fs->super) && in adjust_fs_info()
816 old_fs->desc_blocks != fs->desc_blocks) { in adjust_fs_info()
817 retval = ext2fs_resize_mem(old_fs->desc_blocks * in adjust_fs_info()
818 fs->blocksize, in adjust_fs_info()
819 fs->desc_blocks * fs->blocksize, in adjust_fs_info()
820 &fs->group_desc); in adjust_fs_info()
823 if (fs->desc_blocks > old_fs->desc_blocks) in adjust_fs_info()
824 memset((char *) fs->group_desc + in adjust_fs_info()
825 (old_fs->desc_blocks * fs->blocksize), 0, in adjust_fs_info()
826 (fs->desc_blocks - old_fs->desc_blocks) * in adjust_fs_info()
827 fs->blocksize); in adjust_fs_info()
838 if (EXT2_DESC_SIZE(old_fs->super) == EXT2_DESC_SIZE(fs->super)) in adjust_fs_info()
839 adjust_reserved_gdt_blocks(old_fs, fs); in adjust_fs_info()
841 if (ext2fs_has_feature_meta_bg(fs->super) && in adjust_fs_info()
842 (fs->super->s_first_meta_bg > fs->desc_blocks)) { in adjust_fs_info()
843 ext2fs_clear_feature_meta_bg(fs->super); in adjust_fs_info()
844 fs->super->s_first_meta_bg = 0; in adjust_fs_info()
851 if (ext2fs_has_feature_sparse_super2(fs->super)) { in adjust_fs_info()
852 dgrp_t last_bg = fs->group_desc_count - 1; in adjust_fs_info()
853 dgrp_t old_last_bg = old_fs->group_desc_count - 1; in adjust_fs_info()
856 if (old_fs->group_desc_count == 1) in adjust_fs_info()
857 fs->super->s_backup_bgs[0] = 1; in adjust_fs_info()
858 if ((old_fs->group_desc_count < 3 && in adjust_fs_info()
859 fs->group_desc_count > 2) || in adjust_fs_info()
860 fs->super->s_backup_bgs[1]) in adjust_fs_info()
861 fs->super->s_backup_bgs[1] = last_bg; in adjust_fs_info()
863 if (fs->super->s_backup_bgs[0] > last_bg) in adjust_fs_info()
864 fs->super->s_backup_bgs[0] = 0; in adjust_fs_info()
865 if (fs->super->s_backup_bgs[1] > last_bg) in adjust_fs_info()
866 fs->super->s_backup_bgs[1] = 0; in adjust_fs_info()
868 old_fs->super->s_backup_bgs[1] == old_last_bg) in adjust_fs_info()
869 fs->super->s_backup_bgs[1] = last_bg; in adjust_fs_info()
877 if (old_fs->group_desc_count > fs->group_desc_count) { in adjust_fs_info()
882 retval = free_gdp_blocks(fs, reserve_blocks, old_fs, in adjust_fs_info()
883 fs->group_desc_count); in adjust_fs_info()
890 old_numblocks = (ext2fs_blocks_count(old_fs->super) - in adjust_fs_info()
891 old_fs->super->s_first_data_block) % in adjust_fs_info()
892 old_fs->super->s_blocks_per_group; in adjust_fs_info()
894 old_numblocks = old_fs->super->s_blocks_per_group; in adjust_fs_info()
895 if (old_fs->group_desc_count == fs->group_desc_count) { in adjust_fs_info()
896 numblocks = (ext2fs_blocks_count(fs->super) - in adjust_fs_info()
897 fs->super->s_first_data_block) % in adjust_fs_info()
898 fs->super->s_blocks_per_group; in adjust_fs_info()
900 numblocks = fs->super->s_blocks_per_group; in adjust_fs_info()
902 numblocks = fs->super->s_blocks_per_group; in adjust_fs_info()
903 i = old_fs->group_desc_count - 1; in adjust_fs_info()
904 …ext2fs_bg_free_blocks_count_set(fs, i, ext2fs_bg_free_blocks_count(fs, i) + (numblocks - old_numbl… in adjust_fs_info()
905 ext2fs_group_desc_csum_set(fs, i); in adjust_fs_info()
912 if (old_fs->group_desc_count >= fs->group_desc_count) { in adjust_fs_info()
920 group_block = ext2fs_group_first_block2(fs, in adjust_fs_info()
921 old_fs->group_desc_count); in adjust_fs_info()
922 csum_flag = ext2fs_has_group_desc_csum(fs); in adjust_fs_info()
925 access("/sys/fs/ext4/features/lazy_itable_init", F_OK) == 0)) in adjust_fs_info()
927 if (ext2fs_has_feature_meta_bg(fs->super)) in adjust_fs_info()
928 old_desc_blocks = fs->super->s_first_meta_bg; in adjust_fs_info()
930 old_desc_blocks = fs->desc_blocks + in adjust_fs_info()
931 fs->super->s_reserved_gdt_blocks; in adjust_fs_info()
938 for (i = 0; i < old_fs->group_desc_count; i++) in adjust_fs_info()
939 ext2fs_reserve_super_and_bgd(fs, i, fs->block_map); in adjust_fs_info()
941 for (i = old_fs->group_desc_count; in adjust_fs_info()
942 i < fs->group_desc_count; i++) { in adjust_fs_info()
943 memset(ext2fs_group_desc(fs, fs->group_desc, i), 0, in adjust_fs_info()
947 ext2fs_bg_flags_zap(fs, i); in adjust_fs_info()
949 ext2fs_bg_flags_set(fs, i, EXT2_BG_INODE_UNINIT); in adjust_fs_info()
951 ext2fs_bg_flags_set(fs, i, in adjust_fs_info()
953 ext2fs_bg_itable_unused_set(fs, i, in adjust_fs_info()
954 fs->super->s_inodes_per_group); in adjust_fs_info()
957 numblocks = ext2fs_group_blocks_count(fs, i); in adjust_fs_info()
958 if ((i < fs->group_desc_count - 1) && csum_flag) in adjust_fs_info()
959 ext2fs_bg_flags_set(fs, i, EXT2_BG_BLOCK_UNINIT); in adjust_fs_info()
961 has_super = ext2fs_bg_has_super(fs, i); in adjust_fs_info()
963 ext2fs_block_alloc_stats2(fs, group_block, +1); in adjust_fs_info()
966 meta_bg_size = EXT2_DESC_PER_BLOCK(fs->super); in adjust_fs_info()
968 if (!ext2fs_has_feature_meta_bg(fs->super) || in adjust_fs_info()
969 (meta_bg < fs->super->s_first_meta_bg)) { in adjust_fs_info()
972 ext2fs_block_alloc_stats2(fs, in adjust_fs_info()
981 ((i % meta_bg_size) == (meta_bg_size-1))) in adjust_fs_info()
982 ext2fs_block_alloc_stats2(fs, in adjust_fs_info()
986 adjblocks += 2 + fs->inode_blocks_per_group; in adjust_fs_info()
988 numblocks -= adjblocks; in adjust_fs_info()
989 ext2fs_free_blocks_count_set(fs->super, in adjust_fs_info()
990 ext2fs_free_blocks_count(fs->super) - adjblocks); in adjust_fs_info()
991 fs->super->s_free_inodes_count += in adjust_fs_info()
992 fs->super->s_inodes_per_group; in adjust_fs_info()
993 ext2fs_bg_free_blocks_count_set(fs, i, numblocks); in adjust_fs_info()
994 ext2fs_bg_free_inodes_count_set(fs, i, in adjust_fs_info()
995 fs->super->s_inodes_per_group); in adjust_fs_info()
996 ext2fs_bg_used_dirs_count_set(fs, i, 0); in adjust_fs_info()
997 ext2fs_group_desc_csum_set(fs, i); in adjust_fs_info()
999 retval = ext2fs_allocate_group_table(fs, i, 0); in adjust_fs_info()
1002 group_block += fs->super->s_blocks_per_group; in adjust_fs_info()
1015 mark_table_blocks(fs, reserve_blocks); in adjust_fs_info()
1027 ext2_filsys fs = rfs->new_fs; in adjust_superblock() local
1034 ext2fs_mark_super_dirty(fs); in adjust_superblock()
1035 ext2fs_mark_bb_dirty(fs); in adjust_superblock()
1036 ext2fs_mark_ib_dirty(fs); in adjust_superblock()
1038 retval = ext2fs_allocate_block_bitmap(fs, _("reserved blocks"), in adjust_superblock()
1039 &rfs->reserve_blocks); in adjust_superblock()
1043 retval = adjust_fs_info(fs, rfs->old_fs, rfs->reserve_blocks, new_size); in adjust_superblock()
1050 if ((rfs->old_fs->super->s_inodes_count - in adjust_superblock()
1051 rfs->old_fs->super->s_free_inodes_count) > in adjust_superblock()
1052 rfs->new_fs->super->s_inodes_count) { in adjust_superblock()
1061 if (rfs->old_fs->group_desc_count > fs->group_desc_count) { in adjust_superblock()
1071 if (rfs->old_fs->group_desc_count >= fs->group_desc_count) { in adjust_superblock()
1081 if (lazy_itable_init && ext2fs_has_group_desc_csum(fs)) { in adjust_superblock()
1089 retval = ext2fs_get_array(fs->blocksize, fs->inode_blocks_per_group, in adjust_superblock()
1090 &rfs->itable_buf); in adjust_superblock()
1094 memset(rfs->itable_buf, 0, fs->blocksize * fs->inode_blocks_per_group); in adjust_superblock()
1095 group_block = ext2fs_group_first_block2(fs, in adjust_superblock()
1096 rfs->old_fs->group_desc_count); in adjust_superblock()
1097 adj = rfs->old_fs->group_desc_count; in adjust_superblock()
1098 max_group = fs->group_desc_count - adj; in adjust_superblock()
1099 if (rfs->progress) { in adjust_superblock()
1100 retval = rfs->progress(rfs, E2_RSZ_EXTEND_ITABLE_PASS, in adjust_superblock()
1105 for (i = rfs->old_fs->group_desc_count; in adjust_superblock()
1106 i < fs->group_desc_count; i++) { in adjust_superblock()
1110 retval = ext2fs_zero_blocks2(fs, ext2fs_inode_table_loc(fs, i), in adjust_superblock()
1111 fs->inode_blocks_per_group, NULL, in adjust_superblock()
1116 io_channel_flush(fs->io); in adjust_superblock()
1117 if (rfs->progress) { in adjust_superblock()
1118 retval = rfs->progress(rfs, E2_RSZ_EXTEND_ITABLE_PASS, in adjust_superblock()
1119 i - adj + 1, max_group); in adjust_superblock()
1123 group_block += fs->super->s_blocks_per_group; in adjust_superblock()
1125 io_channel_flush(fs->io); in adjust_superblock()
1132 /* --------------------------------------------------------------------
1141 * --------------------------------------------------------------------
1146 * filesystem meta-data blocks.
1148 static errcode_t mark_table_blocks(ext2_filsys fs, in mark_table_blocks() argument
1154 for (i = 0; i < fs->group_desc_count; i++) { in mark_table_blocks()
1155 ext2fs_reserve_super_and_bgd(fs, i, bmap); in mark_table_blocks()
1160 blk = ext2fs_inode_table_loc(fs, i); in mark_table_blocks()
1163 fs->inode_blocks_per_group); in mark_table_blocks()
1168 blk = ext2fs_block_bitmap_loc(fs, i); in mark_table_blocks()
1175 blk = ext2fs_inode_bitmap_loc(fs, i); in mark_table_blocks()
1191 ext2_filsys fs = rfs->new_fs; in mark_fs_metablock() local
1193 ext2fs_mark_block_bitmap2(rfs->reserve_blocks, blk); in mark_fs_metablock()
1194 ext2fs_block_alloc_stats2(fs, blk, +1); in mark_fs_metablock()
1201 if (is_block_bm(fs, group, blk)) { in mark_fs_metablock()
1202 ext2fs_block_bitmap_loc_set(fs, group, 0); in mark_fs_metablock()
1203 rfs->needed_blocks++; in mark_fs_metablock()
1206 if (is_inode_bm(fs, group, blk)) { in mark_fs_metablock()
1207 ext2fs_inode_bitmap_loc_set(fs, group, 0); in mark_fs_metablock()
1208 rfs->needed_blocks++; in mark_fs_metablock()
1211 if (is_inode_tb(fs, group, blk)) { in mark_fs_metablock()
1212 ext2fs_inode_table_loc_set(fs, group, 0); in mark_fs_metablock()
1213 rfs->needed_blocks++; in mark_fs_metablock()
1216 if (ext2fs_has_feature_flex_bg(fs->super)) { in mark_fs_metablock()
1219 for (i = 0; i < rfs->old_fs->group_desc_count; i++) { in mark_fs_metablock()
1220 if (is_block_bm(fs, i, blk)) { in mark_fs_metablock()
1221 ext2fs_block_bitmap_loc_set(fs, i, 0); in mark_fs_metablock()
1222 rfs->needed_blocks++; in mark_fs_metablock()
1225 if (is_inode_bm(fs, i, blk)) { in mark_fs_metablock()
1226 ext2fs_inode_bitmap_loc_set(fs, i, 0); in mark_fs_metablock()
1227 rfs->needed_blocks++; in mark_fs_metablock()
1230 if (is_inode_tb(fs, i, blk)) { in mark_fs_metablock()
1231 ext2fs_inode_table_loc_set(fs, i, 0); in mark_fs_metablock()
1232 rfs->needed_blocks++; in mark_fs_metablock()
1238 if (ext2fs_has_group_desc_csum(fs) && in mark_fs_metablock()
1239 (ext2fs_bg_flags_test(fs, group, EXT2_BG_BLOCK_UNINIT))) { in mark_fs_metablock()
1245 } else if (ext2fs_test_block_bitmap2(rfs->old_fs->block_map, blk) && in mark_fs_metablock()
1247 ext2fs_mark_block_bitmap2(rfs->move_blocks, blk); in mark_fs_metablock()
1248 rfs->needed_blocks++; in mark_fs_metablock()
1268 ext2_filsys fs, old_fs; in blocks_to_move() local
1272 fs = rfs->new_fs; in blocks_to_move()
1273 old_fs = rfs->old_fs; in blocks_to_move()
1274 if (ext2fs_blocks_count(old_fs->super) > ext2fs_blocks_count(fs->super)) in blocks_to_move()
1275 fs = rfs->old_fs; in blocks_to_move()
1277 retval = ext2fs_allocate_block_bitmap(fs, _("blocks to be moved"), in blocks_to_move()
1278 &rfs->move_blocks); in blocks_to_move()
1282 retval = ext2fs_allocate_block_bitmap(fs, _("meta-data blocks"), in blocks_to_move()
1291 fs = rfs->new_fs; in blocks_to_move()
1299 new_size = ext2fs_blocks_count(fs->super); in blocks_to_move()
1300 if (new_size < ext2fs_blocks_count(old_fs->super)) { in blocks_to_move()
1301 for (g = 0; g < fs->group_desc_count; g++) { in blocks_to_move()
1304 * ext2fs_allocate_group_table will re-allocate any in blocks_to_move()
1307 if (ext2fs_block_bitmap_loc(fs, g) >= new_size) { in blocks_to_move()
1308 ext2fs_block_bitmap_loc_set(fs, g, 0); in blocks_to_move()
1311 if (ext2fs_inode_bitmap_loc(fs, g) >= new_size) { in blocks_to_move()
1312 ext2fs_inode_bitmap_loc_set(fs, g, 0); in blocks_to_move()
1315 if ((ext2fs_inode_table_loc(fs, g) + in blocks_to_move()
1316 fs->inode_blocks_per_group) > new_size) { in blocks_to_move()
1317 ext2fs_inode_table_loc_set(fs, g, 0); in blocks_to_move()
1322 retval = ext2fs_allocate_group_table(fs, g, 0); in blocks_to_move()
1333 for (blk = ext2fs_blocks_count(fs->super); in blocks_to_move()
1334 blk < ext2fs_blocks_count(old_fs->super); blk++) { in blocks_to_move()
1335 g = ext2fs_group_of_blk2(fs, blk); in blocks_to_move()
1336 if (ext2fs_has_group_desc_csum(fs) && in blocks_to_move()
1342 blk = ext2fs_group_first_block2(fs, g+1) - 1; in blocks_to_move()
1345 if (ext2fs_test_block_bitmap2(old_fs->block_map, blk) && in blocks_to_move()
1347 ext2fs_mark_block_bitmap2(rfs->move_blocks, blk); in blocks_to_move()
1348 rfs->needed_blocks++; in blocks_to_move()
1350 ext2fs_mark_block_bitmap2(rfs->reserve_blocks, blk); in blocks_to_move()
1353 if (ext2fs_has_feature_meta_bg(old_fs->super)) in blocks_to_move()
1354 old_blocks = old_fs->super->s_first_meta_bg; in blocks_to_move()
1356 old_blocks = old_fs->desc_blocks + in blocks_to_move()
1357 old_fs->super->s_reserved_gdt_blocks; in blocks_to_move()
1358 if (ext2fs_has_feature_meta_bg(fs->super)) in blocks_to_move()
1359 new_blocks = fs->super->s_first_meta_bg; in blocks_to_move()
1361 new_blocks = fs->desc_blocks + fs->super->s_reserved_gdt_blocks; in blocks_to_move()
1367 if (EXT2_DESC_SIZE(rfs->old_fs->super) == in blocks_to_move()
1368 EXT2_DESC_SIZE(rfs->new_fs->super) && in blocks_to_move()
1374 max_groups = fs->group_desc_count; in blocks_to_move()
1375 if (max_groups > old_fs->group_desc_count) in blocks_to_move()
1376 max_groups = old_fs->group_desc_count; in blocks_to_move()
1377 group_blk = old_fs->super->s_first_data_block; in blocks_to_move()
1380 * makes life easy. :-) We just have to mark some extra in blocks_to_move()
1384 if (EXT2FS_CLUSTER_RATIO(fs) > 1) { in blocks_to_move()
1385 retval = ext2fs_allocate_block_bitmap(fs, in blocks_to_move()
1391 retval = mark_table_blocks(fs, new_meta_bmap); in blocks_to_move()
1398 group_blk += fs->super->s_blocks_per_group; in blocks_to_move()
1408 EXT2FS_CLUSTER_RATIO(fs) - in blocks_to_move()
1410 EXT2FS_CLUSTER_MASK(fs)); in blocks_to_move()
1411 if (cluster_freed > group_end - blk) in blocks_to_move()
1412 cluster_freed = group_end - blk; in blocks_to_move()
1413 ext2fs_block_alloc_stats2(fs, blk, -1); in blocks_to_move()
1414 blk += EXT2FS_CLUSTER_RATIO(fs); in blocks_to_move()
1415 rfs->needed_blocks -= cluster_freed; in blocks_to_move()
1418 rfs->needed_blocks--; in blocks_to_move()
1421 group_blk += fs->super->s_blocks_per_group; in blocks_to_move()
1430 meta_bg_size = EXT2_DESC_PER_BLOCK(fs->super); in blocks_to_move()
1431 flex_bg = ext2fs_has_feature_flex_bg(fs->super); in blocks_to_move()
1432 /* first reserve all of the existing fs meta blocks */ in blocks_to_move()
1434 has_super = ext2fs_bg_has_super(fs, i); in blocks_to_move()
1439 if (!ext2fs_has_feature_meta_bg(fs->super) || in blocks_to_move()
1440 (meta_bg < fs->super->s_first_meta_bg)) { in blocks_to_move()
1452 ((i % meta_bg_size) == (meta_bg_size-1))) in blocks_to_move()
1462 * overwriting fs metadata (especially inode table in blocks_to_move()
1465 * reserve all existing fs metadata blocks. in blocks_to_move()
1467 if (ext2fs_block_bitmap_loc(fs, i)) in blocks_to_move()
1468 ext2fs_mark_block_bitmap2(rfs->reserve_blocks, in blocks_to_move()
1469 ext2fs_block_bitmap_loc(fs, i)); in blocks_to_move()
1470 else if (flex_bg && i < old_fs->group_desc_count) in blocks_to_move()
1471 ext2fs_mark_block_bitmap2(rfs->reserve_blocks, in blocks_to_move()
1474 if (ext2fs_inode_bitmap_loc(fs, i)) in blocks_to_move()
1475 ext2fs_mark_block_bitmap2(rfs->reserve_blocks, in blocks_to_move()
1476 ext2fs_inode_bitmap_loc(fs, i)); in blocks_to_move()
1477 else if (flex_bg && i < old_fs->group_desc_count) in blocks_to_move()
1478 ext2fs_mark_block_bitmap2(rfs->reserve_blocks, in blocks_to_move()
1481 if (ext2fs_inode_table_loc(fs, i)) in blocks_to_move()
1482 ext2fs_mark_block_bitmap_range2(rfs->reserve_blocks, in blocks_to_move()
1483 ext2fs_inode_table_loc(fs, i), in blocks_to_move()
1484 fs->inode_blocks_per_group); in blocks_to_move()
1485 else if (flex_bg && i < old_fs->group_desc_count) in blocks_to_move()
1486 ext2fs_mark_block_bitmap_range2(rfs->reserve_blocks, in blocks_to_move()
1488 old_fs->inode_blocks_per_group); in blocks_to_move()
1490 group_blk += rfs->new_fs->super->s_blocks_per_group; in blocks_to_move()
1495 if (ext2fs_inode_table_loc(fs, i) && in blocks_to_move()
1496 ext2fs_inode_bitmap_loc(fs, i) && in blocks_to_move()
1497 ext2fs_block_bitmap_loc(fs, i)) in blocks_to_move()
1500 retval = ext2fs_allocate_group_table(fs, i, in blocks_to_move()
1501 rfs->reserve_blocks); in blocks_to_move()
1510 (blk = ext2fs_block_bitmap_loc(fs, i))) { in blocks_to_move()
1511 ext2fs_block_alloc_stats2(fs, blk, +1); in blocks_to_move()
1512 if (ext2fs_test_block_bitmap2(old_fs->block_map, blk) && in blocks_to_move()
1514 ext2fs_mark_block_bitmap2(rfs->move_blocks, in blocks_to_move()
1518 (blk = ext2fs_inode_bitmap_loc(fs, i))) { in blocks_to_move()
1519 ext2fs_block_alloc_stats2(fs, blk, +1); in blocks_to_move()
1520 if (ext2fs_test_block_bitmap2(old_fs->block_map, blk) && in blocks_to_move()
1522 ext2fs_mark_block_bitmap2(rfs->move_blocks, in blocks_to_move()
1533 if (ext2fs_inode_table_loc(fs, i) == ext2fs_inode_table_loc(old_fs, i)) in blocks_to_move()
1536 rfs->needed_blocks += fs->inode_blocks_per_group; in blocks_to_move()
1543 for (blk = ext2fs_inode_table_loc(fs, i), j=0; in blocks_to_move()
1544 j < fs->inode_blocks_per_group ; j++, blk++) { in blocks_to_move()
1545 ext2fs_block_alloc_stats2(fs, blk, +1); in blocks_to_move()
1546 if (ext2fs_test_block_bitmap2(old_fs->block_map, blk) && in blocks_to_move()
1548 ext2fs_mark_block_bitmap2(rfs->move_blocks, in blocks_to_move()
1556 for (blk = ext2fs_inode_table_loc(rfs->old_fs, i), j=0; in blocks_to_move()
1557 j < fs->inode_blocks_per_group ; j++, blk++) in blocks_to_move()
1558 ext2fs_mark_block_bitmap2(rfs->reserve_blocks, blk); in blocks_to_move()
1590 rfs->alloc_state = AVOID_OLD; in init_block_alloc()
1591 rfs->new_blk = rfs->new_fs->super->s_first_data_block; in init_block_alloc()
1594 if (ext2fs_blocks_count(rfs->new_fs->super) > in init_block_alloc()
1595 ext2fs_blocks_count(rfs->old_fs->super)) in init_block_alloc()
1596 rfs->new_blk = ext2fs_blocks_count(rfs->old_fs->super); in init_block_alloc()
1602 ext2_filsys fs = rfs->new_fs; in get_new_block() local
1605 if (rfs->new_blk >= ext2fs_blocks_count(fs->super)) { in get_new_block()
1606 if (rfs->alloc_state == DESPERATION) in get_new_block()
1610 if (rfs->flags & RESIZE_DEBUG_BMOVE) in get_new_block()
1614 rfs->alloc_state = DESPERATION; in get_new_block()
1615 rfs->new_blk = fs->super->s_first_data_block; in get_new_block()
1618 if (ext2fs_test_block_bitmap2(fs->block_map, rfs->new_blk) || in get_new_block()
1619 ext2fs_test_block_bitmap2(rfs->reserve_blocks, in get_new_block()
1620 rfs->new_blk) || in get_new_block()
1621 ((rfs->alloc_state == AVOID_OLD) && in get_new_block()
1622 (rfs->new_blk < ext2fs_blocks_count(rfs->old_fs->super)) && in get_new_block()
1623 ext2fs_test_block_bitmap2(rfs->old_fs->block_map, in get_new_block()
1624 rfs->new_blk))) { in get_new_block()
1625 rfs->new_blk++; in get_new_block()
1628 return rfs->new_blk; in get_new_block()
1632 static errcode_t resize2fs_get_alloc_block(ext2_filsys fs, in resize2fs_get_alloc_block() argument
1636 ext2_resize_t rfs = (ext2_resize_t) fs->priv_data; in resize2fs_get_alloc_block()
1645 if (rfs->flags & 0xF) in resize2fs_get_alloc_block()
1649 ext2fs_mark_block_bitmap2(rfs->old_fs->block_map, blk); in resize2fs_get_alloc_block()
1650 ext2fs_mark_block_bitmap2(rfs->new_fs->block_map, blk); in resize2fs_get_alloc_block()
1652 group = ext2fs_group_of_blk2(rfs->old_fs, blk); in resize2fs_get_alloc_block()
1653 ext2fs_clear_block_uninit(rfs->old_fs, group); in resize2fs_get_alloc_block()
1654 group = ext2fs_group_of_blk2(rfs->new_fs, blk); in resize2fs_get_alloc_block()
1655 ext2fs_clear_block_uninit(rfs->new_fs, group); in resize2fs_get_alloc_block()
1664 ext2_filsys fs = rfs->new_fs; in block_mover() local
1665 ext2_filsys old_fs = rfs->old_fs; in block_mover()
1672 fs->get_alloc_block = resize2fs_get_alloc_block; in block_mover()
1673 old_fs->get_alloc_block = resize2fs_get_alloc_block; in block_mover()
1679 new_blk = fs->super->s_first_data_block; in block_mover()
1680 if (!rfs->itable_buf) { in block_mover()
1681 retval = ext2fs_get_array(fs->blocksize, in block_mover()
1682 fs->inode_blocks_per_group, in block_mover()
1683 &rfs->itable_buf); in block_mover()
1687 retval = ext2fs_create_extent_table(&rfs->bmap, 0); in block_mover()
1697 for (blk = B2C(old_fs->super->s_first_data_block); in block_mover()
1698 blk < ext2fs_blocks_count(old_fs->super); in block_mover()
1699 blk += EXT2FS_CLUSTER_RATIO(fs)) { in block_mover()
1700 if (!ext2fs_test_block_bitmap2(old_fs->block_map, blk)) in block_mover()
1702 if (!ext2fs_test_block_bitmap2(rfs->move_blocks, blk)) in block_mover()
1715 ext2fs_block_alloc_stats2(fs, new_blk, +1); in block_mover()
1716 ext2fs_add_extent_entry(rfs->bmap, B2C(blk), B2C(new_blk)); in block_mover()
1721 if (rfs->bmap) { in block_mover()
1722 ext2fs_free_extent_table(rfs->bmap); in block_mover()
1723 rfs->bmap = 0; in block_mover()
1732 retval = ext2fs_iterate_extent(rfs->bmap, 0, 0, 0); in block_mover()
1735 if (rfs->progress) { in block_mover()
1736 retval = (rfs->progress)(rfs, E2_RSZ_BLOCK_RELOC_PASS, in block_mover()
1742 retval = ext2fs_iterate_extent(rfs->bmap, &old_blk, &new_blk, &size); in block_mover()
1750 if (rfs->flags & RESIZE_DEBUG_BMOVE) in block_mover()
1751 printf("Moving %llu blocks %llu->%llu\n", in block_mover()
1756 if (c > fs->inode_blocks_per_group) in block_mover()
1757 c = fs->inode_blocks_per_group; in block_mover()
1758 retval = io_channel_read_blk64(fs->io, old_blk, c, in block_mover()
1759 rfs->itable_buf); in block_mover()
1761 retval = io_channel_write_blk64(fs->io, new_blk, c, in block_mover()
1762 rfs->itable_buf); in block_mover()
1764 size -= c; in block_mover()
1768 if (rfs->progress) { in block_mover()
1769 io_channel_flush(fs->io); in block_mover()
1770 retval = (rfs->progress)(rfs, in block_mover()
1777 io_channel_flush(fs->io); in block_mover()
1791 /* --------------------------------------------------------------------
1795 * --------------------------------------------------------------------
1804 static __u64 extent_translate(ext2_filsys fs, ext2_extent extent, __u64 old_loc) in extent_translate() argument
1809 new_block += old_loc & (EXT2FS_CLUSTER_RATIO(fs) - 1); in extent_translate()
1824 static int process_block(ext2_filsys fs, blk64_t *block_nr, in process_block() argument
1836 if (pb->rfs->bmap) { in process_block()
1837 new_block = extent_translate(fs, pb->rfs->bmap, block); in process_block()
1841 pb->changed = 1; in process_block()
1843 if (pb->rfs->flags & RESIZE_DEBUG_BMOVE) in process_block()
1844 printf("ino=%u, blockcnt=%lld, %llu->%llu\n", in process_block()
1845 pb->old_ino, blockcnt, block, in process_block()
1852 if (pb->is_dir) { in process_block()
1853 retval = ext2fs_add_dir_block2(fs->dblist, pb->ino, in process_block()
1856 pb->error = retval; in process_block()
1866 static errcode_t progress_callback(ext2_filsys fs, in progress_callback() argument
1880 if (rfs->progress) { in progress_callback()
1881 io_channel_flush(fs->io); in progress_callback()
1882 retval = (rfs->progress)(rfs, E2_RSZ_INODE_SCAN_PASS, in progress_callback()
1883 group+1, fs->group_desc_count); in progress_callback()
1899 if (ext2fs_file_acl_block(rfs->old_fs, inode) == 0 || !rfs->bmap) in migrate_ea_block()
1901 new_block = extent_translate(rfs->old_fs, rfs->bmap, in migrate_ea_block()
1902 ext2fs_file_acl_block(rfs->old_fs, inode)); in migrate_ea_block()
1907 ext2fs_file_acl_block_set(rfs->old_fs, inode, new_block); in migrate_ea_block()
1910 if (ext2fs_has_feature_metadata_csum(rfs->new_fs->super)) { in migrate_ea_block()
1911 err = ext2fs_get_mem(rfs->old_fs->blocksize, &buf); in migrate_ea_block()
1914 rfs->old_fs->flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS; in migrate_ea_block()
1915 err = ext2fs_read_ext_attr3(rfs->old_fs, new_block, buf, ino); in migrate_ea_block()
1916 rfs->old_fs->flags &= ~EXT2_FLAG_IGNORE_CSUM_ERRORS; in migrate_ea_block()
1919 err = ext2fs_write_ext_attr3(rfs->old_fs, new_block, buf, ino); in migrate_ea_block()
1931 static errcode_t rewrite_extents(ext2_filsys fs, ext2_ino_t ino) in rewrite_extents() argument
1938 errcode = ext2fs_extent_open(fs, ino, &handle); in rewrite_extents()
1997 if (entry->e_value_inum > last_ino) { in fix_ea_entries()
1999 entry->e_value_inum); in fix_ea_entries()
2000 entry->e_value_inum = new_ino; in fix_ea_entries()
2015 if (inode->i_extra_isize == 0) in fix_ea_ibody_entries()
2019 inode->i_extra_isize); in fix_ea_ibody_entries()
2058 ext2_filsys fs = rfs->new_fs; in fix_ea_inode_refs() local
2061 int inode_size = EXT2_INODE_SIZE(fs->super); in fix_ea_inode_refs()
2072 retval = ext2fs_open_inode_scan(fs, 0, &scan); in fix_ea_inode_refs()
2084 if (inode->i_links_count == 0 && ino != EXT2_RESIZE_INO) in fix_ea_inode_refs()
2088 modified = fix_ea_ibody_entries(rfs->imap, in fix_ea_inode_refs()
2092 retval = ext2fs_write_inode_full(fs, ino, inode, in fix_ea_inode_refs()
2099 blk = ext2fs_file_acl_block(fs, inode); in fix_ea_inode_refs()
2101 retval = ext2fs_read_ext_attr3(fs, blk, block_buf, ino); in fix_ea_inode_refs()
2105 modified = fix_ea_block_entries(rfs->imap, block_buf, in fix_ea_inode_refs()
2106 fs->blocksize, in fix_ea_inode_refs()
2109 retval = ext2fs_write_ext_attr3(fs, blk, in fix_ea_inode_refs()
2118 if (header->h_refcount > 1) in fix_ea_inode_refs()
2142 if ((rfs->old_fs->group_desc_count <= in inode_scan_and_fix()
2143 rfs->new_fs->group_desc_count) && in inode_scan_and_fix()
2144 !rfs->bmap) in inode_scan_and_fix()
2149 retval = ext2fs_open_inode_scan(rfs->old_fs, 0, &scan); in inode_scan_and_fix()
2152 retval = ext2fs_init_dblist(rfs->old_fs, 0); in inode_scan_and_fix()
2154 retval = ext2fs_get_array(rfs->old_fs->blocksize, 3, &block_buf); in inode_scan_and_fix()
2157 start_to_move = (rfs->new_fs->group_desc_count * in inode_scan_and_fix()
2158 rfs->new_fs->super->s_inodes_per_group); in inode_scan_and_fix()
2160 if (rfs->progress) { in inode_scan_and_fix()
2161 retval = (rfs->progress)(rfs, E2_RSZ_INODE_SCAN_PASS, in inode_scan_and_fix()
2162 0, rfs->old_fs->group_desc_count); in inode_scan_and_fix()
2170 new_inode = EXT2_FIRST_INODE(rfs->new_fs->super); in inode_scan_and_fix()
2171 inode_size = EXT2_INODE_SIZE(rfs->new_fs->super); in inode_scan_and_fix()
2187 if (inode->i_links_count == 0 && ino != EXT2_RESIZE_INO) in inode_scan_and_fix()
2190 pb.is_dir = LINUX_S_ISDIR(inode->i_mode); in inode_scan_and_fix()
2207 retval = ext2fs_new_inode(rfs->new_fs, 0, 0, 0, &new_inode); in inode_scan_and_fix()
2211 ext2fs_inode_alloc_stats2(rfs->new_fs, new_inode, +1, in inode_scan_and_fix()
2217 if (inode->i_flags & EXT4_EA_INODE_FL) in inode_scan_and_fix()
2220 inode->i_ctime = time(0); in inode_scan_and_fix()
2222 retval = ext2fs_write_inode_full(rfs->old_fs, new_inode, in inode_scan_and_fix()
2229 if (rfs->flags & RESIZE_DEBUG_INODEMAP) in inode_scan_and_fix()
2230 printf("Inode moved %u->%u\n", ino, new_inode); in inode_scan_and_fix()
2232 if (!rfs->imap) { in inode_scan_and_fix()
2233 retval = ext2fs_create_extent_table(&rfs->imap, 0); in inode_scan_and_fix()
2237 ext2fs_add_extent_entry(rfs->imap, ino, new_inode); in inode_scan_and_fix()
2241 retval = ext2fs_write_inode_full(rfs->old_fs, in inode_scan_and_fix()
2248 if (ext2fs_has_feature_metadata_csum(rfs->old_fs->super) && in inode_scan_and_fix()
2249 (inode->i_flags & EXT4_EXTENTS_FL)) { in inode_scan_and_fix()
2250 rfs->old_fs->flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS; in inode_scan_and_fix()
2251 retval = rewrite_extents(rfs->old_fs, new_inode); in inode_scan_and_fix()
2252 rfs->old_fs->flags &= ~EXT2_FLAG_IGNORE_CSUM_ERRORS; in inode_scan_and_fix()
2262 if (ext2fs_inode_has_valid_blocks2(rfs->old_fs, inode) && in inode_scan_and_fix()
2263 (rfs->bmap || pb.is_dir)) { in inode_scan_and_fix()
2266 pb.has_extents = inode->i_flags & EXT4_EXTENTS_FL; in inode_scan_and_fix()
2267 rfs->old_fs->flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS; in inode_scan_and_fix()
2268 retval = ext2fs_block_iterate3(rfs->old_fs, in inode_scan_and_fix()
2271 rfs->old_fs->flags &= ~EXT2_FLAG_IGNORE_CSUM_ERRORS; in inode_scan_and_fix()
2278 } else if ((inode->i_flags & EXT4_INLINE_DATA_FL) && in inode_scan_and_fix()
2279 (rfs->bmap || pb.is_dir)) { in inode_scan_and_fix()
2281 retval = ext2fs_add_dir_block2(rfs->old_fs->dblist, in inode_scan_and_fix()
2289 ext2fs_has_feature_ea_inode(rfs->new_fs->super)) { in inode_scan_and_fix()
2295 io_channel_flush(rfs->old_fs->io); in inode_scan_and_fix()
2299 if (rfs->bmap) { in inode_scan_and_fix()
2300 ext2fs_free_extent_table(rfs->bmap); in inode_scan_and_fix()
2301 rfs->bmap = 0; in inode_scan_and_fix()
2311 /* --------------------------------------------------------------------
2315 * --------------------------------------------------------------------
2338 if (is->rfs->progress && offset == 0) { in check_and_change_inodes()
2339 io_channel_flush(is->rfs->old_fs->io); in check_and_change_inodes()
2340 is->err = (is->rfs->progress)(is->rfs, in check_and_change_inodes()
2342 ++is->num, is->max_dirs); in check_and_change_inodes()
2343 if (is->err) in check_and_change_inodes()
2349 * old fs, then we must rewrite all dir blocks with new checksums. in check_and_change_inodes()
2351 if (ext2fs_has_feature_metadata_csum(is->rfs->old_fs->super) && in check_and_change_inodes()
2352 !ext2fs_test_inode_bitmap2(is->rfs->old_fs->inode_map, dir)) in check_and_change_inodes()
2355 if (!dirent->inode) in check_and_change_inodes()
2358 new_inode = ext2fs_extent_translate(is->rfs->imap, dirent->inode); in check_and_change_inodes()
2363 if (is->rfs->flags & RESIZE_DEBUG_INODEMAP) in check_and_change_inodes()
2364 printf("Inode translate (dir=%u, name=%.*s, %u->%u)\n", in check_and_change_inodes()
2365 dir, ext2fs_dirent_name_len(dirent), dirent->name, in check_and_change_inodes()
2366 dirent->inode, new_inode); in check_and_change_inodes()
2369 dirent->inode = new_inode; in check_and_change_inodes()
2372 retval = ext2fs_read_inode(is->rfs->old_fs, dir, &inode); in check_and_change_inodes()
2375 is->err = ext2fs_write_inode(is->rfs->old_fs, dir, &inode); in check_and_change_inodes()
2376 if (is->err) in check_and_change_inodes()
2388 if (!rfs->imap) in inode_ref_fix()
2396 is.max_dirs = ext2fs_dblist_count2(rfs->old_fs->dblist); in inode_ref_fix()
2400 if (rfs->progress) { in inode_ref_fix()
2401 retval = (rfs->progress)(rfs, E2_RSZ_INODE_REF_UPD_PASS, in inode_ref_fix()
2407 rfs->old_fs->flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS; in inode_ref_fix()
2408 retval = ext2fs_dblist_dir_iterate(rfs->old_fs->dblist, in inode_ref_fix()
2411 rfs->old_fs->flags &= ~EXT2_FLAG_IGNORE_CSUM_ERRORS; in inode_ref_fix()
2419 if (rfs->progress && (is.num < is.max_dirs)) in inode_ref_fix()
2420 (rfs->progress)(rfs, E2_RSZ_INODE_REF_UPD_PASS, in inode_ref_fix()
2424 ext2fs_free_extent_table(rfs->imap); in inode_ref_fix()
2425 rfs->imap = 0; in inode_ref_fix()
2430 /* --------------------------------------------------------------------
2440 * --------------------------------------------------------------------
2445 * A very scary routine --- this one moves the inode table around!!!
2447 * After this you have to use the rfs->new_fs file handle to read and
2455 ext2_filsys fs = rfs->new_fs; in move_itables() local
2463 max_groups = fs->group_desc_count; in move_itables()
2464 if (max_groups > rfs->old_fs->group_desc_count) in move_itables()
2465 max_groups = rfs->old_fs->group_desc_count; in move_itables()
2467 size = fs->blocksize * fs->inode_blocks_per_group; in move_itables()
2468 if (!rfs->itable_buf) { in move_itables()
2469 retval = ext2fs_get_mem(size, &rfs->itable_buf); in move_itables()
2474 if (EXT2FS_CLUSTER_RATIO(fs) > 1) { in move_itables()
2475 retval = ext2fs_allocate_block_bitmap(fs, _("new meta blocks"), in move_itables()
2480 retval = mark_table_blocks(fs, new_bmap); in move_itables()
2490 if (ext2fs_inode_table_loc(rfs->old_fs, i) != in move_itables()
2491 ext2fs_inode_table_loc(fs, i)) in move_itables()
2499 if (rfs->progress) { in move_itables()
2500 retval = rfs->progress(rfs, E2_RSZ_MOVE_ITABLE_PASS, in move_itables()
2506 rfs->old_fs->flags |= EXT2_FLAG_MASTER_SB_ONLY; in move_itables()
2509 old_blk = ext2fs_inode_table_loc(rfs->old_fs, i); in move_itables()
2510 new_blk = ext2fs_inode_table_loc(fs, i); in move_itables()
2511 diff = new_blk - old_blk; in move_itables()
2514 if (rfs->flags & RESIZE_DEBUG_ITABLEMOVE) in move_itables()
2515 printf("Itable move group %d block %llu->%llu (diff %lld)\n", in move_itables()
2524 retval = io_channel_read_blk64(fs->io, old_blk, in move_itables()
2525 fs->inode_blocks_per_group, in move_itables()
2526 rfs->itable_buf); in move_itables()
2536 for (cp = rfs->itable_buf+size-1, n=0; n < size; n++, cp--) in move_itables()
2539 n = n >> EXT2_BLOCK_SIZE_BITS(fs->super); in move_itables()
2541 if (rfs->flags & RESIZE_DEBUG_ITABLEMOVE) in move_itables()
2544 num = fs->inode_blocks_per_group; in move_itables()
2546 num -= n; in move_itables()
2548 retval = io_channel_write_blk64(fs->io, new_blk, in move_itables()
2549 num, rfs->itable_buf); in move_itables()
2551 io_channel_write_blk64(fs->io, old_blk, in move_itables()
2552 num, rfs->itable_buf); in move_itables()
2556 retval = io_channel_write_blk64(fs->io, in move_itables()
2557 old_blk + fs->inode_blocks_per_group, in move_itables()
2558 diff, (rfs->itable_buf + in move_itables()
2559 (fs->inode_blocks_per_group - diff) * in move_itables()
2560 fs->blocksize)); in move_itables()
2565 for (blk = ext2fs_inode_table_loc(rfs->old_fs, i), j=0; in move_itables()
2566 j < fs->inode_blocks_per_group;) { in move_itables()
2569 ext2fs_block_alloc_stats2(fs, blk, -1); in move_itables()
2570 cluster_freed = EXT2FS_CLUSTER_RATIO(fs) - in move_itables()
2571 (blk & EXT2FS_CLUSTER_MASK(fs)); in move_itables()
2580 ext2fs_inode_table_loc_set(rfs->old_fs, i, new_blk); in move_itables()
2581 ext2fs_group_desc_csum_set(rfs->old_fs, i); in move_itables()
2582 ext2fs_mark_super_dirty(rfs->old_fs); in move_itables()
2583 ext2fs_flush(rfs->old_fs); in move_itables()
2585 if (rfs->progress) { in move_itables()
2586 retval = rfs->progress(rfs, E2_RSZ_MOVE_ITABLE_PASS, in move_itables()
2592 mark_table_blocks(fs, fs->block_map); in move_itables()
2593 ext2fs_flush(fs); in move_itables()
2595 if (rfs->flags & RESIZE_DEBUG_ITABLEMOVE) in move_itables()
2613 ext2_filsys fs = rfs->new_fs; in clear_sparse_super2_last_group() local
2614 ext2_filsys old_fs = rfs->old_fs; in clear_sparse_super2_last_group()
2616 dgrp_t old_last_bg = rfs->old_fs->group_desc_count - 1; in clear_sparse_super2_last_group()
2617 dgrp_t last_bg = fs->group_desc_count - 1; in clear_sparse_super2_last_group()
2621 if (!ext2fs_has_feature_sparse_super2(fs->super)) in clear_sparse_super2_last_group()
2627 if (fs->super->s_backup_bgs[0] == old_fs->super->s_backup_bgs[0] && in clear_sparse_super2_last_group()
2628 fs->super->s_backup_bgs[1] == old_fs->super->s_backup_bgs[1]) in clear_sparse_super2_last_group()
2631 if (old_fs->super->s_backup_bgs[0] != old_last_bg && in clear_sparse_super2_last_group()
2632 old_fs->super->s_backup_bgs[1] != old_last_bg) in clear_sparse_super2_last_group()
2635 if (fs->super->s_backup_bgs[0] == old_last_bg || in clear_sparse_super2_last_group()
2636 fs->super->s_backup_bgs[1] == old_last_bg) in clear_sparse_super2_last_group()
2642 retval = ext2fs_super_and_bgd_loc2(rfs->old_fs, old_last_bg, in clear_sparse_super2_last_group()
2648 ext2fs_unmark_block_bitmap2(fs->block_map, sb); in clear_sparse_super2_last_group()
2650 ext2fs_unmark_block_bitmap_range2(fs->block_map, old_desc, num); in clear_sparse_super2_last_group()
2658 * Unfortunately, those blocks may be used by other files or fs
2664 ext2_filsys fs = rfs->new_fs; in reserve_sparse_super2_last_group() local
2665 ext2_filsys old_fs = rfs->old_fs; in reserve_sparse_super2_last_group()
2667 dgrp_t old_last_bg = rfs->old_fs->group_desc_count - 1; in reserve_sparse_super2_last_group()
2668 dgrp_t last_bg = fs->group_desc_count - 1; in reserve_sparse_super2_last_group()
2674 if (!ext2fs_has_feature_sparse_super2(fs->super)) in reserve_sparse_super2_last_group()
2680 if (fs->super->s_backup_bgs[0] == old_fs->super->s_backup_bgs[0] && in reserve_sparse_super2_last_group()
2681 fs->super->s_backup_bgs[1] == old_fs->super->s_backup_bgs[1]) in reserve_sparse_super2_last_group()
2684 if (fs->super->s_backup_bgs[0] != last_bg && in reserve_sparse_super2_last_group()
2685 fs->super->s_backup_bgs[1] != last_bg) in reserve_sparse_super2_last_group()
2688 if (old_fs->super->s_backup_bgs[0] == last_bg || in reserve_sparse_super2_last_group()
2689 old_fs->super->s_backup_bgs[1] == last_bg) in reserve_sparse_super2_last_group()
2692 retval = ext2fs_super_and_bgd_loc2(rfs->new_fs, last_bg, in reserve_sparse_super2_last_group()
2711 ext2fs_mark_block_bitmap_range2(fs->block_map, sb, num); in reserve_sparse_super2_last_group()
2713 for (g = 0; g < fs->group_desc_count; g++) { in reserve_sparse_super2_last_group()
2716 mb = ext2fs_block_bitmap_loc(fs, g); in reserve_sparse_super2_last_group()
2718 ext2fs_block_bitmap_loc_set(fs, g, 0); in reserve_sparse_super2_last_group()
2721 mb = ext2fs_inode_bitmap_loc(fs, g); in reserve_sparse_super2_last_group()
2723 ext2fs_inode_bitmap_loc_set(fs, g, 0); in reserve_sparse_super2_last_group()
2726 mb = ext2fs_inode_table_loc(fs, g); in reserve_sparse_super2_last_group()
2728 (sb < mb + fs->inode_blocks_per_group)) { in reserve_sparse_super2_last_group()
2729 ext2fs_inode_table_loc_set(fs, g, 0); in reserve_sparse_super2_last_group()
2733 retval = ext2fs_allocate_group_table(fs, g, 0); in reserve_sparse_super2_last_group()
2740 if (ext2fs_test_block_bitmap2(old_fs->block_map, blk) && in reserve_sparse_super2_last_group()
2742 ext2fs_mark_block_bitmap2(rfs->move_blocks, blk); in reserve_sparse_super2_last_group()
2743 rfs->needed_blocks++; in reserve_sparse_super2_last_group()
2745 ext2fs_mark_block_bitmap2(rfs->reserve_blocks, blk); in reserve_sparse_super2_last_group()
2753 static errcode_t fix_resize_inode(ext2_filsys fs) in fix_resize_inode() argument
2758 if (!ext2fs_has_feature_resize_inode(fs->super)) in fix_resize_inode()
2761 retval = ext2fs_read_inode(fs, EXT2_RESIZE_INO, &inode); in fix_resize_inode()
2764 ext2fs_iblk_set(fs, &inode, 1); in fix_resize_inode()
2766 retval = ext2fs_write_inode(fs, EXT2_RESIZE_INO, &inode); in fix_resize_inode()
2780 retval = ext2fs_zero_blocks2(fs, inode.i_block[EXT2_DIND_BLOCK], 1, in fix_resize_inode()
2785 retval = ext2fs_create_resize_inode(fs); in fix_resize_inode()
2796 static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs) in ext2fs_calculate_summary_stats() argument
2812 uninit = ext2fs_bg_flags_test(fs, group, EXT2_BG_BLOCK_UNINIT); in ext2fs_calculate_summary_stats()
2813 ext2fs_super_and_bgd_loc2(fs, group, &super_blk, &old_desc_blk, in ext2fs_calculate_summary_stats()
2815 if (ext2fs_has_feature_meta_bg(fs->super)) in ext2fs_calculate_summary_stats()
2816 old_desc_blocks = fs->super->s_first_meta_bg; in ext2fs_calculate_summary_stats()
2818 old_desc_blocks = fs->desc_blocks + in ext2fs_calculate_summary_stats()
2819 fs->super->s_reserved_gdt_blocks; in ext2fs_calculate_summary_stats()
2820 for (blk = B2C(fs->super->s_first_data_block); in ext2fs_calculate_summary_stats()
2821 blk < ext2fs_blocks_count(fs->super); in ext2fs_calculate_summary_stats()
2822 blk += EXT2FS_CLUSTER_RATIO(fs)) { in ext2fs_calculate_summary_stats()
2829 EQ_CLSTR(blk, ext2fs_block_bitmap_loc(fs, group)) || in ext2fs_calculate_summary_stats()
2830 EQ_CLSTR(blk, ext2fs_inode_bitmap_loc(fs, group)) || in ext2fs_calculate_summary_stats()
2831 ((GE_CLSTR(blk, ext2fs_inode_table_loc(fs, group)) && in ext2fs_calculate_summary_stats()
2832 LT_CLSTR(blk, ext2fs_inode_table_loc(fs, group) in ext2fs_calculate_summary_stats()
2833 + fs->inode_blocks_per_group))))) || in ext2fs_calculate_summary_stats()
2834 (!ext2fs_fast_test_block_bitmap2(fs->block_map, blk))) { in ext2fs_calculate_summary_stats()
2839 if ((count == fs->super->s_clusters_per_group) || in ext2fs_calculate_summary_stats()
2840 EQ_CLSTR(blk, ext2fs_blocks_count(fs->super)-1)) { in ext2fs_calculate_summary_stats()
2841 ext2fs_bg_free_blocks_count_set(fs, group, group_free); in ext2fs_calculate_summary_stats()
2842 ext2fs_group_desc_csum_set(fs, group); in ext2fs_calculate_summary_stats()
2844 if (group >= fs->group_desc_count) in ext2fs_calculate_summary_stats()
2848 uninit = ext2fs_bg_flags_test(fs, group, EXT2_BG_BLOCK_UNINIT); in ext2fs_calculate_summary_stats()
2849 ext2fs_super_and_bgd_loc2(fs, group, &super_blk, in ext2fs_calculate_summary_stats()
2852 if (ext2fs_has_feature_meta_bg(fs->super)) in ext2fs_calculate_summary_stats()
2853 old_desc_blocks = fs->super->s_first_meta_bg; in ext2fs_calculate_summary_stats()
2855 old_desc_blocks = fs->desc_blocks + in ext2fs_calculate_summary_stats()
2856 fs->super->s_reserved_gdt_blocks; in ext2fs_calculate_summary_stats()
2860 ext2fs_free_blocks_count_set(fs->super, total_blocks_free); in ext2fs_calculate_summary_stats()
2869 /* Protect loop from wrap-around if s_inodes_count maxed */ in ext2fs_calculate_summary_stats()
2870 uninit = ext2fs_bg_flags_test(fs, group, EXT2_BG_INODE_UNINIT); in ext2fs_calculate_summary_stats()
2871 for (ino = 1; ino <= fs->super->s_inodes_count && ino > 0; ino++) { in ext2fs_calculate_summary_stats()
2873 !ext2fs_fast_test_inode_bitmap2(fs->inode_map, ino)) { in ext2fs_calculate_summary_stats()
2878 if ((count == fs->super->s_inodes_per_group) || in ext2fs_calculate_summary_stats()
2879 (ino == fs->super->s_inodes_count)) { in ext2fs_calculate_summary_stats()
2880 ext2fs_bg_free_inodes_count_set(fs, group, group_free); in ext2fs_calculate_summary_stats()
2881 ext2fs_group_desc_csum_set(fs, group); in ext2fs_calculate_summary_stats()
2883 if (group >= fs->group_desc_count) in ext2fs_calculate_summary_stats()
2887 uninit = ext2fs_bg_flags_test(fs, group, EXT2_BG_INODE_UNINIT); in ext2fs_calculate_summary_stats()
2890 fs->super->s_free_inodes_count = total_inodes_free; in ext2fs_calculate_summary_stats()
2891 ext2fs_mark_super_dirty(fs); in ext2fs_calculate_summary_stats()
2899 static errcode_t fix_sb_journal_backup(ext2_filsys fs) in fix_sb_journal_backup() argument
2904 if (!ext2fs_has_feature_journal(fs->super)) in fix_sb_journal_backup()
2908 if (fs->super->s_journal_dev && !fs->super->s_journal_inum) in fix_sb_journal_backup()
2911 retval = ext2fs_read_inode(fs, fs->super->s_journal_inum, &inode); in fix_sb_journal_backup()
2914 memcpy(fs->super->s_jnl_blocks, inode.i_block, EXT2_N_BLOCKS*4); in fix_sb_journal_backup()
2915 fs->super->s_jnl_blocks[15] = inode.i_size_high; in fix_sb_journal_backup()
2916 fs->super->s_jnl_blocks[16] = inode.i_size; in fix_sb_journal_backup()
2917 fs->super->s_jnl_backup_type = EXT3_JNL_BACKUP_BLOCKS; in fix_sb_journal_backup()
2918 ext2fs_mark_super_dirty(fs); in fix_sb_journal_backup()
2922 static int calc_group_overhead(ext2_filsys fs, blk64_t grp, in calc_group_overhead() argument
2929 overhead = fs->inode_blocks_per_group + 2; in calc_group_overhead()
2931 ext2fs_super_and_bgd_loc2(fs, grp, &super_blk, in calc_group_overhead()
2944 * calculate the minimum number of blocks the given fs can be resized to
2946 blk64_t calculate_minimum_resize_size(ext2_filsys fs, int flags) in calculate_minimum_resize_size() argument
2954 int flexbg_size = 1 << fs->super->s_log_groups_per_flex; in calculate_minimum_resize_size()
2960 inode_count = fs->super->s_inodes_count - in calculate_minimum_resize_size()
2961 fs->super->s_free_inodes_count; in calculate_minimum_resize_size()
2963 fs->super->s_inodes_per_group) * in calculate_minimum_resize_size()
2964 (blk64_t) EXT2_BLOCKS_PER_GROUP(fs->super); in calculate_minimum_resize_size()
2966 EXT2_BLOCKS_PER_GROUP(fs->super)); in calculate_minimum_resize_size()
2969 printf("fs has %d inodes, %d groups required.\n", in calculate_minimum_resize_size()
2974 * number of old-style block group descriptor blocks in calculate_minimum_resize_size()
2976 if (ext2fs_has_feature_meta_bg(fs->super)) in calculate_minimum_resize_size()
2977 old_desc_blocks = fs->super->s_first_meta_bg; in calculate_minimum_resize_size()
2979 old_desc_blocks = fs->desc_blocks + in calculate_minimum_resize_size()
2980 fs->super->s_reserved_gdt_blocks; in calculate_minimum_resize_size()
2983 data_needed = ext2fs_blocks_count(fs->super) - in calculate_minimum_resize_size()
2984 ext2fs_free_blocks_count(fs->super); in calculate_minimum_resize_size()
2986 for (grp = 0; grp < fs->group_desc_count; grp++) in calculate_minimum_resize_size()
2987 data_needed -= calc_group_overhead(fs, grp, old_desc_blocks); in calculate_minimum_resize_size()
2990 printf("fs requires %llu data blocks.\n", data_needed); in calculate_minimum_resize_size()
2999 if (ext2fs_has_feature_flex_bg(fs->super)) { in calculate_minimum_resize_size()
3000 dgrp_t remainder = groups & (flexbg_size - 1); in calculate_minimum_resize_size()
3002 flex_groups += flexbg_size - remainder; in calculate_minimum_resize_size()
3003 if (flex_groups > fs->group_desc_count) in calculate_minimum_resize_size()
3004 flex_groups = fs->group_desc_count; in calculate_minimum_resize_size()
3011 data_blocks = EXT2_GROUPS_TO_BLOCKS(fs->super, groups); in calculate_minimum_resize_size()
3014 overhead = calc_group_overhead(fs, grp, old_desc_blocks); in calculate_minimum_resize_size()
3021 if (grp < (groups - 1)) in calculate_minimum_resize_size()
3022 last_start += EXT2_BLOCKS_PER_GROUP(fs->super) - in calculate_minimum_resize_size()
3026 data_blocks -= overhead; in calculate_minimum_resize_size()
3042 blk64_t remainder = blks_needed - data_blocks; in calculate_minimum_resize_size()
3047 EXT2_BLOCKS_PER_GROUP(fs->super)); in calculate_minimum_resize_size()
3049 data_blocks += EXT2_GROUPS_TO_BLOCKS(fs->super, extra_grps); in calculate_minimum_resize_size()
3052 overhead = calc_group_overhead(fs, groups-1, old_desc_blocks); in calculate_minimum_resize_size()
3053 last_start += EXT2_BLOCKS_PER_GROUP(fs->super) - overhead; in calculate_minimum_resize_size()
3057 if (!ext2fs_has_feature_flex_bg(fs->super)) in calculate_minimum_resize_size()
3060 dgrp_t r = groups & (flexbg_size - 1); in calculate_minimum_resize_size()
3062 flex_groups = groups + flexbg_size - r; in calculate_minimum_resize_size()
3063 if (flex_groups > fs->group_desc_count) in calculate_minimum_resize_size()
3064 flex_groups = fs->group_desc_count; in calculate_minimum_resize_size()
3068 overhead = calc_group_overhead(fs, grp, in calculate_minimum_resize_size()
3075 if (grp < groups - 1) in calculate_minimum_resize_size()
3076 last_start += EXT2_BLOCKS_PER_GROUP(fs->super) in calculate_minimum_resize_size()
3077 - overhead; in calculate_minimum_resize_size()
3079 data_blocks -= overhead; in calculate_minimum_resize_size()
3092 grp = groups - 1; in calculate_minimum_resize_size()
3093 if (ext2fs_has_feature_flex_bg(fs->super) && in calculate_minimum_resize_size()
3094 (grp & ~(flexbg_size - 1)) == 0) in calculate_minimum_resize_size()
3095 grp = grp & ~(flexbg_size - 1); in calculate_minimum_resize_size()
3098 overhead += calc_group_overhead(fs, grp, old_desc_blocks); in calculate_minimum_resize_size()
3110 blk64_t remainder = blks_needed - last_start; in calculate_minimum_resize_size()
3119 * even worth making/resizing the fs. basically you need to in calculate_minimum_resize_size()
3130 overhead += fs->super->s_first_data_block; in calculate_minimum_resize_size()
3137 if (EXT2FS_CLUSTER_RATIO(fs) > 1) in calculate_minimum_resize_size()
3138 overhead += EXT2FS_CLUSTER_RATIO(fs) * 2; in calculate_minimum_resize_size()
3142 * large, we only do groups-1, and then add the number of in calculate_minimum_resize_size()
3146 blks_needed = EXT2_GROUPS_TO_BLOCKS(fs->super, groups - 1); in calculate_minimum_resize_size()
3153 overhead = ext2fs_inode_table_loc(fs, groups-1) + in calculate_minimum_resize_size()
3154 fs->inode_blocks_per_group; in calculate_minimum_resize_size()
3167 if (blks_needed >= ext2fs_blocks_count(fs->super)) in calculate_minimum_resize_size()
3168 return ext2fs_blocks_count(fs->super); in calculate_minimum_resize_size()
3179 if (ext2fs_has_feature_extents(fs->super)) { in calculate_minimum_resize_size()
3180 blk64_t safe_margin = (ext2fs_blocks_count(fs->super) - in calculate_minimum_resize_size()
3182 unsigned int exts_per_blk = (fs->blocksize / in calculate_minimum_resize_size()
3183 sizeof(struct ext3_extent)) - 1; in calculate_minimum_resize_size()
3184 blk64_t worst_case = ((data_needed + exts_per_blk - 1) / in calculate_minimum_resize_size()