From 87a1a73251ccf6dc25d1e0153c4928ec436473ac Mon Sep 17 00:00:00 2001 From: WangRunji Date: Mon, 7 May 2018 14:25:21 +0800 Subject: [PATCH] Fix `stat` & `getdirentry`. Now `ls` is available. --- src/c_interface.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/c_interface.rs b/src/c_interface.rs index d69114d..ed4004b 100644 --- a/src/c_interface.rs +++ b/src/c_interface.rs @@ -309,6 +309,10 @@ impl IoBuf { self.offset += len as i32; self.resident -= len as u32; } + fn skip_to(&mut self, offset: usize) { + let now = self.offset as usize; + self.skip(offset - now); + } fn write(&mut self, data: &[u8]) { self.as_mut()[..data.len()].copy_from_slice(data); self.skip(data.len()); @@ -406,7 +410,10 @@ impl INode { impl From for Stat { fn from(info: vfs::FileInfo) -> Self { Stat { - mode: info.mode, + mode: info.mode | match info.type_ { + vfs::FileType::File => S_IFREG, + vfs::FileType::Dir => S_IFDIR, + }, nlinks: 0, blocks: info.blocks as u32, size: info.size as u32, @@ -472,6 +479,8 @@ static INODE_OPS: INodeOps = { return ErrorCode::NoEntry; } buf.write(names[id].as_ref()); + buf.write(b"\0"); + buf.skip_to((id + 1) * ENTRY_SIZE); ErrorCode::Ok } extern fn reclaim(inode: &mut INode) -> ErrorCode {