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; }
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; }
// Initialize the file system void fs_init(void) { static_assert(sizeof(struct File) == 256); #ifndef VMM_GUEST // Find a JOS disk. Use the second IDE disk (number 1) if available. if (ide_probe_disk1()) ide_set_disk(1); else ide_set_disk(0); #else host_ipc_init(); #endif bc_init(); // Set "super" to point to the super block. super = diskaddr(1); check_super(); // Set "bitmap" to the beginning of the first bitmap block. bitmap = diskaddr(2); check_bitmap(); }