sdk-core
v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Toggle main menu visibility
Loading...
Searching...
No Matches
fat.h
Go to the documentation of this file.
1
/*
2
* fat.h - USB Mass storage driver for PS2
3
*
4
* (C) 2004, Marek Olejnik (ole00@post.cz)
5
*
6
* FAT helper structures
7
*
8
* See the file LICENSE included with this distribution for licensing terms.
9
*/
10
11
/*
12
FAT References: http://www.igd.fhg.de/~aschaefe/fips/distrib/techinfo.txt
13
: http://home.freeuk.net/foxy2k/disk/disk1.htm
14
*/
15
20
#ifndef _FAT_H
21
#define _FAT_H 1
22
23
#define FAT12 0x0C
24
#define FAT16 0x10
25
#define FAT32 0x20
26
27
#define FAT_MAX_PATH 260
28
29
/* bios parameter block - bpb - fat12, fat16 */
30
typedef
struct
_fat_raw_bpb
31
{
32
unsigned
char
jump[3];
// jump instruction ('eb xx 90' or 'e9 xx xx')
33
unsigned
char
oem[8];
// OEM name and version - e.g. MSDOS5.0
34
unsigned
char
sectorSize[2];
// bytes per sector - should be 512
35
unsigned
char
clusterSize;
// sectors per cluster - power of two
36
unsigned
char
resSectors[2];
// reserved sectors - typically 1 (boot sector)
37
unsigned
char
fatCount;
// number of FATs - must be 2
38
unsigned
char
rootSize[2];
// number of rootdirectory entries - typically 512
39
unsigned
char
sectorCountO[2];
// number of sectors (short) - 0, if BIGDOS partition
40
unsigned
char
mediaDesc;
// media descriptor - typically f8h
41
unsigned
char
fatSize[2];
// sectors per FAT - varies
42
unsigned
char
trackSize[2];
// sectors per track
43
unsigned
char
headCount[2];
// number of heads
44
unsigned
char
hiddenCountL[2];
// number of hidden sectors (low)
45
46
unsigned
char
hiddenCountH[2];
// number of hidden sectors (high)
47
unsigned
char
sectorCount[4];
// number of sectors
48
49
/* extended BPB since DOS 4.0 */
50
unsigned
char
driveNumber;
// physical drive number - 80h or 81h
51
unsigned
char
reserved;
// Current head (not used for this but WinNT stores two flags here).
52
unsigned
char
signature;
// Signature (must be 28h or 29h to be recognised by NT).
53
unsigned
char
serialNumber[4];
// The serial number, the serial number is stored in reverse
54
// order and is the hex representation of the bytes stored here
55
unsigned
char
volumeLabel[11];
// Volume label
56
unsigned
char
fatId[8];
// File system ID. "FAT12", "FAT16" or "FAT "
57
} fat_raw_bpb;
58
59
/* bios parameter block - bpb - fat32 */
60
typedef
struct
_fat32_raw_bpb
61
{
62
unsigned
char
jump[3];
// jump instruction ('eb xx 90' or 'e9 xx xx')
63
unsigned
char
oem[8];
// OEM name and version - e.g. MSDOS5.0
64
unsigned
char
sectorSize[2];
// bytes per sector - should be 512
65
unsigned
char
clusterSize;
// sectors per cluster - power of two
66
unsigned
char
resSectors[2];
// reserved sectors - typically 1 (boot sector)
67
unsigned
char
fatCount;
// number of FATs - must be 2
68
unsigned
char
rootSize[2];
// number of rootdirectory entries - typically 512
69
unsigned
char
sectorCountO[2];
// number of sectors (short) - 0, if BIGDOS partition
70
unsigned
char
mediaDesc;
// media descriptor - typically f8h
71
unsigned
char
fatSize[2];
// sectors per FAT - varies
72
unsigned
char
trackSize[2];
// sectors per track
73
unsigned
char
headCount[2];
// number of heads
74
unsigned
char
hiddenCountL[2];
// number of hidden sectors (low)
75
76
unsigned
char
hiddenCountH[2];
// number of hidden sectors (high)
77
unsigned
char
sectorCount[4];
// number of sectors
78
79
/* fat32 specific */
80
unsigned
char
fatSize32[4];
// FAT32 sectors per FAT
81
unsigned
char
fatStatus[2];
// If bit 7 is clear then all FAT's are updated other wise bits 0-3
82
// give the current active FAT, all other bits are reserved.
83
unsigned
char
revision[2];
// High byte is major revision number, low byte is minor revision number, currently both are 0
84
unsigned
char
rootDirCluster[4];
// Root directory starting cluster
85
unsigned
char
fsInfoSector[2];
// File system information sector.
86
unsigned
char
bootSectorCopy[2];
// If non-zero this gives the sector which holds a copy of the boot record, usually 6
87
unsigned
char
reserved1[12];
// Reserved, set to 0.
88
unsigned
char
pdn;
// Physical drive number (BIOS system ie 80h is first HDD, 00h is first FDD)
89
unsigned
char
reserved2;
// Reserved
90
unsigned
char
signature;
// Signature (must be 28h or 29h to be recognised by NT)
91
unsigned
char
serialNumber[4];
// The serial number, the serial number is stored in reverse
92
// order and is the hex representation of the bytes stored here
93
unsigned
char
volumeLabel[11];
// Volume label
94
unsigned
char
fatId[8];
// File system ID. "FAT12", "FAT16" or "FAT "
95
unsigned
char
machineCode[8];
// Machine code
96
unsigned
char
bootSignature[2];
// Boot Signature AA55h.
97
} fat32_raw_bpb;
98
99
/* directory entry of the short file name */
100
typedef
struct
_fat_direntry_sfn
101
{
102
unsigned
char
name[8];
// Filename padded with spaces if required.
103
unsigned
char
ext[3];
// Filename extension padded with spaces if required.
104
unsigned
char
attr;
// File Attribute Byte.
105
106
unsigned
char
reservedNT;
// Reserved for use by Windows NT.
107
unsigned
char
seconds;
// Tenths of a second at time of file creation, 0-199 is valid.
108
unsigned
char
timeCreate[2];
// Time when file was created.
109
unsigned
char
dateCreate[2];
// Date when file was created.
110
unsigned
char
dateAccess[2];
// Date when file was last accessed.
111
unsigned
char
clusterH[2];
// High word of cluster number (EA index for FAT12 and FAT16).
112
113
unsigned
char
timeWrite[2];
// Time of last write to file (last modified or when created).
114
unsigned
char
dateWrite[2];
// Date of last write to file (last modified or when created).
115
unsigned
char
clusterL[2];
// Starting cluster (Low word).
116
unsigned
char
size[4];
// File size (set to zero if a directory).
117
} fat_direntry_sfn;
118
119
/* directory entry of the long file name
120
121
Each LFN directory entry holds 13 characters of the complete LFN using 16-bit Unicode characters.
122
*/
123
typedef
struct
_fat_direntry_lfn
124
{
125
unsigned
char
entrySeq;
// Bits 0-5 give the LFN part number, bit 6 is set if this is the last entry for the file.
126
unsigned
char
name1[10];
// 1st 5 letters of LFN entry.
127
unsigned
char
rshv;
//?? 0Fh (RSHV attributes set)
128
129
unsigned
char
reserved1;
// Reserved set to 0.
130
unsigned
char
checksum;
// Checksum generated from SFN.
131
unsigned
char
name2[12];
// Next 6 letters of LFN entry.
132
133
unsigned
char
reserved2[2];
// Reserved set to 0.
134
unsigned
char
name3[4];
// Last 2 letters of LFN entry.
135
} fat_direntry_lfn;
136
137
typedef
union
_fat_direntry
138
{
139
fat_direntry_sfn sfn;
140
fat_direntry_lfn lfn;
141
} fat_direntry;
142
143
typedef
struct
_fat_direntry_summary
144
{
145
unsigned
char
attr;
// Attributes (bits:5-Archive 4-Directory 3-Volume Label 2-System 1-Hidden 0-Read Only)
146
char
name[FAT_MAX_NAME];
// Long name (zero terminated)
147
char
sname[13];
// Short name (zero terminated)
148
unsigned
int
size;
// file size, 0 for directory
149
unsigned
int
cluster;
// file start cluster
150
} fat_direntry_summary;
151
152
//---------------------------------------------------------------------------
153
static
USBHD_INLINE
unsigned
int
fat_cluster2sector(fat_bpb *partBpb,
unsigned
int
cluster)
154
{
155
return
partBpb->dataStart + (partBpb->clusterSize * (cluster - 2));
156
}
157
158
extern
unsigned
int
fat_getClusterRecord12(
const
unsigned
char
*buf,
int
type);
159
extern
int
fat_getDirentry(
unsigned
char
fatType, fat_direntry *dir_entry, fat_direntry_summary *dir);
160
extern
int
fat_getDirentrySectorData(fat_driver *fatd,
unsigned
int
*startCluster,
unsigned
int
*startSector,
unsigned
int
*dirSector);
161
extern
void
fat_invalidateLastChainResult(fat_driver *fatd);
162
extern
void
fat_getClusterAtFilePos(fat_driver *fatd, fat_dir *fatDir,
unsigned
int
filePos,
unsigned
int
*cluster,
unsigned
int
*clusterPos);
163
164
#endif
/* _FAT_H */
_fat32_raw_bpb
Definition
fat.h:61
_fat_direntry_lfn
Definition
fat.h:124
_fat_direntry_sfn
Definition
fat.h:101
_fat_direntry_summary
Definition
fat.h:144
_fat_raw_bpb
Definition
fat.h:31
_fat_direntry
Definition
fat.h:138
core
usbhdfsd
src
vfat
include
fat.h
Generated by
1.18.0