MCPcopy Create free account
hub / github.com/FrameworkComputer/framework-system / shell_read_file

Function shell_read_file

framework_lib/src/fw_uefi/fs.rs:36–73  ·  view source on GitHub ↗
(path: &str)

Source from the content-addressed store, hash-verified

34}
35
36pub fn shell_read_file(path: &str) -> Option<Vec<u8>> {
37 let shell = get_shell_protocol();
38 let c_path = CString16::try_from(path).ok()?;
39
40 unsafe {
41 let mut handle: MaybeUninit<ShellFileHandle> = MaybeUninit::zeroed();
42 let status = (shell.open_file_by_name)(
43 c_path.as_ptr().cast(),
44 handle.as_mut_ptr(),
45 FileMode::READ.bits(),
46 );
47 if status.is_error() {
48 return None;
49 }
50
51 let file_handle = handle.assume_init();
52
53 let mut file_size: u64 = 0;
54 let status = (shell.get_file_size)(file_handle, &mut file_size);
55 if status.is_error() {
56 let _ = (shell.close_file)(file_handle);
57 return None;
58 }
59
60 let mut buffer: Vec<u8> = vec![0; file_size as usize];
61 let mut read_size = file_size as usize;
62 let status = (shell.read_file)(file_handle, &mut read_size, buffer.as_mut_ptr().cast());
63
64 let _ = (shell.close_file)(file_handle);
65
66 if status.is_error() {
67 return None;
68 }
69
70 buffer.truncate(read_size);
71 Some(buffer)
72 }
73}
74
75pub fn shell_write_file(path: &str, data: &[u8]) -> Result {
76 let shell = get_shell_protocol();

Callers 3

flash_ecFunction · 0.85
run_with_argsFunction · 0.85
me_infoFunction · 0.85

Calls 1

get_shell_protocolFunction · 0.70

Tested by

no test coverage detected