Exemple #1
0
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");
}
Exemple #2
0
// Call the file system server to obtain and map file pages
// when the size of the file as mapped in our memory increases.
// Harmlessly does nothing if oldsize >= newsize.
// Returns 0 on success, < 0 on error.
// If there is an error, unmaps any newly allocated pages.
static int
fmap(struct Fd* fd, off_t oldsize, off_t newsize)
{
	size_t i;
	char *va;
	int r;

	va = fd2data(fd);
	for (i = ROUNDUP(oldsize, PGSIZE); i < newsize; i += PGSIZE) {
		if ((r = fsipc_map(fd->fd_file.id, i, va + i)) < 0) {
			// unmap anything we may have mapped so far
			funmap(fd, i, oldsize, 0);
			return r;
		}
	}
	return 0;
}
Exemple #3
0
// Call the file system server to obtain and map file pages
// when the size of the file as mapped in our memory increases.
// Harmlessly does nothing if oldsize >= newsize.
// Returns 0 on success, < 0 on error.
// If there is an error, unmaps any newly allocated pages.
static int
fmap(struct Fd* fd, off_t oldsize, off_t newsize)
{
	size_t i;
	char *va;
	int r;

	// Hint: Use fsipc_map.
	// Hint: Remember to unmap any pages you mapped if 
	// an error occurs.

	// LAB 5: Your code here.
	va = fd2data(fd);
	for (i = ROUNDUP(oldsize, PGSIZE); i < newsize; i += PGSIZE) {
		if ((r = fsipc_map(fd->fd_file.id, i, va + i)) < 0) {
			funmap(fd, i, oldsize, 0);
			return r;
		}
	}
	return 0;
}