pub struct Dtb<'a>(/* private fields */);Expand description
设备树二进制对象。
Implementations§
Source§impl Dtb<'static>
impl Dtb<'static>
Sourcepub unsafe fn from_raw_parts(ptr: *const u8) -> Result<Self, HeaderError>
pub unsafe fn from_raw_parts(ptr: *const u8) -> Result<Self, HeaderError>
Sourcepub unsafe fn from_raw_parts_filtered(
ptr: *const u8,
f: impl Fn(&HeaderError) -> bool,
) -> Result<Self, HeaderError>
pub unsafe fn from_raw_parts_filtered( ptr: *const u8, f: impl Fn(&HeaderError) -> bool, ) -> Result<Self, HeaderError>
Examples found in repository?
examples/qemu-virt.rs (lines 15-20)
6fn main() {
7 let mut aligned = vec![0usize; DEVICE_TREE.len() / core::mem::size_of::<usize>()];
8 unsafe {
9 aligned
10 .as_mut_ptr()
11 .copy_from_nonoverlapping(DEVICE_TREE.as_ptr() as _, aligned.len());
12 }
13
14 let dtb = unsafe {
15 Dtb::from_raw_parts_filtered(aligned.as_ptr() as _, |e| {
16 matches!(
17 e,
18 HeaderError::Misaligned(4) | HeaderError::LastCompVersion(16)
19 )
20 })
21 }
22 .unwrap();
23 dtb.walk(|path, obj| match obj {
24 DtbObj::SubNode { name } => {
25 println!("{}{path}/{}", indent(path.level(), INDENT_WIDTH), unsafe {
26 core::str::from_utf8_unchecked(name)
27 });
28 WalkOperation::StepInto
29 }
30 DtbObj::Property(prop) => {
31 let indent = indent(path.level(), INDENT_WIDTH);
32 println!("{indent}{prop:?}");
33 WalkOperation::StepOver
34 }
35 });
36 println!("ok");
37}Sourcepub unsafe fn from_raw_parts_unchecked(ptr: *const u8) -> Self
pub unsafe fn from_raw_parts_unchecked(ptr: *const u8) -> Self
Source§impl<'a> Dtb<'a>
impl<'a> Dtb<'a>
Sourcepub fn from_slice(slice: &'a [u8]) -> Result<Self, ConvertError>
pub fn from_slice(slice: &'a [u8]) -> Result<Self, ConvertError>
从内存切片安全地创建设备树二进制对象。
Source§impl Dtb<'_>
impl Dtb<'_>
Sourcepub const fn total_size(&self) -> usize
pub const fn total_size(&self) -> usize
返回整个二进制对象的尺寸。
Sourcepub fn walk(&self, f: impl FnMut(&Path<'_>, DtbObj<'_>) -> WalkOperation)
pub fn walk(&self, f: impl FnMut(&Path<'_>, DtbObj<'_>) -> WalkOperation)
遍历。
Examples found in repository?
examples/qemu-virt.rs (lines 23-35)
6fn main() {
7 let mut aligned = vec![0usize; DEVICE_TREE.len() / core::mem::size_of::<usize>()];
8 unsafe {
9 aligned
10 .as_mut_ptr()
11 .copy_from_nonoverlapping(DEVICE_TREE.as_ptr() as _, aligned.len());
12 }
13
14 let dtb = unsafe {
15 Dtb::from_raw_parts_filtered(aligned.as_ptr() as _, |e| {
16 matches!(
17 e,
18 HeaderError::Misaligned(4) | HeaderError::LastCompVersion(16)
19 )
20 })
21 }
22 .unwrap();
23 dtb.walk(|path, obj| match obj {
24 DtbObj::SubNode { name } => {
25 println!("{}{path}/{}", indent(path.level(), INDENT_WIDTH), unsafe {
26 core::str::from_utf8_unchecked(name)
27 });
28 WalkOperation::StepInto
29 }
30 DtbObj::Property(prop) => {
31 let indent = indent(path.level(), INDENT_WIDTH);
32 println!("{indent}{prop:?}");
33 WalkOperation::StepOver
34 }
35 });
36 println!("ok");
37}Auto Trait Implementations§
impl<'a> Freeze for Dtb<'a>
impl<'a> RefUnwindSafe for Dtb<'a>
impl<'a> Send for Dtb<'a>
impl<'a> Sync for Dtb<'a>
impl<'a> Unpin for Dtb<'a>
impl<'a> UnsafeUnpin for Dtb<'a>
impl<'a> UnwindSafe for Dtb<'a>
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