Esempio n. 1
0
/* Closes INODE and writes it to disk.
   If this was the last reference to INODE, frees its memory.
   If INODE was also a removed inode, frees its blocks. */
void
inode_close (struct inode *inode) 
{
	if(INODE_DEBUG || FILE_DEBUG) printf("INODE: closing inode %u \n", inode->sector);
	if(INODE_PRINT) inode_print(inode);

	/* Ignore null pointer. */
	if (inode == NULL)
		return;
	
	/* Release resources if this was the last opener. */
	if (--inode->open_cnt == 0)
	{
		lock_acquire(&inode->lock);

		/* Remove from inode list and release lock. */
		list_remove (&inode->elem);

		/* Deallocate blocks if removed. */
		if (inode->removed)
		{
			if(INODE_DEBUG) printf("INODE: removing inode %u\n", inode->sector);

			/* truncate inode to size 0 */
			inode_truncate(inode);

			/* release inode */
			free_map_release (inode->sector, 1);
		}

		lock_release(&inode->lock);

		free (inode);
	}
}
Esempio n. 2
0
void fs_removeAllFiles() {
    int  i;
    int  count;
    INode* node;

    if (FS_DEBUG) {
        lightLine();
        printf("removeAllFiles()\n");
        lightLine();
    }

    count = iNodes->count;
    for (i = 0; i < count; i++) {
        node = list_peekFirst(iNodes);
        inode_print(node);
        fs_removeFile(node->id);
    }
}
Esempio n. 3
0
int main(int argc, char **argv)
{
	FILE *fp;
	ext2_superblock_t *superblock = (ext2_superblock_t *)malloc(sizeof(ext2_superblock_t));
	if(argc != 2){
		printf("incorrect arguments!\n");
		return -1;
	}	
	if((fp = fopen(argv[1],"rb")) == NULL)
	{
		printf("file NULL!\n");
		return -1;
	}	
	fseek(fp, 1024, SEEK_SET);
	fread(superblock, 1024,1, fp);

	//if(superblock->s_magic 
	printf("sizei %x\n",1024 << superblock->s_log_block_size);
	uint32_t blockstart;
	
	if(superblock->s_log_block_size == 0)//1KB blocks
	{
		blockstart = 0x800;
	}else{
		blockstart = 0x1000;
	}

	int32_t groups = (1024/sizeof(ext2_group_descriptor_t));//superblock->s_blocks_count/superblock->s_blocks_per_group + 1; 
	uint32_t total_groups = superblock->s_blocks_count / superblock->s_blocks_per_group;
	uint32_t total_inodes = superblock->s_inodes_count / superblock->s_inodes_per_group;

	printf("inodes %i groups %i\n",total_inodes,total_groups);


	ext2_group_descriptor_t *gd_table = malloc(sizeof(ext2_group_descriptor_t)*groups);
	fread(gd_table, 1024,1, fp);
	
	int i;
//	for(i = 0; i < groups; i++)
	gd_print(gd_table[0]);
	fseek(fp, 0, SEEK_SET);
	
	uint32_t fs_size = superblock->s_blocks_count * 1024;
	char *fs = malloc(fs_size);
	fread(fs, fs_size,1, fp);
	

	int inode_start = BLOCK(gd_table[0].bg_inode_table);
	printf("inode_start %x\n",inode_start);
	ext2_inode_t *inode_table = (ext2_inode_t *)&fs[inode_start];
	
//	for(i = 0; i < 16; i++)
		inode_print(inode_table[21]);
	
	ext2_directory_t *root = open_root(fs, inode_table);
	list_files(root, inode_table[1].i_size);
	printf("\n\n");
	ext2_directory_t *dir = open_dir(fs, inode_table, 12);
	list_files(dir, inode_table[11].i_size);

int test =	lookup_file(dir, inode_table[11].i_size, "map");
	if(test)
		printf("awesome\n");

	
/*
//		printf("\nsize %i\n",sizeof(ext2_inode_t));
	printf("groups %i\n",groups);
	printf("magic %x\n",superblock->s_magic);*/
	fclose(fp);
	return 0;
}