1 /* $Id: vfat.h,v 1.50 2003/01/04 02:07:18 hbirr Exp $ */
5 #define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))
6 #define ROUND_DOWN(N, S) ((N) - ((N) % (S)))
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
[446];
24 unsigned long Signatur1
;
25 } __attribute__((packed
));
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 long BootBackup
; // 50
45 unsigned char Res3
[10]; // 54
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
[418]; // 90
52 unsigned long Signature1
; // 508
53 } __attribute__((packed
));
55 struct _BootBackupSector
57 unsigned long ExtBootSignature2
; // 0
58 unsigned char Res6
[480]; // 4
59 unsigned long FSINFOSignature
; // 484
60 unsigned long FreeCluster
; // 488
61 unsigned long NextCluster
; // 492
62 unsigned char Res7
[12]; // 496
63 unsigned long Signatur2
; // 508
64 } __attribute__((packed
));
66 typedef struct _BootSector BootSector
;
68 #define VFAT_CASE_LOWER_BASE 8 // base is lower case
69 #define VFAT_CASE_LOWER_EXT 16 // extension is lower case
73 unsigned char Filename
[8], Ext
[3];
76 unsigned char CreationTimeMs
;
77 unsigned short CreationTime
,CreationDate
,AccessDate
;
78 unsigned short FirstClusterHigh
; // higher
79 unsigned short UpdateTime
; //time create/update
80 unsigned short UpdateDate
; //date create/update
81 unsigned short FirstCluster
;
82 unsigned long FileSize
;
83 } __attribute__((packed
));
85 typedef struct _FATDirEntry FATDirEntry
, FAT_DIR_ENTRY
, *PFAT_DIR_ENTRY
;
89 unsigned char id
; // sequence number for slot
90 WCHAR name0_4
[5]; // first 5 characters in name
91 unsigned char attr
; // attribute byte
92 unsigned char reserved
; // always 0
93 unsigned char alias_checksum
; // checksum for 8.3 alias
94 WCHAR name5_10
[6]; // 6 more characters in name
95 unsigned char start
[2]; // starting cluster number
96 WCHAR name11_12
[2]; // last 2 characters in name
97 } __attribute__((packed
));
100 typedef struct _slot slot
;
102 #define BLOCKSIZE 512
108 #define VCB_VOLUME_LOCKED 0x0001
109 #define VCB_DISMOUNT_PENDING 0x0002
117 ULONG rootDirectorySectors
;
121 ULONG SectorsPerCluster
;
122 ULONG BytesPerSector
;
123 ULONG BytesPerCluster
;
124 ULONG NumberOfClusters
;
127 } FATINFO
, *PFATINFO
;
131 typedef struct _HASHENTRY
134 struct _VFATFCB
* self
;
135 struct _HASHENTRY
* next
;
139 #define FCB_HASH_TABLE_SIZE 1024
143 ERESOURCE DirResource
;
144 ERESOURCE FatResource
;
146 KSPIN_LOCK FcbListLock
;
147 LIST_ENTRY FcbListHead
;
149 PDEVICE_OBJECT StorageDevice
;
150 PFILE_OBJECT FATFileObject
;
152 ULONG LastAvailableCluster
;
153 ULONG AvailableClusters
;
154 BOOLEAN AvailableClustersValid
;
156 struct _VFATFCB
* VolumeFcb
;
157 struct _HASHENTRY
* FcbHashTable
[FCB_HASH_TABLE_SIZE
];
158 } DEVICE_EXTENSION
, *PDEVICE_EXTENSION
, VCB
, *PVCB
;
162 PDRIVER_OBJECT DriverObject
;
163 PDEVICE_OBJECT DeviceObject
;
165 NPAGED_LOOKASIDE_LIST FcbLookasideList
;
166 NPAGED_LOOKASIDE_LIST CcbLookasideList
;
167 NPAGED_LOOKASIDE_LIST IrpContextLookasideList
;
168 } VFAT_GLOBAL_DATA
, *PVFAT_GLOBAL_DATA
;
170 extern PVFAT_GLOBAL_DATA VfatGlobalData
;
172 #define FCB_CACHE_INITIALIZED 0x0001
173 #define FCB_DELETE_PENDING 0x0002
174 #define FCB_IS_FAT 0x0004
175 #define FCB_IS_PAGE_FILE 0x0008
176 #define FCB_IS_VOLUME 0x0010
177 #define FCB_UPDATE_DIRENTRY 0x0020
179 typedef struct _VFATFCB
181 REACTOS_COMMON_FCB_HEADER RFCB
;
182 SECTION_OBJECT_POINTERS SectionObjectPointers
;
184 /* point on filename (250 chars max) in PathName */
186 /* path+filename 260 max */
187 WCHAR PathName
[MAX_PATH
];
190 PDEVICE_EXTENSION pDevExt
;
191 LIST_ENTRY FcbListEntry
;
192 struct _VFATFCB
* parentFcb
;
194 PFILE_OBJECT FileObject
;
197 ERESOURCE PagingIoResource
;
198 ERESOURCE MainResource
;
200 SHARE_ACCESS FCBShareAccess
;
204 /* Structure members used only for paging files. */
207 } VFATFCB
, *PVFATFCB
;
209 typedef struct _VFATCCB
213 PFILE_OBJECT PtrFileObject
;
214 LARGE_INTEGER CurrentByteOffset
;
215 /* for DirectoryControl */
217 /* for DirectoryControl */
218 PWCHAR DirectorySearchPattern
;
222 } VFATCCB
, *PVFATCCB
;
225 #define TAG(A, B, C, D) (ULONG)(((A)<<0) + ((B)<<8) + ((C)<<16) + ((D)<<24))
228 #define TAG_CCB TAG('V', 'C', 'C', 'B')
229 #define TAG_FCB TAG('V', 'F', 'C', 'B')
230 #define TAG_IRP TAG('V', 'I', 'R', 'P')
232 #define ENTRIES_PER_SECTOR (BLOCKSIZE / sizeof(FATDirEntry))
234 typedef struct __DOSTIME
242 typedef struct __DOSDATE
250 #define IRPCONTEXT_CANWAIT 0x0001
255 PDEVICE_OBJECT DeviceObject
;
256 PDEVICE_EXTENSION DeviceExt
;
258 WORK_QUEUE_ITEM WorkQueueItem
;
259 PIO_STACK_LOCATION Stack
;
262 PFILE_OBJECT FileObject
;
263 } VFAT_IRP_CONTEXT
, *PVFAT_IRP_CONTEXT
;
265 /* ------------------------------------------------------ shutdown.c */
267 NTSTATUS STDCALL
VfatShutdown (PDEVICE_OBJECT DeviceObject
,
270 /* -------------------------------------------------------- volume.c */
272 NTSTATUS
VfatQueryVolumeInformation (PVFAT_IRP_CONTEXT IrpContext
);
274 NTSTATUS
VfatSetVolumeInformation (PVFAT_IRP_CONTEXT IrpContext
);
276 /* ------------------------------------------------------ blockdev.c */
278 NTSTATUS
VfatReadDisk(IN PDEVICE_OBJECT pDeviceObject
,
279 IN PLARGE_INTEGER ReadOffset
,
283 NTSTATUS
VfatWriteDisk(IN PDEVICE_OBJECT pDeviceObject
,
284 IN PLARGE_INTEGER WriteOffset
,
285 IN ULONG WriteLength
,
288 NTSTATUS
VfatBlockDeviceIoControl (IN PDEVICE_OBJECT DeviceObject
,
290 IN PVOID InputBuffer
,
291 IN ULONG InputBufferSize
,
292 IN OUT PVOID OutputBuffer
,
293 IN OUT PULONG pOutputBufferSize
);
295 /* ----------------------------------------------------------- dir.c */
297 NTSTATUS
VfatDirectoryControl (PVFAT_IRP_CONTEXT
);
299 BOOL
FsdDosDateTimeToFileTime (WORD wDosDate
,
303 BOOL
FsdFileTimeToDosDateTime (TIME
*FileTime
,
307 /* -------------------------------------------------------- create.c */
309 NTSTATUS
VfatCreate (PVFAT_IRP_CONTEXT IrpContext
);
311 NTSTATUS
VfatOpenFile (PDEVICE_EXTENSION DeviceExt
,
312 PFILE_OBJECT FileObject
,
315 NTSTATUS
FindFile (PDEVICE_EXTENSION DeviceExt
,
322 VOID
vfat8Dot3ToString (PFAT_DIR_ENTRY pEntry
,
325 NTSTATUS
ReadVolumeLabel(PDEVICE_EXTENSION DeviceExt
,
328 BOOLEAN
IsDeletedEntry (PVOID Block
,
331 BOOLEAN
IsLastEntry (PVOID Block
,
334 /* --------------------------------------------------------- close.c */
336 NTSTATUS
VfatClose (PVFAT_IRP_CONTEXT IrpContext
);
338 NTSTATUS
VfatCloseFile(PDEVICE_EXTENSION DeviceExt
,
339 PFILE_OBJECT FileObject
);
341 /* ------------------------------------------------------- cleanup.c */
343 NTSTATUS
VfatCleanup (PVFAT_IRP_CONTEXT IrpContext
);
345 /* --------------------------------------------------------- fsctl.c */
347 NTSTATUS
VfatFileSystemControl (PVFAT_IRP_CONTEXT IrpContext
);
349 /* --------------------------------------------------------- finfo.c */
351 NTSTATUS
VfatQueryInformation (PVFAT_IRP_CONTEXT IrpContext
);
353 NTSTATUS
VfatSetInformation (PVFAT_IRP_CONTEXT IrpContext
);
356 VfatSetAllocationSizeInformation(PFILE_OBJECT FileObject
,
358 PDEVICE_EXTENSION DeviceExt
,
359 PLARGE_INTEGER AllocationSize
);
361 /* --------------------------------------------------------- iface.c */
363 NTSTATUS STDCALL
DriverEntry (PDRIVER_OBJECT DriverObject
,
364 PUNICODE_STRING RegistryPath
);
366 /* --------------------------------------------------------- dirwr.c */
368 NTSTATUS
VfatAddEntry (PDEVICE_EXTENSION DeviceExt
,
369 PFILE_OBJECT pFileObject
,
370 ULONG RequestedOptions
,UCHAR ReqAttr
);
372 NTSTATUS
VfatUpdateEntry (PDEVICE_EXTENSION DeviceExt
,
373 PFILE_OBJECT pFileObject
);
375 NTSTATUS
delEntry(PDEVICE_EXTENSION
,
378 /* -------------------------------------------------------- string.c */
380 BOOLEAN
wstrcmpjoki (PWSTR s1
,
383 PWCHAR
vfatGetNextPathElement (PWCHAR pFileName
);
385 VOID
vfatWSubString (PWCHAR pTarget
,
386 const PWCHAR pSource
,
389 BOOL
vfatIsFileNameValid (PWCHAR pFileName
);
391 /* ----------------------------------------------------------- fat.c */
393 NTSTATUS
OffsetToCluster (PDEVICE_EXTENSION DeviceExt
,
400 ULONGLONG
ClusterToSector (PDEVICE_EXTENSION DeviceExt
,
403 NTSTATUS
GetNextCluster (PDEVICE_EXTENSION DeviceExt
,
404 ULONG CurrentCluster
,
408 NTSTATUS
CountAvailableClusters (PDEVICE_EXTENSION DeviceExt
,
409 PLARGE_INTEGER Clusters
);
411 /* ------------------------------------------------------ direntry.c */
413 ULONG
vfatDirEntryGetFirstCluster (PDEVICE_EXTENSION pDeviceExt
,
414 PFAT_DIR_ENTRY pDirEntry
);
416 BOOL
vfatIsDirEntryDeleted (FATDirEntry
* pFatDirEntry
);
418 BOOL
vfatIsDirEntryVolume (FATDirEntry
* pFatDirEntry
);
420 BOOL
vfatIsDirEntryEndMarker (FATDirEntry
* pFatDirEntry
);
422 VOID
vfatGetDirEntryName (PFAT_DIR_ENTRY pDirEntry
,
425 NTSTATUS
vfatGetNextDirEntry(PVOID
* pContext
,
428 IN OUT PULONG pDirIndex
,
430 OUT PFAT_DIR_ENTRY pDirEntry
,
431 OUT PULONG pStartIndex
);
433 /* ----------------------------------------------------------- fcb.c */
435 PVFATFCB
vfatNewFCB (PWCHAR pFileName
);
437 VOID
vfatDestroyFCB (PVFATFCB pFCB
);
439 VOID
vfatGrabFCB (PDEVICE_EXTENSION pVCB
,
442 VOID
vfatReleaseFCB (PDEVICE_EXTENSION pVCB
,
445 VOID
vfatAddFCBToTable (PDEVICE_EXTENSION pVCB
,
448 PVFATFCB
vfatGrabFCBFromTable (PDEVICE_EXTENSION pDeviceExt
,
451 PVFATFCB
vfatMakeRootFCB (PDEVICE_EXTENSION pVCB
);
453 PVFATFCB
vfatOpenRootFCB (PDEVICE_EXTENSION pVCB
);
455 BOOL
vfatFCBIsDirectory (PVFATFCB FCB
);
457 NTSTATUS
vfatAttachFCBToFileObject (PDEVICE_EXTENSION vcb
,
459 PFILE_OBJECT fileObject
);
461 NTSTATUS
vfatDirFindFile (PDEVICE_EXTENSION pVCB
,
466 NTSTATUS
vfatGetFCBForFile (PDEVICE_EXTENSION pVCB
,
467 PVFATFCB
*pParentFCB
,
469 const PWSTR pFileName
);
471 NTSTATUS
vfatMakeFCBFromDirEntry (PVCB vcb
,
472 PVFATFCB directoryFCB
,
474 PFAT_DIR_ENTRY dirEntry
,
479 /* ------------------------------------------------------------ rw.c */
481 NTSTATUS
VfatRead (PVFAT_IRP_CONTEXT IrpContext
);
483 NTSTATUS
VfatWrite (PVFAT_IRP_CONTEXT IrpContext
);
485 NTSTATUS
NextCluster(PDEVICE_EXTENSION DeviceExt
,
488 PULONG CurrentCluster
,
491 /* ----------------------------------------------------------- misc.c */
493 NTSTATUS
VfatQueueRequest(PVFAT_IRP_CONTEXT IrpContext
);
495 PVFAT_IRP_CONTEXT
VfatAllocateIrpContext(PDEVICE_OBJECT DeviceObject
,
498 VOID
VfatFreeIrpContext(PVFAT_IRP_CONTEXT IrpContext
);
500 NTSTATUS STDCALL
VfatBuildRequest (PDEVICE_OBJECT DeviceObject
,
503 PVOID
VfatGetUserBuffer(IN PIRP
);
505 NTSTATUS
VfatLockUserBuffer(IN PIRP
, IN ULONG
,
509 VfatSetExtendedAttributes(PFILE_OBJECT FileObject
,