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