]> git.proxmox.com Git - mirror_edk2.git/blob - FatPkg/EnhancedFatDxe/FatFileSystem.h
3f89a3410a57ba4c9cd2cbe538627dc09b128f2b
[mirror_edk2.git] / FatPkg / EnhancedFatDxe / FatFileSystem.h
1 /*++
2
3 Copyright (c) 2005, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials are licensed and made available
5 under the terms and conditions of the BSD License which accompanies this
6 distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12
13 Module Name:
14
15 FatFileSystem.h
16
17 Abstract:
18
19 Definitions for on-disk FAT structures
20
21 Revision History
22
23 --*/
24
25 #ifndef _FATFILESYSTEM_H_
26 #define _FATFILESYSTEM_H_
27
28 #pragma pack(1)
29 //
30 // FAT info signature
31 //
32 #define FAT_INFO_SIGNATURE 0x41615252
33 #define FAT_INFO_BEGIN_SIGNATURE 0x61417272
34 #define FAT_INFO_END_SIGNATURE 0xAA550000
35 //
36 // FAT entry values
37 //
38 #define FAT_CLUSTER_SPECIAL_EXT (-1 & (~0xF))
39 #define FAT_CLUSTER_SPECIAL ((FAT_CLUSTER_SPECIAL_EXT) | 0x07)
40 #define FAT_CLUSTER_FREE 0
41 #define FAT_CLUSTER_RESERVED (FAT_CLUSTER_SPECIAL)
42 #define FAT_CLUSTER_BAD (FAT_CLUSTER_SPECIAL)
43 #define FAT_CLUSTER_LAST (-1)
44 #define FAT_END_OF_FAT_CHAIN(Cluster) ((Cluster) > (FAT_CLUSTER_SPECIAL))
45 #define FAT_MIN_CLUSTER 2
46 #define FAT_MAX_FAT12_CLUSTER 0xFF5
47 #define FAT_MAX_FAT16_CLUSTER 0xFFF5
48 #define FAT_CLUSTER_SPECIAL_FAT12 0xFF7
49 #define FAT_CLUSTER_SPECIAL_FAT16 0xFFF7
50 #define FAT_CLUSTER_SPECIAL_FAT32 0x0FFFFFF7
51 #define FAT_CLUSTER_MASK_FAT12 0xFFF
52 #define FAT_CLUSTER_UNMASK_FAT12 0xF000
53 #define FAT_CLUSTER_MASK_FAT32 0x0FFFFFFF
54 #define FAT_CLUSTER_UNMASK_FAT32 0xF0000000
55 #define FAT_POS_FAT12(a) ((a) * 3 / 2)
56 #define FAT_POS_FAT16(a) ((a) * 2)
57 #define FAT_POS_FAT32(a) ((a) * 4)
58 #define FAT_ODD_CLUSTER_FAT12(a) (((a) & 1) != 0)
59
60
61 //
62 // FAT attribute define
63 //
64 #define FAT_ATTRIBUTE_READ_ONLY 0x01
65 #define FAT_ATTRIBUTE_HIDDEN 0x02
66 #define FAT_ATTRIBUTE_SYSTEM 0x04
67 #define FAT_ATTRIBUTE_VOLUME_ID 0x08
68 #define FAT_ATTRIBUTE_DIRECTORY 0x10
69 #define FAT_ATTRIBUTE_ARCHIVE 0x20
70 #define FAT_ATTRIBUTE_DEVICE 0x40
71 #define FAT_ATTRIBUTE_LFN 0x0F
72 //
73 // Some Long File Name definitions
74 //
75 #define FAT_LFN_LAST 0x40 // Ordinal field
76 #define MAX_LFN_ENTRIES 20
77 #define LFN_CHAR1_LEN 5
78 #define LFN_CHAR2_LEN 6
79 #define LFN_CHAR3_LEN 2
80 #define LFN_CHAR_TOTAL (LFN_CHAR1_LEN + LFN_CHAR2_LEN + LFN_CHAR3_LEN)
81 #define LFN_ENTRY_NUMBER(a) (((a) + LFN_CHAR_TOTAL - 1) / LFN_CHAR_TOTAL)
82 //
83 // Some 8.3 File Name definitions
84 //
85 #define FAT_MAIN_NAME_LEN 8
86 #define FAT_EXTEND_NAME_LEN 3
87 #define FAT_NAME_LEN (FAT_MAIN_NAME_LEN + FAT_EXTEND_NAME_LEN)
88 //
89 // Some directory entry information
90 //
91 #define FAT_ENTRY_INFO_OFFSET 13
92 #define DELETE_ENTRY_MARK 0xE5
93 #define EMPTY_ENTRY_MARK 0x00
94
95 //
96 // Volume dirty Mask
97 //
98 #define FAT16_DIRTY_MASK 0x7fff
99 #define FAT32_DIRTY_MASK 0xf7ffffff
100 //
101 // internal flag
102 //
103 #define FAT_CASE_MIXED 0x01
104 #define FAT_CASE_NAME_LOWER 0x08
105 #define FAT_CASE_EXT_LOWER 0x10
106
107 typedef struct {
108 UINT8 Ia32Jump[3];
109 CHAR8 OemId[8];
110 UINT16 SectorSize;
111 UINT8 SectorsPerCluster;
112 UINT16 ReservedSectors;
113 UINT8 NumFats;
114 UINT16 RootEntries; // < FAT32, root dir is fixed size
115 UINT16 Sectors;
116 UINT8 Media;
117 UINT16 SectorsPerFat; // < FAT32
118 UINT16 SectorsPerTrack; // (ignored)
119 UINT16 Heads; // (ignored)
120 UINT32 HiddenSectors; // (ignored)
121 UINT32 LargeSectors; // Used if Sectors==0
122 } FAT_BOOT_SECTOR_BASIC;
123
124 typedef struct {
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];
131 } FAT_BOOT_SECTOR_EXT;
132
133 typedef struct {
134 UINT32 LargeSectorsPerFat; // FAT32
135 UINT16 ExtendedFlags; // FAT32 (ignored)
136 UINT16 FsVersion; // FAT32 (ignored)
137 UINT32 RootDirFirstCluster; // FAT32
138 UINT16 FsInfoSector; // FAT32
139 UINT16 BackupBootSector; // FAT32
140 UINT8 Reserved[12]; // FAT32 (ignored)
141 UINT8 PhysicalDriveNumber; // (ignored)
142 UINT8 CurrentHead; // holds boot_sector_dirty bit
143 UINT8 Signature; // (ignored)
144 CHAR8 Id[4];
145 CHAR8 FatLabel[11];
146 CHAR8 SystemId[8];
147 } FAT32_BOOT_SECTOR_EXT;
148
149 typedef union {
150 FAT_BOOT_SECTOR_EXT FatBse;
151 FAT32_BOOT_SECTOR_EXT Fat32Bse;
152 } FAT_BSE;
153
154 typedef struct {
155 FAT_BOOT_SECTOR_BASIC FatBsb;
156 FAT_BSE FatBse;
157 } FAT_BOOT_SECTOR;
158
159 //
160 // FAT Info Structure
161 //
162 typedef struct {
163 UINT32 ClusterCount;
164 UINT32 NextCluster;
165 } FAT_FREE_INFO;
166
167 typedef struct {
168 UINT32 Signature;
169 UINT8 ExtraBootCode[480];
170 UINT32 InfoBeginSignature;
171 FAT_FREE_INFO FreeInfo;
172 UINT8 Reserved[12];
173 UINT32 InfoEndSignature;
174 } FAT_INFO_SECTOR;
175
176 //
177 // Directory Entry
178 //
179 #define FAT_MAX_YEAR_FROM_1980 0x7f
180 typedef struct {
181 UINT16 Day : 5;
182 UINT16 Month : 4;
183 UINT16 Year : 7; // From 1980
184 } FAT_DATE;
185
186 typedef struct {
187 UINT16 DoubleSecond : 5;
188 UINT16 Minute : 6;
189 UINT16 Hour : 5;
190 } FAT_TIME;
191
192 typedef struct {
193 FAT_TIME Time;
194 FAT_DATE Date;
195 } FAT_DATE_TIME;
196
197 typedef struct {
198 CHAR8 FileName[11]; // 8.3 filename
199 UINT8 Attributes;
200 UINT8 CaseFlag;
201 UINT8 CreateMillisecond; // (creation milliseconds - ignored)
202 FAT_DATE_TIME FileCreateTime;
203 FAT_DATE FileLastAccess;
204 UINT16 FileClusterHigh; // >= FAT32
205 FAT_DATE_TIME FileModificationTime;
206 UINT16 FileCluster;
207 UINT32 FileSize;
208 } FAT_DIRECTORY_ENTRY;
209
210 typedef struct {
211 UINT8 Ordinal;
212 CHAR8 Name1[10]; // (Really 5 chars, but not WCHAR aligned)
213 UINT8 Attributes;
214 UINT8 Type;
215 UINT8 Checksum;
216 CHAR16 Name2[6];
217 UINT16 MustBeZero;
218 CHAR16 Name3[2];
219 } FAT_DIRECTORY_LFN;
220
221 #pragma pack()
222
223 #endif