#[repr(packed(1))]pub struct File {
pub magic: [u8; 8],
pub len: Be32,
pub kind: Be32,
pub checksum: Be32,
pub offset: Be32,
}
Fields§
§magic: [u8; 8]
§len: Be32
§kind: Be32
§checksum: Be32
§offset: Be32
Implementations§
Source§impl File
impl File
Sourcepub fn name(&self) -> &[u8]
pub fn name(&self) -> &[u8]
Examples found in repository?
examples/file.rs (line 40)
4fn inner(path: &str) -> io::Result<()> {
5 let data = fs::read(path)?;
6 let rom = Rom::new(&data);
7
8 if let Some(fmap) = rom.fmap() {
9 let mut name = String::new();
10 for &b in fmap.name.iter() {
11 if b == 0 {
12 break;
13 }
14 name.push(b as char);
15 }
16
17 eprintln!(" {}", name);
18
19 for i in 0..fmap.nareas {
20 let area = fmap.area(i);
21
22 let mut name = String::new();
23 for &b in area.name.iter() {
24 if b == 0 {
25 break;
26 }
27 name.push(b as char);
28 }
29
30 eprintln!(" {}: {}", i, name);
31 }
32 }
33
34 if let Some(header) = rom.header() {
35 eprintln!(" CBFS");
36
37 let align = u32::from(header.align) as usize;
38 let mut offset = u32::from(header.offset) as usize;
39 while let Some(file) = rom.file(offset) {
40 let name_bytes = file.name();
41
42 let mut name = String::new();
43 for &b in name_bytes.iter() {
44 if b == 0 {
45 break;
46 }
47 name.push(b as char);
48 }
49
50 eprintln!(" {:#X}: {}", offset, name);
51
52 let file_offset = u32::from(file.offset) as usize;
53 let file_len = u32::from(file.len) as usize;
54 offset = ((offset + file_offset + file_len + align - 1) / align) * align;
55 }
56 } else {
57 eprintln!("coreboot header not found");
58 }
59
60 Ok(())
61}
pub fn data(&self) -> &[u8]
Trait Implementations§
Source§impl Plain for File
impl Plain for File
fn from_bytes(bytes: &[u8]) -> Result<&Self, Error>where
Self: Sized,
fn slice_from_bytes(bytes: &[u8]) -> Result<&[Self], Error>where
Self: Sized,
fn slice_from_bytes_len(bytes: &[u8], len: usize) -> Result<&[Self], Error>where
Self: Sized,
fn from_mut_bytes(bytes: &mut [u8]) -> Result<&mut Self, Error>where
Self: Sized,
fn slice_from_mut_bytes(bytes: &mut [u8]) -> Result<&mut [Self], Error>where
Self: Sized,
fn slice_from_mut_bytes_len(
bytes: &mut [u8],
len: usize,
) -> Result<&mut [Self], Error>where
Self: Sized,
fn copy_from_bytes(&mut self, bytes: &[u8]) -> Result<(), Error>
impl Copy for File
Auto Trait Implementations§
impl Freeze for File
impl RefUnwindSafe for File
impl Send for File
impl Sync for File
impl Unpin for File
impl UnwindSafe for File
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more