void read_super_blocks(char* device, file_system_info* fs_info) { uint32_t offset, total, alloc; fs_open(device); strncpy(fs_info->fs, vmfs_MAGIC, FS_MAGIC_SIZE); offset = logical_volume_offset(fs); total = fs->fbb->bmh.total_items + offset; alloc = vmfs_bitmap_allocated_items(fs->fbb) + offset; fs_info->block_size = vmfs_fs_get_blocksize(fs); fs_info->totalblock = total; fs_info->usedblocks = alloc; fs_info->device_size = vmfs_fs_get_blocksize(fs) * total; fs_close(); }
/// read super block and write to image head extern void initial_image_hdr(char* device, image_head* image_hdr) { uint32_t alloc,total; fs_open(device); strncpy(image_hdr->magic, IMAGE_MAGIC, IMAGE_MAGIC_SIZE); strncpy(image_hdr->fs, vmfs_MAGIC, FS_MAGIC_SIZE); total = fs->fbb->bmh.total_items; alloc = vmfs_bitmap_allocated_items(fs->fbb); image_hdr->block_size = vmfs_fs_get_blocksize(fs); image_hdr->totalblock = total; image_hdr->usedblocks = alloc; image_hdr->device_size = (vmfs_fs_get_blocksize(fs)*total); fs_close(); }
/// readbitmap - read bitmap extern void readbitmap(char* device, image_head image_hdr, unsigned long* bitmap, int pui) { uint32_t current = 0, used_block = 0, free_block = 0, err_block = 0, total = 0, alloc = 0; int status = 0; int start = 0; int bit_size = 1; fs_open(device); /// init progress progress_bar prog; /// progress_bar structure defined in progress.h progress_init(&prog, start, image_hdr.totalblock, image_hdr.totalblock, BITMAP, bit_size); total = fs->fbb->bmh.total_items; alloc = vmfs_bitmap_allocated_items(fs->fbb); for(current = 0; current < total; current++){ status = vmfs_block_get_status(fs, VMFS_BLK_FB_BUILD(current)); if (status == -1) { err_block++; pc_clear_bit(current, bitmap); } else if (status == 1){ used_block++; pc_set_bit(current, bitmap); } else if (status == 0){ free_block++; pc_clear_bit(current, bitmap); } log_mesg(2, 0, 0, fs_opt.debug, "%s: Block 0x%8.8x status: %i\n", __FILE__, current, status); update_pui(&prog, current, current, 0); } fs_close(); update_pui(&prog, 1, 1, 1); log_mesg(0, 0, 0, fs_opt.debug, "%s: Used:%lld, Free:%lld, Status err:%lld\n", __FILE__, used_block, free_block, err_block); }