1 /* $Id: vfat.h,v 1.47 2002/09/08 10:22:13 chorns 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
;
70 unsigned char Filename
[8], Ext
[3], Attrib
, Res
[2];
71 unsigned short CreationTime
,CreationDate
,AccessDate
;
72 unsigned short FirstClusterHigh
; // higher
73 unsigned short UpdateTime
; //time create/update
74 unsigned short UpdateDate
; //date create/update
75 unsigned short FirstCluster
;
76 unsigned long FileSize
;
77 } __attribute__((packed
));
79 typedef struct _FATDirEntry FATDirEntry
, FAT_DIR_ENTRY
, *PFAT_DIR_ENTRY
;
83 unsigned char id
; // sequence number for slot
84 WCHAR name0_4
[5]; // first 5 characters in name
85 unsigned char attr
; // attribute byte
86 unsigned char reserved
; // always 0
87 unsigned char alias_checksum
; // checksum for 8.3 alias
88 WCHAR name5_10
[6]; // 6 more characters in name
89 unsigned char start
[2]; // starting cluster number
90 WCHAR name11_12
[2]; // last 2 characters in name
91 } __attribute__((packed
));
94 typedef struct _slot slot
;
102 #define VCB_VOLUME_LOCKED 0x0001
103 #define VCB_DISMOUNT_PENDING 0x0002
111 ULONG rootDirectorySectors
;
115 ULONG SectorsPerCluster
;
116 ULONG BytesPerSector
;
117 ULONG BytesPerCluster
;
118 ULONG NumberOfClusters
;
121 } FATINFO
, *PFATINFO
;
127 ERESOURCE DirResource
;
128 ERESOURCE FatResource
;
130 KSPIN_LOCK FcbListLock
;
131 LIST_ENTRY FcbListHead
;
133 PDEVICE_OBJECT StorageDevice
;
134 PFILE_OBJECT FATFileObject
;
136 ULONG LastAvailableCluster
;
137 ULONG AvailableClusters
;
138 BOOLEAN AvailableClustersValid
;
140 struct _VFATFCB
* VolumeFcb
;
141 } DEVICE_EXTENSION
, *PDEVICE_EXTENSION
, VCB
, *PVCB
;
145 PDRIVER_OBJECT DriverObject
;
146 PDEVICE_OBJECT DeviceObject
;
148 } VFAT_GLOBAL_DATA
, *PVFAT_GLOBAL_DATA
;
150 extern PVFAT_GLOBAL_DATA VfatGlobalData
;
152 #define FCB_CACHE_INITIALIZED 0x0001
153 #define FCB_DELETE_PENDING 0x0002
154 #define FCB_IS_FAT 0x0004
155 #define FCB_IS_PAGE_FILE 0x0008
156 #define FCB_IS_VOLUME 0x0010
157 #define FCB_UPDATE_DIRENTRY 0x0020
159 typedef struct _VFATFCB
161 REACTOS_COMMON_FCB_HEADER RFCB
;
162 SECTION_OBJECT_POINTERS SectionObjectPointers
;
164 /* point on filename (250 chars max) in PathName */
166 /* path+filename 260 max */
167 WCHAR PathName
[MAX_PATH
];
169 PDEVICE_EXTENSION pDevExt
;
170 LIST_ENTRY FcbListEntry
;
171 struct _VFATFCB
* parentFcb
;
173 PFILE_OBJECT FileObject
;
175 ERESOURCE PagingIoResource
;
176 ERESOURCE MainResource
;
178 SHARE_ACCESS FCBShareAccess
;
180 /* Structure members used only for paging files. */
183 } VFATFCB
, *PVFATFCB
;
185 typedef struct _VFATCCB
189 PFILE_OBJECT PtrFileObject
;
190 LARGE_INTEGER CurrentByteOffset
;
191 /* for DirectoryControl */
193 /* for DirectoryControl */
194 PWCHAR DirectorySearchPattern
;
198 } VFATCCB
, *PVFATCCB
;
200 #define TAG(A, B, C, D) (ULONG)(((A)<<0) + ((B)<<8) + ((C)<<16) + ((D)<<24))
202 #define TAG_CCB TAG('V', 'C', 'C', 'B')
204 #define ENTRIES_PER_SECTOR (BLOCKSIZE / sizeof(FATDirEntry))
206 typedef struct __DOSTIME
214 typedef struct __DOSDATE
222 #define IRPCONTEXT_CANWAIT 0x0001
227 PDEVICE_OBJECT DeviceObject
;
228 PDEVICE_EXTENSION DeviceExt
;
230 WORK_QUEUE_ITEM WorkQueueItem
;
231 PIO_STACK_LOCATION Stack
;
234 PFILE_OBJECT FileObject
;
235 } VFAT_IRP_CONTEXT
, *PVFAT_IRP_CONTEXT
;
237 /* ------------------------------------------------------ shutdown.c */
239 NTSTATUS STDCALL
VfatShutdown (PDEVICE_OBJECT DeviceObject
,
242 /* -------------------------------------------------------- volume.c */
244 NTSTATUS
VfatQueryVolumeInformation (PVFAT_IRP_CONTEXT IrpContext
);
246 NTSTATUS
VfatSetVolumeInformation (PVFAT_IRP_CONTEXT IrpContext
);
248 /* ------------------------------------------------------ blockdev.c */
250 NTSTATUS
VfatReadDisk(IN PDEVICE_OBJECT pDeviceObject
,
251 IN PLARGE_INTEGER ReadOffset
,
255 NTSTATUS
VfatWriteDisk(IN PDEVICE_OBJECT pDeviceObject
,
256 IN PLARGE_INTEGER WriteOffset
,
257 IN ULONG WriteLength
,
260 NTSTATUS
VfatBlockDeviceIoControl (IN PDEVICE_OBJECT DeviceObject
,
262 IN PVOID InputBuffer
,
263 IN ULONG InputBufferSize
,
264 IN OUT PVOID OutputBuffer
,
265 IN OUT PULONG pOutputBufferSize
);
267 /* ----------------------------------------------------------- dir.c */
269 NTSTATUS
VfatDirectoryControl (PVFAT_IRP_CONTEXT
);
271 BOOL
FsdDosDateTimeToFileTime (WORD wDosDate
,
275 BOOL
FsdFileTimeToDosDateTime (TIME
*FileTime
,
279 /* -------------------------------------------------------- create.c */
281 NTSTATUS
VfatCreate (PVFAT_IRP_CONTEXT IrpContext
);
283 NTSTATUS
VfatOpenFile (PDEVICE_EXTENSION DeviceExt
,
284 PFILE_OBJECT FileObject
,
287 NTSTATUS
FindFile (PDEVICE_EXTENSION DeviceExt
,
294 VOID
vfat8Dot3ToString (PCHAR pBasename
,
298 NTSTATUS
ReadVolumeLabel(PDEVICE_EXTENSION DeviceExt
,
301 BOOLEAN
IsDeletedEntry (PVOID Block
,
304 BOOLEAN
IsLastEntry (PVOID Block
,
307 /* --------------------------------------------------------- close.c */
309 NTSTATUS
VfatClose (PVFAT_IRP_CONTEXT IrpContext
);
311 NTSTATUS
VfatCloseFile(PDEVICE_EXTENSION DeviceExt
,
312 PFILE_OBJECT FileObject
);
314 /* ------------------------------------------------------- cleanup.c */
316 NTSTATUS
VfatCleanup (PVFAT_IRP_CONTEXT IrpContext
);
318 /* --------------------------------------------------------- fsctl.c */
320 NTSTATUS
VfatFileSystemControl (PVFAT_IRP_CONTEXT IrpContext
);
322 /* --------------------------------------------------------- finfo.c */
324 NTSTATUS
VfatQueryInformation (PVFAT_IRP_CONTEXT IrpContext
);
326 NTSTATUS
VfatSetInformation (PVFAT_IRP_CONTEXT IrpContext
);
329 VfatSetAllocationSizeInformation(PFILE_OBJECT FileObject
,
331 PDEVICE_EXTENSION DeviceExt
,
332 PLARGE_INTEGER AllocationSize
);
334 /* --------------------------------------------------------- iface.c */
336 NTSTATUS STDCALL
DriverEntry (PDRIVER_OBJECT DriverObject
,
337 PUNICODE_STRING RegistryPath
);
339 /* --------------------------------------------------------- dirwr.c */
341 NTSTATUS
VfatAddEntry (PDEVICE_EXTENSION DeviceExt
,
342 PFILE_OBJECT pFileObject
,
343 ULONG RequestedOptions
,UCHAR ReqAttr
);
345 NTSTATUS
VfatUpdateEntry (PDEVICE_EXTENSION DeviceExt
,
346 PFILE_OBJECT pFileObject
);
348 NTSTATUS
delEntry(PDEVICE_EXTENSION
,
351 /* -------------------------------------------------------- string.c */
353 VOID
vfat_initstr (wchar_t *wstr
,
356 wchar_t* vfat_wcsncat (wchar_t * dest
,
361 wchar_t* vfat_wcsncpy (wchar_t * dest
,
365 wchar_t* vfat_movstr (wchar_t *src
,
370 BOOLEAN
wstrcmpi (PWSTR s1
,
373 BOOLEAN
wstrcmpjoki (PWSTR s1
,
376 PWCHAR
vfatGetNextPathElement (PWCHAR pFileName
);
378 VOID
vfatWSubString (PWCHAR pTarget
,
379 const PWCHAR pSource
,
382 BOOL
vfatIsFileNameValid (PWCHAR pFileName
);
384 /* ----------------------------------------------------------- fat.c */
386 NTSTATUS
OffsetToCluster (PDEVICE_EXTENSION DeviceExt
,
393 ULONG
ClusterToSector (PDEVICE_EXTENSION DeviceExt
,
396 NTSTATUS
GetNextCluster (PDEVICE_EXTENSION DeviceExt
,
397 ULONG CurrentCluster
,
401 NTSTATUS
GetNextSector (PDEVICE_EXTENSION DeviceExt
,
406 NTSTATUS
CountAvailableClusters (PDEVICE_EXTENSION DeviceExt
,
407 PLARGE_INTEGER Clusters
);
409 /* ------------------------------------------------------ direntry.c */
411 ULONG
vfatDirEntryGetFirstCluster (PDEVICE_EXTENSION pDeviceExt
,
412 PFAT_DIR_ENTRY pDirEntry
);
414 BOOL
vfatIsDirEntryDeleted (FATDirEntry
* pFatDirEntry
);
416 BOOL
vfatIsDirEntryVolume (FATDirEntry
* pFatDirEntry
);
418 BOOL
vfatIsDirEntryEndMarker (FATDirEntry
* pFatDirEntry
);
420 VOID
vfatGetDirEntryName (PFAT_DIR_ENTRY pDirEntry
,
423 NTSTATUS
vfatGetNextDirEntry (PDEVICE_EXTENSION pDeviceExt
,
424 PVFATFCB pDirectoryFCB
,
425 ULONG
* pDirectoryIndex
,
427 PFAT_DIR_ENTRY pDirEntry
);
429 /* ----------------------------------------------------------- fcb.c */
431 PVFATFCB
vfatNewFCB (PWCHAR pFileName
);
433 VOID
vfatDestroyFCB (PVFATFCB pFCB
);
435 VOID
vfatGrabFCB (PDEVICE_EXTENSION pVCB
,
438 VOID
vfatReleaseFCB (PDEVICE_EXTENSION pVCB
,
441 VOID
vfatAddFCBToTable (PDEVICE_EXTENSION pVCB
,
444 PVFATFCB
vfatGrabFCBFromTable (PDEVICE_EXTENSION pDeviceExt
,
447 PVFATFCB
vfatMakeRootFCB (PDEVICE_EXTENSION pVCB
);
449 PVFATFCB
vfatOpenRootFCB (PDEVICE_EXTENSION pVCB
);
451 BOOL
vfatFCBIsDirectory (PDEVICE_EXTENSION pVCB
,
454 NTSTATUS
vfatAttachFCBToFileObject (PDEVICE_EXTENSION vcb
,
456 PFILE_OBJECT fileObject
);
458 NTSTATUS
vfatDirFindFile (PDEVICE_EXTENSION pVCB
,
463 NTSTATUS
vfatGetFCBForFile (PDEVICE_EXTENSION pVCB
,
464 PVFATFCB
*pParentFCB
,
466 const PWSTR pFileName
);
468 NTSTATUS
vfatMakeFCBFromDirEntry (PVCB vcb
,
469 PVFATFCB directoryFCB
,
471 PFAT_DIR_ENTRY dirEntry
,
475 /* ------------------------------------------------------------ rw.c */
477 NTSTATUS
VfatRead (PVFAT_IRP_CONTEXT IrpContext
);
479 NTSTATUS
VfatWrite (PVFAT_IRP_CONTEXT IrpContext
);
481 NTSTATUS
VfatWriteFile (PDEVICE_EXTENSION DeviceExt
,
482 PFILE_OBJECT FileObject
,
490 NTSTATUS
VfatReadFile (PDEVICE_EXTENSION DeviceExt
,
491 PFILE_OBJECT FileObject
,
492 PVOID Buffer
, ULONG Length
,
497 NTSTATUS
NextCluster(PDEVICE_EXTENSION DeviceExt
,
500 PULONG CurrentCluster
,
503 /* ----------------------------------------------------------- misc.c */
505 NTSTATUS
VfatQueueRequest(PVFAT_IRP_CONTEXT IrpContext
);
507 PVFAT_IRP_CONTEXT
VfatAllocateIrpContext(PDEVICE_OBJECT DeviceObject
,
510 VOID
VfatFreeIrpContext(PVFAT_IRP_CONTEXT IrpContext
);
512 NTSTATUS STDCALL
VfatBuildRequest (PDEVICE_OBJECT DeviceObject
,
515 PVOID
VfatGetUserBuffer(IN PIRP
);
517 NTSTATUS
VfatLockUserBuffer(IN PIRP
, IN ULONG
,
521 VfatSetExtendedAttributes(PFILE_OBJECT FileObject
,