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