Skip to content

Commit

Permalink
feat: 添加 Lab 5 练习 1-3 代码
Browse files Browse the repository at this point in the history
  • Loading branch information
woai3c committed Mar 21, 2020
1 parent 143ec1f commit e139744
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
15 changes: 13 additions & 2 deletions fs/bc.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ bc_pgfault(struct UTrapframe *utf)
// the disk.
//
// LAB 5: you code here:

addr = ROUNDDOWN(addr, PGSIZE);
if ((r = sys_page_alloc(0, addr, PTE_P | PTE_U | PTE_W)) < 0)
panic("in bc_pgfault, sys_page_alloc: %e", r);

if ((r = ide_read(blockno * BLKSIZE / SECTSIZE, addr, BLKSIZE / SECTSIZE)) < 0)
panic("in bc_pgfault, ide_read: %e", r);
// Clear the dirty bit for the disk block page since we just read the
// block from disk
if ((r = sys_page_map(0, addr, 0, addr, uvpt[PGNUM(addr)] & PTE_SYSCALL)) < 0)
Expand Down Expand Up @@ -77,7 +82,13 @@ flush_block(void *addr)
panic("flush_block of bad va %08x", addr);

// LAB 5: Your code here.
panic("flush_block not implemented");
int r;
addr = ROUNDDOWN(addr, PGSIZE);
if (!va_is_mapped(addr) || !va_is_dirty(addr)) return;
if ((r = ide_write(blockno * BLKSIZE / SECTSIZE, addr, BLKSIZE / SECTSIZE)) < 0)
panic("in flush_block, ide_write: %e", r);
if ((r = sys_page_map(0, addr, 0, addr, uvpt[PGNUM(addr)] & PTE_SYSCALL)) < 0)
panic("in flush_block, sys_page_map: %e", r);
}

// Test that the block cache works, by smashing the superblock and
Expand Down
8 changes: 7 additions & 1 deletion fs/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ alloc_block(void)
// super->s_nblocks blocks in the disk altogether.

// LAB 5: Your code here.
panic("alloc_block not implemented");
for (int i = 3; i < super->s_nblocks; i++) {
if (block_is_free(i)) {
bitmap[i/32] &= ~(1<<(i%32));
return i;
}
}

return -E_NO_DISK;
}

Expand Down
3 changes: 3 additions & 0 deletions kern/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,9 @@ env_create(uint8_t *binary, enum EnvType type)

// If this is the file server (type == ENV_TYPE_FS) give it I/O privileges.
// LAB 5: Your code here.
if (type == ENV_TYPE_FS) {
env->env_tf.tf_eflags |= FL_IOPL_MASK;
}
}

//
Expand Down

0 comments on commit e139744

Please sign in to comment.