示例#1
0
文件: pass4.c 项目: ankitC/fsck
/* Pass 4 checks the bitmaps to be consistent */
void pass4()
{
	int i;
	int bitmap;
	int change_req = 0;

	/* Check for discrepancies in the inode bitmap */
	for (i = get_vistied_index(EXT2_ROOT_INO); i < super_block->s_inodes_count; ++i) 
	{
		/* Skip the reserved inodes */
		if (i >= get_vistied_index(EXT2_ROOT_INO) && \
				i <= get_vistied_index(EXT2_FIRST_INO(super_block)))
			continue;

		bitmap = is_inode_allocated(i);
		if (bitmap && !inode_link[i])
		{
			/* Clear this inode from the inode bitmap */
			printf("Pass 4: Inode %d : bitmap is inconsistent with inode table:\
					%d Vs %d\n",i + 1, bitmap, inode_link[i]);
			set_inode_bitmap(i, 0);
			change_req = 1;
		}
		else if (!bitmap && inode_link[i])
示例#2
0
uint8_t* ramdisk_init(){
	int i;
	uint8_t* ramdisk;
	int root_bid;
	struct rd_inode* root_inode;
	struct rd_super_block* InitSuperBlock;
#ifdef UL_DEBUG
	if(!(ramdisk=(uint8_t*)malloc(RAMDISK_SIZE*sizeof(uint8_t)))){
		fprintf(stderr,"No sufficient mem space for ramdisk!\n");
		exit(-1);
	}
#endif

#ifndef UL_DEBUG
	if(!(ramdisk=(uint8_t*)vmalloc(RAMDISK_SIZE*sizeof(uint8_t)))){
		printk("<1> No sufficient mem space for ramdisk!\n");
		return NULL;
	}
#endif

	//Nullify all the data in ramdisk
	memset(ramdisk,0,RAMDISK_SIZE);

	//Init the bitmap
	for(i=0;i<=(BITMAP_LIMIT+1)/RD_BLOCK_SIZE;i++){
		set_bitmap(ramdisk,i);
	}

	//Init the root directory
	root_bid=find_next_free_block(ramdisk);//BlockNO for root dir
#ifdef UL_DEBUG
	if(!(root_inode=(struct rd_inode*)malloc(sizeof(struct rd_inode)))){
		fprintf(stderr, "No sufficient mem space for root dir!\n");
		exit(-1);
	}
#endif
#ifndef UL_DEBUG
	if(!(root_inode=(struct rd_inode*)vmalloc(sizeof(struct rd_inode)))){
		printk("<1> No sufficient mem space for root dir!\n");
		return NULL;
	}
#endif

	root_inode->type=0;
	root_inode->size=0;
	root_inode->BlockPointer[0]=root_bid;
	update_inode(ramdisk,0,root_inode);
	
	//Init the superblock
#ifdef UL_DEBUG
	if(!(InitSuperBlock=(struct rd_super_block*)malloc(sizeof(struct rd_super_block)))){
		fprintf(stderr,"No sufficient mem\n");
		exit(-1);
	}
#endif 
#ifndef UL_DEBUG
	if(!(InitSuperBlock=(struct rd_super_block*)vmalloc(sizeof(struct rd_super_block)))){
		printk("<1> No sufficient mem\n");
		return NULL;
	}
#endif 

	InitSuperBlock->FreeBlockNum=BLOCK_NUM-(BITMAP_LIMIT+1)/RD_BLOCK_SIZE;
	InitSuperBlock->FreeInodeNum=INODE_NUM-1;//The root dir takes one inode
	memset(InitSuperBlock->InodeBitmap,0,INODEBITMAP_SIZE);
	update_superblock(ramdisk,InitSuperBlock);
	
	//Init the inode bitmap in superblock
	set_inode_bitmap(ramdisk,0);

#ifndef UL_DEBUG
	vfree(root_inode);
#endif
	return ramdisk;	

}