void umain(void) { int r; int fileid; struct Fd *fd; if ((r = fsipc_open("/not-found", O_RDONLY, FVA)) < 0 && r != -E_NOT_FOUND) panic("serve_open /not-found: %e", r); else if (r == 0) panic("serve_open /not-found succeeded!"); if ((r = fsipc_open("/newmotd", O_RDONLY, FVA)) < 0) panic("serve_open /newmotd: %e", r); fd = (struct Fd*) FVA; if (strlen(msg) != fd->fd_file.file.f_size) panic("serve_open returned size %d wanted %d\n", fd->fd_file.file.f_size, strlen(msg)); cprintf("serve_open is good\n"); if ((r = fsipc_map(fd->fd_file.id, 0, UTEMP)) < 0) panic("serve_map: %e", r); if (strecmp(UTEMP, msg) != 0) panic("serve_map returned wrong data"); cprintf("serve_map is good\n"); if ((r = fsipc_close(fd->fd_file.id)) < 0) panic("serve_close: %e", r); cprintf("serve_close is good\n"); fileid = fd->fd_file.id; sys_page_unmap(0, (void*) FVA); if ((r = fsipc_map(fileid, 0, UTEMP)) != -E_INVAL) panic("serve_map does not handle stale fileids correctly"); cprintf("stale fileid is good\n"); }
// Clean up a file-server file descriptor. // This function is called by fd_close. static int file_close(struct Fd *fd) { // Unmap any data mapped for the file, // then tell the file server that we have closed the file // (to free up its resources). // LAB 5: Your code here. void *va; void *start; void *end; int r; start=(void *)fd2data(fd); end=(void *)(start + fd->fd_file.file.f_size); for (va=(void *)fd2data(fd); va <= end; va+=PGSIZE) if (va_is_dirty2(va)) if ((r = fsipc_dirty(fd->fd_file.id, (off_t) (va - start))) < 0) return r; if ((r = fsipc_close(fd->fd_file.id)) < 0) return r; funmap(fd, fd->fd_file.file.f_size, 0, 0); return 0; }
// Clean up a file-server file descriptor. // This function is called by fd_close. static int file_close(struct Fd *fd) { // Unmap any data mapped for the file, // then tell the file server that we have closed the file // (to free up its resources). // LAB 5: Your code here. int r; if ((r = funmap(fd, fd->fd_file.file.f_size, 0, 1)) < 0) return r; if (debug) cprintf("close %s\n", fd->fd_file.file.f_name); return fsipc_close(fd->fd_file.id); }