MBR.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * @file MBR.h
  3. * @author fslongjin ([email protected])
  4. * @brief MBR分区表
  5. * @version 0.1
  6. * @date 2022-04-19
  7. *
  8. * @copyright Copyright (c) 2022
  9. *
  10. */
  11. #pragma once
  12. #include <common/glib.h>
  13. #define MBR_MAX_AHCI_CTRL_NUM 4 // 系统支持的最大的ahci控制器数量
  14. #define MBR_MAX_AHCI_PORT_NUM 32 // 系统支持的每个ahci控制器对应的MBR磁盘数量(对应ahci磁盘号)
  15. /**
  16. * @brief MBR硬盘分区表项的结构
  17. *
  18. */
  19. struct MBR_disk_partition_table_entry_t
  20. {
  21. uint8_t flags; // 引导标志符,标记此分区为活动分区
  22. uint8_t starting_head; // 起始磁头号
  23. uint16_t starting_sector : 6, // 起始扇区号
  24. starting_cylinder : 10; // 起始柱面号
  25. uint8_t type; // 分区类型ID
  26. uint8_t ending_head; // 结束磁头号
  27. uint16_t ending_sector : 6, // 结束扇区号
  28. ending_cylinder : 10; // 结束柱面号
  29. uint32_t starting_LBA; // 起始逻辑扇区
  30. uint32_t total_sectors; // 分区占用的磁盘扇区数
  31. } __attribute__((packed));
  32. /**
  33. * @brief MBR磁盘分区表结构体
  34. *
  35. */
  36. struct MBR_disk_partition_table_t
  37. {
  38. uint8_t reserved[446];
  39. struct MBR_disk_partition_table_entry_t DPTE[4]; // 磁盘分区表项
  40. uint16_t BS_TrailSig;
  41. } __attribute__((packed));
  42. extern struct MBR_disk_partition_table_t MBR_partition_tables[MBR_MAX_AHCI_CTRL_NUM][MBR_MAX_AHCI_PORT_NUM]; // 导出全局的MBR磁盘分区表
  43. /**
  44. * @brief 读取磁盘的分区表
  45. *
  46. * @param ahci_ctrl_num ahci控制器编号
  47. * @param ahci_port_num ahci端口编号
  48. */
  49. struct MBR_disk_partition_table_t *MBR_read_partition_table(uint8_t ahci_ctrl_num, uint8_t ahci_port_num);