TianoCore EDK2 master
Loading...
Searching...
No Matches
FatFileSystem.h
Go to the documentation of this file.
1
10#ifndef _FATFILESYSTEM_H_
11#define _FATFILESYSTEM_H_
12
13#pragma pack(1)
14//
15// FAT info signature
16//
17#define FAT_INFO_SIGNATURE 0x41615252
18#define FAT_INFO_BEGIN_SIGNATURE 0x61417272
19#define FAT_INFO_END_SIGNATURE 0xAA550000
20//
21// FAT entry values
22//
23#define FAT_CLUSTER_SPECIAL_EXT (MAX_UINTN & (~0xF))
24#define FAT_CLUSTER_SPECIAL ((FAT_CLUSTER_SPECIAL_EXT) | 0x07)
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#define FAT_END_OF_FAT_CHAIN(Cluster) ((Cluster) > (FAT_CLUSTER_SPECIAL))
30#define FAT_MIN_CLUSTER 2
31#define FAT_MAX_FAT12_CLUSTER 0xFF5
32#define FAT_MAX_FAT16_CLUSTER 0xFFF5
33#define FAT_CLUSTER_SPECIAL_FAT12 0xFF7
34#define FAT_CLUSTER_SPECIAL_FAT16 0xFFF7
35#define FAT_CLUSTER_SPECIAL_FAT32 0x0FFFFFF7
36#define FAT_CLUSTER_MASK_FAT12 0xFFF
37#define FAT_CLUSTER_UNMASK_FAT12 0xF000
38#define FAT_CLUSTER_MASK_FAT32 0x0FFFFFFF
39#define FAT_CLUSTER_UNMASK_FAT32 0xF0000000
40#define FAT_POS_FAT12(a) ((a) * 3 / 2)
41#define FAT_POS_FAT16(a) ((a) * 2)
42#define FAT_POS_FAT32(a) ((a) * 4)
43#define FAT_ODD_CLUSTER_FAT12(a) (((a) & 1) != 0)
44
45//
46// FAT attribute define
47//
48#define FAT_ATTRIBUTE_READ_ONLY 0x01
49#define FAT_ATTRIBUTE_HIDDEN 0x02
50#define FAT_ATTRIBUTE_SYSTEM 0x04
51#define FAT_ATTRIBUTE_VOLUME_ID 0x08
52#define FAT_ATTRIBUTE_DIRECTORY 0x10
53#define FAT_ATTRIBUTE_ARCHIVE 0x20
54#define FAT_ATTRIBUTE_DEVICE 0x40
55#define FAT_ATTRIBUTE_LFN 0x0F
56//
57// Some Long File Name definitions
58//
59#define FAT_LFN_LAST 0x40 // Ordinal field
60#define MAX_LFN_ENTRIES 20
61#define LFN_CHAR1_LEN 5
62#define LFN_CHAR2_LEN 6
63#define LFN_CHAR3_LEN 2
64#define LFN_CHAR_TOTAL (LFN_CHAR1_LEN + LFN_CHAR2_LEN + LFN_CHAR3_LEN)
65#define LFN_ENTRY_NUMBER(a) (((a) + LFN_CHAR_TOTAL - 1) / LFN_CHAR_TOTAL)
66//
67// Some 8.3 File Name definitions
68//
69#define FAT_MAIN_NAME_LEN 8
70#define FAT_EXTEND_NAME_LEN 3
71#define FAT_NAME_LEN (FAT_MAIN_NAME_LEN + FAT_EXTEND_NAME_LEN)
72//
73// Some directory entry information
74//
75#define FAT_ENTRY_INFO_OFFSET 13
76#define DELETE_ENTRY_MARK 0xE5
77#define EMPTY_ENTRY_MARK 0x00
78
79//
80// Volume dirty Mask
81//
82#define FAT16_DIRTY_MASK 0x7fff
83#define FAT32_DIRTY_MASK 0xf7ffffff
84//
85// internal flag
86//
87#define FAT_CASE_MIXED 0x01
88#define FAT_CASE_NAME_LOWER 0x08
89#define FAT_CASE_EXT_LOWER 0x10
90
91typedef struct {
92 UINT8 Ia32Jump[3];
93 CHAR8 OemId[8];
94 UINT16 SectorSize;
95 UINT8 SectorsPerCluster;
96 UINT16 ReservedSectors;
97 UINT8 NumFats;
98 UINT16 RootEntries; // < FAT32, root dir is fixed size
99 UINT16 Sectors;
100 UINT8 Media;
101 UINT16 SectorsPerFat; // < FAT32
102 UINT16 SectorsPerTrack; // (ignored)
103 UINT16 Heads; // (ignored)
104 UINT32 HiddenSectors; // (ignored)
105 UINT32 LargeSectors; // Used if Sectors==0
107
108typedef struct {
109 UINT8 PhysicalDriveNumber; // (ignored)
110 UINT8 CurrentHead; // holds boot_sector_dirty bit
111 UINT8 Signature; // (ignored)
112 CHAR8 Id[4];
113 CHAR8 FatLabel[11];
114 CHAR8 SystemId[8];
116
117typedef struct {
118 UINT32 LargeSectorsPerFat; // FAT32
119 UINT16 ExtendedFlags; // FAT32 (ignored)
120 UINT16 FsVersion; // FAT32 (ignored)
121 UINT32 RootDirFirstCluster; // FAT32
122 UINT16 FsInfoSector; // FAT32
123 UINT16 BackupBootSector; // FAT32
124 UINT8 Reserved[12]; // FAT32 (ignored)
125 UINT8 PhysicalDriveNumber; // (ignored)
126 UINT8 CurrentHead; // holds boot_sector_dirty bit
127 UINT8 Signature; // (ignored)
128 CHAR8 Id[4];
129 CHAR8 FatLabel[11];
130 CHAR8 SystemId[8];
132
133typedef union {
134 FAT_BOOT_SECTOR_EXT FatBse;
135 FAT32_BOOT_SECTOR_EXT Fat32Bse;
136} FAT_BSE;
137
138typedef struct {
140 FAT_BSE FatBse;
142
143//
144// FAT Info Structure
145//
146typedef struct {
147 UINT32 ClusterCount;
148 UINT32 NextCluster;
150
151typedef struct {
152 UINT32 Signature;
153 UINT8 ExtraBootCode[480];
154 UINT32 InfoBeginSignature;
155 FAT_FREE_INFO FreeInfo;
156 UINT8 Reserved[12];
157 UINT32 InfoEndSignature;
159
160//
161// Directory Entry
162//
163#define FAT_MAX_YEAR_FROM_1980 0x7f
164typedef struct {
165 UINT16 Day : 5;
166 UINT16 Month : 4;
167 UINT16 Year : 7; // From 1980
168} FAT_DATE;
169
170typedef struct {
171 UINT16 DoubleSecond : 5;
172 UINT16 Minute : 6;
173 UINT16 Hour : 5;
174} FAT_TIME;
175
176typedef struct {
177 FAT_TIME Time;
178 FAT_DATE Date;
180
181typedef struct {
182 CHAR8 FileName[11]; // 8.3 filename
183 UINT8 Attributes;
184 UINT8 CaseFlag;
185 UINT8 CreateMillisecond; // (creation milliseconds - ignored)
186 FAT_DATE_TIME FileCreateTime;
187 FAT_DATE FileLastAccess;
188 UINT16 FileClusterHigh; // >= FAT32
189 FAT_DATE_TIME FileModificationTime;
190 UINT16 FileCluster;
191 UINT32 FileSize;
193
194typedef struct {
195 UINT8 Ordinal;
196 CHAR8 Name1[10]; // (Really 5 chars, but not WCHAR aligned)
197 UINT8 Attributes;
198 UINT8 Type;
199 UINT8 Checksum;
200 CHAR16 Name2[6];
201 UINT16 MustBeZero;
202 CHAR16 Name3[2];
204
205#pragma pack()
206
207#endif