Lines Matching defs:rfs
44 static errcode_t adjust_superblock(ext2_resize_t rfs, blk_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);
76 errcode_t (*progress)(ext2_resize_t rfs, int pass,
80 ext2_resize_t rfs;
94 retval = ext2fs_get_mem(sizeof(struct ext2_resize_struct), &rfs);
97 memset(rfs, 0, sizeof(struct ext2_resize_struct));
100 fs->priv_data = rfs;
101 rfs->old_fs = fs;
102 rfs->flags = flags;
103 rfs->itable_buf = 0;
104 rfs->progress = progress;
105 retval = ext2fs_dup_handle(fs, &rfs->new_fs);
109 retval = adjust_superblock(rfs, *new_size);
113 fix_uninit_block_bitmaps(rfs->new_fs);
115 rfs->new_fs->group_desc[rfs->new_fs->group_desc_count-1].bg_flags &=
118 *new_size = rfs->new_fs->super->s_blocks_count;
120 retval = blocks_to_move(rfs);
125 if (rfs->flags & RESIZE_DEBUG_BMOVE)
127 rfs->old_fs->super->s_free_blocks_count,
128 rfs->new_fs->super->s_free_blocks_count,
129 rfs->needed_blocks);
132 retval = block_mover(rfs);
136 retval = inode_scan_and_fix(rfs);
140 retval = inode_ref_fix(rfs);
144 retval = move_itables(rfs);
148 retval = ext2fs_calculate_summary_stats(rfs->new_fs);
152 retval = fix_resize_inode(rfs->new_fs);
156 retval = fix_sb_journal_backup(rfs->new_fs);
160 rfs->new_fs->super->s_state &= ~EXT2_ERROR_FS;
161 rfs->new_fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
162 retval = ext2fs_close(rfs->new_fs);
166 rfs->flags = flags;
168 ext2fs_free(rfs->old_fs);
169 if (rfs->itable_buf)
170 ext2fs_free_mem(&rfs->itable_buf);
171 if (rfs->reserve_blocks)
172 ext2fs_free_block_bitmap(rfs->reserve_blocks);
173 if (rfs->move_blocks)
174 ext2fs_free_block_bitmap(rfs->move_blocks);
175 ext2fs_free_mem(&rfs);
180 if (rfs->new_fs)
181 ext2fs_free(rfs->new_fs);
182 if (rfs->itable_buf)
183 ext2fs_free_mem(&rfs->itable_buf);
184 ext2fs_free_mem(&rfs);
568 static errcode_t adjust_superblock(ext2_resize_t rfs, blk_t new_size)
577 fs = rfs->new_fs;
583 &rfs->reserve_blocks);
587 retval = adjust_fs_info(fs, rfs->old_fs, rfs->reserve_blocks, new_size);
594 if ((rfs->old_fs->super->s_inodes_count -
595 rfs->old_fs->super->s_free_inodes_count) >
596 rfs->new_fs->super->s_inodes_count) {
605 if (rfs->old_fs->group_desc_count > fs->group_desc_count) {
615 if (rfs->old_fs->group_desc_count >= fs->group_desc_count) {
624 &rfs->itable_buf);
628 memset(rfs->itable_buf, 0, fs->blocksize * fs->inode_blocks_per_group);
630 rfs->old_fs->group_desc_count * fs->super->s_blocks_per_group;
632 adj = rfs->old_fs->group_desc_count;
634 if (rfs->progress) {
635 retval = rfs->progress(rfs, E2_RSZ_EXTEND_ITABLE_PASS,
640 for (i = rfs->old_fs->group_desc_count;
648 rfs->itable_buf);
652 if (rfs->progress) {
653 retval = rfs->progress(rfs, E2_RSZ_EXTEND_ITABLE_PASS,
729 static void mark_fs_metablock(ext2_resize_t rfs,
733 ext2_filsys fs = rfs->new_fs;
735 ext2fs_mark_block_bitmap(rfs->reserve_blocks, blk);
745 rfs->needed_blocks++;
748 rfs->needed_blocks++;
751 rfs->needed_blocks++;
760 } else if (ext2fs_test_block_bitmap(rfs->old_fs->block_map, blk) &&
762 ext2fs_mark_block_bitmap(rfs->move_blocks, blk);
763 rfs->needed_blocks++;
773 static errcode_t blocks_to_move(ext2_resize_t rfs)
785 fs = rfs->new_fs;
786 old_fs = rfs->old_fs;
788 fs = rfs->old_fs;
791 &rfs->move_blocks);
804 fs = rfs->new_fs;
826 ext2fs_mark_block_bitmap(rfs->move_blocks, blk);
827 rfs->needed_blocks++;
829 ext2fs_mark_block_bitmap(rfs->reserve_blocks, blk);
863 rfs->needed_blocks--;
878 mark_fs_metablock(rfs, meta_bmap, i, group_blk);
887 mark_fs_metablock(rfs, meta_bmap,
896 mark_fs_metablock(rfs, meta_bmap, i,
910 ext2fs_mark_block_bitmap(rfs->reserve_blocks,
913 ext2fs_mark_block_bitmap(rfs->reserve_blocks,
918 ext2fs_mark_block_bitmap(rfs->reserve_blocks,
928 * location. However, passing rfs->reserve_blocks
944 rfs->reserve_blocks);
958 ext2fs_mark_block_bitmap(rfs->move_blocks,
966 ext2fs_mark_block_bitmap(rfs->move_blocks,
980 rfs->needed_blocks += fs->inode_blocks_per_group;
992 ext2fs_mark_block_bitmap(rfs->move_blocks,
1000 for (blk = rfs->old_fs->group_desc[i].bg_inode_table, j=0;
1002 ext2fs_mark_block_bitmap(rfs->reserve_blocks, blk);
1005 group_blk += rfs->new_fs->super->s_blocks_per_group;
1033 static void init_block_alloc(ext2_resize_t rfs)
1035 rfs->alloc_state = AVOID_OLD;
1036 rfs->new_blk = rfs->new_fs->super->s_first_data_block;
1039 if (rfs->new_fs->super->s_blocks_count >
1040 rfs->old_fs->super->s_blocks_count)
1041 rfs->new_blk = rfs->old_fs->super->s_blocks_count;
1045 static blk_t get_new_block(ext2_resize_t rfs)
1047 ext2_filsys fs = rfs->new_fs;
1050 if (rfs->new_blk >= fs->super->s_blocks_count) {
1051 if (rfs->alloc_state == DESPERATION)
1055 if (rfs->flags & RESIZE_DEBUG_BMOVE)
1059 rfs->alloc_state = DESPERATION;
1060 rfs->new_blk = fs->super->s_first_data_block;
1063 if (ext2fs_test_block_bitmap(fs->block_map, rfs->new_blk) ||
1064 ext2fs_test_block_bitmap(rfs->reserve_blocks,
1065 rfs->new_blk) ||
1066 ((rfs->alloc_state == AVOID_OLD) &&
1067 (rfs->new_blk < rfs->old_fs->super->s_blocks_count) &&
1068 ext2fs_test_block_bitmap(rfs->old_fs->block_map,
1069 rfs->new_blk))) {
1070 rfs->new_blk++;
1073 return rfs->new_blk;
1080 ext2_resize_t rfs = (ext2_resize_t) fs->priv_data;
1083 blk = get_new_block(rfs);
1088 if (rfs->flags & 0xF)
1092 ext2fs_mark_block_bitmap(rfs->old_fs->block_map, blk);
1093 ext2fs_mark_block_bitmap(rfs->new_fs->block_map, blk);
1098 static errcode_t block_mover(ext2_resize_t rfs)
1101 ext2_filsys fs = rfs->new_fs;
1102 ext2_filsys old_fs = rfs->old_fs;
1117 if (!rfs->itable_buf) {
1120 &rfs->itable_buf);
1124 retval = ext2fs_create_extent_table(&rfs->bmap, 0);
1133 init_block_alloc(rfs);
1138 if (!ext2fs_test_block_bitmap(rfs->move_blocks, blk))
1146 new_blk = get_new_block(rfs);
1152 ext2fs_add_extent_entry(rfs->bmap, blk, new_blk);
1157 if (rfs->bmap) {
1158 ext2fs_free_extent_table(rfs->bmap);
1159 rfs->bmap = 0;
1168 retval = ext2fs_iterate_extent(rfs->bmap, 0, 0, 0);
1171 if (rfs->progress) {
1172 retval = (rfs->progress)(rfs, E2_RSZ_BLOCK_RELOC_PASS,
1178 retval = ext2fs_iterate_extent(rfs->bmap, &old_blk, &new_blk, &size);
1183 if (rfs->flags & RESIZE_DEBUG_BMOVE)
1192 rfs->itable_buf);
1195 rfs->itable_buf);
1201 if (rfs->progress) {
1203 retval = (rfs->progress)(rfs,
1233 ext2_resize_t rfs;
1253 if (pb->rfs->bmap) {
1254 new_block = ext2fs_extent_translate(pb->rfs->bmap, block);
1260 if (pb->rfs->flags & RESIZE_DEBUG_BMOVE)
1285 ext2_resize_t rfs = (ext2_resize_t) priv_data;
1295 if (rfs->progress) {
1297 retval = (rfs->progress)(rfs, E2_RSZ_INODE_SCAN_PASS,
1306 static errcode_t inode_scan_and_fix(ext2_resize_t rfs)
1318 if ((rfs->old_fs->group_desc_count <=
1319 rfs->new_fs->group_desc_count) &&
1320 !rfs->bmap)
1329 orig_size = rfs->old_fs->super->s_blocks_count;
1330 if (orig_size < rfs->new_fs->super->s_blocks_count)
1331 rfs->old_fs->super->s_blocks_count =
1332 rfs->new_fs->super->s_blocks_count;
1334 retval = ext2fs_open_inode_scan(rfs->old_fs, 0, &scan);
1337 retval = ext2fs_init_dblist(rfs->old_fs, 0);
1339 retval = ext2fs_get_array(rfs->old_fs->blocksize, 3, &block_buf);
1342 start_to_move = (rfs->new_fs->group_desc_count *
1343 rfs->new_fs->super->s_inodes_per_group);
1345 if (rfs->progress) {
1346 retval = (rfs->progress)(rfs, E2_RSZ_INODE_SCAN_PASS,
1347 0, rfs->old_fs->group_desc_count);
1351 ext2fs_set_inode_callback(scan, progress_callback, (void *) rfs);
1352 pb.rfs = rfs;
1355 new_inode = EXT2_FIRST_INODE(rfs->new_fs->super);
1356 inode_size = EXT2_INODE_SIZE(rfs->new_fs->super);
1378 if (inode->i_file_acl && rfs->bmap) {
1379 new_block = ext2fs_extent_translate(rfs->bmap,
1383 retval = ext2fs_write_inode_full(rfs->old_fs,
1390 (rfs->bmap || pb.is_dir)) {
1392 retval = ext2fs_block_iterate2(rfs->old_fs,
1409 retval = ext2fs_new_inode(rfs->new_fs, 0, 0, 0, &new_inode);
1413 ext2fs_inode_alloc_stats2(rfs->new_fs, new_inode, +1,
1417 retval = ext2fs_read_inode_full(rfs->old_fs, ino,
1422 retval = ext2fs_write_inode_full(rfs->old_fs, new_inode,
1427 if (rfs->flags & RESIZE_DEBUG_INODEMAP)
1430 if (!rfs->imap) {
1431 retval = ext2fs_create_extent_table(&rfs->imap, 0);
1435 ext2fs_add_extent_entry(rfs->imap, ino, new_inode);
1437 io_channel_flush(rfs->old_fs->io);
1440 rfs->old_fs->super->s_blocks_count = orig_size;
1441 if (rfs->bmap) {
1442 ext2fs_free_extent_table(rfs->bmap);
1443 rfs->bmap = 0;
1461 ext2_resize_t rfs;
1479 if (is->rfs->progress && offset == 0) {
1480 io_channel_flush(is->rfs->old_fs->io);
1481 is->err = (is->rfs->progress)(is->rfs,
1491 new_inode = ext2fs_extent_translate(is->rfs->imap, dirent->inode);
1496 if (is->rfs->flags & RESIZE_DEBUG_INODEMAP)
1505 retval = ext2fs_read_inode(is->rfs->old_fs, dir, &inode);
1508 is->err = ext2fs_write_inode(is->rfs->old_fs, dir, &inode);
1516 static errcode_t inode_ref_fix(ext2_resize_t rfs)
1521 if (!rfs->imap)
1529 is.max_dirs = ext2fs_dblist_count(rfs->old_fs->dblist);
1530 is.rfs = rfs;
1533 if (rfs->progress) {
1534 retval = (rfs->progress)(rfs, E2_RSZ_INODE_REF_UPD_PASS,
1540 retval = ext2fs_dblist_dir_iterate(rfs->old_fs->dblist,
1550 if (rfs->progress && (is.num < is.max_dirs))
1551 (rfs->progress)(rfs, E2_RSZ_INODE_REF_UPD_PASS,
1555 ext2fs_free_extent_table(rfs->imap);
1556 rfs->imap = 0;
1578 * After this you have to use the rfs->new_fs file handle to read and
1581 static errcode_t move_itables(ext2_resize_t rfs)
1585 ext2_filsys fs = rfs->new_fs;
1592 if (max_groups > rfs->old_fs->group_desc_count)
1593 max_groups = rfs->old_fs->group_desc_count;
1596 if (!rfs->itable_buf) {
1597 retval = ext2fs_get_mem(size, &rfs->itable_buf);
1607 if (rfs->old_fs->group_desc[i].bg_inode_table !=
1614 if (rfs->progress) {
1615 retval = rfs->progress(rfs, E2_RSZ_MOVE_ITABLE_PASS,
1621 rfs->old_fs->flags |= EXT2_FLAG_MASTER_SB_ONLY;
1624 old_blk = rfs->old_fs->group_desc[i].bg_inode_table;
1629 if (rfs->flags & RESIZE_DEBUG_ITABLEMOVE)
1639 rfs->itable_buf);
1649 for (cp = rfs->itable_buf+size-1, n=0; n < size; n++, cp--)
1654 if (rfs->flags & RESIZE_DEBUG_ITABLEMOVE)
1662 num, rfs->itable_buf);
1665 num, rfs->itable_buf);
1671 diff, (rfs->itable_buf +
1678 for (blk = rfs->old_fs->group_desc[i].bg_inode_table, j=0;
1682 rfs->old_fs->group_desc[i].bg_inode_table = new_blk;
1683 ext2fs_group_desc_csum_set(rfs->old_fs, i);
1684 ext2fs_mark_super_dirty(rfs->old_fs);
1685 ext2fs_flush(rfs->old_fs);
1687 if (rfs->progress) {
1688 retval = rfs->progress(rfs, E2_RSZ_MOVE_ITABLE_PASS,
1697 if (rfs->flags & RESIZE_DEBUG_ITABLEMOVE)