fix echo command and add traces to vfs

This commit is contained in:
Able 2022-11-23 01:55:09 -06:00
parent f396c3642d
commit 1f8ea529f9
5 changed files with 56 additions and 18 deletions

View file

@ -7,6 +7,7 @@ enabled = true
level = "Trace" level = "Trace"
log_to_serial = true log_to_serial = true
log_to_vterm = false log_to_vterm = false
# Exact paths required
filter = ["ableos::ps2_mouse", "ableos::vterm"] filter = ["ableos::ps2_mouse", "ableos::vterm"]

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: MPL-2.0 * SPDX-License-Identifier: MPL-2.0
*/ */
use core::fmt::Display;
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
pub enum FsError { pub enum FsError {
EndOfFile, EndOfFile,
@ -17,6 +19,11 @@ pub enum FsError {
Recursion, Recursion,
UnsupportedOperation, UnsupportedOperation,
} }
impl Display for FsError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{:?}", self)
}
}
impl Into<FsError> for ext2::error::Error { impl Into<FsError> for ext2::error::Error {
fn into(self) -> FsError { fn into(self) -> FsError {

View file

@ -51,23 +51,26 @@ impl VirtualFileSystem {
if !path.starts_with('/') { if !path.starts_with('/') {
// FIXME: use current process working directory for relative paths? // FIXME: use current process working directory for relative paths?
error!("Nonabsolute path {}", path);
Err(FsError::NotAbsolute)?; Err(FsError::NotAbsolute)?;
} }
trace!("Splitting path up");
let mut components = path.split_terminator('/'); let mut components = path.split_terminator('/');
components.next(); // throw the empty string caused by the root / components.next(); // throw the empty string caused by the root /
// will be initialised beforehand so okay to unwrap // will be initialised beforehand so okay to unwrap
let mut resolved_node = self.root_handle.unwrap(); let mut resolved_node = self.root_handle.unwrap();
// let mut symlink_recursion_level = 0; // let mut symlink_recursion_level = 0;
for component in components { for component in components {
trace!("iterating through split up path");
// if symlink_recursion_level >= SYMLINK_RECURSION_LIMIT { // if symlink_recursion_level >= SYMLINK_RECURSION_LIMIT {
// Err(FsError::Recursion)?; // Err(FsError::Recursion)?;
// } // }
if component == "" { if component == "" {
error!("Invalid Path {}", path);
Err(FsError::InvalidPath)?; Err(FsError::InvalidPath)?;
} }
trace!("Getting parent of file");
// checked by previous iteration so okay to unwrap // checked by previous iteration so okay to unwrap
let parent = self.fs_node(resolved_node).unwrap(); let parent = self.fs_node(resolved_node).unwrap();
@ -77,16 +80,18 @@ impl VirtualFileSystem {
// that's just more boilerplate in StorageDevice impls // that's just more boilerplate in StorageDevice impls
// we should probably check that here instead to reduce // we should probably check that here instead to reduce
// required boilerplate // required boilerplate
// if !parent.is_dir() { if !parent.is_dir() {
// Err(FsError::NotADirectory)?; error!("file parent {:?} is not a directory", parent);
// } Err(FsError::NotADirectory)?;
}
// FIXME: handle mount points // FIXME: handle mount points
// FIXME: handle symlinks // FIXME: handle symlinks
trace!("resolving node");
resolved_node = parent.find_dir(self, component)?; resolved_node = parent.find_dir(self, component)?;
} }
trace!("returning resolved node");
Ok(resolved_node) Ok(resolved_node)
} }
@ -107,6 +112,7 @@ impl VirtualFileSystem {
} }
pub fn fs_node(&self, handle: Handle) -> Option<Arc<FsNode>> { pub fn fs_node(&self, handle: Handle) -> Option<Arc<FsNode>> {
trace!("Cloning file node and returning");
self.fs_nodes.get(&handle).cloned() self.fs_nodes.get(&handle).cloned()
} }
@ -212,12 +218,16 @@ impl FsNode {
} }
pub fn find_dir(&self, vfs: &mut VirtualFileSystem, name: &str) -> Result<Handle> { pub fn find_dir(&self, vfs: &mut VirtualFileSystem, name: &str) -> Result<Handle> {
trace!("Locking the kernel state");
let state = KERNEL_STATE.lock(); let state = KERNEL_STATE.lock();
trace!("Grabbing storage device");
let device = state let device = state
.storage_device(self.device_handle) .storage_device(self.device_handle)
.ok_or_else(|| FsError::InvalidDevice)?; .ok_or_else(|| FsError::InvalidDevice)?;
trace!("locating directory");
device.find_dir(vfs, self, name) let ret = device.find_dir(vfs, self, name);
trace!("returning directory");
ret
} }
pub fn directory(self: Arc<Self>) -> Option<Directory> { pub fn directory(self: Arc<Self>) -> Option<Directory> {

View file

@ -325,18 +325,37 @@ pub fn sound_off() {
} }
pub fn echo_file(path: String) { 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); current_path.push_str(&path);
debug!("Aquiring lock");
let mut vfs = VFS.lock(); let mut vfs = VFS.lock();
let handle = vfs.resolve(&current_path).unwrap(); debug!("Resolving path");
let file = vfs.fs_node(handle).unwrap(); let maybe_handle = vfs.resolve(&current_path);
match maybe_handle {
Ok(handle) => {
debug!("Loading file");
let maybe_file = vfs.fs_node(handle);
if file.is_dir() { match maybe_file {
// println!("{} is a directory", path); Some(file) => {
} else { trace!("checking is directory");
let mut file_contents = Vec::new(); if file.is_dir() {
file.read(0, file.size(), &mut file_contents).unwrap(); println!("{} is a directory", path);
let file_contents_str = String::from_utf8_lossy(&file_contents); } else {
println!("{}", file_contents_str); 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),
} }
} }

1
limine Submodule

@ -0,0 +1 @@
Subproject commit 8a28109a174333fd9a194b4f299a7b7a65051455