DISK_GEOMETRY DiskGeometry;
ULONG MediaChangeCount = 0;
PVOLUME_DEVICE_OBJECT VolumeDevice;
+ VCB *Vcb;
+ FF_ERROR Error;
DPRINT1("FatMountVolume()\n");
/* Remove unmounted VCBs */
FatiCleanVcbs(IrpContext);
+ /* Acquire the global exclusive lock */
+ FatAcquireExclusiveGlobal(IrpContext);
+
/* Create a new volume device object */
Status = IoCreateDevice(FatGlobalData.DriverObject,
sizeof(VOLUME_DEVICE_OBJECT) - sizeof(DEVICE_OBJECT),
FALSE,
(PDEVICE_OBJECT *)&VolumeDevice);
- if (!NT_SUCCESS(Status)) return Status;
+ if (!NT_SUCCESS(Status))
+ {
+ /* Release the global lock */
+ FatReleaseGlobal(IrpContext);
+
+ return Status;
+ }
/* Match alignment requirements */
if (TargetDeviceObject->AlignmentRequirement > VolumeDevice->DeviceObject.AlignmentRequirement)
Status = FatInitializeVcb(IrpContext, &VolumeDevice->Vcb, TargetDeviceObject, Vpb);
if (!NT_SUCCESS(Status)) goto FatMountVolumeCleanup;
+ Vcb = &VolumeDevice->Vcb;
+
+ /* Initialize FullFAT library */
+ Vcb->Ioman = FF_CreateIOMAN(NULL,
+ 8192,
+ VolumeDevice->DeviceObject.SectorSize,
+ &Error);
+
+ ASSERT(Vcb->Ioman);
+
+ /* Register block device read/write functions */
+ Error = FF_RegisterBlkDevice(Vcb->Ioman,
+ VolumeDevice->DeviceObject.SectorSize,
+ (FF_WRITE_BLOCKS)FatWriteBlocks,
+ (FF_READ_BLOCKS)FatReadBlocks,
+ Vcb);
+
+ if (Error)
+ {
+ DPRINT1("Registering block device with FullFAT failed with error %d\n", Error);
+ FF_DestroyIOMAN(Vcb->Ioman);
+ goto FatMountVolumeCleanup;
+ }
+
+ /* Mount the volume using FullFAT */
+ if(FF_MountPartition(Vcb->Ioman, 0))
+ {
+ DPRINT1("Partition mounting failed\n");
+ FF_DestroyIOMAN(Vcb->Ioman);
+ goto FatMountVolumeCleanup;
+ }
+
+ // TODO: Read BPB and store it in Vcb->Bpb
+
/* Create root DCB for it */
FatCreateRootDcb(IrpContext, &VolumeDevice->Vcb);
/* Keep trace of media changes */
VolumeDevice->Vcb.MediaChangeCount = MediaChangeCount;
+ //ObDereferenceObject(TargetDeviceObject);
+
+ /* Release the global lock */
+ FatReleaseGlobal(IrpContext);
+
/* Notify about volume mount */
- FsRtlNotifyVolumeEvent(VolumeDevice->Vcb.StreamFileObject, FSRTL_VOLUME_MOUNT);
+ //FsRtlNotifyVolumeEvent(VolumeDevice->Vcb.StreamFileObject, FSRTL_VOLUME_MOUNT);
/* Return success */
return STATUS_SUCCESS;
/* Unwind the routine actions */
IoDeleteDevice((PDEVICE_OBJECT)VolumeDevice);
+
+ /* Release the global lock */
+ FatReleaseGlobal(IrpContext);
+
return Status;
}
--- /dev/null
+/*
+ * PROJECT: ReactOS FAT file system driver
+ * LICENSE: GPL - See COPYING in the top level directory
+ * FILE: drivers/filesystems/fastfat/fullfat.c
+ * PURPOSE: FullFAT integration routines
+ * PROGRAMMERS: Aleksey Bragin (aleksey@reactos.org)
+ */
+
+/* INCLUDES *****************************************************************/
+
+#define NDEBUG
+#include "fastfat.h"
+
+/* GLOBALS ******************************************************************/
+
+#define TAG_FULLFAT 'FLUF'
+
+/* FUNCTIONS ****************************************************************/
+
+VOID *
+FF_Malloc(FF_T_UINT32 allocSize)
+{
+ return ExAllocatePoolWithTag(PagedPool, allocSize, TAG_FULLFAT);
+}
+
+VOID
+FF_Free(VOID *pBuffer)
+{
+ return ExFreePoolWithTag(pBuffer, TAG_FULLFAT);
+}
+
+FF_T_SINT32
+FatWriteBlocks(FF_T_UINT8 *pBuffer, FF_T_UINT32 SectorAddress, FF_T_UINT32 Count, void *pParam)
+{
+ DPRINT1("FatWriteBlocks %p %d %d %p\n", pBuffer, SectorAddress, Count, pParam);
+
+ return 0;
+}
+
+FF_T_SINT32
+FatReadBlocks(FF_T_UINT8 *DestBuffer, FF_T_UINT32 SectorAddress, FF_T_UINT32 Count, void *pParam)
+{
+ LARGE_INTEGER Offset;
+ PVOID Buffer;
+ PVCB Vcb = (PVCB)pParam;
+ PBCB Bcb;
+ ULONG SectorSize = 512; // FIXME: hardcoding 512 is bad
+
+ DPRINT1("FatReadBlocks %p %d %d %p\n", DestBuffer, SectorAddress, Count, pParam);
+
+ /* Calculate the offset */
+ Offset.QuadPart = Int32x32To64(SectorAddress, SectorSize);
+
+ if (!CcMapData(Vcb->StreamFileObject,
+ &Offset,
+ Count * SectorSize,
+ TRUE,
+ &Bcb,
+ &Buffer))
+ {
+ /* Mapping failed */
+ return 0;
+ }
+
+ /* Copy data to the buffer */
+ RtlCopyMemory(DestBuffer, Buffer, Count * SectorSize);
+
+ /* Unpin unneeded data */
+ CcUnpinData(Bcb);
+
+ /* Return amount of read data in sectors */
+ return Count;
+}
+
+/* EOF */