コード例 #1
0
ファイル: serv.c プロジェクト: SivilTaram/Jos-mips
void
serve_open(u_int envid, struct Fsreq_open *rq)
{
	writef("serve_open %08x %x 0x%x\n", envid, (int)rq->req_path, rq->req_omode);

	u_char path[MAXPATHLEN];
	struct File *f;
	struct Filefd *ff;
	int fileid;
	int r;
	struct Open *o;

	// Copy in the path, making sure it's null-terminated
	user_bcopy(rq->req_path, path, MAXPATHLEN);
	path[MAXPATHLEN - 1] = 0;
	//writef("serve_open:enter open %s\n",rq->req_path);
	// Find a file id.

	if ((r = open_alloc(&o)) < 0) {
		writef("open_alloc failed: %d", r);
		goto out;
	}

	fileid = r;

	//writef("serve_open:ending find a file id	o = %x\n",o);
	// Open the file.
	if ((r = file_open((char *)path, &f)) < 0) {
		writef("file_open failed: %e", r);
		goto out;
	}

	//writef("serve_open:ending open the file\n");
	// Save the file pointer.
	o->o_file = f;

	// Fill out the Filefd structure
	ff = (struct Filefd *)o->o_ff;
	ff->f_file = *f;
	ff->f_fileid = o->o_fileid;
	o->o_mode = rq->req_omode;
	ff->f_fd.fd_omode = o->o_mode;
	ff->f_fd.fd_dev_id = devfile.dev_id;

	//writef("serve_open:will to ipc send\n");
	if (debug) {
		writef("sending success, page %08x\n", (u_int)o->o_ff);
	}

	ipc_send(envid, 0, (u_int)o->o_ff, PTE_V | PTE_R | PTE_LIBRARY);
	//writef("serve_open:end of open %s\n",rq->req_path);
	return;
out:
	user_panic("*********************path:%s", path);
	ipc_send(envid, r, 0, 0);
}
コード例 #2
0
ファイル: console.c プロジェクト: ostest123/lab4gxemul
int
cons_write(struct Fd *fd, const void *vbuf, u_int n, u_int offset)
{
	int tot, m;
	char buf[128];

	USED(offset);

	// mistake: have to nul-terminate arg to syscall_cputs, 
	// so we have to copy vbuf into buf in chunks and nul-terminate.
	for(tot=0; tot<n; tot+=m) {
		m = n - tot;
		if (m > sizeof buf-1)
			m = sizeof buf-1;
		user_bcopy((char*)vbuf+tot, buf, m);
		buf[m] = 0;
		writef("%s",buf);
	}
	return tot;
}
コード例 #3
0
ファイル: serv.c プロジェクト: SivilTaram/Jos-mips
void
serve_remove(u_int envid, struct Fsreq_remove *rq)
{
	if (debug) {
		writef("serve_map %08x %s\n", envid, rq->req_path);
	}

	// Your code here
	int r;
	u_char path[MAXPATHLEN];

	// Copy in the path, making sure it's null-terminated
	user_bcopy(rq->req_path, path, MAXPATHLEN);
	path[MAXPATHLEN - 1] = 0;

	if ((r = file_remove((char *)path)) < 0) {
		ipc_send(envid, r, 0, 0);
		return;
	}

	ipc_send(envid, 0, 0, 0);//PTE_V);
	//	user_panic("serve_remove not implemented");
}