Full memory management support (memory.c & memory.h & mem.S)
[reactos.git] / freeldr / freeldr / fs.h
1 /*
2 * FreeLoader
3 * Copyright (C) 1999, 2000 Brian Palmer <brianp@sginet.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #ifndef __FS_FAT_H
21 #define __FS_FAT_H
22
23 // Bootsector BPB defines
24 #define BPB_JMPBOOT 0
25 #define BPB_OEMNAME 3
26 #define BPB_BYTESPERSECTOR 11
27 #define BPB_SECTORSPERCLUSTER 13
28 #define BPB_RESERVEDSECTORS 14
29 #define BPB_NUMBEROFFATS 16
30 #define BPB_ROOTDIRENTRIES 17
31 #define BPB_TOTALSECTORS16 19
32 #define BPB_MEDIADESCRIPTOR 21
33 #define BPB_SECTORSPERFAT16 22
34 #define BPB_SECTORSPERTRACK 24
35 #define BPB_NUMBEROFHEADS 26
36 #define BPB_HIDDENSECTORS 28
37 #define BPB_TOTALSECTORS32 32
38
39 // Fat12/16 extended BPB defines
40 #define BPB_DRIVENUMBER16 36
41 #define BPB_RESERVED16_1 37
42 #define BPB_BOOTSIGNATURE16 38
43 #define BPB_VOLUMESERIAL16 39
44 #define BPB_VOLUMELABEL16 43
45 #define BPB_FILESYSTEMTYPE16 54
46
47 // Fat32 extended BPB defines
48 #define BPB_SECTORSPERFAT32 36
49 #define BPB_EXTENDEDFLAGS32 40
50 #define BPB_FILESYSTEMVERSION32 42
51 #define BPB_ROOTDIRSTARTCLUSTER32 44
52 #define BPB_FILESYSTEMINFOSECTOR32 48
53 #define BPB_BACKUPBOOTSECTOR32 50
54 #define BPB_RESERVED32_1 52
55 #define BPB_DRIVENUMBER32 64
56 #define BPB_RESERVED32_2 65
57 #define BPB_BOOTSIGNATURE32 66
58 #define BPB_VOLUMESERIAL32 67
59 #define BPB_VOLUMELABEL32 71
60 #define BPB_FILESYSTEMTYPE32 82
61
62 /*
63 * Structure of MSDOS directory entry
64 */
65 typedef struct //_DIRENTRY
66 {
67 BYTE cFileName[11]; /* Filename + extension */
68 BYTE cAttr; /* File attributes */
69 BYTE cReserved[10]; /* Reserved area */
70 WORD wTime; /* Time last modified */
71 WORD wData; /* Date last modified */
72 WORD wCluster; /* First cluster number */
73 DWORD dwSize; /* File size */
74 } DIRENTRY, * PDIRENTRY;
75
76 /*
77 * Structure of internal file control block
78 */
79 typedef struct //_FCB
80 {
81 BYTE cAttr; /* Open attributes */
82 BYTE cSector; /* Sector within cluster */
83 PDIRENTRY pDirptr; /* Pointer to directory entry */
84 WORD wDirSector; /* Directory sector */
85 WORD wFirstCluster; /* First cluster in file */
86 WORD wLastCluster; /* Last cluster read/written */
87 WORD wNextCluster; /* Next cluster to read/write */
88 WORD wOffset; /* Read/Write offset within sector */
89 DWORD dwSize; /* File size */
90 BYTE cBuffer[512]; /* Data transfer buffer */
91 } FCB, * PFCB;
92
93 typedef struct //_FAT_STRUCT
94 {
95 DWORD dwStartCluster; // File's starting cluster
96 DWORD dwCurrentCluster; // Current read cluster number
97 DWORD dwSize; // File size
98 DWORD dwCurrentReadOffset;// Amount of data already read
99 } FAT_STRUCT, * PFAT_STRUCT;
100
101 typedef struct //_FILE
102 {
103 //DIRENTRY de;
104 //FCB fcb;
105 FAT_STRUCT fat;
106 unsigned long filesize;
107 } FILE;
108
109 extern int nSectorBuffered; // Tells us which sector was read into SectorBuffer[]
110 extern BYTE SectorBuffer[512]; // 512 byte buffer space for read operations, ReadOneSector reads to here
111
112 extern int nFATType;
113
114 extern DWORD nBytesPerSector; // Bytes per sector
115 extern DWORD nSectorsPerCluster; // Number of sectors in a cluster
116 extern DWORD nReservedSectors; // Reserved sectors, usually 1 (the bootsector)
117 extern DWORD nNumberOfFATs; // Number of FAT tables
118 extern DWORD nRootDirEntries; // Number of root directory entries (fat12/16)
119 extern DWORD nTotalSectors16; // Number of total sectors on the drive, 16-bit
120 extern DWORD nSectorsPerFAT16; // Sectors per FAT table (fat12/16)
121 extern DWORD nSectorsPerTrack; // Number of sectors in a track
122 extern DWORD nNumberOfHeads; // Number of heads on the disk
123 extern DWORD nHiddenSectors; // Hidden sectors (sectors before the partition start like the partition table)
124 extern DWORD nTotalSectors32; // Number of total sectors on the drive, 32-bit
125
126 extern DWORD nSectorsPerFAT32; // Sectors per FAT table (fat32)
127 extern DWORD nExtendedFlags; // Extended flags (fat32)
128 extern DWORD nFileSystemVersion; // File system version (fat32)
129 extern DWORD nRootDirStartCluster; // Starting cluster of the root directory (fat32)
130
131 extern DWORD nRootDirSectorStart; // Starting sector of the root directory (fat12/16)
132 extern DWORD nDataSectorStart; // Starting sector of the data area
133 extern DWORD nSectorsPerFAT; // Sectors per FAT table
134 extern DWORD nRootDirSectors; // Number of sectors of the root directory (fat32)
135 extern DWORD nTotalSectors; // Total sectors on the drive
136 extern DWORD nNumberOfClusters; // Number of clusters on the drive
137
138 extern int FSType; // Type of filesystem on boot device, set by OpenDiskDrive()
139
140 extern char *pFileSysData; // Load address for filesystem data
141 extern char *pFat32FATCacheIndex; // Load address for filesystem data
142
143 BOOL OpenDiskDrive(int nDrive, int nPartition); // Opens the disk drive device for reading
144 BOOL ReadMultipleSectors(int nSect, int nNumberOfSectors, void *pBuffer);// Reads a sector from the open device
145 BOOL ReadOneSector(int nSect); // Reads one sector from the open device
146 BOOL OpenFile(char *filename, FILE *pFile); // Opens a file
147 int ReadFile(FILE *pFile, int count, void *buffer); // Reads count bytes from pFile into buffer
148 DWORD GetFileSize(FILE *pFile);
149 DWORD Rewind(FILE *pFile); // Rewinds a file and returns it's size
150 int feof(FILE *pFile);
151 int fseek(FILE *pFILE, DWORD offset);
152
153 BOOL FATLookupFile(char *file, PFAT_STRUCT pFatStruct);
154 int FATGetNumPathParts(char *name);
155 BOOL FATGetFirstNameFromPath(char *buffer, char *name);
156 void FATParseFileName(char *buffer, char *name);
157 DWORD FATGetFATEntry(DWORD nCluster);
158 BOOL FATOpenFile(char *szFileName, PFAT_STRUCT pFatStruct);
159 int FATReadCluster(DWORD nCluster, char *cBuffer);
160 int FATRead(PFAT_STRUCT pFatStruct, int nNumBytes, char *cBuffer);
161 int FATfseek(PFAT_STRUCT pFatStruct, DWORD offset);
162
163
164 #define EOF -1
165
166 #define ATTR_NORMAL 0x00
167 #define ATTR_READONLY 0x01
168 #define ATTR_HIDDEN 0x02
169 #define ATTR_SYSTEM 0x04
170 #define ATTR_VOLUMENAME 0x08
171 #define ATTR_DIRECTORY 0x10
172 #define ATTR_ARCHIVE 0x20
173
174 #define FS_FAT 1
175 #define FS_NTFS 2
176 #define FS_EXT2 3
177
178 #define FAT12 1
179 #define FAT16 2
180 #define FAT32 3
181
182 #endif // #defined __FS_FAT_H