2002-08-14 20:58:39 +00:00
|
|
|
/*
|
2022-09-24 13:24:08 +00:00
|
|
|
* PROJECT: VFAT Filesystem
|
|
|
|
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
|
|
|
|
* PURPOSE: Driver entry interface
|
|
|
|
* COPYRIGHT: Copyright 1998 Jason Filby <jasonfilby@yahoo.com>
|
|
|
|
* Copyright 2010-2018 Pierre Schweitzer <pierre@reactos.org>
|
1999-12-11 21:14:49 +00:00
|
|
|
*/
|
1998-12-20 19:41:39 +00:00
|
|
|
|
1999-12-11 21:14:49 +00:00
|
|
|
/* INCLUDES *****************************************************************/
|
1998-12-20 19:41:39 +00:00
|
|
|
|
1999-12-11 21:14:49 +00:00
|
|
|
#include "vfat.h"
|
1998-12-20 19:41:39 +00:00
|
|
|
|
2013-12-19 16:20:28 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
1999-12-11 21:14:49 +00:00
|
|
|
/* GLOBALS *****************************************************************/
|
1998-10-05 04:00:59 +00:00
|
|
|
|
2002-03-18 22:37:13 +00:00
|
|
|
PVFAT_GLOBAL_DATA VfatGlobalData;
|
1998-10-05 04:00:59 +00:00
|
|
|
|
1999-12-11 21:14:49 +00:00
|
|
|
/* FUNCTIONS ****************************************************************/
|
1999-06-27 23:06:50 +00:00
|
|
|
|
1998-10-05 04:00:59 +00:00
|
|
|
/*
|
2005-01-12 10:46:13 +00:00
|
|
|
* FUNCTION: Called by the system to initialize the driver
|
1998-10-05 04:00:59 +00:00
|
|
|
* ARGUMENTS:
|
|
|
|
* DriverObject = object describing this driver
|
|
|
|
* RegistryPath = path to our configuration entries
|
|
|
|
* RETURNS: Success or failure
|
|
|
|
*/
|
2020-10-06 19:44:01 +00:00
|
|
|
CODE_SEG("INIT")
|
2013-12-09 10:35:15 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
DriverEntry(
|
|
|
|
IN PDRIVER_OBJECT DriverObject,
|
|
|
|
IN PUNICODE_STRING RegistryPath)
|
1998-10-05 04:00:59 +00:00
|
|
|
{
|
2013-12-09 10:35:15 +00:00
|
|
|
PDEVICE_OBJECT DeviceObject;
|
2022-09-13 20:37:04 +00:00
|
|
|
UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\FatX");
|
2013-12-09 10:35:15 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
UNREFERENCED_PARAMETER(RegistryPath);
|
|
|
|
|
|
|
|
Status = IoCreateDevice(DriverObject,
|
|
|
|
sizeof(VFAT_GLOBAL_DATA),
|
|
|
|
&DeviceName,
|
|
|
|
FILE_DEVICE_DISK_FILE_SYSTEM,
|
|
|
|
0,
|
|
|
|
FALSE,
|
|
|
|
&DeviceObject);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
VfatGlobalData = DeviceObject->DeviceExtension;
|
|
|
|
RtlZeroMemory (VfatGlobalData, sizeof(VFAT_GLOBAL_DATA));
|
|
|
|
VfatGlobalData->DriverObject = DriverObject;
|
|
|
|
VfatGlobalData->DeviceObject = DeviceObject;
|
2017-09-24 08:56:06 +00:00
|
|
|
VfatGlobalData->NumberProcessors = KeNumberProcessors;
|
2015-11-01 08:55:47 +00:00
|
|
|
/* Enable this to enter the debugger when file system corruption
|
|
|
|
* has been detected:
|
|
|
|
VfatGlobalData->Flags = VFAT_BREAK_ON_CORRUPTION; */
|
2013-12-09 10:35:15 +00:00
|
|
|
|
[FASTFAT] Implement delayed close
When we're about to close a file (ie, forget everything about it
and release any associated structure), actually delay it.
This allows keep data fresh in memory for faster reuse in case
it would be required. The effective closing will only happen after some time.
For specific operations, this will produce a real speed up in ReactOS.
For instance, with that patch, Winamp starts within seconds, instead of dozen
of minutes.
In most cases, it will bring ReactOS to performances it had before fixing
the huge leak in FastFAT (commit 94ead99) without leaking the whole FS.
For now, due to regressions, this is only activated for files and not
for directories. Once it gets fixed, it will be enabled for both.
CORE-14826
CORE-14917
2018-08-18 15:04:02 +00:00
|
|
|
/* Delayed close support */
|
|
|
|
ExInitializeFastMutex(&VfatGlobalData->CloseMutex);
|
|
|
|
InitializeListHead(&VfatGlobalData->CloseListHead);
|
|
|
|
VfatGlobalData->CloseCount = 0;
|
|
|
|
VfatGlobalData->CloseWorkerRunning = FALSE;
|
2018-08-19 07:55:38 +00:00
|
|
|
VfatGlobalData->ShutdownStarted = FALSE;
|
[FASTFAT] Implement delayed close
When we're about to close a file (ie, forget everything about it
and release any associated structure), actually delay it.
This allows keep data fresh in memory for faster reuse in case
it would be required. The effective closing will only happen after some time.
For specific operations, this will produce a real speed up in ReactOS.
For instance, with that patch, Winamp starts within seconds, instead of dozen
of minutes.
In most cases, it will bring ReactOS to performances it had before fixing
the huge leak in FastFAT (commit 94ead99) without leaking the whole FS.
For now, due to regressions, this is only activated for files and not
for directories. Once it gets fixed, it will be enabled for both.
CORE-14826
CORE-14917
2018-08-18 15:04:02 +00:00
|
|
|
VfatGlobalData->CloseWorkItem = IoAllocateWorkItem(DeviceObject);
|
|
|
|
if (VfatGlobalData->CloseWorkItem == NULL)
|
|
|
|
{
|
|
|
|
IoDeleteDevice(DeviceObject);
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
|
2013-12-09 10:35:15 +00:00
|
|
|
DeviceObject->Flags |= DO_DIRECT_IO;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_CLOSE] = VfatBuildRequest;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_CREATE] = VfatBuildRequest;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_READ] = VfatBuildRequest;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_WRITE] = VfatBuildRequest;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = VfatBuildRequest;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = VfatBuildRequest;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = VfatBuildRequest;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] = VfatBuildRequest;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] = VfatBuildRequest;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] = VfatBuildRequest;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = VfatShutdown;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] = VfatBuildRequest;
|
2014-10-29 23:10:31 +00:00
|
|
|
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = VfatBuildRequest;
|
2013-12-09 10:35:15 +00:00
|
|
|
DriverObject->MajorFunction[IRP_MJ_CLEANUP] = VfatBuildRequest;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = VfatBuildRequest;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_PNP] = VfatBuildRequest;
|
|
|
|
|
|
|
|
DriverObject->DriverUnload = NULL;
|
|
|
|
|
|
|
|
/* Cache manager */
|
|
|
|
VfatGlobalData->CacheMgrCallbacks.AcquireForLazyWrite = VfatAcquireForLazyWrite;
|
|
|
|
VfatGlobalData->CacheMgrCallbacks.ReleaseFromLazyWrite = VfatReleaseFromLazyWrite;
|
2018-02-17 12:48:32 +00:00
|
|
|
VfatGlobalData->CacheMgrCallbacks.AcquireForReadAhead = VfatAcquireForLazyWrite;
|
|
|
|
VfatGlobalData->CacheMgrCallbacks.ReleaseFromReadAhead = VfatReleaseFromLazyWrite;
|
2013-12-09 10:35:15 +00:00
|
|
|
|
|
|
|
/* Fast I/O */
|
|
|
|
VfatInitFastIoRoutines(&VfatGlobalData->FastIoDispatch);
|
|
|
|
DriverObject->FastIoDispatch = &VfatGlobalData->FastIoDispatch;
|
|
|
|
|
|
|
|
/* Private lists */
|
|
|
|
ExInitializeNPagedLookasideList(&VfatGlobalData->FcbLookasideList,
|
|
|
|
NULL, NULL, 0, sizeof(VFATFCB), TAG_FCB, 0);
|
|
|
|
ExInitializeNPagedLookasideList(&VfatGlobalData->CcbLookasideList,
|
|
|
|
NULL, NULL, 0, sizeof(VFATCCB), TAG_CCB, 0);
|
|
|
|
ExInitializeNPagedLookasideList(&VfatGlobalData->IrpContextLookasideList,
|
|
|
|
NULL, NULL, 0, sizeof(VFAT_IRP_CONTEXT), TAG_IRP, 0);
|
[FASTFAT] Implement delayed close
When we're about to close a file (ie, forget everything about it
and release any associated structure), actually delay it.
This allows keep data fresh in memory for faster reuse in case
it would be required. The effective closing will only happen after some time.
For specific operations, this will produce a real speed up in ReactOS.
For instance, with that patch, Winamp starts within seconds, instead of dozen
of minutes.
In most cases, it will bring ReactOS to performances it had before fixing
the huge leak in FastFAT (commit 94ead99) without leaking the whole FS.
For now, due to regressions, this is only activated for files and not
for directories. Once it gets fixed, it will be enabled for both.
CORE-14826
CORE-14917
2018-08-18 15:04:02 +00:00
|
|
|
ExInitializePagedLookasideList(&VfatGlobalData->CloseContextLookasideList,
|
|
|
|
NULL, NULL, 0, sizeof(VFAT_CLOSE_CONTEXT), TAG_CLOSE, 0);
|
2013-12-09 10:35:15 +00:00
|
|
|
|
|
|
|
ExInitializeResourceLite(&VfatGlobalData->VolumeListLock);
|
|
|
|
InitializeListHead(&VfatGlobalData->VolumeListHead);
|
|
|
|
IoRegisterFileSystem(DeviceObject);
|
2018-04-28 07:34:10 +00:00
|
|
|
|
|
|
|
#ifdef KDBG
|
|
|
|
{
|
|
|
|
BOOLEAN Registered;
|
|
|
|
|
2018-04-29 10:23:18 +00:00
|
|
|
Registered = KdRosRegisterCliCallback(vfatKdbgHandler);
|
2022-09-13 20:31:22 +00:00
|
|
|
DPRINT1("VFATFS KDBG extension registered: %s\n", (Registered ? "yes" : "no"));
|
2018-04-28 07:34:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-12-09 10:35:15 +00:00
|
|
|
return STATUS_SUCCESS;
|
1998-10-05 04:00:59 +00:00
|
|
|
}
|
2001-03-06 08:19:58 +00:00
|
|
|
|
|
|
|
/* EOF */
|