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