1
0
Fork 0
forked from koniifer/ableos

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"
log_to_serial = true
log_to_vterm = false
# Exact paths required
filter = ["ableos::ps2_mouse", "ableos::vterm"]

View file

@ -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<FsError> for ext2::error::Error {
fn into(self) -> FsError {

View file

@ -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<Arc<FsNode>> {
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<Handle> {
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<Self>) -> Option<Directory> {

View file

@ -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(&current_path).unwrap();
let file = vfs.fs_node(handle).unwrap();
debug!("Resolving path");
let maybe_handle = vfs.resolve(&current_path);
match maybe_handle {
Ok(handle) => {
debug!("Loading file");
let maybe_file = vfs.fs_node(handle);
match maybe_file {
Some(file) => {
trace!("checking is directory");
if file.is_dir() {
// println!("{} is a directory", path);
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),
}
}

1
limine Submodule

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