Lines Matching refs:rfs

44 static errcode_t adjust_superblock(ext2_resize_t rfs, blk64_t new_size);
45 static errcode_t blocks_to_move(ext2_resize_t rfs);
46 static errcode_t block_mover(ext2_resize_t rfs);
47 static errcode_t inode_scan_and_fix(ext2_resize_t rfs);
48 static errcode_t inode_ref_fix(ext2_resize_t rfs);
49 static errcode_t move_itables(ext2_resize_t rfs);
81 errcode_t (*progress)(ext2_resize_t rfs, int pass, in resize_fs() argument
85 ext2_resize_t rfs; in resize_fs() local
92 retval = ext2fs_get_mem(sizeof(struct ext2_resize_struct), &rfs); in resize_fs()
96 memset(rfs, 0, sizeof(struct ext2_resize_struct)); in resize_fs()
97 fs->priv_data = rfs; in resize_fs()
98 rfs->old_fs = fs; in resize_fs()
99 rfs->flags = flags; in resize_fs()
100 rfs->itable_buf = 0; in resize_fs()
101 rfs->progress = progress; in resize_fs()
108 print_resource_track(rfs, &rtrack, fs->io); 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()
122 retval = adjust_superblock(rfs, *new_size); in resize_fs()
125 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
129 fix_uninit_block_bitmaps(rfs->new_fs); in resize_fs()
130 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
132 ext2fs_bg_flags_clear(rfs->new_fs, rfs->new_fs->group_desc_count - 1, in resize_fs()
135 *new_size = ext2fs_blocks_count(rfs->new_fs->super); in resize_fs()
138 retval = blocks_to_move(rfs); in resize_fs()
141 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
144 if (rfs->flags & RESIZE_DEBUG_BMOVE) in resize_fs()
146 ext2fs_free_blocks_count(rfs->old_fs->super), in resize_fs()
147 ext2fs_free_blocks_count(rfs->new_fs->super), in resize_fs()
148 rfs->needed_blocks); in resize_fs()
152 retval = block_mover(rfs); in resize_fs()
155 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
158 retval = inode_scan_and_fix(rfs); in resize_fs()
161 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
164 retval = inode_ref_fix(rfs); in resize_fs()
167 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
170 retval = move_itables(rfs); in resize_fs()
173 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
176 retval = ext2fs_calculate_summary_stats(rfs->new_fs); in resize_fs()
179 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
182 retval = fix_resize_inode(rfs->new_fs); in resize_fs()
185 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
188 retval = fix_sb_journal_backup(rfs->new_fs); in resize_fs()
191 print_resource_track(rfs, &rtrack, fs->io); in resize_fs()
193 rfs->new_fs->super->s_state &= ~EXT2_ERROR_FS; in resize_fs()
194 rfs->new_fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY; in resize_fs()
196 print_resource_track(rfs, &overall_track, fs->io); in resize_fs()
197 retval = ext2fs_close(rfs->new_fs); in resize_fs()
201 rfs->flags = flags; in resize_fs()
203 ext2fs_free(rfs->old_fs); in resize_fs()
204 if (rfs->itable_buf) in resize_fs()
205 ext2fs_free_mem(&rfs->itable_buf); in resize_fs()
206 if (rfs->reserve_blocks) in resize_fs()
207 ext2fs_free_block_bitmap(rfs->reserve_blocks); in resize_fs()
208 if (rfs->move_blocks) in resize_fs()
209 ext2fs_free_block_bitmap(rfs->move_blocks); in resize_fs()
210 ext2fs_free_mem(&rfs); in resize_fs()
215 if (rfs->new_fs) in resize_fs()
216 ext2fs_free(rfs->new_fs); in resize_fs()
217 if (rfs->itable_buf) in resize_fs()
218 ext2fs_free_mem(&rfs->itable_buf); in resize_fs()
219 ext2fs_free_mem(&rfs); in resize_fs()
615 static errcode_t adjust_superblock(ext2_resize_t rfs, blk64_t new_size) in adjust_superblock() argument
624 fs = rfs->new_fs; in adjust_superblock()
630 &rfs->reserve_blocks); in adjust_superblock()
634 retval = adjust_fs_info(fs, rfs->old_fs, rfs->reserve_blocks, new_size); in adjust_superblock()
641 if ((rfs->old_fs->super->s_inodes_count - in adjust_superblock()
642 rfs->old_fs->super->s_free_inodes_count) > in adjust_superblock()
643 rfs->new_fs->super->s_inodes_count) { 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()
683 &rfs->itable_buf); in adjust_superblock()
687 memset(rfs->itable_buf, 0, fs->blocksize * fs->inode_blocks_per_group); in adjust_superblock()
689 rfs->old_fs->group_desc_count); in adjust_superblock()
690 adj = rfs->old_fs->group_desc_count; in adjust_superblock()
692 if (rfs->progress) { in adjust_superblock()
693 retval = rfs->progress(rfs, E2_RSZ_EXTEND_ITABLE_PASS, in adjust_superblock()
698 for (i = rfs->old_fs->group_desc_count; in adjust_superblock()
706 rfs->itable_buf); in adjust_superblock()
710 if (rfs->progress) { in adjust_superblock()
711 retval = rfs->progress(rfs, E2_RSZ_EXTEND_ITABLE_PASS, in adjust_superblock()
780 static void mark_fs_metablock(ext2_resize_t rfs, in mark_fs_metablock() argument
784 ext2_filsys fs = rfs->new_fs; in mark_fs_metablock()
786 ext2fs_mark_block_bitmap2(rfs->reserve_blocks, blk); in mark_fs_metablock()
796 rfs->needed_blocks++; in mark_fs_metablock()
801 rfs->needed_blocks++; in mark_fs_metablock()
806 rfs->needed_blocks++; in mark_fs_metablock()
812 for (i=0; i < rfs->old_fs->group_desc_count; i++) { in mark_fs_metablock()
815 rfs->needed_blocks++; in mark_fs_metablock()
820 rfs->needed_blocks++; in mark_fs_metablock()
825 rfs->needed_blocks++; in mark_fs_metablock()
838 } else if (ext2fs_test_block_bitmap2(rfs->old_fs->block_map, blk) && in mark_fs_metablock()
840 ext2fs_mark_block_bitmap2(rfs->move_blocks, blk); in mark_fs_metablock()
841 rfs->needed_blocks++; in mark_fs_metablock()
851 static errcode_t blocks_to_move(ext2_resize_t rfs) in blocks_to_move() argument
864 fs = rfs->new_fs; in blocks_to_move()
865 old_fs = rfs->old_fs; in blocks_to_move()
867 fs = rfs->old_fs; in blocks_to_move()
870 &rfs->move_blocks); in blocks_to_move()
883 fs = rfs->new_fs; in blocks_to_move()
940 ext2fs_mark_block_bitmap2(rfs->move_blocks, blk); in blocks_to_move()
941 rfs->needed_blocks++; in blocks_to_move()
943 ext2fs_mark_block_bitmap2(rfs->reserve_blocks, blk); in blocks_to_move()
977 rfs->needed_blocks--; in blocks_to_move()
995 mark_fs_metablock(rfs, meta_bmap, i, group_blk); in blocks_to_move()
1004 mark_fs_metablock(rfs, meta_bmap, in blocks_to_move()
1013 mark_fs_metablock(rfs, meta_bmap, i, in blocks_to_move()
1028 ext2fs_mark_block_bitmap2(rfs->reserve_blocks, in blocks_to_move()
1031 ext2fs_mark_block_bitmap2(rfs->reserve_blocks, in blocks_to_move()
1035 ext2fs_mark_block_bitmap2(rfs->reserve_blocks, in blocks_to_move()
1038 ext2fs_mark_block_bitmap2(rfs->reserve_blocks, in blocks_to_move()
1042 ext2fs_mark_block_bitmap_range2(rfs->reserve_blocks, in blocks_to_move()
1046 ext2fs_mark_block_bitmap_range2(rfs->reserve_blocks, in blocks_to_move()
1050 group_blk += rfs->new_fs->super->s_blocks_per_group; in blocks_to_move()
1061 rfs->reserve_blocks); in blocks_to_move()
1074 ext2fs_mark_block_bitmap2(rfs->move_blocks, in blocks_to_move()
1082 ext2fs_mark_block_bitmap2(rfs->move_blocks, in blocks_to_move()
1096 rfs->needed_blocks += fs->inode_blocks_per_group; in blocks_to_move()
1108 ext2fs_mark_block_bitmap2(rfs->move_blocks, in blocks_to_move()
1116 for (blk = ext2fs_inode_table_loc(rfs->old_fs, i), j=0; in blocks_to_move()
1118 ext2fs_mark_block_bitmap2(rfs->reserve_blocks, blk); in blocks_to_move()
1146 static void init_block_alloc(ext2_resize_t rfs) in init_block_alloc() argument
1148 rfs->alloc_state = AVOID_OLD; in init_block_alloc()
1149 rfs->new_blk = rfs->new_fs->super->s_first_data_block; in init_block_alloc()
1152 if (ext2fs_blocks_count(rfs->new_fs->super) > in init_block_alloc()
1153 ext2fs_blocks_count(rfs->old_fs->super)) in init_block_alloc()
1154 rfs->new_blk = ext2fs_blocks_count(rfs->old_fs->super); in init_block_alloc()
1158 static blk64_t get_new_block(ext2_resize_t rfs) in get_new_block() argument
1160 ext2_filsys fs = rfs->new_fs; in get_new_block()
1163 if (rfs->new_blk >= ext2fs_blocks_count(fs->super)) { in get_new_block()
1164 if (rfs->alloc_state == DESPERATION) in get_new_block()
1168 if (rfs->flags & RESIZE_DEBUG_BMOVE) in get_new_block()
1172 rfs->alloc_state = DESPERATION; 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()
1177 ext2fs_test_block_bitmap2(rfs->reserve_blocks, in get_new_block()
1178 rfs->new_blk) || in get_new_block()
1179 ((rfs->alloc_state == AVOID_OLD) && in get_new_block()
1180 (rfs->new_blk < ext2fs_blocks_count(rfs->old_fs->super)) && in get_new_block()
1181 ext2fs_test_block_bitmap2(rfs->old_fs->block_map, in get_new_block()
1182 rfs->new_blk))) { in get_new_block()
1183 rfs->new_blk++; in get_new_block()
1186 return rfs->new_blk; in get_new_block()
1193 ext2_resize_t rfs = (ext2_resize_t) fs->priv_data; in resize2fs_get_alloc_block() local
1196 blk = get_new_block(rfs); in resize2fs_get_alloc_block()
1201 if (rfs->flags & 0xF) in resize2fs_get_alloc_block()
1205 ext2fs_mark_block_bitmap2(rfs->old_fs->block_map, blk); in resize2fs_get_alloc_block()
1206 ext2fs_mark_block_bitmap2(rfs->new_fs->block_map, blk); in resize2fs_get_alloc_block()
1211 static errcode_t block_mover(ext2_resize_t rfs) in block_mover() argument
1214 ext2_filsys fs = rfs->new_fs; in block_mover()
1215 ext2_filsys old_fs = rfs->old_fs; in block_mover()
1231 if (!rfs->itable_buf) { in block_mover()
1234 &rfs->itable_buf); in block_mover()
1238 retval = ext2fs_create_extent_table(&rfs->bmap, 0); in block_mover()
1247 init_block_alloc(rfs); in block_mover()
1253 if (!ext2fs_test_block_bitmap2(rfs->move_blocks, blk)) in block_mover()
1261 new_blk = get_new_block(rfs); in block_mover()
1267 ext2fs_add_extent_entry(rfs->bmap, B2C(blk), B2C(new_blk)); in block_mover()
1272 if (rfs->bmap) { in block_mover()
1273 ext2fs_free_extent_table(rfs->bmap); in block_mover()
1274 rfs->bmap = 0; in block_mover()
1283 retval = ext2fs_iterate_extent(rfs->bmap, 0, 0, 0); in block_mover()
1286 if (rfs->progress) { in block_mover()
1287 retval = (rfs->progress)(rfs, E2_RSZ_BLOCK_RELOC_PASS, in block_mover()
1293 retval = ext2fs_iterate_extent(rfs->bmap, &old_blk, &new_blk, &size); in block_mover()
1301 if (rfs->flags & RESIZE_DEBUG_BMOVE) in block_mover()
1310 rfs->itable_buf); in block_mover()
1313 rfs->itable_buf); in block_mover()
1319 if (rfs->progress) { in block_mover()
1321 retval = (rfs->progress)(rfs, in block_mover()
1365 ext2_resize_t rfs; member
1385 if (pb->rfs->bmap) { in process_block()
1386 new_block = extent_translate(fs, pb->rfs->bmap, block); in process_block()
1392 if (pb->rfs->flags & RESIZE_DEBUG_BMOVE) in process_block()
1417 ext2_resize_t rfs = (ext2_resize_t) priv_data; in progress_callback() local
1427 if (rfs->progress) { in progress_callback()
1429 retval = (rfs->progress)(rfs, E2_RSZ_INODE_SCAN_PASS, in progress_callback()
1438 static errcode_t inode_scan_and_fix(ext2_resize_t rfs) in inode_scan_and_fix() argument
1451 if ((rfs->old_fs->group_desc_count <= in inode_scan_and_fix()
1452 rfs->new_fs->group_desc_count) && in inode_scan_and_fix()
1453 !rfs->bmap) in inode_scan_and_fix()
1462 orig_size = ext2fs_blocks_count(rfs->old_fs->super); in inode_scan_and_fix()
1463 if (orig_size < ext2fs_blocks_count(rfs->new_fs->super)) in inode_scan_and_fix()
1464 ext2fs_blocks_count_set(rfs->old_fs->super, in inode_scan_and_fix()
1465 ext2fs_blocks_count(rfs->new_fs->super)); in inode_scan_and_fix()
1467 retval = ext2fs_open_inode_scan(rfs->old_fs, 0, &scan); in inode_scan_and_fix()
1470 retval = ext2fs_init_dblist(rfs->old_fs, 0); in inode_scan_and_fix()
1472 retval = ext2fs_get_array(rfs->old_fs->blocksize, 3, &block_buf); in inode_scan_and_fix()
1475 start_to_move = (rfs->new_fs->group_desc_count * in inode_scan_and_fix()
1476 rfs->new_fs->super->s_inodes_per_group); in inode_scan_and_fix()
1478 if (rfs->progress) { in inode_scan_and_fix()
1479 retval = (rfs->progress)(rfs, E2_RSZ_INODE_SCAN_PASS, in inode_scan_and_fix()
1480 0, rfs->old_fs->group_desc_count); in inode_scan_and_fix()
1484 ext2fs_set_inode_callback(scan, progress_callback, (void *) rfs); in inode_scan_and_fix()
1485 pb.rfs = rfs; in inode_scan_and_fix()
1488 new_inode = EXT2_FIRST_INODE(rfs->new_fs->super); in inode_scan_and_fix()
1489 inode_size = EXT2_INODE_SIZE(rfs->new_fs->super); in inode_scan_and_fix()
1511 if (ext2fs_file_acl_block(rfs->old_fs, inode) && rfs->bmap) { in inode_scan_and_fix()
1512 new_block = extent_translate(rfs->old_fs, rfs->bmap, in inode_scan_and_fix()
1513 ext2fs_file_acl_block(rfs->old_fs, inode)); in inode_scan_and_fix()
1515 ext2fs_file_acl_block_set(rfs->old_fs, inode, in inode_scan_and_fix()
1517 retval = ext2fs_write_inode_full(rfs->old_fs, in inode_scan_and_fix()
1523 if (ext2fs_inode_has_valid_blocks2(rfs->old_fs, inode) && in inode_scan_and_fix()
1524 (rfs->bmap || pb.is_dir)) { in inode_scan_and_fix()
1526 retval = ext2fs_block_iterate3(rfs->old_fs, in inode_scan_and_fix()
1543 retval = ext2fs_new_inode(rfs->new_fs, 0, 0, 0, &new_inode); in inode_scan_and_fix()
1547 ext2fs_inode_alloc_stats2(rfs->new_fs, new_inode, +1, in inode_scan_and_fix()
1551 retval = ext2fs_read_inode_full(rfs->old_fs, ino, in inode_scan_and_fix()
1556 retval = ext2fs_write_inode_full(rfs->old_fs, new_inode, in inode_scan_and_fix()
1561 if (rfs->flags & RESIZE_DEBUG_INODEMAP) in inode_scan_and_fix()
1564 if (!rfs->imap) { in inode_scan_and_fix()
1565 retval = ext2fs_create_extent_table(&rfs->imap, 0); in inode_scan_and_fix()
1569 ext2fs_add_extent_entry(rfs->imap, ino, new_inode); in inode_scan_and_fix()
1571 io_channel_flush(rfs->old_fs->io); in inode_scan_and_fix()
1574 ext2fs_blocks_count_set(rfs->old_fs->super, orig_size); in inode_scan_and_fix()
1575 if (rfs->bmap) { in inode_scan_and_fix()
1576 ext2fs_free_extent_table(rfs->bmap); in inode_scan_and_fix()
1577 rfs->bmap = 0; in inode_scan_and_fix()
1595 ext2_resize_t rfs; member
1613 if (is->rfs->progress && offset == 0) { in check_and_change_inodes()
1614 io_channel_flush(is->rfs->old_fs->io); in check_and_change_inodes()
1615 is->err = (is->rfs->progress)(is->rfs, in check_and_change_inodes()
1625 new_inode = ext2fs_extent_translate(is->rfs->imap, dirent->inode); in check_and_change_inodes()
1630 if (is->rfs->flags & RESIZE_DEBUG_INODEMAP) in check_and_change_inodes()
1639 retval = ext2fs_read_inode(is->rfs->old_fs, dir, &inode); in check_and_change_inodes()
1642 is->err = ext2fs_write_inode(is->rfs->old_fs, dir, &inode); in check_and_change_inodes()
1650 static errcode_t inode_ref_fix(ext2_resize_t rfs) in inode_ref_fix() argument
1655 if (!rfs->imap) in inode_ref_fix()
1663 is.max_dirs = ext2fs_dblist_count2(rfs->old_fs->dblist); in inode_ref_fix()
1664 is.rfs = rfs; in inode_ref_fix()
1667 if (rfs->progress) { in inode_ref_fix()
1668 retval = (rfs->progress)(rfs, E2_RSZ_INODE_REF_UPD_PASS, in inode_ref_fix()
1674 retval = ext2fs_dblist_dir_iterate(rfs->old_fs->dblist, in inode_ref_fix()
1684 if (rfs->progress && (is.num < is.max_dirs)) in inode_ref_fix()
1685 (rfs->progress)(rfs, E2_RSZ_INODE_REF_UPD_PASS, in inode_ref_fix()
1689 ext2fs_free_extent_table(rfs->imap); in inode_ref_fix()
1690 rfs->imap = 0; in inode_ref_fix()
1715 static errcode_t move_itables(ext2_resize_t rfs) in move_itables() argument
1720 ext2_filsys fs = rfs->new_fs; in move_itables()
1727 if (max_groups > rfs->old_fs->group_desc_count) in move_itables()
1728 max_groups = rfs->old_fs->group_desc_count; in move_itables()
1731 if (!rfs->itable_buf) { in move_itables()
1732 retval = ext2fs_get_mem(size, &rfs->itable_buf); in move_itables()
1742 if (ext2fs_inode_table_loc(rfs->old_fs, i) != in move_itables()
1749 if (rfs->progress) { in move_itables()
1750 retval = rfs->progress(rfs, E2_RSZ_MOVE_ITABLE_PASS, in move_itables()
1756 rfs->old_fs->flags |= EXT2_FLAG_MASTER_SB_ONLY; in move_itables()
1759 old_blk = ext2fs_inode_table_loc(rfs->old_fs, i); in move_itables()
1764 if (rfs->flags & RESIZE_DEBUG_ITABLEMOVE) in move_itables()
1774 rfs->itable_buf); in move_itables()
1784 for (cp = rfs->itable_buf+size-1, n=0; n < size; n++, cp--) in move_itables()
1789 if (rfs->flags & RESIZE_DEBUG_ITABLEMOVE) in move_itables()
1797 num, rfs->itable_buf); in move_itables()
1800 num, rfs->itable_buf); in move_itables()
1806 diff, (rfs->itable_buf + in move_itables()
1813 for (blk = ext2fs_inode_table_loc(rfs->old_fs, i), j=0; in move_itables()
1817 ext2fs_inode_table_loc_set(rfs->old_fs, i, new_blk); in move_itables()
1818 ext2fs_group_desc_csum_set(rfs->old_fs, i); in move_itables()
1819 ext2fs_mark_super_dirty(rfs->old_fs); in move_itables()
1820 ext2fs_flush(rfs->old_fs); in move_itables()
1822 if (rfs->progress) { in move_itables()
1823 retval = rfs->progress(rfs, E2_RSZ_MOVE_ITABLE_PASS, in move_itables()
1832 if (rfs->flags & RESIZE_DEBUG_ITABLEMOVE) in move_itables()