various QOL updates

master
able 2022-07-28 05:02:43 -05:00
parent 64c21f30ba
commit 034176814f
3 changed files with 108 additions and 75 deletions

View File

@ -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),
}

View File

@ -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<u8> = 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::<Vec<&str>>();
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<u8> = 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::<Vec<&str>>();
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<Ext2<Size1024, Vec<u8>>>, path: &[u8]) -> Vec<DirectoryEntry> {
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
}

View File

@ -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;