1 /* $Id: vfat.h,v 1.46 2002/09/07 15:12:03 chorns Exp $ */
3 #define NTOS_KERNEL_MODE
6 #define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))
7 #define ROUND_DOWN(N, S) ((N) - ((N) % (S)))
11 unsigned char magic0
, res0
, magic1
;
12 unsigned char OEMName
[8];
13 unsigned short BytesPerSector
;
14 unsigned char SectorsPerCluster
;
15 unsigned short ReservedSectors
;
16 unsigned char FATCount
;
17 unsigned short RootEntries
, Sectors
;
19 unsigned short FATSectors
, SectorsPerTrack
, Heads
;
20 unsigned long HiddenSectors
, SectorsHuge
;
21 unsigned char Drive
, Res1
, Sig
;
22 unsigned long VolumeID
;
23 unsigned char VolumeLabel
[11], SysType
[8];
24 unsigned char Res2
[446];
25 unsigned long Signatur1
;
26 } __attribute__((packed
));
30 unsigned char magic0
, res0
, magic1
; // 0
31 unsigned char OEMName
[8]; // 3
32 unsigned short BytesPerSector
; // 11
33 unsigned char SectorsPerCluster
; // 13
34 unsigned short ReservedSectors
; // 14
35 unsigned char FATCount
; // 16
36 unsigned short RootEntries
, Sectors
; // 17
37 unsigned char Media
; // 21
38 unsigned short FATSectors
, SectorsPerTrack
, Heads
; // 22
39 unsigned long HiddenSectors
, SectorsHuge
; // 28
40 unsigned long FATSectors32
; // 36
41 unsigned short ExtFlag
; // 40
42 unsigned short FSVersion
; // 42
43 unsigned long RootCluster
; // 44
44 unsigned short FSInfoSector
; // 48
45 unsigned long BootBackup
; // 50
46 unsigned char Res3
[10]; // 54
47 unsigned char Drive
; // 64
48 unsigned char Res4
; // 65
49 unsigned char ExtBootSignature
; // 66
50 unsigned long VolumeID
; // 67
51 unsigned char VolumeLabel
[11], SysType
[8]; // 71
52 unsigned char Res2
[418]; // 90
53 unsigned long Signature1
; // 508
54 } __attribute__((packed
));
56 struct _BootBackupSector
58 unsigned long ExtBootSignature2
; // 0
59 unsigned char Res6
[480]; // 4
60 unsigned long FSINFOSignature
; // 484
61 unsigned long FreeCluster
; // 488
62 unsigned long NextCluster
; // 492
63 unsigned char Res7
[12]; // 496
64 unsigned long Signatur2
; // 508
65 } __attribute__((packed
));
67 typedef struct _BootSector BootSector
;
71 unsigned char Filename
[8], Ext
[3], Attrib
, Res
[2];
72 unsigned short CreationTime
,CreationDate
,AccessDate
;
73 unsigned short FirstClusterHigh
; // higher
74 unsigned short UpdateTime
; //time create/update
75 unsigned short UpdateDate
; //date create/update
76 unsigned short FirstCluster
;
77 unsigned long FileSize
;
78 } __attribute__((packed
));
80 typedef struct _FATDirEntry FATDirEntry
, FAT_DIR_ENTRY
, *PFAT_DIR_ENTRY
;
84 unsigned char id
; // sequence number for slot
85 WCHAR name0_4
[5]; // first 5 characters in name
86 unsigned char attr
; // attribute byte
87 unsigned char reserved
; // always 0
88 unsigned char alias_checksum
; // checksum for 8.3 alias
89 WCHAR name5_10
[6]; // 6 more characters in name
90 unsigned char start
[2]; // starting cluster number
91 WCHAR name11_12
[2]; // last 2 characters in name
92 } __attribute__((packed
));
95 typedef struct _slot slot
;
103 #define VCB_VOLUME_LOCKED 0x0001
104 #define VCB_DISMOUNT_PENDING 0x0002
112 ULONG rootDirectorySectors
;
116 ULONG SectorsPerCluster
;
117 ULONG BytesPerSector
;
118 ULONG BytesPerCluster
;
119 ULONG NumberOfClusters
;
122 } FATINFO
, *PFATINFO
;
128 ERESOURCE DirResource
;
129 ERESOURCE FatResource
;
131 KSPIN_LOCK FcbListLock
;
132 LIST_ENTRY FcbListHead
;
134 PDEVICE_OBJECT StorageDevice
;
135 PFILE_OBJECT FATFileObject
;
137 ULONG LastAvailableCluster
;
138 ULONG AvailableClusters
;
139 BOOLEAN AvailableClustersValid
;
141 struct _VFATFCB
* VolumeFcb
;
142 } DEVICE_EXTENSION
, *PDEVICE_EXTENSION
, VCB
, *PVCB
;
146 PDRIVER_OBJECT DriverObject
;
147 PDEVICE_OBJECT DeviceObject
;
149 } VFAT_GLOBAL_DATA
, *PVFAT_GLOBAL_DATA
;
151 extern PVFAT_GLOBAL_DATA VfatGlobalData
;
153 #define FCB_CACHE_INITIALIZED 0x0001
154 #define FCB_DELETE_PENDING 0x0002
155 #define FCB_IS_FAT 0x0004
156 #define FCB_IS_PAGE_FILE 0x0008
157 #define FCB_IS_VOLUME 0x0010
158 #define FCB_UPDATE_DIRENTRY 0x0020
160 typedef struct _VFATFCB
162 REACTOS_COMMON_FCB_HEADER RFCB
;
163 SECTION_OBJECT_POINTERS SectionObjectPointers
;
165 /* point on filename (250 chars max) in PathName */
167 /* path+filename 260 max */
168 WCHAR PathName
[MAX_PATH
];
170 PDEVICE_EXTENSION pDevExt
;
171 LIST_ENTRY FcbListEntry
;
172 struct _VFATFCB
* parentFcb
;
174 PFILE_OBJECT FileObject
;
176 ERESOURCE PagingIoResource
;
177 ERESOURCE MainResource
;
179 SHARE_ACCESS FCBShareAccess
;
181 /* Structure members used only for paging files. */
184 } VFATFCB
, *PVFATFCB
;
186 typedef struct _VFATCCB
190 PFILE_OBJECT PtrFileObject
;
191 LARGE_INTEGER CurrentByteOffset
;
192 /* for DirectoryControl */
194 /* for DirectoryControl */
195 PWCHAR DirectorySearchPattern
;
199 } VFATCCB
, *PVFATCCB
;
202 #define TAG(A, B, C, D) (ULONG)(((A)<<0) + ((B)<<8) + ((C)<<16) + ((D)<<24))
205 #define TAG_CCB TAG('V', 'C', 'C', 'B')
207 #define ENTRIES_PER_SECTOR (BLOCKSIZE / sizeof(FATDirEntry))
209 typedef struct __DOSTIME
217 typedef struct __DOSDATE
225 #define IRPCONTEXT_CANWAIT 0x0001
230 PDEVICE_OBJECT DeviceObject
;
231 PDEVICE_EXTENSION DeviceExt
;
233 WORK_QUEUE_ITEM WorkQueueItem
;
234 PIO_STACK_LOCATION Stack
;
237 PFILE_OBJECT FileObject
;
238 } VFAT_IRP_CONTEXT
, *PVFAT_IRP_CONTEXT
;
240 /* ------------------------------------------------------ shutdown.c */
242 NTSTATUS STDCALL
VfatShutdown (PDEVICE_OBJECT DeviceObject
,
245 /* -------------------------------------------------------- volume.c */
247 NTSTATUS
VfatQueryVolumeInformation (PVFAT_IRP_CONTEXT IrpContext
);
249 NTSTATUS
VfatSetVolumeInformation (PVFAT_IRP_CONTEXT IrpContext
);
251 /* ------------------------------------------------------ blockdev.c */
253 NTSTATUS
VfatReadDisk(IN PDEVICE_OBJECT pDeviceObject
,
254 IN PLARGE_INTEGER ReadOffset
,
258 NTSTATUS
VfatWriteDisk(IN PDEVICE_OBJECT pDeviceObject
,
259 IN PLARGE_INTEGER WriteOffset
,
260 IN ULONG WriteLength
,
263 NTSTATUS
VfatBlockDeviceIoControl (IN PDEVICE_OBJECT DeviceObject
,
265 IN PVOID InputBuffer
,
266 IN ULONG InputBufferSize
,
267 IN OUT PVOID OutputBuffer
,
268 IN OUT PULONG pOutputBufferSize
);
270 /* ----------------------------------------------------------- dir.c */
272 NTSTATUS
VfatDirectoryControl (PVFAT_IRP_CONTEXT
);
274 BOOL
FsdDosDateTimeToFileTime (WORD wDosDate
,
276 LARGE_INTEGER
*FileTime
);
278 BOOL
FsdFileTimeToDosDateTime (LARGE_INTEGER
*FileTime
,
282 /* -------------------------------------------------------- create.c */
284 NTSTATUS
VfatCreate (PVFAT_IRP_CONTEXT IrpContext
);
286 NTSTATUS
VfatOpenFile (PDEVICE_EXTENSION DeviceExt
,
287 PFILE_OBJECT FileObject
,
290 NTSTATUS
FindFile (PDEVICE_EXTENSION DeviceExt
,
297 VOID
vfat8Dot3ToString (PCHAR pBasename
,
301 NTSTATUS
ReadVolumeLabel(PDEVICE_EXTENSION DeviceExt
,
304 BOOLEAN
IsDeletedEntry (PVOID Block
,
307 BOOLEAN
IsLastEntry (PVOID Block
,
310 /* --------------------------------------------------------- close.c */
312 NTSTATUS
VfatClose (PVFAT_IRP_CONTEXT IrpContext
);
314 NTSTATUS
VfatCloseFile(PDEVICE_EXTENSION DeviceExt
,
315 PFILE_OBJECT FileObject
);
317 /* ------------------------------------------------------- cleanup.c */
319 NTSTATUS
VfatCleanup (PVFAT_IRP_CONTEXT IrpContext
);
321 /* --------------------------------------------------------- fsctl.c */
323 NTSTATUS
VfatFileSystemControl (PVFAT_IRP_CONTEXT IrpContext
);
325 /* --------------------------------------------------------- finfo.c */
327 NTSTATUS
VfatQueryInformation (PVFAT_IRP_CONTEXT IrpContext
);
329 NTSTATUS
VfatSetInformation (PVFAT_IRP_CONTEXT IrpContext
);
332 VfatSetAllocationSizeInformation(PFILE_OBJECT FileObject
,
334 PDEVICE_EXTENSION DeviceExt
,
335 PLARGE_INTEGER AllocationSize
);
337 /* --------------------------------------------------------- iface.c */
339 NTSTATUS STDCALL
DriverEntry (PDRIVER_OBJECT DriverObject
,
340 PUNICODE_STRING RegistryPath
);
342 /* --------------------------------------------------------- dirwr.c */
344 NTSTATUS
VfatAddEntry (PDEVICE_EXTENSION DeviceExt
,
345 PFILE_OBJECT pFileObject
,
346 ULONG RequestedOptions
,UCHAR ReqAttr
);
348 NTSTATUS
VfatUpdateEntry (PDEVICE_EXTENSION DeviceExt
,
349 PFILE_OBJECT pFileObject
);
351 NTSTATUS
delEntry(PDEVICE_EXTENSION
,
354 /* -------------------------------------------------------- string.c */
356 VOID
vfat_initstr (wchar_t *wstr
,
359 wchar_t* vfat_wcsncat (wchar_t * dest
,
364 wchar_t* vfat_wcsncpy (wchar_t * dest
,
368 wchar_t* vfat_movstr (wchar_t *src
,
373 BOOLEAN
wstrcmpi (PWSTR s1
,
376 BOOLEAN
wstrcmpjoki (PWSTR s1
,
379 PWCHAR
vfatGetNextPathElement (PWCHAR pFileName
);
381 VOID
vfatWSubString (PWCHAR pTarget
,
382 const PWCHAR pSource
,
385 BOOL
vfatIsFileNameValid (PWCHAR pFileName
);
387 /* ----------------------------------------------------------- fat.c */
389 NTSTATUS
OffsetToCluster (PDEVICE_EXTENSION DeviceExt
,
396 ULONG
ClusterToSector (PDEVICE_EXTENSION DeviceExt
,
399 NTSTATUS
GetNextCluster (PDEVICE_EXTENSION DeviceExt
,
400 ULONG CurrentCluster
,
404 NTSTATUS
GetNextSector (PDEVICE_EXTENSION DeviceExt
,
409 NTSTATUS
CountAvailableClusters (PDEVICE_EXTENSION DeviceExt
,
410 PLARGE_INTEGER Clusters
);
412 /* ------------------------------------------------------ direntry.c */
414 ULONG
vfatDirEntryGetFirstCluster (PDEVICE_EXTENSION pDeviceExt
,
415 PFAT_DIR_ENTRY pDirEntry
);
417 BOOL
vfatIsDirEntryDeleted (FATDirEntry
* pFatDirEntry
);
419 BOOL
vfatIsDirEntryVolume (FATDirEntry
* pFatDirEntry
);
421 BOOL
vfatIsDirEntryEndMarker (FATDirEntry
* pFatDirEntry
);
423 VOID
vfatGetDirEntryName (PFAT_DIR_ENTRY pDirEntry
,
426 NTSTATUS
vfatGetNextDirEntry (PDEVICE_EXTENSION pDeviceExt
,
427 PVFATFCB pDirectoryFCB
,
428 ULONG
* pDirectoryIndex
,
430 PFAT_DIR_ENTRY pDirEntry
);
432 /* ----------------------------------------------------------- fcb.c */
434 PVFATFCB
vfatNewFCB (PWCHAR pFileName
);
436 VOID
vfatDestroyFCB (PVFATFCB pFCB
);
438 VOID
vfatGrabFCB (PDEVICE_EXTENSION pVCB
,
441 VOID
vfatReleaseFCB (PDEVICE_EXTENSION pVCB
,
444 VOID
vfatAddFCBToTable (PDEVICE_EXTENSION pVCB
,
447 PVFATFCB
vfatGrabFCBFromTable (PDEVICE_EXTENSION pDeviceExt
,
450 PVFATFCB
vfatMakeRootFCB (PDEVICE_EXTENSION pVCB
);
452 PVFATFCB
vfatOpenRootFCB (PDEVICE_EXTENSION pVCB
);
454 BOOL
vfatFCBIsDirectory (PDEVICE_EXTENSION pVCB
,
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
,
478 /* ------------------------------------------------------------ rw.c */
480 NTSTATUS
VfatRead (PVFAT_IRP_CONTEXT IrpContext
);
482 NTSTATUS
VfatWrite (PVFAT_IRP_CONTEXT IrpContext
);
484 NTSTATUS
VfatWriteFile (PDEVICE_EXTENSION DeviceExt
,
485 PFILE_OBJECT FileObject
,
493 NTSTATUS
VfatReadFile (PDEVICE_EXTENSION DeviceExt
,
494 PFILE_OBJECT FileObject
,
495 PVOID Buffer
, ULONG Length
,
500 NTSTATUS
NextCluster(PDEVICE_EXTENSION DeviceExt
,
503 PULONG CurrentCluster
,
506 /* ----------------------------------------------------------- misc.c */
508 NTSTATUS
VfatQueueRequest(PVFAT_IRP_CONTEXT IrpContext
);
510 PVFAT_IRP_CONTEXT
VfatAllocateIrpContext(PDEVICE_OBJECT DeviceObject
,
513 VOID
VfatFreeIrpContext(PVFAT_IRP_CONTEXT IrpContext
);
515 NTSTATUS STDCALL
VfatBuildRequest (PDEVICE_OBJECT DeviceObject
,
518 PVOID
VfatGetUserBuffer(IN PIRP
);
520 NTSTATUS
VfatLockUserBuffer(IN PIRP
, IN ULONG
,
524 VfatSetExtendedAttributes(PFILE_OBJECT FileObject
,