diff --git a/utility/main.rs b/utility/main.rs index fdadae792a09b5fd1d827bc1516859d4e4fecf89..2e9a8b850f36f332253a7e6b5a30fc06cb877c96 100644 --- a/utility/main.rs +++ b/utility/main.rs @@ -1,6 +1,7 @@ extern crate redoxfs; use std::env; +use std::io::{self, Write}; use redoxfs::{Disk, FileSystem}; @@ -8,13 +9,23 @@ use file_disk::FileDisk; pub mod file_disk; -fn main() { - let mut args = env::args(); - if let Some(path) = args.nth(1) { - match FileDisk::new(&path) { - Ok(disk) => match FileSystem::new(Box::new(disk)) { - Ok(filesystem) => { - let path = args.next().unwrap_or(String::new()); +fn shell<E>(filesystem: FileSystem<E>){ + let mut stdout = io::stdout(); + let stdin = io::stdin(); + + loop { + stdout.write(b"redoxfs# ").unwrap(); + stdout.flush().unwrap(); + + let mut line = String::new(); + stdin.read_line(&mut line).unwrap(); + + let mut args = line.trim().split(' '); + if let Some(command) = args.next() { + match command { + "" => (), + "ls" => { + let path = args.next().unwrap_or("/"); for (node_block, node) in filesystem.nodes.iter() { let mut name = "/".to_string(); for &b in node.name.iter() { @@ -24,14 +35,23 @@ fn main() { unsafe { name.as_mut_vec().push(b); } } } - if name == path { - println!("{}: {}", node_block, name); - break; - } else if name.starts_with(&path) { + if name.starts_with(&path) { println!("{}: {}", node_block, name); } } }, + _ => println!("unknown command: {}", command) + } + } + } +} + +fn main() { + let mut args = env::args(); + if let Some(path) = args.nth(1) { + match FileDisk::new(&path) { + Ok(disk) => match FileSystem::new(Box::new(disk)) { + Ok(filesystem) => shell(filesystem), Err(err) => { println!("redoxfs: failed to open filesystem: {}", err); }