mirror of
https://github.com/reactos/reactos.git
synced 2024-09-28 13:34:53 +00:00
[0.4.14] Sledgehammer-revert of the work towards MountMgr
to fix regression CORE-16619 "Delay during bootup due to workqueue deadlocks" (verified) to fix regression CORE-16511 "Regression: USB drives are not mounted anymore" (verified) to fix regression CORE-16486 "doubled drive letters for USB drives" (verified) to fix regression "got ioctl intended for the mount manager"-logspam (verified) and hopefully to improve on CORE-15575 (this last part still needs verification) This reverts the following commits: 0.4.14-dev-373-g0917815efa
0.4.14-dev-296-g324285f0b9
0.4.14-dev-294-g887200703c
0.4.14-dev-172-g6889cff5b5
0.4.14-dev-106-g5ab1cfc553
0.4.14-dev-105-gb68104dd87
This commit is contained in:
parent
eac5f78b44
commit
1128de5b86
|
@ -731,130 +731,6 @@ Return Value:
|
|||
RtlFreeUnicodeString(&unicodeString);
|
||||
}
|
||||
|
||||
|
||||
VOID
|
||||
NTAPI
|
||||
ReportToMountMgr(
|
||||
IN PDEVICE_OBJECT CdDeviceObject
|
||||
)
|
||||
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
This routine reports the creation of a cdrom device object to the
|
||||
MountMgr to fake PnP.
|
||||
|
||||
Arguments:
|
||||
|
||||
CdDeviceObject - Pointer to the created cdrom device.
|
||||
|
||||
Return Value:
|
||||
|
||||
VOID
|
||||
|
||||
--*/
|
||||
{
|
||||
NTSTATUS status;
|
||||
UNICODE_STRING mountMgrDevice;
|
||||
PDEVICE_OBJECT deviceObject;
|
||||
PFILE_OBJECT fileObject;
|
||||
PMOUNTMGR_TARGET_NAME mountTarget;
|
||||
ULONG cdLen;
|
||||
PDEVICE_EXTENSION deviceExtension;
|
||||
PIRP irp;
|
||||
KEVENT event;
|
||||
IO_STATUS_BLOCK ioStatus;
|
||||
|
||||
//
|
||||
// First, get MountMgr DeviceObject.
|
||||
//
|
||||
|
||||
RtlInitUnicodeString(&mountMgrDevice, MOUNTMGR_DEVICE_NAME);
|
||||
status = IoGetDeviceObjectPointer(&mountMgrDevice, FILE_READ_ATTRIBUTES,
|
||||
&fileObject, &deviceObject);
|
||||
|
||||
if (!NT_SUCCESS(status)) {
|
||||
|
||||
DebugPrint((1,
|
||||
"ReportToMountMgr: Can't get MountMgr pointers %lx\n",
|
||||
status));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
deviceExtension = CdDeviceObject->DeviceExtension;
|
||||
cdLen = deviceExtension->DeviceName.Length;
|
||||
|
||||
//
|
||||
// Allocate input buffer to report our partition device.
|
||||
//
|
||||
|
||||
mountTarget = ExAllocatePool(NonPagedPool,
|
||||
sizeof(MOUNTMGR_TARGET_NAME) + cdLen);
|
||||
|
||||
if (!mountTarget) {
|
||||
|
||||
DebugPrint((1,
|
||||
"ReportToMountMgr: Allocation of mountTarget failed\n"));
|
||||
|
||||
ObDereferenceObject(fileObject);
|
||||
return;
|
||||
}
|
||||
|
||||
mountTarget->DeviceNameLength = cdLen;
|
||||
RtlCopyMemory(mountTarget->DeviceName, deviceExtension->DeviceName.Buffer, cdLen);
|
||||
|
||||
KeInitializeEvent(&event, NotificationEvent, FALSE);
|
||||
|
||||
//
|
||||
// Build the IRP used to communicate with the MountMgr.
|
||||
//
|
||||
|
||||
irp = IoBuildDeviceIoControlRequest(IOCTL_MOUNTMGR_VOLUME_ARRIVAL_NOTIFICATION,
|
||||
deviceObject,
|
||||
mountTarget,
|
||||
sizeof(MOUNTMGR_TARGET_NAME) + cdLen,
|
||||
NULL,
|
||||
0,
|
||||
FALSE,
|
||||
&event,
|
||||
&ioStatus);
|
||||
|
||||
if (!irp) {
|
||||
|
||||
DebugPrint((1,
|
||||
"ReportToMountMgr: Allocation of irp failed\n"));
|
||||
|
||||
ExFreePool(mountTarget);
|
||||
ObDereferenceObject(fileObject);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Call the MountMgr.
|
||||
//
|
||||
|
||||
status = IoCallDriver(deviceObject, irp);
|
||||
|
||||
if (status == STATUS_PENDING) {
|
||||
KeWaitForSingleObject(&event, Suspended, KernelMode, FALSE, NULL);
|
||||
status = ioStatus.Status;
|
||||
}
|
||||
|
||||
//
|
||||
// We're done.
|
||||
//
|
||||
|
||||
DPRINT1("Reported to the MountMgr: %lx\n", status);
|
||||
|
||||
ExFreePool(mountTarget);
|
||||
ObDereferenceObject(fileObject);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
CreateCdRomDeviceObject(
|
||||
|
@ -1447,8 +1323,6 @@ Return Value:
|
|||
|
||||
ExFreePool(buffer);
|
||||
|
||||
ReportToMountMgr(deviceObject);
|
||||
|
||||
//
|
||||
// Start the timer now regardless of if Autorun is enabled.
|
||||
// The timer must run forever since IoStopTimer faults.
|
||||
|
|
|
@ -3,7 +3,5 @@
|
|||
|
||||
#include <ntdef.h>
|
||||
#include <ntstatus.h>
|
||||
#include <mountmgr.h>
|
||||
#include <mountdev.h>
|
||||
|
||||
#endif /* _CDROM_PCH_ */
|
||||
|
|
|
@ -13,6 +13,10 @@
|
|||
#include <include/class2.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* Part of the drive letter hack */
|
||||
#include <ntifs.h>
|
||||
#include <ketypes.h>
|
||||
|
||||
//#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
|
@ -131,28 +135,315 @@ DriverEntry(
|
|||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/* The following hack to assign drive letters with a non-PnP storage stack */
|
||||
|
||||
typedef struct _CLASS_DEVICE_INFO {
|
||||
ULONG Signature;
|
||||
ULONG DeviceType;
|
||||
ULONG Partitions;
|
||||
ULONG DeviceNumber;
|
||||
ULONG DriveNumber;
|
||||
PDEVICE_OBJECT LowerDevice;
|
||||
} CLASS_DEVICE_INFO, *PCLASS_DEVICE_INFO;
|
||||
|
||||
typedef struct _CLASS_DRIVER_EXTENSION {
|
||||
ULONG PortNumber;
|
||||
UNICODE_STRING RegistryPath;
|
||||
CLASS_INIT_DATA InitializationData;
|
||||
} CLASS_DRIVER_EXTENSION, *PCLASS_DRIVER_EXTENSION;
|
||||
|
||||
VOID
|
||||
NTAPI
|
||||
ScsiClassRemoveDriveLetter(PCLASS_DEVICE_INFO DeviceInfo)
|
||||
{
|
||||
WCHAR Buffer1[100];
|
||||
UNICODE_STRING DriveLetterU;
|
||||
ULONG Index;
|
||||
|
||||
DriveLetterU.Buffer = Buffer1;
|
||||
DriveLetterU.MaximumLength = sizeof(Buffer1);
|
||||
|
||||
/* Delete the symbolic link to PhysicalDriveX */
|
||||
DriveLetterU.Length = swprintf(DriveLetterU.Buffer, L"\\??\\PhysicalDrive%d", DeviceInfo->DriveNumber) * sizeof(WCHAR);
|
||||
IoDeleteSymbolicLink(&DriveLetterU);
|
||||
|
||||
DbgPrint("HACK: Deleted symbolic link %wZ\n", &DriveLetterU);
|
||||
|
||||
for (Index = 0; Index < sizeof(ULONG) * 8; Index++)
|
||||
{
|
||||
if (DeviceInfo->Partitions & (1 << Index))
|
||||
{
|
||||
DriveLetterU.Length = swprintf(DriveLetterU.Buffer, L"\\??\\%C:", ('C' + Index)) * sizeof(WCHAR);
|
||||
IoDeleteSymbolicLink(&DriveLetterU);
|
||||
DbgPrint("HACK: Deleted symbolic link %wZ\n", &DriveLetterU);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
ScsiClassAssignDriveLetter(PCLASS_DEVICE_INFO DeviceInfo)
|
||||
{
|
||||
WCHAR Buffer1[100];
|
||||
WCHAR Buffer2[100];
|
||||
UNICODE_STRING DriveLetterU, PartitionU;
|
||||
NTSTATUS Status;
|
||||
ULONG Index, PartitionNumber, DeviceNumber, DriveNumber;
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
IO_STATUS_BLOCK Iosb;
|
||||
HANDLE PartitionHandle;
|
||||
|
||||
/* We assume this device does not current have a drive letter */
|
||||
|
||||
Index = 0;
|
||||
DeviceNumber = 0;
|
||||
DriveNumber = 0;
|
||||
PartitionNumber = 1;
|
||||
DriveLetterU.Buffer = Buffer1;
|
||||
DriveLetterU.MaximumLength = sizeof(Buffer1);
|
||||
PartitionU.Buffer = Buffer2;
|
||||
PartitionU.MaximumLength = sizeof(Buffer2);
|
||||
|
||||
/* Determine the correct disk number */
|
||||
do
|
||||
{
|
||||
/* Check that the disk exists */
|
||||
if (DeviceInfo->DeviceType == FILE_DEVICE_DISK)
|
||||
{
|
||||
PartitionU.Length = swprintf(PartitionU.Buffer, L"\\Device\\HardDisk%d\\Partition0", DeviceNumber) * sizeof(WCHAR);
|
||||
}
|
||||
else if (DeviceInfo->DeviceType == FILE_DEVICE_CD_ROM)
|
||||
{
|
||||
PartitionU.Length = swprintf(PartitionU.Buffer, L"\\Device\\CdRom%d", DeviceNumber) * sizeof(WCHAR);
|
||||
}
|
||||
|
||||
InitializeObjectAttributes(&ObjectAttributes,
|
||||
&PartitionU,
|
||||
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
|
||||
NULL,
|
||||
NULL);
|
||||
Status = ZwOpenFile(&PartitionHandle,
|
||||
FILE_READ_ATTRIBUTES,
|
||||
&ObjectAttributes,
|
||||
&Iosb,
|
||||
0,
|
||||
0);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
/* Return the last one that worked */
|
||||
DeviceNumber--;
|
||||
}
|
||||
else
|
||||
{
|
||||
ZwClose(PartitionHandle);
|
||||
DeviceNumber++;
|
||||
}
|
||||
} while (Status == STATUS_SUCCESS);
|
||||
|
||||
/* Determine the correct drive number */
|
||||
do
|
||||
{
|
||||
/* Check that the drive exists */
|
||||
if (DeviceInfo->DeviceType == FILE_DEVICE_DISK)
|
||||
{
|
||||
PartitionU.Length = swprintf(PartitionU.Buffer, L"\\??\\PhysicalDrive%d", DriveNumber) * sizeof(WCHAR);
|
||||
}
|
||||
else if (DeviceInfo->DeviceType == FILE_DEVICE_CD_ROM)
|
||||
{
|
||||
PartitionU.Length = swprintf(PartitionU.Buffer, L"\\??\\%C:", ('C' + DriveNumber)) * sizeof(WCHAR);
|
||||
}
|
||||
InitializeObjectAttributes(&ObjectAttributes,
|
||||
&PartitionU,
|
||||
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
|
||||
NULL,
|
||||
NULL);
|
||||
Status = ZwOpenFile(&PartitionHandle,
|
||||
FILE_READ_ATTRIBUTES,
|
||||
&ObjectAttributes,
|
||||
&Iosb,
|
||||
0,
|
||||
0);
|
||||
if (NT_SUCCESS(Status))
|
||||
{
|
||||
ZwClose(PartitionHandle);
|
||||
DriveNumber++;
|
||||
}
|
||||
} while (Status == STATUS_SUCCESS);
|
||||
|
||||
if (DeviceInfo->DeviceType == FILE_DEVICE_DISK)
|
||||
{
|
||||
PartitionU.Length = swprintf(PartitionU.Buffer, L"\\Device\\Harddisk%d\\Partition0", DeviceNumber) * sizeof(WCHAR);
|
||||
DriveLetterU.Length = swprintf(DriveLetterU.Buffer, L"\\??\\PhysicalDrive%d", DriveNumber) * sizeof(WCHAR);
|
||||
}
|
||||
else if (DeviceInfo->DeviceType == FILE_DEVICE_CD_ROM)
|
||||
{
|
||||
PartitionU.Length = swprintf(PartitionU.Buffer, L"\\Device\\CdRom%d", DeviceNumber) * sizeof(WCHAR);
|
||||
DriveLetterU.Length = swprintf(DriveLetterU.Buffer, L"\\??\\%C:", ('C' + DriveNumber)) * sizeof(WCHAR);
|
||||
}
|
||||
|
||||
/* Create the symbolic link to PhysicalDriveX */
|
||||
Status = IoCreateSymbolicLink(&DriveLetterU, &PartitionU);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
/* Failed to create symbolic link */
|
||||
DbgPrint("Failed to create symbolic link %wZ -> %wZ with %lx\n", &PartitionU, &DriveLetterU, Status);
|
||||
return Status;
|
||||
}
|
||||
|
||||
DbgPrint("HACK: Created symbolic link %wZ -> %wZ\n", &PartitionU, &DriveLetterU);
|
||||
|
||||
DeviceInfo->DeviceNumber = DeviceNumber;
|
||||
DeviceInfo->DriveNumber = DriveNumber;
|
||||
|
||||
if (DeviceInfo->DeviceType == FILE_DEVICE_CD_ROM)
|
||||
{
|
||||
/* done for cdroms */
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
/* Check that the disk exists */
|
||||
PartitionU.Length = swprintf(PartitionU.Buffer, L"\\Device\\Harddisk%d\\Partition%d", DeviceNumber, PartitionNumber) * sizeof(WCHAR);
|
||||
InitializeObjectAttributes(&ObjectAttributes,
|
||||
&PartitionU,
|
||||
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
|
||||
NULL,
|
||||
NULL);
|
||||
Status = ZwOpenFile(&PartitionHandle,
|
||||
FILE_READ_ATTRIBUTES,
|
||||
&ObjectAttributes,
|
||||
&Iosb,
|
||||
0,
|
||||
0);
|
||||
if (!NT_SUCCESS(Status))
|
||||
break;
|
||||
else
|
||||
{
|
||||
ZwClose(PartitionHandle);
|
||||
|
||||
/* Assign it a drive letter */
|
||||
do
|
||||
{
|
||||
DriveLetterU.Length = swprintf(DriveLetterU.Buffer, L"\\??\\%C:", ('C' + Index)) * sizeof(WCHAR);
|
||||
|
||||
Status = IoCreateSymbolicLink(&DriveLetterU, &PartitionU);
|
||||
|
||||
Index++;
|
||||
} while (Status != STATUS_SUCCESS);
|
||||
|
||||
DeviceInfo->Partitions |= (1 << (Index - 1));
|
||||
|
||||
DbgPrint("HACK: Created symbolic link %wZ -> %wZ\n", &PartitionU, &DriveLetterU);
|
||||
PartitionNumber++;
|
||||
}
|
||||
}
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
ScsiClassPlugPlay(
|
||||
IN PDEVICE_OBJECT DeviceObject,
|
||||
IN PIRP Irp)
|
||||
{
|
||||
PCLASS_DEVICE_INFO DeviceInfo = DeviceObject->DeviceExtension;
|
||||
PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp);
|
||||
|
||||
if (IrpSp->MinorFunction == IRP_MN_START_DEVICE)
|
||||
{
|
||||
ASSERT(DeviceInfo->Signature == '2slc');
|
||||
IoSkipCurrentIrpStackLocation(Irp);
|
||||
return IoCallDriver(DeviceInfo->LowerDevice, Irp);
|
||||
}
|
||||
else if (IrpSp->MinorFunction == IRP_MN_REMOVE_DEVICE)
|
||||
{
|
||||
ASSERT(DeviceInfo->Signature == '2slc');
|
||||
ScsiClassRemoveDriveLetter(DeviceInfo);
|
||||
|
||||
IoForwardIrpSynchronously(DeviceInfo->LowerDevice, Irp);
|
||||
|
||||
Irp->IoStatus.Status = STATUS_SUCCESS;
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
|
||||
IoDetachDevice(DeviceInfo->LowerDevice);
|
||||
IoDeleteDevice(DeviceObject);
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (DeviceInfo->Signature == '2slc')
|
||||
{
|
||||
IoSkipCurrentIrpStackLocation(Irp);
|
||||
return IoCallDriver(DeviceInfo->LowerDevice, Irp);
|
||||
}
|
||||
|
||||
Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
return STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
ScsiClassAddDevice(
|
||||
IN PDRIVER_OBJECT DriverObject,
|
||||
IN PDEVICE_OBJECT PhysicalDeviceObject)
|
||||
{
|
||||
PCLASS_DRIVER_EXTENSION DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject);
|
||||
PCLASS_DEVICE_INFO DeviceInfo;
|
||||
PDEVICE_OBJECT DeviceObject;
|
||||
NTSTATUS Status;
|
||||
|
||||
if (DriverExtension->InitializationData.ClassFindDevices(DriverObject, &DriverExtension->RegistryPath, &DriverExtension->InitializationData,
|
||||
PhysicalDeviceObject, DriverExtension->PortNumber))
|
||||
{
|
||||
/* Create a device object */
|
||||
Status = IoCreateDevice(DriverObject,
|
||||
sizeof(CLASS_DEVICE_INFO),
|
||||
NULL,
|
||||
DriverExtension->InitializationData.DeviceType,
|
||||
0,
|
||||
FALSE,
|
||||
&DeviceObject);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
return Status;
|
||||
}
|
||||
|
||||
DeviceInfo = DeviceObject->DeviceExtension;
|
||||
RtlZeroMemory(DeviceInfo, sizeof(CLASS_DEVICE_INFO));
|
||||
DeviceInfo->Signature = '2slc';
|
||||
|
||||
/* Attach it to the PDO */
|
||||
DeviceInfo->LowerDevice = IoAttachDeviceToDeviceStack(DeviceObject, PhysicalDeviceObject);
|
||||
DeviceInfo->DeviceType = DriverExtension->InitializationData.DeviceType;
|
||||
|
||||
/* Check that the kernel has already assigned drive letters */
|
||||
if (KeLoaderBlock == NULL)
|
||||
{
|
||||
/* Assign a drive letter */
|
||||
ScsiClassAssignDriveLetter(DeviceInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The kernel will handle it */
|
||||
}
|
||||
|
||||
/* Move to the next port number */
|
||||
DriverExtension->PortNumber++;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Failed to find device */
|
||||
DbgPrint("FAILED TO FIND DEVICE!\n");
|
||||
}
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
/* ---- End hack ---- */
|
||||
|
||||
|
||||
|
||||
ULONG
|
||||
|
@ -186,14 +477,15 @@ Return Value:
|
|||
|
||||
|
||||
PDRIVER_OBJECT DriverObject = Argument1;
|
||||
ULONG portNumber = 0;
|
||||
PDEVICE_OBJECT portDeviceObject;
|
||||
NTSTATUS status;
|
||||
STRING deviceNameString;
|
||||
UNICODE_STRING unicodeDeviceName;
|
||||
PFILE_OBJECT fileObject;
|
||||
CCHAR deviceNameBuffer[256];
|
||||
BOOLEAN deviceFound = FALSE;
|
||||
/* BOOLEAN deviceFound = FALSE; See note at the end */
|
||||
PCLASS_DRIVER_EXTENSION DriverExtension;
|
||||
PUNICODE_STRING RegistryPath = Argument2;
|
||||
|
||||
DebugPrint((3,"\n\nSCSI Class Driver\n"));
|
||||
|
||||
|
@ -224,6 +516,27 @@ Return Value:
|
|||
return (ULONG) STATUS_REVISION_MISMATCH;
|
||||
}
|
||||
|
||||
status = IoAllocateDriverObjectExtension(DriverObject,
|
||||
DriverObject,
|
||||
sizeof(CLASS_DRIVER_EXTENSION),
|
||||
(PVOID *)&DriverExtension);
|
||||
if (!NT_SUCCESS(status))
|
||||
return status;
|
||||
|
||||
RtlCopyMemory(&DriverExtension->InitializationData, InitializationData, sizeof(CLASS_INIT_DATA));
|
||||
DriverExtension->PortNumber = 0;
|
||||
|
||||
DriverExtension->RegistryPath.Buffer = ExAllocatePool(PagedPool, RegistryPath->MaximumLength);
|
||||
if (!DriverExtension->RegistryPath.Buffer)
|
||||
return STATUS_NO_MEMORY;
|
||||
|
||||
DriverExtension->RegistryPath.Length = RegistryPath->Length;
|
||||
DriverExtension->RegistryPath.MaximumLength = RegistryPath->MaximumLength;
|
||||
|
||||
RtlCopyMemory(DriverExtension->RegistryPath.Buffer,
|
||||
RegistryPath->Buffer,
|
||||
RegistryPath->Length);
|
||||
|
||||
//
|
||||
// Update driver object with entry points.
|
||||
//
|
||||
|
@ -237,6 +550,7 @@ Return Value:
|
|||
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = ScsiClassDeviceControlDispatch;
|
||||
DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = ScsiClassShutdownFlush;
|
||||
DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = ScsiClassShutdownFlush;
|
||||
DriverObject->DriverExtension->AddDevice = ScsiClassAddDevice;
|
||||
|
||||
if (InitializationData->ClassStartIo) {
|
||||
DriverObject->DriverStartIo = InitializationData->ClassStartIo;
|
||||
|
@ -248,7 +562,7 @@ Return Value:
|
|||
|
||||
do {
|
||||
|
||||
sprintf(deviceNameBuffer, "\\Device\\ScsiPort%lu", portNumber);
|
||||
sprintf(deviceNameBuffer, "\\Device\\ScsiPort%lu", DriverExtension->PortNumber);
|
||||
|
||||
DebugPrint((2, "ScsiClassInitialize: Open Port %s\n", deviceNameBuffer));
|
||||
|
||||
|
@ -274,9 +588,9 @@ Return Value:
|
|||
//
|
||||
|
||||
if (InitializationData->ClassFindDevices(DriverObject, Argument2, InitializationData,
|
||||
portDeviceObject, portNumber)) {
|
||||
portDeviceObject, DriverExtension->PortNumber)) {
|
||||
|
||||
deviceFound = TRUE;
|
||||
/* deviceFound = TRUE; See note at the end */
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -284,11 +598,12 @@ Return Value:
|
|||
// Check next SCSI adapter.
|
||||
//
|
||||
|
||||
portNumber++;
|
||||
DriverExtension->PortNumber++;
|
||||
|
||||
} while(NT_SUCCESS(status));
|
||||
|
||||
return deviceFound ? STATUS_SUCCESS : STATUS_NO_SUCH_DEVICE;
|
||||
/* We don't want to fail init just because we don't have devices right now */
|
||||
return STATUS_SUCCESS; /*deviceFound ? STATUS_SUCCESS : STATUS_NO_SUCH_DEVICE;*/
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1067,129 +1067,6 @@ CreateDiskDeviceObjectsExit:
|
|||
|
||||
} // end CreateDiskDeviceObjects()
|
||||
|
||||
|
||||
VOID
|
||||
NTAPI
|
||||
ReportToMountMgr(
|
||||
IN PDEVICE_OBJECT DiskDeviceObject
|
||||
)
|
||||
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
This routine reports the creation of a disk device object to the
|
||||
MountMgr to fake PnP.
|
||||
|
||||
Arguments:
|
||||
|
||||
DiskDeviceObject - Pointer to the created disk device.
|
||||
|
||||
Return Value:
|
||||
|
||||
VOID
|
||||
|
||||
--*/
|
||||
{
|
||||
NTSTATUS status;
|
||||
UNICODE_STRING mountMgrDevice;
|
||||
PDEVICE_OBJECT deviceObject;
|
||||
PFILE_OBJECT fileObject;
|
||||
PMOUNTMGR_TARGET_NAME mountTarget;
|
||||
ULONG diskLen;
|
||||
PDEVICE_EXTENSION deviceExtension;
|
||||
PIRP irp;
|
||||
KEVENT event;
|
||||
IO_STATUS_BLOCK ioStatus;
|
||||
|
||||
//
|
||||
// First, get MountMgr DeviceObject.
|
||||
//
|
||||
|
||||
RtlInitUnicodeString(&mountMgrDevice, MOUNTMGR_DEVICE_NAME);
|
||||
status = IoGetDeviceObjectPointer(&mountMgrDevice, FILE_READ_ATTRIBUTES,
|
||||
&fileObject, &deviceObject);
|
||||
|
||||
if (!NT_SUCCESS(status)) {
|
||||
|
||||
DebugPrint((1,
|
||||
"ReportToMountMgr: Can't get MountMgr pointers %lx\n",
|
||||
status));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
deviceExtension = DiskDeviceObject->DeviceExtension;
|
||||
diskLen = deviceExtension->DeviceName.Length;
|
||||
|
||||
//
|
||||
// Allocate input buffer to report our partition device.
|
||||
//
|
||||
|
||||
mountTarget = ExAllocatePool(NonPagedPool,
|
||||
sizeof(MOUNTMGR_TARGET_NAME) + diskLen);
|
||||
|
||||
if (!mountTarget) {
|
||||
|
||||
DebugPrint((1,
|
||||
"ReportToMountMgr: Allocation of mountTarget failed\n"));
|
||||
|
||||
ObDereferenceObject(fileObject);
|
||||
return;
|
||||
}
|
||||
|
||||
mountTarget->DeviceNameLength = diskLen;
|
||||
RtlCopyMemory(mountTarget->DeviceName, deviceExtension->DeviceName.Buffer, diskLen);
|
||||
|
||||
KeInitializeEvent(&event, NotificationEvent, FALSE);
|
||||
|
||||
//
|
||||
// Build the IRP used to communicate with the MountMgr.
|
||||
//
|
||||
|
||||
irp = IoBuildDeviceIoControlRequest(IOCTL_MOUNTMGR_VOLUME_ARRIVAL_NOTIFICATION,
|
||||
deviceObject,
|
||||
mountTarget,
|
||||
sizeof(MOUNTMGR_TARGET_NAME) + diskLen,
|
||||
NULL,
|
||||
0,
|
||||
FALSE,
|
||||
&event,
|
||||
&ioStatus);
|
||||
|
||||
if (!irp) {
|
||||
|
||||
DebugPrint((1,
|
||||
"ReportToMountMgr: Allocation of irp failed\n"));
|
||||
|
||||
ExFreePool(mountTarget);
|
||||
ObDereferenceObject(fileObject);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Call the MountMgr.
|
||||
//
|
||||
|
||||
status = IoCallDriver(deviceObject, irp);
|
||||
|
||||
if (status == STATUS_PENDING) {
|
||||
KeWaitForSingleObject(&event, Suspended, KernelMode, FALSE, NULL);
|
||||
status = ioStatus.Status;
|
||||
}
|
||||
|
||||
//
|
||||
// We're done.
|
||||
//
|
||||
|
||||
DPRINT1("Reported to the MountMgr: %lx\n", status);
|
||||
|
||||
ExFreePool(mountTarget);
|
||||
ObDereferenceObject(fileObject);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
|
@ -1583,14 +1460,6 @@ CreatePartitionDeviceObjects(
|
|||
deviceExtension->DeviceObject = deviceObject;
|
||||
deviceExtension->DeviceFlags |= physicalDeviceExtension->DeviceFlags;
|
||||
|
||||
//
|
||||
// Now we're done, report to the MountMgr.
|
||||
// This is a HACK required to have the driver
|
||||
// handle the associated DosDevices.
|
||||
//
|
||||
|
||||
ReportToMountMgr(deviceObject);
|
||||
|
||||
} // end for (partitionNumber) ...
|
||||
|
||||
//
|
||||
|
|
|
@ -406,6 +406,9 @@ Unload(PDRIVER_OBJECT DriverObject)
|
|||
{
|
||||
UNICODE_STRING Link;
|
||||
|
||||
RtlInitUnicodeString(&Link, gControllerInfo[i].DriveInfo[j].SymLinkBuffer);
|
||||
IoDeleteSymbolicLink(&Link);
|
||||
|
||||
RtlInitUnicodeString(&Link, gControllerInfo[i].DriveInfo[j].ArcPathBuffer);
|
||||
IoDeassignArcName(&Link);
|
||||
|
||||
|
@ -808,98 +811,6 @@ InitController(PCONTROLLER_INFO ControllerInfo)
|
|||
}
|
||||
|
||||
|
||||
static VOID NTAPI
|
||||
ReportToMountMgr(UCHAR ControlerId, UCHAR DriveId)
|
||||
/*
|
||||
* FUNCTION: Called to report a new controler to the MountMgr
|
||||
* ARGUMENTS:
|
||||
* ControlerId: ID of the controler
|
||||
* DriveId: ID of the device for the controler
|
||||
* RETURNS:
|
||||
* Nothing
|
||||
* NOTES:
|
||||
* - This is a hack to allow MountMgr handling our devices
|
||||
*/
|
||||
{
|
||||
NTSTATUS Status;
|
||||
UNICODE_STRING MountMgrDevice;
|
||||
PDEVICE_OBJECT DeviceObject;
|
||||
PFILE_OBJECT FileObject;
|
||||
PMOUNTMGR_TARGET_NAME MountTarget;
|
||||
ULONG DeviceLen;
|
||||
PIRP Irp;
|
||||
KEVENT Event;
|
||||
IO_STATUS_BLOCK IoStatus;
|
||||
|
||||
/* First, get MountMgr DeviceObject */
|
||||
RtlInitUnicodeString(&MountMgrDevice, MOUNTMGR_DEVICE_NAME);
|
||||
Status = IoGetDeviceObjectPointer(&MountMgrDevice, FILE_READ_ATTRIBUTES,
|
||||
&FileObject, &DeviceObject);
|
||||
|
||||
if(!NT_SUCCESS(Status))
|
||||
{
|
||||
WARN_(FLOPPY, "ReportToMountMgr: Can't get MountMgr pointers %lx\n", Status);
|
||||
return;
|
||||
}
|
||||
|
||||
DeviceLen = wcslen(&gControllerInfo[ControlerId].DriveInfo[DriveId].DeviceNameBuffer[0]) * sizeof(WCHAR);
|
||||
|
||||
/* Allocate input buffer to report our floppy device */
|
||||
MountTarget = ExAllocatePool(NonPagedPool,
|
||||
sizeof(MOUNTMGR_TARGET_NAME) + DeviceLen);
|
||||
|
||||
if(!MountTarget)
|
||||
{
|
||||
WARN_(FLOPPY, "ReportToMountMgr: Allocation of mountTarget failed\n");
|
||||
ObDereferenceObject(FileObject);
|
||||
return;
|
||||
}
|
||||
|
||||
MountTarget->DeviceNameLength = DeviceLen;
|
||||
RtlCopyMemory(MountTarget->DeviceName,
|
||||
gControllerInfo[ControlerId].DriveInfo[DriveId].DeviceNameBuffer,
|
||||
DeviceLen);
|
||||
|
||||
KeInitializeEvent(&Event, NotificationEvent, FALSE);
|
||||
|
||||
/* Build the IRP used to communicate with the MountMgr */
|
||||
Irp = IoBuildDeviceIoControlRequest(IOCTL_MOUNTMGR_VOLUME_ARRIVAL_NOTIFICATION,
|
||||
DeviceObject,
|
||||
MountTarget,
|
||||
sizeof(MOUNTMGR_TARGET_NAME) + DeviceLen,
|
||||
NULL,
|
||||
0,
|
||||
FALSE,
|
||||
&Event,
|
||||
&IoStatus);
|
||||
|
||||
if(!Irp)
|
||||
{
|
||||
WARN_(FLOPPY, "ReportToMountMgr: Allocation of irp failed\n");
|
||||
ExFreePool(MountTarget);
|
||||
ObDereferenceObject(FileObject);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Call the MountMgr */
|
||||
Status = IoCallDriver(DeviceObject, Irp);
|
||||
|
||||
if (Status == STATUS_PENDING) {
|
||||
KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
|
||||
Status = IoStatus.Status;
|
||||
}
|
||||
|
||||
/* We're done */
|
||||
|
||||
INFO_(FLOPPY, "Reported to the MountMgr: %lx\n", Status);
|
||||
|
||||
ExFreePool(MountTarget);
|
||||
ObDereferenceObject(FileObject);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
static BOOLEAN NTAPI
|
||||
AddControllers(PDRIVER_OBJECT DriverObject)
|
||||
/*
|
||||
|
@ -1001,7 +912,9 @@ AddControllers(PDRIVER_OBJECT DriverObject)
|
|||
/* 3: per-drive setup */
|
||||
for(j = 0; j < gControllerInfo[i].NumberOfDrives; j++)
|
||||
{
|
||||
WCHAR DeviceNameBuf[MAX_DEVICE_NAME];
|
||||
UNICODE_STRING DeviceName;
|
||||
UNICODE_STRING LinkName;
|
||||
UNICODE_STRING ArcPath;
|
||||
UCHAR DriveNumber;
|
||||
|
||||
|
@ -1023,8 +936,9 @@ AddControllers(PDRIVER_OBJECT DriverObject)
|
|||
|
||||
DriveNumber = (UCHAR)(i*4 + j); /* loss of precision is OK; there are only 16 of 'em */
|
||||
|
||||
swprintf(gControllerInfo[i].DriveInfo[j].DeviceNameBuffer, L"\\Device\\Floppy%d", DriveNumber);
|
||||
RtlInitUnicodeString(&DeviceName, gControllerInfo[i].DriveInfo[j].DeviceNameBuffer);
|
||||
RtlZeroMemory(&DeviceNameBuf, MAX_DEVICE_NAME * sizeof(WCHAR));
|
||||
swprintf(DeviceNameBuf, L"\\Device\\Floppy%d", DriveNumber);
|
||||
RtlInitUnicodeString(&DeviceName, DeviceNameBuf);
|
||||
|
||||
if(IoCreateDevice(DriverObject, sizeof(PVOID), &DeviceName,
|
||||
FILE_DEVICE_DISK, FILE_REMOVABLE_MEDIA | FILE_FLOPPY_DISKETTE, FALSE,
|
||||
|
@ -1035,9 +949,7 @@ AddControllers(PDRIVER_OBJECT DriverObject)
|
|||
continue; /* continue on to next drive */
|
||||
}
|
||||
|
||||
INFO_(FLOPPY, "AddControllers: New device: %S (0x%p)\n",
|
||||
gControllerInfo[i].DriveInfo[j].DeviceNameBuffer,
|
||||
gControllerInfo[i].DriveInfo[j].DeviceObject);
|
||||
INFO_(FLOPPY, "AddControllers: New device: %S (0x%p)\n", DeviceNameBuf, gControllerInfo[i].DriveInfo[j].DeviceObject);
|
||||
|
||||
/* 3b.5: Create an ARC path in case we're booting from this drive */
|
||||
swprintf(gControllerInfo[i].DriveInfo[j].ArcPathBuffer,
|
||||
|
@ -1049,30 +961,38 @@ AddControllers(PDRIVER_OBJECT DriverObject)
|
|||
/* 3c: Set flags up */
|
||||
gControllerInfo[i].DriveInfo[j].DeviceObject->Flags |= DO_DIRECT_IO;
|
||||
|
||||
/* 3d: Increase global floppy drives count */
|
||||
/* 3d: Create a symlink */
|
||||
swprintf(gControllerInfo[i].DriveInfo[j].SymLinkBuffer, L"\\DosDevices\\%c:", DriveNumber + 'A');
|
||||
RtlInitUnicodeString(&LinkName, gControllerInfo[i].DriveInfo[j].SymLinkBuffer);
|
||||
if(IoCreateSymbolicLink(&LinkName, &DeviceName) != STATUS_SUCCESS)
|
||||
{
|
||||
WARN_(FLOPPY, "AddControllers: Unable to create a symlink for drive %d\n", DriveNumber);
|
||||
IoDisconnectInterrupt(gControllerInfo[i].InterruptObject);
|
||||
IoDeassignArcName(&ArcPath);
|
||||
continue; /* continue to next drive */
|
||||
}
|
||||
|
||||
/* 3e: Increase global floppy drives count */
|
||||
IoGetConfigurationInformation()->FloppyCount++;
|
||||
|
||||
/* 3e: Set up the DPC */
|
||||
/* 3f: Set up the DPC */
|
||||
IoInitializeDpcRequest(gControllerInfo[i].DriveInfo[j].DeviceObject, (PIO_DPC_ROUTINE)DpcForIsr);
|
||||
|
||||
/* 3f: Point the device extension at our DriveInfo struct */
|
||||
/* 3g: Point the device extension at our DriveInfo struct */
|
||||
gControllerInfo[i].DriveInfo[j].DeviceObject->DeviceExtension = &gControllerInfo[i].DriveInfo[j];
|
||||
|
||||
/* 3g: neat comic strip */
|
||||
/* 3h: neat comic strip */
|
||||
|
||||
/* 3h: set the initial media type to unknown */
|
||||
/* 3i: set the initial media type to unknown */
|
||||
memset(&gControllerInfo[i].DriveInfo[j].DiskGeometry, 0, sizeof(DISK_GEOMETRY));
|
||||
gControllerInfo[i].DriveInfo[j].DiskGeometry.MediaType = Unknown;
|
||||
|
||||
/* 3i: Now that we're done, set the Initialized flag so we know to free this in Unload */
|
||||
/* 3j: Now that we're done, set the Initialized flag so we know to free this in Unload */
|
||||
gControllerInfo[i].DriveInfo[j].Initialized = TRUE;
|
||||
|
||||
/* 3j: Clear the DO_DEVICE_INITIALIZING flag */
|
||||
/* 3k: Clear the DO_DEVICE_INITIALIZING flag */
|
||||
gControllerInfo[i].DriveInfo[j].DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
|
||||
|
||||
/* 3k: Report to the MountMgr */
|
||||
ReportToMountMgr(i, j);
|
||||
|
||||
/* 3l: Attempt to get drive info - if a floppy is already present */
|
||||
StartMotor(&gControllerInfo[i].DriveInfo[j]);
|
||||
RWDetermineMediaType(&gControllerInfo[i].DriveInfo[j], TRUE);
|
||||
|
|
|
@ -48,8 +48,8 @@ typedef struct _DRIVE_INFO
|
|||
CM_FLOPPY_DEVICE_DATA FloppyDeviceData;
|
||||
DISK_GEOMETRY DiskGeometry;
|
||||
UCHAR BytesPerSectorCode;
|
||||
WCHAR SymLinkBuffer[MAX_DEVICE_NAME];
|
||||
WCHAR ArcPathBuffer[MAX_ARC_PATH_LEN];
|
||||
WCHAR DeviceNameBuffer[MAX_DEVICE_NAME];
|
||||
ULONG DiskChangeCount;
|
||||
BOOLEAN Initialized;
|
||||
} DRIVE_INFO, *PDRIVE_INFO;
|
||||
|
|
|
@ -75,7 +75,6 @@ DeviceIoctlPassive(PDRIVE_INFO DriveInfo, PIRP Irp)
|
|||
ULONG Code = Stack->Parameters.DeviceIoControl.IoControlCode;
|
||||
BOOLEAN DiskChanged;
|
||||
PMOUNTDEV_NAME Name;
|
||||
PMOUNTDEV_UNIQUE_ID UniqueId;
|
||||
|
||||
TRACE_(FLOPPY, "DeviceIoctl called\n");
|
||||
Irp->IoStatus.Status = STATUS_SUCCESS;
|
||||
|
@ -257,54 +256,27 @@ DeviceIoctlPassive(PDRIVE_INFO DriveInfo, PIRP Irp)
|
|||
Irp->IoStatus.Information = 0;
|
||||
break;
|
||||
|
||||
case IOCTL_MOUNTDEV_QUERY_UNIQUE_ID:
|
||||
if(OutputLength < sizeof(MOUNTDEV_UNIQUE_ID))
|
||||
{
|
||||
Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
|
||||
Irp->IoStatus.Information = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
UniqueId = Irp->AssociatedIrp.SystemBuffer;
|
||||
UniqueId->UniqueIdLength = wcslen(&DriveInfo->DeviceNameBuffer[0]) * sizeof(WCHAR);
|
||||
|
||||
if(OutputLength < FIELD_OFFSET(MOUNTDEV_UNIQUE_ID, UniqueId) + UniqueId->UniqueIdLength)
|
||||
{
|
||||
Irp->IoStatus.Status = STATUS_BUFFER_OVERFLOW;
|
||||
Irp->IoStatus.Information = sizeof(MOUNTDEV_UNIQUE_ID);
|
||||
break;
|
||||
}
|
||||
|
||||
RtlCopyMemory(UniqueId->UniqueId, &DriveInfo->DeviceNameBuffer[0],
|
||||
UniqueId->UniqueIdLength);
|
||||
|
||||
Irp->IoStatus.Status = STATUS_SUCCESS;
|
||||
Irp->IoStatus.Information = FIELD_OFFSET(MOUNTDEV_UNIQUE_ID, UniqueId) + UniqueId->UniqueIdLength;
|
||||
break;
|
||||
|
||||
case IOCTL_MOUNTDEV_QUERY_DEVICE_NAME:
|
||||
if(OutputLength < sizeof(MOUNTDEV_NAME))
|
||||
{
|
||||
if (OutputLength < sizeof(MOUNTDEV_NAME)) {
|
||||
Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
|
||||
Irp->IoStatus.Information = 0;
|
||||
Irp->IoStatus.Information = sizeof(MOUNTDEV_NAME);
|
||||
break;
|
||||
}
|
||||
|
||||
Name = Irp->AssociatedIrp.SystemBuffer;
|
||||
Name->NameLength = wcslen(&DriveInfo->DeviceNameBuffer[0]) * sizeof(WCHAR);
|
||||
Name->NameLength = wcslen(&DriveInfo->SymLinkBuffer[0]) * sizeof(WCHAR);
|
||||
|
||||
if(OutputLength < FIELD_OFFSET(MOUNTDEV_NAME, Name) + Name->NameLength)
|
||||
{
|
||||
if (OutputLength < sizeof(USHORT) + Name->NameLength) {
|
||||
Irp->IoStatus.Status = STATUS_BUFFER_OVERFLOW;
|
||||
Irp->IoStatus.Information = sizeof(MOUNTDEV_NAME);
|
||||
break;
|
||||
}
|
||||
|
||||
RtlCopyMemory(Name->Name, &DriveInfo->DeviceNameBuffer[0],
|
||||
RtlCopyMemory(Name->Name, &DriveInfo->SymLinkBuffer[0],
|
||||
Name->NameLength);
|
||||
|
||||
Irp->IoStatus.Status = STATUS_SUCCESS;
|
||||
Irp->IoStatus.Information = FIELD_OFFSET(MOUNTDEV_NAME, Name) + Name->NameLength;
|
||||
Irp->IoStatus.Information = sizeof(USHORT) + Name->NameLength;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -4,6 +4,5 @@
|
|||
#include <initguid.h>
|
||||
#include <batclass.h>
|
||||
#include <poclass.h>
|
||||
#include <diskguid.h>
|
||||
|
||||
/* NO CODE HERE, THIS IS JUST REQUIRED FOR THE GUID DEFINITIONS */
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
#include <ntdef.h>
|
||||
#include <ntifs.h>
|
||||
#include <wdmguid.h>
|
||||
#include <diskguid.h>
|
||||
#include <arc/arc.h>
|
||||
#include <mountmgr.h>
|
||||
#undef NTHALAPI
|
||||
|
|
Loading…
Reference in a new issue