- Add symlink creation support for CDROM devices
[USBSTOR]
- Simply forward unsupported SCSI operations

Fixes USB CDROM support. CORE-6591 #resolve
Patch by Johannes "USB God" Anderwald.

svn path=/trunk/; revision=59091
This commit is contained in:
Thomas Faber 2013-05-27 18:39:32 +00:00
parent 7e7378f7c9
commit a701847436
3 changed files with 62 additions and 41 deletions

View file

@ -137,6 +137,7 @@ DriverEntry(
/* The following hack to assign drive letters with a non-PnP storage stack */ /* The following hack to assign drive letters with a non-PnP storage stack */
typedef struct _CLASS_DEVICE_INFO { typedef struct _CLASS_DEVICE_INFO {
ULONG DeviceType;
ULONG Partitions; ULONG Partitions;
ULONG DeviceNumber; ULONG DeviceNumber;
ULONG DriveNumber; ULONG DriveNumber;
@ -205,7 +206,15 @@ ScsiClassAssignDriveLetter(PCLASS_DEVICE_INFO DeviceInfo)
do do
{ {
/* Check that the disk exists */ /* Check that the disk exists */
PartitionU.Length = swprintf(PartitionU.Buffer, L"\\Device\\HardDisk%d\\Partition0", DeviceNumber) * sizeof(WCHAR); 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, InitializeObjectAttributes(&ObjectAttributes,
&PartitionU, &PartitionU,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
@ -233,7 +242,14 @@ ScsiClassAssignDriveLetter(PCLASS_DEVICE_INFO DeviceInfo)
do do
{ {
/* Check that the drive exists */ /* Check that the drive exists */
PartitionU.Length = swprintf(PartitionU.Buffer, L"\\??\\PhysicalDrive%d", DriveNumber) * sizeof(WCHAR); 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, InitializeObjectAttributes(&ObjectAttributes,
&PartitionU, &PartitionU,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
@ -252,19 +268,37 @@ ScsiClassAssignDriveLetter(PCLASS_DEVICE_INFO DeviceInfo)
} }
} while (Status == STATUS_SUCCESS); } while (Status == STATUS_SUCCESS);
/* Create the symbolic link to PhysicalDriveX */ 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); 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); Status = IoCreateSymbolicLink(&DriveLetterU, &PartitionU);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
/* Failed to create symbolic link */ /* Failed to create symbolic link */
DbgPrint("Failed to create symbolic link %wZ -> %wZ with %lx\n", &PartitionU, &DriveLetterU, Status);
return Status; return Status;
} }
DbgPrint("HACK: Created symbolic link %wZ -> %wZ\n", &PartitionU, &DriveLetterU); 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) while (TRUE)
{ {
/* Check that the disk exists */ /* Check that the disk exists */
@ -303,9 +337,6 @@ ScsiClassAssignDriveLetter(PCLASS_DEVICE_INFO DeviceInfo)
} }
} }
DeviceInfo->DeviceNumber = DeviceNumber;
DeviceInfo->DriveNumber = DriveNumber;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
@ -361,7 +392,7 @@ ScsiClassAddDevice(
Status = IoCreateDevice(DriverObject, Status = IoCreateDevice(DriverObject,
sizeof(CLASS_DEVICE_INFO), sizeof(CLASS_DEVICE_INFO),
NULL, NULL,
FILE_DEVICE_DISK, DriverExtension->InitializationData.DeviceType,
0, 0,
FALSE, FALSE,
&DeviceObject); &DeviceObject);
@ -375,6 +406,7 @@ ScsiClassAddDevice(
/* Attach it to the PDO */ /* Attach it to the PDO */
DeviceInfo->LowerDevice = IoAttachDeviceToDeviceStack(DeviceObject, PhysicalDeviceObject); DeviceInfo->LowerDevice = IoAttachDeviceToDeviceStack(DeviceObject, PhysicalDeviceObject);
DeviceInfo->DeviceType = DriverExtension->InitializationData.DeviceType;
/* Check that the kernel has already assigned drive letters */ /* Check that the kernel has already assigned drive letters */
if (KeLoaderBlock == NULL) if (KeLoaderBlock == NULL)

View file

@ -171,7 +171,7 @@ NTSTATUS
NTAPI NTAPI
USBSTOR_CSWCompletionRoutine( USBSTOR_CSWCompletionRoutine(
PDEVICE_OBJECT DeviceObject, PDEVICE_OBJECT DeviceObject,
PIRP Irp, PIRP Irp,
PVOID Ctx) PVOID Ctx)
{ {
PIRP_CONTEXT Context; PIRP_CONTEXT Context;
@ -430,7 +430,7 @@ NTSTATUS
NTAPI NTAPI
USBSTOR_DataCompletionRoutine( USBSTOR_DataCompletionRoutine(
PDEVICE_OBJECT DeviceObject, PDEVICE_OBJECT DeviceObject,
PIRP Irp, PIRP Irp,
PVOID Ctx) PVOID Ctx)
{ {
PIRP_CONTEXT Context; PIRP_CONTEXT Context;
@ -475,7 +475,7 @@ NTSTATUS
NTAPI NTAPI
USBSTOR_CBWCompletionRoutine( USBSTOR_CBWCompletionRoutine(
PDEVICE_OBJECT DeviceObject, PDEVICE_OBJECT DeviceObject,
PIRP Irp, PIRP Irp,
PVOID Ctx) PVOID Ctx)
{ {
PIRP_CONTEXT Context; PIRP_CONTEXT Context;
@ -509,7 +509,7 @@ USBSTOR_CBWCompletionRoutine(
{ {
// //
// write request use bulk out pipe // write request use bulk out pipe
// //
PipeHandle = Context->FDODeviceExtension->InterfaceInformation->Pipes[Context->FDODeviceExtension->BulkOutPipeIndex].PipeHandle; PipeHandle = Context->FDODeviceExtension->InterfaceInformation->Pipes[Context->FDODeviceExtension->BulkOutPipeIndex].PipeHandle;
} }
else else
@ -582,7 +582,7 @@ DumpCBW(
DPRINT("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", DPRINT("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
Block[0] & 0xFF, Block[1] & 0xFF, Block[2] & 0xFF, Block[3] & 0xFF, Block[4] & 0xFF, Block[5] & 0xFF, Block[6] & 0xFF, Block[7] & 0xFF, Block[8] & 0xFF, Block[9] & 0xFF, Block[0] & 0xFF, Block[1] & 0xFF, Block[2] & 0xFF, Block[3] & 0xFF, Block[4] & 0xFF, Block[5] & 0xFF, Block[6] & 0xFF, Block[7] & 0xFF, Block[8] & 0xFF, Block[9] & 0xFF,
Block[10] & 0xFF, Block[11] & 0xFF, Block[12] & 0xFF, Block[13] & 0xFF, Block[14] & 0xFF, Block[15] & 0xFF, Block[16] & 0xFF, Block[17] & 0xFF, Block[18] & 0xFF, Block[19] & 0xFF, Block[10] & 0xFF, Block[11] & 0xFF, Block[12] & 0xFF, Block[13] & 0xFF, Block[14] & 0xFF, Block[15] & 0xFF, Block[16] & 0xFF, Block[17] & 0xFF, Block[18] & 0xFF, Block[19] & 0xFF,
Block[20] & 0xFF, Block[21] & 0xFF, Block[22] & 0xFF, Block[23] & 0xFF, Block[24] & 0xFF, Block[25] & 0xFF, Block[26] & 0xFF, Block[27] & 0xFF, Block[28] & 0xFF, Block[29] & 0xFF, Block[20] & 0xFF, Block[21] & 0xFF, Block[22] & 0xFF, Block[23] & 0xFF, Block[24] & 0xFF, Block[25] & 0xFF, Block[26] & 0xFF, Block[27] & 0xFF, Block[28] & 0xFF, Block[29] & 0xFF,
Block[30] & 0xFF); Block[30] & 0xFF);
} }
@ -1079,10 +1079,10 @@ USBSTOR_SendModeSense(
// first struct is the header // first struct is the header
// MODE_PARAMETER_HEADER / _MODE_PARAMETER_HEADER10 // MODE_PARAMETER_HEADER / _MODE_PARAMETER_HEADER10
// //
// followed by // followed by
// MODE_PARAMETER_BLOCK // MODE_PARAMETER_BLOCK
// //
// //
UNIMPLEMENTED UNIMPLEMENTED
// //
@ -1258,7 +1258,7 @@ USBSTOR_SendUnknownRequest(
PPDO_DEVICE_EXTENSION PDODeviceExtension; PPDO_DEVICE_EXTENSION PDODeviceExtension;
PIO_STACK_LOCATION IoStack; PIO_STACK_LOCATION IoStack;
PSCSI_REQUEST_BLOCK Request; PSCSI_REQUEST_BLOCK Request;
UFI_TEST_UNIT_CMD Cmd; UFI_UNKNOWN_CMD Cmd;
// //
// get current stack location // get current stack location
@ -1283,7 +1283,7 @@ USBSTOR_SendUnknownRequest(
// //
// sanity check // sanity check
// //
ASSERT(Request->CdbLength == sizeof(UFI_TEST_UNIT_CMD)); ASSERT(Request->CdbLength <= sizeof(UFI_UNKNOWN_CMD));
// //
// initialize test unit cmd // initialize test unit cmd
@ -1412,28 +1412,11 @@ USBSTOR_HandleExecuteSCSI(
// //
Status = USBSTOR_SendTestUnit(DeviceObject, Irp, RetryCount); Status = USBSTOR_SendTestUnit(DeviceObject, Irp, RetryCount);
} }
#if 0
else if (pCDB->AsByte[0] == SCSIOP_MECHANISM_STATUS)
{
DPRINT1("SCSIOP_MECHANISM_STATUS\n");
//
// Just send it the way it is
//
Status = USBSTOR_SendUnknownRequest(DeviceObject, Irp, RetryCount);
}
#endif
else else
{ {
// unsupported request // Unknown request. Simply forward
DPRINT1("UNIMPLEMENTED Operation Code %x\n", pCDB->AsByte[0]); DPRINT1("Forwarding unknown Operation Code %x\n", pCDB->AsByte[0]);
Status = STATUS_NOT_SUPPORTED; Status = USBSTOR_SendUnknownRequest(DeviceObject, Irp, RetryCount);
Request->SrbStatus = SRB_STATUS_ERROR;
Irp->IoStatus.Status = Status;
Irp->IoStatus.Information = 0;
USBSTOR_QueueTerminateRequest(PDODeviceExtension->LowerDeviceObject, Irp);
IoCompleteRequest(Irp, IO_NO_INCREMENT);
} }
return Status; return Status;

View file

@ -317,6 +317,12 @@ C_ASSERT(sizeof(UFI_TEST_UNIT_CMD) == 12);
#define UFI_TEST_UNIT_CMD_LEN (6) #define UFI_TEST_UNIT_CMD_LEN (6)
//-------------------------------------------------------------------------------------------------------------------------------------------
typedef struct
{
UCHAR Bytes[16];
}UFI_UNKNOWN_CMD, *PUFI_UNKNOWN_CMD;
typedef struct typedef struct
{ {
union union
@ -385,7 +391,7 @@ USBSTOR_GetBusInterface(
PVOID PVOID
AllocateItem( AllocateItem(
IN POOL_TYPE PoolType, IN POOL_TYPE PoolType,
IN ULONG ItemSize); IN ULONG ItemSize);
VOID VOID
@ -406,7 +412,7 @@ NTSTATUS
NTAPI NTAPI
USBSTOR_SyncForwardIrpCompletionRoutine( USBSTOR_SyncForwardIrpCompletionRoutine(
PDEVICE_OBJECT DeviceObject, PDEVICE_OBJECT DeviceObject,
PIRP Irp, PIRP Irp,
PVOID Context); PVOID Context);
NTSTATUS NTSTATUS
@ -452,7 +458,7 @@ NTSTATUS
NTAPI NTAPI
USBSTOR_CSWCompletionRoutine( USBSTOR_CSWCompletionRoutine(
PDEVICE_OBJECT DeviceObject, PDEVICE_OBJECT DeviceObject,
PIRP Irp, PIRP Irp,
PVOID Ctx); PVOID Ctx);
NTSTATUS NTSTATUS