fat32.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "fat32.h"
  2. #include <common/kprint.h>
  3. #include <driver/disk/ahci/ahci.h>
  4. /**
  5. * @brief 读取指定磁盘上的第0个分区的fat32文件系统
  6. *
  7. * @param disk_num
  8. */
  9. void fat32_FS_init(int disk_num)
  10. {
  11. int i;
  12. unsigned char buf[512];
  13. struct MBR_disk_partition_table_t DPT;
  14. struct fat32_BootSector_t fat32_bootsector;
  15. struct fat32_FSInfo_t fat32_fsinfo;
  16. memset(buf, 0, 512);
  17. ahci_operation.transfer(ATA_CMD_READ_DMA_EXT, 0, 1, (uint64_t)&buf, 0, 0);
  18. DPT = *(struct MBR_disk_partition_table_t *)buf;
  19. // for(i = 0 ;i < 512 ; i++)
  20. // color_printk(PURPLE,WHITE,"%02x",buf[i]);
  21. printk_color(ORANGE, BLACK, "DPTE[0] start_LBA:%#018lx\ttype:%#018lx\n", DPT.DPTE[0].starting_LBA, DPT.DPTE[0].type);
  22. memset(buf, 0, 512);
  23. ahci_operation.transfer(ATA_CMD_READ_DMA_EXT, DPT.DPTE[0].starting_LBA, 1, (uint64_t)&buf, 0, 0);
  24. fat32_bootsector = *(struct fat32_BootSector_t *)buf;
  25. // for(i = 0 ;i < 512 ; i++)
  26. // printk_color(PURPLE,WHITE,"%02x",buf[i]);
  27. printk_color(ORANGE, BLACK, "FAT32 Boot Sector\n\tBPB_FSInfo:%#018lx\n\tBPB_BkBootSec:%#018lx\n\tBPB_TotSec32:%#018lx\n", fat32_bootsector.BPB_FSInfo, fat32_bootsector.BPB_BkBootSec, fat32_bootsector.BPB_TotSec32);
  28. memset(buf, 0, 512);
  29. ahci_operation.transfer(ATA_CMD_READ_DMA_EXT, DPT.DPTE[0].starting_LBA+ fat32_bootsector.BPB_FSInfo, 1, (uint64_t)&buf, 0, 0);
  30. fat32_fsinfo = *(struct fat32_FSInfo_t *)buf;
  31. // for(i = 0 ;i < 512 ; i++)
  32. // printk_color(PURPLE,WHITE,"%02x",buf[i]);
  33. printk_color(ORANGE, BLACK, "FAT32 FSInfo\n\tFSI_LeadSig:%#018lx\n\tFSI_StrucSig:%#018lx\n\tFSI_Free_Count:%#018lx\n", fat32_fsinfo.FSI_LeadSig, fat32_fsinfo.FSI_StrucSig, fat32_fsinfo.FSI_Free_Count);
  34. }