1use alloc::string::String;
7use alloc::vec::Vec;
8
9pub struct FileEntry {
11 pub name: &'static str,
13 pub data: &'static [u8],
15 pub size: usize,
17}
18
19pub struct SimpleMemoryFileSystem {
21 files: &'static [FileEntry],
22}
23
24#[repr(align(8))]
26struct Align8<const N: usize>([u8; N]);
27
28const INIT: Align8<{ include_bytes!("../../../user/bin/init").len() }> =
30 Align8(*include_bytes!("../../../user/bin/init"));
31static HELLO: Align8<{ include_bytes!("../../../user/bin/hello").len() }> =
32 Align8(*include_bytes!("../../../user/bin/hello"));
33
34static STATIC_FILES: [FileEntry; 2] = [
36 FileEntry {
37 name: "init",
38 data: &INIT.0,
39 size: INIT.0.len(),
40 },
41 FileEntry {
42 name: "hello",
43 data: &HELLO.0,
44 size: HELLO.0.len(),
45 },
46];
47
48impl SimpleMemoryFileSystem {
52 pub const fn init() -> Self {
55 Self {
56 files: &STATIC_FILES,
57 }
58 }
59
60 pub fn lookup(&self, name: &str) -> Option<&'static [u8]> {
66 self.files
67 .iter()
68 .find(|entry| entry.name == name)
69 .map(|entry| entry.data)
70 }
71
72 pub fn list_all(&self) -> Vec<String> {
75 self.files
76 .iter()
77 .map(|entry| String::from(entry.name))
78 .collect()
79 }
80
81 pub fn load_elf(&self, name: &str) -> Option<&'static [u8]> {
87 self.lookup(name)
88 }
89}