xref: /DragonOS/kernel/src/filesystem/mbr.rs (revision 8d72b68da9339ec97e1b8929bcf2946f0fd83cd5)
1 #![allow(dead_code)]
2 use core::default::Default;
3 
4 /// @brief MBR硬盘分区表项的结构
5 #[repr(packed)]
6 #[derive(Debug, Clone, Copy)]
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 MbrDiskPartitionTableEntry {
43     fn default() -> Self {
44         MbrDiskPartitionTableEntry {
45             flags: 0,
46             starting_head: 0,
47             starting_sector_cylinder: 0,
48             part_type: 0,
49             ending_head: 0,
50             ending_sector_cylingder: 0,
51             starting_lba: 0,
52             total_sectors: 0,
53         }
54     }
55 }
56 
57 impl Default for MbrDiskPartionTable {
58     fn default() -> Self {
59         MbrDiskPartionTable {
60             reserved: [0; 446],
61             dpte: [Default::default(); 4],
62             bs_trailsig: Default::default(),
63         }
64     }
65 }
66