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