1
5
mirror of https://github.com/vinc/moros.git synced 2024-06-25 18:37:04 +00:00

Add dummy read and write commands

This commit is contained in:
Vincent Ollivier 2019-12-30 21:55:42 +01:00
parent 82dc5d5082
commit 978a1cca49
4 changed files with 76 additions and 15 deletions

View File

@ -1,3 +1,5 @@
pub mod date;
pub mod read;
pub mod shell;
pub mod uptime;
pub mod write;

25
src/user/read.rs Normal file
View File

@ -0,0 +1,25 @@
use crate::print;
use crate::kernel::fs;
use crate::user;
pub fn main(args: &[&str]) {
if args.len() != 2 {
return;
}
let pathname = args[1];
match pathname {
"/dev/rtc" => user::date::main(&["date", "--iso-8601"]),
"/dev/clk/realtime" => user::date::main(&["date", "--raw"]),
"/dev/clk/uptime" => user::uptime::main(&["uptime", "--raw"]),
"/sys/version" => print!("MOROS v{}\n", env!("CARGO_PKG_VERSION")),
_ => {
if let Some(file) = fs::File::open(pathname) {
print!("{}\n", file.read());
} else {
print!("File not found '{}'\n", pathname);
}
}
}
}

View File

@ -47,21 +47,35 @@ pub fn key_handle(key: DecodedKey) {
let line = stdin.clone();
let args: Vec<&str, U256> = line.split_whitespace().collect();
match args[0] {
"help" => {
print!("RTFM!\n");
},
"version" => {
print!("MOROS v{}\n", env!("CARGO_PKG_VERSION"));
},
"date" => {
user::date::main(&args);
},
"uptime" => {
user::uptime::main(&args);
},
_ => {
print!("?\n");
}
"a" | "alias" => print!("TODO\n"),
"b" => print!("?\n"),
"c" | "copy" | "cp" => print!("TODO\n"),
"d" | "del" | "delete" | "rm" => print!("TODO\n"),
"e" | "edit" => print!("TODO\n"),
"f" | "find" => print!("TODO\n"),
"g" | "gd" | "go" | "go-dir" | "cd" => print!("TODO\n"),
"h" | "help" => print!("RTFM!\n"),
"i" => print!("?\n"),
"j" | "jd" | "jump" | "jump-dir" => print!("TODO\n"),
"k" | "kill" => print!("TODO\n"),
"l" | "list" | "ls" => print!("TODO\n"), // same as `rd`
"m" | "move" | "mv" => print!("TODO\n"),
"n" => print!("?\n"),
"o" => print!("?\n"),
"p" | "print" => print!("TODO\n"),
"q" | "quit" | "exit" => print!("QUIT\n"),
"r" | "read" => user::read::main(&args),
"s" => print!("?\n"),
"t" | "tag" => print!("TODO\n"),
"u" => print!("?\n"),
"v" => print!("?\n"),
"w" | "write" => user::write::main(&args),
"x" => print!("?\n"),
"y" => print!("?\n"),
"z" => print!("?\n"),
"rd" | "read-dir" => print!("TODO\n"),
"wd" | "write-dir" | "mkdir" => print!("TODO\n"),
_ => print!("?\n"),
}
stdin.clear();
}

20
src/user/write.rs Normal file
View File

@ -0,0 +1,20 @@
use crate::print;
use crate::kernel::fs;
pub fn main(args: &[&str]) {
if args.len() != 2 {
return;
}
let pathname = args[1];
if pathname.starts_with("/dev") || pathname.starts_with("/sys") {
print!("Permission denied to write to '{}'\n", pathname);
} else {
if let Some(mut file) = fs::File::create(pathname) {
file.write("fake contents");
} else {
print!("Permission denied to write to '{}'\n", pathname);
}
}
}