Fixed the 'REACTOS' volume label bug.
[reactos.git] / reactos / drivers / fs / vfat / vfat.h
1 /* $Id: vfat.h,v 1.34 2001/07/28 07:05:56 hbirr Exp $ */
2
3 #include <ddk/ntifs.h>
4
5 struct _BootSector
6 {
7 unsigned char magic0, res0, magic1;
8 unsigned char OEMName[8];
9 unsigned short BytesPerSector;
10 unsigned char SectorsPerCluster;
11 unsigned short ReservedSectors;
12 unsigned char FATCount;
13 unsigned short RootEntries, Sectors;
14 unsigned char Media;
15 unsigned short FATSectors, SectorsPerTrack, Heads;
16 unsigned long HiddenSectors, SectorsHuge;
17 unsigned char Drive, Res1, Sig;
18 unsigned long VolumeID;
19 unsigned char VolumeLabel[11], SysType[8];
20 unsigned char Res2[450];
21 } __attribute__((packed));
22
23 struct _BootSector32
24 {
25 unsigned char magic0, res0, magic1; // 0
26 unsigned char OEMName[8]; // 3
27 unsigned short BytesPerSector; // 11
28 unsigned char SectorsPerCluster; // 13
29 unsigned short ReservedSectors; // 14
30 unsigned char FATCount; // 16
31 unsigned short RootEntries, Sectors; // 17
32 unsigned char Media; // 21
33 unsigned short FATSectors, SectorsPerTrack, Heads; // 22
34 unsigned long HiddenSectors, SectorsHuge; // 28
35 unsigned long FATSectors32; // 36
36 unsigned short ExtFlag; // 40
37 unsigned short FSVersion; // 42
38 unsigned long RootCluster; // 44
39 unsigned short FSInfoSector; // 48
40 unsigned long BootBackup; // 50
41 unsigned char Res3[10]; // 54
42 unsigned char Drive; // 64
43 unsigned char Res4; // 65
44 unsigned char ExtBootSignature; // 66
45 unsigned long VolumeID; // 67
46 unsigned char VolumeLabel[11], SysType[8]; // 71
47 unsigned char Res2[418]; // 90
48 unsigned long Signature1; // 508
49 } __attribute__((packed));
50
51 struct _BootBackupSector
52 {
53 unsigned long ExtBootSignature2; // 0
54 unsigned char Res6[480]; // 4
55 unsigned long FSINFOSignature; // 484
56 unsigned long FreeCluster; // 488
57 unsigned long NextCluster; // 492
58 unsigned char Res7[12]; // 496
59 unsigned long Signatur2; // 508
60 } __attribute__((packed));
61
62 typedef struct _BootSector BootSector;
63
64 struct _FATDirEntry {
65 unsigned char Filename[8], Ext[3], Attrib, Res[2];
66 unsigned short CreationTime,CreationDate,AccessDate;
67 unsigned short FirstClusterHigh;// higher
68 unsigned short UpdateTime;//time create/update
69 unsigned short UpdateDate;//date create/update
70 unsigned short FirstCluster;
71 unsigned long FileSize;
72 } __attribute__((packed));
73
74 typedef struct _FATDirEntry FATDirEntry, FAT_DIR_ENTRY, *PFAT_DIR_ENTRY;
75
76 struct _slot
77 {
78 unsigned char id; // sequence number for slot
79 WCHAR name0_4[5]; // first 5 characters in name
80 unsigned char attr; // attribute byte
81 unsigned char reserved; // always 0
82 unsigned char alias_checksum; // checksum for 8.3 alias
83 WCHAR name5_10[6]; // 6 more characters in name
84 unsigned char start[2]; // starting cluster number
85 WCHAR name11_12[2]; // last 2 characters in name
86 } __attribute__((packed));
87
88
89 typedef struct _slot slot;
90
91 #define BLOCKSIZE 512
92
93 #define FAT16 (1)
94 #define FAT12 (2)
95 #define FAT32 (3)
96
97 typedef struct
98 {
99 ERESOURCE DirResource;
100 ERESOURCE FatResource;
101
102 KSPIN_LOCK FcbListLock;
103 LIST_ENTRY FcbListHead;
104
105 PDEVICE_OBJECT StorageDevice;
106 PFILE_OBJECT StreamStorageDevice;
107 PBCB StorageBcb;
108 PFILE_OBJECT Fat12StorageDevice;
109 PBCB Fat12StorageBcb;
110 BootSector *Boot;
111 int rootDirectorySectors, FATStart, rootStart, dataStart;
112 int BytesPerSector;
113 int FATEntriesPerSector, FATUnit;
114 ULONG BytesPerCluster;
115 ULONG FatType;
116 } DEVICE_EXTENSION, *PDEVICE_EXTENSION, VCB, *PVCB;
117
118 typedef struct _VFATFCB
119 {
120 REACTOS_COMMON_FCB_HEADER RFCB;
121 SECTION_OBJECT_POINTERS SectionObjectPointers;
122 FATDirEntry entry;
123 /* point on filename (250 chars max) in PathName */
124 WCHAR *ObjectName;
125 /* path+filename 260 max */
126 WCHAR PathName[MAX_PATH];
127 LONG RefCount;
128 PDEVICE_EXTENSION pDevExt;
129 LIST_ENTRY FcbListEntry;
130 struct _VFATFCB* parentFcb;
131 BOOL isCacheInitialized;
132 } VFATFCB, *PVFATFCB;
133
134 typedef struct _VFATCCB
135 {
136 VFATFCB * pFcb;
137 LIST_ENTRY NextCCB;
138 PFILE_OBJECT PtrFileObject;
139 LARGE_INTEGER CurrentByteOffset;
140 /* for DirectoryControl */
141 ULONG StartSector;
142 /* for DirectoryControl */
143 ULONG StartEntry;
144 // PSTRING DirectorySearchPattern;// for DirectoryControl ?
145 } VFATCCB, *PVFATCCB;
146
147 #define TAG(A, B, C, D) (ULONG)(((A)<<0) + ((B)<<8) + ((C)<<16) + ((D)<<24))
148
149 #define TAG_CCB TAG('V', 'C', 'C', 'B')
150
151 #define ENTRIES_PER_SECTOR (BLOCKSIZE / sizeof(FATDirEntry))
152
153 typedef struct __DOSTIME
154 {
155 WORD Second:5;
156 WORD Minute:6;
157 WORD Hour:5;
158 } DOSTIME, *PDOSTIME;
159
160 typedef struct __DOSDATE
161 {
162 WORD Day:5;
163 WORD Month:4;
164 WORD Year:5;
165 } DOSDATE, *PDOSDATE;
166
167 /* functions called by i/o manager : */
168 NTSTATUS STDCALL
169 DriverEntry(PDRIVER_OBJECT _DriverObject,PUNICODE_STRING RegistryPath);
170 NTSTATUS STDCALL
171 VfatDirectoryControl(PDEVICE_OBJECT DeviceObject, PIRP Irp);
172 NTSTATUS STDCALL
173 VfatRead(PDEVICE_OBJECT DeviceObject, PIRP Irp);
174 NTSTATUS STDCALL
175 VfatWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp);
176 NTSTATUS STDCALL
177 VfatCreate(PDEVICE_OBJECT DeviceObject, PIRP Irp);
178 NTSTATUS STDCALL
179 VfatClose(PDEVICE_OBJECT DeviceObject, PIRP Irp);
180 NTSTATUS STDCALL
181 VfatFileSystemControl(PDEVICE_OBJECT DeviceObject, PIRP Irp);
182 NTSTATUS STDCALL
183 VfatQueryInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp);
184 NTSTATUS STDCALL
185 VfatSetInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp);
186 NTSTATUS STDCALL
187 VfatCleanup (PDEVICE_OBJECT DeviceObject, PIRP Irp);
188 NTSTATUS STDCALL
189 VfatShutdown(PDEVICE_OBJECT DeviceObject, PIRP Irp);
190 NTSTATUS STDCALL
191 VfatQueryVolumeInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp);
192 NTSTATUS STDCALL
193 VfatSetVolumeInformation(PDEVICE_OBJECT DeviceObject, PIRP Irp);
194
195
196 NTSTATUS
197 NextCluster(PDEVICE_EXTENSION DeviceExt,
198 ULONG FirstCluster,
199 PULONG CurrentCluster,
200 BOOLEAN Extend);
201
202 /* internal functions in blockdev.c */
203 NTSTATUS
204 VfatReadSectors(IN PDEVICE_OBJECT pDeviceObject,
205 IN ULONG DiskSector,
206 IN ULONG SectorCount,
207 IN UCHAR* Buffer);
208
209 NTSTATUS
210 VfatWriteSectors(IN PDEVICE_OBJECT pDeviceObject,
211 IN ULONG DiskSector,
212 IN ULONG SectorCount,
213 IN UCHAR* Buffer);
214
215 /* internal functions in dir.c : */
216 BOOL FsdDosDateTimeToFileTime(WORD wDosDate,WORD wDosTime, TIME *FileTime);
217 BOOL FsdFileTimeToDosDateTime(TIME *FileTime,WORD *pwDosDate,WORD *pwDosTime);
218
219 /* internal functions in iface.c : */
220 NTSTATUS
221 FindFile(PDEVICE_EXTENSION DeviceExt, PVFATFCB Fcb,
222 PVFATFCB Parent, PWSTR FileToFind,ULONG *StartSector,ULONG *Entry);
223 NTSTATUS
224 VfatCloseFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject);
225 NTSTATUS
226 VfatOpenFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
227 PWSTR FileName);
228 NTSTATUS
229 VfatReadFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
230 PVOID Buffer, ULONG Length, ULONG ReadOffset,
231 PULONG LengthRead, ULONG NoCache);
232 NTSTATUS
233 VfatWriteFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
234 PVOID Buffer, ULONG Length, ULONG WriteOffset, ULONG NoCache);
235 NTSTATUS
236 GetNextWriteCluster(PDEVICE_EXTENSION DeviceExt,
237 ULONG FirstCluster,
238 ULONG CurrentCluster,
239 PULONG NextCluster);
240 BOOLEAN
241 IsDeletedEntry(PVOID Block, ULONG Offset);
242 BOOLEAN
243 IsLastEntry(PVOID Block, ULONG Offset);
244 wchar_t*
245 vfat_wcsncpy(wchar_t * dest, const wchar_t *src,size_t wcount);
246 NTSTATUS
247 VfatRawWriteCluster(PDEVICE_EXTENSION DeviceExt,
248 ULONG FirstCluster, PVOID Buffer, ULONG Cluster);
249
250 /* internal functions in dirwr.c */
251 NTSTATUS
252 addEntry(PDEVICE_EXTENSION DeviceExt,
253 PFILE_OBJECT pFileObject,ULONG RequestedOptions,UCHAR ReqAttr);
254 NTSTATUS
255 updEntry(PDEVICE_EXTENSION DeviceExt,PFILE_OBJECT pFileObject);
256
257 /*
258 * String functions
259 */
260 VOID
261 vfat_initstr(wchar_t *wstr, ULONG wsize);
262 wchar_t*
263 vfat_wcsncat(wchar_t * dest, const wchar_t * src,size_t wstart, size_t wcount);
264 wchar_t*
265 vfat_wcsncpy(wchar_t * dest, const wchar_t *src,size_t wcount);
266 wchar_t*
267 vfat_movstr(wchar_t *src, ULONG dpos, ULONG spos, ULONG len);
268 BOOLEAN
269 wstrcmpi(PWSTR s1, PWSTR s2);
270 BOOLEAN
271 wstrcmpjoki(PWSTR s1, PWSTR s2);
272 PWCHAR vfatGetNextPathElement (PWCHAR pFileName);
273 void vfatWSubString (PWCHAR pTarget, const PWCHAR pSource, size_t pLength);
274 BOOL vfatIsFileNameValid (PWCHAR pFileName);
275
276 /*
277 * functions from fat.c
278 */
279 NTSTATUS
280 OffsetToCluster(PDEVICE_EXTENSION DeviceExt,
281 ULONG FirstCluster,
282 ULONG FileOffset,
283 PULONG Cluster,
284 BOOLEAN Extend);
285 ULONG
286 ClusterToSector(PDEVICE_EXTENSION DeviceExt,
287 ULONG Cluster);
288 NTSTATUS
289 GetNextCluster(PDEVICE_EXTENSION DeviceExt,
290 ULONG CurrentCluster,
291 PULONG NextCluster,
292 BOOLEAN Extend);
293 NTSTATUS
294 GetNextSector(PDEVICE_EXTENSION DeviceExt,
295 ULONG CurrentSector,
296 PULONG NextSector,
297 BOOLEAN Extend);
298 NTSTATUS
299 VfatRawReadCluster(PDEVICE_EXTENSION DeviceExt,
300 ULONG FirstCluster,
301 PVOID Buffer,
302 ULONG Cluster);
303 NTSTATUS
304 VfatRawWriteCluster(PDEVICE_EXTENSION DeviceExt,
305 ULONG FirstCluster,
306 PVOID Buffer,
307 ULONG Cluster);
308 NTSTATUS
309 FAT12CountAvailableClusters(PDEVICE_EXTENSION DeviceExt,
310 PLARGE_INTEGER Clusters);
311 NTSTATUS
312 FAT16CountAvailableClusters(PDEVICE_EXTENSION DeviceExt,
313 PLARGE_INTEGER Clusters);
314 NTSTATUS
315 FAT32CountAvailableClusters(PDEVICE_EXTENSION DeviceExt,
316 PLARGE_INTEGER Clusters);
317 NTSTATUS
318 WriteCluster(PDEVICE_EXTENSION DeviceExt,
319 ULONG ClusterToWrite,
320 ULONG NewValue);
321
322 /* --------------------------------------------------------- create.c */
323
324 void vfat8Dot3ToString (PCHAR pBasename, PCHAR pExtension, PWSTR pName);
325 NTSTATUS
326 ReadVolumeLabel(PDEVICE_EXTENSION DeviceExt, PVPB Vpb);
327 NTSTATUS
328 VfatOpenFile(PDEVICE_EXTENSION DeviceExt,
329 PFILE_OBJECT FileObject,
330 PWSTR FileName);
331
332 /* ----------------------------------------------- DirEntry Functions */
333
334 ULONG vfatDirEntryGetFirstCluster (PDEVICE_EXTENSION pDeviceExt,
335 PFAT_DIR_ENTRY pDirEntry);
336 BOOL vfatIsDirEntryDeleted (FATDirEntry * pFatDirEntry);
337 BOOL vfatIsDirEntryVolume (FATDirEntry * pFatDirEntry);
338 void vfatGetDirEntryName (PFAT_DIR_ENTRY pDirEntry, PWSTR pEntryName);
339 NTSTATUS vfatGetNextDirEntry (PDEVICE_EXTENSION pDeviceExt,
340 PVFATFCB pDirectoryFCB,
341 ULONG * pDirectoryIndex,
342 PWSTR pLongFileName,
343 PFAT_DIR_ENTRY pDirEntry);
344
345 /* ----------------------------------------------------- FCB Functions */
346
347 PVFATFCB vfatNewFCB (PWCHAR pFileName);
348 void vfatDestroyFCB (PVFATFCB pFCB);
349 void vfatGrabFCB (PDEVICE_EXTENSION pVCB, PVFATFCB pFCB);
350 void vfatReleaseFCB (PDEVICE_EXTENSION pVCB, PVFATFCB pFCB);
351 void vfatAddFCBToTable (PDEVICE_EXTENSION pVCB,
352 PVFATFCB pFCB);
353 PVFATFCB vfatGrabFCBFromTable (PDEVICE_EXTENSION pDeviceExt,
354 PWSTR pFileName);
355 NTSTATUS vfatRequestAndValidateRegion (PDEVICE_EXTENSION pDeviceExt,
356 PVFATFCB pFCB,
357 ULONG pOffset,
358 PVOID * pBuffer,
359 PCACHE_SEGMENT * pCacheSegment,
360 BOOL pExtend);
361 NTSTATUS vfatReleaseRegion (PDEVICE_EXTENSION pDeviceExt,
362 PVFATFCB pFCB,
363 PCACHE_SEGMENT pCacheSegment);
364 PVFATFCB vfatMakeRootFCB (PDEVICE_EXTENSION pVCB);
365 PVFATFCB vfatOpenRootFCB (PDEVICE_EXTENSION pVCB);
366 BOOL vfatFCBIsDirectory (PDEVICE_EXTENSION pVCB, PVFATFCB FCB);
367 NTSTATUS vfatAttachFCBToFileObject (PDEVICE_EXTENSION vcb,
368 PVFATFCB fcb,
369 PFILE_OBJECT fileObject);
370 NTSTATUS vfatDirFindFile (PDEVICE_EXTENSION pVCB,
371 PVFATFCB parentFCB,
372 PWSTR elementName,
373 PVFATFCB * fileFCB);
374 NTSTATUS vfatGetFCBForFile (PDEVICE_EXTENSION pVCB,
375 PVFATFCB *pParentFCB,
376 PVFATFCB *pFCB,
377 const PWSTR pFileName);
378
379
380
381