xref: /DragonOS/kernel/src/filesystem/mbr.rs (revision 9fab312ea9921618629924ab15c28c2d255b21c6)
1 #![allow(dead_code)]
2 use core::default::Default;
3 
4 /// @brief MBR硬盘分区表项的结构
5 #[repr(packed)]
6 #[derive(Debug, Clone, Copy, Default)]
7 pub struct MbrDiskPartitionTableEntry {
8     pub flags: u8,                     // 引导标志符,标记此分区为活动分区
9     pub starting_head: u8,             // 起始磁头号
10     pub starting_sector_cylinder: u16, // sector : 低6, cylinder : 高10;   起始扇区号 + 起始柱面号
11     pub part_type: u8,                 // 分区类型ID
12     pub ending_head: u8,               // 结束磁头号
13     pub ending_sector_cylingder: u16, // ending_sector : 低6, ending_cylinder : 高10;  结束扇区号 + 结束柱面号
14     pub starting_lba: u32,            // 起始逻辑扇区
15     pub total_sectors: u32,           // 分区占用的磁盘扇区数
16 }
17 
18 impl MbrDiskPartitionTableEntry {
19     pub fn starting_sector(&self) -> u16 {
20         return self.starting_sector_cylinder & ((1 << 6) - 1) as u16;
21     }
22     pub fn starting_cylinder(&self) -> u16 {
23         return (self.starting_sector_cylinder >> 6) & ((1 << 10) - 1) as u16;
24     }
25     pub fn ending_sector(&self) -> u16 {
26         return self.ending_sector_cylingder & ((1 << 6) - 1) as u16;
27     }
28     pub fn ending_cylinder(&self) -> u16 {
29         return (self.ending_sector_cylingder >> 6) & ((1 << 10) - 1) as u16;
30     }
31 }
32 
33 /// @brief MBR磁盘分区表结构体
34 #[repr(packed)]
35 #[derive(Debug, Clone, Copy)]
36 pub struct MbrDiskPartionTable {
37     pub reserved: [u8; 446],
38     pub dpte: [MbrDiskPartitionTableEntry; 4], // 磁盘分区表项
39     pub bs_trailsig: u16,
40 }
41 
42 impl Default for MbrDiskPartionTable {
43     fn default() -> Self {
44         MbrDiskPartionTable {
45             reserved: [0; 446],
46             dpte: [Default::default(); 4],
47             bs_trailsig: Default::default(),
48         }
49     }
50 }
51