diff options
Diffstat (limited to '')
| -rw-r--r-- | bins/ls/Cargo.toml | 8 | ||||
| -rw-r--r-- | bins/ls/src/main.rs | 47 |
2 files changed, 55 insertions, 0 deletions
diff --git a/bins/ls/Cargo.toml b/bins/ls/Cargo.toml new file mode 100644 index 0000000..78497bd --- /dev/null +++ b/bins/ls/Cargo.toml | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | [package] | ||
| 2 | name = "ls" | ||
| 3 | version.workspace = true | ||
| 4 | edition.workspace = true | ||
| 5 | [lints] | ||
| 6 | workspace = true | ||
| 7 | [dependencies] | ||
| 8 | rsapi = { path = "../../rsapi" } | ||
diff --git a/bins/ls/src/main.rs b/bins/ls/src/main.rs new file mode 100644 index 0000000..956bf18 --- /dev/null +++ b/bins/ls/src/main.rs | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | //! ls — list directory contents via the exports table. | ||
| 2 | //! | ||
| 3 | //! Args: [path] — defaults to "." (root). | ||
| 4 | |||
| 5 | #![no_std] | ||
| 6 | #![no_main] | ||
| 7 | |||
| 8 | #[panic_handler] | ||
| 9 | fn panic(_info: &core::panic::PanicInfo) -> ! { | ||
| 10 | loop { core::hint::spin_loop(); } | ||
| 11 | } | ||
| 12 | |||
| 13 | fn put(exports: &rsapi::Exports, buf: &[u8]) { | ||
| 14 | (exports.put_line)(rsapi::Line { ptr: buf.as_ptr(), len: buf.len() }); | ||
| 15 | } | ||
| 16 | |||
| 17 | #[unsafe(no_mangle)] | ||
| 18 | pub extern "C" fn efi_main(exports: &'static rsapi::Exports, argc: usize, argv: *const rsapi::Arg) -> i32 { | ||
| 19 | let path_str = if argc > 0 { | ||
| 20 | let a = unsafe { &*argv }; | ||
| 21 | unsafe { core::str::from_utf8_unchecked(core::slice::from_raw_parts(a.ptr, a.len)) } | ||
| 22 | } else { | ||
| 23 | "/" | ||
| 24 | }; | ||
| 25 | let h = (exports.fs_resolve)(rsapi::Line { ptr: path_str.as_ptr(), len: path_str.len() }); | ||
| 26 | if h < 0 { return 1; } | ||
| 27 | let mut entry = rsapi::DirEntry { | ||
| 28 | name: rsapi::Line { ptr: core::ptr::null(), len: 0 }, | ||
| 29 | is_dir: false, | ||
| 30 | _pad: 0, | ||
| 31 | size: 0, | ||
| 32 | }; | ||
| 33 | while (exports.fs_dir_next)(h, &mut entry) { | ||
| 34 | let name = unsafe { core::str::from_utf8_unchecked(core::slice::from_raw_parts(entry.name.ptr, entry.name.len)) }; | ||
| 35 | if entry.is_dir { | ||
| 36 | let mut buf = [0u8; 64]; | ||
| 37 | let nb = name.as_bytes(); | ||
| 38 | buf[..nb.len()].copy_from_slice(nb); | ||
| 39 | buf[nb.len()] = b'/'; | ||
| 40 | put(exports, &buf[..nb.len() + 1]); | ||
| 41 | } else { | ||
| 42 | put(exports, name.as_bytes()); | ||
| 43 | } | ||
| 44 | } | ||
| 45 | (exports.fs_close)(h); | ||
| 46 | 0 | ||
| 47 | } | ||
