2 Definitions for on-disk FAT structures.
4 Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available
6 under the terms and conditions of the BSD License which accompanies this
7 distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #ifndef _FATFILESYSTEM_H_
17 #define _FATFILESYSTEM_H_
23 #define FAT_INFO_SIGNATURE 0x41615252
24 #define FAT_INFO_BEGIN_SIGNATURE 0x61417272
25 #define FAT_INFO_END_SIGNATURE 0xAA550000
29 #define FAT_CLUSTER_SPECIAL_EXT (MAX_UINTN & (~0xF))
30 #define FAT_CLUSTER_SPECIAL ((FAT_CLUSTER_SPECIAL_EXT) | 0x07)
31 #define FAT_CLUSTER_FREE 0
32 #define FAT_CLUSTER_RESERVED (FAT_CLUSTER_SPECIAL)
33 #define FAT_CLUSTER_BAD (FAT_CLUSTER_SPECIAL)
34 #define FAT_CLUSTER_LAST (-1)
35 #define FAT_END_OF_FAT_CHAIN(Cluster) ((Cluster) > (FAT_CLUSTER_SPECIAL))
36 #define FAT_MIN_CLUSTER 2
37 #define FAT_MAX_FAT12_CLUSTER 0xFF5
38 #define FAT_MAX_FAT16_CLUSTER 0xFFF5
39 #define FAT_CLUSTER_SPECIAL_FAT12 0xFF7
40 #define FAT_CLUSTER_SPECIAL_FAT16 0xFFF7
41 #define FAT_CLUSTER_SPECIAL_FAT32 0x0FFFFFF7
42 #define FAT_CLUSTER_MASK_FAT12 0xFFF
43 #define FAT_CLUSTER_UNMASK_FAT12 0xF000
44 #define FAT_CLUSTER_MASK_FAT32 0x0FFFFFFF
45 #define FAT_CLUSTER_UNMASK_FAT32 0xF0000000
46 #define FAT_POS_FAT12(a) ((a) * 3 / 2)
47 #define FAT_POS_FAT16(a) ((a) * 2)
48 #define FAT_POS_FAT32(a) ((a) * 4)
49 #define FAT_ODD_CLUSTER_FAT12(a) (((a) & 1) != 0)
53 // FAT attribute define
55 #define FAT_ATTRIBUTE_READ_ONLY 0x01
56 #define FAT_ATTRIBUTE_HIDDEN 0x02
57 #define FAT_ATTRIBUTE_SYSTEM 0x04
58 #define FAT_ATTRIBUTE_VOLUME_ID 0x08
59 #define FAT_ATTRIBUTE_DIRECTORY 0x10
60 #define FAT_ATTRIBUTE_ARCHIVE 0x20
61 #define FAT_ATTRIBUTE_DEVICE 0x40
62 #define FAT_ATTRIBUTE_LFN 0x0F
64 // Some Long File Name definitions
66 #define FAT_LFN_LAST 0x40 // Ordinal field
67 #define MAX_LFN_ENTRIES 20
68 #define LFN_CHAR1_LEN 5
69 #define LFN_CHAR2_LEN 6
70 #define LFN_CHAR3_LEN 2
71 #define LFN_CHAR_TOTAL (LFN_CHAR1_LEN + LFN_CHAR2_LEN + LFN_CHAR3_LEN)
72 #define LFN_ENTRY_NUMBER(a) (((a) + LFN_CHAR_TOTAL - 1) / LFN_CHAR_TOTAL)
74 // Some 8.3 File Name definitions
76 #define FAT_MAIN_NAME_LEN 8
77 #define FAT_EXTEND_NAME_LEN 3
78 #define FAT_NAME_LEN (FAT_MAIN_NAME_LEN + FAT_EXTEND_NAME_LEN)
80 // Some directory entry information
82 #define FAT_ENTRY_INFO_OFFSET 13
83 #define DELETE_ENTRY_MARK 0xE5
84 #define EMPTY_ENTRY_MARK 0x00
89 #define FAT16_DIRTY_MASK 0x7fff
90 #define FAT32_DIRTY_MASK 0xf7ffffff
94 #define FAT_CASE_MIXED 0x01
95 #define FAT_CASE_NAME_LOWER 0x08
96 #define FAT_CASE_EXT_LOWER 0x10
102 UINT8 SectorsPerCluster
;
103 UINT16 ReservedSectors
;
105 UINT16 RootEntries
; // < FAT32, root dir is fixed size
108 UINT16 SectorsPerFat
; // < FAT32
109 UINT16 SectorsPerTrack
; // (ignored)
110 UINT16 Heads
; // (ignored)
111 UINT32 HiddenSectors
; // (ignored)
112 UINT32 LargeSectors
; // Used if Sectors==0
113 } FAT_BOOT_SECTOR_BASIC
;
116 UINT8 PhysicalDriveNumber
; // (ignored)
117 UINT8 CurrentHead
; // holds boot_sector_dirty bit
118 UINT8 Signature
; // (ignored)
122 } FAT_BOOT_SECTOR_EXT
;
125 UINT32 LargeSectorsPerFat
; // FAT32
126 UINT16 ExtendedFlags
; // FAT32 (ignored)
127 UINT16 FsVersion
; // FAT32 (ignored)
128 UINT32 RootDirFirstCluster
; // FAT32
129 UINT16 FsInfoSector
; // FAT32
130 UINT16 BackupBootSector
; // FAT32
131 UINT8 Reserved
[12]; // FAT32 (ignored)
132 UINT8 PhysicalDriveNumber
; // (ignored)
133 UINT8 CurrentHead
; // holds boot_sector_dirty bit
134 UINT8 Signature
; // (ignored)
138 } FAT32_BOOT_SECTOR_EXT
;
141 FAT_BOOT_SECTOR_EXT FatBse
;
142 FAT32_BOOT_SECTOR_EXT Fat32Bse
;
146 FAT_BOOT_SECTOR_BASIC FatBsb
;
151 // FAT Info Structure
160 UINT8 ExtraBootCode
[480];
161 UINT32 InfoBeginSignature
;
162 FAT_FREE_INFO FreeInfo
;
164 UINT32 InfoEndSignature
;
170 #define FAT_MAX_YEAR_FROM_1980 0x7f
174 UINT16 Year
: 7; // From 1980
178 UINT16 DoubleSecond
: 5;
189 CHAR8 FileName
[11]; // 8.3 filename
192 UINT8 CreateMillisecond
; // (creation milliseconds - ignored)
193 FAT_DATE_TIME FileCreateTime
;
194 FAT_DATE FileLastAccess
;
195 UINT16 FileClusterHigh
; // >= FAT32
196 FAT_DATE_TIME FileModificationTime
;
199 } FAT_DIRECTORY_ENTRY
;
203 CHAR8 Name1
[10]; // (Really 5 chars, but not WCHAR aligned)