my solution to lab 6

This commit is contained in:
winPond
2019-07-17 16:08:06 +08:00
parent 8147d99448
commit c62da1c86d
534 changed files with 60875 additions and 6513 deletions

View File

@@ -12,6 +12,8 @@ USERAPPS := $(OBJDIR)/user/init
FSIMGTXTFILES := fs/newmotd \
fs/motd
FSIMGTXTFILES := $(FSIMGTXTFILES) \
fs/index.html
USERAPPS := $(USERAPPS) \
$(OBJDIR)/user/cat \

View File

@@ -48,6 +48,10 @@ bc_pgfault(struct UTrapframe *utf)
// the disk.
//
// LAB 5: you code here:
// Clear the dirty bit for the disk block page since we just read the
// block from disk
// envid 传入 0 在最初的哪个进程下 alloc 一个page ?
addr =(void *) ROUNDDOWN(addr, PGSIZE);
if ( (r = sys_page_alloc(0, addr, PTE_P
@@ -61,6 +65,7 @@ bc_pgfault(struct UTrapframe *utf)
// 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)
panic("in bc_pgfault, sys_page_map: %e", r);
@@ -85,6 +90,7 @@ flush_block(void *addr)
uint32_t blockno = ((uint32_t)addr - DISKMAP) / BLKSIZE;
if (addr < (void*)DISKMAP || addr >= (void*)(DISKMAP + DISKSIZE))
panic("flush_block of bad va %08x", addr);
int r;
// LAB 5: Your code here.

View File

@@ -41,7 +41,9 @@ void
free_block(uint32_t blockno)
{
// Blockno zero is the null pointer of block numbers.
// 0 块启动块
if (blockno == 0)
panic("attempt to free zero block");
bitmap[blockno/32] |= 1<<(blockno%32);
@@ -72,6 +74,7 @@ alloc_block(void)
}
}
// panic("alloc_block not implemented");
return -E_NO_DISK;
}
@@ -175,6 +178,7 @@ file_block_walk(struct File *f, uint32_t filebno, uint32_t **ppdiskbno, bool all
*ppdiskbno = (uint32_t *)diskaddr(f->f_indirect) + filebno;
return 0;
// panic("file_block_walk not implemented");
}
// Set *blk to the address in memory where the filebno'th
@@ -188,6 +192,7 @@ file_block_walk(struct File *f, uint32_t filebno, uint32_t **ppdiskbno, bool all
int
file_get_block(struct File *f, uint32_t filebno, char **blk)
{
// LAB 5: Your code here.
uint32_t *pdiskbno;
int r;
@@ -207,6 +212,7 @@ file_get_block(struct File *f, uint32_t filebno, char **blk)
*blk = diskaddr(*pdiskbno);
return 0;
//panic("file_get_block not implemented");
}
// Try to find a file named "name" in dir. If so, set *file to it.
@@ -224,7 +230,9 @@ dir_lookup(struct File *dir, const char *name, struct File **file)
// Search dir for name.
// We maintain the invariant that the size of a directory-file
// is always a multiple of the file system's block size.
// 目录size 必须为 文件系统块size的倍数。
assert((dir->f_size % BLKSIZE) == 0);
nblock = dir->f_size / BLKSIZE;
for (i = 0; i < nblock; i++) {
@@ -232,7 +240,9 @@ dir_lookup(struct File *dir, const char *name, struct File **file)
return r;
f = (struct File*) blk;
for (j = 0; j < BLKFILES; j++)
// 不会出现子目录与文件同名吗?
if (strcmp(f[j].f_name, name) == 0) {
*file = &f[j];
return 0;
@@ -263,7 +273,9 @@ dir_alloc_file(struct File *dir, struct File **file)
return 0;
}
}
// 目录里没有空项,增添一个块
dir->f_size += BLKSIZE;
if ((r = file_get_block(dir, i, &blk)) < 0)
return r;

11
lab/fs/index.html Normal file
View File

@@ -0,0 +1,11 @@
<html>
<head>
<title>jhttpd on JOS</title>
</head>
<body>
<center>
<h2>This file came from JOS.</h2>
<marquee>Cheesy web page!</marquee>
</center>
</body>
</html>

View File

@@ -209,11 +209,14 @@ serve_read(envid_t envid, union Fsipc *ipc)
{
struct Fsreq_read *req = &ipc->read;
struct Fsret_read *ret = &ipc->readRet;
int r;
if (debug)
cprintf("serve_read %08x %08x %08x\n", envid, req->req_fileid, req->req_n);
// Lab 5: Your code here:
struct OpenFile *of;
if ( (r = openfile_lookup(envid, req->req_fileid, &of) )< 0)
return r;
@@ -224,6 +227,7 @@ serve_read(envid_t envid, union Fsipc *ipc)
// then update the seek position.
of->o_fd->fd_offset += r;
return r;
}
@@ -236,6 +240,7 @@ serve_write(envid_t envid, struct Fsreq_write *req)
{
if (debug)
cprintf("serve_write %08x %08x %08x\n", envid, req->req_fileid, req->req_n);
int r;
struct OpenFile *of;
int reqn;
@@ -250,6 +255,7 @@ serve_write(envid_t envid, struct Fsreq_write *req)
return r;
// LAB 5: Your code here.
// panic("serve_write not implemented");
}
// Stat ipc->stat.req_fileid. Return the file's struct Stat to the
@@ -359,7 +365,6 @@ umain(int argc, char **argv)
serve_init();
fs_init();
fs_test();
serve();
}