ReactOS.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
February
List overview
Download
Ros-diffs
June 2019
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
ros-diffs@reactos.org
28 participants
288 discussions
Start a n
N
ew thread
[reactos] 07/17: [USBSTOR] Refactor request issue code. Pipe handle selection now made more correctly. Simplified an MDL allocation for a request.
by Victor Perevertkin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=c452f7dab49f815ccd504…
commit c452f7dab49f815ccd5048d8d261dfbf1843c341 Author: Victor Perevertkin <victor(a)perevertkin.ru> AuthorDate: Mon Apr 1 01:07:55 2019 +0300 Commit: Victor Perevertkin <victor(a)perevertkin.ru> CommitDate: Tue Jun 11 04:39:43 2019 +0300 [USBSTOR] Refactor request issue code. Pipe handle selection now made more correctly. Simplified an MDL allocation for a request. --- drivers/usb/usbstor/error.c | 2 +- drivers/usb/usbstor/scsi.c | 372 ++++++++++++++++++------------------------ drivers/usb/usbstor/usbstor.h | 14 +- 3 files changed, 162 insertions(+), 226 deletions(-) diff --git a/drivers/usb/usbstor/error.c b/drivers/usb/usbstor/error.c index 0256c741a64..3ae8a3bfca4 100644 --- a/drivers/usb/usbstor/error.c +++ b/drivers/usb/usbstor/error.c @@ -160,7 +160,7 @@ USBSTOR_ResetHandlerWorkItemRoutine( DPRINT1("USBSTOR_ResetPipeWithHandle Status %x\n", Status); // now resend the csw as the stall got cleared - USBSTOR_SendCSW(WorkItemData->Context, WorkItemData->Irp); + USBSTOR_SendCSWRequest(WorkItemData->Context, WorkItemData->Irp); } VOID diff --git a/drivers/usb/usbstor/scsi.c b/drivers/usb/usbstor/scsi.c index f563f77fa8e..5411468a0a9 100644 --- a/drivers/usb/usbstor/scsi.c +++ b/drivers/usb/usbstor/scsi.c @@ -55,27 +55,45 @@ USBSTOR_SrbStatusToNtStatus( } } +static NTSTATUS -USBSTOR_BuildCBW( - IN ULONG Tag, - IN ULONG DataTransferLength, - IN UCHAR LUN, - IN UCHAR CommandBlockLength, - IN PUCHAR CommandBlock, - IN OUT PCBW Control) +USBSTOR_IssueBulkOrInterruptRequest( + IN PFDO_DEVICE_EXTENSION FDODeviceExtension, + IN PIRP Irp, + IN USBD_PIPE_HANDLE PipeHandle, + IN ULONG TransferFlags, + IN ULONG TransferBufferLength, + IN PVOID TransferBuffer, + IN PMDL TransferBufferMDL, + IN PIO_COMPLETION_ROUTINE CompletionRoutine, + IN PIRP_CONTEXT Context) { - ASSERT(CommandBlockLength <= 16); + PIO_STACK_LOCATION NextStack; + + RtlZeroMemory(&Context->Urb, sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER)); + + Context->Urb.UrbHeader.Length = sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER); + Context->Urb.UrbHeader.Function = URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER; - Control->Signature = CBW_SIGNATURE; - Control->Tag = Tag; - Control->DataTransferLength = DataTransferLength; - Control->Flags = (CommandBlock[0] != SCSIOP_WRITE) ? 0x80 : 0x00; - Control->LUN = (LUN & MAX_LUN); - Control->CommandBlockLength = CommandBlockLength; + Context->Urb.UrbBulkOrInterruptTransfer.PipeHandle = PipeHandle; + Context->Urb.UrbBulkOrInterruptTransfer.TransferFlags = TransferFlags; + Context->Urb.UrbBulkOrInterruptTransfer.TransferBufferLength = TransferBufferLength; + Context->Urb.UrbBulkOrInterruptTransfer.TransferBuffer = TransferBuffer; + Context->Urb.UrbBulkOrInterruptTransfer.TransferBufferMDL = TransferBufferMDL; - RtlCopyMemory(Control->CommandBlock, CommandBlock, CommandBlockLength); + NextStack = IoGetNextIrpStackLocation(Irp); + NextStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; + NextStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB; + NextStack->Parameters.Others.Argument1 = &Context->Urb; - return STATUS_SUCCESS; + IoSetCompletionRoutine(Irp, + CompletionRoutine, + Context, + TRUE, + TRUE, + TRUE); + + return IoCallDriver(FDODeviceExtension->LowerDeviceObject, Irp); } PIRP_CONTEXT @@ -170,11 +188,6 @@ USBSTOR_CSWCompletionRoutine( Context = (PIRP_CONTEXT)Ctx; - if (Context->TransferBufferMDL && Context->TransferBufferMDL != Context->Irp->MdlAddress) - { - IoFreeMdl(Context->TransferBufferMDL); - } - DPRINT("USBSTOR_CSWCompletionRoutine Irp %p Ctx %p Status %x\n", Irp, Ctx, Irp->IoStatus.Status); // first check for Irp errors @@ -274,35 +287,20 @@ USBSTOR_CSWCompletionRoutine( return Status; } -VOID -USBSTOR_SendCSW( +NTSTATUS +USBSTOR_SendCSWRequest( PIRP_CONTEXT Context, PIRP Irp) { - PIO_STACK_LOCATION IoStack; - - IoStack = IoGetNextIrpStackLocation(Irp); - - // now initialize the urb for sending the csw - UsbBuildInterruptOrBulkTransferRequest(&Context->Urb, - sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER), - Context->FDODeviceExtension->InterfaceInformation->Pipes[Context->FDODeviceExtension->BulkInPipeIndex].PipeHandle, - Context->csw, - NULL, - 512, //FIXME - USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK, - NULL); - - // initialize stack location - IoStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; - IoStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB; - IoStack->Parameters.Others.Argument1 = (PVOID)&Context->Urb; - IoStack->Parameters.DeviceIoControl.InputBufferLength = Context->Urb.UrbHeader.Length; - Irp->IoStatus.Status = STATUS_SUCCESS; - - IoSetCompletionRoutine(Irp, USBSTOR_CSWCompletionRoutine, Context, TRUE, TRUE, TRUE); - - IoCallDriver(Context->FDODeviceExtension->LowerDeviceObject, Irp); + return USBSTOR_IssueBulkOrInterruptRequest(Context->FDODeviceExtension, + Irp, + Context->FDODeviceExtension->InterfaceInformation->Pipes[Context->FDODeviceExtension->BulkInPipeIndex].PipeHandle, + USBD_TRANSFER_DIRECTION_IN, + sizeof(CSW), + Context->csw, + NULL, + USBSTOR_CSWCompletionRoutine, + Context); } IO_COMPLETION_ROUTINE USBSTOR_DataCompletionRoutine; @@ -316,13 +314,19 @@ USBSTOR_DataCompletionRoutine( { PIRP_CONTEXT Context; NTSTATUS Status; - + PIO_STACK_LOCATION IoStack; + PSCSI_REQUEST_BLOCK Request; DPRINT("USBSTOR_DataCompletionRoutine Irp %p Ctx %p Status %x\n", Irp, Ctx, Irp->IoStatus.Status); Context = (PIRP_CONTEXT)Ctx; - PIO_STACK_LOCATION IoStack = IoGetCurrentIrpStackLocation(Irp); - PSCSI_REQUEST_BLOCK Request = IoStack->Parameters.Scsi.Srb; + IoStack = IoGetCurrentIrpStackLocation(Irp); + Request = IoStack->Parameters.Scsi.Srb; + + if (Context->Urb.UrbBulkOrInterruptTransfer.TransferBufferMDL != Irp->MdlAddress) + { + IoFreeMdl(Context->Urb.UrbBulkOrInterruptTransfer.TransferBufferMDL); + } if (NT_SUCCESS(Irp->IoStatus.Status)) { @@ -336,7 +340,7 @@ USBSTOR_DataCompletionRoutine( } Request->DataTransferLength = Context->Urb.UrbBulkOrInterruptTransfer.TransferBufferLength; - USBSTOR_SendCSW(Context, Irp); + USBSTOR_SendCSWRequest(Context, Irp); } else if (USBD_STATUS(Context->Urb.UrbHeader.Status) == USBD_STATUS(USBD_STATUS_STALL_PID)) { @@ -373,8 +377,11 @@ USBSTOR_CBWCompletionRoutine( PIRP_CONTEXT Context; PIO_STACK_LOCATION IoStack; PSCSI_REQUEST_BLOCK Request; - UCHAR Code; USBD_PIPE_HANDLE PipeHandle; + ULONG TransferFlags; + PMDL Mdl = NULL; + PVOID TransferBuffer = NULL; + NTSTATUS Status; DPRINT("USBSTOR_CBWCompletionRoutine Irp %p Ctx %p Status %x\n", Irp, Ctx, Irp->IoStatus.Status); @@ -384,73 +391,79 @@ USBSTOR_CBWCompletionRoutine( if (!NT_SUCCESS(Irp->IoStatus.Status)) { - // perform reset recovery - Context->ErrorIndex = 2; - Status = USBSTOR_QueueWorkItem(Context, NULL); - ASSERT(Status == STATUS_MORE_PROCESSING_REQUIRED); + goto ResetRecovery; + } + + // a request without the buffer + if (!Irp->MdlAddress) + { + Request->SrbStatus = SRB_STATUS_SUCCESS; + USBSTOR_SendCSWRequest(Context, Irp); return STATUS_MORE_PROCESSING_REQUIRED; } - // is there data to be submitted - if (Context->TransferDataLength) + // a request with the data buffer + + if ((Request->SrbFlags & SRB_FLAGS_UNSPECIFIED_DIRECTION) == SRB_FLAGS_DATA_IN) + { + PipeHandle = Context->FDODeviceExtension->InterfaceInformation->Pipes[Context->FDODeviceExtension->BulkInPipeIndex].PipeHandle; + TransferFlags = USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK; + } + else if ((Request->SrbFlags & SRB_FLAGS_UNSPECIFIED_DIRECTION) == SRB_FLAGS_DATA_OUT) + { + PipeHandle = Context->FDODeviceExtension->InterfaceInformation->Pipes[Context->FDODeviceExtension->BulkOutPipeIndex].PipeHandle; + TransferFlags = USBD_TRANSFER_DIRECTION_OUT; + } + else { - // get command code - Code = Context->cbw->CommandBlock[0]; + // we check the validity of a request in disk.c so we should never be here + DPRINT1("Warning: shouldn't be here\n"); + goto ResetRecovery; + } - if (Code == SCSIOP_WRITE) + if (MmGetMdlVirtualAddress(Irp->MdlAddress) == Request->DataBuffer) { - // write request - use bulk out pipe - PipeHandle = Context->FDODeviceExtension->InterfaceInformation->Pipes[Context->FDODeviceExtension->BulkOutPipeIndex].PipeHandle; + Mdl = Irp->MdlAddress; } else { - // default bulk in pipe - PipeHandle = Context->FDODeviceExtension->InterfaceInformation->Pipes[Context->FDODeviceExtension->BulkInPipeIndex].PipeHandle; + Mdl = IoAllocateMdl(Request->DataBuffer, + Request->DataTransferLength, + FALSE, + FALSE, + NULL); + + if (Mdl) + { + IoBuildPartialMdl(Irp->MdlAddress, + Mdl, + Request->DataBuffer, + Request->DataTransferLength); + } } - // now initialize the urb for sending data - UsbBuildInterruptOrBulkTransferRequest(&Context->Urb, - sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER), - PipeHandle, - NULL, - Context->TransferBufferMDL, - Context->TransferDataLength, - ((Code == SCSIOP_WRITE) ? USBD_TRANSFER_DIRECTION_OUT : (USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK)), - NULL); - - IoSetCompletionRoutine(Irp, USBSTOR_DataCompletionRoutine, Context, TRUE, TRUE, TRUE); - } - else - { - if (NT_SUCCESS(Irp->IoStatus.Status)) + if (!Mdl) { - Request->SrbStatus = SRB_STATUS_SUCCESS; + DPRINT1("USBSTOR_DataTransfer: Mdl - %p\n", Mdl); + goto ResetRecovery; } - // now initialize the urb for sending the csw - UsbBuildInterruptOrBulkTransferRequest(&Context->Urb, - sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER), - Context->FDODeviceExtension->InterfaceInformation->Pipes[Context->FDODeviceExtension->BulkInPipeIndex].PipeHandle, - Context->csw, - NULL, - 512, //FIXME - USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK, - NULL); - - IoSetCompletionRoutine(Irp, USBSTOR_CSWCompletionRoutine, Context, TRUE, TRUE, TRUE); - } - - IoStack = IoGetNextIrpStackLocation(Irp); + USBSTOR_IssueBulkOrInterruptRequest(Context->FDODeviceExtension, + Irp, + PipeHandle, + TransferFlags, + Request->DataTransferLength, + TransferBuffer, + Mdl, + USBSTOR_DataCompletionRoutine, + Context); - // initialize stack location - IoStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; - IoStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB; - IoStack->Parameters.Others.Argument1 = (PVOID)&Context->Urb; - IoStack->Parameters.DeviceIoControl.InputBufferLength = Context->Urb.UrbHeader.Length; - Irp->IoStatus.Status = STATUS_SUCCESS; - - IoCallDriver(Context->FDODeviceExtension->LowerDeviceObject, Irp); + return STATUS_MORE_PROCESSING_REQUIRED; +ResetRecovery: + Context->ErrorIndex = 2; + Status = USBSTOR_QueueWorkItem(Context, NULL); + ASSERT(Status == STATUS_MORE_PROCESSING_REQUIRED); return STATUS_MORE_PROCESSING_REQUIRED; } @@ -463,132 +476,67 @@ DumpCBW( 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[30] & 0xFF); - -} - -NTSTATUS -USBSTOR_SendCBW( - PIRP_CONTEXT Context, - PIRP Irp) -{ - PIO_STACK_LOCATION IoStack; - - IoStack = IoGetNextIrpStackLocation(Irp); - - // initialize stack location - IoStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; - IoStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB; - IoStack->Parameters.Others.Argument1 = (PVOID)&Context->Urb; - IoStack->Parameters.DeviceIoControl.InputBufferLength = Context->Urb.UrbHeader.Length; - Irp->IoStatus.Status = STATUS_SUCCESS; - - IoSetCompletionRoutine(Irp, USBSTOR_CBWCompletionRoutine, Context, TRUE, TRUE, TRUE); - - return IoCallDriver(Context->FDODeviceExtension->LowerDeviceObject, Irp); } +static NTSTATUS -USBSTOR_SendRequest( - IN PDEVICE_OBJECT DeviceObject, - IN PIRP OriginalRequest, - IN UCHAR CommandLength, - IN PUCHAR Command, - IN ULONG TransferDataLength, - IN PUCHAR TransferData, - IN ULONG RetryCount) +USBSTOR_SendCBWRequest( + IN PFDO_DEVICE_EXTENSION FDODeviceExtension, + IN PIRP Irp, + IN PIRP_CONTEXT Context) { - PIRP_CONTEXT Context; PPDO_DEVICE_EXTENSION PDODeviceExtension; - PFDO_DEVICE_EXTENSION FDODeviceExtension; - PUCHAR MdlVirtualAddress; + PIO_STACK_LOCATION IoStack; + PSCSI_REQUEST_BLOCK Request; - Context = USBSTOR_AllocateIrpContext(); if (!Context) { - return STATUS_INSUFFICIENT_RESOURCES; + Context = USBSTOR_AllocateIrpContext(); + if (!Context) + { + return STATUS_INSUFFICIENT_RESOURCES; + } } + else + { + RtlZeroMemory(Context->cbw, sizeof(CBW)); + RtlZeroMemory(&Context->Urb, sizeof(URB)); + } - PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - FDODeviceExtension = (PFDO_DEVICE_EXTENSION)PDODeviceExtension->LowerDeviceObject->DeviceExtension; + IoStack = IoGetCurrentIrpStackLocation(Irp); + PDODeviceExtension = IoStack->DeviceObject->DeviceExtension; + Request = IoStack->Parameters.Scsi.Srb; - USBSTOR_BuildCBW(PtrToUlong(Context->cbw), - TransferDataLength, - PDODeviceExtension->LUN, - CommandLength, - Command, - Context->cbw); + Context->cbw->Signature = CBW_SIGNATURE; + Context->cbw->Tag = PtrToUlong(Context->cbw); + Context->cbw->DataTransferLength = Request->DataTransferLength; + Context->cbw->Flags = ((UCHAR)Request->SrbFlags & SRB_FLAGS_UNSPECIFIED_DIRECTION) << 1; + Context->cbw->LUN = PDODeviceExtension->LUN; + Context->cbw->CommandBlockLength = Request->CdbLength; + + RtlCopyMemory(Context->cbw->CommandBlock, Request->Cdb, Request->CdbLength); DPRINT("CBW %p\n", Context->cbw); DumpCBW((PUCHAR)Context->cbw); - // now initialize the urb - UsbBuildInterruptOrBulkTransferRequest(&Context->Urb, - sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER), - FDODeviceExtension->InterfaceInformation->Pipes[FDODeviceExtension->BulkOutPipeIndex].PipeHandle, - Context->cbw, - NULL, - sizeof(CBW), - USBD_TRANSFER_DIRECTION_OUT, - NULL); - // initialize rest of context - Context->Irp = OriginalRequest; - Context->TransferData = TransferData; - Context->TransferDataLength = TransferDataLength; + Context->Irp = Irp; + Context->TransferData = Request->DataBuffer; + Context->TransferDataLength = Request->DataTransferLength; Context->FDODeviceExtension = FDODeviceExtension; Context->PDODeviceExtension = PDODeviceExtension; - Context->RetryCount = RetryCount; - - // is there transfer data - if (Context->TransferDataLength) - { - // check if the original request already does have an mdl associated - if ((OriginalRequest->MdlAddress != NULL) && - (Context->TransferData == NULL || Command[0] == SCSIOP_READ || Command[0] == SCSIOP_WRITE)) - { - // Sanity check that the Mdl does describe the TransferData for read/write - if (CommandLength == UFI_READ_WRITE_CMD_LEN) - { - MdlVirtualAddress = MmGetMdlVirtualAddress(OriginalRequest->MdlAddress); - - // is there an offset - if (MdlVirtualAddress != Context->TransferData) - { - // lets build an mdl - Context->TransferBufferMDL = IoAllocateMdl(Context->TransferData, MmGetMdlByteCount(OriginalRequest->MdlAddress), FALSE, FALSE, NULL); - if (!Context->TransferBufferMDL) - { - FreeItem(Context->cbw); - FreeItem(Context); - return STATUS_INSUFFICIENT_RESOURCES; - } - - IoBuildPartialMdl(OriginalRequest->MdlAddress, Context->TransferBufferMDL, Context->TransferData, Context->TransferDataLength); - } - } - - if (!Context->TransferBufferMDL) - { - // I/O paging request - Context->TransferBufferMDL = OriginalRequest->MdlAddress; - } - } - else - { - // allocate mdl for buffer, buffer must be allocated from NonPagedPool - Context->TransferBufferMDL = IoAllocateMdl(Context->TransferData, Context->TransferDataLength, FALSE, FALSE, NULL); - if (!Context->TransferBufferMDL) - { - FreeItem(Context->cbw); - FreeItem(Context); - return STATUS_INSUFFICIENT_RESOURCES; - } - - MmBuildMdlForNonPagedPool(Context->TransferBufferMDL); - } - } - - return USBSTOR_SendCBW(Context, OriginalRequest); + Context->RetryCount = 0; + + return USBSTOR_IssueBulkOrInterruptRequest( + FDODeviceExtension, + Irp, + FDODeviceExtension->InterfaceInformation->Pipes[FDODeviceExtension->BulkOutPipeIndex].PipeHandle, + USBD_TRANSFER_DIRECTION_OUT, + sizeof(CBW), + Context->cbw, + NULL, + USBSTOR_CBWCompletionRoutine, + Context); } NTSTATUS @@ -614,7 +562,7 @@ USBSTOR_HandleExecuteSCSI( // check that we're sending to the right LUN ASSERT(pCDB->CDB10.LogicalUnitNumber == (PDODeviceExtension->LUN & MAX_LUN)); - Status = USBSTOR_SendRequest(DeviceObject, Irp, Request->CdbLength, (PUCHAR)pCDB, Request->DataTransferLength, Request->DataBuffer, RetryCount); + Status = USBSTOR_SendCBWRequest(PDODeviceExtension->LowerDeviceObject->DeviceExtension, Irp, NULL); return Status; } diff --git a/drivers/usb/usbstor/usbstor.h b/drivers/usb/usbstor/usbstor.h index 6d23a567853..fc3870ed298 100644 --- a/drivers/usb/usbstor/usbstor.h +++ b/drivers/usb/usbstor/usbstor.h @@ -413,19 +413,7 @@ USBSTOR_HandleExecuteSCSI( IN ULONG RetryCount); NTSTATUS -NTAPI -USBSTOR_CSWCompletionRoutine( - PDEVICE_OBJECT DeviceObject, - PIRP Irp, - PVOID Ctx); - -NTSTATUS -USBSTOR_SendCBW( - PIRP_CONTEXT Context, - PIRP Irp); - -VOID -USBSTOR_SendCSW( +USBSTOR_SendCSWRequest( PIRP_CONTEXT Context, PIRP Irp);
5 years, 6 months
1
0
0
0
[reactos] 06/17: [USBSTOR] Better handle CBW/CSW transfer errors and set SrbStatus correctly.
by Victor Perevertkin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=84f78cb0d79ada58965fe…
commit 84f78cb0d79ada58965fe936664f4f8245d7e63b Author: Victor Perevertkin <victor(a)perevertkin.ru> AuthorDate: Sun Mar 31 23:03:33 2019 +0300 Commit: Victor Perevertkin <victor(a)perevertkin.ru> CommitDate: Tue Jun 11 04:39:43 2019 +0300 [USBSTOR] Better handle CBW/CSW transfer errors and set SrbStatus correctly. --- drivers/usb/usbstor/scsi.c | 135 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 117 insertions(+), 18 deletions(-) diff --git a/drivers/usb/usbstor/scsi.c b/drivers/usb/usbstor/scsi.c index 120a3b09811..f563f77fa8e 100644 --- a/drivers/usb/usbstor/scsi.c +++ b/drivers/usb/usbstor/scsi.c @@ -5,6 +5,8 @@ * COPYRIGHT: 2005-2006 James Tabor * 2011-2012 Michael Martin (michael.martin(a)reactos.org) * 2011-2013 Johannes Anderwald (johannes.anderwald(a)reactos.org) + * 2017 Vadim Galyant + * 2019 Victor Perevertkin (victor.perevertkin(a)reactos.org) */ #include "usbstor.h" @@ -13,6 +15,46 @@ #include <debug.h> +static +NTSTATUS +USBSTOR_SrbStatusToNtStatus( + IN PSCSI_REQUEST_BLOCK Srb) +{ + UCHAR SrbStatus; + + SrbStatus = SRB_STATUS(Srb->SrbStatus); + + switch (SrbStatus) + { + case SRB_STATUS_SUCCESS: + return STATUS_SUCCESS; + + case SRB_STATUS_DATA_OVERRUN: + return STATUS_BUFFER_OVERFLOW; + + case SRB_STATUS_BAD_FUNCTION: + case SRB_STATUS_BAD_SRB_BLOCK_LENGTH: + return STATUS_INVALID_DEVICE_REQUEST; + + case SRB_STATUS_INVALID_LUN: + case SRB_STATUS_INVALID_TARGET_ID: + case SRB_STATUS_NO_HBA: + case SRB_STATUS_NO_DEVICE: + return STATUS_DEVICE_DOES_NOT_EXIST; + + case SRB_STATUS_TIMEOUT: + return STATUS_IO_TIMEOUT; + + case SRB_STATUS_BUS_RESET: + case SRB_STATUS_COMMAND_TIMEOUT: + case SRB_STATUS_SELECTION_TIMEOUT: + return STATUS_DEVICE_NOT_CONNECTED; + + default: + return STATUS_IO_DEVICE_ERROR; + } +} + NTSTATUS USBSTOR_BuildCBW( IN ULONG Tag, @@ -140,11 +182,12 @@ USBSTOR_CSWCompletionRoutine( { if (USBD_STATUS(Context->Urb.UrbHeader.Status) == USBD_STATUS(USBD_STATUS_STALL_PID)) { - if (Context->ErrorIndex == 0) + if (Context->RetryCount < 2) { - Context->ErrorIndex = 1; + ++Context->RetryCount; // clear stall and resend cbw + Context->ErrorIndex = 1; Status = USBSTOR_QueueWorkItem(Context, Irp); ASSERT(Status == STATUS_MORE_PROCESSING_REQUIRED); @@ -177,8 +220,6 @@ USBSTOR_CSWCompletionRoutine( Request = IoStack->Parameters.Scsi.Srb; ASSERT(Request); - Status = Irp->IoStatus.Status; - // finally check for CSW errors if (Context->csw->Status == CSW_STATUS_COMMAND_PASSED) { @@ -193,21 +234,36 @@ USBSTOR_CSWCompletionRoutine( Context->PDODeviceExtension->LastLogicBlockAddress = NTOHL(Response->LastLogicalBlockAddress); } - Status = STATUS_SUCCESS; - Request->SrbStatus = SRB_STATUS_SUCCESS; - Irp->IoStatus.Status = STATUS_SUCCESS; - Irp->IoStatus.Information = Request->DataTransferLength; + Status = USBSTOR_SrbStatusToNtStatus(Request); } else if (Context->csw->Status == CSW_STATUS_COMMAND_FAILED) { + // the command is correct but with failed status - issue request sense DPRINT("USBSTOR_CSWCompletionRoutine: CSW_STATUS_COMMAND_FAILED\n"); - // perform reset recovery - Context->ErrorIndex = 2; - Status = USBSTOR_QueueWorkItem(Context, NULL); - ASSERT(Status == STATUS_MORE_PROCESSING_REQUIRED); - return STATUS_MORE_PROCESSING_REQUIRED; + + ASSERT(Context->FDODeviceExtension->ActiveSrb == Request); + + // setting a generic error status, additional information + // should be read by higher-level driver from SenseInfoBuffer + Request->SrbStatus = SRB_STATUS_ERROR; + Request->ScsiStatus = 2; + Request->DataTransferLength = 0; + + DPRINT("Flags: %x SBL: %x, buf: %p\n", Request->SrbFlags, Request->SenseInfoBufferLength, Request->SenseInfoBuffer); + + if (!(Request->SrbFlags & SRB_FLAGS_DISABLE_AUTOSENSE) && + Request->SenseInfoBufferLength && + Request->SenseInfoBuffer) + { + // TODO: issue request sense + } + + Status = STATUS_IO_DEVICE_ERROR; } + Irp->IoStatus.Status = Status; + Irp->IoStatus.Information = Request->DataTransferLength; + FreeItem(Context->cbw); // terminate current request @@ -265,17 +321,42 @@ USBSTOR_DataCompletionRoutine( DPRINT("USBSTOR_DataCompletionRoutine Irp %p Ctx %p Status %x\n", Irp, Ctx, Irp->IoStatus.Status); Context = (PIRP_CONTEXT)Ctx; + PIO_STACK_LOCATION IoStack = IoGetCurrentIrpStackLocation(Irp); + PSCSI_REQUEST_BLOCK Request = IoStack->Parameters.Scsi.Srb; - if (!NT_SUCCESS(Irp->IoStatus.Status)) + if (NT_SUCCESS(Irp->IoStatus.Status)) + { + if (Context->Urb.UrbBulkOrInterruptTransfer.TransferBufferLength < Request->DataTransferLength) + { + Request->SrbStatus = SRB_STATUS_DATA_OVERRUN; + } + else + { + Request->SrbStatus = SRB_STATUS_SUCCESS; + } + + Request->DataTransferLength = Context->Urb.UrbBulkOrInterruptTransfer.TransferBufferLength; + USBSTOR_SendCSW(Context, Irp); + } + else if (USBD_STATUS(Context->Urb.UrbHeader.Status) == USBD_STATUS(USBD_STATUS_STALL_PID)) { + ++Context->RetryCount; + + Request->SrbStatus = SRB_STATUS_DATA_OVERRUN; + Request->DataTransferLength = Context->Urb.UrbBulkOrInterruptTransfer.TransferBufferLength; + // clear stall and resend cbw Context->ErrorIndex = 1; Status = USBSTOR_QueueWorkItem(Context, Irp); ASSERT(Status == STATUS_MORE_PROCESSING_REQUIRED); - return STATUS_MORE_PROCESSING_REQUIRED; } - - USBSTOR_SendCSW(Context, Irp); + else + { + // perform reset recovery + Context->ErrorIndex = 2; + Status = USBSTOR_QueueWorkItem(Context, NULL); + ASSERT(Status == STATUS_MORE_PROCESSING_REQUIRED); + } return STATUS_MORE_PROCESSING_REQUIRED; } @@ -291,13 +372,24 @@ USBSTOR_CBWCompletionRoutine( { PIRP_CONTEXT Context; PIO_STACK_LOCATION IoStack; + PSCSI_REQUEST_BLOCK Request; UCHAR Code; USBD_PIPE_HANDLE PipeHandle; DPRINT("USBSTOR_CBWCompletionRoutine Irp %p Ctx %p Status %x\n", Irp, Ctx, Irp->IoStatus.Status); Context = (PIRP_CONTEXT)Ctx; - IoStack = IoGetNextIrpStackLocation(Irp); + IoStack = IoGetCurrentIrpStackLocation(Irp); + Request = IoStack->Parameters.Scsi.Srb; + + if (!NT_SUCCESS(Irp->IoStatus.Status)) + { + // perform reset recovery + Context->ErrorIndex = 2; + Status = USBSTOR_QueueWorkItem(Context, NULL); + ASSERT(Status == STATUS_MORE_PROCESSING_REQUIRED); + return STATUS_MORE_PROCESSING_REQUIRED; + } // is there data to be submitted if (Context->TransferDataLength) @@ -330,6 +422,11 @@ USBSTOR_CBWCompletionRoutine( } else { + if (NT_SUCCESS(Irp->IoStatus.Status)) + { + Request->SrbStatus = SRB_STATUS_SUCCESS; + } + // now initialize the urb for sending the csw UsbBuildInterruptOrBulkTransferRequest(&Context->Urb, sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER), @@ -343,6 +440,8 @@ USBSTOR_CBWCompletionRoutine( IoSetCompletionRoutine(Irp, USBSTOR_CSWCompletionRoutine, Context, TRUE, TRUE, TRUE); } + IoStack = IoGetNextIrpStackLocation(Irp); + // initialize stack location IoStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; IoStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB;
5 years, 6 months
1
0
0
0
[reactos] 05/17: [USBSTOR] Better validate SCSI IRPs. Patch by Vadim Galyant
by Victor Perevertkin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=3faf5efd49586b46b2c19…
commit 3faf5efd49586b46b2c19e7b99e7771b59580125 Author: Victor Perevertkin <victor(a)perevertkin.ru> AuthorDate: Sun Mar 31 17:20:27 2019 +0300 Commit: Victor Perevertkin <victor(a)perevertkin.ru> CommitDate: Tue Jun 11 04:39:43 2019 +0300 [USBSTOR] Better validate SCSI IRPs. Patch by Vadim Galyant --- drivers/usb/usbstor/disk.c | 101 +++++++++++++++++++++++++++++++++--------- drivers/usb/usbstor/usbstor.h | 1 + 2 files changed, 81 insertions(+), 21 deletions(-) diff --git a/drivers/usb/usbstor/disk.c b/drivers/usb/usbstor/disk.c index 984296214cf..b73ca91292c 100644 --- a/drivers/usb/usbstor/disk.c +++ b/drivers/usb/usbstor/disk.c @@ -5,6 +5,7 @@ * COPYRIGHT: 2005-2006 James Tabor * 2011-2012 Michael Martin (michael.martin(a)reactos.org) * 2011-2013 Johannes Anderwald (johannes.anderwald(a)reactos.org) + * 2017 Vadim Galyant */ #include "usbstor.h" @@ -13,6 +14,69 @@ #include <debug.h> +static +BOOLEAN +IsRequestValid(PIRP Irp) +{ + ULONG TransferLength; + PIO_STACK_LOCATION IoStack; + PSCSI_REQUEST_BLOCK Srb; + + IoStack = IoGetCurrentIrpStackLocation(Irp); + Srb = IoStack->Parameters.Scsi.Srb; + + if (Srb->SrbFlags & (SRB_FLAGS_DATA_IN | SRB_FLAGS_DATA_OUT)) + { + if ((Srb->SrbFlags & SRB_FLAGS_UNSPECIFIED_DIRECTION) == SRB_FLAGS_UNSPECIFIED_DIRECTION) + { + DPRINT1("IsRequestValid: Invalid Srb. Srb->SrbFlags - %X\n", Srb->SrbFlags); + return FALSE; + } + + TransferLength = Srb->DataTransferLength; + + if (Irp->MdlAddress == NULL) + { + DPRINT1("IsRequestValid: Invalid Srb. Irp->MdlAddress == NULL\n"); + return FALSE; + } + + if (TransferLength == 0) + { + DPRINT1("IsRequestValid: Invalid Srb. TransferLength == 0\n"); + return FALSE; + } + + if (TransferLength > USBSTOR_DEFAULT_MAX_TRANSFER_LENGTH) + { + DPRINT1("IsRequestValid: Invalid Srb. TransferLength > 0x10000\n"); + return FALSE; + } + } + else + { + if (Srb->DataTransferLength) + { + DPRINT1("IsRequestValid: Invalid Srb. Srb->DataTransferLength != 0\n"); + return FALSE; + } + + if (Srb->DataBuffer) + { + DPRINT1("IsRequestValid: Invalid Srb. Srb->DataBuffer != NULL\n"); + return FALSE; + } + + if (Irp->MdlAddress) + { + DPRINT1("IsRequestValid: Invalid Srb. Irp->MdlAddress != NULL\n"); + return FALSE; + } + } + + return TRUE; +} + NTSTATUS USBSTOR_HandleInternalDeviceControl( IN PDEVICE_OBJECT DeviceObject, @@ -35,28 +99,23 @@ USBSTOR_HandleInternalDeviceControl( { DPRINT("SRB_FUNCTION_EXECUTE_SCSI\n"); - // check if request is valid - if (Request->SrbFlags & (SRB_FLAGS_DATA_IN | SRB_FLAGS_DATA_OUT)) + if (!IsRequestValid(Irp)) { - // data is transferred with this irp - if ((Request->SrbFlags & (SRB_FLAGS_DATA_IN | SRB_FLAGS_DATA_OUT)) == (SRB_FLAGS_DATA_IN | SRB_FLAGS_DATA_OUT) || - Request->DataTransferLength == 0 || - Irp->MdlAddress == NULL) - { - Status = STATUS_INVALID_PARAMETER; - break; - } + Status = STATUS_INVALID_PARAMETER; + break; } - else + + if (Request->Cdb[0] == SCSIOP_MODE_SENSE) { - // sense buffer request - if (Request->DataTransferLength || Request->DataBuffer || Irp->MdlAddress) - { - Status = STATUS_INVALID_PARAMETER; - break; - } + DPRINT("USBSTOR_Scsi: SRB_FUNCTION_EXECUTE_SCSI - FIXME SCSIOP_MODE_SENSE\n"); + // FIXME Get from registry WriteProtect for StorageDevicePolicies; + // L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\StorageDevicePolicies" + // QueryTable[0].Name = L"WriteProtect" } + IoMarkIrpPending(Irp); + Request->SrbStatus = SRB_STATUS_PENDING; + // add the request if (!USBSTOR_QueueAddIrp(PDODeviceExtension->LowerDeviceObject, Irp)) { @@ -337,8 +396,8 @@ USBSTOR_HandleQueryProperty( // fill out descriptor AdapterDescriptor->Version = sizeof(STORAGE_ADAPTER_DESCRIPTOR); AdapterDescriptor->Size = sizeof(STORAGE_ADAPTER_DESCRIPTOR); - AdapterDescriptor->MaximumTransferLength = MAXULONG; //FIXME compute some sane value - AdapterDescriptor->MaximumPhysicalPages = 25; //FIXME compute some sane value + AdapterDescriptor->MaximumTransferLength = USBSTOR_DEFAULT_MAX_TRANSFER_LENGTH; + AdapterDescriptor->MaximumPhysicalPages = USBSTOR_DEFAULT_MAX_TRANSFER_LENGTH / PAGE_SIZE + 1; // See CORE-10515 and CORE-10755 AdapterDescriptor->AlignmentMask = 0; AdapterDescriptor->AdapterUsesPio = FALSE; AdapterDescriptor->AdapterScansDown = FALSE; @@ -406,8 +465,8 @@ USBSTOR_HandleDeviceControl( if (Capabilities) { - Capabilities->MaximumTransferLength = MAXULONG; - Capabilities->MaximumPhysicalPages = 25; + Capabilities->MaximumTransferLength = USBSTOR_DEFAULT_MAX_TRANSFER_LENGTH; + Capabilities->MaximumPhysicalPages = USBSTOR_DEFAULT_MAX_TRANSFER_LENGTH / PAGE_SIZE + 1; // See CORE-10515 and CORE-10755 Capabilities->SupportedAsynchronousEvents = 0; Capabilities->AlignmentMask = 0; Capabilities->TaggedQueuing = FALSE; diff --git a/drivers/usb/usbstor/usbstor.h b/drivers/usb/usbstor/usbstor.h index 1ac3e33a55e..6d23a567853 100644 --- a/drivers/usb/usbstor/usbstor.h +++ b/drivers/usb/usbstor/usbstor.h @@ -9,6 +9,7 @@ #define USB_STOR_TAG 'sbsu' #define USB_MAXCHILDREN (16) +#define USBSTOR_DEFAULT_MAX_TRANSFER_LENGTH 0x10000 #define HTONS(n) (((((unsigned short)(n) & 0xFF)) << 8) | (((unsigned short)(n) & 0xFF00) >> 8)) #define NTOHS(n) (((((unsigned short)(n) & 0xFF)) << 8) | (((unsigned short)(n) & 0xFF00) >> 8))
5 years, 6 months
1
0
0
0
[reactos] 04/17: [USBSTOR] Rework the routines for sending internal SCSI requests. Now for each request SenseBuffer is correctly set and 3 attempts are made to be sure the STALL state is cleared and the error is in something else. Remove the usage of UFI_INQUIRY_DATA structure in favor of "standard" INQUIRYDATA structure from scsi.h
by Victor Perevertkin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=f3fd12b9be4143f27f6ce…
commit f3fd12b9be4143f27f6ce5cbb5f9943b1dedfe20 Author: Victor Perevertkin <victor(a)perevertkin.ru> AuthorDate: Sun Mar 31 16:52:04 2019 +0300 Commit: Victor Perevertkin <victor(a)perevertkin.ru> CommitDate: Tue Jun 11 04:39:43 2019 +0300 [USBSTOR] Rework the routines for sending internal SCSI requests. Now for each request SenseBuffer is correctly set and 3 attempts are made to be sure the STALL state is cleared and the error is in something else. Remove the usage of UFI_INQUIRY_DATA structure in favor of "standard" INQUIRYDATA structure from scsi.h Based in Vadim Galyant's patches to usbstor --- drivers/usb/usbstor/disk.c | 71 +++----- drivers/usb/usbstor/misc.c | 2 + drivers/usb/usbstor/pdo.c | 392 +++++++++++++++++++++--------------------- drivers/usb/usbstor/usbstor.h | 38 +--- 4 files changed, 230 insertions(+), 273 deletions(-) diff --git a/drivers/usb/usbstor/disk.c b/drivers/usb/usbstor/disk.c index cf9c0380136..984296214cf 100644 --- a/drivers/usb/usbstor/disk.c +++ b/drivers/usb/usbstor/disk.c @@ -174,7 +174,7 @@ USBSTOR_HandleQueryProperty( PSTORAGE_ADAPTER_DESCRIPTOR AdapterDescriptor; ULONG FieldLengthVendor, FieldLengthProduct, FieldLengthRevision, TotalLength, FieldLengthSerialNumber; PPDO_DEVICE_EXTENSION PDODeviceExtension; - PUFI_INQUIRY_RESPONSE InquiryData; + PINQUIRYDATA InquiryData; PSTORAGE_DEVICE_DESCRIPTOR DeviceDescriptor; PUCHAR Buffer; PFDO_DEVICE_EXTENSION FDODeviceExtension; @@ -224,13 +224,13 @@ USBSTOR_HandleQueryProperty( ASSERT(FDODeviceExtension); ASSERT(FDODeviceExtension->Common.IsFDO); - InquiryData = (PUFI_INQUIRY_RESPONSE)PDODeviceExtension->InquiryData; + InquiryData = PDODeviceExtension->InquiryData; ASSERT(InquiryData); // compute extra parameters length - FieldLengthVendor = USBSTOR_GetFieldLength(InquiryData->Vendor, 8); - FieldLengthProduct = USBSTOR_GetFieldLength(InquiryData->Product, 16); - FieldLengthRevision = USBSTOR_GetFieldLength(InquiryData->Revision, 4); + FieldLengthVendor = USBSTOR_GetFieldLength(InquiryData->VendorId, 8); + FieldLengthProduct = USBSTOR_GetFieldLength(InquiryData->ProductId, 16); + FieldLengthRevision = USBSTOR_GetFieldLength(InquiryData->ProductRevisionLevel, 4); if (FDODeviceExtension->SerialNumber) { @@ -263,11 +263,11 @@ USBSTOR_HandleQueryProperty( // initialize the device descriptor DeviceDescriptor = (PSTORAGE_DEVICE_DESCRIPTOR)Irp->AssociatedIrp.SystemBuffer; - DeviceDescriptor->Version = TotalLength; + DeviceDescriptor->Version = sizeof(STORAGE_DEVICE_DESCRIPTOR); DeviceDescriptor->Size = TotalLength; DeviceDescriptor->DeviceType = InquiryData->DeviceType; - DeviceDescriptor->DeviceTypeModifier = (InquiryData->RMB & 0x7F); - DeviceDescriptor->RemovableMedia = (InquiryData->RMB & 0x80) ? TRUE : FALSE; + DeviceDescriptor->DeviceTypeModifier = InquiryData->DeviceTypeModifier; + DeviceDescriptor->RemovableMedia = InquiryData->RemovableMedia; DeviceDescriptor->CommandQueueing = FALSE; DeviceDescriptor->BusType = BusTypeUsb; DeviceDescriptor->VendorIdOffset = sizeof(STORAGE_DEVICE_DESCRIPTOR) - sizeof(UCHAR); @@ -279,15 +279,15 @@ USBSTOR_HandleQueryProperty( // copy descriptors Buffer = (PUCHAR)((ULONG_PTR)DeviceDescriptor + sizeof(STORAGE_DEVICE_DESCRIPTOR) - sizeof(UCHAR)); - RtlCopyMemory(Buffer, InquiryData->Vendor, FieldLengthVendor); + RtlCopyMemory(Buffer, InquiryData->VendorId, FieldLengthVendor); Buffer[FieldLengthVendor] = '\0'; Buffer += FieldLengthVendor + 1; - RtlCopyMemory(Buffer, InquiryData->Product, FieldLengthProduct); + RtlCopyMemory(Buffer, InquiryData->ProductId, FieldLengthProduct); Buffer[FieldLengthProduct] = '\0'; Buffer += FieldLengthProduct + 1; - RtlCopyMemory(Buffer, InquiryData->Revision, FieldLengthRevision); + RtlCopyMemory(Buffer, InquiryData->ProductRevisionLevel, FieldLengthRevision); Buffer[FieldLengthRevision] = '\0'; Buffer += FieldLengthRevision + 1; @@ -364,9 +364,8 @@ USBSTOR_HandleDeviceControl( NTSTATUS Status; PPDO_DEVICE_EXTENSION PDODeviceExtension; PSCSI_ADAPTER_BUS_INFO BusInfo; - PSCSI_INQUIRY_DATA InquiryData; - PINQUIRYDATA ScsiInquiryData; - PUFI_INQUIRY_RESPONSE UFIInquiryResponse; + PSCSI_INQUIRY_DATA ScsiInquiryData; + PINQUIRYDATA InquiryData; IoStack = IoGetCurrentIrpStackLocation(Irp); @@ -431,11 +430,8 @@ USBSTOR_HandleDeviceControl( // get parameters BusInfo = Irp->AssociatedIrp.SystemBuffer; - InquiryData = (PSCSI_INQUIRY_DATA)(BusInfo + 1); - ScsiInquiryData = (PINQUIRYDATA)InquiryData->InquiryData; - - UFIInquiryResponse = (PUFI_INQUIRY_RESPONSE)PDODeviceExtension->InquiryData; - ASSERT(UFIInquiryResponse); + ScsiInquiryData = (PSCSI_INQUIRY_DATA)(BusInfo + 1); + InquiryData = (PINQUIRYDATA)ScsiInquiryData->InquiryData; BusInfo->NumberOfBuses = 1; @@ -443,30 +439,19 @@ USBSTOR_HandleDeviceControl( BusInfo->BusData[0].InitiatorBusId = 0; BusInfo->BusData[0].InquiryDataOffset = sizeof(SCSI_ADAPTER_BUS_INFO); - InquiryData->PathId = 0; - InquiryData->TargetId = 0; - InquiryData->Lun = PDODeviceExtension->LUN & MAX_LUN; - InquiryData->DeviceClaimed = PDODeviceExtension->Claimed; - InquiryData->InquiryDataLength = sizeof(INQUIRYDATA); - InquiryData->NextInquiryDataOffset = 0; - - RtlZeroMemory(ScsiInquiryData, sizeof(INQUIRYDATA)); - ScsiInquiryData->DeviceType = UFIInquiryResponse->DeviceType; - ScsiInquiryData->DeviceTypeQualifier = (UFIInquiryResponse->RMB & 0x7F); - - // Hack for IoReadPartitionTable call in disk.sys - ScsiInquiryData->RemovableMedia = ((ScsiInquiryData->DeviceType == DIRECT_ACCESS_DEVICE) ? ((UFIInquiryResponse->RMB & 0x80) ? 1 : 0) : 0); - - ScsiInquiryData->Versions = 0x04; - ScsiInquiryData->ResponseDataFormat = 0x02; - ScsiInquiryData->AdditionalLength = 31; - ScsiInquiryData->SoftReset = 0; - ScsiInquiryData->CommandQueue = 0; - ScsiInquiryData->LinkedCommands = 0; - ScsiInquiryData->RelativeAddressing = 0; - - RtlCopyMemory(&ScsiInquiryData->VendorId, UFIInquiryResponse->Vendor, USBSTOR_GetFieldLength(UFIInquiryResponse->Vendor, 8)); - RtlCopyMemory(&ScsiInquiryData->ProductId, UFIInquiryResponse->Product, USBSTOR_GetFieldLength(UFIInquiryResponse->Product, 16)); + ScsiInquiryData->PathId = 0; + ScsiInquiryData->TargetId = 0; + ScsiInquiryData->Lun = PDODeviceExtension->LUN & MAX_LUN; + ScsiInquiryData->DeviceClaimed = PDODeviceExtension->Claimed; + ScsiInquiryData->InquiryDataLength = sizeof(INQUIRYDATA); + ScsiInquiryData->NextInquiryDataOffset = 0; + + // Note: INQUIRYDATA structure is larger than INQUIRYDATABUFFERSIZE + RtlZeroMemory(InquiryData, sizeof(INQUIRYDATA)); + RtlCopyMemory(InquiryData, PDODeviceExtension->InquiryData, INQUIRYDATABUFFERSIZE); + + InquiryData->Versions = 0x04; + InquiryData->ResponseDataFormat = 0x02; // some devices set this to 1 Irp->IoStatus.Information = sizeof(SCSI_ADAPTER_BUS_INFO) + sizeof(SCSI_INQUIRY_DATA) + sizeof(INQUIRYDATA) - 1; Status = STATUS_SUCCESS; diff --git a/drivers/usb/usbstor/misc.c b/drivers/usb/usbstor/misc.c index 671336df88c..3dbbf160813 100644 --- a/drivers/usb/usbstor/misc.c +++ b/drivers/usb/usbstor/misc.c @@ -258,6 +258,7 @@ USBSTOR_ResetDevice( return Status; } +#if 0 BOOLEAN USBSTOR_IsFloppy( IN PUCHAR Buffer, @@ -319,3 +320,4 @@ USBSTOR_IsFloppy( return FALSE; } +#endif diff --git a/drivers/usb/usbstor/pdo.c b/drivers/usb/usbstor/pdo.c index 98c01d1cb7b..93caca4e1ef 100644 --- a/drivers/usb/usbstor/pdo.c +++ b/drivers/usb/usbstor/pdo.c @@ -5,6 +5,8 @@ * COPYRIGHT: 2005-2006 James Tabor * 2011-2012 Michael Martin (michael.martin(a)reactos.org) * 2011-2013 Johannes Anderwald (johannes.anderwald(a)reactos.org) + * 2017 Vadim Galyant + * 2019 Victor Perevertkin (victor.perevertkin(a)reactos.org) */ #include "usbstor.h" @@ -15,7 +17,7 @@ LPCSTR USBSTOR_GetDeviceType( - IN PUFI_INQUIRY_RESPONSE InquiryData, + IN PINQUIRYDATA InquiryData, IN UCHAR IsFloppy) { if (InquiryData->DeviceType == 0) @@ -67,7 +69,7 @@ USBSTOR_GetDeviceType( LPCSTR USBSTOR_GetGenericType( - IN PUFI_INQUIRY_RESPONSE InquiryData, + IN PINQUIRYDATA InquiryData, IN UCHAR IsFloppy) { if (InquiryData->DeviceType == 0) @@ -198,13 +200,13 @@ USBSTOR_PdoHandleQueryDeviceId( CHAR Buffer[100] = {0}; LPCSTR DeviceType; ULONG Offset = 0; - PUFI_INQUIRY_RESPONSE InquiryData; + PINQUIRYDATA InquiryData; ANSI_STRING AnsiString; UNICODE_STRING DeviceId; DeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; ASSERT(DeviceExtension->InquiryData); - InquiryData = (PUFI_INQUIRY_RESPONSE)DeviceExtension->InquiryData; + InquiryData = DeviceExtension->InquiryData; DeviceType = USBSTOR_GetDeviceType(InquiryData, DeviceExtension->IsFloppy); @@ -212,17 +214,17 @@ USBSTOR_PdoHandleQueryDeviceId( Offset = sprintf(&Buffer[Offset], "USBSTOR\\"); Offset += sprintf(&Buffer[Offset], DeviceType); Offset += sprintf(&Buffer[Offset], "&Ven_"); - Offset += CopyField(InquiryData->Vendor, &Buffer[Offset], 8); + Offset += CopyField(InquiryData->VendorId, &Buffer[Offset], 8); Offset += sprintf(&Buffer[Offset], "&Prod_"); - Offset += CopyField(InquiryData->Product, &Buffer[Offset], 16); + Offset += CopyField(InquiryData->ProductId, &Buffer[Offset], 16); Offset += sprintf(&Buffer[Offset], "&Rev_"); - Offset += CopyField(InquiryData->Revision, &Buffer[Offset], 4); + Offset += CopyField(InquiryData->ProductRevisionLevel, &Buffer[Offset], 4); RtlInitAnsiString(&AnsiString, (PCSZ)Buffer); // allocate DeviceId string DeviceId.Length = 0; - DeviceId.MaximumLength = (strlen((PCHAR)Buffer) + 1) * sizeof(WCHAR); + DeviceId.MaximumLength = (USHORT)((strlen((PCHAR)Buffer) + 1) * sizeof(WCHAR)); DeviceId.Buffer = (LPWSTR)AllocateItem(PagedPool, DeviceId.MaximumLength); if (!DeviceId.Buffer) { @@ -289,12 +291,12 @@ USBSTOR_PdoHandleQueryHardwareId( CHAR Id1[50], Id2[50], Id3[50], Id4[50], Id5[50], Id6[50]; ULONG Id1Length, Id2Length, Id3Length, Id4Length, Id5Length,Id6Length; ULONG Offset, TotalLength, Length; - PUFI_INQUIRY_RESPONSE InquiryData; + PINQUIRYDATA InquiryData; PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; FDODeviceExtension = (PFDO_DEVICE_EXTENSION)PDODeviceExtension->LowerDeviceObject->DeviceExtension; ASSERT(FDODeviceExtension->DeviceDescriptor); - InquiryData = (PUFI_INQUIRY_RESPONSE)PDODeviceExtension->InquiryData; + InquiryData = PDODeviceExtension->InquiryData; DeviceType = USBSTOR_GetDeviceType(InquiryData, PDODeviceExtension->IsFloppy); GenericType = USBSTOR_GetGenericType(InquiryData, PDODeviceExtension->IsFloppy); @@ -302,47 +304,47 @@ USBSTOR_PdoHandleQueryHardwareId( ASSERT(GenericType); // generate id 1 - // USBSTOR\SCSIType_Vendor(8)_Product(16)_Revision(4) + // USBSTOR\SCSIType_VendorId(8)_ProductId(16)_Revision(4) RtlZeroMemory(Id1, sizeof(Id1)); Offset = 0; Offset = sprintf(&Id1[Offset], "USBSTOR\\"); Offset += sprintf(&Id1[Offset], DeviceType); - Offset += CopyField(InquiryData->Vendor, &Id1[Offset], 8); - Offset += CopyField(InquiryData->Product, &Id1[Offset], 16); - Offset += CopyField(InquiryData->Revision, &Id1[Offset], 4); + Offset += CopyField(InquiryData->VendorId, &Id1[Offset], 8); + Offset += CopyField(InquiryData->ProductId, &Id1[Offset], 16); + Offset += CopyField(InquiryData->ProductRevisionLevel, &Id1[Offset], 4); Id1Length = strlen(Id1) + 1; DPRINT("USBSTOR_PdoHandleQueryHardwareId HardwareId1 %s\n", Id1); // generate id 2 - // USBSTOR\SCSIType_VENDOR(8)_Product(16) + // USBSTOR\SCSIType_VendorId(8)_ProductId(16) RtlZeroMemory(Id2, sizeof(Id2)); Offset = 0; Offset = sprintf(&Id2[Offset], "USBSTOR\\"); Offset += sprintf(&Id2[Offset], DeviceType); - Offset += CopyField(InquiryData->Vendor, &Id2[Offset], 8); - Offset += CopyField(InquiryData->Product, &Id2[Offset], 16); + Offset += CopyField(InquiryData->VendorId, &Id2[Offset], 8); + Offset += CopyField(InquiryData->ProductId, &Id2[Offset], 16); Id2Length = strlen(Id2) + 1; DPRINT("USBSTOR_PdoHandleQueryHardwareId HardwareId2 %s\n", Id2); // generate id 3 - // USBSTOR\SCSIType_VENDOR(8) + // USBSTOR\SCSIType_VendorId(8) RtlZeroMemory(Id3, sizeof(Id3)); Offset = 0; Offset = sprintf(&Id3[Offset], "USBSTOR\\"); Offset += sprintf(&Id3[Offset], DeviceType); - Offset += CopyField(InquiryData->Vendor, &Id3[Offset], 8); + Offset += CopyField(InquiryData->VendorId, &Id3[Offset], 8); Id3Length = strlen(Id3) + 1; DPRINT("USBSTOR_PdoHandleQueryHardwareId HardwareId3 %s\n", Id3); // generate id 4 - // USBSTOR\SCSIType_VENDOR(8)_Product(16)_Revision(1) + // USBSTOR\SCSIType_VendorId(8)_ProductId(16)_Revision(1) RtlZeroMemory(Id4, sizeof(Id4)); Offset = 0; Offset = sprintf(&Id4[Offset], "USBSTOR\\"); Offset += sprintf(&Id4[Offset], DeviceType); - Offset += CopyField(InquiryData->Vendor, &Id4[Offset], 8); - Offset += CopyField(InquiryData->Product, &Id4[Offset], 16); - Offset += CopyField(InquiryData->Revision, &Id4[Offset], 1); + Offset += CopyField(InquiryData->VendorId, &Id4[Offset], 8); + Offset += CopyField(InquiryData->ProductId, &Id4[Offset], 16); + Offset += CopyField(InquiryData->ProductRevisionLevel, &Id4[Offset], 1); Id4Length = strlen(Id4) + 1; DPRINT("USBSTOR_PdoHandleQueryHardwareId HardwareId4 %s\n", Id4); @@ -404,7 +406,7 @@ USBSTOR_PdoHandleQueryCompatibleId( PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; FDODeviceExtension = (PFDO_DEVICE_EXTENSION)PDODeviceExtension->LowerDeviceObject->DeviceExtension; ASSERT(FDODeviceExtension->DeviceDescriptor); - DeviceType = USBSTOR_GetDeviceType((PUFI_INQUIRY_RESPONSE)PDODeviceExtension->InquiryData, PDODeviceExtension->IsFloppy); + DeviceType = USBSTOR_GetDeviceType(PDODeviceExtension->InquiryData, PDODeviceExtension->IsFloppy); // format instance id Length = sprintf(Buffer, "USBSTOR\\%s", DeviceType) + 1; @@ -645,201 +647,204 @@ USBSTOR_PdoHandlePnp( NTSTATUS NTAPI -USBSTOR_CompletionRoutine( +USBSTOR_SyncCompletionRoutine( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Ctx) { - PKEVENT Event = (PKEVENT)Ctx; - - KeSetEvent(Event, 0, FALSE); + KeSetEvent((PKEVENT)Ctx, IO_NO_INCREMENT, FALSE); return STATUS_MORE_PROCESSING_REQUIRED; } +/* +* @name USBSTOR_SendInternalCdb +* +* Issues an internal SCSI request to device. +* The request is sent in a synchronous way. +*/ +static NTSTATUS -USBSTOR_AllocateIrp( - IN PDEVICE_OBJECT DeviceObject, - IN ULONG DataTransferLength, - IN UCHAR OpCode, - IN PKEVENT Event, - OUT PSCSI_REQUEST_BLOCK *OutRequest, - OUT PIRP *OutIrp) +USBSTOR_SendInternalCdb( + IN PDEVICE_OBJECT PdoDevice, + IN PCDB Cdb, + IN UCHAR CdbLength, + IN ULONG TimeOutValue, + OUT PVOID OutDataBuffer, + OUT PULONG OutDataTransferLength) { - PIRP Irp; + PSCSI_REQUEST_BLOCK Srb; + PSENSE_DATA SenseBuffer; PIO_STACK_LOCATION IoStack; - PSCSI_REQUEST_BLOCK Request; - PCDB pCDB; - - Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE); - if (!Irp) - { - return STATUS_INSUFFICIENT_RESOURCES; - } - - IoStack = IoGetNextIrpStackLocation(Irp); - - Request = ExAllocatePoolWithTag(NonPagedPool, - sizeof(SCSI_REQUEST_BLOCK), - USB_STOR_TAG); - if (!Request) - { - IoFreeIrp(Irp); - return STATUS_INSUFFICIENT_RESOURCES; - } - - RtlZeroMemory(Request, sizeof(SCSI_REQUEST_BLOCK)); - - // allocate data transfer block - Request->DataBuffer = ExAllocatePoolWithTag(NonPagedPool, - DataTransferLength, - USB_STOR_TAG); - if (!Request->DataBuffer) - { - IoFreeIrp(Irp); - ExFreePoolWithTag(Request, USB_STOR_TAG); - return STATUS_INSUFFICIENT_RESOURCES; - } - - Irp->MdlAddress = IoAllocateMdl(Request->DataBuffer, DataTransferLength, FALSE, FALSE, NULL); - if (!Irp->MdlAddress) - { - IoFreeIrp(Irp); - ExFreePoolWithTag(Request->DataBuffer, USB_STOR_TAG); - ExFreePoolWithTag(Request, USB_STOR_TAG); - return STATUS_INSUFFICIENT_RESOURCES; - } - - MmBuildMdlForNonPagedPool(Irp->MdlAddress); - - Request->DataTransferLength = DataTransferLength; - Request->Function = SRB_FUNCTION_EXECUTE_SCSI; - Request->SrbFlags = SRB_FLAGS_DATA_IN; - - RtlZeroMemory(Request->DataBuffer, DataTransferLength); - - // get SCSI command data block - pCDB = (PCDB)Request->Cdb; - - // set op code - pCDB->AsByte[0] = OpCode; - - // store result - IoStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; - IoStack->Parameters.Others.Argument1 = Request; - IoStack->DeviceObject = DeviceObject; - - KeInitializeEvent(Event, NotificationEvent, FALSE); - - IoSetCompletionRoutine(Irp, USBSTOR_CompletionRoutine, (PVOID)Event, TRUE, TRUE, TRUE); - - *OutIrp = Irp; - *OutRequest = Request; - return STATUS_SUCCESS; -} - -NTSTATUS -USBSTOR_SendIrp( - IN PDEVICE_OBJECT PDODeviceObject, - IN ULONG DataTransferLength, - IN UCHAR OpCode, - OUT PVOID *OutData) -{ - NTSTATUS Status; - PIRP Irp; KEVENT Event; - PPDO_DEVICE_EXTENSION PDODeviceExtension; - PSCSI_REQUEST_BLOCK Request; + PIRP Irp = NULL; + PMDL Mdl = NULL; + ULONG ix = 0; + NTSTATUS Status = STATUS_INSUFFICIENT_RESOURCES; + UCHAR SrbStatus; - Status = USBSTOR_AllocateIrp(PDODeviceObject, DataTransferLength, OpCode, &Event, &Request, &Irp); - if (!NT_SUCCESS(Status)) - { - DPRINT1("[USBSTOR] Failed to build irp\n"); - return Status; - } - - PDODeviceExtension = (PPDO_DEVICE_EXTENSION)PDODeviceObject->DeviceExtension; + DPRINT("USBSTOR_SendInternalCdb SCSIOP %x\n", Cdb->CDB6GENERIC.OperationCode); - ASSERT(Irp); - ASSERT(PDODeviceExtension->LowerDeviceObject); - Status = IoCallDriver(PDODeviceExtension->Self, Irp); + Srb = ExAllocatePoolWithTag(NonPagedPool, + sizeof(SCSI_REQUEST_BLOCK), + USB_STOR_TAG); - if (Status == STATUS_PENDING) + if (Srb) { - KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL); - Status = Irp->IoStatus.Status; - } + SenseBuffer = ExAllocatePoolWithTag(NonPagedPool, + SENSE_BUFFER_SIZE, + USB_STOR_TAG); - if (NT_SUCCESS(Status)) - { - *OutData = Request->DataBuffer; - } - else - { - ExFreePoolWithTag(Request->DataBuffer, USB_STOR_TAG); - *OutData = NULL; + if (SenseBuffer) + { + Mdl = IoAllocateMdl(OutDataBuffer, + *OutDataTransferLength, + FALSE, + FALSE, + NULL); + + if (!Mdl) + { + ExFreePoolWithTag(SenseBuffer, USB_STOR_TAG); + ExFreePoolWithTag(Srb, USB_STOR_TAG); + return Status; + } + + MmBuildMdlForNonPagedPool(Mdl); + + // make 3 attempts - the device may be in STALL state after the first one + do + { + Irp = IoAllocateIrp(PdoDevice->StackSize, FALSE); + + if (!Irp) + { + break; + } + + IoStack = IoGetNextIrpStackLocation(Irp); + IoStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; + IoStack->Parameters.Scsi.Srb = Srb; + + RtlZeroMemory(Srb, sizeof(SCSI_REQUEST_BLOCK)); + + Srb->Length = sizeof(SCSI_REQUEST_BLOCK); + Srb->Function = SRB_FUNCTION_EXECUTE_SCSI; + Srb->CdbLength = CdbLength; + Srb->SenseInfoBufferLength = SENSE_BUFFER_SIZE; + Srb->SrbFlags = SRB_FLAGS_DATA_IN | SRB_FLAGS_NO_QUEUE_FREEZE; + Srb->DataTransferLength = *OutDataTransferLength; + Srb->TimeOutValue = TimeOutValue; + Srb->DataBuffer = OutDataBuffer; + Srb->SenseInfoBuffer = SenseBuffer; + + RtlCopyMemory(Srb->Cdb, Cdb, CdbLength); + + Irp->MdlAddress = Mdl; + + KeInitializeEvent(&Event, SynchronizationEvent, FALSE); + + IoSetCompletionRoutine(Irp, + USBSTOR_SyncCompletionRoutine, + &Event, + TRUE, + TRUE, + TRUE); + + if (IoCallDriver(PdoDevice, Irp) == STATUS_PENDING) + { + KeWaitForSingleObject(&Event, + Executive, + KernelMode, + FALSE, + NULL); + } + + SrbStatus = SRB_STATUS(Srb->SrbStatus); + + IoFreeIrp(Irp); + Irp = NULL; + + if (SrbStatus == SRB_STATUS_SUCCESS || + SrbStatus == SRB_STATUS_DATA_OVERRUN) + { + Status = STATUS_SUCCESS; + *OutDataTransferLength = Srb->DataTransferLength; + break; + } + + Status = STATUS_UNSUCCESSFUL; + + ++ix; + } while (ix < 3); + + if (Mdl) + { + IoFreeMdl(Mdl); + } + + ExFreePoolWithTag(SenseBuffer, USB_STOR_TAG); + } + + ExFreePoolWithTag(Srb, USB_STOR_TAG); } - ExFreePoolWithTag(Request, USB_STOR_TAG); - IoFreeMdl(Irp->MdlAddress); - IoFreeIrp(Irp); return Status; } +/* +* @name USBSTOR_FillInquiryData +* +* Sends a SCSI Inquiry request and fills in the PDODeviceExtension->InquiryData field with a result. +*/ +static NTSTATUS -USBSTOR_SendInquiryIrp( +USBSTOR_FillInquiryData( IN PDEVICE_OBJECT PDODeviceObject) { - NTSTATUS Status; + NTSTATUS Status = STATUS_INSUFFICIENT_RESOURCES; PPDO_DEVICE_EXTENSION PDODeviceExtension; - PUFI_INQUIRY_RESPONSE Response; + CDB Cdb; + ULONG DataTransferLength = INQUIRYDATABUFFERSIZE; + PINQUIRYDATA InquiryData; PDODeviceExtension = (PPDO_DEVICE_EXTENSION)PDODeviceObject->DeviceExtension; + InquiryData = ExAllocatePoolWithTag(NonPagedPool, INQUIRYDATABUFFERSIZE, USB_STOR_TAG); - Status = USBSTOR_SendIrp(PDODeviceObject, sizeof(UFI_INQUIRY_RESPONSE), SCSIOP_INQUIRY, (PVOID*)&Response); - if (!NT_SUCCESS(Status)) + if (!InquiryData) { - DPRINT1("USBSTOR_SendInquiryIrp Failed with %x\n", Status); + DPRINT1("USBSTOR_FillInquiryData failed with %x\n", Status); return Status; } - DPRINT1("Response %p\n", Response); - DPRINT1("DeviceType %x\n", Response->DeviceType); - DPRINT1("RMB %x\n", Response->RMB); - DPRINT1("Version %x\n", Response->Version); - DPRINT1("Format %x\n", Response->Format); - DPRINT1("Length %x\n", Response->Length); - DPRINT1("Reserved %p\n", Response->Reserved); - DPRINT1("Vendor %c%c%c%c%c%c%c%c\n", Response->Vendor[0], Response->Vendor[1], Response->Vendor[2], Response->Vendor[3], Response->Vendor[4], Response->Vendor[5], Response->Vendor[6], Response->Vendor[7]); - DPRINT1("Product %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n", Response->Product[0], Response->Product[1], Response->Product[2], Response->Product[3], - Response->Product[4], Response->Product[5], Response->Product[6], Response->Product[7], - Response->Product[8], Response->Product[9], Response->Product[10], Response->Product[11], - Response->Product[12], Response->Product[13], Response->Product[14], Response->Product[15]); - - DPRINT1("Revision %c%c%c%c\n", Response->Revision[0], Response->Revision[1], Response->Revision[2], Response->Revision[3]); - - PDODeviceExtension->InquiryData = (PVOID)Response; - return Status; -} + RtlZeroMemory(&Cdb, sizeof(Cdb)); + Cdb.CDB6INQUIRY.OperationCode = SCSIOP_INQUIRY; + Cdb.CDB6INQUIRY.AllocationLength = INQUIRYDATABUFFERSIZE; -NTSTATUS -USBSTOR_SendFormatCapacityIrp( - IN PDEVICE_OBJECT PDODeviceObject) -{ - NTSTATUS Status; - PPDO_DEVICE_EXTENSION PDODeviceExtension; - PUCHAR Response; - - PDODeviceExtension = (PPDO_DEVICE_EXTENSION)PDODeviceObject->DeviceExtension; + Status = USBSTOR_SendInternalCdb(PDODeviceObject, &Cdb, CDB6GENERIC_LENGTH, 20, InquiryData, &DataTransferLength); - Status = USBSTOR_SendIrp(PDODeviceObject, 0xFC, SCSIOP_READ_FORMATTED_CAPACITY, (PVOID*)&Response); if (!NT_SUCCESS(Status)) { + DPRINT1("USBSTOR_FillInquiryData failed with %x\n", Status); + ExFreePoolWithTag(InquiryData, USB_STOR_TAG); return Status; } - PDODeviceExtension->IsFloppy = USBSTOR_IsFloppy(Response, 0xFC /*FIXME*/, &PDODeviceExtension->MediumTypeCode); - - ExFreePoolWithTag(Response, USB_STOR_TAG); + DPRINT("DeviceType %x\n", InquiryData->DeviceType); + DPRINT("DeviceTypeModifier %x\n", InquiryData->DeviceTypeModifier); + DPRINT("RemovableMedia %x\n", InquiryData->RemovableMedia); + DPRINT("Version %x\n", InquiryData->Versions); + DPRINT("Format %x\n", InquiryData->ResponseDataFormat); + DPRINT("Length %x\n", InquiryData->AdditionalLength); + DPRINT("Reserved %p\n", InquiryData->Reserved); + DPRINT("VendorId %c%c%c%c%c%c%c%c\n", InquiryData->VendorId[0], InquiryData->VendorId[1], InquiryData->VendorId[2], InquiryData->VendorId[3], InquiryData->VendorId[4], InquiryData->VendorId[5], InquiryData->VendorId[6], InquiryData->VendorId[7]); + DPRINT("ProductId %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\n", InquiryData->ProductId[0], InquiryData->ProductId[1], InquiryData->ProductId[2], InquiryData->ProductId[3], + InquiryData->ProductId[4], InquiryData->ProductId[5], InquiryData->ProductId[6], InquiryData->ProductId[7], + InquiryData->ProductId[8], InquiryData->ProductId[9], InquiryData->ProductId[10], InquiryData->ProductId[11], + InquiryData->ProductId[12], InquiryData->ProductId[13], InquiryData->ProductId[14], InquiryData->ProductId[15]); + + DPRINT("Revision %c%c%c%c\n", InquiryData->ProductRevisionLevel[0], InquiryData->ProductRevisionLevel[1], InquiryData->ProductRevisionLevel[2], InquiryData->ProductRevisionLevel[3]); + + PDODeviceExtension->InquiryData = InquiryData; return Status; } @@ -851,7 +856,6 @@ USBSTOR_CreatePDO( PDEVICE_OBJECT PDO; NTSTATUS Status; PPDO_DEVICE_EXTENSION PDODeviceExtension; - PUFI_INQUIRY_RESPONSE Response; PFDO_DEVICE_EXTENSION FDODeviceExtension; FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; @@ -860,6 +864,7 @@ USBSTOR_CreatePDO( Status = IoCreateDevice(DeviceObject->DriverObject, sizeof(PDO_DEVICE_EXTENSION), NULL, FILE_DEVICE_MASS_STORAGE, FILE_AUTOGENERATED_DEVICE_NAME | FILE_DEVICE_SECURE_OPEN, FALSE, &PDO); if (!NT_SUCCESS(Status)) { + DPRINT1("Failed to create PDO, status %x\n", Status); return Status; } @@ -876,7 +881,7 @@ USBSTOR_CreatePDO( PDODeviceExtension->Self = PDO; PDODeviceExtension->LUN = LUN; - PDO->Flags |= DO_DIRECT_IO | DO_MAP_IO_BUFFER; + PDO->Flags |= DO_DIRECT_IO; // device is initialized PDO->Flags &= ~DO_DEVICE_INITIALIZING; @@ -885,20 +890,21 @@ USBSTOR_CreatePDO( FDODeviceExtension->ChildPDO[LUN] = PDO; // send inquiry command by irp - Status = USBSTOR_SendInquiryIrp(PDO); - ASSERT(Status == STATUS_SUCCESS); - - Response = (PUFI_INQUIRY_RESPONSE)PDODeviceExtension->InquiryData; - ASSERT(Response); + Status = USBSTOR_FillInquiryData(PDO); - if (Response->DeviceType == 0) + if (!NT_SUCCESS(Status)) { - // check if it is a floppy - Status = USBSTOR_SendFormatCapacityIrp(PDO); - DPRINT1("[USBSTOR] Status %x IsFloppy %x MediumTypeCode %x\n", Status, PDODeviceExtension->IsFloppy, PDODeviceExtension->MediumTypeCode); + return Status; + } - // failing command is non critical - Status = STATUS_SUCCESS; + if (PDODeviceExtension->InquiryData->DeviceType == DIRECT_ACCESS_DEVICE) + { + PDODeviceExtension->IsFloppy = FALSE; // TODO: implement the actual check + } + else + { + // we work only with DIRECT_ACCESS_DEVICE for now + return STATUS_NOT_SUPPORTED; } return Status; diff --git a/drivers/usb/usbstor/usbstor.h b/drivers/usb/usbstor/usbstor.h index 40b369bd15e..1ac3e33a55e 100644 --- a/drivers/usb/usbstor/usbstor.h +++ b/drivers/usb/usbstor/usbstor.h @@ -68,7 +68,7 @@ typedef struct USBSTOR_COMMON_DEVICE_EXTENSION Common; PDEVICE_OBJECT LowerDeviceObject; // points to FDO UCHAR LUN; // lun id - PVOID InquiryData; // USB SCSI inquiry data + PINQUIRYDATA InquiryData; // USB SCSI inquiry data PUCHAR FormatData; // USB SCSI Read Format Capacity Data UCHAR Claimed; // indicating if it has been claimed by upper driver ULONG BlockLength; // length of block @@ -117,42 +117,6 @@ typedef struct UCHAR Status; // CSW status }CSW, *PCSW; -//-------------------------------------------------------------------------------------------------------------------------------------------- -// -// UFI INQUIRY command -// -typedef struct -{ - UCHAR Code; // operation code 0x12 - UCHAR LUN; // lun address - UCHAR PageCode; // product data information, always 0x00 - UCHAR Reserved; // reserved 0x00 - UCHAR AllocationLength; // length of inquiry data to be returned, default 36 bytes - UCHAR Reserved1[7]; //reserved bytes 0x00 -}UFI_INQUIRY_CMD, *PUFI_INQUIRY_CMD; - -C_ASSERT(sizeof(UFI_INQUIRY_CMD) == 12); - -#define UFI_INQUIRY_CMD_LEN 0x6 - -// -// UFI INQUIRY command response -// -typedef struct -{ - UCHAR DeviceType; // device type - UCHAR RMB; // removable media bit - UCHAR Version; // contains version 0x00 - UCHAR Format; // response format - UCHAR Length; // additional length - UCHAR Reserved[3]; // reserved - UCHAR Vendor[8]; // vendor identification string - UCHAR Product[16]; // product identification string - UCHAR Revision[4]; // product revision code -}UFI_INQUIRY_RESPONSE, *PUFI_INQUIRY_RESPONSE; - -C_ASSERT(sizeof(UFI_INQUIRY_RESPONSE) == 36); - //-------------------------------------------------------------------------------------------------------------------------------------------- // // UFI read cmd
5 years, 6 months
1
0
0
0
[reactos] 03/17: [USBSTOR] Do not create a new Irp for USB requests - use the original one from higher-level driver instead. Refactored CSWCompletionRoutine for correct handling different CSW statuses, more work to be done here.
by Victor Perevertkin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=ed6724cd7e2d769d7453f…
commit ed6724cd7e2d769d7453ff0bd3eb3bc835bf2f04 Author: Victor Perevertkin <victor(a)perevertkin.ru> AuthorDate: Thu Mar 28 02:45:32 2019 +0300 Commit: Victor Perevertkin <victor(a)perevertkin.ru> CommitDate: Tue Jun 11 04:39:43 2019 +0300 [USBSTOR] Do not create a new Irp for USB requests - use the original one from higher-level driver instead. Refactored CSWCompletionRoutine for correct handling different CSW statuses, more work to be done here. --- drivers/usb/usbstor/scsi.c | 179 +++++++++++++++++------------------------- drivers/usb/usbstor/usbstor.h | 4 + 2 files changed, 75 insertions(+), 108 deletions(-) diff --git a/drivers/usb/usbstor/scsi.c b/drivers/usb/usbstor/scsi.c index b2989f01fce..120a3b09811 100644 --- a/drivers/usb/usbstor/scsi.c +++ b/drivers/usb/usbstor/scsi.c @@ -57,6 +57,7 @@ USBSTOR_AllocateIrpContext() return Context; } +static BOOLEAN USBSTOR_IsCSWValid( PIRP_CONTEXT Context) @@ -73,12 +74,6 @@ USBSTOR_IsCSWValid( return FALSE; } - if (Context->csw->Status != 0x00) - { - DPRINT1("[USBSTOR] Expected Status 0x00 but got %x\n", Context->csw->Status); - return FALSE; - } - return TRUE; } @@ -128,99 +123,99 @@ USBSTOR_CSWCompletionRoutine( PIRP_CONTEXT Context; PIO_STACK_LOCATION IoStack; PSCSI_REQUEST_BLOCK Request; - PCDB pCDB; PUFI_CAPACITY_RESPONSE Response; NTSTATUS Status; Context = (PIRP_CONTEXT)Ctx; - if (Context->TransferBufferMDL) + if (Context->TransferBufferMDL && Context->TransferBufferMDL != Context->Irp->MdlAddress) { - // is there an irp associated - if (Context->Irp) - { - // did we allocate the mdl - if (Context->TransferBufferMDL != Context->Irp->MdlAddress) - { - IoFreeMdl(Context->TransferBufferMDL); - } - } - else - { - IoFreeMdl(Context->TransferBufferMDL); - } + IoFreeMdl(Context->TransferBufferMDL); } - DPRINT("USBSTOR_CSWCompletionRoutine Status %x\n", Irp->IoStatus.Status); + DPRINT("USBSTOR_CSWCompletionRoutine Irp %p Ctx %p Status %x\n", Irp, Ctx, Irp->IoStatus.Status); - if (!NT_SUCCESS(Irp->IoStatus.Information)) + // first check for Irp errors + if (!NT_SUCCESS(Irp->IoStatus.Status)) { - if (Context->ErrorIndex == 0) + if (USBD_STATUS(Context->Urb.UrbHeader.Status) == USBD_STATUS(USBD_STATUS_STALL_PID)) { - Context->ErrorIndex = 1; + if (Context->ErrorIndex == 0) + { + Context->ErrorIndex = 1; + + // clear stall and resend cbw + Status = USBSTOR_QueueWorkItem(Context, Irp); + ASSERT(Status == STATUS_MORE_PROCESSING_REQUIRED); - // clear stall and resend cbw - Status = USBSTOR_QueueWorkItem(Context, Irp); - ASSERT(Status == STATUS_MORE_PROCESSING_REQUIRED); - return STATUS_MORE_PROCESSING_REQUIRED; + return STATUS_MORE_PROCESSING_REQUIRED; + } + } + else + { + DPRINT1("USBSTOR_CSWCompletionRoutine: Urb.Hdr.Status - %x\n", Context->Urb.UrbHeader.Status); } // perform reset recovery Context->ErrorIndex = 2; - IoFreeIrp(Irp); Status = USBSTOR_QueueWorkItem(Context, NULL); ASSERT(Status == STATUS_MORE_PROCESSING_REQUIRED); return STATUS_MORE_PROCESSING_REQUIRED; } - if (!USBSTOR_IsCSWValid(Context)) + // now check the CSW packet validity + if (!USBSTOR_IsCSWValid(Context) || Context->csw->Status == CSW_STATUS_PHASE_ERROR) { // perform reset recovery Context->ErrorIndex = 2; - IoFreeIrp(Irp); Status = USBSTOR_QueueWorkItem(Context, NULL); ASSERT(Status == STATUS_MORE_PROCESSING_REQUIRED); return STATUS_MORE_PROCESSING_REQUIRED; } - - IoStack = IoGetCurrentIrpStackLocation(Context->Irp); - - Request = (PSCSI_REQUEST_BLOCK)IoStack->Parameters.Others.Argument1; + IoStack = IoGetCurrentIrpStackLocation(Irp); + Request = IoStack->Parameters.Scsi.Srb; ASSERT(Request); Status = Irp->IoStatus.Status; - pCDB = (PCDB)Request->Cdb; - Request->SrbStatus = SRB_STATUS_SUCCESS; - - // read capacity needs special work - if (pCDB->AsByte[0] == SCSIOP_READ_CAPACITY) + // finally check for CSW errors + if (Context->csw->Status == CSW_STATUS_COMMAND_PASSED) { - // get output buffer - Response = (PUFI_CAPACITY_RESPONSE)Context->TransferData; + // read capacity needs special work + if (Request->Cdb[0] == SCSIOP_READ_CAPACITY) + { + // get output buffer + Response = (PUFI_CAPACITY_RESPONSE)Context->TransferData; - // store in pdo - Context->PDODeviceExtension->BlockLength = NTOHL(Response->BlockLength); - Context->PDODeviceExtension->LastLogicBlockAddress = NTOHL(Response->LastLogicalBlockAddress); + // store in pdo + Context->PDODeviceExtension->BlockLength = NTOHL(Response->BlockLength); + Context->PDODeviceExtension->LastLogicBlockAddress = NTOHL(Response->LastLogicalBlockAddress); + } + + Status = STATUS_SUCCESS; + Request->SrbStatus = SRB_STATUS_SUCCESS; + Irp->IoStatus.Status = STATUS_SUCCESS; + Irp->IoStatus.Information = Request->DataTransferLength; + } + else if (Context->csw->Status == CSW_STATUS_COMMAND_FAILED) + { + DPRINT("USBSTOR_CSWCompletionRoutine: CSW_STATUS_COMMAND_FAILED\n"); + // perform reset recovery + Context->ErrorIndex = 2; + Status = USBSTOR_QueueWorkItem(Context, NULL); + ASSERT(Status == STATUS_MORE_PROCESSING_REQUIRED); + return STATUS_MORE_PROCESSING_REQUIRED; } FreeItem(Context->cbw); - // FIXME: check status - Context->Irp->IoStatus.Status = Irp->IoStatus.Status; - Context->Irp->IoStatus.Information = Context->TransferDataLength; - // terminate current request - USBSTOR_QueueTerminateRequest(Context->PDODeviceExtension->LowerDeviceObject, Context->Irp); - - IoCompleteRequest(Context->Irp, IO_NO_INCREMENT); - + USBSTOR_QueueTerminateRequest(Context->PDODeviceExtension->LowerDeviceObject, Irp); USBSTOR_QueueNextRequest(Context->PDODeviceExtension->LowerDeviceObject); - IoFreeIrp(Irp); FreeItem(Context); - return STATUS_MORE_PROCESSING_REQUIRED; + return Status; } VOID @@ -406,7 +401,6 @@ USBSTOR_SendRequest( PIRP_CONTEXT Context; PPDO_DEVICE_EXTENSION PDODeviceExtension; PFDO_DEVICE_EXTENSION FDODeviceExtension; - PIRP Irp; PUCHAR MdlVirtualAddress; Context = USBSTOR_AllocateIrpContext(); @@ -450,50 +444,34 @@ USBSTOR_SendRequest( if (Context->TransferDataLength) { // check if the original request already does have an mdl associated - if (OriginalRequest) + if ((OriginalRequest->MdlAddress != NULL) && + (Context->TransferData == NULL || Command[0] == SCSIOP_READ || Command[0] == SCSIOP_WRITE)) { - if ((OriginalRequest->MdlAddress != NULL) && - (Context->TransferData == NULL || Command[0] == SCSIOP_READ || Command[0] == SCSIOP_WRITE)) + // Sanity check that the Mdl does describe the TransferData for read/write + if (CommandLength == UFI_READ_WRITE_CMD_LEN) { - // Sanity check that the Mdl does describe the TransferData for read/write - if (CommandLength == UFI_READ_WRITE_CMD_LEN) - { - MdlVirtualAddress = MmGetMdlVirtualAddress(OriginalRequest->MdlAddress); + MdlVirtualAddress = MmGetMdlVirtualAddress(OriginalRequest->MdlAddress); - // is there an offset - if (MdlVirtualAddress != Context->TransferData) + // is there an offset + if (MdlVirtualAddress != Context->TransferData) + { + // lets build an mdl + Context->TransferBufferMDL = IoAllocateMdl(Context->TransferData, MmGetMdlByteCount(OriginalRequest->MdlAddress), FALSE, FALSE, NULL); + if (!Context->TransferBufferMDL) { - // lets build an mdl - Context->TransferBufferMDL = IoAllocateMdl(Context->TransferData, MmGetMdlByteCount(OriginalRequest->MdlAddress), FALSE, FALSE, NULL); - if (!Context->TransferBufferMDL) - { - FreeItem(Context->cbw); - FreeItem(Context); - return STATUS_INSUFFICIENT_RESOURCES; - } - - IoBuildPartialMdl(OriginalRequest->MdlAddress, Context->TransferBufferMDL, Context->TransferData, Context->TransferDataLength); + FreeItem(Context->cbw); + FreeItem(Context); + return STATUS_INSUFFICIENT_RESOURCES; } - } - if (!Context->TransferBufferMDL) - { - // I/O paging request - Context->TransferBufferMDL = OriginalRequest->MdlAddress; + IoBuildPartialMdl(OriginalRequest->MdlAddress, Context->TransferBufferMDL, Context->TransferData, Context->TransferDataLength); } } - else - { - // allocate mdl for buffer, buffer must be allocated from NonPagedPool - Context->TransferBufferMDL = IoAllocateMdl(Context->TransferData, Context->TransferDataLength, FALSE, FALSE, NULL); - if (!Context->TransferBufferMDL) - { - FreeItem(Context->cbw); - FreeItem(Context); - return STATUS_INSUFFICIENT_RESOURCES; - } - MmBuildMdlForNonPagedPool(Context->TransferBufferMDL); + if (!Context->TransferBufferMDL) + { + // I/O paging request + Context->TransferBufferMDL = OriginalRequest->MdlAddress; } } else @@ -511,22 +489,7 @@ USBSTOR_SendRequest( } } - Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE); - if (!Irp) - { - FreeItem(Context->cbw); - FreeItem(Context); - return STATUS_INSUFFICIENT_RESOURCES; - } - - if (OriginalRequest) - { - IoMarkIrpPending(OriginalRequest); - } - - USBSTOR_SendCBW(Context, Irp); - - return STATUS_PENDING; + return USBSTOR_SendCBW(Context, OriginalRequest); } NTSTATUS diff --git a/drivers/usb/usbstor/usbstor.h b/drivers/usb/usbstor/usbstor.h index f477e9a1a04..40b369bd15e 100644 --- a/drivers/usb/usbstor/usbstor.h +++ b/drivers/usb/usbstor/usbstor.h @@ -105,6 +105,10 @@ C_ASSERT(sizeof(CBW) == 31); #define MAX_LUN 0xF +#define CSW_STATUS_COMMAND_PASSED 0x00 +#define CSW_STATUS_COMMAND_FAILED 0x01 +#define CSW_STATUS_PHASE_ERROR 0x02 + typedef struct { ULONG Signature; // CSW signature
5 years, 6 months
1
0
0
0
[reactos] 02/17: [USBSTOR] Do not attempt additional processing of SCSI requests. Now the driver sends all requests transparently. Inspired by Vadim Galyant's patches to usbstor
by Victor Perevertkin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=b4c03399ba19cfc141dad…
commit b4c03399ba19cfc141dad9582a82ecf88549b760 Author: Victor Perevertkin <victor(a)perevertkin.ru> AuthorDate: Tue Mar 26 14:26:06 2019 +0300 Commit: Victor Perevertkin <victor(a)perevertkin.ru> CommitDate: Tue Jun 11 04:39:43 2019 +0300 [USBSTOR] Do not attempt additional processing of SCSI requests. Now the driver sends all requests transparently. Inspired by Vadim Galyant's patches to usbstor --- drivers/usb/usbstor/scsi.c | 436 +-------------------------------------------- 1 file changed, 5 insertions(+), 431 deletions(-) diff --git a/drivers/usb/usbstor/scsi.c b/drivers/usb/usbstor/scsi.c index 4c7c3efb7d7..b2989f01fce 100644 --- a/drivers/usb/usbstor/scsi.c +++ b/drivers/usb/usbstor/scsi.c @@ -129,8 +129,6 @@ USBSTOR_CSWCompletionRoutine( PIO_STACK_LOCATION IoStack; PSCSI_REQUEST_BLOCK Request; PCDB pCDB; - PREAD_CAPACITY_DATA_EX CapacityDataEx; - PREAD_CAPACITY_DATA CapacityData; PUFI_CAPACITY_RESPONSE Response; NTSTATUS Status; @@ -205,29 +203,6 @@ USBSTOR_CSWCompletionRoutine( // store in pdo Context->PDODeviceExtension->BlockLength = NTOHL(Response->BlockLength); Context->PDODeviceExtension->LastLogicBlockAddress = NTOHL(Response->LastLogicalBlockAddress); - - if (Request->DataTransferLength == sizeof(READ_CAPACITY_DATA_EX)) - { - // get input buffer - CapacityDataEx = (PREAD_CAPACITY_DATA_EX)Request->DataBuffer; - - // set result - CapacityDataEx->BytesPerBlock = Response->BlockLength; - CapacityDataEx->LogicalBlockAddress.QuadPart = Response->LastLogicalBlockAddress; - Irp->IoStatus.Information = sizeof(READ_CAPACITY_DATA_EX); - } - else - { - // get input buffer - CapacityData = (PREAD_CAPACITY_DATA)Request->DataBuffer; - - // set result - CapacityData->BytesPerBlock = Response->BlockLength; - CapacityData->LogicalBlockAddress = Response->LastLogicalBlockAddress; - Irp->IoStatus.Information = sizeof(READ_CAPACITY_DATA); - } - - FreeItem(Context->TransferData); } FreeItem(Context->cbw); @@ -554,350 +529,6 @@ USBSTOR_SendRequest( return STATUS_PENDING; } -NTSTATUS -USBSTOR_SendFormatCapacity( - IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp, - IN ULONG RetryCount) -{ - UFI_READ_FORMAT_CAPACITY Cmd; - PPDO_DEVICE_EXTENSION PDODeviceExtension; - PIO_STACK_LOCATION IoStack; - PSCSI_REQUEST_BLOCK Request; - - IoStack = IoGetCurrentIrpStackLocation(Irp); - PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - Request = (PSCSI_REQUEST_BLOCK)IoStack->Parameters.Others.Argument1; - - // initialize inquiry cmd - RtlZeroMemory(&Cmd, sizeof(UFI_READ_FORMAT_CAPACITY)); - Cmd.Code = SCSIOP_READ_FORMATTED_CAPACITY; - Cmd.LUN = (PDODeviceExtension->LUN & MAX_LUN); - Cmd.AllocationLengthMsb = HTONS(Request->DataTransferLength & 0xFFFF) >> 8; - Cmd.AllocationLengthLsb = HTONS(Request->DataTransferLength & 0xFFFF) & 0xFF; - - return USBSTOR_SendRequest(DeviceObject, Irp, UFI_READ_FORMAT_CAPACITY_CMD_LEN, (PUCHAR)&Cmd, Request->DataTransferLength, (PUCHAR)Request->DataBuffer, RetryCount); -} - -NTSTATUS -USBSTOR_SendInquiry( - IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp, - IN ULONG RetryCount) -{ - UFI_INQUIRY_CMD Cmd; - PPDO_DEVICE_EXTENSION PDODeviceExtension; - PIO_STACK_LOCATION IoStack; - PSCSI_REQUEST_BLOCK Request; - - IoStack = IoGetCurrentIrpStackLocation(Irp); - Request = (PSCSI_REQUEST_BLOCK)IoStack->Parameters.Others.Argument1; - PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - - // initialize inquiry cmd - RtlZeroMemory(&Cmd, sizeof(UFI_INQUIRY_CMD)); - Cmd.Code = SCSIOP_INQUIRY; - Cmd.LUN = (PDODeviceExtension->LUN & MAX_LUN); - Cmd.AllocationLength = sizeof(UFI_INQUIRY_RESPONSE); - - ASSERT(Request->DataTransferLength >= sizeof(UFI_INQUIRY_RESPONSE)); - - return USBSTOR_SendRequest(DeviceObject, Irp, UFI_INQUIRY_CMD_LEN, (PUCHAR)&Cmd, Request->DataTransferLength, (PUCHAR)Request->DataBuffer, RetryCount); -} - -NTSTATUS -USBSTOR_SendCapacity( - IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp, - IN ULONG RetryCount) -{ - UFI_CAPACITY_CMD Cmd; - PUFI_CAPACITY_RESPONSE Response; - PPDO_DEVICE_EXTENSION PDODeviceExtension; - - PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - - Response = (PUFI_CAPACITY_RESPONSE)AllocateItem(NonPagedPool, PAGE_SIZE); - if (!Response) - { - return STATUS_INSUFFICIENT_RESOURCES; - } - - // initialize capacity cmd - RtlZeroMemory(&Cmd, sizeof(UFI_INQUIRY_CMD)); - Cmd.Code = SCSIOP_READ_CAPACITY; - Cmd.LUN = (PDODeviceExtension->LUN & MAX_LUN); - - return USBSTOR_SendRequest(DeviceObject, Irp, UFI_READ_CAPACITY_CMD_LEN, (PUCHAR)&Cmd, sizeof(UFI_CAPACITY_RESPONSE), (PUCHAR)Response, RetryCount); -} - -NTSTATUS -USBSTOR_SendModeSense( - IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp, - IN ULONG RetryCount) -{ -#if 0 - UFI_SENSE_CMD Cmd; - NTSTATUS Status; - PVOID Response; - PCBW OutControl; - PCDB pCDB; - PUFI_MODE_PARAMETER_HEADER Header; -#endif - PPDO_DEVICE_EXTENSION PDODeviceExtension; - PIO_STACK_LOCATION IoStack; - PSCSI_REQUEST_BLOCK Request; - - PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - ASSERT(PDODeviceExtension->Common.IsFDO == FALSE); - - IoStack = IoGetCurrentIrpStackLocation(Irp); - Request = (PSCSI_REQUEST_BLOCK)IoStack->Parameters.Others.Argument1; - - RtlZeroMemory(Request->DataBuffer, Request->DataTransferLength); - Request->SrbStatus = SRB_STATUS_SUCCESS; - Irp->IoStatus.Information = Request->DataTransferLength; - Irp->IoStatus.Status = STATUS_SUCCESS; - USBSTOR_QueueTerminateRequest(PDODeviceExtension->LowerDeviceObject, Irp); - IoCompleteRequest(Irp, IO_NO_INCREMENT); - - USBSTOR_QueueNextRequest(PDODeviceExtension->LowerDeviceObject); - - return STATUS_SUCCESS; - -#if 0 - // - // get SCSI command data block - // - pCDB = (PCDB)Request->Cdb; - - // - // get PDO device extension - // - PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - - // - // allocate sense response from non paged pool - // - Response = (PUFI_CAPACITY_RESPONSE)AllocateItem(NonPagedPool, Request->DataTransferLength); - if (!Response) - { - // - // no memory - // - return STATUS_INSUFFICIENT_RESOURCES; - } - - // - // sanity check - // - - - // Supported pages - // MODE_PAGE_ERROR_RECOVERY - // MODE_PAGE_FLEXIBILE - // MODE_PAGE_LUN_MAPPING - // MODE_PAGE_FAULT_REPORTING - // MODE_SENSE_RETURN_ALL - - // - // initialize mode sense cmd - // - RtlZeroMemory(&Cmd, sizeof(UFI_INQUIRY_CMD)); - Cmd.Code = SCSIOP_MODE_SENSE; - Cmd.LUN = (PDODeviceExtension->LUN & MAX_LUN); - Cmd.PageCode = pCDB->MODE_SENSE.PageCode; - Cmd.PC = pCDB->MODE_SENSE.Pc; - Cmd.AllocationLength = HTONS(pCDB->MODE_SENSE.AllocationLength); - - DPRINT1("PageCode %x\n", pCDB->MODE_SENSE.PageCode); - DPRINT1("PC %x\n", pCDB->MODE_SENSE.Pc); - - // - // now send mode sense cmd - // - Status = USBSTOR_SendCBW(DeviceObject, UFI_SENSE_CMD_LEN, (PUCHAR)&Cmd, Request->DataTransferLength, &OutControl); - if (!NT_SUCCESS(Status)) - { - // - // failed to send CBW - // - DPRINT1("USBSTOR_SendCapacityCmd> USBSTOR_SendCBW failed with %x\n", Status); - FreeItem(Response); - ASSERT(FALSE); - return Status; - } - - // - // now send data block response - // - Status = USBSTOR_SendData(DeviceObject, Request->DataTransferLength, Response); - if (!NT_SUCCESS(Status)) - { - // - // failed to send CBW - // - DPRINT1("USBSTOR_SendCapacityCmd> USBSTOR_SendData failed with %x\n", Status); - FreeItem(Response); - ASSERT(FALSE); - return Status; - } - - Header = (PUFI_MODE_PARAMETER_HEADER)Response; - - // - // TODO: build layout - // - // first struct is the header - // MODE_PARAMETER_HEADER / _MODE_PARAMETER_HEADER10 - // - // followed by - // MODE_PARAMETER_BLOCK - // - // - UNIMPLEMENTED; - - // - // send csw - // - Status = USBSTOR_SendCSW(DeviceObject, OutControl, 512, &CSW); - - DPRINT1("------------------------\n"); - DPRINT1("CSW %p\n", &CSW); - DPRINT1("Signature %x\n", CSW.Signature); - DPRINT1("Tag %x\n", CSW.Tag); - DPRINT1("DataResidue %x\n", CSW.DataResidue); - DPRINT1("Status %x\n", CSW.Status); - - // - // FIXME: handle error - // - ASSERT(CSW.Status == 0); - ASSERT(CSW.DataResidue == 0); - - // - // calculate transfer length - // - *TransferBufferLength = Request->DataTransferLength - CSW.DataResidue; - - // - // copy buffer - // - RtlCopyMemory(Request->DataBuffer, Response, *TransferBufferLength); - - // - // free item - // - FreeItem(OutControl); - - // - // free response - // - FreeItem(Response); - - // - // done - // - return Status; -#endif -} - -NTSTATUS -USBSTOR_SendReadWrite( - IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp, - IN ULONG RetryCount) -{ - UFI_READ_WRITE_CMD Cmd; - PPDO_DEVICE_EXTENSION PDODeviceExtension; - PCDB pCDB; - ULONG BlockCount, Temp; - PIO_STACK_LOCATION IoStack; - PSCSI_REQUEST_BLOCK Request; - - IoStack = IoGetCurrentIrpStackLocation(Irp); - Request = (PSCSI_REQUEST_BLOCK)IoStack->Parameters.Others.Argument1; - - pCDB = (PCDB)Request->Cdb; - - PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - - DPRINT("USBSTOR_SendReadWrite DataTransferLength %lu, BlockLength %lu\n", Request->DataTransferLength, PDODeviceExtension->BlockLength); - - ASSERT(PDODeviceExtension->BlockLength); - - BlockCount = Request->DataTransferLength / PDODeviceExtension->BlockLength; - - // initialize read cmd - RtlZeroMemory(&Cmd, sizeof(UFI_READ_WRITE_CMD)); - Cmd.Code = pCDB->AsByte[0]; - Cmd.LUN = (PDODeviceExtension->LUN & MAX_LUN); - Cmd.ContiguousLogicBlocksByte0 = pCDB->CDB10.TransferBlocksMsb; - Cmd.ContiguousLogicBlocksByte1 = pCDB->CDB10.TransferBlocksLsb; - Cmd.LogicalBlockByte0 = pCDB->CDB10.LogicalBlockByte0; - Cmd.LogicalBlockByte1 = pCDB->CDB10.LogicalBlockByte1; - Cmd.LogicalBlockByte2 = pCDB->CDB10.LogicalBlockByte2; - Cmd.LogicalBlockByte3 = pCDB->CDB10.LogicalBlockByte3; - - Temp = (Cmd.ContiguousLogicBlocksByte0 << 8 | Cmd.ContiguousLogicBlocksByte1); - ASSERT(Temp == BlockCount); - - DPRINT("USBSTOR_SendReadWrite BlockAddress %x%x%x%x BlockCount %lu BlockLength %lu\n", Cmd.LogicalBlockByte0, Cmd.LogicalBlockByte1, Cmd.LogicalBlockByte2, Cmd.LogicalBlockByte3, BlockCount, PDODeviceExtension->BlockLength); - - return USBSTOR_SendRequest(DeviceObject, Irp, UFI_READ_WRITE_CMD_LEN, (PUCHAR)&Cmd, Request->DataTransferLength, (PUCHAR)Request->DataBuffer, RetryCount); -} - -NTSTATUS -USBSTOR_SendTestUnit( - IN PDEVICE_OBJECT DeviceObject, - IN OUT PIRP Irp, - IN ULONG RetryCount) -{ - UFI_TEST_UNIT_CMD Cmd; - PPDO_DEVICE_EXTENSION PDODeviceExtension; - PIO_STACK_LOCATION IoStack; - PSCSI_REQUEST_BLOCK Request; - - IoStack = IoGetCurrentIrpStackLocation(Irp); - Request = (PSCSI_REQUEST_BLOCK)IoStack->Parameters.Others.Argument1; - - ASSERT(Request->DataTransferLength == 0); - - PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - - // initialize test unit cmd - RtlZeroMemory(&Cmd, sizeof(UFI_TEST_UNIT_CMD)); - Cmd.Code = SCSIOP_TEST_UNIT_READY; - Cmd.LUN = (PDODeviceExtension->LUN & MAX_LUN); - - return USBSTOR_SendRequest(DeviceObject, Irp, UFI_TEST_UNIT_CMD_LEN, (PUCHAR)&Cmd, 0, NULL, RetryCount); -} - -NTSTATUS -USBSTOR_SendUnknownRequest( - IN PDEVICE_OBJECT DeviceObject, - IN OUT PIRP Irp, - IN ULONG RetryCount) -{ - PPDO_DEVICE_EXTENSION PDODeviceExtension; - PIO_STACK_LOCATION IoStack; - PSCSI_REQUEST_BLOCK Request; - UFI_UNKNOWN_CMD Cmd; - - IoStack = IoGetCurrentIrpStackLocation(Irp); - Request = IoStack->Parameters.Others.Argument1; - PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - - // check that we're sending to the right LUN - ASSERT(Request->Cdb[1] == (PDODeviceExtension->LUN & MAX_LUN)); - ASSERT(Request->CdbLength <= sizeof(UFI_UNKNOWN_CMD)); - - RtlCopyMemory(&Cmd, Request->Cdb, Request->CdbLength); - - return USBSTOR_SendRequest(DeviceObject, Irp, Request->CdbLength, (PUCHAR)&Cmd, Request->DataTransferLength, Request->DataBuffer, RetryCount); -} - NTSTATUS USBSTOR_HandleExecuteSCSI( IN PDEVICE_OBJECT DeviceObject, @@ -914,71 +545,14 @@ USBSTOR_HandleExecuteSCSI( ASSERT(PDODeviceExtension->Common.IsFDO == FALSE); IoStack = IoGetCurrentIrpStackLocation(Irp); - Request = (PSCSI_REQUEST_BLOCK)IoStack->Parameters.Others.Argument1; + Request = IoStack->Parameters.Scsi.Srb; pCDB = (PCDB)Request->Cdb; - DPRINT("USBSTOR_HandleExecuteSCSI Operation Code %x\n", pCDB->AsByte[0]); - - if (pCDB->AsByte[0] == SCSIOP_READ_CAPACITY) - { - ASSERT(Request->DataBuffer); - - DPRINT("SCSIOP_READ_CAPACITY Length %lu\n", Request->DataTransferLength); - Status = USBSTOR_SendCapacity(DeviceObject, Irp, RetryCount); - } - else if (pCDB->MODE_SENSE.OperationCode == SCSIOP_MODE_SENSE) - { - DPRINT("SCSIOP_MODE_SENSE DataTransferLength %lu\n", Request->DataTransferLength); - ASSERT(pCDB->MODE_SENSE.AllocationLength == Request->DataTransferLength); - ASSERT(Request->DataBuffer); - - Status = USBSTOR_SendModeSense(DeviceObject, Irp, RetryCount); - } - else if (pCDB->AsByte[0] == SCSIOP_READ_FORMATTED_CAPACITY) - { - DPRINT("SCSIOP_READ_FORMATTED_CAPACITY DataTransferLength %lu\n", Request->DataTransferLength); - - Status = USBSTOR_SendFormatCapacity(DeviceObject, Irp, RetryCount); - } - else if (pCDB->AsByte[0] == SCSIOP_INQUIRY) - { - DPRINT("SCSIOP_INQUIRY DataTransferLength %lu\n", Request->DataTransferLength); - - Status = USBSTOR_SendInquiry(DeviceObject, Irp, RetryCount); - } - else if (pCDB->MODE_SENSE.OperationCode == SCSIOP_READ || pCDB->MODE_SENSE.OperationCode == SCSIOP_WRITE) - { - DPRINT("SCSIOP_READ / SCSIOP_WRITE DataTransferLength %lu\n", Request->DataTransferLength); - - Status = USBSTOR_SendReadWrite(DeviceObject, Irp, RetryCount); - } - else if (pCDB->AsByte[0] == SCSIOP_MEDIUM_REMOVAL) - { - DPRINT("SCSIOP_MEDIUM_REMOVAL\n"); - - // just complete the request - Request->SrbStatus = SRB_STATUS_SUCCESS; - Irp->IoStatus.Status = STATUS_SUCCESS; - Irp->IoStatus.Information = Request->DataTransferLength; - USBSTOR_QueueTerminateRequest(PDODeviceExtension->LowerDeviceObject, Irp); - IoCompleteRequest(Irp, IO_NO_INCREMENT); - - USBSTOR_QueueNextRequest(PDODeviceExtension->LowerDeviceObject); - - return STATUS_SUCCESS; - } - else if (pCDB->MODE_SENSE.OperationCode == SCSIOP_TEST_UNIT_READY) - { - DPRINT("SCSIOP_TEST_UNIT_READY\n"); + DPRINT("USBSTOR_HandleExecuteSCSI Operation Code %x, Length %lu\n", pCDB->CDB10.OperationCode, Request->DataTransferLength); - Status = USBSTOR_SendTestUnit(DeviceObject, Irp, RetryCount); - } - else - { - // Unknown request. Simply forward - DPRINT1("Forwarding unknown Operation Code %x\n", pCDB->AsByte[0]); - Status = USBSTOR_SendUnknownRequest(DeviceObject, Irp, RetryCount); - } + // check that we're sending to the right LUN + ASSERT(pCDB->CDB10.LogicalUnitNumber == (PDODeviceExtension->LUN & MAX_LUN)); + Status = USBSTOR_SendRequest(DeviceObject, Irp, Request->CdbLength, (PUCHAR)pCDB, Request->DataTransferLength, Request->DataBuffer, RetryCount); return Status; }
5 years, 6 months
1
0
0
0
[reactos] 01/17: [FORMATTING][USBSTOR] Remove Captain Obvious and line-wasting comments. Now the driver conforms with our current Coding Style. No functional changes
by Victor Perevertkin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=d17d15ab6c2048f0ac3fa…
commit d17d15ab6c2048f0ac3fa6f427f82fc2d243f528 Author: Victor Perevertkin <victor(a)perevertkin.ru> AuthorDate: Sun Mar 24 23:01:43 2019 +0300 Commit: Victor Perevertkin <victor(a)perevertkin.ru> CommitDate: Tue Jun 11 04:39:43 2019 +0300 [FORMATTING][USBSTOR] Remove Captain Obvious and line-wasting comments. Now the driver conforms with our current Coding Style. No functional changes --- drivers/usb/usbstor/descriptor.c | 234 ++----------------- drivers/usb/usbstor/disk.c | 437 ++++++++++------------------------- drivers/usb/usbstor/error.c | 138 +---------- drivers/usb/usbstor/fdo.c | 269 ++++++--------------- drivers/usb/usbstor/misc.c | 219 +----------------- drivers/usb/usbstor/pdo.c | 487 +-------------------------------------- drivers/usb/usbstor/queue.c | 325 +------------------------- drivers/usb/usbstor/scsi.c | 457 +----------------------------------- drivers/usb/usbstor/usbstor.c | 118 +--------- 9 files changed, 258 insertions(+), 2426 deletions(-) diff --git a/drivers/usb/usbstor/descriptor.c b/drivers/usb/usbstor/descriptor.c index 3df36a671cc..885cc7f6b72 100644 --- a/drivers/usb/usbstor/descriptor.c +++ b/drivers/usb/usbstor/descriptor.c @@ -1,12 +1,10 @@ /* * PROJECT: ReactOS Universal Serial Bus Bulk Storage Driver - * LICENSE: GPL - See COPYING in the top level directory - * FILE: drivers/usb/usbstor/descriptor.c + * LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later
) * PURPOSE: USB block storage device driver. - * PROGRAMMERS: - * James Tabor - * Michael Martin (michael.martin(a)reactos.org) - * Johannes Anderwald (johannes.anderwald(a)reactos.org) + * COPYRIGHT: 2005-2006 James Tabor + * 2011-2012 Michael Martin (michael.martin(a)reactos.org) + * 2011-2013 Johannes Anderwald (johannes.anderwald(a)reactos.org) */ #include "usbstor.h" @@ -14,6 +12,7 @@ #define NDEBUG #include <debug.h> + NTSTATUS NTAPI USBSTOR_GetDescriptor( @@ -28,41 +27,27 @@ USBSTOR_GetDescriptor( NTSTATUS Status; PVOID Descriptor; - // - // sanity checks - // ASSERT(DeviceObject); ASSERT(OutDescriptor); ASSERT(DescriptorLength); - // // first allocate descriptor buffer - // Descriptor = AllocateItem(NonPagedPool, DescriptorLength); if (!Descriptor) { - // // no memory - // return STATUS_INSUFFICIENT_RESOURCES; } - // - // allocate urb - // Urb = (PURB) AllocateItem(NonPagedPool, sizeof(URB)); if (!Urb) { - // // no memory - // FreeItem(Descriptor); return STATUS_INSUFFICIENT_RESOURCES; } - // // initialize urb - // UsbBuildGetDescriptorRequest(Urb, sizeof(Urb->UrbControlDescriptorRequest), DescriptorType, @@ -73,31 +58,19 @@ USBSTOR_GetDescriptor( DescriptorLength, NULL); - // // submit urb - // Status = USBSTOR_SyncUrbRequest(DeviceObject, Urb); - // - // free urb - // FreeItem(Urb); if (NT_SUCCESS(Status)) { - // - // store result - // *OutDescriptor = Descriptor; } - // - // done - // return Status; } - NTSTATUS USBSTOR_GetDescriptors( IN PDEVICE_OBJECT DeviceObject) @@ -106,89 +79,54 @@ USBSTOR_GetDescriptors( PFDO_DEVICE_EXTENSION DeviceExtension; USHORT DescriptorLength; - // - // get device extension - // DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - // // first get device descriptor - // Status = USBSTOR_GetDescriptor(DeviceExtension->LowerDeviceObject, USB_DEVICE_DESCRIPTOR_TYPE, sizeof(USB_DEVICE_DESCRIPTOR), 0, 0, (PVOID*)&DeviceExtension->DeviceDescriptor); if (!NT_SUCCESS(Status)) { - // - // failed to get device descriptor - // DeviceExtension->DeviceDescriptor = NULL; return Status; } - // // now get basic configuration descriptor - // Status = USBSTOR_GetDescriptor(DeviceExtension->LowerDeviceObject, USB_CONFIGURATION_DESCRIPTOR_TYPE, sizeof(USB_CONFIGURATION_DESCRIPTOR), 0, 0, (PVOID*)&DeviceExtension->ConfigurationDescriptor); if (!NT_SUCCESS(Status)) { - // - // failed to get configuration descriptor - // FreeItem(DeviceExtension->DeviceDescriptor); DeviceExtension->DeviceDescriptor = NULL; return Status; } - // // backup length - // DescriptorLength = DeviceExtension->ConfigurationDescriptor->wTotalLength; - // // release basic descriptor - // FreeItem(DeviceExtension->ConfigurationDescriptor); DeviceExtension->ConfigurationDescriptor = NULL; - // // allocate full descriptor - // Status = USBSTOR_GetDescriptor(DeviceExtension->LowerDeviceObject, USB_CONFIGURATION_DESCRIPTOR_TYPE, DescriptorLength, 0, 0, (PVOID*)&DeviceExtension->ConfigurationDescriptor); if (!NT_SUCCESS(Status)) { - // - // failed to get configuration descriptor - // FreeItem(DeviceExtension->DeviceDescriptor); DeviceExtension->DeviceDescriptor = NULL; return Status; } - // // check if there is a serial number provided - // if (DeviceExtension->DeviceDescriptor->iSerialNumber) { - // // get serial number - // Status = USBSTOR_GetDescriptor(DeviceExtension->LowerDeviceObject, USB_STRING_DESCRIPTOR_TYPE, 100 * sizeof(WCHAR), DeviceExtension->DeviceDescriptor->iSerialNumber, 0x0409, (PVOID*)&DeviceExtension->SerialNumber); if (!NT_SUCCESS(Status)) { - // - // failed to get serial number descriptor, free device descriptor - // FreeItem(DeviceExtension->DeviceDescriptor); DeviceExtension->DeviceDescriptor = NULL; - // - // free configuration descriptor - // FreeItem(DeviceExtension->ConfigurationDescriptor); DeviceExtension->ConfigurationDescriptor = NULL; - // - // set serial number to zero - // DeviceExtension->SerialNumber = NULL; return Status; } @@ -201,133 +139,80 @@ NTSTATUS NTAPI USBSTOR_ScanConfigurationDescriptor( IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, - OUT PUSB_INTERFACE_DESCRIPTOR * OutInterfaceDescriptor, - OUT PUSB_ENDPOINT_DESCRIPTOR * InEndpointDescriptor, - OUT PUSB_ENDPOINT_DESCRIPTOR * OutEndpointDescriptor) + OUT PUSB_INTERFACE_DESCRIPTOR *OutInterfaceDescriptor, + OUT PUSB_ENDPOINT_DESCRIPTOR *InEndpointDescriptor, + OUT PUSB_ENDPOINT_DESCRIPTOR *OutEndpointDescriptor) { PUSB_CONFIGURATION_DESCRIPTOR CurrentDescriptor; PUSB_ENDPOINT_DESCRIPTOR EndpointDescriptor; - // - // sanity checks - // ASSERT(ConfigurationDescriptor); ASSERT(OutInterfaceDescriptor); ASSERT(InEndpointDescriptor); ASSERT(OutEndpointDescriptor); - // - // nullify pointers - // *OutInterfaceDescriptor = NULL; *InEndpointDescriptor = NULL; *OutEndpointDescriptor = NULL; - // // start scanning - // CurrentDescriptor = ConfigurationDescriptor; do { - // - // check current descriptor type - // if (CurrentDescriptor->bDescriptorType == USB_INTERFACE_DESCRIPTOR_TYPE) { - // - // found interface descriptor - // if (*OutInterfaceDescriptor) { - // // we only process the first interface descriptor as ms does -> see documentation - // break; } - // // store interface descriptor - // *OutInterfaceDescriptor = (PUSB_INTERFACE_DESCRIPTOR)CurrentDescriptor; } else if (CurrentDescriptor->bDescriptorType == USB_ENDPOINT_DESCRIPTOR_TYPE) { - // - // convert to endpoint descriptor - // EndpointDescriptor = (PUSB_ENDPOINT_DESCRIPTOR)CurrentDescriptor; - // - // sanity check - // ASSERT(*OutInterfaceDescriptor); - // // get endpoint type - // if ((EndpointDescriptor->bmAttributes & USB_ENDPOINT_TYPE_MASK) == USB_ENDPOINT_TYPE_BULK) { - // - // bulk endpoint type - // - if (USB_ENDPOINT_DIRECTION_IN(EndpointDescriptor->bEndpointAddress)) - { - // - // bulk in - // - *InEndpointDescriptor = EndpointDescriptor; - } - else - { - // - // bulk out - // - *OutEndpointDescriptor = EndpointDescriptor; - } + if (USB_ENDPOINT_DIRECTION_IN(EndpointDescriptor->bEndpointAddress)) + { + *InEndpointDescriptor = EndpointDescriptor; + } + else + { + *OutEndpointDescriptor = EndpointDescriptor; + } } else if ((EndpointDescriptor->bmAttributes & USB_ENDPOINT_TYPE_MASK) == USB_ENDPOINT_TYPE_INTERRUPT) { - // - // interrupt endpoint type - // - UNIMPLEMENTED; + UNIMPLEMENTED; } } - // // move to next descriptor - // CurrentDescriptor = (PUSB_CONFIGURATION_DESCRIPTOR)((ULONG_PTR)CurrentDescriptor + CurrentDescriptor->bLength); - // // was it the last descriptor - // if ((ULONG_PTR)CurrentDescriptor >= ((ULONG_PTR)ConfigurationDescriptor + ConfigurationDescriptor->wTotalLength)) { - // - // reached last descriptor - // break; } - }while(TRUE); + } while(TRUE); - // // check if everything has been found - // if (*OutInterfaceDescriptor == NULL || *InEndpointDescriptor == NULL || *OutEndpointDescriptor == NULL) { - // - // failed to find interface / endpoint descriptor - // DPRINT1("USBSTOR_ScanConfigurationDescriptor: Failed to find InterfaceDescriptor %p InEndpointDescriptor %p OutEndpointDescriptor %p\n", *OutInterfaceDescriptor, *InEndpointDescriptor, *OutEndpointDescriptor); return STATUS_UNSUCCESSFUL; } - // - // completed successfully - // return STATUS_SUCCESS; } @@ -356,128 +241,77 @@ USBSTOR_SelectConfigurationAndInterface( PURB Urb; PUSBD_INTERFACE_LIST_ENTRY InterfaceList; - // - // now scan configuration descriptors - // Status = USBSTOR_ScanConfigurationDescriptor(DeviceExtension->ConfigurationDescriptor, &InterfaceDescriptor, &InEndpointDescriptor, &OutEndpointDescriptor); if (!NT_SUCCESS(Status)) { - // - // failed to scan - // return Status; } - // // now allocate one interface entry and terminating null entry - // InterfaceList = (PUSBD_INTERFACE_LIST_ENTRY)AllocateItem(PagedPool, sizeof(USBD_INTERFACE_LIST_ENTRY) * 2); if (!InterfaceList) { - // - // no memory - // return STATUS_INSUFFICIENT_RESOURCES; } - // // initialize interface list entry - // InterfaceList[0].InterfaceDescriptor = InterfaceDescriptor; - // // now allocate the urb - // Urb = USBD_CreateConfigurationRequestEx(DeviceExtension->ConfigurationDescriptor, InterfaceList); if (!Urb) { - // - // no memory - // FreeItem(InterfaceList); return STATUS_INSUFFICIENT_RESOURCES; } - // - // sanity check - // + ASSERT(InterfaceList[0].Interface); - // // submit urb - // Status = USBSTOR_SyncUrbRequest(DeviceExtension->LowerDeviceObject, Urb); if (!NT_SUCCESS(Status)) { - // // failed to set configuration - // DPRINT1("USBSTOR_SelectConfiguration failed to set interface %x\n", Status); FreeItem(InterfaceList); ExFreePoolWithTag(Urb, 0); return Status; } - // // backup interface information - // DeviceExtension->InterfaceInformation = (PUSBD_INTERFACE_INFORMATION)AllocateItem(NonPagedPool, Urb->UrbSelectConfiguration.Interface.Length); if (!DeviceExtension->InterfaceInformation) { - // - // failed to allocate interface information structure - // FreeItem(InterfaceList); ExFreePoolWithTag(Urb, 0); return STATUS_INSUFFICIENT_RESOURCES; } - // // copy interface information - // RtlCopyMemory(DeviceExtension->InterfaceInformation, &Urb->UrbSelectConfiguration.Interface, Urb->UrbSelectConfiguration.Interface.Length); - // // store pipe handle - // DeviceExtension->ConfigurationHandle = Urb->UrbSelectConfiguration.ConfigurationHandle; - // // now prepare interface urb - // UsbBuildSelectInterfaceRequest(Urb, GET_SELECT_INTERFACE_REQUEST_SIZE(InterfaceDescriptor->bNumEndpoints), DeviceExtension->ConfigurationHandle, InterfaceDescriptor->bInterfaceNumber, InterfaceDescriptor->bAlternateSetting); - // // copy interface information structure back - as offset for SelectConfiguration / SelectInterface request do differ - // RtlCopyMemory(&Urb->UrbSelectInterface.Interface, DeviceExtension->InterfaceInformation, DeviceExtension->InterfaceInformation->Length); - // // now select the interface - // Status = USBSTOR_SyncUrbRequest(DeviceExtension->LowerDeviceObject, Urb); - - // - // did it succeed - // if (NT_SUCCESS(Status)) { - // // update configuration info - // ASSERT(Urb->UrbSelectInterface.Interface.Length == DeviceExtension->InterfaceInformation->Length); RtlCopyMemory(DeviceExtension->InterfaceInformation, &Urb->UrbSelectInterface.Interface, Urb->UrbSelectInterface.Interface.Length); } - // - // free interface list & urb - // FreeItem(InterfaceList); ExFreePoolWithTag(Urb, 0); - // - // done - // return Status; } @@ -488,62 +322,36 @@ USBSTOR_GetPipeHandles( ULONG Index; BOOLEAN BulkInFound = FALSE, BulkOutFound = FALSE; - // - // no enumerate all pipes and extract bulk-in / bulk-out pipe handle - // - for(Index = 0; Index < DeviceExtension->InterfaceInformation->NumberOfPipes; Index++) + // enumerate all pipes and extract bulk-in / bulk-out pipe handle + for (Index = 0; Index < DeviceExtension->InterfaceInformation->NumberOfPipes; Index++) { - // - // check pipe type - // if (DeviceExtension->InterfaceInformation->Pipes[Index].PipeType == UsbdPipeTypeBulk) { - // - // check direction - // if (USB_ENDPOINT_DIRECTION_IN(DeviceExtension->InterfaceInformation->Pipes[Index].EndpointAddress)) { - // - // bulk in pipe - // DeviceExtension->BulkInPipeIndex = Index; - // // there should not be another bulk in pipe - // ASSERT(BulkInFound == FALSE); BulkInFound = TRUE; } else { - // - // bulk out pipe - // DeviceExtension->BulkOutPipeIndex = Index; - // // there should not be another bulk out pipe - // ASSERT(BulkOutFound == FALSE); BulkOutFound = TRUE; } } } - // - // check if both bulk pipes have been found - // if (!BulkInFound || !BulkOutFound) { - // // WTF? usb port driver does not give us bulk pipe access - // DPRINT1("USBSTOR_GetPipeHandles> BulkInFound %c BulkOutFound %c missing!!!\n", BulkInFound, BulkOutFound); return STATUS_DEVICE_CONFIGURATION_ERROR; } - // - // device is configured - // return STATUS_SUCCESS; } diff --git a/drivers/usb/usbstor/disk.c b/drivers/usb/usbstor/disk.c index 7dc4438cdc4..cf9c0380136 100644 --- a/drivers/usb/usbstor/disk.c +++ b/drivers/usb/usbstor/disk.c @@ -1,12 +1,10 @@ /* * PROJECT: ReactOS Universal Serial Bus Bulk Storage Driver - * LICENSE: GPL - See COPYING in the top level directory - * FILE: drivers/usb/usbstor/disk.c + * LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later
) * PURPOSE: USB block storage device driver. - * PROGRAMMERS: - * James Tabor - * Michael Martin (michael.martin(a)reactos.org) - * Johannes Anderwald (johannes.anderwald(a)reactos.org) + * COPYRIGHT: 2005-2006 James Tabor + * 2011-2012 Michael Martin (michael.martin(a)reactos.org) + * 2011-2013 Johannes Anderwald (johannes.anderwald(a)reactos.org) */ #include "usbstor.h" @@ -14,6 +12,7 @@ #define NDEBUG #include <debug.h> + NTSTATUS USBSTOR_HandleInternalDeviceControl( IN PDEVICE_OBJECT DeviceObject, @@ -24,29 +23,10 @@ USBSTOR_HandleInternalDeviceControl( PPDO_DEVICE_EXTENSION PDODeviceExtension; NTSTATUS Status; - // - // get current stack location - // IoStack = IoGetCurrentIrpStackLocation(Irp); - - // - // get request block - // Request = (PSCSI_REQUEST_BLOCK)IoStack->Parameters.Others.Argument1; - - // - // sanity check - // ASSERT(Request); - - // - // get device extension - // PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - - // - // sanity check - // ASSERT(PDODeviceExtension->Common.IsFDO == FALSE); switch(Request->Function) @@ -55,69 +35,42 @@ USBSTOR_HandleInternalDeviceControl( { DPRINT("SRB_FUNCTION_EXECUTE_SCSI\n"); - // // check if request is valid - // if (Request->SrbFlags & (SRB_FLAGS_DATA_IN | SRB_FLAGS_DATA_OUT)) { - // // data is transferred with this irp - // if ((Request->SrbFlags & (SRB_FLAGS_DATA_IN | SRB_FLAGS_DATA_OUT)) == (SRB_FLAGS_DATA_IN | SRB_FLAGS_DATA_OUT) || Request->DataTransferLength == 0 || Irp->MdlAddress == NULL) { - // - // invalid parameter - // Status = STATUS_INVALID_PARAMETER; break; } } else { - // // sense buffer request - // - if (Request->DataTransferLength || - Request->DataBuffer || - Irp->MdlAddress) + if (Request->DataTransferLength || Request->DataBuffer || Irp->MdlAddress) { - // - // invalid parameter - // Status = STATUS_INVALID_PARAMETER; break; } } - // // add the request - // if (!USBSTOR_QueueAddIrp(PDODeviceExtension->LowerDeviceObject, Irp)) { - // - // irp was not added to the queue - // IoStartPacket(PDODeviceExtension->LowerDeviceObject, Irp, &Request->QueueSortKey, USBSTOR_CancelIo); } - // - // irp pending - // return STATUS_PENDING; } case SRB_FUNCTION_RELEASE_DEVICE: { DPRINT1("SRB_FUNCTION_RELEASE_DEVICE\n"); - // - // sanity check - // ASSERT(PDODeviceExtension->Claimed == TRUE); - // // release claim - // PDODeviceExtension->Claimed = FALSE; Status = STATUS_SUCCESS; break; @@ -125,32 +78,22 @@ USBSTOR_HandleInternalDeviceControl( case SRB_FUNCTION_CLAIM_DEVICE: { DPRINT1("SRB_FUNCTION_CLAIM_DEVICE\n"); - // + // check if the device has been claimed - // if (PDODeviceExtension->Claimed) { - // // device has already been claimed - // Status = STATUS_DEVICE_BUSY; Request->SrbStatus = SRB_STATUS_BUSY; break; } - // // claim device - // PDODeviceExtension->Claimed = TRUE; - // // output device object - // Request->DataBuffer = DeviceObject; - // - // completed successfully - // Status = STATUS_SUCCESS; break; } @@ -158,14 +101,8 @@ USBSTOR_HandleInternalDeviceControl( { DPRINT1("SRB_FUNCTION_RELEASE_QUEUE\n"); - // - // release queue - // USBSTOR_QueueRelease(PDODeviceExtension->LowerDeviceObject); - // - // set status success - // Request->SrbStatus = SRB_STATUS_SUCCESS; Status = STATUS_SUCCESS; break; @@ -184,9 +121,7 @@ USBSTOR_HandleInternalDeviceControl( // USBSTOR_QueueWaitForPendingRequests(PDODeviceExtension->LowerDeviceObject); #endif - // - // set status success - // + Request->SrbStatus = SRB_STATUS_SUCCESS; Status = STATUS_SUCCESS; break; @@ -201,9 +136,6 @@ USBSTOR_HandleInternalDeviceControl( } } - // - // complete request - // Irp->IoStatus.Status = Status; IoCompleteRequest(Irp, IO_NO_INCREMENT); return Status; @@ -217,23 +149,17 @@ USBSTOR_GetFieldLength( ULONG Index; ULONG LastCharacterPosition = 0; - // // scan the field and return last position which contains a valid character - // for(Index = 0; Index < MaxLength; Index++) { if (Name[Index] != ' ') { - // // trim white spaces from field - // LastCharacterPosition = Index; } } - // // convert from zero based index to length - // return LastCharacterPosition + 1; } @@ -258,125 +184,75 @@ USBSTOR_HandleQueryProperty( DPRINT("USBSTOR_HandleQueryProperty\n"); - // - // get current stack location - // IoStack = IoGetCurrentIrpStackLocation(Irp); - - // - // sanity check - // ASSERT(IoStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(STORAGE_PROPERTY_QUERY)); ASSERT(Irp->AssociatedIrp.SystemBuffer); - // - // get property query - // PropertyQuery = (PSTORAGE_PROPERTY_QUERY)Irp->AssociatedIrp.SystemBuffer; - // // check property type - // if (PropertyQuery->PropertyId != StorageDeviceProperty && PropertyQuery->PropertyId != StorageAdapterProperty) { - // // only device property / adapter property are supported - // return STATUS_INVALID_PARAMETER_1; } - // // check query type - // if (PropertyQuery->QueryType == PropertyExistsQuery) { - // // device property / adapter property is supported - // return STATUS_SUCCESS; } if (PropertyQuery->QueryType != PropertyStandardQuery) { - // // only standard query and exists query are supported - // return STATUS_INVALID_PARAMETER_2; } - // // check if it is a device property - // if (PropertyQuery->PropertyId == StorageDeviceProperty) { DPRINT("USBSTOR_HandleQueryProperty StorageDeviceProperty OutputBufferLength %lu\n", IoStack->Parameters.DeviceIoControl.OutputBufferLength); - // - // get device extension - // PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; ASSERT(PDODeviceExtension); ASSERT(PDODeviceExtension->Common.IsFDO == FALSE); - // - // get device extension - // FDODeviceExtension = (PFDO_DEVICE_EXTENSION)PDODeviceExtension->LowerDeviceObject->DeviceExtension; ASSERT(FDODeviceExtension); ASSERT(FDODeviceExtension->Common.IsFDO); - // - // get inquiry data - // InquiryData = (PUFI_INQUIRY_RESPONSE)PDODeviceExtension->InquiryData; ASSERT(InquiryData); - // // compute extra parameters length - // FieldLengthVendor = USBSTOR_GetFieldLength(InquiryData->Vendor, 8); FieldLengthProduct = USBSTOR_GetFieldLength(InquiryData->Product, 16); FieldLengthRevision = USBSTOR_GetFieldLength(InquiryData->Revision, 4); - // - // is there a serial number - // if (FDODeviceExtension->SerialNumber) { - // - // get length - // FieldLengthSerialNumber = wcslen(FDODeviceExtension->SerialNumber->bString); } else { - // - // no serial number - // FieldLengthSerialNumber = 0; } - // // total length required is sizeof(STORAGE_DEVICE_DESCRIPTOR) + FieldLength + 4 extra null bytes - 1 // -1 due STORAGE_DEVICE_DESCRIPTOR contains one byte length of parameter data - // TotalLength = sizeof(STORAGE_DEVICE_DESCRIPTOR) + FieldLengthVendor + FieldLengthProduct + FieldLengthRevision + FieldLengthSerialNumber + 3; - // // check if output buffer is long enough - // if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < TotalLength) { - // // buffer too small - // DescriptorHeader = (PSTORAGE_DESCRIPTOR_HEADER)Irp->AssociatedIrp.SystemBuffer; ASSERT(IoStack->Parameters.DeviceIoControl.OutputBufferLength >= sizeof(STORAGE_DESCRIPTOR_HEADER)); - // // return required size - // DescriptorHeader->Version = TotalLength; DescriptorHeader->Size = TotalLength; @@ -384,14 +260,9 @@ USBSTOR_HandleQueryProperty( return STATUS_SUCCESS; } - // - // get device descriptor - // + // initialize the device descriptor DeviceDescriptor = (PSTORAGE_DEVICE_DESCRIPTOR)Irp->AssociatedIrp.SystemBuffer; - // - // initialize device descriptor - // DeviceDescriptor->Version = TotalLength; DeviceDescriptor->Size = TotalLength; DeviceDescriptor->DeviceType = InquiryData->DeviceType; @@ -405,86 +276,54 @@ USBSTOR_HandleQueryProperty( DeviceDescriptor->SerialNumberOffset = (FieldLengthSerialNumber > 0 ? DeviceDescriptor->ProductRevisionOffset + FieldLengthRevision + 1 : 0); DeviceDescriptor->RawPropertiesLength = FieldLengthVendor + FieldLengthProduct + FieldLengthRevision + FieldLengthSerialNumber + 3 + (FieldLengthSerialNumber > 0 ? + 1 : 0); - // // copy descriptors - // Buffer = (PUCHAR)((ULONG_PTR)DeviceDescriptor + sizeof(STORAGE_DEVICE_DESCRIPTOR) - sizeof(UCHAR)); - // - // copy vendor - // RtlCopyMemory(Buffer, InquiryData->Vendor, FieldLengthVendor); Buffer[FieldLengthVendor] = '\0'; Buffer += FieldLengthVendor + 1; - // - // copy product - // RtlCopyMemory(Buffer, InquiryData->Product, FieldLengthProduct); Buffer[FieldLengthProduct] = '\0'; Buffer += FieldLengthProduct + 1; - // - // copy revision - // RtlCopyMemory(Buffer, InquiryData->Revision, FieldLengthRevision); Buffer[FieldLengthRevision] = '\0'; Buffer += FieldLengthRevision + 1; - // - // copy serial number - // if (FieldLengthSerialNumber) { - // - // init unicode string - // RtlInitUnicodeString(&SerialNumber, FDODeviceExtension->SerialNumber->bString); - // - // init ansi string - // AnsiString.Buffer = (PCHAR)Buffer; AnsiString.Length = 0; AnsiString.MaximumLength = FieldLengthSerialNumber * sizeof(WCHAR); - // - // convert to ansi code - // Status = RtlUnicodeStringToAnsiString(&AnsiString, &SerialNumber, FALSE); ASSERT(Status == STATUS_SUCCESS); } - DPRINT("Vendor %s\n", (LPCSTR)((ULONG_PTR)DeviceDescriptor + DeviceDescriptor->VendorIdOffset)); DPRINT("Product %s\n", (LPCSTR)((ULONG_PTR)DeviceDescriptor + DeviceDescriptor->ProductIdOffset)); DPRINT("Revision %s\n", (LPCSTR)((ULONG_PTR)DeviceDescriptor + DeviceDescriptor->ProductRevisionOffset)); DPRINT("Serial %s\n", (LPCSTR)((ULONG_PTR)DeviceDescriptor + DeviceDescriptor->SerialNumberOffset)); - // - // done - // Irp->IoStatus.Information = TotalLength; return STATUS_SUCCESS; } else { - // // adapter property query request - // + DPRINT("USBSTOR_HandleQueryProperty StorageAdapterProperty OutputBufferLength %lu\n", IoStack->Parameters.DeviceIoControl.OutputBufferLength); if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(STORAGE_ADAPTER_DESCRIPTOR)) { - // // buffer too small - // DescriptorHeader = (PSTORAGE_DESCRIPTOR_HEADER)Irp->AssociatedIrp.SystemBuffer; ASSERT(IoStack->Parameters.DeviceIoControl.OutputBufferLength >= sizeof(STORAGE_DESCRIPTOR_HEADER)); - // // return required size - // DescriptorHeader->Version = sizeof(STORAGE_ADAPTER_DESCRIPTOR); DescriptorHeader->Size = sizeof(STORAGE_ADAPTER_DESCRIPTOR); @@ -492,14 +331,10 @@ USBSTOR_HandleQueryProperty( return STATUS_SUCCESS; } - // // get adapter descriptor, information is returned in the same buffer - // AdapterDescriptor = (PSTORAGE_ADAPTER_DESCRIPTOR)Irp->AssociatedIrp.SystemBuffer; - // // fill out descriptor - // AdapterDescriptor->Version = sizeof(STORAGE_ADAPTER_DESCRIPTOR); AdapterDescriptor->Size = sizeof(STORAGE_ADAPTER_DESCRIPTOR); AdapterDescriptor->MaximumTransferLength = MAXULONG; //FIXME compute some sane value @@ -513,14 +348,9 @@ USBSTOR_HandleQueryProperty( AdapterDescriptor->BusMajorVersion = 0x2; //FIXME verify AdapterDescriptor->BusMinorVersion = 0x00; //FIXME - // // store returned length - // Irp->IoStatus.Information = sizeof(STORAGE_ADAPTER_DESCRIPTOR); - // - // done - // return STATUS_SUCCESS; } } @@ -538,153 +368,130 @@ USBSTOR_HandleDeviceControl( PINQUIRYDATA ScsiInquiryData; PUFI_INQUIRY_RESPONSE UFIInquiryResponse; - // - // get current stack location - // IoStack = IoGetCurrentIrpStackLocation(Irp); - if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_STORAGE_QUERY_PROPERTY) + switch (IoStack->Parameters.DeviceIoControl.IoControlCode) { - // - // query property - // - Status = USBSTOR_HandleQueryProperty(DeviceObject, Irp); - } - else if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_SCSI_PASS_THROUGH) - { - // - // query scsi pass through - // - DPRINT1("USBSTOR_HandleDeviceControl IOCTL_SCSI_PASS_THROUGH NOT implemented\n"); - Status = STATUS_NOT_SUPPORTED; - } - else if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_SCSI_PASS_THROUGH_DIRECT) - { - // - // query scsi pass through direct - // - DPRINT1("USBSTOR_HandleDeviceControl IOCTL_SCSI_PASS_THROUGH_DIRECT NOT implemented\n"); - Status = STATUS_NOT_SUPPORTED; - } - else if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER) - { - // - // query serial number - // - DPRINT1("USBSTOR_HandleDeviceControl IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER NOT implemented\n"); - Status = STATUS_NOT_SUPPORTED; - } - else if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_SCSI_GET_CAPABILITIES) - { - PIO_SCSI_CAPABILITIES Capabilities; - - /* Legacy port capability query */ - if (IoStack->Parameters.DeviceIoControl.OutputBufferLength == sizeof(PVOID)) - { - Capabilities = *((PVOID *)Irp->AssociatedIrp.SystemBuffer) = ExAllocatePoolWithTag(NonPagedPool, - sizeof(IO_SCSI_CAPABILITIES), - USB_STOR_TAG); - Irp->IoStatus.Information = sizeof(PVOID); - } - else + case IOCTL_STORAGE_QUERY_PROPERTY: + Status = USBSTOR_HandleQueryProperty(DeviceObject, Irp); + break; + case IOCTL_SCSI_PASS_THROUGH: + DPRINT1("USBSTOR_HandleDeviceControl IOCTL_SCSI_PASS_THROUGH NOT implemented\n"); + Status = STATUS_NOT_SUPPORTED; + break; + case IOCTL_SCSI_PASS_THROUGH_DIRECT: + DPRINT1("USBSTOR_HandleDeviceControl IOCTL_SCSI_PASS_THROUGH_DIRECT NOT implemented\n"); + Status = STATUS_NOT_SUPPORTED; + break; + case IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER: + DPRINT1("USBSTOR_HandleDeviceControl IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER NOT implemented\n"); + Status = STATUS_NOT_SUPPORTED; + break; + case IOCTL_SCSI_GET_CAPABILITIES: { - Capabilities = Irp->AssociatedIrp.SystemBuffer; - Irp->IoStatus.Information = sizeof(IO_SCSI_CAPABILITIES); - } + PIO_SCSI_CAPABILITIES Capabilities; - if (Capabilities) + // Legacy port capability query + if (IoStack->Parameters.DeviceIoControl.OutputBufferLength == sizeof(PVOID)) + { + Capabilities = *((PVOID *)Irp->AssociatedIrp.SystemBuffer) = ExAllocatePoolWithTag(NonPagedPool, + sizeof(IO_SCSI_CAPABILITIES), + USB_STOR_TAG); + Irp->IoStatus.Information = sizeof(PVOID); + } + else + { + Capabilities = Irp->AssociatedIrp.SystemBuffer; + Irp->IoStatus.Information = sizeof(IO_SCSI_CAPABILITIES); + } + + if (Capabilities) + { + Capabilities->MaximumTransferLength = MAXULONG; + Capabilities->MaximumPhysicalPages = 25; + Capabilities->SupportedAsynchronousEvents = 0; + Capabilities->AlignmentMask = 0; + Capabilities->TaggedQueuing = FALSE; + Capabilities->AdapterScansDown = FALSE; + Capabilities->AdapterUsesPio = FALSE; + Status = STATUS_SUCCESS; + } + else + { + Status = STATUS_INSUFFICIENT_RESOURCES; + } + + break; + } + case IOCTL_SCSI_GET_INQUIRY_DATA: { - Capabilities->MaximumTransferLength = MAXULONG; - Capabilities->MaximumPhysicalPages = 25; - Capabilities->SupportedAsynchronousEvents = 0; - Capabilities->AlignmentMask = 0; - Capabilities->TaggedQueuing = FALSE; - Capabilities->AdapterScansDown = FALSE; - Capabilities->AdapterUsesPio = FALSE; + PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; + ASSERT(PDODeviceExtension); + ASSERT(PDODeviceExtension->Common.IsFDO == FALSE); + + // get parameters + BusInfo = Irp->AssociatedIrp.SystemBuffer; + InquiryData = (PSCSI_INQUIRY_DATA)(BusInfo + 1); + ScsiInquiryData = (PINQUIRYDATA)InquiryData->InquiryData; + + UFIInquiryResponse = (PUFI_INQUIRY_RESPONSE)PDODeviceExtension->InquiryData; + ASSERT(UFIInquiryResponse); + + + BusInfo->NumberOfBuses = 1; + BusInfo->BusData[0].NumberOfLogicalUnits = 1; //FIXME + BusInfo->BusData[0].InitiatorBusId = 0; + BusInfo->BusData[0].InquiryDataOffset = sizeof(SCSI_ADAPTER_BUS_INFO); + + InquiryData->PathId = 0; + InquiryData->TargetId = 0; + InquiryData->Lun = PDODeviceExtension->LUN & MAX_LUN; + InquiryData->DeviceClaimed = PDODeviceExtension->Claimed; + InquiryData->InquiryDataLength = sizeof(INQUIRYDATA); + InquiryData->NextInquiryDataOffset = 0; + + RtlZeroMemory(ScsiInquiryData, sizeof(INQUIRYDATA)); + ScsiInquiryData->DeviceType = UFIInquiryResponse->DeviceType; + ScsiInquiryData->DeviceTypeQualifier = (UFIInquiryResponse->RMB & 0x7F); + + // Hack for IoReadPartitionTable call in disk.sys + ScsiInquiryData->RemovableMedia = ((ScsiInquiryData->DeviceType == DIRECT_ACCESS_DEVICE) ? ((UFIInquiryResponse->RMB & 0x80) ? 1 : 0) : 0); + + ScsiInquiryData->Versions = 0x04; + ScsiInquiryData->ResponseDataFormat = 0x02; + ScsiInquiryData->AdditionalLength = 31; + ScsiInquiryData->SoftReset = 0; + ScsiInquiryData->CommandQueue = 0; + ScsiInquiryData->LinkedCommands = 0; + ScsiInquiryData->RelativeAddressing = 0; + + RtlCopyMemory(&ScsiInquiryData->VendorId, UFIInquiryResponse->Vendor, USBSTOR_GetFieldLength(UFIInquiryResponse->Vendor, 8)); + RtlCopyMemory(&ScsiInquiryData->ProductId, UFIInquiryResponse->Product, USBSTOR_GetFieldLength(UFIInquiryResponse->Product, 16)); + + Irp->IoStatus.Information = sizeof(SCSI_ADAPTER_BUS_INFO) + sizeof(SCSI_INQUIRY_DATA) + sizeof(INQUIRYDATA) - 1; Status = STATUS_SUCCESS; + + break; } - else + case IOCTL_SCSI_GET_ADDRESS: { - Status = STATUS_INSUFFICIENT_RESOURCES; - } - } - else if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_SCSI_GET_INQUIRY_DATA) - { - // - // get device extension - // - PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - ASSERT(PDODeviceExtension); - ASSERT(PDODeviceExtension->Common.IsFDO == FALSE); + PSCSI_ADDRESS Address = Irp->AssociatedIrp.SystemBuffer; - // - // get parameters - // - BusInfo = Irp->AssociatedIrp.SystemBuffer; - InquiryData = (PSCSI_INQUIRY_DATA)(BusInfo + 1); - ScsiInquiryData = (PINQUIRYDATA)InquiryData->InquiryData; - - - // - // get inquiry data - // - UFIInquiryResponse = (PUFI_INQUIRY_RESPONSE)PDODeviceExtension->InquiryData; - ASSERT(UFIInquiryResponse); - - - BusInfo->NumberOfBuses = 1; - BusInfo->BusData[0].NumberOfLogicalUnits = 1; //FIXME - BusInfo->BusData[0].InitiatorBusId = 0; - BusInfo->BusData[0].InquiryDataOffset = sizeof(SCSI_ADAPTER_BUS_INFO); - - InquiryData->PathId = 0; - InquiryData->TargetId = 0; - InquiryData->Lun = PDODeviceExtension->LUN & MAX_LUN; - InquiryData->DeviceClaimed = PDODeviceExtension->Claimed; - InquiryData->InquiryDataLength = sizeof(INQUIRYDATA); - InquiryData->NextInquiryDataOffset = 0; - - RtlZeroMemory(ScsiInquiryData, sizeof(INQUIRYDATA)); - ScsiInquiryData->DeviceType = UFIInquiryResponse->DeviceType; - ScsiInquiryData->DeviceTypeQualifier = (UFIInquiryResponse->RMB & 0x7F); - - /* Hack for IoReadPartitionTable call in disk.sys */ - ScsiInquiryData->RemovableMedia = ((ScsiInquiryData->DeviceType == DIRECT_ACCESS_DEVICE) ? ((UFIInquiryResponse->RMB & 0x80) ? 1 : 0) : 0); - - ScsiInquiryData->Versions = 0x04; - ScsiInquiryData->ResponseDataFormat = 0x02; - ScsiInquiryData->AdditionalLength = 31; - ScsiInquiryData->SoftReset = 0; - ScsiInquiryData->CommandQueue = 0; - ScsiInquiryData->LinkedCommands = 0; - ScsiInquiryData->RelativeAddressing = 0; - - RtlCopyMemory(&ScsiInquiryData->VendorId, UFIInquiryResponse->Vendor, USBSTOR_GetFieldLength(UFIInquiryResponse->Vendor, 8)); - RtlCopyMemory(&ScsiInquiryData->ProductId, UFIInquiryResponse->Product, USBSTOR_GetFieldLength(UFIInquiryResponse->Product, 16)); - - Irp->IoStatus.Information = sizeof(SCSI_ADAPTER_BUS_INFO) + sizeof(SCSI_INQUIRY_DATA) + sizeof(INQUIRYDATA) - 1; - Status = STATUS_SUCCESS; - } - else if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_SCSI_GET_ADDRESS) - { - PSCSI_ADDRESS Address = Irp->AssociatedIrp.SystemBuffer; + Address->Length = sizeof(SCSI_ADDRESS); + Address->PortNumber = 0; + Address->PathId = 0; + Address->TargetId = 0; + Address->Lun = (((PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LUN & MAX_LUN); + Irp->IoStatus.Information = sizeof(SCSI_ADDRESS); - Address->Length = sizeof(SCSI_ADDRESS); - Address->PortNumber = 0; - Address->PathId = 0; - Address->TargetId = 0; - Address->Lun = (((PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LUN & MAX_LUN); - Irp->IoStatus.Information = sizeof(SCSI_ADDRESS); + Status = STATUS_SUCCESS; - Status = STATUS_SUCCESS; - } - else - { - // - // unsupported - // - DPRINT("USBSTOR_HandleDeviceControl IoControl %x not supported\n", IoStack->Parameters.DeviceIoControl.IoControlCode); - Status = STATUS_NOT_SUPPORTED; + break; + } + default: + DPRINT("USBSTOR_HandleDeviceControl IoControl %x not supported\n", IoStack->Parameters.DeviceIoControl.IoControlCode); + Status = STATUS_NOT_SUPPORTED; + break; } return Status; diff --git a/drivers/usb/usbstor/error.c b/drivers/usb/usbstor/error.c index e920d353d1b..0256c741a64 100644 --- a/drivers/usb/usbstor/error.c +++ b/drivers/usb/usbstor/error.c @@ -1,12 +1,10 @@ /* * PROJECT: ReactOS Universal Serial Bus Bulk Storage Driver - * LICENSE: GPL - See COPYING in the top level directory - * FILE: drivers/usb/usbstor/error.c + * LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later
) * PURPOSE: USB block storage device driver. - * PROGRAMMERS: - * James Tabor - * Michael Martin (michael.martin(a)reactos.org) - * Johannes Anderwald (johannes.anderwald(a)reactos.org) + * COPYRIGHT: 2005-2006 James Tabor + * 2011-2012 Michael Martin (michael.martin(a)reactos.org) + * 2011-2013 Johannes Anderwald (johannes.anderwald(a)reactos.org) */ #include "usbstor.h" @@ -14,6 +12,7 @@ #define NDEBUG #include <debug.h> + NTSTATUS USBSTOR_GetEndpointStatus( IN PDEVICE_OBJECT DeviceObject, @@ -23,44 +22,25 @@ USBSTOR_GetEndpointStatus( PURB Urb; NTSTATUS Status; - // - // allocate urb - // DPRINT("Allocating URB\n"); Urb = (PURB)AllocateItem(NonPagedPool, sizeof(struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST)); if (!Urb) { - // - // out of memory - // DPRINT1("OutofMemory!\n"); return STATUS_INSUFFICIENT_RESOURCES; } - // // build status - // - UsbBuildGetStatusRequest(Urb, URB_FUNCTION_GET_STATUS_FROM_ENDPOINT, bEndpointAddress & 0x0F, Value, NULL, NULL); + UsbBuildGetStatusRequest(Urb, URB_FUNCTION_GET_STATUS_FROM_ENDPOINT, bEndpointAddress & 0x0F, Value, NULL, NULL); - // // send the request - // DPRINT1("Sending Request DeviceObject %p, Urb %p\n", DeviceObject, Urb); Status = USBSTOR_SyncUrbRequest(DeviceObject, Urb); - // - // free urb - // FreeItem(Urb); - - // - // done - // return Status; } - - NTSTATUS USBSTOR_ResetPipeWithHandle( IN PDEVICE_OBJECT DeviceObject, @@ -69,45 +49,26 @@ USBSTOR_ResetPipeWithHandle( PURB Urb; NTSTATUS Status; - // - // allocate urb - // DPRINT("Allocating URB\n"); Urb = (PURB)AllocateItem(NonPagedPool, sizeof(struct _URB_PIPE_REQUEST)); if (!Urb) { - // - // out of memory - // DPRINT1("OutofMemory!\n"); return STATUS_INSUFFICIENT_RESOURCES; } - // - // initialize the urb - // Urb->UrbPipeRequest.Hdr.Length = sizeof(struct _URB_PIPE_REQUEST); Urb->UrbPipeRequest.Hdr.Function = URB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL; Urb->UrbPipeRequest.PipeHandle = PipeHandle; - // // send the request - // DPRINT1("Sending Request DeviceObject %p, Urb %p\n", DeviceObject, Urb); Status = USBSTOR_SyncUrbRequest(DeviceObject, Urb); - // - // free urb - // FreeItem(Urb); - - // - // done - // return Status; } - NTSTATUS USBSTOR_HandleTransferError( PDEVICE_OBJECT DeviceObject, @@ -118,107 +79,70 @@ USBSTOR_HandleTransferError( PSCSI_REQUEST_BLOCK Request; PCDB pCDB; - // - // sanity checks - // ASSERT(Context); ASSERT(Context->PDODeviceExtension); ASSERT(Context->PDODeviceExtension->Self); ASSERT(Context->Irp); - // // first perform a mass storage reset step 1 in 5.3.4 USB Mass Storage Bulk Only Specification - // Status = USBSTOR_ResetDevice(Context->FDODeviceExtension->LowerDeviceObject, Context->FDODeviceExtension); if (NT_SUCCESS(Status)) { - // // step 2 reset bulk in pipe section 5.3.4 - // Status = USBSTOR_ResetPipeWithHandle(Context->FDODeviceExtension->LowerDeviceObject, Context->FDODeviceExtension->InterfaceInformation->Pipes[Context->FDODeviceExtension->BulkInPipeIndex].PipeHandle); if (NT_SUCCESS(Status)) { - // // finally reset bulk out pipe - // Status = USBSTOR_ResetPipeWithHandle(Context->FDODeviceExtension->LowerDeviceObject, Context->FDODeviceExtension->InterfaceInformation->Pipes[Context->FDODeviceExtension->BulkOutPipeIndex].PipeHandle); } } - // - // get next stack location - // Stack = IoGetCurrentIrpStackLocation(Context->Irp); - // - // get request block - // Request = (PSCSI_REQUEST_BLOCK)Stack->Parameters.Others.Argument1; ASSERT(Request); - // // obtain request type - // pCDB = (PCDB)Request->Cdb; ASSERT(pCDB); if (Status != STATUS_SUCCESS || Context->RetryCount >= 1) { - // // Complete the master IRP - // Context->Irp->IoStatus.Status = Status; Context->Irp->IoStatus.Information = 0; USBSTOR_QueueTerminateRequest(Context->PDODeviceExtension->LowerDeviceObject, Context->Irp); IoCompleteRequest(Context->Irp, IO_NO_INCREMENT); - // // Start the next request - // USBSTOR_QueueNextRequest(Context->PDODeviceExtension->LowerDeviceObject); - // // srb handling finished - // Context->FDODeviceExtension->SrbErrorHandlingActive = FALSE; - // // clear timer srb - // Context->FDODeviceExtension->LastTimerActiveSrb = NULL; } else { DPRINT1("Retrying Count %lu %p\n", Context->RetryCount, Context->PDODeviceExtension->Self); - // // re-schedule request - // USBSTOR_HandleExecuteSCSI(Context->PDODeviceExtension->Self, Context->Irp, Context->RetryCount + 1); - // // srb error handling finished - // Context->FDODeviceExtension->SrbErrorHandlingActive = FALSE; - // // srb error handling finished - // Context->FDODeviceExtension->TimerWorkQueueEnabled = TRUE; - // // clear timer srb - // Context->FDODeviceExtension->LastTimerActiveSrb = NULL; } - // - // cleanup irp context - // FreeItem(Context->cbw); FreeItem(Context); - DPRINT1("USBSTOR_HandleTransferError returning with Status %x\n", Status); return Status; } @@ -231,15 +155,11 @@ USBSTOR_ResetHandlerWorkItemRoutine( NTSTATUS Status; PERRORHANDLER_WORKITEM_DATA WorkItemData = (PERRORHANDLER_WORKITEM_DATA)Context; - // // clear stall on BulkIn pipe - // Status = USBSTOR_ResetPipeWithHandle(WorkItemData->Context->FDODeviceExtension->LowerDeviceObject, WorkItemData->Context->FDODeviceExtension->InterfaceInformation->Pipes[WorkItemData->Context->FDODeviceExtension->BulkInPipeIndex].PipeHandle); DPRINT1("USBSTOR_ResetPipeWithHandle Status %x\n", Status); - // // now resend the csw as the stall got cleared - // USBSTOR_SendCSW(WorkItemData->Context, WorkItemData->Irp); } @@ -252,22 +172,16 @@ ErrorHandlerWorkItemRoutine( if (WorkItemData->Context->ErrorIndex == 2) { - // // reset device - // USBSTOR_HandleTransferError(WorkItemData->DeviceObject, WorkItemData->Context); } else { - // // clear stall - // USBSTOR_ResetHandlerWorkItemRoutine(WorkItemData); } - // // Free Work Item Data - // ExFreePoolWithTag(WorkItemData, USB_STOR_TAG); } @@ -280,56 +194,35 @@ USBSTOR_TimerWorkerRoutine( NTSTATUS Status; PERRORHANDLER_WORKITEM_DATA WorkItemData = (PERRORHANDLER_WORKITEM_DATA)Context; - // - // get device extension - // FDODeviceExtension = (PFDO_DEVICE_EXTENSION)WorkItemData->DeviceObject->DeviceExtension; ASSERT(FDODeviceExtension->Common.IsFDO); - // // first perform a mass storage reset step 1 in 5.3.4 USB Mass Storage Bulk Only Specification - // Status = USBSTOR_ResetDevice(FDODeviceExtension->LowerDeviceObject, FDODeviceExtension); if (NT_SUCCESS(Status)) { - // // step 2 reset bulk in pipe section 5.3.4 - // Status = USBSTOR_ResetPipeWithHandle(FDODeviceExtension->LowerDeviceObject, FDODeviceExtension->InterfaceInformation->Pipes[FDODeviceExtension->BulkInPipeIndex].PipeHandle); if (NT_SUCCESS(Status)) { - // // finally reset bulk out pipe - // Status = USBSTOR_ResetPipeWithHandle(FDODeviceExtension->LowerDeviceObject, FDODeviceExtension->InterfaceInformation->Pipes[FDODeviceExtension->BulkOutPipeIndex].PipeHandle); } } DPRINT1("Status %x\n", Status); - // // clear timer srb - // FDODeviceExtension->LastTimerActiveSrb = NULL; - // // re-schedule request - // //USBSTOR_HandleExecuteSCSI(WorkItemData->Context->PDODeviceExtension->Self, WorkItemData->Context->Irp, Context->RetryCount + 1); - - - // // do not retry for the same packet again - // FDODeviceExtension->TimerWorkQueueEnabled = FALSE; - // - // Free Work Item Data - // ExFreePoolWithTag(WorkItemData, USB_STOR_TAG); } - VOID NTAPI USBSTOR_TimerRoutine( @@ -340,50 +233,33 @@ USBSTOR_TimerRoutine( BOOLEAN ResetDevice = FALSE; PERRORHANDLER_WORKITEM_DATA WorkItemData; - // - // get device extension - // FDODeviceExtension = (PFDO_DEVICE_EXTENSION)Context; DPRINT1("[USBSTOR] TimerRoutine entered\n"); DPRINT1("[USBSTOR] ActiveSrb %p ResetInProgress %x LastTimerActiveSrb %p\n", FDODeviceExtension->ActiveSrb, FDODeviceExtension->ResetInProgress, FDODeviceExtension->LastTimerActiveSrb); - // - // acquire spinlock - // KeAcquireSpinLockAtDpcLevel(&FDODeviceExtension->IrpListLock); - // // is there an active srb and no global reset is in progress - // if (FDODeviceExtension->ActiveSrb && FDODeviceExtension->ResetInProgress == FALSE && FDODeviceExtension->TimerWorkQueueEnabled) { if (FDODeviceExtension->LastTimerActiveSrb != NULL && FDODeviceExtension->LastTimerActiveSrb == FDODeviceExtension->ActiveSrb) { - // // check if empty - // DPRINT1("[USBSTOR] ActiveSrb %p hang detected\n", FDODeviceExtension->ActiveSrb); ResetDevice = TRUE; } else { - // // update pointer - // FDODeviceExtension->LastTimerActiveSrb = FDODeviceExtension->ActiveSrb; } } else { - // // reset srb - // FDODeviceExtension->LastTimerActiveSrb = NULL; } - // - // release lock - // KeReleaseSpinLockFromDpcLevel(&FDODeviceExtension->IrpListLock); @@ -394,9 +270,7 @@ USBSTOR_TimerRoutine( USB_STOR_TAG); if (WorkItemData) { - // // Initialize and queue the work item to handle the error - // ExInitializeWorkItem(&WorkItemData->WorkQueueItem, USBSTOR_TimerWorkerRoutine, WorkItemData); diff --git a/drivers/usb/usbstor/fdo.c b/drivers/usb/usbstor/fdo.c index e3707041f58..3dff594dccb 100644 --- a/drivers/usb/usbstor/fdo.c +++ b/drivers/usb/usbstor/fdo.c @@ -1,12 +1,10 @@ /* * PROJECT: ReactOS Universal Serial Bus Bulk Storage Driver - * LICENSE: GPL - See COPYING in the top level directory - * FILE: drivers/usb/usbstor/fdo.c + * LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later
) * PURPOSE: USB block storage device driver. - * PROGRAMMERS: - * James Tabor - * Michael Martin (michael.martin(a)reactos.org) - * Johannes Anderwald (johannes.anderwald(a)reactos.org) + * COPYRIGHT: 2005-2006 James Tabor + * 2011-2012 Michael Martin (michael.martin(a)reactos.org) + * 2011-2013 Johannes Anderwald (johannes.anderwald(a)reactos.org) */ #include "usbstor.h" @@ -14,6 +12,7 @@ #define NDEBUG #include <debug.h> + VOID USBSTOR_DumpDeviceDescriptor(PUSB_DEVICE_DESCRIPTOR DeviceDescriptor) { @@ -44,80 +43,47 @@ USBSTOR_FdoHandleDeviceRelations( PDEVICE_RELATIONS DeviceRelations; PIO_STACK_LOCATION IoStack; - // - // get current irp stack location - // IoStack = IoGetCurrentIrpStackLocation(Irp); - // // check if relation type is BusRelations - // if (IoStack->Parameters.QueryDeviceRelations.Type != BusRelations) { - // // FDO always only handles bus relations - // return USBSTOR_SyncForwardIrp(DeviceExtension->LowerDeviceObject, Irp); } - // // go through array and count device objects - // for (Index = 0; Index < max(DeviceExtension->MaxLUN, 1); Index++) { if (DeviceExtension->ChildPDO[Index]) { - // - // child pdo - // DeviceCount++; } } - // - // allocate device relations - // DeviceRelations = (PDEVICE_RELATIONS)AllocateItem(PagedPool, sizeof(DEVICE_RELATIONS) + (DeviceCount > 1 ? (DeviceCount-1) * sizeof(PDEVICE_OBJECT) : 0)); if (!DeviceRelations) { - // - // no memory - // return STATUS_INSUFFICIENT_RESOURCES; } - // // add device objects - // - for(Index = 0; Index < max(DeviceExtension->MaxLUN, 1); Index++) + for (Index = 0; Index < max(DeviceExtension->MaxLUN, 1); Index++) { if (DeviceExtension->ChildPDO[Index]) { - // // store child pdo - // DeviceRelations->Objects[DeviceRelations->Count] = DeviceExtension->ChildPDO[Index]; - // // add reference - // ObReferenceObject(DeviceExtension->ChildPDO[Index]); - // - // increment count - // DeviceRelations->Count++; } } - // - // store result - // Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations; - // - // request completed successfully - // return STATUS_SUCCESS; } @@ -132,8 +98,8 @@ USBSTOR_FdoHandleRemoveDevice( DPRINT("Handling FDO removal %p\n", DeviceObject); - /* FIXME: wait for devices finished processing */ - for(Index = 0; Index < 16; Index++) + // FIXME: wait for devices finished processing + for (Index = 0; Index < 16; Index++) { if (DeviceExtension->ChildPDO[Index] != NULL) { @@ -142,14 +108,13 @@ USBSTOR_FdoHandleRemoveDevice( } } - /* Send the IRP down the stack */ + // Send the IRP down the stack IoSkipCurrentIrpStackLocation(Irp); Status = IoCallDriver(DeviceExtension->LowerDeviceObject, Irp); - /* Detach from the device stack */ + // Detach from the device stack IoDetachDevice(DeviceExtension->LowerDeviceObject); - /* Delete the device object */ IoDeleteDevice(DeviceObject); return Status; @@ -165,50 +130,31 @@ USBSTOR_FdoHandleStartDevice( NTSTATUS Status; UCHAR Index = 0; - // // forward irp to lower device - // Status = USBSTOR_SyncForwardIrp(DeviceExtension->LowerDeviceObject, Irp); if (!NT_SUCCESS(Status)) { - // - // failed to start - // DPRINT1("USBSTOR_FdoHandleStartDevice Lower device failed to start %x\n", Status); return Status; } - // // initialize irp queue - // USBSTOR_QueueInitialize(DeviceExtension); - // // first get device & configuration & string descriptor - // Status = USBSTOR_GetDescriptors(DeviceObject); if (!NT_SUCCESS(Status)) { - // - // failed to get device descriptor - // DPRINT1("USBSTOR_FdoHandleStartDevice failed to get device descriptor with %x\n", Status); return Status; } - // - // dump device descriptor - // USBSTOR_DumpDeviceDescriptor(DeviceExtension->DeviceDescriptor); - // + // Check that this device uses bulk transfers and is SCSI - // - InterfaceDesc = (PUSB_INTERFACE_DESCRIPTOR)((ULONG_PTR)DeviceExtension->ConfigurationDescriptor + sizeof(USB_CONFIGURATION_DESCRIPTOR)); - // - // sanity check - // + InterfaceDesc = (PUSB_INTERFACE_DESCRIPTOR)((ULONG_PTR)DeviceExtension->ConfigurationDescriptor + sizeof(USB_CONFIGURATION_DESCRIPTOR)); ASSERT(InterfaceDesc->bDescriptorType == USB_INTERFACE_DESCRIPTOR_TYPE); ASSERT(InterfaceDesc->bLength == sizeof(USB_INTERFACE_DESCRIPTOR)); @@ -221,82 +167,51 @@ USBSTOR_FdoHandleStartDevice( if (InterfaceDesc->bInterfaceSubClass != 0x06) { - // // FIXME: need to pad CDBs to 12 byte // mode select commands must be translated from 1AH / 15h to 5AH / 55h - // DPRINT1("[USBSTOR] Error: need to pad CDBs\n"); return STATUS_NOT_IMPLEMENTED; } - // // now select an interface - // Status = USBSTOR_SelectConfigurationAndInterface(DeviceObject, DeviceExtension); if (!NT_SUCCESS(Status)) { - // // failed to get device descriptor - // DPRINT1("USBSTOR_FdoHandleStartDevice failed to select configuration / interface with %x\n", Status); return Status; } - // // check if we got a bulk in + bulk out endpoint - // Status = USBSTOR_GetPipeHandles(DeviceExtension); if (!NT_SUCCESS(Status)) { - // - // failed to get pipe handles descriptor - // DPRINT1("USBSTOR_FdoHandleStartDevice no pipe handles %x\n", Status); return Status; } - // - // get num of lun which are supported - // Status = USBSTOR_GetMaxLUN(DeviceExtension->LowerDeviceObject, DeviceExtension); if (!NT_SUCCESS(Status)) { - // - // failed to get max LUN - // DPRINT1("USBSTOR_FdoHandleStartDevice failed to get max lun %x\n", Status); return Status; } - // // now create for each LUN a device object, 1 minimum - // do { - // - // create pdo - // Status = USBSTOR_CreatePDO(DeviceObject, Index); - // - // check for failure - // if (!NT_SUCCESS(Status)) { - // - // failed to create child pdo - // DPRINT1("USBSTOR_FdoHandleStartDevice USBSTOR_CreatePDO failed for Index %lu with Status %x\n", Index, Status); return Status; } - // - // increment pdo index - // Index++; DeviceExtension->InstanceCount++; - }while(Index < DeviceExtension->MaxLUN); + } while(Index < DeviceExtension->MaxLUN); #if 0 // @@ -313,16 +228,8 @@ USBSTOR_FdoHandleStartDevice( } #endif - - // - // start the timer - // //IoStartTimer(DeviceObject); - - // - // fdo is now initialized - // DPRINT("USBSTOR_FdoHandleStartDevice FDO is initialized\n"); return STATUS_SUCCESS; } @@ -336,126 +243,94 @@ USBSTOR_FdoHandlePnp( PFDO_DEVICE_EXTENSION DeviceExtension; NTSTATUS Status; - // - // get current stack location - // IoStack = IoGetCurrentIrpStackLocation(Irp); - - // - // get device extension - // DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - - // - // sanity check - // ASSERT(DeviceExtension->Common.IsFDO); switch(IoStack->MinorFunction) { - case IRP_MN_SURPRISE_REMOVAL: - { - DPRINT("IRP_MN_SURPRISE_REMOVAL %p\n", DeviceObject); - Irp->IoStatus.Status = STATUS_SUCCESS; + case IRP_MN_SURPRISE_REMOVAL: + { + DPRINT("IRP_MN_SURPRISE_REMOVAL %p\n", DeviceObject); + Irp->IoStatus.Status = STATUS_SUCCESS; - // // forward irp to next device object - // IoSkipCurrentIrpStackLocation(Irp); return IoCallDriver(DeviceExtension->LowerDeviceObject, Irp); - } - case IRP_MN_QUERY_DEVICE_RELATIONS: - { - DPRINT("IRP_MN_QUERY_DEVICE_RELATIONS %p\n", DeviceObject); - Status = USBSTOR_FdoHandleDeviceRelations(DeviceExtension, Irp); - break; - } - case IRP_MN_STOP_DEVICE: - { - DPRINT1("USBSTOR_FdoHandlePnp: IRP_MN_STOP_DEVICE unimplemented\n"); - IoStopTimer(DeviceObject); - Irp->IoStatus.Status = STATUS_SUCCESS; + } + case IRP_MN_QUERY_DEVICE_RELATIONS: + { + DPRINT("IRP_MN_QUERY_DEVICE_RELATIONS %p\n", DeviceObject); + Status = USBSTOR_FdoHandleDeviceRelations(DeviceExtension, Irp); + break; + } + case IRP_MN_STOP_DEVICE: + { + DPRINT1("USBSTOR_FdoHandlePnp: IRP_MN_STOP_DEVICE unimplemented\n"); + IoStopTimer(DeviceObject); + Irp->IoStatus.Status = STATUS_SUCCESS; - // // forward irp to next device object - // IoSkipCurrentIrpStackLocation(Irp); return IoCallDriver(DeviceExtension->LowerDeviceObject, Irp); - } - case IRP_MN_REMOVE_DEVICE: - { - DPRINT("IRP_MN_REMOVE_DEVICE\n"); - - return USBSTOR_FdoHandleRemoveDevice(DeviceObject, DeviceExtension, Irp); - } - case IRP_MN_QUERY_CAPABILITIES: - { - // - // FIXME: set custom capabilities - // - IoSkipCurrentIrpStackLocation(Irp); - return IoCallDriver(DeviceExtension->LowerDeviceObject, Irp); - } - case IRP_MN_QUERY_STOP_DEVICE: - case IRP_MN_QUERY_REMOVE_DEVICE: - { + } + case IRP_MN_REMOVE_DEVICE: + { + DPRINT("IRP_MN_REMOVE_DEVICE\n"); + + return USBSTOR_FdoHandleRemoveDevice(DeviceObject, DeviceExtension, Irp); + } + case IRP_MN_QUERY_CAPABILITIES: + { + // FIXME: set custom capabilities + IoSkipCurrentIrpStackLocation(Irp); + return IoCallDriver(DeviceExtension->LowerDeviceObject, Irp); + } + case IRP_MN_QUERY_STOP_DEVICE: + case IRP_MN_QUERY_REMOVE_DEVICE: + { #if 0 - // - // we can if nothing is pending - // - if (DeviceExtension->IrpPendingCount != 0 || - DeviceExtension->ActiveSrb != NULL) + // + // we can if nothing is pending + // + if (DeviceExtension->IrpPendingCount != 0 || + DeviceExtension->ActiveSrb != NULL) #else - if (TRUE) + if (TRUE) #endif - { - /* We have pending requests */ - DPRINT1("Failing removal/stop request due to pending requests present\n"); - Status = STATUS_UNSUCCESSFUL; - } - else - { - /* We're all clear */ - Irp->IoStatus.Status = STATUS_SUCCESS; - - IoSkipCurrentIrpStackLocation(Irp); - return IoCallDriver(DeviceExtension->LowerDeviceObject, Irp); - } - break; - } - case IRP_MN_START_DEVICE: - { - Status = USBSTOR_FdoHandleStartDevice(DeviceObject, DeviceExtension, Irp); - break; - } - default: + { + /* We have pending requests */ + DPRINT1("Failing removal/stop request due to pending requests present\n"); + Status = STATUS_UNSUCCESSFUL; + } + else + { + /* We're all clear */ + Irp->IoStatus.Status = STATUS_SUCCESS; + + IoSkipCurrentIrpStackLocation(Irp); + return IoCallDriver(DeviceExtension->LowerDeviceObject, Irp); + } + break; + } + case IRP_MN_START_DEVICE: + { + Status = USBSTOR_FdoHandleStartDevice(DeviceObject, DeviceExtension, Irp); + break; + } + default: { - // // forward irp to next device object - // IoSkipCurrentIrpStackLocation(Irp); return IoCallDriver(DeviceExtension->LowerDeviceObject, Irp); } } - // - // complete request - // if (Status != STATUS_PENDING) { - // - // store result - // Irp->IoStatus.Status = Status; - - // - // complete request - // IoCompleteRequest(Irp, IO_NO_INCREMENT); } - // - // done processing - // return Status; } diff --git a/drivers/usb/usbstor/misc.c b/drivers/usb/usbstor/misc.c index 6b60cf828e7..671336df88c 100644 --- a/drivers/usb/usbstor/misc.c +++ b/drivers/usb/usbstor/misc.c @@ -1,12 +1,10 @@ /* * PROJECT: ReactOS Universal Serial Bus Bulk Storage Driver - * LICENSE: GPL - See COPYING in the top level directory - * FILE: drivers/usb/usbstor/misc.c + * LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later
) * PURPOSE: USB block storage device driver. - * PROGRAMMERS: - * James Tabor - * Michael Martin (michael.martin(a)reactos.org) - * Johannes Anderwald (johannes.anderwald(a)reactos.org) + * COPYRIGHT: 2005-2006 James Tabor + * 2011-2012 Michael Martin (michael.martin(a)reactos.org) + * 2011-2013 Johannes Anderwald (johannes.anderwald(a)reactos.org) */ #include "usbstor.h" @@ -14,9 +12,7 @@ #define NDEBUG #include <debug.h> -// -// driver verifier -// + IO_COMPLETION_ROUTINE SyncForwardIrpCompletionRoutine; NTSTATUS @@ -40,46 +36,19 @@ USBSTOR_SyncForwardIrp(PDEVICE_OBJECT DeviceObject, PIRP Irp) KEVENT Event; NTSTATUS Status; - // - // initialize event - // KeInitializeEvent(&Event, NotificationEvent, FALSE); - - // - // copy irp stack location - // IoCopyCurrentIrpStackLocationToNext(Irp); - - // - // set completion routine - // IoSetCompletionRoutine(Irp, USBSTOR_SyncForwardIrpCompletionRoutine, &Event, TRUE, TRUE, TRUE); - - // - // call driver - // Status = IoCallDriver(DeviceObject, Irp); - // - // check if pending - // if (Status == STATUS_PENDING) { - // // wait for the request to finish - // KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL); - - // - // copy status code - // Status = Irp->IoStatus.Status; } - // - // done - // return Status; } @@ -95,22 +64,11 @@ USBSTOR_GetBusInterface( IO_STATUS_BLOCK IoStatus; PIO_STACK_LOCATION Stack; - // - // sanity checks - // ASSERT(DeviceObject); ASSERT(BusInterface); - - // - // initialize event - // KeInitializeEvent(&Event, NotificationEvent, FALSE); - - // - // create irp - // Irp = IoBuildSynchronousFsdRequest(IRP_MJ_PNP, DeviceObject, NULL, @@ -118,22 +76,13 @@ USBSTOR_GetBusInterface( NULL, &Event, &IoStatus); - - // - // was irp built - // if (Irp == NULL) { - // - // no memory - // return STATUS_INSUFFICIENT_RESOURCES; } - // // initialize request - // - Stack=IoGetNextIrpStackLocation(Irp); + Stack = IoGetNextIrpStackLocation(Irp); Stack->MajorFunction = IRP_MJ_PNP; Stack->MinorFunction = IRP_MN_QUERY_INTERFACE; Stack->Parameters.QueryInterface.Size = sizeof(BUS_INTERFACE_STANDARD); @@ -143,25 +92,12 @@ USBSTOR_GetBusInterface( Stack->Parameters.QueryInterface.InterfaceSpecificData = NULL; Irp->IoStatus.Status = STATUS_NOT_SUPPORTED; - // - // call driver - // - Status= IoCallDriver(DeviceObject, Irp); + Status = IoCallDriver(DeviceObject, Irp); - // - // did operation complete - // if (Status == STATUS_PENDING) { - // - // wait for completion - // KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL); - - // - // collect status - // - Status=IoStatus.Status; + Status = IoStatus.Status; } return Status; @@ -177,72 +113,34 @@ USBSTOR_SyncUrbRequest( KEVENT Event; NTSTATUS Status; - // - // allocate irp - // Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE); if (!Irp) { - // - // no memory - // return STATUS_INSUFFICIENT_RESOURCES; } - // - // initialize event - // KeInitializeEvent(&Event, NotificationEvent, FALSE); - - // - // get next stack location - // IoStack = IoGetNextIrpStackLocation(Irp); - // // initialize stack location - // IoStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; IoStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB; IoStack->Parameters.Others.Argument1 = (PVOID)UrbRequest; IoStack->Parameters.DeviceIoControl.InputBufferLength = UrbRequest->UrbHeader.Length; Irp->IoStatus.Status = STATUS_SUCCESS; - // - // setup completion routine - // IoSetCompletionRoutine(Irp, USBSTOR_SyncForwardIrpCompletionRoutine, &Event, TRUE, TRUE, TRUE); - // - // call driver - // Status = IoCallDriver(DeviceObject, Irp); - // - // check if request is pending - // if (Status == STATUS_PENDING) { - // - // wait for completion - // KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL); - - // - // update status - // Status = Irp->IoStatus.Status; } - // - // free irp - // IoFreeIrp(Irp); - - // - // done - // return Status; } @@ -251,22 +149,13 @@ AllocateItem( IN POOL_TYPE PoolType, IN ULONG ItemSize) { - // - // allocate item - // PVOID Item = ExAllocatePoolWithTag(PoolType, ItemSize, USB_STOR_TAG); if (Item) { - // - // zero item - // RtlZeroMemory(Item, ItemSize); } - // - // return element - // return Item; } @@ -274,9 +163,6 @@ VOID FreeItem( IN PVOID Item) { - // - // free item - // ExFreePoolWithTag(Item, USB_STOR_TAG); } @@ -294,21 +180,12 @@ USBSTOR_ClassRequest( PURB Urb; NTSTATUS Status; - // - // first allocate urb - // Urb = (PURB)AllocateItem(NonPagedPool, sizeof(struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST)); if (!Urb) { - // - // no memory - // return STATUS_INSUFFICIENT_RESOURCES; } - // - // initialize vendor request - // Urb->UrbControlVendorClassRequest.Hdr.Length = sizeof(struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST); Urb->UrbControlVendorClassRequest.Hdr.Function = URB_FUNCTION_CLASS_INTERFACE; Urb->UrbControlVendorClassRequest.TransferFlags = TransferFlags; @@ -317,23 +194,12 @@ USBSTOR_ClassRequest( Urb->UrbControlVendorClassRequest.Request = RequestType; Urb->UrbControlVendorClassRequest.Index = Index; - // - // submit request - // Status = USBSTOR_SyncUrbRequest(DeviceObject, Urb); - // - // free urb - // FreeItem(Urb); - - // - // done - // return Status; } - NTSTATUS USBSTOR_GetMaxLUN( IN PDEVICE_OBJECT DeviceObject, @@ -342,22 +208,13 @@ USBSTOR_GetMaxLUN( PUCHAR Buffer; NTSTATUS Status; - // - // allocate 1-byte buffer - // Buffer = (PUCHAR)AllocateItem(NonPagedPool, sizeof(UCHAR)); if (!Buffer) { - // - // no memory - // FreeItem(Buffer); return STATUS_INSUFFICIENT_RESOURCES; } - // - // execute request - // Status = USBSTOR_ClassRequest(DeviceObject, DeviceExtension, USB_BULK_GET_MAX_LUN, DeviceExtension->InterfaceInformation->InterfaceNumber, USBD_TRANSFER_DIRECTION_IN, sizeof(UCHAR), Buffer); DPRINT("MaxLUN: %x\n", *Buffer); @@ -366,42 +223,28 @@ USBSTOR_GetMaxLUN( { if (*Buffer > 0xF) { - // // invalid response documented in usb mass storage specification - // Status = STATUS_DEVICE_DATA_ERROR; } else { - // // store maxlun - // DeviceExtension->MaxLUN = *Buffer; } } else { - // // "USB Mass Storage Class. Bulk-Only Transport. Revision 1.0" // 3.2 Get Max LUN (class-specific request) : // Devices that do not support multiple LUNs may STALL this command. - // USBSTOR_ResetDevice(DeviceExtension->LowerDeviceObject, DeviceExtension); DeviceExtension->MaxLUN = 0; Status = STATUS_SUCCESS; } - // - // free buffer - // FreeItem(Buffer); - - // - // done - // return Status; - } NTSTATUS @@ -411,16 +254,8 @@ USBSTOR_ResetDevice( { NTSTATUS Status; - // - // execute request - // Status = USBSTOR_ClassRequest(DeviceObject, DeviceExtension, USB_BULK_RESET_DEVICE, DeviceExtension->InterfaceInformation->InterfaceNumber, USBD_TRANSFER_DIRECTION_OUT, 0, NULL); - - // - // done - // return Status; - } BOOLEAN @@ -433,88 +268,54 @@ USBSTOR_IsFloppy( PUFI_CAPACITY_DESCRIPTOR Descriptor; ULONG Length, Index, BlockCount, BlockLength; - // - // get format header - // FormatHeader = (PUFI_CAPACITY_FORMAT_HEADER)Buffer; - - // - // sanity checks - // ASSERT(FormatHeader->Reserved1 == 0x00); ASSERT(FormatHeader->Reserved2 == 0x00); ASSERT(FormatHeader->Reserved3 == 0x00); - // // is there capacity data - // if (!FormatHeader->CapacityLength) { - // - // no data provided - // DPRINT1("[USBSTOR] No capacity length\n"); return FALSE; } - // // the format header are always 8 bytes in length - // ASSERT((FormatHeader->CapacityLength & 0x7) == 0); DPRINT1("CapacityLength %x\n", FormatHeader->CapacityLength); - // // grab length and locate first descriptor - // Length = FormatHeader->CapacityLength; Descriptor = (PUFI_CAPACITY_DESCRIPTOR)(FormatHeader + 1); - for(Index = 0; Index < Length / sizeof(UFI_CAPACITY_DESCRIPTOR); Index++) + for (Index = 0; Index < Length / sizeof(UFI_CAPACITY_DESCRIPTOR); Index++) { - // // blocks are little endian format - // BlockCount = NTOHL(Descriptor->BlockCount); - - // - // get block length - // BlockLength = NTOHL((Descriptor->BlockLengthByte0 << 24 | Descriptor->BlockLengthByte1 << 16 | Descriptor->BlockLengthByte2 << 8)); DPRINT1("BlockCount %x BlockLength %x Code %x\n", BlockCount, BlockLength, Descriptor->Code); if (BlockLength == 512 && BlockCount == 1440) { - // // 720 KB DD - // *MediumTypeCode = 0x1E; return TRUE; } else if (BlockLength == 1024 && BlockCount == 1232) { - // // 1,25 MB - // *MediumTypeCode = 0x93; return TRUE; } else if (BlockLength == 512 && BlockCount == 2880) { - // // 1,44MB KB DD - // *MediumTypeCode = 0x94; return TRUE; } - // - // move to next descriptor - // - Descriptor = (Descriptor + 1); + Descriptor++; } - // - // no floppy detected - // return FALSE; } diff --git a/drivers/usb/usbstor/pdo.c b/drivers/usb/usbstor/pdo.c index 6ce5d8f7460..98c01d1cb7b 100644 --- a/drivers/usb/usbstor/pdo.c +++ b/drivers/usb/usbstor/pdo.c @@ -1,12 +1,10 @@ /* * PROJECT: ReactOS Universal Serial Bus Bulk Storage Driver - * LICENSE: GPL - See COPYING in the top level directory - * FILE: drivers/usb/usbstor/pdo.c + * LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later
) * PURPOSE: USB block storage device driver. - * PROGRAMMERS: - * James Tabor - * Michael Martin (michael.martin(a)reactos.org) - * Johannes Anderwald (johannes.anderwald(a)reactos.org) + * COPYRIGHT: 2005-2006 James Tabor + * 2011-2012 Michael Martin (michael.martin(a)reactos.org) + * 2011-2013 Johannes Anderwald (johannes.anderwald(a)reactos.org) */ #include "usbstor.h" @@ -14,75 +12,54 @@ #define NDEBUG #include <debug.h> + LPCSTR USBSTOR_GetDeviceType( IN PUFI_INQUIRY_RESPONSE InquiryData, IN UCHAR IsFloppy) { - // - // check if device type is zero - // if (InquiryData->DeviceType == 0) { if (IsFloppy) { - // // floppy device - // return "SFloppy"; } - // // direct access device - // return "Disk"; } - // - // FIXME: use constant - derived from
http://en.wikipedia.org/wiki/SCSI_Peripheral_Device_Type
- // switch (InquiryData->DeviceType) { case 1: { - // // sequential device, i.e magnetic tape - // return "Sequential"; } case 4: { - // // write once device - // return "Worm"; } case 5: { - // // CDROM device - // return "CdRom"; } case 7: { - // // optical memory device - // return "Optical"; } case 8: { - // // medium change device - // return "Changer"; } default: { - // // other device - // return "Other"; } } @@ -93,76 +70,53 @@ USBSTOR_GetGenericType( IN PUFI_INQUIRY_RESPONSE InquiryData, IN UCHAR IsFloppy) { - // - // check if device type is zero - // if (InquiryData->DeviceType == 0) { if (IsFloppy) { - // // floppy device - // return "GenSFloppy"; } - // // direct access device - // return "GenDisk"; } - // - // FIXME: use constant - derived from
http://en.wikipedia.org/wiki/SCSI_Peripheral_Device_Type
- // switch (InquiryData->DeviceType) { case 1: { - // // sequential device, i.e magnetic tape - // return "GenSequential"; } case 4: { - // // write once device - // return "GenWorm"; } case 5: { - // // CDROM device - // return "GenCdRom"; } case 7: { - // // optical memory device - // return "GenOptical"; } case 8: { - // // medium change device - // return "GenChanger"; } default: { - // // other device - // return "UsbstorOther"; } } } - ULONG CopyField( IN PUCHAR Name, @@ -171,20 +125,16 @@ CopyField( { ULONG Index; - for(Index = 0; Index < MaxLength; Index++) + for (Index = 0; Index < MaxLength; Index++) { if (Name[Index] <= ' ' || Name[Index] >= 0x7F /* last printable ascii character */ || Name[Index] == ',') { - // // convert to underscore - // Buffer[Index] = '_'; } else { - // // just copy character - // Buffer[Index] = Name[Index]; } } @@ -197,41 +147,25 @@ USBSTOR_PdoHandleQueryDeviceText( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) { - //PPDO_DEVICE_EXTENSION DeviceExtension; PIO_STACK_LOCATION IoStack; LPWSTR Buffer; static WCHAR DeviceText[] = L"USB Mass Storage Device"; - // - // get current stack location - // IoStack = IoGetCurrentIrpStackLocation(Irp); if (IoStack->Parameters.QueryDeviceText.DeviceTextType == DeviceTextDescription) { DPRINT("USBSTOR_PdoHandleQueryDeviceText DeviceTextDescription\n"); - // - // allocate item - // Buffer = (LPWSTR)AllocateItem(PagedPool, sizeof(DeviceText)); if (!Buffer) { - // - // no memory - // Irp->IoStatus.Information = 0; return STATUS_INSUFFICIENT_RESOURCES; } - // - // copy buffer - // wcscpy(Buffer, DeviceText); - // - // save result - // Irp->IoStatus.Information = (ULONG_PTR)Buffer; return STATUS_SUCCESS; } @@ -239,34 +173,21 @@ USBSTOR_PdoHandleQueryDeviceText( { DPRINT("USBSTOR_PdoHandleQueryDeviceText DeviceTextLocationInformation\n"); - // - // allocate item - // Buffer = (LPWSTR)AllocateItem(PagedPool, sizeof(DeviceText)); if (!Buffer) { - // - // no memory - // Irp->IoStatus.Information = 0; return STATUS_INSUFFICIENT_RESOURCES; } - // - // copy buffer - // wcscpy(Buffer, DeviceText); - // - // save result - // Irp->IoStatus.Information = (ULONG_PTR)Buffer; return STATUS_SUCCESS; } } - NTSTATUS USBSTOR_PdoHandleQueryDeviceId( IN PDEVICE_OBJECT DeviceObject, @@ -274,41 +195,20 @@ USBSTOR_PdoHandleQueryDeviceId( { PPDO_DEVICE_EXTENSION DeviceExtension; NTSTATUS Status; - CHAR Buffer[100]; + CHAR Buffer[100] = {0}; LPCSTR DeviceType; ULONG Offset = 0; PUFI_INQUIRY_RESPONSE InquiryData; ANSI_STRING AnsiString; UNICODE_STRING DeviceId; - // - // get device extension - // DeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - - // - // sanity check - // ASSERT(DeviceExtension->InquiryData); - - // - // get inquiry data - // InquiryData = (PUFI_INQUIRY_RESPONSE)DeviceExtension->InquiryData; - // - // get device type - // DeviceType = USBSTOR_GetDeviceType(InquiryData, DeviceExtension->IsFloppy); - // - // zero buffer - // - RtlZeroMemory(Buffer, sizeof(Buffer)); - - // // lets create device string - // Offset = sprintf(&Buffer[Offset], "USBSTOR\\"); Offset += sprintf(&Buffer[Offset], DeviceType); Offset += sprintf(&Buffer[Offset], "&Ven_"); @@ -318,45 +218,27 @@ USBSTOR_PdoHandleQueryDeviceId( Offset += sprintf(&Buffer[Offset], "&Rev_"); Offset += CopyField(InquiryData->Revision, &Buffer[Offset], 4); - // - // now initialize ansi string - // RtlInitAnsiString(&AnsiString, (PCSZ)Buffer); - // // allocate DeviceId string - // DeviceId.Length = 0; DeviceId.MaximumLength = (strlen((PCHAR)Buffer) + 1) * sizeof(WCHAR); DeviceId.Buffer = (LPWSTR)AllocateItem(PagedPool, DeviceId.MaximumLength); if (!DeviceId.Buffer) { - // - // no memory - // Irp->IoStatus.Information = 0; return STATUS_INSUFFICIENT_RESOURCES; } - - // - // convert to unicode - // Status = RtlAnsiStringToUnicodeString(&DeviceId, &AnsiString, FALSE); if (NT_SUCCESS(Status)) { - // - // store result - // Irp->IoStatus.Information = (ULONG_PTR)DeviceId.Buffer; } DPRINT("DeviceId %wZ Status %x\n", &DeviceId, Status); - // - // done - // return Status; } @@ -377,38 +259,24 @@ USBSTOR_ConvertToUnicodeString( DPRINT("ResultBufferOffset %lu ResultBufferLength %lu Buffer %s Length %lu\n", ResultBufferOffset, ResultBufferLength, Buffer, strlen(Buffer)); - // // construct destination string - // DeviceString.Buffer = &ResultBuffer[ResultBufferOffset]; DeviceString.Length = 0; DeviceString.MaximumLength = (ResultBufferLength - ResultBufferOffset) * sizeof(WCHAR); - // // initialize source string - // RtlInitAnsiString(&AnsiString, Buffer); - // - // convert to unicode - // Status = RtlAnsiStringToUnicodeString(&DeviceString, &AnsiString, FALSE); ASSERT(Status == STATUS_SUCCESS); - // // subtract consumed bytes - // ResultBufferLength -= (DeviceString.Length + sizeof(WCHAR)) / sizeof(WCHAR); ResultBufferOffset += (DeviceString.Length + sizeof(WCHAR)) / sizeof(WCHAR); - // - // store new offset - // *NewResultBufferOffset = ResultBufferOffset; } - - NTSTATUS USBSTOR_PdoHandleQueryHardwareId( IN PDEVICE_OBJECT DeviceObject, @@ -423,39 +291,18 @@ USBSTOR_PdoHandleQueryHardwareId( ULONG Offset, TotalLength, Length; PUFI_INQUIRY_RESPONSE InquiryData; - // - // get PDO device extension - // PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - - // - // get FDO device extension - // FDODeviceExtension = (PFDO_DEVICE_EXTENSION)PDODeviceExtension->LowerDeviceObject->DeviceExtension; - - // - // sanity check - // ASSERT(FDODeviceExtension->DeviceDescriptor); - - // - // get inquiry data - // InquiryData = (PUFI_INQUIRY_RESPONSE)PDODeviceExtension->InquiryData; - - // - // get device type and generic type - // DeviceType = USBSTOR_GetDeviceType(InquiryData, PDODeviceExtension->IsFloppy); GenericType = USBSTOR_GetGenericType(InquiryData, PDODeviceExtension->IsFloppy); ASSERT(GenericType); - // // generate id 1 // USBSTOR\SCSIType_Vendor(8)_Product(16)_Revision(4) - // RtlZeroMemory(Id1, sizeof(Id1)); Offset = 0; Offset = sprintf(&Id1[Offset], "USBSTOR\\"); @@ -466,10 +313,8 @@ USBSTOR_PdoHandleQueryHardwareId( Id1Length = strlen(Id1) + 1; DPRINT("USBSTOR_PdoHandleQueryHardwareId HardwareId1 %s\n", Id1); - // // generate id 2 // USBSTOR\SCSIType_VENDOR(8)_Product(16) - // RtlZeroMemory(Id2, sizeof(Id2)); Offset = 0; Offset = sprintf(&Id2[Offset], "USBSTOR\\"); @@ -479,10 +324,8 @@ USBSTOR_PdoHandleQueryHardwareId( Id2Length = strlen(Id2) + 1; DPRINT("USBSTOR_PdoHandleQueryHardwareId HardwareId2 %s\n", Id2); - // // generate id 3 // USBSTOR\SCSIType_VENDOR(8) - // RtlZeroMemory(Id3, sizeof(Id3)); Offset = 0; Offset = sprintf(&Id3[Offset], "USBSTOR\\"); @@ -491,10 +334,8 @@ USBSTOR_PdoHandleQueryHardwareId( Id3Length = strlen(Id3) + 1; DPRINT("USBSTOR_PdoHandleQueryHardwareId HardwareId3 %s\n", Id3); - // // generate id 4 // USBSTOR\SCSIType_VENDOR(8)_Product(16)_Revision(1) - // RtlZeroMemory(Id4, sizeof(Id4)); Offset = 0; Offset = sprintf(&Id4[Offset], "USBSTOR\\"); @@ -505,10 +346,8 @@ USBSTOR_PdoHandleQueryHardwareId( Id4Length = strlen(Id4) + 1; DPRINT("USBSTOR_PdoHandleQueryHardwareId HardwareId4 %s\n", Id4); - // // generate id 5 // USBSTOR\SCSIType - // RtlZeroMemory(Id5, sizeof(Id5)); Offset = 0; Offset = sprintf(&Id5[Offset], "USBSTOR\\"); @@ -516,37 +355,24 @@ USBSTOR_PdoHandleQueryHardwareId( Id5Length = strlen(Id5) + 1; DPRINT("USBSTOR_PdoHandleQueryHardwareId HardwareId5 %s\n", Id5); - // // generate id 6 // SCSIType - // RtlZeroMemory(Id6, sizeof(Id6)); Offset = 0; Offset = sprintf(&Id6[Offset], GenericType); Id6Length = strlen(Id6) + 1; DPRINT("USBSTOR_PdoHandleQueryHardwareId HardwareId6 %s\n", Id6); - // - // compute total length - // TotalLength = Id1Length + Id2Length + Id3Length + Id4Length + Id5Length + Id6Length + 1; - // - // allocate buffer - // Buffer = (LPWSTR)AllocateItem(PagedPool, TotalLength * sizeof(WCHAR)); if (!Buffer) { - // - // no memory - // Irp->IoStatus.Information = 0; return STATUS_INSUFFICIENT_RESOURCES; } - // // reset offset - // Offset = 0; Length = TotalLength; @@ -557,19 +383,9 @@ USBSTOR_PdoHandleQueryHardwareId( USBSTOR_ConvertToUnicodeString(Id5, Length, Offset, Buffer, &Offset); USBSTOR_ConvertToUnicodeString(Id6, Length, Offset, Buffer, &Offset); - // - // sanity check - // ASSERT(Offset + 1 == Length); - // - // store result - // Irp->IoStatus.Information = (ULONG_PTR)Buffer; - - // - // done - // return STATUS_SUCCESS; } @@ -580,51 +396,23 @@ USBSTOR_PdoHandleQueryCompatibleId( { PPDO_DEVICE_EXTENSION PDODeviceExtension; PFDO_DEVICE_EXTENSION FDODeviceExtension; - CHAR Buffer[100]; + CHAR Buffer[100] = {0}; ULONG Length, Offset; LPWSTR InstanceId; LPCSTR DeviceType; - // - // get PDO device extension - // PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - - // - // get FDO device extension - // FDODeviceExtension = (PFDO_DEVICE_EXTENSION)PDODeviceExtension->LowerDeviceObject->DeviceExtension; - - // - // sanity check - // ASSERT(FDODeviceExtension->DeviceDescriptor); - - // - // get target device type - // DeviceType = USBSTOR_GetDeviceType((PUFI_INQUIRY_RESPONSE)PDODeviceExtension->InquiryData, PDODeviceExtension->IsFloppy); - // - // zero memory - // - RtlZeroMemory(Buffer, sizeof(Buffer)); - - // // format instance id - // Length = sprintf(Buffer, "USBSTOR\\%s", DeviceType) + 1; Length += sprintf(&Buffer[Length], "USBSTOR\\%s", "RAW") + 2; - // - // allocate instance id - // InstanceId = (LPWSTR)AllocateItem(PagedPool, Length * sizeof(WCHAR)); if (!InstanceId) { - // - // no memory - // Irp->IoStatus.Information = 0; return STATUS_INSUFFICIENT_RESOURCES; } @@ -634,14 +422,7 @@ USBSTOR_PdoHandleQueryCompatibleId( DPRINT("USBSTOR_PdoHandleQueryCompatibleId %S\n", InstanceId); - // - // store result - // Irp->IoStatus.Information = (ULONG_PTR)InstanceId; - - // - // completed successfully - // return STATUS_SUCCESS; } @@ -656,67 +437,35 @@ USBSTOR_PdoHandleQueryInstanceId( ULONG Length; LPWSTR InstanceId; - // - // get PDO device extension - // PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - - // - // get FDO device extension - // FDODeviceExtension = (PFDO_DEVICE_EXTENSION)PDODeviceExtension->LowerDeviceObject->DeviceExtension; - // // format instance id - // if (FDODeviceExtension->SerialNumber) { - // // using serial number from device - // swprintf(Buffer, L"%s&%c", FDODeviceExtension->SerialNumber->bString, PDODeviceExtension->LUN); } else { - // // use instance count and LUN - // swprintf(Buffer, L"%04lu&%c", FDODeviceExtension->InstanceCount, PDODeviceExtension->LUN); } - // - // calculate length - // Length = wcslen(Buffer) + 1; - // - // allocate instance id - // InstanceId = (LPWSTR)AllocateItem(PagedPool, Length * sizeof(WCHAR)); if (!InstanceId) { - // - // no memory - // Irp->IoStatus.Information = 0; return STATUS_INSUFFICIENT_RESOURCES; } - // - // copy instance id - // wcscpy(InstanceId, Buffer); DPRINT("USBSTOR_PdoHandleQueryInstanceId %S\n", InstanceId); - // - // store result - // Irp->IoStatus.Information = (ULONG_PTR)InstanceId; - - // - // completed successfully - // return STATUS_SUCCESS; } @@ -730,53 +479,30 @@ USBSTOR_PdoHandleDeviceRelations( DPRINT("USBSTOR_PdoHandleDeviceRelations\n"); - // - // get current irp stack location - // IoStack = IoGetCurrentIrpStackLocation(Irp); - // // check if relation type is BusRelations - // if (IoStack->Parameters.QueryDeviceRelations.Type != TargetDeviceRelation) { - // // PDO handles only target device relation - // return Irp->IoStatus.Status; } - // - // allocate device relations - // DeviceRelations = (PDEVICE_RELATIONS)AllocateItem(PagedPool, sizeof(DEVICE_RELATIONS)); if (!DeviceRelations) { - // - // no memory - // return STATUS_INSUFFICIENT_RESOURCES; } - // // initialize device relations - // DeviceRelations->Count = 1; DeviceRelations->Objects[0] = DeviceObject; ObReferenceObject(DeviceObject); - // - // store result - // Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations; - - // - // completed successfully - // return STATUS_SUCCESS; } - NTSTATUS USBSTOR_PdoHandlePnp( IN PDEVICE_OBJECT DeviceObject, @@ -788,19 +514,8 @@ USBSTOR_PdoHandlePnp( PDEVICE_CAPABILITIES Caps; ULONG bDelete; - // - // get current stack location - // IoStack = IoGetCurrentIrpStackLocation(Irp); - - // - // get device extension - // DeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - - // - // sanity check - // ASSERT(DeviceExtension->Common.IsFDO == FALSE); switch(IoStack->MinorFunction) @@ -819,33 +534,21 @@ USBSTOR_PdoHandlePnp( { if (IoStack->Parameters.QueryId.IdType == BusQueryDeviceID) { - // - // handle query device id - // Status = USBSTOR_PdoHandleQueryDeviceId(DeviceObject, Irp); break; } else if (IoStack->Parameters.QueryId.IdType == BusQueryHardwareIDs) { - // - // handle instance id - // Status = USBSTOR_PdoHandleQueryHardwareId(DeviceObject, Irp); break; } else if (IoStack->Parameters.QueryId.IdType == BusQueryInstanceID) { - // - // handle instance id - // Status = USBSTOR_PdoHandleQueryInstanceId(DeviceObject, Irp); break; } else if (IoStack->Parameters.QueryId.IdType == BusQueryCompatibleIDs) { - // - // handle instance id - // Status = USBSTOR_PdoHandleQueryCompatibleId(DeviceObject, Irp); break; } @@ -861,44 +564,33 @@ USBSTOR_PdoHandlePnp( if(*DeviceExtension->PDODeviceObject != NULL) { - // - // clear entry in FDO pdo list - // *DeviceExtension->PDODeviceObject = NULL; bDelete = TRUE; } else { - // // device object already marked for deletion - // bDelete = FALSE; } - /* Complete the IRP */ Irp->IoStatus.Status = STATUS_SUCCESS; IoCompleteRequest(Irp, IO_NO_INCREMENT); if (bDelete) { - /* Delete the device object */ IoDeleteDevice(DeviceObject); } return STATUS_SUCCESS; } case IRP_MN_QUERY_CAPABILITIES: { - // // just forward irp to lower device - // Status = USBSTOR_SyncForwardIrp(DeviceExtension->LowerDeviceObject, Irp); ASSERT(Status == STATUS_SUCCESS); if (NT_SUCCESS(Status)) { - // // check if no unique id - // Caps = (PDEVICE_CAPABILITIES)IoStack->Parameters.DeviceCapabilities.Capabilities; Caps->UniqueID = FALSE; // no unique id is supported Caps->Removable = TRUE; //FIXME @@ -926,9 +618,7 @@ USBSTOR_PdoHandlePnp( } case IRP_MN_START_DEVICE: { - // // no-op for PDO - // Status = STATUS_SUCCESS; break; } @@ -939,32 +629,17 @@ USBSTOR_PdoHandlePnp( } default: { - // // do nothing - // Status = Irp->IoStatus.Status; } } - // - // complete request - // if (Status != STATUS_PENDING) { - // - // store result - // Irp->IoStatus.Status = Status; - - // - // complete request - // IoCompleteRequest(Irp, IO_NO_INCREMENT); } - // - // done processing - // return Status; } @@ -977,9 +652,6 @@ USBSTOR_CompletionRoutine( { PKEVENT Event = (PKEVENT)Ctx; - // - // signal event - // KeSetEvent(Event, 0, FALSE); return STATUS_MORE_PROCESSING_REQUIRED; } @@ -998,119 +670,68 @@ USBSTOR_AllocateIrp( PSCSI_REQUEST_BLOCK Request; PCDB pCDB; - // - // allocate irp - // Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE); if (!Irp) { - // - // no memory - // return STATUS_INSUFFICIENT_RESOURCES; } - // - // get next stack location - // IoStack = IoGetNextIrpStackLocation(Irp); - // - // create scsi block - // Request = ExAllocatePoolWithTag(NonPagedPool, sizeof(SCSI_REQUEST_BLOCK), USB_STOR_TAG); if (!Request) { - // - // no memory - // IoFreeIrp(Irp); return STATUS_INSUFFICIENT_RESOURCES; } - // - // init request - // RtlZeroMemory(Request, sizeof(SCSI_REQUEST_BLOCK)); - // // allocate data transfer block - // Request->DataBuffer = ExAllocatePoolWithTag(NonPagedPool, DataTransferLength, USB_STOR_TAG); if (!Request->DataBuffer) { - // - // no memory - // IoFreeIrp(Irp); ExFreePoolWithTag(Request, USB_STOR_TAG); return STATUS_INSUFFICIENT_RESOURCES; } - // - // allocate MDL - // Irp->MdlAddress = IoAllocateMdl(Request->DataBuffer, DataTransferLength, FALSE, FALSE, NULL); if (!Irp->MdlAddress) { - // - // no memory - // IoFreeIrp(Irp); ExFreePoolWithTag(Request->DataBuffer, USB_STOR_TAG); ExFreePoolWithTag(Request, USB_STOR_TAG); return STATUS_INSUFFICIENT_RESOURCES; } - // - // non paged pool - // MmBuildMdlForNonPagedPool(Irp->MdlAddress); - // - // init scsi block - // Request->DataTransferLength = DataTransferLength; Request->Function = SRB_FUNCTION_EXECUTE_SCSI; Request->SrbFlags = SRB_FLAGS_DATA_IN; RtlZeroMemory(Request->DataBuffer, DataTransferLength); - - // // get SCSI command data block - // pCDB = (PCDB)Request->Cdb; - // // set op code - // pCDB->AsByte[0] = OpCode; - // // store result - // IoStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; IoStack->Parameters.Others.Argument1 = Request; IoStack->DeviceObject = DeviceObject; - // - // init event - // KeInitializeEvent(Event, NotificationEvent, FALSE); - // - // lets setup a completion routine - // IoSetCompletionRoutine(Irp, USBSTOR_CompletionRoutine, (PVOID)Event, TRUE, TRUE, TRUE); - // - // output result - // *OutIrp = Irp; *OutRequest = Request; return STATUS_SUCCESS; @@ -1129,59 +750,35 @@ USBSTOR_SendIrp( PPDO_DEVICE_EXTENSION PDODeviceExtension; PSCSI_REQUEST_BLOCK Request; - // - // let's allocate an irp - // Status = USBSTOR_AllocateIrp(PDODeviceObject, DataTransferLength, OpCode, &Event, &Request, &Irp); if (!NT_SUCCESS(Status)) { - // - // failed - // DPRINT1("[USBSTOR] Failed to build irp\n"); return Status; } - // - // get device extension - // PDODeviceExtension = (PPDO_DEVICE_EXTENSION)PDODeviceObject->DeviceExtension; - // - // send irp - // ASSERT(Irp); ASSERT(PDODeviceExtension->LowerDeviceObject); Status = IoCallDriver(PDODeviceExtension->Self, Irp); if (Status == STATUS_PENDING) { - // - // wait for completion - // KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL); Status = Irp->IoStatus.Status; } if (NT_SUCCESS(Status)) { - // - // store result - // *OutData = Request->DataBuffer; } else { - // - // free the data - // ExFreePoolWithTag(Request->DataBuffer, USB_STOR_TAG); *OutData = NULL; } - // - // free resources - // ExFreePoolWithTag(Request, USB_STOR_TAG); IoFreeMdl(Irp->MdlAddress); IoFreeIrp(Irp); @@ -1196,20 +793,11 @@ USBSTOR_SendInquiryIrp( PPDO_DEVICE_EXTENSION PDODeviceExtension; PUFI_INQUIRY_RESPONSE Response; - // - // get device extension - // PDODeviceExtension = (PPDO_DEVICE_EXTENSION)PDODeviceObject->DeviceExtension; - // - // send request - // Status = USBSTOR_SendIrp(PDODeviceObject, sizeof(UFI_INQUIRY_RESPONSE), SCSIOP_INQUIRY, (PVOID*)&Response); if (!NT_SUCCESS(Status)) { - // - // command failed - // DPRINT1("USBSTOR_SendInquiryIrp Failed with %x\n", Status); return Status; } @@ -1229,9 +817,6 @@ USBSTOR_SendInquiryIrp( DPRINT1("Revision %c%c%c%c\n", Response->Revision[0], Response->Revision[1], Response->Revision[2], Response->Revision[3]); - // - // store result - // PDODeviceExtension->InquiryData = (PVOID)Response; return Status; } @@ -1244,37 +829,20 @@ USBSTOR_SendFormatCapacityIrp( PPDO_DEVICE_EXTENSION PDODeviceExtension; PUCHAR Response; - // - // get device extension - // PDODeviceExtension = (PPDO_DEVICE_EXTENSION)PDODeviceObject->DeviceExtension; - // - // send request - // Status = USBSTOR_SendIrp(PDODeviceObject, 0xFC, SCSIOP_READ_FORMATTED_CAPACITY, (PVOID*)&Response); if (!NT_SUCCESS(Status)) { - // - // command failed - // return Status; } - // - // check if its a floppy - // PDODeviceExtension->IsFloppy = USBSTOR_IsFloppy(Response, 0xFC /*FIXME*/, &PDODeviceExtension->MediumTypeCode); - // - // free response - // ExFreePoolWithTag(Response, USB_STOR_TAG); return Status; } - - NTSTATUS USBSTOR_CreatePDO( IN PDEVICE_OBJECT DeviceObject, @@ -1286,37 +854,21 @@ USBSTOR_CreatePDO( PUFI_INQUIRY_RESPONSE Response; PFDO_DEVICE_EXTENSION FDODeviceExtension; - // - // get device extension - // FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - - // // create child device object - // Status = IoCreateDevice(DeviceObject->DriverObject, sizeof(PDO_DEVICE_EXTENSION), NULL, FILE_DEVICE_MASS_STORAGE, FILE_AUTOGENERATED_DEVICE_NAME | FILE_DEVICE_SECURE_OPEN, FALSE, &PDO); if (!NT_SUCCESS(Status)) { - // - // failed to create device - // return Status; } - // // patch the stack size - // PDO->StackSize = DeviceObject->StackSize; - // - // get device extension - // PDODeviceExtension = (PPDO_DEVICE_EXTENSION)PDO->DeviceExtension; - // // initialize device extension - // RtlZeroMemory(PDODeviceExtension, sizeof(PDO_DEVICE_EXTENSION)); PDODeviceExtension->Common.IsFDO = FALSE; PDODeviceExtension->LowerDeviceObject = DeviceObject; @@ -1324,53 +876,30 @@ USBSTOR_CreatePDO( PDODeviceExtension->Self = PDO; PDODeviceExtension->LUN = LUN; - // - // set device flags - // PDO->Flags |= DO_DIRECT_IO | DO_MAP_IO_BUFFER; - // // device is initialized - // PDO->Flags &= ~DO_DEVICE_INITIALIZING; - // // output device object - // FDODeviceExtension->ChildPDO[LUN] = PDO; - // // send inquiry command by irp - // Status = USBSTOR_SendInquiryIrp(PDO); ASSERT(Status == STATUS_SUCCESS); - // - // check response data - // Response = (PUFI_INQUIRY_RESPONSE)PDODeviceExtension->InquiryData; ASSERT(Response); if (Response->DeviceType == 0) { - // // check if it is a floppy - // Status = USBSTOR_SendFormatCapacityIrp(PDO); - - // - // display result - // DPRINT1("[USBSTOR] Status %x IsFloppy %x MediumTypeCode %x\n", Status, PDODeviceExtension->IsFloppy, PDODeviceExtension->MediumTypeCode); - // // failing command is non critical - // Status = STATUS_SUCCESS; } - // - // done - // return Status; } diff --git a/drivers/usb/usbstor/queue.c b/drivers/usb/usbstor/queue.c index a945ab97c95..f4dbe5c63d9 100644 --- a/drivers/usb/usbstor/queue.c +++ b/drivers/usb/usbstor/queue.c @@ -1,12 +1,10 @@ /* * PROJECT: ReactOS Universal Serial Bus Bulk Storage Driver - * LICENSE: GPL - See COPYING in the top level directory - * FILE: drivers/usb/usbstor/queue.c + * LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later
) * PURPOSE: USB block storage device driver. - * PROGRAMMERS: - * James Tabor - * Michael Martin (michael.martin(a)reactos.org) - * Johannes Anderwald (johannes.anderwald(a)reactos.org) + * COPYRIGHT: 2005-2006 James Tabor + * 2011-2012 Michael Martin (michael.martin(a)reactos.org) + * 2011-2013 Johannes Anderwald (johannes.anderwald(a)reactos.org) */ #include "usbstor.h" @@ -14,28 +12,14 @@ #define NDEBUG #include <debug.h> + VOID USBSTOR_QueueInitialize( PFDO_DEVICE_EXTENSION FDODeviceExtension) { - // - // sanity check - // ASSERT(FDODeviceExtension->Common.IsFDO); - - // - // initialize queue lock - // KeInitializeSpinLock(&FDODeviceExtension->IrpListLock); - - // - // initialize irp list head - // InitializeListHead(&FDODeviceExtension->IrpListHead); - - // - // initialize event - // KeInitializeEvent(&FDODeviceExtension->NoPendingRequests, NotificationEvent, TRUE); } @@ -47,40 +31,18 @@ USBSTOR_CancelIo( { PFDO_DEVICE_EXTENSION FDODeviceExtension; - // - // get FDO device extension - // FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - - // - // sanity check - // - ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL); + ASSERT_IRQL_EQUAL(DISPATCH_LEVEL); ASSERT(FDODeviceExtension->Common.IsFDO); - // // this IRP isn't in our list here - // - - // // now release the cancel lock - // IoReleaseCancelSpinLock(Irp->CancelIrql); - - // - // set cancel status - // Irp->IoStatus.Status = STATUS_CANCELLED; - // - // now cancel the irp - // USBSTOR_QueueTerminateRequest(DeviceObject, Irp); IoCompleteRequest(Irp, IO_NO_INCREMENT); - // - // start the next one - // USBSTOR_QueueNextRequest(DeviceObject); } @@ -92,51 +54,20 @@ USBSTOR_Cancel( { PFDO_DEVICE_EXTENSION FDODeviceExtension; - // - // get FDO device extension - // FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - - // - // sanity check - // - ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL); + ASSERT_IRQL_EQUAL(DISPATCH_LEVEL); ASSERT(FDODeviceExtension->Common.IsFDO); - // - // acquire irp list lock - // KeAcquireSpinLockAtDpcLevel(&FDODeviceExtension->IrpListLock); - - // - // remove the irp from the list - // RemoveEntryList(&Irp->Tail.Overlay.ListEntry); - - // - // release irp list lock - // KeReleaseSpinLockFromDpcLevel(&FDODeviceExtension->IrpListLock); - // - // now release the cancel lock - // IoReleaseCancelSpinLock(Irp->CancelIrql); - - // - // set cancel status - // Irp->IoStatus.Status = STATUS_CANCELLED; - // - // now cancel the irp - // USBSTOR_QueueTerminateRequest(DeviceObject, Irp); IoCompleteRequest(Irp, IO_NO_INCREMENT); - // - // start the next one - // USBSTOR_QueueNextRequest(DeviceObject); } @@ -153,68 +84,32 @@ USBSTOR_QueueAddIrp( PIO_STACK_LOCATION IoStack = IoGetCurrentIrpStackLocation(Irp); PSCSI_REQUEST_BLOCK Request = (PSCSI_REQUEST_BLOCK)IoStack->Parameters.Others.Argument1; - // - // get FDO device extension - // FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - - // - // sanity check - // ASSERT(FDODeviceExtension->Common.IsFDO); - // - // mark irp pending - // IoMarkIrpPending(Irp); - // - // acquire lock - // KeAcquireSpinLock(&FDODeviceExtension->IrpListLock, &OldLevel); - // - // check if there are irp pending - // SrbProcessing = FDODeviceExtension->IrpPendingCount != 0; if (SrbProcessing) { - // // add irp to queue - // InsertTailList(&FDODeviceExtension->IrpListHead, &Irp->Tail.Overlay.ListEntry); } - // - // increment pending count - // FDODeviceExtension->IrpPendingCount++; - - - // - // clear the no requests pending event - // KeClearEvent(&FDODeviceExtension->NoPendingRequests); - // // check if queue is freezed - // IrpListFreeze = FDODeviceExtension->IrpListFreeze; - // - // release list lock - // KeReleaseSpinLock(&FDODeviceExtension->IrpListLock, OldLevel); - // // synchronize with cancellations by holding the cancel lock - // IoAcquireCancelSpinLock(&Irp->CancelIrql); - // - // now set the driver cancel routine - // if (SrbProcessing) { ASSERT(FDODeviceExtension->ActiveSrb != NULL); @@ -229,30 +124,17 @@ USBSTOR_QueueAddIrp( OldDriverCancel = IoSetCancelRoutine(Irp, USBSTOR_CancelIo); } - // // check if the irp has already been cancelled - // if (Irp->Cancel && OldDriverCancel == NULL) { - // // cancel irp - // Irp->CancelRoutine(DeviceObject, Irp); - - // - // irp was cancelled - // return FALSE; } - // - // release the cancel lock - // IoReleaseCancelSpinLock(Irp->CancelIrql); - // // if list is freezed, dont start this packet - // DPRINT("IrpListFreeze: %lu IrpPendingCount %lu\n", IrpListFreeze, FDODeviceExtension->IrpPendingCount); return (IrpListFreeze || SrbProcessing); @@ -267,45 +149,21 @@ USBSTOR_RemoveIrp( PLIST_ENTRY Entry; PIRP Irp = NULL; - // - // get FDO device extension - // FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - - // - // sanity check - // ASSERT(FDODeviceExtension->Common.IsFDO); - // - // acquire lock - // KeAcquireSpinLock(&FDODeviceExtension->IrpListLock, &OldLevel); - // - // check if list is empty - // if (!IsListEmpty(&FDODeviceExtension->IrpListHead)) { - // - // remove entry - // Entry = RemoveHeadList(&FDODeviceExtension->IrpListHead); - // // get offset to start of irp - // Irp = (PIRP)CONTAINING_RECORD(Entry, IRP, Tail.Overlay.ListEntry); } - // - // release list lock - // KeReleaseSpinLock(&FDODeviceExtension->IrpListLock, OldLevel); - // - // return result - // return Irp; } @@ -315,14 +173,8 @@ USBSTOR_QueueWaitForPendingRequests( { PFDO_DEVICE_EXTENSION FDODeviceExtension; - // - // get FDO device extension - // FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - // - // perform the wait - // KeWaitForSingleObject(&FDODeviceExtension->NoPendingRequests, Executive, KernelMode, @@ -340,51 +192,28 @@ USBSTOR_QueueTerminateRequest( PIO_STACK_LOCATION IoStack = IoGetCurrentIrpStackLocation(Irp); PSCSI_REQUEST_BLOCK Request = (PSCSI_REQUEST_BLOCK)IoStack->Parameters.Others.Argument1; - // - // get FDO device extension - // FDODeviceExtension = (PFDO_DEVICE_EXTENSION)FDODeviceObject->DeviceExtension; - - // - // sanity check - // ASSERT(FDODeviceExtension->Common.IsFDO); - // - // acquire lock - // KeAcquireSpinLock(&FDODeviceExtension->IrpListLock, &OldLevel); - // - // decrement pending irp count - // FDODeviceExtension->IrpPendingCount--; - // // check if this was our current active SRB - // if (FDODeviceExtension->ActiveSrb == Request) { - // // indicate processing is completed - // FDODeviceExtension->ActiveSrb = NULL; } - // // Set the event if nothing else is pending - // if (FDODeviceExtension->IrpPendingCount == 0 && FDODeviceExtension->ActiveSrb == NULL) { KeSetEvent(&FDODeviceExtension->NoPendingRequests, IO_NO_INCREMENT, FALSE); } - // - // release lock - // KeReleaseSpinLock(&FDODeviceExtension->IrpListLock, OldLevel); - } VOID @@ -396,73 +225,36 @@ USBSTOR_QueueNextRequest( PIO_STACK_LOCATION IoStack; PSCSI_REQUEST_BLOCK Request; - // - // get pdo device extension - // FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - - // - // sanity check - // ASSERT(FDODeviceExtension->Common.IsFDO); - // // check first if there's already a request pending or the queue is frozen - // if (FDODeviceExtension->ActiveSrb != NULL || FDODeviceExtension->IrpListFreeze) { - // // no work to do yet - // return; } - // // remove first irp from list - // Irp = USBSTOR_RemoveIrp(DeviceObject); - // // is there an irp pending - // if (!Irp) { - // // no work to do - // IoStartNextPacket(DeviceObject, TRUE); return; } - // - // get current stack location - // IoStack = IoGetCurrentIrpStackLocation(Irp); - - // - // get srb - // Request = (PSCSI_REQUEST_BLOCK)IoStack->Parameters.Others.Argument1; - - // - // sanity check - // ASSERT(Request); - // - // set the active SRB - // FDODeviceExtension->ActiveSrb = Request; - // // start next packet - // IoStartPacket(DeviceObject, Irp, &Request->QueueSortKey, USBSTOR_CancelIo); - - // - // start next request - // IoStartNextPacket(DeviceObject, TRUE); } @@ -476,67 +268,33 @@ USBSTOR_QueueRelease( PIO_STACK_LOCATION IoStack; PSCSI_REQUEST_BLOCK Request; - // - // get FDO device extension - // FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - - // - // sanity check - // ASSERT(FDODeviceExtension->Common.IsFDO); - // - // acquire lock - // KeAcquireSpinLock(&FDODeviceExtension->IrpListLock, &OldLevel); - // // clear freezed status - // FDODeviceExtension->IrpListFreeze = FALSE; - // - // release irp list lock - // KeReleaseSpinLock(&FDODeviceExtension->IrpListLock, OldLevel); - // // grab newest irp - // Irp = USBSTOR_RemoveIrp(DeviceObject); - // - // is there an irp - // if (!Irp) { - // - // no irp - // return; } - // - // get current irp stack location - // IoStack = IoGetCurrentIrpStackLocation(Irp); - - // - // get srb - // Request = (PSCSI_REQUEST_BLOCK)IoStack->Parameters.Others.Argument1; - // - // start new packet - // IoStartPacket(DeviceObject, Irp, &Request->QueueSortKey, USBSTOR_CancelIo); } - VOID NTAPI USBSTOR_StartIo( @@ -551,107 +309,45 @@ USBSTOR_StartIo( DPRINT("USBSTOR_StartIo\n"); - // - // get FDO device extension - // FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - - // - // sanity check - // ASSERT(FDODeviceExtension->Common.IsFDO); - // - // acquire cancel spinlock - // IoAcquireCancelSpinLock(&OldLevel); - // - // set cancel routine to zero - // IoSetCancelRoutine(Irp, NULL); - // // check if the irp has been cancelled - // if (Irp->Cancel) { - // - // irp has been cancelled, release cancel spinlock - // IoReleaseCancelSpinLock(OldLevel); - // - // irp is cancelled - // Irp->IoStatus.Status = STATUS_CANCELLED; Irp->IoStatus.Information = 0; - // - // terminate request - // USBSTOR_QueueTerminateRequest(DeviceObject, Irp); - - // - // complete request - // IoCompleteRequest(Irp, IO_NO_INCREMENT); - - // - // queue next request - // USBSTOR_QueueNextRequest(DeviceObject); - - // - // done - // return; } - // - // release cancel spinlock - // IoReleaseCancelSpinLock(OldLevel); - // - // acquire lock - // KeAcquireSpinLock(&FDODeviceExtension->IrpListLock, &OldLevel); - // - // check reset is in progress - // ResetInProgress = FDODeviceExtension->ResetInProgress; ASSERT(ResetInProgress == FALSE); - // - // release lock - // KeReleaseSpinLock(&FDODeviceExtension->IrpListLock, OldLevel); - // - // get current irp stack location - // IoStack = IoGetCurrentIrpStackLocation(Irp); - // - // get pdo device extension - // PDODeviceExtension = (PPDO_DEVICE_EXTENSION)IoStack->DeviceObject->DeviceExtension; - - // - // sanity check - // ASSERT(PDODeviceExtension->Common.IsFDO == FALSE); - // - // is a reset in progress - // + // TODO: this condition is always false if (ResetInProgress) { - // // hard reset is in progress - // Irp->IoStatus.Information = 0; Irp->IoStatus.Status = STATUS_DEVICE_DOES_NOT_EXIST; USBSTOR_QueueTerminateRequest(DeviceObject, Irp); @@ -659,12 +355,7 @@ USBSTOR_StartIo( return; } - // - // execute scsi - // USBSTOR_HandleExecuteSCSI(IoStack->DeviceObject, Irp, 0); - // // FIXME: handle error - // } diff --git a/drivers/usb/usbstor/scsi.c b/drivers/usb/usbstor/scsi.c index b5f9fbc9f2f..4c7c3efb7d7 100644 --- a/drivers/usb/usbstor/scsi.c +++ b/drivers/usb/usbstor/scsi.c @@ -1,12 +1,10 @@ /* * PROJECT: ReactOS Universal Serial Bus Bulk Storage Driver - * LICENSE: GPL - See COPYING in the top level directory - * FILE: drivers/usb/usbstor/pdo.c + * LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later
) * PURPOSE: USB block storage device driver. - * PROGRAMMERS: - * James Tabor - * Michael Martin (michael.martin(a)reactos.org) - * Johannes Anderwald (johannes.anderwald(a)reactos.org) + * COPYRIGHT: 2005-2006 James Tabor + * 2011-2012 Michael Martin (michael.martin(a)reactos.org) + * 2011-2013 Johannes Anderwald (johannes.anderwald(a)reactos.org) */ #include "usbstor.h" @@ -14,6 +12,7 @@ #define NDEBUG #include <debug.h> + NTSTATUS USBSTOR_BuildCBW( IN ULONG Tag, @@ -23,14 +22,8 @@ USBSTOR_BuildCBW( IN PUCHAR CommandBlock, IN OUT PCBW Control) { - // - // sanity check - // ASSERT(CommandBlockLength <= 16); - // - // now initialize CBW - // Control->Signature = CBW_SIGNATURE; Control->Tag = Tag; Control->DataTransferLength = DataTransferLength; @@ -38,14 +31,8 @@ USBSTOR_BuildCBW( Control->LUN = (LUN & MAX_LUN); Control->CommandBlockLength = CommandBlockLength; - // - // copy command block - // RtlCopyMemory(Control->CommandBlock, CommandBlock, CommandBlockLength); - // - // done - // return STATUS_SUCCESS; } @@ -54,45 +41,26 @@ USBSTOR_AllocateIrpContext() { PIRP_CONTEXT Context; - // - // allocate irp context - // Context = (PIRP_CONTEXT)AllocateItem(NonPagedPool, sizeof(IRP_CONTEXT)); if (!Context) { - // - // no memory - // return NULL; } - // - // allocate cbw block - // Context->cbw = (PCBW)AllocateItem(NonPagedPool, 512); if (!Context->cbw) { - // - // no memory - // FreeItem(Context); return NULL; } - // - // done - // return Context; - } BOOLEAN USBSTOR_IsCSWValid( PIRP_CONTEXT Context) { - // - // sanity checks - // if (Context->csw->Signature != CSW_SIGNATURE) { DPRINT1("[USBSTOR] Expected Signature %x but got %x\n", CSW_SIGNATURE, Context->csw->Signature); @@ -111,11 +79,7 @@ USBSTOR_IsCSWValid( return FALSE; } - // - // CSW is valid - // return TRUE; - } NTSTATUS @@ -125,31 +89,19 @@ USBSTOR_QueueWorkItem( { PERRORHANDLER_WORKITEM_DATA ErrorHandlerWorkItemData; - // - // Allocate Work Item Data - // ErrorHandlerWorkItemData = ExAllocatePoolWithTag(NonPagedPool, sizeof(ERRORHANDLER_WORKITEM_DATA), USB_STOR_TAG); if (!ErrorHandlerWorkItemData) { - // - // no memory - // return STATUS_INSUFFICIENT_RESOURCES; } - // // error handling started - // Context->FDODeviceExtension->SrbErrorHandlingActive = TRUE; - // // srb error handling finished - // Context->FDODeviceExtension->TimerWorkQueueEnabled = FALSE; - // // Initialize and queue the work item to handle the error - // ExInitializeWorkItem(&ErrorHandlerWorkItemData->WorkQueueItem, ErrorHandlerWorkItemRoutine, ErrorHandlerWorkItemData); @@ -164,10 +116,6 @@ USBSTOR_QueueWorkItem( return STATUS_MORE_PROCESSING_REQUIRED; } - -// -// driver verifier -// IO_COMPLETION_ROUTINE USBSTOR_CSWCompletionRoutine; NTSTATUS @@ -186,37 +134,21 @@ USBSTOR_CSWCompletionRoutine( PUFI_CAPACITY_RESPONSE Response; NTSTATUS Status; - // - // access context - // Context = (PIRP_CONTEXT)Ctx; - // - // is there a mdl - // if (Context->TransferBufferMDL) { - // // is there an irp associated - // if (Context->Irp) { - // // did we allocate the mdl - // if (Context->TransferBufferMDL != Context->Irp->MdlAddress) { - // - // free mdl - // IoFreeMdl(Context->TransferBufferMDL); } } else { - // - // free mdl - // IoFreeMdl(Context->TransferBufferMDL); } } @@ -227,22 +159,15 @@ USBSTOR_CSWCompletionRoutine( { if (Context->ErrorIndex == 0) { - // - // increment error index - // Context->ErrorIndex = 1; - // // clear stall and resend cbw - // Status = USBSTOR_QueueWorkItem(Context, Irp); ASSERT(Status == STATUS_MORE_PROCESSING_REQUIRED); return STATUS_MORE_PROCESSING_REQUIRED; } - // // perform reset recovery - // Context->ErrorIndex = 2; IoFreeIrp(Irp); Status = USBSTOR_QueueWorkItem(Context, NULL); @@ -252,9 +177,7 @@ USBSTOR_CSWCompletionRoutine( if (!USBSTOR_IsCSWValid(Context)) { - // // perform reset recovery - // Context->ErrorIndex = 2; IoFreeIrp(Irp); Status = USBSTOR_QueueWorkItem(Context, NULL); @@ -263,115 +186,65 @@ USBSTOR_CSWCompletionRoutine( } - // - // get current stack location - // IoStack = IoGetCurrentIrpStackLocation(Context->Irp); - // - // get request block - // Request = (PSCSI_REQUEST_BLOCK)IoStack->Parameters.Others.Argument1; ASSERT(Request); Status = Irp->IoStatus.Status; - // - // get SCSI command data block - // pCDB = (PCDB)Request->Cdb; Request->SrbStatus = SRB_STATUS_SUCCESS; - // // read capacity needs special work - // if (pCDB->AsByte[0] == SCSIOP_READ_CAPACITY) { - // // get output buffer - // Response = (PUFI_CAPACITY_RESPONSE)Context->TransferData; - // // store in pdo - // Context->PDODeviceExtension->BlockLength = NTOHL(Response->BlockLength); Context->PDODeviceExtension->LastLogicBlockAddress = NTOHL(Response->LastLogicalBlockAddress); if (Request->DataTransferLength == sizeof(READ_CAPACITY_DATA_EX)) { - // // get input buffer - // CapacityDataEx = (PREAD_CAPACITY_DATA_EX)Request->DataBuffer; - // // set result - // CapacityDataEx->BytesPerBlock = Response->BlockLength; CapacityDataEx->LogicalBlockAddress.QuadPart = Response->LastLogicalBlockAddress; Irp->IoStatus.Information = sizeof(READ_CAPACITY_DATA_EX); } else { - // // get input buffer - // CapacityData = (PREAD_CAPACITY_DATA)Request->DataBuffer; - // // set result - // CapacityData->BytesPerBlock = Response->BlockLength; CapacityData->LogicalBlockAddress = Response->LastLogicalBlockAddress; Irp->IoStatus.Information = sizeof(READ_CAPACITY_DATA); } - // - // free response - // FreeItem(Context->TransferData); } - // - // free cbw - // FreeItem(Context->cbw); - // // FIXME: check status - // Context->Irp->IoStatus.Status = Irp->IoStatus.Status; Context->Irp->IoStatus.Information = Context->TransferDataLength; - // // terminate current request - // USBSTOR_QueueTerminateRequest(Context->PDODeviceExtension->LowerDeviceObject, Context->Irp); - // - // complete request - // IoCompleteRequest(Context->Irp, IO_NO_INCREMENT); - // - // start next request - // USBSTOR_QueueNextRequest(Context->PDODeviceExtension->LowerDeviceObject); - // - // free our allocated irp - // IoFreeIrp(Irp); - - // - // free context - // FreeItem(Context); - - // - // done - // return STATUS_MORE_PROCESSING_REQUIRED; } @@ -382,14 +255,9 @@ USBSTOR_SendCSW( { PIO_STACK_LOCATION IoStack; - // - // get next irp stack location - // IoStack = IoGetNextIrpStackLocation(Irp); - // // now initialize the urb for sending the csw - // UsbBuildInterruptOrBulkTransferRequest(&Context->Urb, sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER), Context->FDODeviceExtension->InterfaceInformation->Pipes[Context->FDODeviceExtension->BulkInPipeIndex].PipeHandle, @@ -399,31 +267,18 @@ USBSTOR_SendCSW( USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK, NULL); - // // initialize stack location - // IoStack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL; IoStack->Parameters.DeviceIoControl.IoControlCode = IOCTL_INTERNAL_USB_SUBMIT_URB; IoStack->Parameters.Others.Argument1 = (PVOID)&Context->Urb; IoStack->Parameters.DeviceIoControl.InputBufferLength = Context->Urb.UrbHeader.Length; Irp->IoStatus.Status = STATUS_SUCCESS; - - // - // setup completion routine - // IoSetCompletionRoutine(Irp, USBSTOR_CSWCompletionRoutine, Context, TRUE, TRUE, TRUE); - // - // call driver - // IoCallDriver(Context->FDODeviceExtension->LowerDeviceObject, Irp); } - -// -// driver verifier -// IO_COMPLETION_ROUTINE USBSTOR_DataCompletionRoutine; NTSTATUS @@ -439,36 +294,22 @@ USBSTOR_DataCompletionRoutine( DPRINT("USBSTOR_DataCompletionRoutine Irp %p Ctx %p Status %x\n", Irp, Ctx, Irp->IoStatus.Status); - // - // access context - // Context = (PIRP_CONTEXT)Ctx; if (!NT_SUCCESS(Irp->IoStatus.Status)) { - // // clear stall and resend cbw - // Context->ErrorIndex = 1; Status = USBSTOR_QueueWorkItem(Context, Irp); ASSERT(Status == STATUS_MORE_PROCESSING_REQUIRED); return STATUS_MORE_PROCESSING_REQUIRED; } - // - // send csw - // USBSTOR_SendCSW(Context, Irp); - // - // cancel completion - // return STATUS_MORE_PROCESSING_REQUIRED; } -// -// driver verifier -// IO_COMPLETION_ROUTINE USBSTOR_CBWCompletionRoutine; NTSTATUS @@ -485,44 +326,27 @@ USBSTOR_CBWCompletionRoutine( DPRINT("USBSTOR_CBWCompletionRoutine Irp %p Ctx %p Status %x\n", Irp, Ctx, Irp->IoStatus.Status); - // - // access context - // Context = (PIRP_CONTEXT)Ctx; - - // - // get next stack location - // IoStack = IoGetNextIrpStackLocation(Irp); - // // is there data to be submitted - // if (Context->TransferDataLength) { - // // get command code - // Code = Context->cbw->CommandBlock[0]; if (Code == SCSIOP_WRITE) { - // - // write request use bulk out pipe - // + // write request - use bulk out pipe PipeHandle = Context->FDODeviceExtension->InterfaceInformation->Pipes[Context->FDODeviceExtension->BulkOutPipeIndex].PipeHandle; } else { - // // default bulk in pipe - // PipeHandle = Context->FDODeviceExtension->InterfaceInformation->Pipes[Context->FDODeviceExtension->BulkInPipeIndex].PipeHandle; } - // // now initialize the urb for sending data - // UsbBuildInterruptOrBulkTransferRequest(&Context->Urb, sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER), PipeHandle, @@ -532,17 +356,11 @@ USBSTOR_CBWCompletionRoutine( ((Code == SCSIOP_WRITE) ? USBD_TRANSFER_DIRECTION_OUT : (USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK)), NULL); - // - // setup completion routine - // IoSetCompletionRoutine(Irp, USBSTOR_DataCompletionRoutine, Context, TRUE, TRUE, TRUE); } else { - // // now initialize the urb for sending the csw - // - UsbBuildInterruptOrBulkTransferRequest(&Context->Urb, sizeof(struct _URB_BULK_OR_INTERRUPT_TRANSFER), Context->FDODeviceExtension->InterfaceInformation->Pipes[Context->FDODeviceExtension->BulkInPipeIndex].PipeHandle, @@ -552,24 +370,16 @@ USBSTOR_CBWCompletionRoutine( USBD_TRANSFER_DIRECTION_IN | USBD_SHORT_TRANSFER_OK, NULL); ... 880 lines suppressed ...
5 years, 6 months
1
0
0
0
[reactos] 01/01: [NTOSKRNL] Fix ObpLUIDDeviceMapsEnabled initialization
by Pierre Schweitzer
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=33604e014768009d2c66c…
commit 33604e014768009d2c66c106d54d6d22945063fa Author: Pierre Schweitzer <pierre(a)reactos.org> AuthorDate: Mon Jun 10 21:16:41 2019 +0200 Commit: Pierre Schweitzer <pierre(a)reactos.org> CommitDate: Mon Jun 10 21:17:21 2019 +0200 [NTOSKRNL] Fix ObpLUIDDeviceMapsEnabled initialization --- ntoskrnl/ob/obname.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ntoskrnl/ob/obname.c b/ntoskrnl/ob/obname.c index 5700d43d5ca..460338f0d48 100644 --- a/ntoskrnl/ob/obname.c +++ b/ntoskrnl/ob/obname.c @@ -188,6 +188,8 @@ ObpCreateDosDevicesDirectory(VOID) */ if (ObpProtectionMode == 0 || ObpLUIDDeviceMapsDisabled != 0) ObpLUIDDeviceMapsEnabled = 0; + else + ObpLUIDDeviceMapsEnabled = 1; /* Create a custom security descriptor for the global DosDevices directory */ Status = ObpGetDosDevicesProtection(&DosDevicesSD);
5 years, 6 months
1
0
0
0
[reactos] 01/01: [NETCFGX] Do not update the TCP/IP properties when the cancels the advanced properties dialog.
by Eric Kohl
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=8f285f71c95701d997cd5…
commit 8f285f71c95701d997cd5b9af190d3f3c20abba3 Author: Eric Kohl <eric.kohl(a)reactos.org> AuthorDate: Mon Jun 10 20:27:45 2019 +0200 Commit: Eric Kohl <eric.kohl(a)reactos.org> CommitDate: Mon Jun 10 20:28:58 2019 +0200 [NETCFGX] Do not update the TCP/IP properties when the cancels the advanced properties dialog. CORE-9908 --- dll/win32/netcfgx/tcpipconf_notify.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/dll/win32/netcfgx/tcpipconf_notify.c b/dll/win32/netcfgx/tcpipconf_notify.c index 0fa79d860a1..208a9496d2e 100644 --- a/dll/win32/netcfgx/tcpipconf_notify.c +++ b/dll/win32/netcfgx/tcpipconf_notify.c @@ -2139,10 +2139,11 @@ LaunchAdvancedTcpipSettings( pinfo.pfnCallback = PropSheetProc; StoreTcpipBasicSettings(hwndDlg, This, FALSE); - PropertySheetW(&pinfo); - - InitializeTcpipBasicDlgCtrls(hwndDlg, This->pCurrentConfig); - PropSheet_Changed(GetParent(hwndDlg), hwndDlg); + if (PropertySheetW(&pinfo) > 0) + { + InitializeTcpipBasicDlgCtrls(hwndDlg, This->pCurrentConfig); + PropSheet_Changed(GetParent(hwndDlg), hwndDlg); + } } INT_PTR
5 years, 6 months
1
0
0
0
[reactos] 01/01: [NETPLWIZ] Add French translation
by Pierre Schweitzer
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=72d229b38c206254098ae…
commit 72d229b38c206254098aedf115c4a8ab3e870e16 Author: Pierre Schweitzer <pierre(a)reactos.org> AuthorDate: Mon Jun 10 19:01:04 2019 +0200 Commit: Pierre Schweitzer <pierre(a)reactos.org> CommitDate: Mon Jun 10 19:01:30 2019 +0200 [NETPLWIZ] Add French translation --- dll/shellext/netplwiz/lang/fr-FR.rc | 21 +++++++++++++++++++++ dll/shellext/netplwiz/netplwiz.rc | 3 +++ 2 files changed, 24 insertions(+) diff --git a/dll/shellext/netplwiz/lang/fr-FR.rc b/dll/shellext/netplwiz/lang/fr-FR.rc new file mode 100644 index 00000000000..657ed65ed47 --- /dev/null +++ b/dll/shellext/netplwiz/lang/fr-FR.rc @@ -0,0 +1,21 @@ +LANGUAGE LANG_FRENCH, SUBLANG_NEUTRAL + +IDD_DISCONNECTDRIVES DIALOGEX 0, 0, 300, 200 +STYLE DS_SHELLFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Déconnecter un lecteur réseau" +FONT 8, "MS Shell Dlg" +BEGIN + LTEXT "Sélectionnez le(s) lecteur(s) réseau que vous voulez déconnecter, puis cliquez sur OK.", -1, 7, 7, 286, 8 + LTEXT "&Lecteurs réseau :", -1, 7, 23, 286, 8 + CONTROL "", IDC_CONNECTEDDRIVELIST, "SysListView32", LVS_REPORT | LVS_SHOWSELALWAYS | LVS_SORTASCENDING | LVS_SINGLESEL | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_TABSTOP, 7, 31, 286, 140 + PUSHBUTTON "OK", ID_OK, 189, 179, 50, 14 + PUSHBUTTON "Annuler", IDCANCEL, 243, 179, 50, 14 +END + +STRINGTABLE +BEGIN + IDS_DIALOG_CAPTION "Déconnecter un lecteur réseau" + IDS_DRIVE_LETTER "Lecteur" + IDS_NETWORK_PATH "Chemin réseau" + IDS_NO_DRIVES "Vous n'avez pas de lecteurs réseau à déconnecter." +END diff --git a/dll/shellext/netplwiz/netplwiz.rc b/dll/shellext/netplwiz/netplwiz.rc index aac48703fbf..27bd8c14e65 100644 --- a/dll/shellext/netplwiz/netplwiz.rc +++ b/dll/shellext/netplwiz/netplwiz.rc @@ -24,3 +24,6 @@ IDI_DISCONNECT_NET_DRIVES ICON "res/4400.ico" #ifdef LANGUAGE_EN_US #include "lang/en-US.rc" #endif +#ifdef LANGUAGE_FR_FR + #include "lang/fr-FR.rc" +#endif
5 years, 6 months
1
0
0
0
← Newer
1
...
16
17
18
19
20
21
22
...
29
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Results per page:
10
25
50
100
200