empty_dir_info init_empty_dir(e2fsck_t ctx) { empty_dir_info edi; errcode_t retval; edi = malloc(sizeof(struct empty_dir_info_struct)); if (!edi) return NULL; memset(edi, 0, sizeof(struct empty_dir_info_struct)); retval = ext2fs_init_dblist(ctx->fs, &edi->empty_dblist); if (retval) goto errout; retval = ext2fs_allocate_block_bitmap(ctx->fs, _("empty dirblocks"), &edi->empty_dir_blocks); if (retval) goto errout; retval = ext2fs_allocate_inode_bitmap(ctx->fs, _("empty dir map"), &edi->dir_map); if (retval) goto errout; return (edi); errout: free_empty_dirblock(edi); return NULL; }
errcode_t ext2fs_move_blocks(ext2_filsys fs, ext2fs_block_bitmap reserve, ext2fs_block_bitmap alloc_map, int flags) { ext2_ino_t ino; struct ext2_inode inode; errcode_t retval; struct process_block_struct pb; ext2_inode_scan scan; char *block_buf; retval = ext2fs_open_inode_scan(fs, 0, &scan); if (retval) return retval; pb.reserve = reserve; pb.error = 0; pb.alloc_map = alloc_map ? alloc_map : fs->block_map; pb.flags = flags; retval = ext2fs_get_array(4, fs->blocksize, &block_buf); if (retval) return retval; pb.buf = block_buf + fs->blocksize * 3; /* * If GET_DBLIST is set in the flags field, then we should * gather directory block information while we're doing the * block move. */ if (flags & EXT2_BMOVE_GET_DBLIST) { if (fs->dblist) { ext2fs_free_dblist(fs->dblist); fs->dblist = NULL; } retval = ext2fs_init_dblist(fs, 0); if (retval) return retval; } retval = ext2fs_get_next_inode(scan, &ino, &inode); if (retval) return retval; while (ino) { if ((inode.i_links_count == 0) || !ext2fs_inode_has_valid_blocks(&inode)) goto next; pb.ino = ino; pb.inode = &inode; pb.add_dir = (LINUX_S_ISDIR(inode.i_mode) && flags & EXT2_BMOVE_GET_DBLIST); retval = ext2fs_block_iterate2(fs, ino, 0, block_buf, process_block, &pb); if (retval) return retval; if (pb.error) return pb.error; next: retval = ext2fs_get_next_inode(scan, &ino, &inode); if (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE) goto next; } return 0; }