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