errcode_t ea_refcount_create(size_t size, ext2_refcount_t *ret) { ext2_refcount_t refcount; errcode_t retval; size_t bytes; retval = ext2fs_get_mem(sizeof(struct ea_refcount), &refcount); if (retval) return retval; memset(refcount, 0, sizeof(struct ea_refcount)); if (!size) size = 500; refcount->size = size; bytes = size * sizeof(struct ea_refcount_el); #ifdef DEBUG printf("Refcount allocated %zu entries, %zu bytes.\n", refcount->size, bytes); #endif retval = ext2fs_get_mem(bytes, &refcount->list); if (retval) goto errout; memset(refcount->list, 0, bytes); refcount->count = 0; refcount->cursor = 0; *ret = refcount; return 0; errout: ea_refcount_free(refcount); return(retval); }
/* * This function resets an e2fsck context; it is called when e2fsck * needs to be restarted. */ errcode_t e2fsck_reset_context(e2fsck_t ctx) { ctx->flags = 0; ctx->lost_and_found = 0; ctx->bad_lost_and_found = 0; if (ctx->inode_used_map) { ext2fs_free_inode_bitmap(ctx->inode_used_map); ctx->inode_used_map = 0; } if (ctx->inode_dir_map) { ext2fs_free_inode_bitmap(ctx->inode_dir_map); ctx->inode_dir_map = 0; } if (ctx->inode_reg_map) { ext2fs_free_inode_bitmap(ctx->inode_reg_map); ctx->inode_reg_map = 0; } if (ctx->block_found_map) { ext2fs_free_block_bitmap(ctx->block_found_map); ctx->block_found_map = 0; } if (ctx->inode_link_info) { ext2fs_free_icount(ctx->inode_link_info); ctx->inode_link_info = 0; } if (ctx->journal_io) { if (ctx->fs && ctx->fs->io != ctx->journal_io) io_channel_close(ctx->journal_io); ctx->journal_io = 0; } if (ctx->fs && ctx->fs->dblist) { ext2fs_free_dblist(ctx->fs->dblist); ctx->fs->dblist = 0; } e2fsck_free_dir_info(ctx); #ifdef ENABLE_HTREE e2fsck_free_dx_dir_info(ctx); #endif if (ctx->refcount) { ea_refcount_free(ctx->refcount); ctx->refcount = 0; } if (ctx->refcount_extra) { ea_refcount_free(ctx->refcount_extra); ctx->refcount_extra = 0; } if (ctx->block_dup_map) { ext2fs_free_block_bitmap(ctx->block_dup_map); ctx->block_dup_map = 0; } if (ctx->block_ea_map) { ext2fs_free_block_bitmap(ctx->block_ea_map); ctx->block_ea_map = 0; } if (ctx->inode_bb_map) { ext2fs_free_inode_bitmap(ctx->inode_bb_map); ctx->inode_bb_map = 0; } if (ctx->inode_bad_map) { ext2fs_free_inode_bitmap(ctx->inode_bad_map); ctx->inode_bad_map = 0; } if (ctx->inode_imagic_map) { ext2fs_free_inode_bitmap(ctx->inode_imagic_map); ctx->inode_imagic_map = 0; } if (ctx->dirs_to_hash) { ext2fs_u32_list_free(ctx->dirs_to_hash); ctx->dirs_to_hash = 0; } /* * Clear the array of invalid meta-data flags */ if (ctx->invalid_inode_bitmap_flag) { ext2fs_free_mem(&ctx->invalid_inode_bitmap_flag); ctx->invalid_inode_bitmap_flag = 0; } if (ctx->invalid_block_bitmap_flag) { ext2fs_free_mem(&ctx->invalid_block_bitmap_flag); ctx->invalid_block_bitmap_flag = 0; } if (ctx->invalid_inode_table_flag) { ext2fs_free_mem(&ctx->invalid_inode_table_flag); ctx->invalid_inode_table_flag = 0; } /* Clear statistic counters */ ctx->fs_directory_count = 0; ctx->fs_regular_count = 0; ctx->fs_blockdev_count = 0; ctx->fs_chardev_count = 0; ctx->fs_links_count = 0; ctx->fs_symlinks_count = 0; ctx->fs_fast_symlinks_count = 0; ctx->fs_fifo_count = 0; ctx->fs_total_count = 0; ctx->fs_badblocks_count = 0; ctx->fs_sockets_count = 0; ctx->fs_ind_count = 0; ctx->fs_dind_count = 0; ctx->fs_tind_count = 0; ctx->fs_fragmented = 0; ctx->large_files = 0; /* Reset the superblock to the user's requested value */ ctx->superblock = ctx->use_superblock; return 0; }
/* * This function resets an e2fsck context; it is called when e2fsck * needs to be restarted. */ errcode_t e2fsck_reset_context(e2fsck_t ctx) { int i; ctx->flags &= E2F_RESET_FLAGS; ctx->lost_and_found = 0; ctx->bad_lost_and_found = 0; if (ctx->inode_used_map) { ext2fs_free_inode_bitmap(ctx->inode_used_map); ctx->inode_used_map = 0; } if (ctx->inode_dir_map) { ext2fs_free_inode_bitmap(ctx->inode_dir_map); ctx->inode_dir_map = 0; } if (ctx->inode_reg_map) { ext2fs_free_inode_bitmap(ctx->inode_reg_map); ctx->inode_reg_map = 0; } if (ctx->block_found_map) { ext2fs_free_block_bitmap(ctx->block_found_map); ctx->block_found_map = 0; } if (ctx->inode_link_info) { ext2fs_free_icount(ctx->inode_link_info); ctx->inode_link_info = 0; } if (ctx->journal_io) { if (ctx->fs && ctx->fs->io != ctx->journal_io) io_channel_close(ctx->journal_io); ctx->journal_io = 0; } if (ctx->fs && ctx->fs->dblist) { ext2fs_free_dblist(ctx->fs->dblist); ctx->fs->dblist = 0; } e2fsck_free_dir_info(ctx); e2fsck_free_dx_dir_info(ctx); if (ctx->refcount) { ea_refcount_free(ctx->refcount); ctx->refcount = 0; } if (ctx->refcount_extra) { ea_refcount_free(ctx->refcount_extra); ctx->refcount_extra = 0; } if (ctx->block_dup_map) { ext2fs_free_block_bitmap(ctx->block_dup_map); ctx->block_dup_map = 0; } if (ctx->block_ea_map) { ext2fs_free_block_bitmap(ctx->block_ea_map); ctx->block_ea_map = 0; } if (ctx->block_metadata_map) { ext2fs_free_block_bitmap(ctx->block_metadata_map); ctx->block_metadata_map = 0; } if (ctx->inode_bb_map) { ext2fs_free_inode_bitmap(ctx->inode_bb_map); ctx->inode_bb_map = 0; } if (ctx->inode_bad_map) { ext2fs_free_inode_bitmap(ctx->inode_bad_map); ctx->inode_bad_map = 0; } if (ctx->inode_imagic_map) { ext2fs_free_inode_bitmap(ctx->inode_imagic_map); ctx->inode_imagic_map = 0; } if (ctx->dirs_to_hash) { ext2fs_u32_list_free(ctx->dirs_to_hash); ctx->dirs_to_hash = 0; } /* * Clear the array of invalid meta-data flags */ if (ctx->invalid_inode_bitmap_flag) { ext2fs_free_mem(&ctx->invalid_inode_bitmap_flag); ctx->invalid_inode_bitmap_flag = 0; } if (ctx->invalid_block_bitmap_flag) { ext2fs_free_mem(&ctx->invalid_block_bitmap_flag); ctx->invalid_block_bitmap_flag = 0; } if (ctx->invalid_inode_table_flag) { ext2fs_free_mem(&ctx->invalid_inode_table_flag); ctx->invalid_inode_table_flag = 0; } if (ctx->encrypted_dirs) { ext2fs_u32_list_free(ctx->encrypted_dirs); ctx->encrypted_dirs = 0; } if (ctx->inode_count) { ext2fs_free_icount(ctx->inode_count); ctx->inode_count = 0; } /* Clear statistic counters */ ctx->fs_directory_count = 0; ctx->fs_regular_count = 0; ctx->fs_blockdev_count = 0; ctx->fs_chardev_count = 0; ctx->fs_links_count = 0; ctx->fs_symlinks_count = 0; ctx->fs_fast_symlinks_count = 0; ctx->fs_fifo_count = 0; ctx->fs_total_count = 0; ctx->fs_badblocks_count = 0; ctx->fs_sockets_count = 0; ctx->fs_ind_count = 0; ctx->fs_dind_count = 0; ctx->fs_tind_count = 0; ctx->fs_fragmented = 0; ctx->fs_fragmented_dir = 0; ctx->large_files = 0; for (i=0; i < MAX_EXTENT_DEPTH_COUNT; i++) ctx->extent_depth_count[i] = 0; /* Reset the superblock to the user's requested value */ ctx->superblock = ctx->use_superblock; return 0; }
int main(int argc, char **argv) { int i = 0; ext2_refcount_t refcount; size_t size; ea_key_t ea_key; ea_value_t arg; errcode_t retval; while (1) { switch (bcode_program[i++]) { case BCODE_END: exit(0); case BCODE_CREATE: size = bcode_program[i++]; retval = ea_refcount_create(size, &refcount); if (retval) { com_err("ea_refcount_create", retval, "while creating size %zu", size); exit(1); } else printf("Creating refcount with size %zu\n", size); break; case BCODE_FREE: ea_refcount_free(refcount); refcount = 0; printf("Freeing refcount\n"); break; case BCODE_STORE: ea_key = (size_t) bcode_program[i++]; arg = bcode_program[i++]; printf("Storing ea_key %llu with value %llu\n", ea_key, arg); retval = ea_refcount_store(refcount, ea_key, arg); if (retval) com_err("ea_refcount_store", retval, "while storing ea_key %llu", ea_key); break; case BCODE_FETCH: ea_key = (size_t) bcode_program[i++]; retval = ea_refcount_fetch(refcount, ea_key, &arg); if (retval) com_err("ea_refcount_fetch", retval, "while fetching ea_key %llu", ea_key); else printf("bcode_fetch(%llu) returns %llu\n", ea_key, arg); break; case BCODE_INCR: ea_key = (size_t) bcode_program[i++]; retval = ea_refcount_increment(refcount, ea_key, &arg); if (retval) com_err("ea_refcount_increment", retval, "while incrementing ea_key %llu", ea_key); else printf("bcode_increment(%llu) returns %llu\n", ea_key, arg); break; case BCODE_DECR: ea_key = (size_t) bcode_program[i++]; retval = ea_refcount_decrement(refcount, ea_key, &arg); if (retval) com_err("ea_refcount_decrement", retval, "while decrementing ea_key %llu", ea_key); else printf("bcode_decrement(%llu) returns %llu\n", ea_key, arg); break; case BCODE_VALIDATE: retval = ea_refcount_validate(refcount, stderr); if (retval) com_err("ea_refcount_validate", retval, "while validating"); else printf("Refcount validation OK.\n"); break; case BCODE_LIST: ea_refcount_intr_begin(refcount); while (1) { ea_key = ea_refcount_intr_next(refcount, &arg); if (!ea_key) break; printf("\tea_key=%llu, count=%llu\n", ea_key, arg); } break; case BCODE_COLLAPSE: refcount_collapse(refcount); break; } } }
int main(int argc, char **argv) { int i = 0; ext2_refcount_t refcount; int size, arg; blk_t blk; errcode_t retval; while (1) { switch (bcode_program[i++]) { case BCODE_END: exit(0); case BCODE_CREATE: size = bcode_program[i++]; retval = ea_refcount_create(size, &refcount); if (retval) { com_err("ea_refcount_create", retval, ""); exit(1); } else printf("Creating refcount with size %d\n", size); break; case BCODE_FREE: ea_refcount_free(refcount); refcount = 0; printf("Freeing refcount\n"); break; case BCODE_STORE: blk = (blk_t) bcode_program[i++]; arg = bcode_program[i++]; retval = ea_refcount_store(refcount, blk, arg); printf("Storing blk %u with value %d\n", blk, arg); if (retval) com_err("ea_refcount_store", retval, ""); break; case BCODE_FETCH: blk = (blk_t) bcode_program[i++]; retval = ea_refcount_fetch(refcount, blk, &arg); if (retval) com_err("ea_refcount_fetch", retval, ""); else printf("bcode_fetch(%u) returns %d\n", blk, arg); break; case BCODE_INCR: blk = (blk_t) bcode_program[i++]; retval = ea_refcount_increment(refcount, blk, &arg); if (retval) com_err("ea_refcount_increment", retval, ""); else printf("bcode_increment(%u) returns %d\n", blk, arg); break; case BCODE_DECR: blk = (blk_t) bcode_program[i++]; retval = ea_refcount_decrement(refcount, blk, &arg); if (retval) com_err("ea_refcount_decrement", retval, "while decrementing blk %u", blk); else printf("bcode_decrement(%u) returns %d\n", blk, arg); break; case BCODE_VALIDATE: retval = ea_refcount_validate(refcount, stderr); if (retval) com_err("ea_refcount_validate", retval, ""); else printf("Refcount validation OK.\n"); break; case BCODE_LIST: ea_refcount_intr_begin(refcount); while (1) { blk = ea_refcount_intr_next(refcount, &arg); if (!blk) break; printf("\tblk=%u, count=%d\n", blk, arg); } break; case BCODE_COLLAPSE: refcount_collapse(refcount); break; } } }