FatLiteFmt.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /** @file
  2. FAT format data structures
  3. Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef _FAT_FMT_H_
  7. #define _FAT_FMT_H_
  8. //
  9. // Definitions
  10. //
  11. #define FAT_ATTR_READ_ONLY 0x01
  12. #define FAT_ATTR_HIDDEN 0x02
  13. #define FAT_ATTR_SYSTEM 0x04
  14. #define FAT_ATTR_VOLUME_ID 0x08
  15. #define FAT_ATTR_DIRECTORY 0x10
  16. #define FAT_ATTR_ARCHIVE 0x20
  17. #define FAT_ATTR_LFN (FAT_ATTR_READ_ONLY | FAT_ATTR_HIDDEN | FAT_ATTR_SYSTEM | FAT_ATTR_VOLUME_ID)
  18. #define FAT_CLUSTER_SPECIAL ((MAX_UINT32 &~0xF) | 0x7)
  19. #define FAT_CLUSTER_FREE 0
  20. #define FAT_CLUSTER_RESERVED (FAT_CLUSTER_SPECIAL)
  21. #define FAT_CLUSTER_BAD (FAT_CLUSTER_SPECIAL)
  22. #define FAT_CLUSTER_LAST (-1)
  23. #define DELETE_ENTRY_MARK 0xE5
  24. #define EMPTY_ENTRY_MARK 0x00
  25. #define FAT_CLUSTER_FUNCTIONAL(Cluster) (((Cluster) == 0) || ((Cluster) >= FAT_CLUSTER_SPECIAL))
  26. #define FAT_CLUSTER_END_OF_CHAIN(Cluster) ((Cluster) > (FAT_CLUSTER_SPECIAL))
  27. //
  28. // Directory Entry
  29. //
  30. #pragma pack(1)
  31. typedef struct {
  32. UINT16 Day : 5;
  33. UINT16 Month : 4;
  34. UINT16 Year : 7; // From 1980
  35. } FAT_DATE;
  36. typedef struct {
  37. UINT16 DoubleSecond : 5;
  38. UINT16 Minute : 6;
  39. UINT16 Hour : 5;
  40. } FAT_TIME;
  41. typedef struct {
  42. FAT_TIME Time;
  43. FAT_DATE Date;
  44. } FAT_DATE_TIME;
  45. typedef struct {
  46. CHAR8 FileName[11]; // 8.3 filename
  47. UINT8 Attributes;
  48. UINT8 CaseFlag;
  49. UINT8 CreateMillisecond; // (creation milliseconds - ignored)
  50. FAT_DATE_TIME FileCreateTime;
  51. FAT_DATE FileLastAccess;
  52. UINT16 FileClusterHigh; // >= FAT32
  53. FAT_DATE_TIME FileModificationTime;
  54. UINT16 FileCluster;
  55. UINT32 FileSize;
  56. } FAT_DIRECTORY_ENTRY;
  57. #pragma pack()
  58. //
  59. // Boot Sector
  60. //
  61. #pragma pack(1)
  62. typedef struct {
  63. UINT8 Ia32Jump[3];
  64. CHAR8 OemId[8];
  65. UINT16 SectorSize;
  66. UINT8 SectorsPerCluster;
  67. UINT16 ReservedSectors;
  68. UINT8 NoFats;
  69. UINT16 RootEntries; // < FAT32, root dir is fixed size
  70. UINT16 Sectors;
  71. UINT8 Media; // (ignored)
  72. UINT16 SectorsPerFat; // < FAT32
  73. UINT16 SectorsPerTrack; // (ignored)
  74. UINT16 Heads; // (ignored)
  75. UINT32 HiddenSectors; // (ignored)
  76. UINT32 LargeSectors; // => FAT32
  77. UINT8 PhysicalDriveNumber; // (ignored)
  78. UINT8 CurrentHead; // holds boot_sector_dirty bit
  79. UINT8 Signature; // (ignored)
  80. CHAR8 Id[4];
  81. CHAR8 FatLabel[11];
  82. CHAR8 SystemId[8];
  83. } PEI_FAT_BOOT_SECTOR;
  84. typedef struct {
  85. UINT8 Ia32Jump[3];
  86. CHAR8 OemId[8];
  87. UINT16 SectorSize;
  88. UINT8 SectorsPerCluster;
  89. UINT16 ReservedSectors;
  90. UINT8 NoFats;
  91. UINT16 RootEntries; // < FAT32, root dir is fixed size
  92. UINT16 Sectors;
  93. UINT8 Media; // (ignored)
  94. UINT16 SectorsPerFat; // < FAT32
  95. UINT16 SectorsPerTrack; // (ignored)
  96. UINT16 Heads; // (ignored)
  97. UINT32 HiddenSectors; // (ignored)
  98. UINT32 LargeSectors; // Used if Sectors==0
  99. UINT32 LargeSectorsPerFat; // FAT32
  100. UINT16 ExtendedFlags; // FAT32 (ignored)
  101. UINT16 FsVersion; // FAT32 (ignored)
  102. UINT32 RootDirFirstCluster; // FAT32
  103. UINT16 FsInfoSector; // FAT32
  104. UINT16 BackupBootSector; // FAT32
  105. UINT8 Reserved[12]; // FAT32 (ignored)
  106. UINT8 PhysicalDriveNumber; // (ignored)
  107. UINT8 CurrentHead; // holds boot_sector_dirty bit
  108. UINT8 Signature; // (ignored)
  109. CHAR8 Id[4];
  110. CHAR8 FatLabel[11];
  111. CHAR8 SystemId[8];
  112. } PEI_FAT_BOOT_SECTOR_EX;
  113. #pragma pack()
  114. #endif