MBR.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #include <common/blk_types.h>
  14. #define MBR_MAX_AHCI_CTRL_NUM 4 // 系统支持的最大的ahci控制器数量
  15. #define MBR_MAX_AHCI_PORT_NUM 32 // 系统支持的每个ahci控制器对应的MBR磁盘数量(对应ahci磁盘号)
  16. /**
  17. * @brief MBR硬盘分区表项的结构
  18. *
  19. */
  20. struct MBR_disk_partition_table_entry_t
  21. {
  22. uint8_t flags; // 引导标志符,标记此分区为活动分区
  23. uint8_t starting_head; // 起始磁头号
  24. uint16_t starting_sector : 6, // 起始扇区号
  25. starting_cylinder : 10; // 起始柱面号
  26. uint8_t type; // 分区类型ID
  27. uint8_t ending_head; // 结束磁头号
  28. uint16_t ending_sector : 6, // 结束扇区号
  29. ending_cylinder : 10; // 结束柱面号
  30. uint32_t starting_LBA; // 起始逻辑扇区
  31. uint32_t total_sectors; // 分区占用的磁盘扇区数
  32. } __attribute__((packed));
  33. /**
  34. * @brief MBR磁盘分区表结构体
  35. *
  36. */
  37. struct MBR_disk_partition_table_t
  38. {
  39. uint8_t reserved[446];
  40. struct MBR_disk_partition_table_entry_t DPTE[4]; // 磁盘分区表项
  41. uint16_t BS_TrailSig;
  42. } __attribute__((packed));
  43. extern struct MBR_disk_partition_table_t MBR_partition_tables[MBR_MAX_AHCI_CTRL_NUM][MBR_MAX_AHCI_PORT_NUM]; // 导出全局的MBR磁盘分区表
  44. /**
  45. * @brief 读取磁盘的分区表
  46. *
  47. * @param ahci_ctrl_num ahci控制器编号
  48. * @param ahci_port_num ahci端口编号
  49. * @param buf 输出缓冲区(512字节)
  50. */
  51. int MBR_read_partition_table(struct blk_gendisk* gd, void *buf);