Beispiel #1
0
// Set *blk to point at the filebno'th block in file 'f'.
// Allocate the block if it doesn't yet exist.
// Returns 0 on success, < 0 on error.
int
file_get_block(struct File *f, uint32_t filebno, char **blk)
{
	int r;
	uint32_t diskbno;

	// Read in the block, leaving the pointer in *blk.
	// Hint: Use file_map_block and read_block.
	// LAB 5: Your code here.
	r = file_map_block(f, filebno, &diskbno, 1);
	if (r)
		return r;

	// If the block is already mapped we return it
	// instead of reading the block from disk again.
	// XXX: I'm not sure whether this is the right
	// thing to do, however, looks like lab5 says
	// to do that (p. 7).
	if (block_is_mapped(diskbno)) {
		if (blk)
			*blk = diskaddr(diskbno);
		return 0;
	}

	return read_block(diskbno, blk);
}
Beispiel #2
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)
{
	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);
	}	
}
Beispiel #3
0
Datei: fs.c Projekt: 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);
	}
}
Beispiel #4
0
// Set *blk to point at the filebno'th block in file 'f'.
// Allocate the block if it doesn't yet exist.
// Returns 0 on success, < 0 on error.
int
file_get_block(struct File *f, uint32_t filebno, char **blk)
{
	int r;
	uint32_t diskbno;

	// Read in the block, leaving the pointer in *blk.
	// Hint: Use file_map_block and read_block.
	// LAB 5: Your code here.
	if ((r = file_map_block(f, filebno, &diskbno, 1) < 0))
		return r;
	if ((r = read_block(diskbno, blk)) < 0)
		return r;
	return 0;
}
Beispiel #5
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);
	}
}
Beispiel #6
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)
{
	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);
	}
}
Beispiel #7
0
Datei: fs.c Projekt: darfux/jos
// Set *blk to point at the filebno'th block in file 'f'.
// Allocate the block if it doesn't yet exist.
// Returns 0 on success, < 0 on error.
int
file_get_block(struct File *f, uint32_t filebno, char **blk)
{
	int error;
	uint32_t diskbno;

	// Read in the block, leaving the pointer in *blk.
	// Hint: Use file_map_block and read_block.
	// LAB 5: Your code here.
	// panic("file_get_block not implemented");
	error = file_map_block(f, filebno, &diskbno, 1);
	if(error< 0) return error;

	error = read_block(diskbno, blk);
	if(error< 0) return error;

	return 0;
}
Beispiel #8
0
Datei: fs.c Projekt: 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);			
	}
}
Beispiel #9
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 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);
	}
}
Beispiel #10
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 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;
}
Beispiel #11
0
// Set *blk to point at the filebno'th block in file 'f'.
// Allocate the block if it doesn't yet exist.
// Returns 0 on success, < 0 on error.
int
file_get_block(struct File *f, uint32_t filebno, char **blk)
{
	int r;
	uint32_t diskbno;

	// Read in the block, leaving the pointer in *blk.
	// Hint: Use file_map_block and read_block.
	// LAB 5: Your code here.
    r = file_map_block(f, filebno, &diskbno, 1);
    if(r < 0)
        return r;
    if(!block_is_mapped(diskbno))
        read_block(diskbno, blk);
    else
        *blk = diskaddr(diskbno);
	//panic("file_get_block not implemented");
	
	return 0;
}