From 59aaa9622b0f93ffaff3a26e33f74de42d56e88f Mon Sep 17 00:00:00 2001 From: able Date: Thu, 28 Jul 2022 05:02:43 -0500 Subject: [PATCH] various QOL updates --- ableos/src/handle.rs | 1 + ableos/src/scratchpad.rs | 171 ++++++++++++++++++++++----------------- ext2-rs/src/fs/sync.rs | 11 +++ 3 files changed, 108 insertions(+), 75 deletions(-) diff --git a/ableos/src/handle.rs b/ableos/src/handle.rs index 67260049..0873d153 100644 --- a/ableos/src/handle.rs +++ b/ableos/src/handle.rs @@ -15,6 +15,7 @@ pub struct BinaryData { pub enum HandleResource { Channel(Channel), // Device + /// Used for things like files or images or the like BinaryData(BinaryData), } diff --git a/ableos/src/scratchpad.rs b/ableos/src/scratchpad.rs index af87734a..1a33a3ec 100644 --- a/ableos/src/scratchpad.rs +++ b/ableos/src/scratchpad.rs @@ -1,8 +1,8 @@ use core::fmt::Error; // use crate::aalloc::aalloc; -use crate::arch::generate_process_pass; use crate::arch::interrupts::{reset_pit_for_cpu, set_pit_2}; +use crate::arch::{generate_process_pass, shutdown}; use crate::channels::{Channel, ChannelPermission}; use crate::devices::pci; use crate::filesystem::FILE_SYSTEM; @@ -15,8 +15,12 @@ use acpi::{AcpiTables, PlatformInfo}; use alloc::collections::{vec_deque, VecDeque}; use cpuio::inb; use cpuio::outb; -use genfs::Fs; +use ext2::fs::sync::{DirectoryEntry, Synced}; +use ext2::fs::Ext2; +use ext2::sector::Size1024; +use ext2::sys::inode; use genfs::OpenOptions; +use genfs::{DirEntry, Fs}; use kernel::proccess::PID; use vga::writers::GraphicsWriter; @@ -68,13 +72,13 @@ pub fn scratchpad() { }"; let axel = axel::parse(axel_raw.to_string()); - let xyz = pci::brute_force_scan(); - for dev in xyz { - trace!("{:?}", dev); - dev.bars.iter().for_each(|bar| { - trace!("{:?}", bar); - }); - } + // let xyz = pci::brute_force_scan(); + // for dev in xyz { + // trace!("{:?}", dev); + // dev.bars.iter().for_each(|bar| { + // trace!("{:?}", bar); + // }); + // } for node in axel { info!("{:?}", node); @@ -97,16 +101,6 @@ pub fn scratchpad() { */ - let home_path = Path::new("/home/able".to_string()); - - let mut chan = Channel::new(); - - let ret = chan.read(); - - let chan_handle = Handle::from_channel(chan); - - println!("{}", chan_handle); - real_shell(); } use crate::graphics::VgaBuffer; @@ -174,68 +168,84 @@ pub fn command_parser(user: String, command: String) { let fs = &*FILE_SYSTEM.lock(); let mut iter = command.split_whitespace(); + // TODO: update the open() function to take either a ableOS path or a b"/" type path + let current_path = Path::new("/home/able".to_string()); + trace!("Current path: {:?}", current_path); + let current_path = b"/home/able/"; + let bin_name = iter.next().unwrap(); - if bin_name == "rhai" { - drop(fs); - shell(); - return; - } - - let home_exec_path = format!("/home/{}/bins/{}.wasm", user, bin_name); - let shared_exec_path = format!("/shared/bins/{}.wasm", bin_name); - let system_exec_path = format!("/system/bins/{}.wasm", bin_name); - - let home_exec_file = fs.open(&home_exec_path.as_bytes(), OpenOptions::new().read(true)); - let shared_exec_file = fs.open(&shared_exec_path.as_bytes(), OpenOptions::new().read(true)); - let system_exec_file = fs.open(&system_exec_path.as_bytes(), OpenOptions::new().read(true)); - - let mut in_home = false; - let mut in_shared = false; - let mut in_system = false; - - let mut binary_prog: Vec = vec![]; - - match home_exec_file { - Ok(file) => { - let ret = file.read_to_end(&mut binary_prog).unwrap(); - in_home = true; + match bin_name { + "rhai" => { + drop(fs); + shell(); } + "list" | "ls" => { + for dir_entry in list_files_in_dir(fs, current_path) { + println!("{}", dir_entry.file_name_string()); + } + } + "quit" => shutdown(), - Err(error) => { - trace!("{:?}", error); - in_home = false; - } - } - match shared_exec_file { - Ok(file) => { - let ret = file.read_to_end(&mut binary_prog).unwrap(); - in_shared = true; - } - Err(error) => { - trace!("{:?}", error); - in_shared = false; - } - } - match system_exec_file { - Ok(file) => { - let ret = file.read_to_end(&mut binary_prog).unwrap(); - in_system = true; - } + _ => { + let home_exec_path = format!("/home/{}/bins/{}.wasm", user, bin_name); + let shared_exec_path = format!("/shared/bins/{}.wasm", bin_name); + let system_exec_path = format!("/system/bins/{}.wasm", bin_name); - Err(error) => { - trace!("{:?}", error); - in_system = false; - } - } + let home_exec_file = fs.open(&home_exec_path.as_bytes(), OpenOptions::new().read(true)); + let shared_exec_file = + fs.open(&shared_exec_path.as_bytes(), OpenOptions::new().read(true)); + let system_exec_file = + fs.open(&system_exec_path.as_bytes(), OpenOptions::new().read(true)); - let args = iter.collect::>(); - println!("{:?}", args); - if in_home || in_shared || in_system { - run_program(&binary_prog); - } else { - println!("No such binary: {}", bin_name); - error!("No such binary: {}", bin_name); + let mut in_home = false; + let mut in_shared = false; + let mut in_system = false; + + let mut binary_prog: Vec = vec![]; + + match home_exec_file { + Ok(file) => { + let ret = file.read_to_end(&mut binary_prog).unwrap(); + in_home = true; + } + + Err(error) => { + trace!("{:?}", error); + in_home = false; + } + } + match shared_exec_file { + Ok(file) => { + let ret = file.read_to_end(&mut binary_prog).unwrap(); + in_shared = true; + } + Err(error) => { + trace!("{:?}", error); + in_shared = false; + } + } + match system_exec_file { + Ok(file) => { + let ret = file.read_to_end(&mut binary_prog).unwrap(); + in_system = true; + } + + Err(error) => { + trace!("{:?}", error); + in_system = false; + } + } + + let args = iter.collect::>(); + println!("{:?}", args); + if in_home || in_shared || in_system { + run_program(&binary_prog); + } else { + println!("No such binary: {}", bin_name); + error!("No such binary: {}", bin_name); + } + } } } @@ -264,3 +274,14 @@ pub fn sound_off() { }; reset_pit_for_cpu(); } + +pub fn list_files_in_dir(fs: &Synced>>, path: &[u8]) -> Vec { + let mut entry_list = vec![]; + + let dirr = fs.read_dir(b"/").unwrap(); + for dir_entry in dirr { + entry_list.push(dir_entry.unwrap()); + } + + entry_list +} diff --git a/ext2-rs/src/fs/sync.rs b/ext2-rs/src/fs/sync.rs index bbf8521a..d028b03e 100644 --- a/ext2-rs/src/fs/sync.rs +++ b/ext2-rs/src/fs/sync.rs @@ -710,6 +710,17 @@ impl DirEntry for DirectoryEntry { } } +impl DirectoryEntry { + /// Turns a filename into a string for display + pub fn file_name_string(&self) -> String { + let mut filename = String::new(); + for ch in &self.name { + filename.push(*ch as char); + } + filename + } +} + #[cfg(test)] mod tests { use std::cell::RefCell;