limine_protocol_for_rust/
file.rs

1use core::ffi::{c_char, CStr};
2
3#[repr(C, align(8))]
4#[derive(Copy, Clone)]
5pub struct LimineUUID(u16, u16, u16, [u8; 8]);
6
7#[repr(C, align(8))]
8#[derive(Copy, Clone)]
9pub struct LimineFile {
10    revision: u64,
11    pub address: usize,
12    pub size: u64,
13    path: *const c_char,
14    string: *const c_char,
15    media_type: u32,
16    _unused: u32,
17    pub tftp_ip: u32,
18    pub tfpt_port: u32,
19    pub partition_index: u32,
20    pub mbr_disk_id: u32,
21    pub gpt_disk_uuid: LimineUUID,
22    pub gpt_part_uuid: LimineUUID,
23    pub part_uuid: LimineUUID
24}
25
26impl LimineFile {
27    pub fn get_path(&self) -> &str {
28        unsafe {
29            CStr::from_ptr(self.path).to_str().unwrap()
30        }
31    }
32
33    pub fn get_string(&self) -> &str {
34        unsafe {
35            CStr::from_ptr(self.string).to_str().unwrap()
36        }
37    }
38
39    pub fn get_media_type(&self) -> MediaType {
40        MediaType::from(self.media_type)
41    }
42}
43
44pub enum MediaType {
45    Generic,
46    Optical,
47    TFTP
48}
49
50impl From<u32> for MediaType {
51    fn from(value: u32) -> Self {
52        match value {
53            0 => MediaType::Generic,
54            1 => MediaType::Optical,
55            2 => MediaType::TFTP,
56            _ => panic!("Invalid media type")
57        }
58    }
59}