[CDFS_NEW] Replace old driver with a Ms-PL licensed version straight out of the driver samples github repository.

This commit is contained in:
David Quintana 2017-11-23 21:02:16 +01:00 committed by Pierre Schweitzer
parent 87d276f05d
commit fd34548263
38 changed files with 5298 additions and 2802 deletions

View file

@ -13,7 +13,7 @@ Abstract:
--*/
#include "cdprocs.h"
#include "CdProcs.h"
//
// The Bug check file id for this module
@ -21,40 +21,33 @@ Abstract:
#define BugCheckFileId (CDFS_BUG_CHECK_CDINIT)
// Tell prefast the function type.
DRIVER_INITIALIZE DriverEntry;
NTSTATUS
NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath
_In_ PDRIVER_OBJECT DriverObject,
_In_ PUNICODE_STRING RegistryPath
);
// tell prefast this is a driver unload function
DRIVER_UNLOAD CdUnload;
VOID
NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
CdUnload(
IN PDRIVER_OBJECT DriverObject
_In_ PDRIVER_OBJECT DriverObject
);
NTSTATUS
CdInitializeGlobalData (
IN PDRIVER_OBJECT DriverObject,
IN PDEVICE_OBJECT FileSystemDeviceObject
#ifdef __REACTOS__
,
IN PDEVICE_OBJECT HddFileSystemDeviceObject
#endif
);
NTSTATUS
NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
CdShutdown (
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
_In_ PDRIVER_OBJECT DriverObject,
_In_ PDEVICE_OBJECT FileSystemDeviceObject
);
#ifdef ALLOC_PRAGMA
#pragma alloc_text(INIT, DriverEntry)
#pragma alloc_text(PAGE, CdUnload)
#pragma alloc_text(PAGE, CdShutdown)
#pragma alloc_text(INIT, CdInitializeGlobalData)
#endif
@ -64,10 +57,9 @@ CdShutdown (
//
NTSTATUS
NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath
_In_ PDRIVER_OBJECT DriverObject,
_In_ PUNICODE_STRING RegistryPath
)
/*++
@ -93,9 +85,9 @@ Return Value:
NTSTATUS Status;
UNICODE_STRING UnicodeString;
PDEVICE_OBJECT CdfsFileSystemDeviceObject;
#ifdef __REACTOS__
PDEVICE_OBJECT HddFileSystemDeviceObject;
#endif
FS_FILTER_CALLBACKS FilterCallbacks;
UNREFERENCED_PARAMETER( RegistryPath );
//
// Create the device object.
@ -115,27 +107,14 @@ Return Value:
return Status;
}
#ifdef __REACTOS__
//
// Create the HDD device object.
//
#pragma prefast(push)
#pragma prefast(disable: 28155, "the dispatch routine has the correct type, prefast is just being paranoid.")
#pragma prefast(disable: 28168, "the dispatch routine has the correct type, prefast is just being paranoid.")
#pragma prefast(disable: 28169, "the dispatch routine has the correct type, prefast is just being paranoid.")
#pragma prefast(disable: 28175, "we're allowed to change these.")
RtlInitUnicodeString( &UnicodeString, L"\\CdfsHdd" );
Status = IoCreateDevice( DriverObject,
0,
&UnicodeString,
FILE_DEVICE_DISK_FILE_SYSTEM,
0,
FALSE,
&HddFileSystemDeviceObject );
if (!NT_SUCCESS( Status )) {
IoDeleteDevice (CdfsFileSystemDeviceObject);
return Status;
}
#endif
DriverObject->DriverUnload = CdUnload;
//
// Note that because of the way data caching is done, we set neither
// the Direct I/O or Buffered I/O bit in DeviceObject->Flags. If
@ -153,6 +132,7 @@ Return Value:
DriverObject->MajorFunction[IRP_MJ_CREATE] =
DriverObject->MajorFunction[IRP_MJ_CLOSE] =
DriverObject->MajorFunction[IRP_MJ_READ] =
DriverObject->MajorFunction[IRP_MJ_WRITE] =
DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] =
DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] =
DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION]=
@ -161,17 +141,29 @@ Return Value:
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] =
DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] =
DriverObject->MajorFunction[IRP_MJ_CLEANUP] =
DriverObject->MajorFunction[IRP_MJ_PNP] = (PDRIVER_DISPATCH) CdFsdDispatch;
DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = CdShutdown;
DriverObject->MajorFunction[IRP_MJ_PNP] =
DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = (PDRIVER_DISPATCH) CdFsdDispatch;
#pragma prefast(pop)
#pragma prefast(suppress: 28175, "this is a file system driver, we're allowed to touch FastIoDispatch.")
DriverObject->FastIoDispatch = &CdFastIoDispatch;
Status = IoRegisterShutdownNotification (CdfsFileSystemDeviceObject);
if (!NT_SUCCESS (Status)) {
IoDeleteDevice (CdfsFileSystemDeviceObject);
#ifdef __REACTOS__
IoDeleteDevice (HddFileSystemDeviceObject);
#endif
//
// Initialize the filter callbacks we use.
//
RtlZeroMemory( &FilterCallbacks,
sizeof(FS_FILTER_CALLBACKS) );
FilterCallbacks.SizeOfFsFilterCallbacks = sizeof(FS_FILTER_CALLBACKS);
FilterCallbacks.PreAcquireForSectionSynchronization = CdFilterCallbackAcquireForCreateSection;
Status = FsRtlRegisterFileSystemFilterCallbacks( DriverObject,
&FilterCallbacks );
if (!NT_SUCCESS( Status )) {
IoDeleteDevice( CdfsFileSystemDeviceObject );
return Status;
}
@ -179,16 +171,9 @@ Return Value:
// Initialize the global data structures
//
#ifndef __REACTOS__
Status = CdInitializeGlobalData( DriverObject, CdfsFileSystemDeviceObject );
#else
Status = CdInitializeGlobalData( DriverObject, CdfsFileSystemDeviceObject, HddFileSystemDeviceObject );
#endif
if (!NT_SUCCESS (Status)) {
IoDeleteDevice (CdfsFileSystemDeviceObject);
#ifdef __REACTOS__
IoDeleteDevice (HddFileSystemDeviceObject);
#endif
return Status;
}
@ -199,15 +184,17 @@ Return Value:
//
CdfsFileSystemDeviceObject->Flags |= DO_LOW_PRIORITY_FILESYSTEM;
#ifdef __REACTOS__
HddFileSystemDeviceObject->Flags |= DO_LOW_PRIORITY_FILESYSTEM;
#endif
IoRegisterFileSystem( CdfsFileSystemDeviceObject );
ObReferenceObject (CdfsFileSystemDeviceObject);
#ifdef __REACTOS__
IoRegisterFileSystem( HddFileSystemDeviceObject );
ObReferenceObject (HddFileSystemDeviceObject);
#ifdef CDFS_TELEMETRY_DATA
//
// Initialize Telemetry
//
CdInitializeTelemetry();
#endif
//
@ -217,51 +204,10 @@ Return Value:
return( STATUS_SUCCESS );
}
NTSTATUS
NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
CdShutdown (
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
/*++
Routine Description:
This routine is the shutdown handler for CDFS.
Arguments:
DeviceObject - Supplies the registered device object for CDFS.
Irp - Shutdown IRP
Return Value:
None.
--*/
{
#ifdef __REACTOS__
ASSERT(DeviceObject == CdData.FileSystemDeviceObject ||
DeviceObject == CdData.HddFileSystemDeviceObject);
#endif
IoUnregisterFileSystem (DeviceObject);
#ifndef __REACTOS__
IoDeleteDevice (CdData.FileSystemDeviceObject);
#else
IoDeleteDevice (DeviceObject);
#endif
CdCompleteRequest( NULL, Irp, STATUS_SUCCESS );
return STATUS_SUCCESS;
}
VOID
NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
CdUnload(
IN PDRIVER_OBJECT DriverObject
_In_ PDRIVER_OBJECT DriverObject
)
/*++
@ -281,6 +227,10 @@ Return Value:
{
PIRP_CONTEXT IrpContext;
PAGED_CODE();
UNREFERENCED_PARAMETER( DriverObject );
//
// Free any IRP contexts
//
@ -295,9 +245,6 @@ Return Value:
IoFreeWorkItem (CdData.CloseItem);
ExDeleteResourceLite( &CdData.DataResource );
ObDereferenceObject (CdData.FileSystemDeviceObject);
#ifdef __REACTOS__
ObDereferenceObject (CdData.HddFileSystemDeviceObject);
#endif
}
//
@ -306,12 +253,8 @@ Return Value:
NTSTATUS
CdInitializeGlobalData (
IN PDRIVER_OBJECT DriverObject,
IN PDEVICE_OBJECT FileSystemDeviceObject
#ifdef __REACTOS__
,
IN PDEVICE_OBJECT HddFileSystemDeviceObject
#endif
_In_ PDRIVER_OBJECT DriverObject,
_In_ PDEVICE_OBJECT FileSystemDeviceObject
)
/*++
@ -340,6 +283,10 @@ Return Value:
RtlZeroMemory( &CdFastIoDispatch, sizeof( FAST_IO_DISPATCH ));
CdFastIoDispatch.SizeOfFastIoDispatch = sizeof(FAST_IO_DISPATCH);
#pragma prefast(push)
#pragma prefast(disable:28155, "these are all correct")
CdFastIoDispatch.FastIoCheckIfPossible = CdFastIoCheckIfPossible; // CheckForFastIo
CdFastIoDispatch.FastIoRead = FsRtlCopyRead; // Read
CdFastIoDispatch.FastIoQueryBasicInfo = CdFastQueryBasicInfo; // QueryBasicInfo
@ -348,7 +295,12 @@ Return Value:
CdFastIoDispatch.FastIoUnlockSingle = CdFastUnlockSingle; // UnlockSingle
CdFastIoDispatch.FastIoUnlockAll = CdFastUnlockAll; // UnlockAll
CdFastIoDispatch.FastIoUnlockAllByKey = CdFastUnlockAllByKey; // UnlockAllByKey
CdFastIoDispatch.AcquireFileForNtCreateSection = CdAcquireForCreateSection;
//
// This callback has been replaced by CdFilterCallbackAcquireForCreateSection.
//
CdFastIoDispatch.AcquireFileForNtCreateSection = NULL;
CdFastIoDispatch.ReleaseFileForNtCreateSection = CdReleaseForCreateSection;
CdFastIoDispatch.FastIoQueryNetworkOpenInfo = CdFastQueryNetworkInfo; // QueryNetworkInfo
@ -357,6 +309,8 @@ Return Value:
CdFastIoDispatch.PrepareMdlWrite = FsRtlPrepareMdlWriteDev;
CdFastIoDispatch.MdlWriteComplete = FsRtlMdlWriteCompleteDev;
#pragma prefast(pop)
//
// Initialize the CdData structure.
//
@ -368,9 +322,6 @@ Return Value:
CdData.DriverObject = DriverObject;
CdData.FileSystemDeviceObject = FileSystemDeviceObject;
#ifdef __REACTOS__
CdData.HddFileSystemDeviceObject = HddFileSystemDeviceObject;
#endif
InitializeListHead( &CdData.VcbQueue );
@ -380,10 +331,10 @@ Return Value:
// Initialize the cache manager callback routines
//
CdData.CacheManagerCallbacks.AcquireForLazyWrite = (PVOID)&CdAcquireForCache;/* ReactOS Change: GCC "assignment from incompatible pointer type" */
CdData.CacheManagerCallbacks.ReleaseFromLazyWrite = (PVOID)&CdReleaseFromCache;/* ReactOS Change: GCC "assignment from incompatible pointer type" */
CdData.CacheManagerCallbacks.AcquireForReadAhead = (PVOID)&CdAcquireForCache;/* ReactOS Change: GCC "assignment from incompatible pointer type" */
CdData.CacheManagerCallbacks.ReleaseFromReadAhead = (PVOID)&CdReleaseFromCache;/* ReactOS Change: GCC "assignment from incompatible pointer type" */
CdData.CacheManagerCallbacks.AcquireForLazyWrite = &CdAcquireForCache;
CdData.CacheManagerCallbacks.ReleaseFromLazyWrite = &CdReleaseFromCache;
CdData.CacheManagerCallbacks.AcquireForReadAhead = &CdAcquireForCache;
CdData.CacheManagerCallbacks.ReleaseFromReadAhead = &CdReleaseFromCache;
CdData.CacheManagerVolumeCallbacks.AcquireForLazyWrite = &CdNoopAcquire;
CdData.CacheManagerVolumeCallbacks.ReleaseFromLazyWrite = &CdNoopRelease;