Example #1
0
extern void readbitmap(char* device, image_head image_hdr, unsigned long* bitmap, int pui){
    unsigned long zones = get_nzones();
    unsigned long imaps = get_nimaps();
    unsigned long zmaps = get_nzmaps();
    char * inode_map;
    char * zone_map;
    ssize_t rc;
    unsigned long test_block = 0, test_zone = 0;

    fs_open(device);

    unsigned long block_size = get_block_size();

    if (fs_version == 3){
	if (lseek(dev, block_size*2, SEEK_SET) != 8192)
	    log_mesg(0, 1, 1, fs_opt.debug, "%s: seek failed", __FILE__);
    }

    inode_map = malloc(imaps * block_size);
    if (!inode_map)
	log_mesg(0, 1, 1, fs_opt.debug, "%s: Unable to allocate buffer for inode map", __FILE__);
    zone_map = malloc(zmaps * block_size);
    if (!inode_map)
	log_mesg(0, 1, 1, fs_opt.debug, "%s: Unable to allocate buffer for zone map", __FILE__);
    memset(inode_map,0,sizeof(inode_map));
    memset(zone_map,0,sizeof(zone_map));
    memset(bitmap,0,sizeof(unsigned long)*LONGS(image_hdr.totalblock));

    rc = read(dev, inode_map, imaps * block_size);
    if (rc < 0 || imaps * block_size != (size_t) rc)
	log_mesg(0, 1, 1, fs_opt.debug, "%s: Unable to read inode map", __FILE__);

    rc = read(dev, zone_map, zmaps * block_size);
    if (rc < 0 || zmaps * block_size != (size_t) rc)
	log_mesg(0, 1, 1, fs_opt.debug, "%s: Unable to read zone map", __FILE__);

    log_mesg(0, 0, 0, fs_opt.debug, "%s: %ld blocks\n", __FILE__, zones);
    log_mesg(0, 0, 0, fs_opt.debug, "%s: log2 block/zone: %lu\n", __FILE__, get_zone_size());
    log_mesg(0, 0, 0, fs_opt.debug, "%s: Zonesize=%d\n", __FILE__,block_size<<get_zone_size());
    log_mesg(0, 0, 0, fs_opt.debug, "%s: Maxsize=%ld\n", __FILE__, get_max_size());


    for (test_block = 0; test_block < zones; test_block++){
	test_zone = test_block - get_first_zone()+1;
	if ((test_zone < 0) || (test_zone > zones+get_first_zone()))
	    test_zone = 0;
	if(isset(zone_map,test_zone)){
	    log_mesg(3, 0, 0, fs_opt.debug, "%s: test_block %lu in use\n", __FILE__, test_block);    
	    pc_set_bit(test_block, bitmap);
	}else{
	    log_mesg(3, 0, 0, fs_opt.debug, "%s: test_block %lu not use\n", __FILE__, test_block);    
	}
    }
    fs_close();
}
Example #2
0
extern void initial_image_hdr(char* device, image_head* image_hdr){
    fs_open(device);
    if (MAGIC == MINIX_SUPER_MAGIC) {
	fs_version = 1;
    } else if (MAGIC == MINIX_SUPER_MAGIC2) {
	fs_version = 1;
    } else if (MAGIC == MINIX2_SUPER_MAGIC) {
	fs_version = 2;
    } else if (MAGIC == MINIX2_SUPER_MAGIC2) {
	fs_version = 2;
    } else if (MAGIC3 == MINIX3_SUPER_MAGIC){
	fs_version = 3;
    } else
	log_mesg(0, 1, 1, fs_opt.debug, "%s: bad magic number in super-block", __FILE__);

    log_mesg(0, 0, 0, fs_opt.debug, "%s: get_first_zone %lu\n", __FILE__, get_first_zone());
    log_mesg(0, 0, 0, fs_opt.debug, "%s: get_nzones %lu\n", __FILE__, get_nzones());
    log_mesg(0, 0, 0, fs_opt.debug, "%s: zones map size %lu\n", __FILE__, get_nzmaps());
    strncpy(image_hdr->magic, IMAGE_MAGIC, IMAGE_MAGIC_SIZE);
    strncpy(image_hdr->fs, minix_MAGIC, FS_MAGIC_SIZE);
    image_hdr->block_size  = get_block_size();
    image_hdr->totalblock  = get_nzones();
    image_hdr->usedblocks  = count_used_block();
    image_hdr->device_size = get_nzones()*get_block_size();
    fs_close();
}
Example #3
0
void read_super_blocks(char* device, file_system_info* fs_info) {
    fs_open(device);
    if (MAGIC == MINIX_SUPER_MAGIC) {
        fs_version = 1;
    } else if (MAGIC == MINIX_SUPER_MAGIC2) {
        fs_version = 1;
    } else if (MAGIC == MINIX2_SUPER_MAGIC) {
        fs_version = 2;
    } else if (MAGIC == MINIX2_SUPER_MAGIC2) {
        fs_version = 2;
    } else if (MAGIC3 == MINIX3_SUPER_MAGIC) {
        fs_version = 3;
    } else
        log_mesg(0, 1, 1, fs_opt.debug, "%s: bad magic number in super-block", __FILE__);

    log_mesg(0, 0, 0, fs_opt.debug, "%s: get_first_zone %lu\n", __FILE__, get_first_zone());
    log_mesg(0, 0, 0, fs_opt.debug, "%s: get_nzones %lu\n", __FILE__, get_nzones());
    log_mesg(0, 0, 0, fs_opt.debug, "%s: zones map size %lu\n", __FILE__, get_nzmaps());
    strncpy(fs_info->fs, minix_MAGIC, FS_MAGIC_SIZE);
    fs_info->block_size  = get_block_size();
    fs_info->totalblock  = get_nzones();
    fs_info->usedblocks  = count_used_block();
    fs_info->device_size = fs_info->totalblock * fs_info->block_size;
    fs_close();
}
Example #4
0
static unsigned long count_used_block(){
    unsigned long zones = get_nzones();
    unsigned long imaps = get_nimaps();
    unsigned long zmaps = get_nzmaps();
    char * inode_map;
    char * zone_map;
    ssize_t rc;
    unsigned long test_block = 0, test_zone = 0;
    unsigned long used_block = 0;
    unsigned long block_size = get_block_size();

    if (fs_version == 3){
	if (lseek(dev, block_size*2, SEEK_SET) != 8192)
	    log_mesg(0, 1, 1, fs_opt.debug, "%s: seek failed", __FILE__);
    }

    inode_map = malloc(imaps * block_size);
    if (!inode_map)
	log_mesg(0, 1, 1, fs_opt.debug, "%s: Unable to allocate buffer for inode map", __FILE__);
    zone_map = malloc(zmaps * block_size);
    if (!inode_map)
	log_mesg(0, 1, 1, fs_opt.debug, "%s: Unable to allocate buffer for zone map", __FILE__);
    memset(inode_map,0,sizeof(inode_map));
    memset(zone_map,0,sizeof(zone_map));

    rc = read(dev, inode_map, imaps * block_size);
    if (rc < 0 || imaps * block_size != (size_t) rc)
	log_mesg(0, 1, 1, fs_opt.debug, "%s: Unable to read inode map", __FILE__);

    rc = read(dev, zone_map, zmaps * block_size);
    if (rc < 0 || zmaps * block_size != (size_t) rc)
	log_mesg(0, 1, 1, fs_opt.debug, "%s: Unable to read zone map", __FILE__);

    for (test_block = 0; test_block < zones; test_block++){
	test_zone = test_block - get_first_zone()+1;
	if ((test_zone < 0) || (test_zone > zones+get_first_zone()))
	    test_zone = 0;
	if(isset(zone_map,test_zone)){
	    log_mesg(3, 0, 0, fs_opt.debug, "%s: test_block %lu in use\n", __FILE__, test_block);    
	    used_block++;
	}else{
	    log_mesg(3, 0, 0, fs_opt.debug, "%s: test_block %lu not use\n", __FILE__, test_block);    
	}
    }
    return used_block;
}
Example #5
0
static inline int next(unsigned long zone) {
	unsigned long zones = get_nzones();
	unsigned long first_zone = get_first_zone();

	if (!zone)
		zone = first_zone-1;
	while (++zone < zones)
		if (zone_in_use(zone))
			return zone;
	return 0;
}
Example #6
0
static int get_free_block(void) {
	unsigned int blk;
	unsigned int zones = get_nzones();
	unsigned int first_zone = get_first_zone();

	if (used_good_blocks+1 >= MAX_GOOD_BLOCKS)
		errx(MKFS_EX_ERROR, _("%s: too many bad blocks"), device_name);
	if (used_good_blocks)
		blk = good_blocks_table[used_good_blocks-1]+1;
	else
		blk = first_zone;
	while (blk < zones && zone_in_use(blk))
		blk++;
	if (blk >= zones)
		errx(MKFS_EX_ERROR, _("%s: not enough good blocks"), device_name);
	good_blocks_table[used_good_blocks] = blk;
	used_good_blocks++;
	return blk;
}
Example #7
0
static void setup_tables(void) {
	unsigned long inodes, zmaps, imaps, zones, i;

	super_block_buffer = calloc(1, MINIX_BLOCK_SIZE);
	if (!super_block_buffer)
		err(MKFS_EX_ERROR, _("%s: unable to allocate buffer for superblock"),
				device_name);

	memset(boot_block_buffer,0,512);
	super_set_magic();

	if (fs_version == 3) {
		Super3.s_log_zone_size = 0;
		Super3.s_blocksize = MINIX_BLOCK_SIZE;
	}
	else {
		Super.s_log_zone_size = 0;
	}

	super_init_maxsize();
	super_set_nzones();
	zones = get_nzones();

	/* some magic nrs: 1 inode / 3 blocks */
	if ( req_nr_inodes == 0 ) 
		inodes = BLOCKS/3;
	else
		inodes = req_nr_inodes;
	/* Round up inode count to fill block size */
	if (fs_version == 2 || fs_version == 3)
		inodes = ((inodes + MINIX2_INODES_PER_BLOCK - 1) &
			  ~(MINIX2_INODES_PER_BLOCK - 1));
	else
		inodes = ((inodes + MINIX_INODES_PER_BLOCK - 1) &
			  ~(MINIX_INODES_PER_BLOCK - 1));

	if (fs_version == 3)
		Super3.s_ninodes = inodes;
	else {
		Super.s_ninodes = inodes;
		if (inodes > MINIX_MAX_INODES)
			inodes = MINIX_MAX_INODES;
	}

	super_set_map_blocks(inodes);
	imaps = get_nimaps();
	zmaps = get_nzmaps();

	inode_map = malloc(imaps * MINIX_BLOCK_SIZE);
	zone_map = malloc(zmaps * MINIX_BLOCK_SIZE);
	if (!inode_map || !zone_map)
		err(MKFS_EX_ERROR, _("%s: unable to allocate buffers for maps"),
				device_name);
	memset(inode_map,0xff,imaps * MINIX_BLOCK_SIZE);
	memset(zone_map,0xff,zmaps * MINIX_BLOCK_SIZE);
	for (i = get_first_zone() ; i<zones ; i++)
		unmark_zone(i);
	for (i = MINIX_ROOT_INO ; i<=inodes; i++)
		unmark_inode(i);
	inode_buffer = malloc(get_inode_buffer_size());
	if (!inode_buffer)
		err(MKFS_EX_ERROR, _("%s: unable to allocate buffer for inodes"),
				device_name);
	memset(inode_buffer,0, get_inode_buffer_size());
	printf(P_("%lu inode\n", "%lu inodes\n", inodes), inodes);
	printf(P_("%lu block\n", "%lu blocks\n", zones), zones);
	printf(_("Firstdatazone=%jd (%jd)\n"), get_first_zone(), first_zone_data());
	printf(_("Zonesize=%zu\n"), (size_t) MINIX_BLOCK_SIZE << get_zone_size());
	printf(_("Maxsize=%zu\n\n"),get_max_size());
}
Example #8
0
static void setup_tables(const struct fs_control *ctl) {
	unsigned long inodes, zmaps, imaps, zones, i;

	super_block_buffer = xcalloc(1, MINIX_BLOCK_SIZE);

	memset(boot_block_buffer,0,512);
	super_set_magic(ctl);

	if (fs_version == 3) {
		Super3.s_log_zone_size = 0;
		Super3.s_blocksize = MINIX_BLOCK_SIZE;
	}
	else {
		Super.s_log_zone_size = 0;
	}

	super_init_maxsize();
	super_set_nzones(ctl);
	zones = get_nzones();

	/* some magic nrs: 1 inode / 3 blocks for smaller filesystems,
	 * for one inode / 16 blocks for large ones. mkfs will eventually
	 * crab about too far when getting close to the maximum size. */
	if (ctl->fs_inodes == 0)
		if (2048 * 1024 < ctl->fs_blocks)	/* 2GB */
			inodes = ctl->fs_blocks / 16;
		else if (512 * 1024 < ctl->fs_blocks)	/* 0.5GB */
			inodes = ctl->fs_blocks / 8;
		else
			inodes = ctl->fs_blocks / 3;
	else
		inodes = ctl->fs_inodes;
	/* Round up inode count to fill block size */
	if (fs_version == 2 || fs_version == 3)
		inodes = ((inodes + MINIX2_INODES_PER_BLOCK - 1) &
			  ~(MINIX2_INODES_PER_BLOCK - 1));
	else
		inodes = ((inodes + MINIX_INODES_PER_BLOCK - 1) &
			  ~(MINIX_INODES_PER_BLOCK - 1));

	if (fs_version == 3)
		Super3.s_ninodes = inodes;
	else {
		Super.s_ninodes = inodes;
		if (inodes > MINIX_MAX_INODES)
			inodes = MINIX_MAX_INODES;
	}
	super_set_map_blocks(ctl, inodes);
	if (MINIX_MAX_INODES < first_zone_data())
		errx(MKFS_EX_ERROR,
		     _("First data block at %jd, which is too far (max %d).\n"
		       "Try specifying fewer inodes by passing --inodes <num>"),
		     first_zone_data(),
		     MINIX_MAX_INODES);
	imaps = get_nimaps();
	zmaps = get_nzmaps();

	inode_map = xmalloc(imaps * MINIX_BLOCK_SIZE);
	zone_map = xmalloc(zmaps * MINIX_BLOCK_SIZE);
	memset(inode_map,0xff,imaps * MINIX_BLOCK_SIZE);
	memset(zone_map,0xff,zmaps * MINIX_BLOCK_SIZE);

	for (i = get_first_zone() ; i<zones ; i++)
		unmark_zone(i);
	for (i = MINIX_ROOT_INO ; i<=inodes; i++)
		unmark_inode(i);

	inode_buffer = xmalloc(get_inode_buffer_size());
	memset(inode_buffer,0, get_inode_buffer_size());

	printf(P_("%lu inode\n", "%lu inodes\n", inodes), inodes);
	printf(P_("%lu block\n", "%lu blocks\n", zones), zones);
	printf(_("Firstdatazone=%jd (%jd)\n"), get_first_zone(), first_zone_data());
	printf(_("Zonesize=%zu\n"), (size_t) MINIX_BLOCK_SIZE << get_zone_size());
	printf(_("Maxsize=%zu\n\n"),get_max_size());
}