From 4c31f8c563da7f09f729145c8ed3af8b55c17fbc Mon Sep 17 00:00:00 2001 From: Stephen Marz Date: Fri, 24 Apr 2020 19:22:27 -0400 Subject: [PATCH] Add inode number to fs_read --- risc_v/src/minixfs.rs | 9 +++++---- risc_v/src/syscall.rs | 13 +++++++------ risc_v/src/test.rs | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/risc_v/src/minixfs.rs b/risc_v/src/minixfs.rs index f59c50f..a4ad1c1 100755 --- a/risc_v/src/minixfs.rs +++ b/risc_v/src/minixfs.rs @@ -135,7 +135,7 @@ impl MinixFileSystem { // Now, we read the inode itself. syc_read(desc, buffer.get_mut(), 512, inode_offset as u32); - println!("Inode sizex = {} {:o}, DZ {} {} {} {} {} {} {}", inode.size, inode.mode, inode.zones[0], inode.zones[1], inode.zones[2], inode.zones[3], inode.zones[4], inode.zones[5], inode.zones[6]); + println!("Inode {} sizex = {} {:o}, DZ {} {} {} {} {} {} {}", inode_num, inode.size, inode.mode, inode.zones[0], inode.zones[1], inode.zones[2], inode.zones[3], inode.zones[4], inode.zones[5], inode.zones[6]); return Some(*inode); } // If we get here, some result wasn't OK. Either the super block @@ -154,7 +154,6 @@ impl FileSystem for MinixFileSystem { } fn read(desc: &Descriptor, buffer: *mut u8, size: u32, offset: u32) -> u32 { - println!("MinixFileSystem::read: {}, {:p}, off: {}, sz: {}", desc.blockdev, buffer, offset, size); let mut blocks_seen = 0u32; let offset_block = offset / BLOCK_SIZE; let offset_byte = offset % BLOCK_SIZE; @@ -233,6 +232,7 @@ struct ProcArgs { pub buffer: *mut u8, pub size: u32, pub offset: u32, + pub node: u32, } fn read_proc(args_addr: usize) { @@ -240,7 +240,7 @@ fn read_proc(args_addr: usize) { let args = unsafe { args_ptr.as_ref().unwrap() }; let desc = Descriptor { blockdev: args.dev, - node: 1, + node: args.node, loc: 0, size: 500, pid: args.pid, }; @@ -249,7 +249,7 @@ fn read_proc(args_addr: usize) { tfree(args_ptr); } -pub fn process_read(pid: u16, dev: usize, buffer: *mut u8, size: u32, offset: u32) { +pub fn process_read(pid: u16, dev: usize, node: u32, buffer: *mut u8, size: u32, offset: u32) { // println!("FS read {}, {}, 0x{:x}, {}, {}", pid, dev, buffer as usize, size, offset); let args = talloc::().unwrap(); args.pid = pid; @@ -257,6 +257,7 @@ pub fn process_read(pid: u16, dev: usize, buffer: *mut u8, size: u32, offset: u3 args.buffer = buffer; args.size = size; args.offset = offset; + args.node = node; set_waiting(pid); let _ = add_kernel_process_args(read_proc, args as *mut ProcArgs as usize); } diff --git a/risc_v/src/syscall.rs b/risc_v/src/syscall.rs index 90f5c8e..c1365a5 100755 --- a/risc_v/src/syscall.rs +++ b/risc_v/src/syscall.rs @@ -49,10 +49,11 @@ pub fn do_syscall(mepc: usize, frame: *mut TrapFrame) -> usize { // This needs to be put into a process and ran. let _ = minixfs::process_read( (*frame).pid as u16, - (*frame).regs[10] as usize, - (*frame).regs[11] as *mut u8, - (*frame).regs[12] as u32, - (*frame).regs[13] as u32 + (*frame).regs[10] as usize, + (*frame).regs[11] as u32, + (*frame).regs[12] as *mut u8, + (*frame).regs[13] as u32, + (*frame).regs[14] as u32 ); // If we return 0, the trap handler will schedule another process. 0 @@ -97,8 +98,8 @@ pub fn syscall_exit() { let _ = do_make_syscall(93, 0, 0, 0, 0, 0, 0); } -pub fn syscall_fs_read(dev: usize, buffer: *mut u8, size: u32, offset: u32) -> usize { - do_make_syscall(63, dev, buffer as usize, size as usize, offset as usize, 0, 0) +pub fn syscall_fs_read(dev: usize, inode: u32, buffer: *mut u8, size: u32, offset: u32) -> usize { + do_make_syscall(63, dev, inode as usize, buffer as usize, size as usize, offset as usize, 0) } pub fn syscall_block_read(dev: usize, buffer: *mut u8, size: u32, offset: u32) -> usize { diff --git a/risc_v/src/test.rs b/risc_v/src/test.rs index c532287..717a31c 100644 --- a/risc_v/src/test.rs +++ b/risc_v/src/test.rs @@ -7,7 +7,7 @@ pub fn test_block() { let buffer = crate::kmem::kmalloc(1024); println!("Started test block process, buffer is at {:p}.", buffer); unsafe { - syscall_fs_read(8, buffer, 0, 1024); + syscall_fs_read(8, 1, buffer, 0, 1024); for i in 0..32 { print!("{:02x} ", buffer.add(i).read()); if (i+1) % 16 == 0 {