multiboot2_host/bootinfo/
mod.rs1use byteorder::{WriteBytesExt, LE};
2use std::io::Write;
3
4mod tag;
5pub use tag::{MemMapEntry, RegionType, Tag, TagType};
6
7pub fn bootinfo_size<'a, I: IntoIterator<Item = &'a Tag>>(tags: I) -> u32 {
8 8 + tags.into_iter().map(Tag::size).sum::<u32>()
9}
10
11pub fn write_bootinfo<'a, I, W>(tags: I, mut w: W) -> std::io::Result<()>
12where
13 I: IntoIterator<Item = &'a Tag> + Clone,
15 W: Write,
16{
17 w.write_u32::<LE>(bootinfo_size(tags.clone()))?;
18 w.write_u32::<LE>(0)?;
19
20 let mut final_tag = None;
21 for tag in tags {
22 final_tag = Some(tag);
23 tag.write_to(&mut w)?;
24 }
25
26 match final_tag {
27 Some(Tag::End) => Ok(()),
28 _ => Err(std::io::Error::new(
29 std::io::ErrorKind::InvalidData,
30 "bootinfo tags must end with Tag::End",
31 )),
32 }
33}