ReactOS  0.4.14-dev-1007-g90d795b
fat.h
Go to the documentation of this file.
1 /*
2  * FreeLoader
3  * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #pragma once
21 
22 #include <pshpack1.h>
23 typedef struct _FAT_BOOTSECTOR
24 {
25  UCHAR JumpBoot[3]; // Jump instruction to boot code
26  CHAR OemName[8]; // "MSWIN4.1" for MS formatted volumes
27  USHORT BytesPerSector; // Bytes per sector
28  UCHAR SectorsPerCluster; // Number of sectors in a cluster
29  USHORT ReservedSectors; // Reserved sectors, usually 1 (the bootsector)
30  UCHAR NumberOfFats; // Number of FAT tables
31  USHORT RootDirEntries; // Number of root directory entries (fat12/16)
32  USHORT TotalSectors; // Number of total sectors on the drive, 16-bit
33  UCHAR MediaDescriptor; // Media descriptor byte
34  USHORT SectorsPerFat; // Sectors per FAT table (fat12/16)
35  USHORT SectorsPerTrack; // Number of sectors in a track
36  USHORT NumberOfHeads; // Number of heads on the disk
37  ULONG HiddenSectors; // Hidden sectors (sectors before the partition start like the partition table)
38  ULONG TotalSectorsBig; // This field is the new 32-bit total count of sectors on the volume
39  UCHAR DriveNumber; // Int 0x13 drive number (e.g. 0x80)
40  UCHAR Reserved1; // Reserved (used by Windows NT). Code that formats FAT volumes should always set this byte to 0.
41  UCHAR BootSignature; // Extended boot signature (0x29). This is a signature byte that indicates that the following three fields in the boot sector are present.
42  ULONG VolumeSerialNumber; // Volume serial number
43  CHAR VolumeLabel[11]; // Volume label. This field matches the 11-byte volume label recorded in the root directory
44  CHAR FileSystemType[8]; // One of the strings "FAT12 ", "FAT16 ", or "FAT "
45 
46  UCHAR BootCodeAndData[448]; // The remainder of the boot sector
47 
48  USHORT BootSectorMagic; // 0xAA55
49 
51 
52 typedef struct _FAT32_BOOTSECTOR
53 {
54  UCHAR JumpBoot[3]; // Jump instruction to boot code
55  CHAR OemName[8]; // "MSWIN4.1" for MS formatted volumes
56  USHORT BytesPerSector; // Bytes per sector
57  UCHAR SectorsPerCluster; // Number of sectors in a cluster
58  USHORT ReservedSectors; // Reserved sectors, usually 1 (the bootsector)
59  UCHAR NumberOfFats; // Number of FAT tables
60  USHORT RootDirEntries; // Number of root directory entries (fat12/16)
61  USHORT TotalSectors; // Number of total sectors on the drive, 16-bit
62  UCHAR MediaDescriptor; // Media descriptor byte
63  USHORT SectorsPerFat; // Sectors per FAT table (fat12/16)
64  USHORT SectorsPerTrack; // Number of sectors in a track
65  USHORT NumberOfHeads; // Number of heads on the disk
66  ULONG HiddenSectors; // Hidden sectors (sectors before the partition start like the partition table)
67  ULONG TotalSectorsBig; // This field is the new 32-bit total count of sectors on the volume
68  ULONG SectorsPerFatBig; // This field is the FAT32 32-bit count of sectors occupied by ONE FAT. BPB_FATSz16 must be 0
69  USHORT ExtendedFlags; // Extended flags (fat32)
70  USHORT FileSystemVersion; // File system version (fat32)
71  ULONG RootDirStartCluster; // Starting cluster of the root directory (fat32)
72  USHORT FsInfo; // Sector number of FSINFO structure in the reserved area of the FAT32 volume. Usually 1.
73  USHORT BackupBootSector; // If non-zero, indicates the sector number in the reserved area of the volume of a copy of the boot record. Usually 6.
74  UCHAR Reserved[12]; // Reserved for future expansion
75  UCHAR DriveNumber; // Int 0x13 drive number (e.g. 0x80)
76  UCHAR Reserved1; // Reserved (used by Windows NT). Code that formats FAT volumes should always set this byte to 0.
77  UCHAR BootSignature; // Extended boot signature (0x29). This is a signature byte that indicates that the following three fields in the boot sector are present.
78  ULONG VolumeSerialNumber; // Volume serial number
79  CHAR VolumeLabel[11]; // Volume label. This field matches the 11-byte volume label recorded in the root directory
80  CHAR FileSystemType[8]; // Always set to the string "FAT32 "
81 
82  UCHAR BootCodeAndData[420]; // The remainder of the boot sector
83 
84  USHORT BootSectorMagic; // 0xAA55
85 
87 
88 typedef struct _FATX_BOOTSECTOR
89 {
90  CHAR FileSystemType[4]; /* String "FATX" */
91  ULONG VolumeSerialNumber; /* Volume serial number */
92  ULONG SectorsPerCluster; /* Number of sectors in a cluster */
93  USHORT NumberOfFats; /* Number of FAT tables */
94  ULONG Unknown; /* Always 0? */
95  UCHAR Unused[494]; /* Actually size should be 4078 (boot block is 4096 bytes) */
96 
98 
99 /*
100  * Structure of MSDOS directory entry
101  */
102 typedef struct //_DIRENTRY
103 {
104  CHAR FileName[11]; /* Filename + extension */
105  UCHAR Attr; /* File attributes */
106  UCHAR ReservedNT; /* Reserved for use by Windows NT */
107  UCHAR TimeInTenths; /* Millisecond stamp at file creation */
108  USHORT CreateTime; /* Time file was created */
109  USHORT CreateDate; /* Date file was created */
110  USHORT LastAccessDate; /* Date file was last accessed */
111  USHORT ClusterHigh; /* High word of this entry's start cluster */
112  USHORT Time; /* Time last modified */
113  USHORT Date; /* Date last modified */
114  USHORT ClusterLow; /* First cluster number low word */
115  ULONG Size; /* File size */
116 } DIRENTRY, * PDIRENTRY;
117 
118 typedef struct
119 {
120  UCHAR SequenceNumber; /* Sequence number for slot */
121  WCHAR Name0_4[5]; /* First 5 characters in name */
122  UCHAR EntryAttributes; /* Attribute byte */
123  UCHAR Reserved; /* Always 0 */
124  UCHAR AliasChecksum; /* Checksum for 8.3 alias */
125  WCHAR Name5_10[6]; /* 6 more characters in name */
126  USHORT StartCluster; /* Starting cluster number */
127  WCHAR Name11_12[2]; /* Last 2 characters in name */
129 
130 typedef struct
131 {
132  UCHAR FileNameSize; /* Size of filename (max 42) */
133  UCHAR Attr; /* File attributes */
134  CHAR FileName[42]; /* Filename in ASCII, padded with 0xff (not zero-terminated) */
135  ULONG StartCluster; /* Starting cluster number */
136  ULONG Size; /* File size */
137  USHORT Time; /* Time last modified */
138  USHORT Date; /* Date last modified */
139  USHORT CreateTime; /* Time file was created */
140  USHORT CreateDate; /* Date file was created */
141  USHORT LastAccessTime; /* Time file was last accessed */
142  USHORT LastAccessDate; /* Date file was last accessed */
144 #include <poppack.h>
145 
147 
148 typedef struct
149 {
151  ULONG FileSize; /* File size */
152  ULONG FilePointer; /* File pointer */
153  ULONG CurrentCluster; /* The cluster for file pointer */
154  ULONG StartCluster; /* The first cluster for file */
155  UCHAR Attributes; /* File attributes */
157 
158 #define ATTR_NORMAL 0x00
159 #define ATTR_READONLY 0x01
160 #define ATTR_HIDDEN 0x02
161 #define ATTR_SYSTEM 0x04
162 #define ATTR_VOLUMENAME 0x08
163 #define ATTR_DIRECTORY 0x10
164 #define ATTR_ARCHIVE 0x20
165 #define ATTR_LONG_NAME (ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | ATTR_VOLUMENAME)
166 
167 #define FAT12 1
168 #define FAT16 2
169 #define FAT32 3
170 #define FATX16 4
171 #define FATX32 5
172 
173 #define ISFATX(FT) ((FT) == FATX16 || (FT) == FATX32)
174 
USHORT BytesPerSector
Definition: bootsup.c:79
UCHAR FileNameSize
Definition: fat.h:132
UCHAR SectorsPerCluster
Definition: bootsup.c:51
UCHAR EntryAttributes
Definition: fat.h:122
USHORT CreateTime
Definition: fat.h:139
struct DIRENTRY * PDIRENTRY
UCHAR SectorsPerCluster
Definition: bootsup.c:80
UCHAR SequenceNumber
Definition: fat.h:120
USHORT TotalSectors
Definition: bootsup.c:55
const DEVVTBL * FatMount(ULONG DeviceId)
Definition: fat.c:1552
UCHAR Reserved1
Definition: bootsup.c:99
USHORT BootSectorMagic
Definition: bootsup.c:107
char CHAR
Definition: xmlstorage.h:175
USHORT CreateDate
Definition: fat.h:140
struct _FAT32_BOOTSECTOR * PFAT32_BOOTSECTOR
USHORT Date
Definition: fat.h:138
UCHAR JumpBoot[3]
Definition: bootsup.c:77
Definition: fs.h:24
ULONG StartCluster
Definition: fat.h:154
PFAT_VOLUME_INFO Volume
Definition: fat.h:150
struct _FAT32_BOOTSECTOR FAT32_BOOTSECTOR
ULONG TotalSectorsBig
Definition: bootsup.c:90
USHORT Time
Definition: fat.h:112
struct FAT_FILE_INFO * PFAT_FILE_INFO
struct FATX_DIRENTRY * PFATX_DIRENTRY
USHORT StartCluster
Definition: fat.h:126
USHORT Date
Definition: fat.h:113
ULONG VolumeSerialNumber
Definition: bootsup.c:101
USHORT CreateDate
Definition: fat.h:109
UCHAR Attr
Definition: fat.h:105
USHORT BytesPerSector
Definition: bootsup.c:50
CHAR VolumeLabel[11]
Definition: bootsup.c:66
UCHAR TimeInTenths
Definition: fat.h:107
struct _FAT_VOLUME_INFO * PFAT_VOLUME_INFO
Definition: fat.h:146
struct LFN_DIRENTRY * PLFN_DIRENTRY
USHORT LastAccessDate
Definition: fat.h:142
USHORT LastAccessDate
Definition: fat.h:110
UCHAR Unused[494]
Definition: fat.h:95
USHORT Time
Definition: fat.h:137
UCHAR AliasChecksum
Definition: fat.h:124
ULONG SectorsPerFatBig
Definition: bootsup.c:91
USHORT RootDirEntries
Definition: bootsup.c:54
CHAR OemName[8]
Definition: bootsup.c:49
UCHAR JumpBoot[3]
Definition: bootsup.c:48
struct _FAT_BOOTSECTOR * PFAT_BOOTSECTOR
ULONG FilePointer
Definition: fat.h:152
USHORT ClusterHigh
Definition: fat.h:111
USHORT NumberOfHeads
Definition: bootsup.c:59
struct tagDIRENTRY DIRENTRY
USHORT CreateTime
Definition: fat.h:108
UCHAR BootCodeAndData[448]
Definition: bootsup.c:69
_Reserved_ PVOID Reserved
Definition: winddi.h:3974
USHORT NumberOfFats
Definition: fat.h:93
CHAR FileSystemType[8]
Definition: bootsup.c:103
UCHAR BootSignature
Definition: bootsup.c:64
USHORT RootDirEntries
Definition: bootsup.c:83
ULONG Size
Definition: fat.h:136
USHORT ReservedSectors
Definition: bootsup.c:52
USHORT ReservedSectors
Definition: bootsup.c:81
__wchar_t WCHAR
Definition: xmlstorage.h:180
CHAR OemName[8]
Definition: bootsup.c:78
ULONG CurrentCluster
Definition: fat.h:153
UCHAR Reserved1
Definition: bootsup.c:63
USHORT SectorsPerFat
Definition: bootsup.c:57
UCHAR BootSignature
Definition: bootsup.c:100
USHORT BackupBootSector
Definition: bootsup.c:96
USHORT BootSectorMagic
Definition: bootsup.c:71
UCHAR NumberOfFats
Definition: bootsup.c:53
CHAR VolumeLabel[11]
Definition: bootsup.c:102
UCHAR DriveNumber
Definition: bootsup.c:98
unsigned char UCHAR
Definition: xmlstorage.h:181
ULONG DeviceId
Definition: fat.c:51
USHORT TotalSectors
Definition: bootsup.c:84
ULONG StartCluster
Definition: fat.h:135
USHORT ClusterLow
Definition: fat.h:114
USHORT SectorsPerTrack
Definition: bootsup.c:87
ULONG VolumeSerialNumber
Definition: bootsup.c:65
ULONG Unknown
Definition: fat.h:94
UCHAR MediaDescriptor
Definition: bootsup.c:85
UCHAR ReservedNT
Definition: fat.h:106
USHORT SectorsPerTrack
Definition: bootsup.c:58
struct _FATX_BOOTSECTOR FATX_BOOTSECTOR
ULONG Size
Definition: fat.h:115
USHORT LastAccessTime
Definition: fat.h:141
USHORT FileSystemVersion
Definition: bootsup.c:93
USHORT FsInfo
Definition: bootsup.c:95
ULONG FileSize
Definition: fat.h:151
unsigned short USHORT
Definition: pedump.c:61
UCHAR Attr
Definition: fat.h:133
UCHAR MediaDescriptor
Definition: bootsup.c:56
CHAR FileSystemType[8]
Definition: bootsup.c:67
ULONG VolumeSerialNumber
Definition: fat.h:91
USHORT SectorsPerFat
Definition: bootsup.c:86
UCHAR NumberOfFats
Definition: bootsup.c:82
ULONG SectorsPerCluster
Definition: fat.h:92
struct _FAT_BOOTSECTOR FAT_BOOTSECTOR
USHORT NumberOfHeads
Definition: bootsup.c:88
ULONG TotalSectorsBig
Definition: bootsup.c:61
ULONG HiddenSectors
Definition: bootsup.c:60
ULONG HiddenSectors
Definition: bootsup.c:89
unsigned int ULONG
Definition: retypes.h:1
UCHAR BootCodeAndData[420]
Definition: bootsup.c:105
CHAR FileSystemType[4]
Definition: fat.h:90
struct _FATX_BOOTSECTOR * PFATX_BOOTSECTOR
UCHAR Attributes
Definition: fat.h:155
UCHAR Reserved
Definition: fat.h:123
UCHAR DriveNumber
Definition: bootsup.c:62
ULONG RootDirStartCluster
Definition: bootsup.c:94
USHORT ExtendedFlags
Definition: bootsup.c:92