ReactOS  0.4.15-dev-1197-g8081ba9
pdo.c File Reference
#include "usbstor.h"
#include <debug.h>
Include dependency graph for pdo.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static LPCSTR USBSTOR_GetDeviceType (IN PINQUIRYDATA InquiryData)
 
static LPCSTR USBSTOR_GetGenericType (IN PINQUIRYDATA InquiryData)
 
static ULONG CopyField (IN PUCHAR Name, IN PCHAR Buffer, IN ULONG MaxLength)
 
static ULONG CopyFieldTruncate (IN PUCHAR Name, IN PCHAR Buffer, IN ULONG MaxLength)
 
NTSTATUS USBSTOR_PdoHandleQueryDeviceText (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS USBSTOR_PdoHandleQueryDeviceId (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
VOID USBSTOR_ConvertToUnicodeString (IN CHAR *Buffer, IN ULONG ResultBufferLength, IN ULONG ResultBufferOffset, OUT LPWSTR ResultBuffer, OUT PULONG NewResultBufferOffset)
 
NTSTATUS USBSTOR_PdoHandleQueryHardwareId (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS USBSTOR_PdoHandleQueryCompatibleId (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS USBSTOR_PdoHandleQueryInstanceId (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS USBSTOR_PdoHandleDeviceRelations (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS USBSTOR_PdoHandlePnp (IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
 
NTSTATUS NTAPI USBSTOR_SyncCompletionRoutine (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Ctx)
 
static NTSTATUS USBSTOR_SendInternalCdb (IN PDEVICE_OBJECT PdoDevice, IN PCDB Cdb, IN UCHAR CdbLength, IN ULONG TimeOutValue, OUT PVOID OutDataBuffer, OUT PULONG OutDataTransferLength)
 
static NTSTATUS USBSTOR_FillInquiryData (IN PDEVICE_OBJECT PDODeviceObject)
 
NTSTATUS USBSTOR_CreatePDO (IN PDEVICE_OBJECT DeviceObject, IN UCHAR LUN)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file pdo.c.

Function Documentation

◆ CopyField()

static ULONG CopyField ( IN PUCHAR  Name,
IN PCHAR  Buffer,
IN ULONG  MaxLength 
)
static

Definition at line 70 of file pdo.c.

74 {
75  ULONG Index;
76 
77  for (Index = 0; Index < MaxLength; Index++)
78  {
79  if (Name[Index] <= ' ' || Name[Index] >= 0x7F /* last printable ascii character */ || Name[Index] == ',')
80  {
81  // convert to underscore
82  Buffer[Index] = '_';
83  }
84  else
85  {
86  // just copy character
87  Buffer[Index] = Name[Index];
88  }
89  }
90 
91  return MaxLength;
92 }
Definition: bufpool.h:45
static const UCHAR Index[8]
Definition: usbohci.c:18
unsigned int ULONG
Definition: retypes.h:1

Referenced by USBSTOR_PdoHandleQueryDeviceId(), and USBSTOR_PdoHandleQueryHardwareId().

◆ CopyFieldTruncate()

static ULONG CopyFieldTruncate ( IN PUCHAR  Name,
IN PCHAR  Buffer,
IN ULONG  MaxLength 
)
static

Definition at line 96 of file pdo.c.

100 {
101  ULONG Index;
102 
103  for (Index = 0; Index < MaxLength; Index++)
104  {
105  if (Name[Index] == '\0')
106  {
107  break;
108  }
109  else if (Name[Index] <= ' ' || Name[Index] >= 0x7F /* last printable ascii character */ || Name[Index] == ',')
110  {
111  // convert to underscore
112  Buffer[Index] = ' ';
113  }
114  else
115  {
116  // just copy character
117  Buffer[Index] = Name[Index];
118  }
119  }
120 
121  return Index;
122 }
Definition: bufpool.h:45
static const UCHAR Index[8]
Definition: usbohci.c:18
unsigned int ULONG
Definition: retypes.h:1

Referenced by USBSTOR_PdoHandleQueryDeviceText().

◆ USBSTOR_ConvertToUnicodeString()

VOID USBSTOR_ConvertToUnicodeString ( IN CHAR Buffer,
IN ULONG  ResultBufferLength,
IN ULONG  ResultBufferOffset,
OUT LPWSTR  ResultBuffer,
OUT PULONG  NewResultBufferOffset 
)

Definition at line 232 of file pdo.c.

238 {
239  UNICODE_STRING DeviceString;
242 
243  ASSERT(ResultBufferLength);
244  ASSERT(ResultBufferLength > ResultBufferOffset);
245 
246  DPRINT("ResultBufferOffset %lu ResultBufferLength %lu Buffer %s Length %lu\n", ResultBufferOffset, ResultBufferLength, Buffer, strlen(Buffer));
247 
248  // construct destination string
249  DeviceString.Buffer = &ResultBuffer[ResultBufferOffset];
250  DeviceString.Length = 0;
251  DeviceString.MaximumLength = (ResultBufferLength - ResultBufferOffset) * sizeof(WCHAR);
252 
253  // initialize source string
255 
258 
259  // subtract consumed bytes
260  ResultBufferLength -= (DeviceString.Length + sizeof(WCHAR)) / sizeof(WCHAR);
261  ResultBufferOffset += (DeviceString.Length + sizeof(WCHAR)) / sizeof(WCHAR);
262 
263  *NewResultBufferOffset = ResultBufferOffset;
264 }
USHORT MaximumLength
Definition: env_spec_w32.h:370
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
LONG NTSTATUS
Definition: precomp.h:26
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define FALSE
Definition: types.h:117
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
__wchar_t WCHAR
Definition: xmlstorage.h:180
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
return STATUS_SUCCESS
Definition: btrfs.c:3014
PKMT_RESULTBUFFER ResultBuffer

Referenced by USBSTOR_PdoHandleQueryCompatibleId(), and USBSTOR_PdoHandleQueryHardwareId().

◆ USBSTOR_CreatePDO()

NTSTATUS USBSTOR_CreatePDO ( IN PDEVICE_OBJECT  DeviceObject,
IN UCHAR  LUN 
)

Definition at line 843 of file pdo.c.

846 {
847  PDEVICE_OBJECT PDO;
849  PPDO_DEVICE_EXTENSION PDODeviceExtension;
850  PFDO_DEVICE_EXTENSION FDODeviceExtension;
851  PINQUIRYDATA InquiryData;
852 
853  FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
854 
855  // create child device object
857  if (!NT_SUCCESS(Status))
858  {
859  DPRINT1("Failed to create PDO, status %x\n", Status);
860  return Status;
861  }
862 
863  // patch the stack size
864  PDO->StackSize = DeviceObject->StackSize;
865 
866  PDODeviceExtension = (PPDO_DEVICE_EXTENSION)PDO->DeviceExtension;
867  InquiryData = (PINQUIRYDATA)&PDODeviceExtension->InquiryData;
868 
869  // initialize device extension
870  RtlZeroMemory(PDODeviceExtension, sizeof(PDO_DEVICE_EXTENSION));
871  PDODeviceExtension->Common.IsFDO = FALSE;
872  PDODeviceExtension->LowerDeviceObject = DeviceObject;
873  PDODeviceExtension->PDODeviceObject = &FDODeviceExtension->ChildPDO[LUN];
874  PDODeviceExtension->Self = PDO;
875  PDODeviceExtension->LUN = LUN;
876 
877  PDO->Flags |= DO_DIRECT_IO;
878 
879  // device is initialized
880  PDO->Flags &= ~DO_DEVICE_INITIALIZING;
881 
882  // output device object
883  FDODeviceExtension->ChildPDO[LUN] = PDO;
884 
885  // send inquiry command by irp
887 
888  if (!NT_SUCCESS(Status))
889  {
890  return Status;
891  }
892 
893  if (InquiryData->DeviceType != DIRECT_ACCESS_DEVICE &&
895  {
896  return STATUS_NOT_SUPPORTED;
897  }
898 
899  return Status;
900 }
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
LONG NTSTATUS
Definition: precomp.h:26
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
#define FILE_DEVICE_MASS_STORAGE
Definition: imports.h:62
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
#define FALSE
Definition: types.h:117
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:56
#define FILE_AUTOGENERATED_DEVICE_NAME
Definition: iotypes.h:138
#define DIRECT_ACCESS_DEVICE
Definition: cdrw_hw.h:1144
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
UCHAR DeviceType
Definition: cdrw_hw.h:1116
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define DPRINT1
Definition: precomp.h:8
#define READ_ONLY_DIRECT_ACCESS_DEVICE
Definition: cdrw_hw.h:1149
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
static NTSTATUS USBSTOR_FillInquiryData(IN PDEVICE_OBJECT PDODeviceObject)
Definition: pdo.c:803

Referenced by USBSTOR_FdoHandleStartDevice().

◆ USBSTOR_FillInquiryData()

static NTSTATUS USBSTOR_FillInquiryData ( IN PDEVICE_OBJECT  PDODeviceObject)
static

Definition at line 803 of file pdo.c.

805 {
807  PPDO_DEVICE_EXTENSION PDODeviceExtension = (PPDO_DEVICE_EXTENSION)PDODeviceObject->DeviceExtension;
808  CDB Cdb;
809  ULONG DataTransferLength = INQUIRYDATABUFFERSIZE;
810  PINQUIRYDATA InquiryData = (PINQUIRYDATA)&PDODeviceExtension->InquiryData;
811 
812  RtlZeroMemory(&Cdb, sizeof(Cdb));
813  Cdb.CDB6INQUIRY.OperationCode = SCSIOP_INQUIRY;
814  Cdb.CDB6INQUIRY.AllocationLength = INQUIRYDATABUFFERSIZE;
815 
816  Status = USBSTOR_SendInternalCdb(PDODeviceObject, &Cdb, CDB6GENERIC_LENGTH, 20, InquiryData, &DataTransferLength);
817 
818  if (!NT_SUCCESS(Status))
819  {
820  DPRINT1("USBSTOR_FillInquiryData failed with %x\n", Status);
821  return Status;
822  }
823 
824  DPRINT("DeviceType %x\n", InquiryData->DeviceType);
825  DPRINT("DeviceTypeModifier %x\n", InquiryData->DeviceTypeModifier);
826  DPRINT("RemovableMedia %x\n", InquiryData->RemovableMedia);
827  DPRINT("Version %x\n", InquiryData->Versions);
828  DPRINT("Format %x\n", InquiryData->ResponseDataFormat);
829  DPRINT("Length %x\n", InquiryData->AdditionalLength);
830  DPRINT("Reserved %p\n", InquiryData->Reserved);
831  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]);
832  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],
833  InquiryData->ProductId[4], InquiryData->ProductId[5], InquiryData->ProductId[6], InquiryData->ProductId[7],
834  InquiryData->ProductId[8], InquiryData->ProductId[9], InquiryData->ProductId[10], InquiryData->ProductId[11],
835  InquiryData->ProductId[12], InquiryData->ProductId[13], InquiryData->ProductId[14], InquiryData->ProductId[15]);
836 
837  DPRINT("Revision %c%c%c%c\n", InquiryData->ProductRevisionLevel[0], InquiryData->ProductRevisionLevel[1], InquiryData->ProductRevisionLevel[2], InquiryData->ProductRevisionLevel[3]);
838 
839  return Status;
840 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
Definition: cdrw_hw.h:28
LONG NTSTATUS
Definition: precomp.h:26
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
static NTSTATUS USBSTOR_SendInternalCdb(IN PDEVICE_OBJECT PdoDevice, IN PCDB Cdb, IN UCHAR CdbLength, IN ULONG TimeOutValue, OUT PVOID OutDataBuffer, OUT PULONG OutDataTransferLength)
Definition: pdo.c:669
#define INQUIRYDATABUFFERSIZE
Definition: cdrw_hw.h:1113
void DPRINT(...)
Definition: polytest.cpp:61
#define SCSIOP_INQUIRY
Definition: cdrw_hw.h:888
#define CDB6GENERIC_LENGTH
Definition: cdrw_hw.h:830
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_opt_ WDFREQUEST _In_ ULONG _In_ BOOLEAN _In_ PCDB Cdb
Definition: scratch.h:156
Status
Definition: gdiplustypes.h:24
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
struct _CDB::_CDB6INQUIRY CDB6INQUIRY

Referenced by USBSTOR_CreatePDO().

◆ USBSTOR_GetDeviceType()

static LPCSTR USBSTOR_GetDeviceType ( IN PINQUIRYDATA  InquiryData)
static

Definition at line 20 of file pdo.c.

22 {
23  switch (InquiryData->DeviceType)
24  {
26  return "Disk";
28  // sequential device, i.e magnetic tape
29  return "Sequential";
31  return "Worm";
33  return "CdRom";
34  case OPTICAL_DEVICE:
35  return "Optical";
36  case MEDIUM_CHANGER:
37  return "Changer";
38  default:
39  return "Other";
40  }
41 }
#define WRITE_ONCE_READ_MULTIPLE_DEVICE
Definition: cdrw_hw.h:1148
#define SEQUENTIAL_ACCESS_DEVICE
Definition: cdrw_hw.h:1145
#define DIRECT_ACCESS_DEVICE
Definition: cdrw_hw.h:1144
#define OPTICAL_DEVICE
Definition: cdrw_hw.h:1151
#define MEDIUM_CHANGER
Definition: cdrw_hw.h:1152
#define READ_ONLY_DIRECT_ACCESS_DEVICE
Definition: cdrw_hw.h:1149

Referenced by USBSTOR_PdoHandleQueryCompatibleId(), USBSTOR_PdoHandleQueryDeviceId(), and USBSTOR_PdoHandleQueryHardwareId().

◆ USBSTOR_GetGenericType()

static LPCSTR USBSTOR_GetGenericType ( IN PINQUIRYDATA  InquiryData)
static

Definition at line 45 of file pdo.c.

47 {
48  switch (InquiryData->DeviceType)
49  {
51  return "GenDisk";
53  // sequential device, i.e magnetic tape
54  return "GenSequential";
56  return "GenWorm";
58  return "GenCdRom";
59  case OPTICAL_DEVICE:
60  return "GenOptical";
61  case MEDIUM_CHANGER:
62  return "GenChanger";
63  default:
64  return "UsbstorOther";
65  }
66 }
#define WRITE_ONCE_READ_MULTIPLE_DEVICE
Definition: cdrw_hw.h:1148
#define SEQUENTIAL_ACCESS_DEVICE
Definition: cdrw_hw.h:1145
#define DIRECT_ACCESS_DEVICE
Definition: cdrw_hw.h:1144
#define OPTICAL_DEVICE
Definition: cdrw_hw.h:1151
#define MEDIUM_CHANGER
Definition: cdrw_hw.h:1152
#define READ_ONLY_DIRECT_ACCESS_DEVICE
Definition: cdrw_hw.h:1149

Referenced by USBSTOR_PdoHandleQueryHardwareId().

◆ USBSTOR_PdoHandleDeviceRelations()

NTSTATUS USBSTOR_PdoHandleDeviceRelations ( IN PDEVICE_OBJECT  DeviceObject,
IN OUT PIRP  Irp 
)

Definition at line 477 of file pdo.c.

480 {
481  PDEVICE_RELATIONS DeviceRelations;
482  PIO_STACK_LOCATION IoStack;
483 
484  DPRINT("USBSTOR_PdoHandleDeviceRelations\n");
485 
487 
488  // check if relation type is BusRelations
489  if (IoStack->Parameters.QueryDeviceRelations.Type != TargetDeviceRelation)
490  {
491  // PDO handles only target device relation
492  return Irp->IoStatus.Status;
493  }
494 
495  DeviceRelations = ExAllocatePoolWithTag(PagedPool, sizeof(DEVICE_RELATIONS), USB_STOR_TAG);
496  if (!DeviceRelations)
497  {
499  }
500 
501  // initialize device relations
502  DeviceRelations->Count = 1;
503  DeviceRelations->Objects[0] = DeviceObject;
505 
506  Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
507  return STATUS_SUCCESS;
508 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PIRP Irp
Definition: csq.h:116
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2143
void DPRINT(...)
Definition: polytest.cpp:61
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define USB_STOR_TAG
Definition: usbstor.h:10
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define ObReferenceObject
Definition: obfuncs.h:204
#define ULONG_PTR
Definition: config.h:101
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by USBSTOR_PdoHandlePnp().

◆ USBSTOR_PdoHandlePnp()

NTSTATUS USBSTOR_PdoHandlePnp ( IN PDEVICE_OBJECT  DeviceObject,
IN OUT PIRP  Irp 
)

Definition at line 511 of file pdo.c.

514 {
515  PIO_STACK_LOCATION IoStack;
516  PPDO_DEVICE_EXTENSION DeviceExtension;
519  ULONG bDelete;
520 
522  DeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
523  ASSERT(DeviceExtension->Common.IsFDO == FALSE);
524 
525  switch(IoStack->MinorFunction)
526  {
528  {
530  break;
531  }
533  {
535  break;
536  }
537  case IRP_MN_QUERY_ID:
538  {
539  if (IoStack->Parameters.QueryId.IdType == BusQueryDeviceID)
540  {
542  break;
543  }
544  else if (IoStack->Parameters.QueryId.IdType == BusQueryHardwareIDs)
545  {
547  break;
548  }
549  else if (IoStack->Parameters.QueryId.IdType == BusQueryInstanceID)
550  {
552  break;
553  }
554  else if (IoStack->Parameters.QueryId.IdType == BusQueryCompatibleIDs)
555  {
557  break;
558  }
559 
560  DPRINT1("USBSTOR_PdoHandlePnp: IRP_MN_QUERY_ID IdType %x unimplemented\n", IoStack->Parameters.QueryId.IdType);
562  Irp->IoStatus.Information = 0;
563  break;
564  }
566  {
567  DPRINT("IRP_MN_REMOVE_DEVICE\n");
568 
569  if(*DeviceExtension->PDODeviceObject != NULL)
570  {
571  *DeviceExtension->PDODeviceObject = NULL;
572  bDelete = TRUE;
573  }
574  else
575  {
576  // device object already marked for deletion
577  bDelete = FALSE;
578  }
579 
580  Irp->IoStatus.Status = STATUS_SUCCESS;
582 
583  if (bDelete)
584  {
586  }
587  return STATUS_SUCCESS;
588  }
590  {
591  // just forward irp to lower device
592  Status = USBSTOR_SyncForwardIrp(DeviceExtension->LowerDeviceObject, Irp);
594 
595  if (NT_SUCCESS(Status))
596  {
597  // check if no unique id
598  Caps = (PDEVICE_CAPABILITIES)IoStack->Parameters.DeviceCapabilities.Capabilities;
599  Caps->UniqueID = FALSE; // no unique id is supported
600  Caps->Removable = TRUE; //FIXME
601  }
602  break;
603  }
606  {
607 #if 0
608  //
609  // if we're not claimed it's ok
610  //
611  if (DeviceExtension->Claimed)
612 #else
613  if (TRUE)
614 #endif
615  {
617  DPRINT1("[USBSTOR] Request %x fails because device is still claimed\n", IoStack->MinorFunction);
618  }
619  else
621  break;
622  }
623  case IRP_MN_START_DEVICE:
624  {
625  // no-op for PDO
627  break;
628  }
630  {
632  break;
633  }
634  default:
635  {
636  // do nothing
637  Status = Irp->IoStatus.Status;
638  }
639  }
640 
641  if (Status != STATUS_PENDING)
642  {
643  Irp->IoStatus.Status = Status;
645  }
646 
647  return Status;
648 }
#define IRP_MN_REMOVE_DEVICE
#define IRP_MN_QUERY_ID
NTSTATUS USBSTOR_PdoHandleDeviceRelations(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: pdo.c:477
_In_ PIRP Irp
Definition: csq.h:116
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS USBSTOR_PdoHandleQueryDeviceText(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: pdo.c:125
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
NTSTATUS USBSTOR_PdoHandleQueryDeviceId(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: pdo.c:179
#define FALSE
Definition: types.h:117
#define IRP_MN_QUERY_REMOVE_DEVICE
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
NTSTATUS NTAPI USBSTOR_SyncForwardIrp(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: misc.c:34
NTSTATUS USBSTOR_PdoHandleQueryInstanceId(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: pdo.c:434
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:56
void DPRINT(...)
Definition: polytest.cpp:61
#define IRP_MN_QUERY_STOP_DEVICE
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IRP_MN_START_DEVICE
#define IRP_MN_QUERY_DEVICE_TEXT
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
NTSTATUS USBSTOR_PdoHandleQueryCompatibleId(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: pdo.c:394
Status
Definition: gdiplustypes.h:24
NTSTATUS USBSTOR_PdoHandleQueryHardwareId(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: pdo.c:267
* PDEVICE_CAPABILITIES
Definition: iotypes.h:948
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define DPRINT1
Definition: precomp.h:8
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:581
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
return STATUS_SUCCESS
Definition: btrfs.c:3014
#define IRP_MN_QUERY_CAPABILITIES

Referenced by USBSTOR_DispatchPnp().

◆ USBSTOR_PdoHandleQueryCompatibleId()

NTSTATUS USBSTOR_PdoHandleQueryCompatibleId ( IN PDEVICE_OBJECT  DeviceObject,
IN OUT PIRP  Irp 
)

Definition at line 394 of file pdo.c.

397 {
398  PPDO_DEVICE_EXTENSION PDODeviceExtension;
399  PFDO_DEVICE_EXTENSION FDODeviceExtension;
400  CHAR Buffer[100] = {0};
404 
405  PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
406  FDODeviceExtension = (PFDO_DEVICE_EXTENSION)PDODeviceExtension->LowerDeviceObject->DeviceExtension;
407  ASSERT(FDODeviceExtension->DeviceDescriptor);
408  DeviceType = USBSTOR_GetDeviceType((PINQUIRYDATA)&PDODeviceExtension->InquiryData);
409 
410  // format instance id
411  Length = sprintf(Buffer, "USBSTOR\\%s", DeviceType) + 1;
412  // +1 for terminating \0 and another +1 for \0 at the end of REG_MULTI_SZ
413  Length += sprintf(&Buffer[Length], "USBSTOR\\%s", "RAW") + 2;
414 
416  if (!InstanceId)
417  {
418  Irp->IoStatus.Information = 0;
420  }
421 
424 
425  InstanceId[Offset] = UNICODE_NULL; // finish the REG_MULTI_SZ
426 
427  DPRINT("USBSTOR_PdoHandleQueryCompatibleId %S\n", InstanceId);
428 
429  Irp->IoStatus.Information = (ULONG_PTR)InstanceId;
430  return STATUS_SUCCESS;
431 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
VOID USBSTOR_ConvertToUnicodeString(IN CHAR *Buffer, IN ULONG ResultBufferLength, IN ULONG ResultBufferOffset, OUT LPWSTR ResultBuffer, OUT PULONG NewResultBufferOffset)
Definition: pdo.c:232
_In_ PIRP Irp
Definition: csq.h:116
DeviceType
Definition: mmdrv.h:41
char CHAR
Definition: xmlstorage.h:175
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
#define sprintf(buf, format,...)
Definition: sprintf.c:55
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define UNICODE_NULL
static LPCSTR USBSTOR_GetDeviceType(IN PINQUIRYDATA InquiryData)
Definition: pdo.c:20
_Must_inspect_result_ _In_opt_ PVOID _In_opt_ PVOID InstanceId
Definition: fsrtlfuncs.h:907
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
const char * LPCSTR
Definition: xmlstorage.h:183
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define USB_STOR_TAG
Definition: usbstor.h:10
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
WCHAR * LPWSTR
Definition: xmlstorage.h:184
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by USBSTOR_PdoHandlePnp().

◆ USBSTOR_PdoHandleQueryDeviceId()

NTSTATUS USBSTOR_PdoHandleQueryDeviceId ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 179 of file pdo.c.

182 {
183  PPDO_DEVICE_EXTENSION DeviceExtension;
185  CHAR Buffer[100] = {0};
187  ULONG Offset = 0;
188  PINQUIRYDATA InquiryData;
190  UNICODE_STRING DeviceId;
191 
192  DeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
193  InquiryData = (PINQUIRYDATA)&DeviceExtension->InquiryData;
194 
195  DeviceType = USBSTOR_GetDeviceType(InquiryData);
196 
197  // lets create device string
198  Offset = sprintf(&Buffer[Offset], "USBSTOR\\");
200  Offset += sprintf(&Buffer[Offset], "&Ven_");
201  Offset += CopyField(InquiryData->VendorId, &Buffer[Offset], 8);
202  Offset += sprintf(&Buffer[Offset], "&Prod_");
203  Offset += CopyField(InquiryData->ProductId, &Buffer[Offset], 16);
204  Offset += sprintf(&Buffer[Offset], "&Rev_");
205  Offset += CopyField(InquiryData->ProductRevisionLevel, &Buffer[Offset], 4);
206 
208 
209  // allocate DeviceId string
210  DeviceId.Length = 0;
211  DeviceId.MaximumLength = (USHORT)((strlen((PCHAR)Buffer) + 1) * sizeof(WCHAR));
213  if (!DeviceId.Buffer)
214  {
215  Irp->IoStatus.Information = 0;
217  }
218 
220 
221  if (NT_SUCCESS(Status))
222  {
223  Irp->IoStatus.Information = (ULONG_PTR)DeviceId.Buffer;
224  }
225 
226  DPRINT("DeviceId %wZ Status %x\n", &DeviceId, Status);
227 
228  return Status;
229 }
signed char * PCHAR
Definition: retypes.h:7
CONST char * PCSZ
Definition: umtypes.h:125
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
UCHAR ProductRevisionLevel[4]
Definition: cdrw_hw.h:1134
USHORT MaximumLength
Definition: env_spec_w32.h:370
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
_In_ PIRP Irp
Definition: csq.h:116
DeviceType
Definition: mmdrv.h:41
char CHAR
Definition: xmlstorage.h:175
static ULONG CopyField(IN PUCHAR Name, IN PCHAR Buffer, IN ULONG MaxLength)
Definition: pdo.c:70
LONG NTSTATUS
Definition: precomp.h:26
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
UCHAR ProductId[16]
Definition: cdrw_hw.h:1133
UCHAR VendorId[8]
Definition: cdrw_hw.h:1132
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define sprintf(buf, format,...)
Definition: sprintf.c:55
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define FALSE
Definition: types.h:117
static LPCSTR USBSTOR_GetDeviceType(IN PINQUIRYDATA InquiryData)
Definition: pdo.c:20
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
const char * LPCSTR
Definition: xmlstorage.h:183
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Status
Definition: gdiplustypes.h:24
#define USB_STOR_TAG
Definition: usbstor.h:10
unsigned short USHORT
Definition: pedump.c:61
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101

Referenced by USBSTOR_PdoHandlePnp().

◆ USBSTOR_PdoHandleQueryDeviceText()

NTSTATUS USBSTOR_PdoHandleQueryDeviceText ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 125 of file pdo.c.

128 {
129  PPDO_DEVICE_EXTENSION DeviceExtension;
130  PIO_STACK_LOCATION IoStack;
131  CHAR LocalBuffer[26];
132  UINT32 Offset = 0;
133  PINQUIRYDATA InquiryData;
136 
138 
139  DeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
140  InquiryData = (PINQUIRYDATA)&DeviceExtension->InquiryData;
141 
142  switch (IoStack->Parameters.QueryDeviceText.DeviceTextType)
143  {
146  {
147  DPRINT("USBSTOR_PdoHandleQueryDeviceText\n");
148 
149  Offset += CopyFieldTruncate(InquiryData->VendorId, &LocalBuffer[Offset], sizeof(InquiryData->VendorId));
150  LocalBuffer[Offset++] = ' ';
151  Offset += CopyFieldTruncate(InquiryData->ProductId, &LocalBuffer[Offset], sizeof(InquiryData->ProductId));
152  LocalBuffer[Offset++] = '\0';
153 
154  RtlInitAnsiString(&AnsiString, (PCSZ)&LocalBuffer);
155 
156  DeviceDescription.Length = 0;
159  if (!DeviceDescription.Buffer)
160  {
161  Irp->IoStatus.Information = 0;
163  }
164 
166 
167  Irp->IoStatus.Information = (ULONG_PTR)DeviceDescription.Buffer;
168  return STATUS_SUCCESS;
169  }
170  default:
171  {
172  Irp->IoStatus.Information = 0;
173  return Irp->IoStatus.Status;
174  }
175  }
176 }
CONST char * PCSZ
Definition: umtypes.h:125
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PIRP Irp
Definition: csq.h:116
char CHAR
Definition: xmlstorage.h:175
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
UCHAR ProductId[16]
Definition: cdrw_hw.h:1133
UCHAR VendorId[8]
Definition: cdrw_hw.h:1132
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define FALSE
Definition: types.h:117
unsigned int UINT32
void DPRINT(...)
Definition: polytest.cpp:61
static ULONG CopyFieldTruncate(IN PUCHAR Name, IN PCHAR Buffer, IN ULONG MaxLength)
Definition: pdo.c:96
_Must_inspect_result_ _In_ PDEVICE_DESCRIPTION DeviceDescription
Definition: iofuncs.h:1015
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define USB_STOR_TAG
Definition: usbstor.h:10
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
unsigned short USHORT
Definition: pedump.c:61
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
#define ULONG_PTR
Definition: config.h:101
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by USBSTOR_PdoHandlePnp().

◆ USBSTOR_PdoHandleQueryHardwareId()

NTSTATUS USBSTOR_PdoHandleQueryHardwareId ( IN PDEVICE_OBJECT  DeviceObject,
IN OUT PIRP  Irp 
)

Definition at line 267 of file pdo.c.

270 {
271  PPDO_DEVICE_EXTENSION PDODeviceExtension;
272  PFDO_DEVICE_EXTENSION FDODeviceExtension;
273  LPCSTR GenericType, DeviceType;
274  LPWSTR Buffer;
275  CHAR Id1[50], Id2[50], Id3[50], Id4[50], Id5[50], Id6[50], Id7[50];
276  ULONG Id1Length, Id2Length, Id3Length, Id4Length, Id5Length, Id6Length, Id7Length;
278  PINQUIRYDATA InquiryData;
279 
280  PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
281  FDODeviceExtension = (PFDO_DEVICE_EXTENSION)PDODeviceExtension->LowerDeviceObject->DeviceExtension;
282  ASSERT(FDODeviceExtension->DeviceDescriptor);
283  InquiryData = (PINQUIRYDATA)&PDODeviceExtension->InquiryData;
284 
285  DeviceType = USBSTOR_GetDeviceType(InquiryData);
286  GenericType = USBSTOR_GetGenericType(InquiryData);
287 
288  ASSERT(GenericType);
289 
290  // generate id 1
291  // USBSTOR\SCSIType_VendorId(8)_ProductId(16)_Revision(4)
292  RtlZeroMemory(Id1, sizeof(Id1));
293  Offset = 0;
294  Offset = sprintf(&Id1[Offset], "USBSTOR\\");
295  Offset += sprintf(&Id1[Offset], DeviceType);
296  Offset += CopyField(InquiryData->VendorId, &Id1[Offset], 8);
297  Offset += CopyField(InquiryData->ProductId, &Id1[Offset], 16);
298  Offset += CopyField(InquiryData->ProductRevisionLevel, &Id1[Offset], 4);
299  Id1Length = strlen(Id1) + 1;
300  DPRINT("USBSTOR_PdoHandleQueryHardwareId HardwareId1 %s\n", Id1);
301 
302  // generate id 2
303  // USBSTOR\SCSIType_VendorId(8)_ProductId(16)
304  RtlZeroMemory(Id2, sizeof(Id2));
305  Offset = 0;
306  Offset = sprintf(&Id2[Offset], "USBSTOR\\");
307  Offset += sprintf(&Id2[Offset], DeviceType);
308  Offset += CopyField(InquiryData->VendorId, &Id2[Offset], 8);
309  Offset += CopyField(InquiryData->ProductId, &Id2[Offset], 16);
310  Id2Length = strlen(Id2) + 1;
311  DPRINT("USBSTOR_PdoHandleQueryHardwareId HardwareId2 %s\n", Id2);
312 
313  // generate id 3
314  // USBSTOR\SCSIType_VendorId(8)
315  RtlZeroMemory(Id3, sizeof(Id3));
316  Offset = 0;
317  Offset = sprintf(&Id3[Offset], "USBSTOR\\");
318  Offset += sprintf(&Id3[Offset], DeviceType);
319  Offset += CopyField(InquiryData->VendorId, &Id3[Offset], 8);
320  Id3Length = strlen(Id3) + 1;
321  DPRINT("USBSTOR_PdoHandleQueryHardwareId HardwareId3 %s\n", Id3);
322 
323  // generate id 4
324  // USBSTOR\SCSIType_VendorId(8)_ProductId(16)_Revision(1)
325  RtlZeroMemory(Id4, sizeof(Id4));
326  Offset = 0;
327  Offset = sprintf(&Id4[Offset], "USBSTOR\\");
328  Offset += sprintf(&Id4[Offset], DeviceType);
329  Offset += CopyField(InquiryData->VendorId, &Id4[Offset], 8);
330  Offset += CopyField(InquiryData->ProductId, &Id4[Offset], 16);
331  Offset += CopyField(InquiryData->ProductRevisionLevel, &Id4[Offset], 1);
332  Id4Length = strlen(Id4) + 1;
333  DPRINT("USBSTOR_PdoHandleQueryHardwareId HardwareId4 %s\n", Id4);
334 
335  // generate id 5
336  // SCSIType_VendorId(8)_ProductId(16)_Revision(1)
337  RtlZeroMemory(Id5, sizeof(Id5));
338  Offset = 0;
339  Offset = sprintf(&Id5[Offset], DeviceType);
340  Offset += CopyField(InquiryData->VendorId, &Id5[Offset], 8);
341  Offset += CopyField(InquiryData->ProductId, &Id5[Offset], 16);
342  Offset += CopyField(InquiryData->ProductRevisionLevel, &Id5[Offset], 1);
343  Id5Length = strlen(Id5) + 1;
344  DPRINT("USBSTOR_PdoHandleQueryHardwareId HardwareId5 %s\n", Id5);
345 
346  // generate id 6
347  // USBSTOR\SCSIType
348  RtlZeroMemory(Id6, sizeof(Id6));
349  Offset = 0;
350  Offset = sprintf(&Id6[Offset], "USBSTOR\\");
351  Offset += sprintf(&Id6[Offset], GenericType);
352  Id6Length = strlen(Id6) + 1;
353  DPRINT("USBSTOR_PdoHandleQueryHardwareId HardwareId6 %s\n", Id6);
354 
355  // generate id 7
356  // SCSIType
357  RtlZeroMemory(Id7, sizeof(Id7));
358  Offset = 0;
359  Offset = sprintf(&Id7[Offset], GenericType);
360  Id7Length = strlen(Id7) + 1;
361  DPRINT("USBSTOR_PdoHandleQueryHardwareId HardwareId7 %s\n", Id7);
362 
363  // last +1 is for terminating \0 of REG_MULTI_SZ
364  TotalLength = Id1Length + Id2Length + Id3Length + Id4Length + Id5Length + Id6Length + Id7Length + 1;
365 
367  if (!Buffer)
368  {
369  Irp->IoStatus.Information = 0;
371  }
372 
373  // reset offset
374  Offset = 0;
376 
384 
385  Buffer[Offset] = UNICODE_NULL; // finish the REG_MULTI_SZ
386 
387  ASSERT(Offset + 1 == Length);
388 
389  Irp->IoStatus.Information = (ULONG_PTR)Buffer;
390  return STATUS_SUCCESS;
391 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
VOID USBSTOR_ConvertToUnicodeString(IN CHAR *Buffer, IN ULONG ResultBufferLength, IN ULONG ResultBufferOffset, OUT LPWSTR ResultBuffer, OUT PULONG NewResultBufferOffset)
Definition: pdo.c:232
UCHAR ProductRevisionLevel[4]
Definition: cdrw_hw.h:1134
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
_In_ PIRP Irp
Definition: csq.h:116
DeviceType
Definition: mmdrv.h:41
char CHAR
Definition: xmlstorage.h:175
static ULONG CopyField(IN PUCHAR Name, IN PCHAR Buffer, IN ULONG MaxLength)
Definition: pdo.c:70
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
struct _INQUIRYDATA * PINQUIRYDATA
UCHAR ProductId[16]
Definition: cdrw_hw.h:1133
UCHAR VendorId[8]
Definition: cdrw_hw.h:1132
_In_ ULONG TotalLength
Definition: usbdlib.h:158
#define sprintf(buf, format,...)
Definition: sprintf.c:55
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define UNICODE_NULL
static LPCSTR USBSTOR_GetDeviceType(IN PINQUIRYDATA InquiryData)
Definition: pdo.c:20
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
const char * LPCSTR
Definition: xmlstorage.h:183
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static LPCSTR USBSTOR_GetGenericType(IN PINQUIRYDATA InquiryData)
Definition: pdo.c:45
#define USB_STOR_TAG
Definition: usbstor.h:10
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define ULONG_PTR
Definition: config.h:101
WCHAR * LPWSTR
Definition: xmlstorage.h:184
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by USBSTOR_PdoHandlePnp().

◆ USBSTOR_PdoHandleQueryInstanceId()

NTSTATUS USBSTOR_PdoHandleQueryInstanceId ( IN PDEVICE_OBJECT  DeviceObject,
IN OUT PIRP  Irp 
)

Definition at line 434 of file pdo.c.

437 {
438  PPDO_DEVICE_EXTENSION PDODeviceExtension;
439  PFDO_DEVICE_EXTENSION FDODeviceExtension;
440  WCHAR Buffer[100];
441  ULONG Length;
443 
444  PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
445  FDODeviceExtension = (PFDO_DEVICE_EXTENSION)PDODeviceExtension->LowerDeviceObject->DeviceExtension;
446 
447  // format instance id
448  if (FDODeviceExtension->SerialNumber)
449  {
450  // using serial number from device
451  swprintf(Buffer, L"%s&%c", FDODeviceExtension->SerialNumber->bString, PDODeviceExtension->LUN);
452  }
453  else
454  {
455  // use instance count and LUN
456  swprintf(Buffer, L"%04lu&%c", FDODeviceExtension->InstanceCount, PDODeviceExtension->LUN);
457  }
458 
459  Length = wcslen(Buffer) + 1;
460 
462  if (!InstanceId)
463  {
464  Irp->IoStatus.Information = 0;
466  }
467 
469 
470  DPRINT("USBSTOR_PdoHandleQueryInstanceId %S\n", InstanceId);
471 
472  Irp->IoStatus.Information = (ULONG_PTR)InstanceId;
473  return STATUS_SUCCESS;
474 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PIRP Irp
Definition: csq.h:116
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
_Must_inspect_result_ _In_opt_ PVOID _In_opt_ PVOID InstanceId
Definition: fsrtlfuncs.h:907
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define swprintf(buf, format,...)
Definition: sprintf.c:56
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
#define USB_STOR_TAG
Definition: usbstor.h:10
_In_ PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2464
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
WCHAR * LPWSTR
Definition: xmlstorage.h:184
return STATUS_SUCCESS
Definition: btrfs.c:3014
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

Referenced by USBSTOR_PdoHandlePnp().

◆ USBSTOR_SendInternalCdb()

static NTSTATUS USBSTOR_SendInternalCdb ( IN PDEVICE_OBJECT  PdoDevice,
IN PCDB  Cdb,
IN UCHAR  CdbLength,
IN ULONG  TimeOutValue,
OUT PVOID  OutDataBuffer,
OUT PULONG  OutDataTransferLength 
)
static

Definition at line 669 of file pdo.c.

676 {
678  PSENSE_DATA SenseBuffer;
679  PIO_STACK_LOCATION IoStack;
680  KEVENT Event;
681  PIRP Irp = NULL;
682  PMDL Mdl = NULL;
683  ULONG ix = 0;
685  UCHAR SrbStatus;
686 
687  DPRINT("USBSTOR_SendInternalCdb SCSIOP %x\n", Cdb->CDB6GENERIC.OperationCode);
688 
690  sizeof(SCSI_REQUEST_BLOCK),
691  USB_STOR_TAG);
692 
693  if (Srb)
694  {
695  SenseBuffer = ExAllocatePoolWithTag(NonPagedPool,
697  USB_STOR_TAG);
698 
699  if (SenseBuffer)
700  {
701  Mdl = IoAllocateMdl(OutDataBuffer,
702  *OutDataTransferLength,
703  FALSE,
704  FALSE,
705  NULL);
706 
707  if (!Mdl)
708  {
709  ExFreePoolWithTag(SenseBuffer, USB_STOR_TAG);
711  return Status;
712  }
713 
715 
716  // make 3 attempts - the device may be in STALL state after the first one
717  do
718  {
719  Irp = IoAllocateIrp(PdoDevice->StackSize, FALSE);
720 
721  if (!Irp)
722  {
723  break;
724  }
725 
726  IoStack = IoGetNextIrpStackLocation(Irp);
728  IoStack->Parameters.Scsi.Srb = Srb;
729 
731 
732  Srb->Length = sizeof(SCSI_REQUEST_BLOCK);
733  Srb->Function = SRB_FUNCTION_EXECUTE_SCSI;
734  Srb->CdbLength = CdbLength;
735  Srb->SenseInfoBufferLength = SENSE_BUFFER_SIZE;
737  Srb->DataTransferLength = *OutDataTransferLength;
738  Srb->TimeOutValue = TimeOutValue;
739  Srb->DataBuffer = OutDataBuffer;
740  Srb->SenseInfoBuffer = SenseBuffer;
741 
742  RtlCopyMemory(Srb->Cdb, Cdb, CdbLength);
743 
744  Irp->MdlAddress = Mdl;
745 
747 
750  &Event,
751  TRUE,
752  TRUE,
753  TRUE);
754 
755  if (IoCallDriver(PdoDevice, Irp) == STATUS_PENDING)
756  {
758  Executive,
759  KernelMode,
760  FALSE,
761  NULL);
762  }
763 
764  SrbStatus = SRB_STATUS(Srb->SrbStatus);
765 
766  IoFreeIrp(Irp);
767  Irp = NULL;
768 
769  if (SrbStatus == SRB_STATUS_SUCCESS ||
770  SrbStatus == SRB_STATUS_DATA_OVERRUN)
771  {
773  *OutDataTransferLength = Srb->DataTransferLength;
774  break;
775  }
776 
778 
779  ++ix;
780  } while (ix < 3);
781 
782  if (Mdl)
783  {
784  IoFreeMdl(Mdl);
785  }
786 
787  ExFreePoolWithTag(SenseBuffer, USB_STOR_TAG);
788  }
789 
791  }
792 
793  return Status;
794 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PIRP Irp
Definition: csq.h:116
#define SRB_FLAGS_NO_QUEUE_FREEZE
Definition: srb.h:396
#define TRUE
Definition: types.h:120
VOID NTAPI MmBuildMdlForNonPagedPool(IN PMDL Mdl)
Definition: mdlsup.c:428
LONG NTSTATUS
Definition: precomp.h:26
#define SRB_FLAGS_DATA_IN
Definition: srb.h:392
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define SRB_STATUS(Status)
Definition: srb.h:381
#define SENSE_BUFFER_SIZE
Definition: cdrw_hw.h:1183
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:498
#define FALSE
Definition: types.h:117
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:450
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define STATUS_PENDING
Definition: ntstatus.h:82
_In_opt_ WDFREQUEST _In_ ULONG _In_ BOOLEAN _In_ PCDB Cdb
Definition: scratch.h:156
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
#define SRB_STATUS_DATA_OVERRUN
Definition: srb.h:349
struct _SCSI_REQUEST_BLOCK SCSI_REQUEST_BLOCK
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
unsigned char UCHAR
Definition: xmlstorage.h:181
Status
Definition: gdiplustypes.h:24
#define USB_STOR_TAG
Definition: usbstor.h:10
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2691
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
struct _CDB::_CDB6GENERIC CDB6GENERIC
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
#define SRB_FUNCTION_EXECUTE_SCSI
Definition: srb.h:307
NTSTATUS NTAPI USBSTOR_SyncCompletionRoutine(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Ctx)
Definition: pdo.c:652
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define SRB_STATUS_SUCCESS
Definition: srb.h:333
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
IN PSCSI_REQUEST_BLOCK Srb
Definition: class2.h:49
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107
return STATUS_SUCCESS
Definition: btrfs.c:3014

Referenced by USBSTOR_FillInquiryData().

◆ USBSTOR_SyncCompletionRoutine()

NTSTATUS NTAPI USBSTOR_SyncCompletionRoutine ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PVOID  Ctx 
)

Definition at line 652 of file pdo.c.

656 {
659 }
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define FALSE
Definition: types.h:117
#define IO_NO_INCREMENT
Definition: iotypes.h:581

Referenced by USBSTOR_SendInternalCdb().