sdk-core
v2026.11.05
PS2 SDK - core tier (build-critical EE/IOP modules)
Toggle main menu visibility
Loading...
Searching...
No Matches
fat_driver.h
Go to the documentation of this file.
1
5
#ifndef _FAT_DRIVER_H
6
#define _FAT_DRIVER_H 1
7
8
#if !defined(BUILDING_IEEE1394_DISK) && !defined(BUILDING_USBHDFSD)
9
#include "
scache.h
"
10
#include <
bdm.h
>
11
#endif
12
13
#define DIR_CHAIN_SIZE 32
14
15
#define FAT_MAX_NAME 256
16
17
// attributes (bits:5-Archive 4-Directory 3-Volume Label 2-System 1-Hidden 0-Read Only)
18
#define FAT_ATTR_READONLY 0x01
19
#define FAT_ATTR_HIDDEN 0x02
20
#define FAT_ATTR_SYSTEM 0x04
21
#define FAT_ATTR_VOLUME_LABEL 0x08
22
#define FAT_ATTR_DIRECTORY 0x10
23
#define FAT_ATTR_ARCHIVE 0x20
24
25
#ifndef BUILDING_USBHDFSD
26
typedef
struct
_fat_bpb
27
{
28
unsigned
int
sectorSize;
// bytes per sector - should be 512
29
unsigned
char
clusterSize;
// sectors per cluster - power of two
30
unsigned
int
resSectors;
// reserved sectors - typically 1 (boot sector)
31
unsigned
char
fatCount;
// number of FATs - must be 2
32
unsigned
int
rootSize;
// number of rootdirectory entries - typically 512
33
unsigned
int
fatSize;
// sectors per FAT - varies
34
unsigned
int
trackSize;
// sectors per track
35
unsigned
int
headCount;
// number of heads
36
unsigned
int
sectorCount;
// number of sectors
37
unsigned
int
partStart;
// sector where partition starts (boot sector)
38
unsigned
int
rootDirStart;
// sector where root directory starts
39
unsigned
int
rootDirCluster;
// fat32 - cluster of the root directory
40
unsigned
int
activeFat;
// fat32 - current active fat number
41
unsigned
char
fatType;
// 12-FAT16, 16-FAT16, 32-FAT32
42
unsigned
char
fatId[9];
// File system ID. "FAT12", "FAT16" or "FAT " - for debug only
43
unsigned
int
dataStart;
// sector where data starts
44
} fat_bpb;
45
46
typedef
struct
_fat_driver
47
{
48
#if !defined(BUILDING_IEEE1394_DISK) && !defined(BUILDING_USBHDFSD)
49
struct
block_device *bd;
50
cache_set *cache;
51
#else
52
struct
SBP2Device *dev;
53
#endif
54
fat_bpb partBpb;
// partition bios parameter block
55
56
// modified by Hermes
57
#define MAX_DIR_CLUSTER 512
58
unsigned
int
cbuf[MAX_DIR_CLUSTER];
// cluster index buffer // 2048 by Hermes
59
60
unsigned
int
lastChainCluster;
61
int
lastChainResult;
62
63
/* enough for long filename of length 260 characters (20*13) and one short filename */
64
#define MAX_DE_STACK 21
65
unsigned
int
deSec[MAX_DE_STACK];
// direntry sector
66
int
deOfs[MAX_DE_STACK];
// direntry offset
67
int
deIdx;
// direntry index
68
69
#define SEQ_MASK_SIZE 2048
// Allow 2K files per directory
70
u8 seq_mask[SEQ_MASK_SIZE / 8];
// bitmask for consumed seq numbers
71
#define DIR_MASK_SIZE 2048 * 11
// Allow 2K maxed fullnames per directory
72
u8 dir_used_mask[DIR_MASK_SIZE / 8];
// bitmask for used directory entries
73
74
#define MAX_CLUSTER_STACK 128
75
unsigned
int
clStack[MAX_CLUSTER_STACK];
// cluster allocation stack
76
int
clStackIndex;
77
unsigned
int
clStackLast;
// last free cluster of the fat table
78
} fat_driver;
79
#endif
/* BUILDING_USBHDFSD */
80
81
typedef
struct
_fat_dir_list
82
{
83
unsigned
int
direntryCluster;
// the directory cluster requested by getFirstDirentry
84
int
direntryIndex;
// index of the directory children
85
} fat_dir_list;
86
87
typedef
struct
_fat_dir_chain_record
88
{
89
unsigned
int
cluster;
90
unsigned
int
index;
91
} fat_dir_chain_record;
92
93
typedef
struct
_fat_dir
94
{
95
unsigned
char
attr;
// attributes (bits:5-Archive 4-Directory 3-Volume Label 2-System 1-Hidden 0-Read Only)
96
char
name[FAT_MAX_NAME];
97
unsigned
char
cdate[4];
// D:M:Yl:Yh
98
unsigned
char
ctime[3];
// H:M:S
99
unsigned
char
adate[4];
// D:M:Yl:Yh
100
unsigned
char
atime[3];
// H:M:S
101
unsigned
char
mdate[4];
// D:M:Yl:Yh
102
unsigned
char
mtime[3];
// H:M:S
103
unsigned
int
size;
// file size, 0 for directory
104
unsigned
int
parentDirCluster;
// The cluster number of the parent directory.
105
unsigned
int
startCluster;
106
// Stuff here are used for caching and might not be filled.
107
unsigned
int
lastCluster;
108
fat_dir_chain_record chain[DIR_CHAIN_SIZE];
// cluser/offset cache - for seeking purpose
109
} fat_dir;
110
111
#ifdef BUILDING_IEEE1394_DISK
112
extern
int
InitFAT(
void
);
113
#endif
/* BUILDING_IEEE1394_DISK */
114
extern
int
strEqual(
const
char
*s1,
const
char
*s2);
115
116
#ifdef BUILDING_USBHDFSD
117
extern
int
fat_mount(mass_dev *dev,
unsigned
int
start,
unsigned
int
count
);
118
extern
void
fat_forceUnmount(mass_dev *dev);
119
#endif
/* BUILDING_USBHDFSD */
120
#ifdef BUILDING_IEEE1394_DISK
121
extern
int
fat_mount(
struct
SBP2Device
*dev,
unsigned
int
start,
unsigned
int
count
);
122
extern
void
fat_forceUnmount(
struct
SBP2Device
*dev);
123
#endif
/* BUILDING_IEEE1394_DISK */
124
#if !defined(BUILDING_IEEE1394_DISK) && !defined(BUILDING_USBHDFSD)
125
extern
int
fat_mount(
struct
block_device
*bd);
126
extern
void
fat_forceUnmount(
struct
block_device
*bd);
127
#endif
128
129
extern
void
fat_setFatDirChain(fat_driver *fatd, fat_dir *fatDir);
130
extern
int
fat_readFile(fat_driver *fatd, fat_dir *fatDir,
unsigned
int
filePos,
unsigned
char
*buffer,
unsigned
int
size);
131
extern
int
fat_getFirstDirentry(fat_driver *fatd,
const
char
*dirName, fat_dir_list *fatdlist, fat_dir *fatDir_host, fat_dir *fatDir);
132
extern
int
fat_getNextDirentry(fat_driver *fatd, fat_dir_list *fatdlist, fat_dir *fatDir);
133
134
extern
fat_driver *fat_getData(
int
device);
135
extern
int
fat_getFileStartCluster(fat_driver *fatd,
const
char
*fname,
unsigned
int
*startCluster, fat_dir *fatDir);
136
extern
int
fat_getClusterChain(fat_driver *fatd,
unsigned
int
cluster,
unsigned
int
*buf,
unsigned
int
bufSize,
int
startFlag);
137
#ifndef BUILDING_IEEE1394_DISK
138
extern
int
fat_CheckChain(fat_driver *fatd,
unsigned
int
cluster);
139
#endif
/* BUILDING_USBHDFSD */
140
141
#if !defined(BUILDING_IEEE1394_DISK) && !defined(BUILDING_USBHDFSD)
142
extern
int
fat_stopUnit(
int
device);
143
extern
void
fat_stopAll(
void
);
144
#endif
145
146
#endif
bdm.h
scache.h
SBP2Device
Definition
sbp2_disk.h:132
_fat_bpb
Definition
usbhdfsd.h:83
_fat_dir_chain_record
Definition
fat_driver.h:88
_fat_dir_list
Definition
fat_driver.h:82
_fat_dir
Definition
fat_driver.h:94
_fat_driver
Definition
usbhdfsd.h:103
block_device
Definition
bdm.h:23
count
u32 count
start sector of fragmented bd/file
Definition
usbhdfsd-common.h:1
core
usbhdfsd
src
vfat
include
fat_driver.h
Generated by
1.18.0