multiboot2/
bootdev.rs

1//! Module for [`BootdevTag`].
2
3use crate::{TagHeader, TagType};
4use core::mem;
5use multiboot2_common::{MaybeDynSized, Tag};
6
7/// The end tag ends the information struct.
8#[derive(Debug)]
9#[repr(C, align(8))]
10pub struct BootdevTag {
11    header: TagHeader,
12    biosdev: u32,
13    slice: u32,
14    part: u32,
15}
16
17impl BootdevTag {
18    /// Creates a new tag.
19    #[must_use]
20    pub fn new(biosdev: u32, slice: u32, part: u32) -> Self {
21        Self {
22            header: TagHeader::new(Self::ID, mem::size_of::<Self>() as u32),
23            biosdev,
24            slice,
25            part,
26        }
27    }
28
29    /// Returns the bios device from which the device was booted from.
30    /// `0x00` represents the first floppy disk.
31    /// `0x80` represents the first hard disk, 0x81 the second hard disk, and
32    /// so on.
33    #[must_use]
34    pub const fn biosdev(&self) -> u32 {
35        self.biosdev
36    }
37
38    /// The slice field identifies the partition (also known as a "slice" in BSD
39    /// terminology) on the BIOS device from which the operating system was
40    /// booted.
41    #[must_use]
42    pub const fn slice(&self) -> u32 {
43        self.slice
44    }
45
46    /// The part field denotes the subpartition or logical partition within the
47    /// primary partition (if applicable) from which the operating system was
48    /// booted.
49    #[must_use]
50    pub const fn part(&self) -> u32 {
51        self.part
52    }
53}
54
55impl MaybeDynSized for BootdevTag {
56    type Header = TagHeader;
57
58    const BASE_SIZE: usize = mem::size_of::<Self>();
59
60    fn dst_len(_: &TagHeader) {}
61}
62
63impl Tag for BootdevTag {
64    type IDType = TagType;
65
66    const ID: TagType = TagType::Bootdev;
67}