3 #include <reactos/helper.h>
6 /* FAT on-disk data structures */
10 unsigned char magic0
, res0
, magic1
;
11 unsigned char OEMName
[8];
12 unsigned short BytesPerSector
;
13 unsigned char SectorsPerCluster
;
14 unsigned short ReservedSectors
;
15 unsigned char FATCount
;
16 unsigned short RootEntries
, Sectors
;
18 unsigned short FATSectors
, SectorsPerTrack
, Heads
;
19 unsigned long HiddenSectors
, SectorsHuge
;
20 unsigned char Drive
, Res1
, Sig
;
21 unsigned long VolumeID
;
22 unsigned char VolumeLabel
[11], SysType
[8];
23 unsigned char Res2
[448];
24 unsigned short Signatur1
;
29 unsigned char magic0
, res0
, magic1
; // 0
30 unsigned char OEMName
[8]; // 3
31 unsigned short BytesPerSector
; // 11
32 unsigned char SectorsPerCluster
; // 13
33 unsigned short ReservedSectors
; // 14
34 unsigned char FATCount
; // 16
35 unsigned short RootEntries
, Sectors
; // 17
36 unsigned char Media
; // 21
37 unsigned short FATSectors
, SectorsPerTrack
, Heads
; // 22
38 unsigned long HiddenSectors
, SectorsHuge
; // 28
39 unsigned long FATSectors32
; // 36
40 unsigned short ExtFlag
; // 40
41 unsigned short FSVersion
; // 42
42 unsigned long RootCluster
; // 44
43 unsigned short FSInfoSector
; // 48
44 unsigned short BootBackup
; // 50
45 unsigned char Res3
[12]; // 52
46 unsigned char Drive
; // 64
47 unsigned char Res4
; // 65
48 unsigned char ExtBootSignature
; // 66
49 unsigned long VolumeID
; // 67
50 unsigned char VolumeLabel
[11], SysType
[8]; // 71
51 unsigned char Res2
[420]; // 90
52 unsigned short Signature1
; // 510
55 struct _BootSectorFatX
57 unsigned char SysType
[4]; // 0
58 unsigned long VolumeID
; // 4
59 unsigned long SectorsPerCluster
; // 8
60 unsigned short FATCount
; // 12
61 unsigned long Unknown
; // 14
62 unsigned char Unused
[4078]; // 18
67 unsigned long ExtBootSignature2
; // 0
68 unsigned char Res6
[480]; // 4
69 unsigned long FSINFOSignature
; // 484
70 unsigned long FreeCluster
; // 488
71 unsigned long NextCluster
; // 492
72 unsigned char Res7
[12]; // 496
73 unsigned long Signatur2
; // 508
76 typedef struct _BootSector BootSector
;
82 struct { unsigned char Filename
[8], Ext
[3]; };
83 unsigned char ShortName
[11];
87 unsigned char CreationTimeMs
;
88 unsigned short CreationTime
,CreationDate
,AccessDate
;
91 unsigned short FirstClusterHigh
; // FAT32
92 unsigned short ExtendedAttributes
; // FAT12/FAT16
94 unsigned short UpdateTime
; //time create/update
95 unsigned short UpdateDate
; //date create/update
96 unsigned short FirstCluster
;
97 unsigned long FileSize
;
100 #define FAT_EAFILE "EA DATA. SF"
102 typedef struct _EAFileHeader FAT_EA_FILE_HEADER
, *PFAT_EA_FILE_HEADER
;
106 unsigned short Signature
; // ED
107 unsigned short Unknown
[15];
108 unsigned short EASetTable
[240];
111 typedef struct _EASetHeader FAT_EA_SET_HEADER
, *PFAT_EA_SET_HEADER
;
115 unsigned short Signature
; // EA
116 unsigned short Offset
; // relative offset, same value as in the EASetTable
117 unsigned short Unknown1
[2];
118 char TargetFileName
[12];
119 unsigned short Unknown2
[3];
120 unsigned int EALength
;
124 typedef struct _EAHeader FAT_EA_HEADER
, *PFAT_EA_HEADER
;
128 unsigned char Unknown
;
129 unsigned char EANameLength
;
130 unsigned short EAValueLength
;
135 typedef struct _FATDirEntry FAT_DIR_ENTRY
, *PFAT_DIR_ENTRY
;
139 unsigned char FilenameLength
; // 0
140 unsigned char Attrib
; // 1
141 unsigned char Filename
[42]; // 2
142 unsigned long FirstCluster
; // 44
143 unsigned long FileSize
; // 48
144 unsigned short UpdateTime
; // 52
145 unsigned short UpdateDate
; // 54
146 unsigned short CreationTime
; // 56
147 unsigned short CreationDate
; // 58
148 unsigned short AccessTime
; // 60
149 unsigned short AccessDate
; // 62
154 unsigned char id
; // sequence number for slot
155 WCHAR name0_4
[5]; // first 5 characters in name
156 unsigned char attr
; // attribute byte
157 unsigned char reserved
; // always 0
158 unsigned char alias_checksum
; // checksum for 8.3 alias
159 WCHAR name5_10
[6]; // 6 more characters in name
160 unsigned char start
[2]; // starting cluster number
161 WCHAR name11_12
[2]; // last 2 characters in name
164 typedef struct _slot slot
;
169 /* File system types */
177 #define VCB_VOLUME_LOCKED 0x0001
178 #define VCB_DISMOUNT_PENDING 0x0002
179 #define VCB_IS_FATX 0x0004
180 #define VCB_IS_DIRTY 0x4000 /* Volume is dirty */
181 #define VCB_CLEAR_DIRTY 0x8000 /* Clean dirty flag at shutdown */
189 ULONG rootDirectorySectors
;
193 ULONG SectorsPerCluster
;
194 ULONG BytesPerSector
;
195 ULONG BytesPerCluster
;
196 ULONG NumberOfClusters
;
200 } FATINFO
, *PFATINFO
;
203 struct _VFAT_DIRENTRY_CONTEXT
;
205 typedef struct DEVICE_EXTENSION
*PDEVICE_EXTENSION
;
207 typedef struct _DEVICE_EXTENSION
209 ERESOURCE DirResource
;
210 ERESOURCE FatResource
;
212 KSPIN_LOCK FcbListLock
;
213 LIST_ENTRY FcbListHead
;
215 struct _HASHENTRY
** FcbHashTable
;
217 PDEVICE_OBJECT StorageDevice
;
218 PFILE_OBJECT FATFileObject
;
220 ULONG LastAvailableCluster
;
221 ULONG AvailableClusters
;
222 BOOLEAN AvailableClustersValid
;
224 struct _VFATFCB
* VolumeFcb
;
228 LIST_ENTRY VolumeListEntry
;
231 typedef struct _FAT_GLOBAL_DATA
234 PDRIVER_OBJECT DriverObject
;
235 PDEVICE_OBJECT DiskDeviceObject
;
236 NPAGED_LOOKASIDE_LIST NonPagedFcbList
;
237 NPAGED_LOOKASIDE_LIST ResourceList
;
238 NPAGED_LOOKASIDE_LIST IrpContextList
;
239 FAST_IO_DISPATCH FastIoDispatch
;
240 CACHE_MANAGER_CALLBACKS CacheMgrCallbacks
;
241 CACHE_MANAGER_CALLBACKS CacheMgrNoopCallbacks
;
242 } FAT_GLOBAL_DATA
, *VFAT_GLOBAL_DATA
;
244 extern VFAT_GLOBAL_DATA VfatGlobalData
;
247 #define FCB_CACHE_INITIALIZED 0x0001
248 #define FCB_DELETE_PENDING 0x0002
249 #define FCB_IS_FAT 0x0004
250 #define FCB_IS_PAGE_FILE 0x0008
251 #define FCB_IS_VOLUME 0x0010
252 #define FCB_IS_DIRTY 0x0020
253 #define FCB_IS_FATX_ENTRY 0x0040
255 typedef struct _VFATFCB
257 /* FCB header required by ROS/NT */
258 FSRTL_COMMON_FCB_HEADER RFCB
;
259 SECTION_OBJECT_POINTERS SectionObjectPointers
;
260 ERESOURCE MainResource
;
261 ERESOURCE PagingIoResource
;
262 /* end FCB header required by ROS/NT */
264 /* Pointer to attributes in entry */
267 /* long file name, points into PathNameBuffer */
268 UNICODE_STRING LongNameU
;
270 /* short file name */
271 UNICODE_STRING ShortNameU
;
273 /* directory name, points into PathNameBuffer */
274 UNICODE_STRING DirNameU
;
276 /* path + long file name 260 max*/
277 UNICODE_STRING PathNameU
;
279 /* buffer for PathNameU */
280 PWCHAR PathNameBuffer
;
282 /* buffer for ShortNameU */
283 WCHAR ShortNameBuffer
[13];
288 /* List of FCB's for this volume */
289 LIST_ENTRY FcbListEntry
;
291 /* pointer to the parent fcb */
292 struct _VFATFCB
* parentFcb
;
294 /* Flags for the fcb */
297 /* pointer to the file object which has initialized the fcb */
298 PFILE_OBJECT FileObject
;
300 /* Directory index for the short name entry */
303 /* Directory index where the long name starts */
306 /* Share access for the file object */
307 SHARE_ACCESS FCBShareAccess
;
309 /* Incremented on IRP_MJ_CREATE, decremented on IRP_MJ_CLEANUP */
310 ULONG OpenHandleCount
;
312 /* List of byte-range locks for this file */
316 * Optimalization: caching of last read/write cluster+offset pair. Can't
317 * be in VFATCCB because it must be reset everytime the allocated clusters
320 FAST_MUTEX LastMutex
;
323 } VFATFCB
, *PVFATFCB
;
325 typedef struct _VFATCCB
327 LARGE_INTEGER CurrentByteOffset
;
328 /* for DirectoryControl */
330 /* for DirectoryControl */
331 UNICODE_STRING SearchPattern
;
332 } VFATCCB
, *PVFATCCB
;
334 /* Volume Control Block */
337 FSRTL_ADVANCED_FCB_HEADER VolumeFileHeader
;
340 /* Volume Device Object */
341 typedef struct _VOLUME_DEVICE_OBJECT
343 DEVICE_OBJECT DeviceObject
;
344 FSRTL_COMMON_FCB_HEADER VolumeHeader
;
345 VCB Vcb
; /* Must be the last entry! */
346 } VOLUME_DEVICE_OBJECT
, *PVOLUME_DEVICE_OBJECT
;
350 #define TAG(A, B, C, D) (ULONG)(((A)<<0) + ((B)<<8) + ((C)<<16) + ((D)<<24))
353 #define TAG_CCB TAG('V', 'C', 'C', 'B')
354 #define TAG_FCB TAG('V', 'F', 'C', 'B')
355 #define TAG_IRP TAG('V', 'I', 'R', 'P')
356 #define TAG_VFAT TAG('V', 'F', 'A', 'T')
358 typedef struct __DOSTIME
366 typedef struct __DOSDATE
374 #define IRPCONTEXT_CANWAIT 0x0001
375 #define IRPCONTEXT_PENDINGRETURNED 0x0002
376 #define IRPCONTEXT_STACK_IO_CONTEXT 0x0004
378 typedef struct _FAT_IRP_CONTEXT
381 PDEVICE_OBJECT DeviceObject
;
384 PFILE_OBJECT FileObject
;
388 struct _FAT_IO_CONTEXT
*FatIoContext
;
390 PDEVICE_EXTENSION DeviceExt
;
391 WORK_QUEUE_ITEM WorkQueueItem
;
392 PIO_STACK_LOCATION Stack
;
394 } FAT_IRP_CONTEXT
, *PFAT_IRP_CONTEXT
;
396 typedef struct _FAT_IO_CONTEXT
399 } _FAT_IO_CONTEXT
, *PFAT_IO_CONTEXT
;
401 /* ------------------------------------------------------ shutdown.c */
403 DRIVER_DISPATCH FatShutdown
;
405 FatShutdown(PDEVICE_OBJECT DeviceObject
, PIRP Irp
);
407 /* -------------------------------------------------------- volume.c */
410 FatQueryVolumeInfo(PDEVICE_OBJECT DeviceObject
, PIRP Irp
);
413 FatSetVolumeInfo(PDEVICE_OBJECT DeviceObject
, PIRP Irp
);
415 /* ------------------------------------------------------ blockdev.c */
417 /* ----------------------------------------------------------- dir.c */
420 FatDirectoryControl(PDEVICE_OBJECT DeviceObject
, PIRP Irp
);
422 /* -------------------------------------------------------- create.c */
425 FatCreate(PDEVICE_OBJECT DeviceObject
, PIRP Irp
);
427 /* --------------------------------------------------------- close.c */
430 FatClose(PDEVICE_OBJECT DeviceObject
, PIRP Irp
);
432 /* ------------------------------------------------------- cleanup.c */
435 FatCleanup(PDEVICE_OBJECT DeviceObject
, PIRP Irp
);
437 /* --------------------------------------------------------- fastio.c */
440 FatInitFastIoRoutines(PFAST_IO_DISPATCH FastIoDispatch
);
443 FatAcquireForLazyWrite(IN PVOID Context
,
447 FatReleaseFromLazyWrite(IN PVOID Context
);
450 FatAcquireForReadAhead(IN PVOID Context
,
454 FatReleaseFromReadAhead(IN PVOID Context
);
457 FatNoopAcquire(IN PVOID Context
,
461 FatNoopRelease(IN PVOID Context
);
463 /* --------------------------------------------------------- fastfat.c */
465 PFAT_IRP_CONTEXT NTAPI
466 FatBuildIrpContext(PIRP Irp
, BOOLEAN CanWait
);
469 FatDestroyIrpContext(PFAT_IRP_CONTEXT IrpContext
);
472 FatCompleteRequest(PFAT_IRP_CONTEXT IrpContext OPTIONAL
,
477 /* --------------------------------------------------------- lock.c */
480 FatLockControl(PDEVICE_OBJECT DeviceObject
, PIRP Irp
);
482 /* --------------------------------------------------------- fsctl.c */
485 FatFileSystemControl(PDEVICE_OBJECT DeviceObject
, PIRP Irp
);
487 /* --------------------------------------------------------- finfo.c */
489 NTSTATUS NTAPI
FatQueryInformation(PDEVICE_OBJECT DeviceObject
, PIRP Irp
);
490 NTSTATUS NTAPI
FatSetInformation(PDEVICE_OBJECT DeviceObject
, PIRP Irp
);
492 /* --------------------------------------------------------- iface.c */
496 DriverEntry(PDRIVER_OBJECT DriverObject
, PUNICODE_STRING RegistryPath
);
498 /* ----------------------------------------------------------- fat.c */
500 /* ------------------------------------------------------ device.c */
503 FatDeviceControl(PDEVICE_OBJECT DeviceObject
, PIRP Irp
);
505 /* ------------------------------------------------------ direntry.c */
507 /* ----------------------------------------------------------- fcb.c */
509 /* ------------------------------------------------------------ rw.c */
512 FatRead(PDEVICE_OBJECT DeviceObject
, PIRP Irp
);
515 FatWrite(PDEVICE_OBJECT DeviceObject
, PIRP Irp
);
517 /* ------------------------------------------------------------- flush.c */
520 FatFlushBuffers(PDEVICE_OBJECT DeviceObject
, PIRP Irp
);