Skip to content

Commit

Permalink
feat: 添加 Lab 5 练习 5 代码
Browse files Browse the repository at this point in the history
  • Loading branch information
woai3c committed Mar 24, 2020
1 parent 9f26921 commit efca92e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
18 changes: 16 additions & 2 deletions fs/serv.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,14 @@ serve_read(envid_t envid, union Fsipc *ipc)
cprintf("serve_read %08x %08x %08x\n", envid, req->req_fileid, req->req_n);

// Lab 5: Your code here:
return 0;
struct OpenFile *o;
int r;
if ((r = openfile_lookup(envid, req->req_fileid, &o)) < 0)
return r;
if ((r = file_read(o->o_file, ret->ret_buf, req->req_n, o->o_fd->fd_offset)) < 0)
return r;
o->o_fd->fd_offset += req->req_n;
return r;
}


Expand All @@ -229,7 +236,14 @@ serve_write(envid_t envid, struct Fsreq_write *req)
cprintf("serve_write %08x %08x %08x\n", envid, req->req_fileid, req->req_n);

// LAB 5: Your code here.
panic("serve_write not implemented");
struct OpenFile *o;
int r;
if ((r = openfile_lookup(envid, req->req_fileid, &o)) < 0)
return r;
if ((r = file_write(o->o_file, req->req_buf, req->req_n, o->o_fd->fd_offset)) < 0)
return r;
o->o_fd->fd_offset += req->req_n;
return r;
}

// Stat ipc->stat.req_fileid. Return the file's struct Stat to the
Expand Down
5 changes: 4 additions & 1 deletion lib/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ devfile_write(struct Fd *fd, const void *buf, size_t n)
// remember that write is always allowed to write *fewer*
// bytes than requested.
// LAB 5: Your code here
panic("devfile_write not implemented");
fsipcbuf.write.req_fileid = fd->fd_file.id;
fsipcbuf.write.req_n = n;
memmove(fsipcbuf.write.req_buf, buf, n);
return fsipc(FSREQ_WRITE, NULL);
}

static int
Expand Down

0 comments on commit efca92e

Please sign in to comment.