Exemplo n.º 1
0
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);
}
Exemplo n.º 2
0
void
serve_open(u_int envid, struct Fsreq_open *rq)
{
	if (debug) printf("serve_open %08x %s 0x%x\n", envid, 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
	memcpy(path, rq->req_path, MAXPATHLEN);
	path[MAXPATHLEN-1] = 0;

	// Find a file id.
	if ((r = open_alloc(&o)) < 0) {
		if (debug) printf("open_alloc failed: %e", r);
		goto out;
	}
	fileid = r;

	// Open the file.
	if ((r = file_open(path, &f)) < 0) {
		if (debug) printf("file_open failed: %e", r);
		goto out;
	}

	// 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;

	if (debug) printf("sending success, page %08x\n", (u_int)o->o_ff);
	ipc_send(envid, 0, (u_int)o->o_ff, PTE_P|PTE_U|PTE_W|PTE_LIBRARY);
	return;
out:
	ipc_send(envid, r, 0, 0);
}