int host_read(uint32_t secno, void *dst, size_t nsecs) { int r, read = 0; if(host_fd->fd_file.id == 0) { host_ipc_init(); } //This rewrites offset visible to host fs as well host_fd->fd_offset = secno * SECTSIZE; // read from the host, 2 sectors at a time. for(; nsecs > 0; nsecs-=2) { host_fsipcbuf.read.req_fileid = host_fd->fd_file.id; host_fsipcbuf.read.req_n = SECTSIZE * 2; if ((r = host_fsipc(FSREQ_READ, NULL)) < 0) return r; // FIXME: Handle case where r < SECTSIZE * 2; memmove(dst+read, &host_fsipcbuf, r); read += SECTSIZE * 2; } return 0; }
void host_ipc_init() { int r; if ((r = fd_alloc(&host_fd)) < 0) panic("Couldn't allocate an fd!"); strcpy(host_fsipcbuf.open.req_path, HOST_FS_FILE); host_fsipcbuf.open.req_omode = O_RDWR; if ((r = host_fsipc(FSREQ_OPEN, host_fd)) < 0) { fd_close(host_fd, 0); panic("Couldn't open host file!"); } }
void host_ipc_init() { int r; if ((r = fd_alloc(&host_fd)) < 0) //if(( host_fd = (struct Fd*)malloc(sizeof(host_fd)))< 0) if((r = sys_page_alloc(0, (void*)host_fd, PTE_P|PTE_W|PTE_U)) < 0) panic("Couldn't allocate an fd!"); strcpy(host_fsipcbuf.open.req_path, HOST_FS_FILE); host_fsipcbuf.open.req_omode = O_RDWR; if ((r = host_fsipc(FSREQ_OPEN, host_fd)) < 0) { fd_close(host_fd, 0); panic("Couldn't open host file!"); } }
int host_write(uint32_t secno, const void *src, size_t nsecs) { int r, written = 0; if(host_fd->fd_file.id == 0) { host_ipc_init(); } host_fd->fd_offset = secno * SECTSIZE; for(; nsecs > 0; nsecs-=2) { host_fsipcbuf.write.req_fileid = host_fd->fd_file.id; host_fsipcbuf.write.req_n = SECTSIZE * 2; memmove(host_fsipcbuf.write.req_buf, src+written, SECTSIZE * 2); if ((r = host_fsipc(FSREQ_WRITE, NULL)) < 0) return r; written += SECTSIZE * 2; } return 0; }
void host_ipc_init() { int r; if ((r = fd_alloc(&host_fd)) < 0) panic("Couldn't allocate an fd!"); //r = sys_page_alloc(0, &host_fd, PTE_P | PTE_U | PTE_W); //if (r < 0) //{ // panic("Not Valid ALloc"); //} strcpy(host_fsipcbuf.open.req_path, HOST_FS_FILE); host_fsipcbuf.open.req_omode = O_RDWR; if ((r = host_fsipc(FSREQ_OPEN, host_fd)) < 0) { fd_close(host_fd, 0); panic("Couldn't open host file!"); } }