Home | History | Annotate | Download | only in resize

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