feat(userspace): shell runs programs (ls, cat) via spawn w/ terminal+storage+args page; ext4 holes read as zeros; storage re-attach same buffer
This commit is contained in:
13
crates/apps/ls/Cargo.toml
Normal file
13
crates/apps/ls/Cargo.toml
Normal file
@@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "ls"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[[bin]]
|
||||
name = "ls"
|
||||
test = false
|
||||
bench = false
|
||||
|
||||
[dependencies]
|
||||
types = { workspace = true }
|
||||
libkos = { workspace = true }
|
||||
35
crates/apps/ls/src/main.rs
Normal file
35
crates/apps/ls/src/main.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
//! Lists a directory: `ls [dir]`, the root by default.
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate libkos;
|
||||
|
||||
use libkos::fs::Storage;
|
||||
use libkos::println;
|
||||
|
||||
/// Where storage's buffer is mapped.
|
||||
const STORAGE_BUF_VA: usize = 0x0180_0000;
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn main() {
|
||||
let Some(mut fs) = libkos::start::storage().and_then(|ep| Storage::attach(ep, STORAGE_BUF_VA).ok()) else {
|
||||
println!("ls: no storage");
|
||||
return;
|
||||
};
|
||||
let dir = libkos::start::args().nth(1).unwrap_or("/");
|
||||
let listed = fs.list_dir(dir.as_bytes(), |e| {
|
||||
let name = core::str::from_utf8(e.name()).unwrap_or("?");
|
||||
if name == "." || name == ".." {
|
||||
return;
|
||||
}
|
||||
if e.is_dir {
|
||||
println!("{}/", name);
|
||||
} else {
|
||||
println!("{:<24} {:>8}", name, e.size);
|
||||
}
|
||||
});
|
||||
if listed.is_err() {
|
||||
println!("ls: {}: no such directory", dir);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user