PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
usbhdfsd.h
Go to the documentation of this file.
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Licenced under Academic Free License version 2.0
7# Review ps2sdk README & LICENSE files for further details.
8*/
9
15#ifndef __USBHDFSD_H__
16#define __USBHDFSD_H__
17
18#include <types.h>
19#include <irx.h>
20#include <usbhdfsd-common.h>
21
22// Structure definitions
23typedef struct UsbMassDeviceInfo
24{
26 unsigned short int status;
27 unsigned short int SectorSize;
28 unsigned int MaxLBA;
30
31typedef void (*usbmass_cb_t)(int cause);
32
33struct _cache_set;
34typedef struct _cache_set cache_set;
35struct _mass_dev;
36typedef struct _mass_dev mass_dev;
37
38// number of cache slots (1 slot = block)
39#define CACHE_SIZE 32
40
41typedef struct _cache_record
42{
43 unsigned int sector;
44 int tax;
45 char writeDirty;
47
48struct _cache_set
49{
50 mass_dev *dev;
51 unsigned int sectorSize;
52 unsigned int indexLimit;
53 unsigned char *sectorBuf; // = NULL; //sector content - the cache buffer
54 cache_record rec[CACHE_SIZE]; // cache info record
55
56#ifdef SCACHE_RECORD_STATS
57 // statistical information
58 unsigned int cacheAccess;
59 unsigned int cacheHits;
60#endif
61 unsigned int writeFlag;
62};
63
65{
66 int controlEp; // config endpoint id
67 int bulkEpI; // in endpoint id
68 int bulkEpO; // out endpoint id
69 int devId; // device id
70 unsigned char configId; // configuration id
71 unsigned char status;
72 unsigned char interfaceNumber; // interface number
73 unsigned char interfaceAlt; // interface alternate setting
74 unsigned int sectorSize; // = 512; // store size of sector from usb mass
75 unsigned int maxLBA;
76 int ioSema;
77 cache_set *cache;
78 usbmass_cb_t callback;
79};
80
81typedef struct _fat_bpb
82{
83 unsigned int sectorSize; // bytes per sector - should be 512
84 unsigned char clusterSize; // sectors per cluster - power of two
85 unsigned int resSectors; // reserved sectors - typically 1 (boot sector)
86 unsigned char fatCount; // number of FATs - must be 2
87 unsigned int rootSize; // number of rootdirectory entries - typically 512
88 unsigned int fatSize; // sectors per FAT - varies
89 unsigned int trackSize; // sectors per track
90 unsigned int headCount; // number of heads
91 unsigned int sectorCount; // number of sectors
92 unsigned int partStart; // sector where partition starts (boot sector)
93 unsigned int rootDirStart; // sector where root directory starts
94 unsigned int rootDirCluster; // fat32 - cluster of the root directory
95 unsigned int activeFat; // fat32 - current active fat number
96 unsigned char fatType; // 12-FAT16, 16-FAT16, 32-FAT32
97 unsigned char fatId[9]; // File system ID. "FAT12", "FAT16" or "FAT " - for debug only
98 unsigned int dataStart; // sector where data starts
99} fat_bpb;
100
101typedef struct _fat_driver
102{
103 mass_dev *dev;
104 fat_bpb partBpb; // partition bios parameter block
105
106 // modified by Hermes
107#define MAX_DIR_CLUSTER 512
108 unsigned int cbuf[MAX_DIR_CLUSTER]; // cluster index buffer // 2048 by Hermes
109
110 unsigned int lastChainCluster;
111 int lastChainResult;
112
113/* enough for long filename of length 260 characters (20*13) and one short filename */
114#define MAX_DE_STACK 21
115 unsigned int deSec[MAX_DE_STACK]; // direntry sector
116 int deOfs[MAX_DE_STACK]; // direntry offset
117 int deIdx; // direntry index
118
119#define SEQ_MASK_SIZE 2048 // Allow 2K files per directory
120 u8 seq_mask[SEQ_MASK_SIZE / 8]; // bitmask for consumed seq numbers
121#define DIR_MASK_SIZE 2048 * 11 // Allow 2K maxed fullnames per directory
122 u8 dir_used_mask[DIR_MASK_SIZE / 8]; // bitmask for used directory entries
123
124#define MAX_CLUSTER_STACK 128
125 unsigned int clStack[MAX_CLUSTER_STACK]; // cluster allocation stack
126 int clStackIndex;
127 unsigned int clStackLast; // last free cluster of the fat table
128} fat_driver;
129
130// Exported functions
131extern int UsbMassGetDeviceInfo(int device, UsbMassDeviceInfo_t *info);
132extern int UsbMassRegisterCallback(int device, usbmass_cb_t callback);
133extern fat_driver *UsbMassFatGetData(int device);
134extern int UsbMassReadSector(fat_driver *fatd, void **buffer, u32 sector);
135extern int UsbMassWriteSector(fat_driver *fatd, u32 sector);
136extern void UsbMassFlushCache(fat_driver *fatd);
137extern int UsbMassFatGetClusterChain(fat_driver *fatd, unsigned int cluster, unsigned int *buf, unsigned int bufSize, int startFlag);
138
139#define usbmass_IMPORTS_start DECLARE_IMPORT_TABLE(usbmass, 1, 2)
140#define usbmass_IMPORTS_end END_IMPORT_TABLE
141
142#define I_UsbMassGetDeviceInfo DECLARE_IMPORT(4, UsbMassGetDeviceInfo)
143#define I_UsbMassRegisterCallback DECLARE_IMPORT(5, UsbMassRegisterCallback)
144#define I_UsbMassFatGetData DECLARE_IMPORT(6, UsbMassFatGetData)
145#define I_UsbMassReadSector DECLARE_IMPORT(7, UsbMassReadSector)
146#define I_UsbMassWriteSector DECLARE_IMPORT(8, UsbMassWriteSector)
147#define I_UsbMassFlushCache DECLARE_IMPORT(9, UsbMassFlushCache)
148#define I_UsbMassFatGetClusterChain DECLARE_IMPORT(10, UsbMassFatGetClusterChain)
149
150#endif /* __USBHDFSD_H__ */
unsigned short int status
Definition usbhdfsd.h:26