From 25c2a72fd1f3220052c9ae4fa2c5b7a1997b3bbc Mon Sep 17 00:00:00 2001 From: Able Date: Wed, 23 Nov 2022 01:55:09 -0600 Subject: [PATCH] fix echo command and add traces to vfs --- ableos/assets/kernel.toml | 1 + ableos/src/filesystem/errors.rs | 7 ++++++ ableos/src/filesystem/vfs.rs | 26 +++++++++++++++------- ableos/src/scratchpad.rs | 39 ++++++++++++++++++++++++--------- limine | 1 + 5 files changed, 56 insertions(+), 18 deletions(-) create mode 160000 limine diff --git a/ableos/assets/kernel.toml b/ableos/assets/kernel.toml index efcb00c0..e06d3349 100644 --- a/ableos/assets/kernel.toml +++ b/ableos/assets/kernel.toml @@ -7,6 +7,7 @@ enabled = true level = "Trace" log_to_serial = true log_to_vterm = false +# Exact paths required filter = ["ableos::ps2_mouse", "ableos::vterm"] diff --git a/ableos/src/filesystem/errors.rs b/ableos/src/filesystem/errors.rs index 3f2fb406..84c3e6c6 100644 --- a/ableos/src/filesystem/errors.rs +++ b/ableos/src/filesystem/errors.rs @@ -4,6 +4,8 @@ * SPDX-License-Identifier: MPL-2.0 */ +use core::fmt::Display; + #[derive(Copy, Clone, Debug)] pub enum FsError { EndOfFile, @@ -17,6 +19,11 @@ pub enum FsError { Recursion, UnsupportedOperation, } +impl Display for FsError { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "{:?}", self) + } +} impl Into for ext2::error::Error { fn into(self) -> FsError { diff --git a/ableos/src/filesystem/vfs.rs b/ableos/src/filesystem/vfs.rs index 5a8fdeb7..9f03b39c 100644 --- a/ableos/src/filesystem/vfs.rs +++ b/ableos/src/filesystem/vfs.rs @@ -51,23 +51,26 @@ impl VirtualFileSystem { if !path.starts_with('/') { // FIXME: use current process working directory for relative paths? + error!("Nonabsolute path {}", path); Err(FsError::NotAbsolute)?; } - + trace!("Splitting path up"); let mut components = path.split_terminator('/'); components.next(); // throw the empty string caused by the root / // will be initialised beforehand so okay to unwrap let mut resolved_node = self.root_handle.unwrap(); // let mut symlink_recursion_level = 0; for component in components { + trace!("iterating through split up path"); // if symlink_recursion_level >= SYMLINK_RECURSION_LIMIT { // Err(FsError::Recursion)?; // } if component == "" { + error!("Invalid Path {}", path); Err(FsError::InvalidPath)?; } - + trace!("Getting parent of file"); // checked by previous iteration so okay to unwrap let parent = self.fs_node(resolved_node).unwrap(); @@ -77,16 +80,18 @@ impl VirtualFileSystem { // that's just more boilerplate in StorageDevice impls // we should probably check that here instead to reduce // required boilerplate - // if !parent.is_dir() { - // Err(FsError::NotADirectory)?; - // } + if !parent.is_dir() { + error!("file parent {:?} is not a directory", parent); + Err(FsError::NotADirectory)?; + } // FIXME: handle mount points // FIXME: handle symlinks - + trace!("resolving node"); resolved_node = parent.find_dir(self, component)?; } + trace!("returning resolved node"); Ok(resolved_node) } @@ -107,6 +112,7 @@ impl VirtualFileSystem { } pub fn fs_node(&self, handle: Handle) -> Option> { + trace!("Cloning file node and returning"); self.fs_nodes.get(&handle).cloned() } @@ -212,12 +218,16 @@ impl FsNode { } pub fn find_dir(&self, vfs: &mut VirtualFileSystem, name: &str) -> Result { + trace!("Locking the kernel state"); let state = KERNEL_STATE.lock(); + trace!("Grabbing storage device"); let device = state .storage_device(self.device_handle) .ok_or_else(|| FsError::InvalidDevice)?; - - device.find_dir(vfs, self, name) + trace!("locating directory"); + let ret = device.find_dir(vfs, self, name); + trace!("returning directory"); + ret } pub fn directory(self: Arc) -> Option { diff --git a/ableos/src/scratchpad.rs b/ableos/src/scratchpad.rs index 173997cd..cf6177c2 100644 --- a/ableos/src/scratchpad.rs +++ b/ableos/src/scratchpad.rs @@ -325,18 +325,37 @@ pub fn sound_off() { } pub fn echo_file(path: String) { - let mut current_path = String::from("/"); + println!("{}", path); + let mut current_path = String::from(""); current_path.push_str(&path); + debug!("Aquiring lock"); let mut vfs = VFS.lock(); - let handle = vfs.resolve(¤t_path).unwrap(); - let file = vfs.fs_node(handle).unwrap(); + debug!("Resolving path"); + let maybe_handle = vfs.resolve(¤t_path); + match maybe_handle { + Ok(handle) => { + debug!("Loading file"); + let maybe_file = vfs.fs_node(handle); - if file.is_dir() { - // println!("{} is a directory", path); - } else { - let mut file_contents = Vec::new(); - file.read(0, file.size(), &mut file_contents).unwrap(); - let file_contents_str = String::from_utf8_lossy(&file_contents); - println!("{}", file_contents_str); + match maybe_file { + Some(file) => { + trace!("checking is directory"); + if file.is_dir() { + println!("{} is a directory", path); + } else { + trace!("allocating buffer for file contents"); + let mut file_contents = Vec::new(); + trace!("Reading file {} into buffer", path); + file.read(0, file.size(), &mut file_contents).unwrap(); + trace!("Converting file bytes into string"); + let file_contents_str = String::from_utf8_lossy(&file_contents); + println!("{}", file_contents_str); + } + } + + None => todo!(), + } + } + Err(err) => error!("path {} Error {}", path, err), } } diff --git a/limine b/limine new file mode 160000 index 00000000..8a28109a --- /dev/null +++ b/limine @@ -0,0 +1 @@ +Subproject commit 8a28109a174333fd9a194b4f299a7b7a65051455