Exemplo n.º 1
0
Arquivo: fs.c Projeto: yaobaiwei/JOS
// Flush the contents of file f out to disk.
// Loop over all the blocks in file.
// Translate the file block number into a disk block number
// and then check whether that disk block is dirty.  If so, write it out.
//
// Hint: use file_map_block, block_is_dirty, and write_block.
void
file_flush(struct File *f)
{
	int i;
	uint32_t diskbno;
	
	for (i = 0; i < (f->f_size + BLKSIZE - 1) / BLKSIZE; i++) {
		if (file_map_block(f, i, &diskbno, 0) < 0)
			continue;
		if (block_is_dirty(diskbno))
			write_block(diskbno);
	}	
}
Exemplo n.º 2
0
Arquivo: fs.c Projeto: mainboy/xv6
// Flush the contents of file f out to disk.
// Loop over all the blocks in file.
// Translate the file block number into a disk block number
// and then check whether that disk block is dirty.  If so, write it out.
//
// Hint: use file_map_block, block_is_dirty, and write_block.
void
file_flush(struct File *f)
{
	// LAB 5: Your code here.
	int blkno = ROUNDUP(f->f_size,BLKSIZE) / BLKSIZE;
	int i,disk_blk_no;
	for(i=0;i<blkno;i++){
		if(file_map_block(f,i,(unsigned int *)(&disk_blk_no),0) < 0)
			panic("file_flush: file_map_block fail!\n");
		if(block_is_dirty(disk_blk_no) != 0)
			write_block(disk_blk_no);
	}
}
Exemplo n.º 3
0
Arquivo: fs.c Projeto: ren85/jos2006
// Make sure this block is unmapped.
void
unmap_block(uint32_t blockno)
{
	int r;

	if (!block_is_mapped(blockno))
		return;

	assert(block_is_free(blockno) || !block_is_dirty(blockno));

	if ((r = sys_page_unmap(0, diskaddr(blockno))) < 0)
		panic("unmap_block: sys_mem_unmap: %e", r);
	assert(!block_is_mapped(blockno));
}
Exemplo n.º 4
0
// Flush the contents of file f out to disk.
// Loop over all the blocks in file.
// Translate the file block number into a disk block number
// and then check whether that disk block is dirty.  If so, write it out.
//
// Hint: use file_map_block, block_is_dirty, and write_block.
void
file_flush(struct File *f)
{
	// LAB 5: Your code here.
	int i, n, r;
	uint32_t diskbno;

	for (i = 0; i < f->f_size; i += BLKSIZE) {
		if ((r = file_map_block(f, i/BLKSIZE, &diskbno, 0)) < 0)
			panic("file map block error: %e", r);
		if (block_is_dirty(diskbno))
			write_block(diskbno);
		//if (f->f_indirect && block_is_dirty(f->f_indirect))
			//write_block(f->f_indirect);
	}
}
Exemplo n.º 5
0
Arquivo: fs.c Projeto: reesun/guavaos
// Flush the contents of file f out to disk.
// Loop over all the blocks in file.
// Translate the file block number into a disk block number
// and then check whether that disk block is dirty.  If so, write it out.
//
// Hint: use file_map_block, block_is_dirty, and write_block.
void
file_flush(struct File *f)
{
	int r;
	uint32_t diskbno, i;

	// LAB 5: Your code here.
	for (i = 0; i < NINDIRECT; i++) {
		r = file_map_block(f, i, &diskbno, 0);
		if (r == -E_NOT_FOUND || r == -E_INVAL)
			break;
		if (r < 0)
			continue;
		if (block_is_dirty(diskbno))
			write_block(diskbno);
	}
}
Exemplo n.º 6
0
Arquivo: fs.c Projeto: darfux/jos
// Flush the contents of file f out to disk.
// Loop over all the blocks in file.
// Translate the file block number into a disk block number
// and then check whether that disk block is dirty.  If so, write it out.
//
// Hint: use file_map_block, block_is_dirty, and write_block.
void
file_flush(struct File *f)
{
	// LAB 5: Your code here.
	// panic("file_flush not implemented");
	int error;
	int filebno;
	uint32_t diskbno;

	int filebnum = DIV_ROUNDUP(f->f_size, BLKSIZE);
	
	for(filebno=0; filebno<filebnum; filebno++)
	{
		error = file_map_block(f, filebno, &diskbno, 0);
		if(error< 0) panic("file_map_block fail");

		if(block_is_dirty(diskbno)) write_block(diskbno);			
	}
}
Exemplo n.º 7
0
Arquivo: fs.c Projeto: sunrenjie/jos
// Flush the contents of file f out to disk.
// Loop over all the blocks in file.
// Translate the file block number into a disk block number
// and then check whether that disk block is dirty.  If so, write it out.
//
// Hint: use file_map_block, block_is_dirty, and write_block.
void
file_flush(struct File *f)
{
	// LAB 5: Your code here.
	int r;
	off_t i;
	uint32_t diskbno;
	if (f->f_size == 0)
		return;
	for (i = 0; i < (f->f_size - 1) / BLKSIZE + 1; i++) {
		// Blocks not even allocated cannot be dirty.
		if ((r = file_map_block(f, i, &diskbno, 0)) == -E_NOT_FOUND)
			continue;
		if (r)
			panic("file_flush: file_map_block error: %e\n", r);
		if (block_is_dirty(diskbno))
			write_block(diskbno);
	}
}
Exemplo n.º 8
0
Arquivo: fs.c Projeto: ren85/jos2006
// Flush the contents of file f out to disk.
// Loop over all the blocks in file.
// Translate the file block number into a disk block number
// and then check whether that disk block is dirty.  If so, write it out.
//
// Hint: use file_map_block, block_is_dirty, and write_block.
void
file_flush(struct File *f)
{
	// LAB 5: Your code here.

	int r, i, how_many;
	uint32_t diskbno;

	how_many = f->f_size/BLKSIZE;
	if (f->f_size % BLKSIZE)
		how_many++;
	
	for(i=0; i<how_many; i++){
		if ((r = file_map_block(f, i, &diskbno, 0)) < 0)
			panic("file_flush - file_map_block failed!");
		if (block_is_dirty(diskbno))
			write_block(diskbno);			
	}
	return;
}
Exemplo n.º 9
0
Arquivo: fs.c Projeto: ren85/jos2006
// Copy the current contents of the block out to disk.
// Then clear the PTE_D bit using sys_page_map.
// Hint: Use ide_write.
// Hint: Use the PTE_USER constant when calling sys_page_map.
int
write_block(uint32_t blockno)
{
	char *addr;
	int r;

	if (!block_is_mapped(blockno))
		panic("write unmapped block %08x", blockno);
	
	// Write the disk block and clear PTE_D.
	// LAB 5: Your code here.

	addr = diskaddr(blockno);
	
	if((r = ide_write(blockno*(BLKSIZE/SECTSIZE), (const void *)addr, (size_t) BLKSIZE/SECTSIZE)) < 0)
			return r;	
	if(block_is_dirty(blockno))	
		if ((r = sys_page_map(sys_getenvid(), addr, sys_getenvid(), 
							  addr, (PTE_U|PTE_P|PTE_W) & ~PTE_D)) < 0)
				return r;

	return 0;
}