ReactOS  0.4.15-dev-318-g99b52df
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

LPCSTR USBSTOR_GetDeviceType (IN PINQUIRYDATA InquiryData, IN UCHAR IsFloppy)
 
LPCSTR USBSTOR_GetGenericType (IN PINQUIRYDATA InquiryData, IN UCHAR IsFloppy)
 
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 124 of file pdo.c.

128 {
129  ULONG Index;
130 
131  for (Index = 0; Index < MaxLength; Index++)
132  {
133  if (Name[Index] <= ' ' || Name[Index] >= 0x7F /* last printable ascii character */ || Name[Index] == ',')
134  {
135  // convert to underscore
136  Buffer[Index] = '_';
137  }
138  else
139  {
140  // just copy character
141  Buffer[Index] = Name[Index];
142  }
143  }
144 
145  return MaxLength;
146 }
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 150 of file pdo.c.

154 {
155  ULONG Index;
156 
157  for (Index = 0; Index < MaxLength; Index++)
158  {
159  if (Name[Index] == '\0')
160  {
161  break;
162  }
163  else if (Name[Index] <= ' ' || Name[Index] >= 0x7F /* last printable ascii character */ || Name[Index] == ',')
164  {
165  // convert to underscore
166  Buffer[Index] = ' ';
167  }
168  else
169  {
170  // just copy character
171  Buffer[Index] = Name[Index];
172  }
173  }
174 
175  return Index;
176 }
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 288 of file pdo.c.

294 {
295  UNICODE_STRING DeviceString;
298 
299  ASSERT(ResultBufferLength);
300  ASSERT(ResultBufferLength > ResultBufferOffset);
301 
302  DPRINT("ResultBufferOffset %lu ResultBufferLength %lu Buffer %s Length %lu\n", ResultBufferOffset, ResultBufferLength, Buffer, strlen(Buffer));
303 
304  // construct destination string
305  DeviceString.Buffer = &ResultBuffer[ResultBufferOffset];
306  DeviceString.Length = 0;
307  DeviceString.MaximumLength = (ResultBufferLength - ResultBufferOffset) * sizeof(WCHAR);
308 
309  // initialize source string
311 
314 
315  // subtract consumed bytes
316  ResultBufferLength -= (DeviceString.Length + sizeof(WCHAR)) / sizeof(WCHAR);
317  ResultBufferOffset += (DeviceString.Length + sizeof(WCHAR)) / sizeof(WCHAR);
318 
319  *NewResultBufferOffset = ResultBufferOffset;
320 }
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)
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 908 of file pdo.c.

911 {
912  PDEVICE_OBJECT PDO;
914  PPDO_DEVICE_EXTENSION PDODeviceExtension;
915  PFDO_DEVICE_EXTENSION FDODeviceExtension;
916 
917  FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
918 
919  // create child device object
921  if (!NT_SUCCESS(Status))
922  {
923  DPRINT1("Failed to create PDO, status %x\n", Status);
924  return Status;
925  }
926 
927  // patch the stack size
929 
930  PDODeviceExtension = (PPDO_DEVICE_EXTENSION)PDO->DeviceExtension;
931 
932  // initialize device extension
933  RtlZeroMemory(PDODeviceExtension, sizeof(PDO_DEVICE_EXTENSION));
934  PDODeviceExtension->Common.IsFDO = FALSE;
935  PDODeviceExtension->LowerDeviceObject = DeviceObject;
936  PDODeviceExtension->PDODeviceObject = &FDODeviceExtension->ChildPDO[LUN];
937  PDODeviceExtension->Self = PDO;
938  PDODeviceExtension->LUN = LUN;
939 
940  PDO->Flags |= DO_DIRECT_IO;
941 
942  // device is initialized
943  PDO->Flags &= ~DO_DEVICE_INITIALIZING;
944 
945  // output device object
946  FDODeviceExtension->ChildPDO[LUN] = PDO;
947 
948  // send inquiry command by irp
950 
951  if (!NT_SUCCESS(Status))
952  {
953  return Status;
954  }
955 
956  if (PDODeviceExtension->InquiryData->DeviceType == DIRECT_ACCESS_DEVICE || PDODeviceExtension->InquiryData->DeviceType == READ_ONLY_DIRECT_ACCESS_DEVICE)
957  {
958  PDODeviceExtension->IsFloppy = FALSE; // TODO: implement the actual check
959  }
960  else
961  {
962  // we work only with DIRECT_ACCESS_DEVICE for now
963  return STATUS_NOT_SUPPORTED;
964  }
965 
966  return Status;
967 }
#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
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
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define DPRINT1
Definition: precomp.h:8
#define READ_ONLY_DIRECT_ACCESS_DEVICE
Definition: cdrw_hw.h:1149
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
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:261
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
static NTSTATUS USBSTOR_FillInquiryData(IN PDEVICE_OBJECT PDODeviceObject)
Definition: pdo.c:857

Referenced by USBSTOR_FdoHandleStartDevice().

◆ USBSTOR_FillInquiryData()

static NTSTATUS USBSTOR_FillInquiryData ( IN PDEVICE_OBJECT  PDODeviceObject)
static

Definition at line 857 of file pdo.c.

859 {
861  PPDO_DEVICE_EXTENSION PDODeviceExtension;
862  CDB Cdb;
863  ULONG DataTransferLength = INQUIRYDATABUFFERSIZE;
864  PINQUIRYDATA InquiryData;
865 
866  PDODeviceExtension = (PPDO_DEVICE_EXTENSION)PDODeviceObject->DeviceExtension;
868 
869  if (!InquiryData)
870  {
871  DPRINT1("USBSTOR_FillInquiryData failed with %x\n", Status);
872  return Status;
873  }
874 
875  RtlZeroMemory(&Cdb, sizeof(Cdb));
876  Cdb.CDB6INQUIRY.OperationCode = SCSIOP_INQUIRY;
877  Cdb.CDB6INQUIRY.AllocationLength = INQUIRYDATABUFFERSIZE;
878 
879  Status = USBSTOR_SendInternalCdb(PDODeviceObject, &Cdb, CDB6GENERIC_LENGTH, 20, InquiryData, &DataTransferLength);
880 
881  if (!NT_SUCCESS(Status))
882  {
883  DPRINT1("USBSTOR_FillInquiryData failed with %x\n", Status);
884  ExFreePoolWithTag(InquiryData, USB_STOR_TAG);
885  return Status;
886  }
887 
888  DPRINT("DeviceType %x\n", InquiryData->DeviceType);
889  DPRINT("DeviceTypeModifier %x\n", InquiryData->DeviceTypeModifier);
890  DPRINT("RemovableMedia %x\n", InquiryData->RemovableMedia);
891  DPRINT("Version %x\n", InquiryData->Versions);
892  DPRINT("Format %x\n", InquiryData->ResponseDataFormat);
893  DPRINT("Length %x\n", InquiryData->AdditionalLength);
894  DPRINT("Reserved %p\n", InquiryData->Reserved);
895  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]);
896  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],
897  InquiryData->ProductId[4], InquiryData->ProductId[5], InquiryData->ProductId[6], InquiryData->ProductId[7],
898  InquiryData->ProductId[8], InquiryData->ProductId[9], InquiryData->ProductId[10], InquiryData->ProductId[11],
899  InquiryData->ProductId[12], InquiryData->ProductId[13], InquiryData->ProductId[14], InquiryData->ProductId[15]);
900 
901  DPRINT("Revision %c%c%c%c\n", InquiryData->ProductRevisionLevel[0], InquiryData->ProductRevisionLevel[1], InquiryData->ProductRevisionLevel[2], InquiryData->ProductRevisionLevel[3]);
902 
903  PDODeviceExtension->InquiryData = InquiryData;
904  return Status;
905 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
UCHAR ProductRevisionLevel[4]
Definition: cdrw_hw.h:1134
UCHAR ResponseDataFormat
Definition: cdrw_hw.h:1121
Definition: cdrw_hw.h:28
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
UCHAR Reserved[2]
Definition: cdrw_hw.h:1123
UCHAR RemovableMedia
Definition: cdrw_hw.h:1119
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:723
#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
UCHAR Versions
Definition: cdrw_hw.h:1120
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define USB_STOR_TAG
Definition: usbstor.h:10
UCHAR AdditionalLength
Definition: cdrw_hw.h:1122
UCHAR DeviceTypeModifier
Definition: cdrw_hw.h:1118
Status
Definition: gdiplustypes.h:24
UCHAR DeviceType
Definition: cdrw_hw.h:1116
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
struct _CDB::_CDB6INQUIRY CDB6INQUIRY

Referenced by USBSTOR_CreatePDO().

◆ USBSTOR_GetDeviceType()

LPCSTR USBSTOR_GetDeviceType ( IN PINQUIRYDATA  InquiryData,
IN UCHAR  IsFloppy 
)

Definition at line 19 of file pdo.c.

22 {
23  if (InquiryData->DeviceType == 0)
24  {
25  if (IsFloppy)
26  {
27  // floppy device
28  return "SFloppy";
29  }
30 
31  // direct access device
32  return "Disk";
33  }
34 
35  switch (InquiryData->DeviceType)
36  {
37  case 1:
38  {
39  // sequential device, i.e magnetic tape
40  return "Sequential";
41  }
42  case 4:
43  {
44  // write once device
45  return "Worm";
46  }
47  case 5:
48  {
49  // CDROM device
50  return "CdRom";
51  }
52  case 7:
53  {
54  // optical memory device
55  return "Optical";
56  }
57  case 8:
58  {
59  // medium change device
60  return "Changer";
61  }
62  default:
63  {
64  // other device
65  return "Other";
66  }
67  }
68 }

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

◆ USBSTOR_GetGenericType()

LPCSTR USBSTOR_GetGenericType ( IN PINQUIRYDATA  InquiryData,
IN UCHAR  IsFloppy 
)

Definition at line 71 of file pdo.c.

74 {
75  if (InquiryData->DeviceType == 0)
76  {
77  if (IsFloppy)
78  {
79  // floppy device
80  return "GenSFloppy";
81  }
82 
83  // direct access device
84  return "GenDisk";
85  }
86 
87  switch (InquiryData->DeviceType)
88  {
89  case 1:
90  {
91  // sequential device, i.e magnetic tape
92  return "GenSequential";
93  }
94  case 4:
95  {
96  // write once device
97  return "GenWorm";
98  }
99  case 5:
100  {
101  // CDROM device
102  return "GenCdRom";
103  }
104  case 7:
105  {
106  // optical memory device
107  return "GenOptical";
108  }
109  case 8:
110  {
111  // medium change device
112  return "GenChanger";
113  }
114  default:
115  {
116  // other device
117  return "UsbstorOther";
118  }
119  }
120 }

Referenced by USBSTOR_PdoHandleQueryHardwareId().

◆ USBSTOR_PdoHandleDeviceRelations()

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

Definition at line 527 of file pdo.c.

530 {
531  PDEVICE_RELATIONS DeviceRelations;
532  PIO_STACK_LOCATION IoStack;
533 
534  DPRINT("USBSTOR_PdoHandleDeviceRelations\n");
535 
537 
538  // check if relation type is BusRelations
539  if (IoStack->Parameters.QueryDeviceRelations.Type != TargetDeviceRelation)
540  {
541  // PDO handles only target device relation
542  return Irp->IoStatus.Status;
543  }
544 
545  DeviceRelations = (PDEVICE_RELATIONS)AllocateItem(PagedPool, sizeof(DEVICE_RELATIONS));
546  if (!DeviceRelations)
547  {
549  }
550 
551  // initialize device relations
552  DeviceRelations->Count = 1;
553  DeviceRelations->Objects[0] = DeviceObject;
555 
556  Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
557  return STATUS_SUCCESS;
558 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PIRP Irp
Definition: csq.h:116
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2055
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
struct _DEVICE_RELATIONS * PDEVICE_RELATIONS
void DPRINT(...)
Definition: polytest.cpp:61
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define ObReferenceObject
Definition: obfuncs.h:204
#define ULONG_PTR
Definition: config.h:101
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
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 561 of file pdo.c.

564 {
565  PIO_STACK_LOCATION IoStack;
566  PPDO_DEVICE_EXTENSION DeviceExtension;
569  ULONG bDelete;
570 
573  ASSERT(DeviceExtension->Common.IsFDO == FALSE);
574 
575  switch(IoStack->MinorFunction)
576  {
578  {
580  break;
581  }
583  {
585  break;
586  }
587  case IRP_MN_QUERY_ID:
588  {
589  if (IoStack->Parameters.QueryId.IdType == BusQueryDeviceID)
590  {
592  break;
593  }
594  else if (IoStack->Parameters.QueryId.IdType == BusQueryHardwareIDs)
595  {
597  break;
598  }
599  else if (IoStack->Parameters.QueryId.IdType == BusQueryInstanceID)
600  {
602  break;
603  }
604  else if (IoStack->Parameters.QueryId.IdType == BusQueryCompatibleIDs)
605  {
607  break;
608  }
609 
610  DPRINT1("USBSTOR_PdoHandlePnp: IRP_MN_QUERY_ID IdType %x unimplemented\n", IoStack->Parameters.QueryId.IdType);
612  Irp->IoStatus.Information = 0;
613  break;
614  }
616  {
617  DPRINT("IRP_MN_REMOVE_DEVICE\n");
618 
619  if(*DeviceExtension->PDODeviceObject != NULL)
620  {
621  *DeviceExtension->PDODeviceObject = NULL;
622  bDelete = TRUE;
623  }
624  else
625  {
626  // device object already marked for deletion
627  bDelete = FALSE;
628  }
629 
630  // clean up the device extension
631  ASSERT(DeviceExtension->InquiryData);
632  ExFreePoolWithTag(DeviceExtension->InquiryData, USB_STOR_TAG);
633 
634  Irp->IoStatus.Status = STATUS_SUCCESS;
636 
637  if (bDelete)
638  {
640  }
641  return STATUS_SUCCESS;
642  }
644  {
645  // just forward irp to lower device
646  Status = USBSTOR_SyncForwardIrp(DeviceExtension->LowerDeviceObject, Irp);
648 
649  if (NT_SUCCESS(Status))
650  {
651  // check if no unique id
652  Caps = (PDEVICE_CAPABILITIES)IoStack->Parameters.DeviceCapabilities.Capabilities;
653  Caps->UniqueID = FALSE; // no unique id is supported
654  Caps->Removable = TRUE; //FIXME
655  }
656  break;
657  }
660  {
661 #if 0
662  //
663  // if we're not claimed it's ok
664  //
665  if (DeviceExtension->Claimed)
666 #else
667  if (TRUE)
668 #endif
669  {
671  DPRINT1("[USBSTOR] Request %x fails because device is still claimed\n", IoStack->MinorFunction);
672  }
673  else
675  break;
676  }
677  case IRP_MN_START_DEVICE:
678  {
679  // no-op for PDO
681  break;
682  }
684  {
686  break;
687  }
688  default:
689  {
690  // do nothing
691  Status = Irp->IoStatus.Status;
692  }
693  }
694 
695  if (Status != STATUS_PENDING)
696  {
697  Irp->IoStatus.Status = Status;
699  }
700 
701  return Status;
702 }
#define TRUE
Definition: types.h:120
#define IRP_MN_REMOVE_DEVICE
#define IRP_MN_QUERY_ID
NTSTATUS USBSTOR_PdoHandleDeviceRelations(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: pdo.c:527
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS USBSTOR_PdoHandleQueryDeviceText(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: pdo.c:179
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
NTSTATUS USBSTOR_PdoHandleQueryDeviceId(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: pdo.c:234
#define IRP_MN_QUERY_REMOVE_DEVICE
PVOID DeviceExtension
Definition: env_spec_w32.h:418
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:484
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:447
#define USB_STOR_TAG
Definition: usbstor.h:10
NTSTATUS USBSTOR_PdoHandleQueryHardwareId(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: pdo.c:323
* PDEVICE_CAPABILITIES
Definition: iotypes.h:928
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define DPRINT1
Definition: precomp.h:8
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
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 447 of file pdo.c.

450 {
451  PPDO_DEVICE_EXTENSION PDODeviceExtension;
452  PFDO_DEVICE_EXTENSION FDODeviceExtension;
453  CHAR Buffer[100] = {0};
457 
458  PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
459  FDODeviceExtension = (PFDO_DEVICE_EXTENSION)PDODeviceExtension->LowerDeviceObject->DeviceExtension;
460  ASSERT(FDODeviceExtension->DeviceDescriptor);
461  DeviceType = USBSTOR_GetDeviceType(PDODeviceExtension->InquiryData, PDODeviceExtension->IsFloppy);
462 
463  // format instance id
464  Length = sprintf(Buffer, "USBSTOR\\%s", DeviceType) + 1;
465  Length += sprintf(&Buffer[Length], "USBSTOR\\%s", "RAW") + 2;
466 
468  if (!InstanceId)
469  {
470  Irp->IoStatus.Information = 0;
472  }
473 
476 
477  DPRINT("USBSTOR_PdoHandleQueryCompatibleId %S\n", InstanceId);
478 
479  Irp->IoStatus.Information = (ULONG_PTR)InstanceId;
480  return STATUS_SUCCESS;
481 }
#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:288
_In_ PIRP Irp
Definition: csq.h:116
DeviceType
Definition: mmdrv.h:41
char CHAR
Definition: xmlstorage.h:175
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
LPCSTR USBSTOR_GetDeviceType(IN PINQUIRYDATA InquiryData, IN UCHAR IsFloppy)
Definition: pdo.c:19
#define sprintf(buf, format,...)
Definition: sprintf.c:55
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_Must_inspect_result_ _In_opt_ PVOID _In_opt_ PVOID InstanceId
Definition: fsrtlfuncs.h:907
PVOID DeviceExtension
Definition: env_spec_w32.h:418
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)
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
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 234 of file pdo.c.

237 {
238  PPDO_DEVICE_EXTENSION DeviceExtension;
240  CHAR Buffer[100] = {0};
242  ULONG Offset = 0;
243  PINQUIRYDATA InquiryData;
245  UNICODE_STRING DeviceId;
246 
248  ASSERT(DeviceExtension->InquiryData);
249  InquiryData = DeviceExtension->InquiryData;
250 
251  DeviceType = USBSTOR_GetDeviceType(InquiryData, DeviceExtension->IsFloppy);
252 
253  // lets create device string
254  Offset = sprintf(&Buffer[Offset], "USBSTOR\\");
256  Offset += sprintf(&Buffer[Offset], "&Ven_");
257  Offset += CopyField(InquiryData->VendorId, &Buffer[Offset], 8);
258  Offset += sprintf(&Buffer[Offset], "&Prod_");
259  Offset += CopyField(InquiryData->ProductId, &Buffer[Offset], 16);
260  Offset += sprintf(&Buffer[Offset], "&Rev_");
261  Offset += CopyField(InquiryData->ProductRevisionLevel, &Buffer[Offset], 4);
262 
264 
265  // allocate DeviceId string
266  DeviceId.Length = 0;
267  DeviceId.MaximumLength = (USHORT)((strlen((PCHAR)Buffer) + 1) * sizeof(WCHAR));
268  DeviceId.Buffer = (LPWSTR)AllocateItem(PagedPool, DeviceId.MaximumLength);
269  if (!DeviceId.Buffer)
270  {
271  Irp->IoStatus.Information = 0;
273  }
274 
276 
277  if (NT_SUCCESS(Status))
278  {
279  Irp->IoStatus.Information = (ULONG_PTR)DeviceId.Buffer;
280  }
281 
282  DPRINT("DeviceId %wZ Status %x\n", &DeviceId, Status);
283 
284  return Status;
285 }
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:124
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
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
LPCSTR USBSTOR_GetDeviceType(IN PINQUIRYDATA InquiryData, IN UCHAR IsFloppy)
Definition: pdo.c:19
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
PVOID DeviceExtension
Definition: env_spec_w32.h:418
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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
unsigned short USHORT
Definition: pedump.c:61
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by USBSTOR_PdoHandlePnp().

◆ USBSTOR_PdoHandleQueryDeviceText()

NTSTATUS USBSTOR_PdoHandleQueryDeviceText ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 179 of file pdo.c.

182 {
183  PPDO_DEVICE_EXTENSION DeviceExtension;
184  PIO_STACK_LOCATION IoStack;
185  CHAR LocalBuffer[26];
186  UINT32 Offset = 0;
187  PINQUIRYDATA InquiryData;
190 
192 
194  ASSERT(DeviceExtension->InquiryData);
195  InquiryData = DeviceExtension->InquiryData;
196 
197  switch (IoStack->Parameters.QueryDeviceText.DeviceTextType)
198  {
201  {
202  DPRINT("USBSTOR_PdoHandleQueryDeviceText\n");
203 
204  Offset += CopyFieldTruncate(InquiryData->VendorId, &LocalBuffer[Offset], sizeof(InquiryData->VendorId));
205  LocalBuffer[Offset++] = ' ';
206  Offset += CopyFieldTruncate(InquiryData->ProductId, &LocalBuffer[Offset], sizeof(InquiryData->ProductId));
207  LocalBuffer[Offset++] = '\0';
208 
209  RtlInitAnsiString(&AnsiString, (PCSZ)&LocalBuffer);
210 
211  DeviceDescription.Length = 0;
214  if (!DeviceDescription.Buffer)
215  {
216  Irp->IoStatus.Information = 0;
218  }
219 
221 
222  Irp->IoStatus.Information = (ULONG_PTR)DeviceDescription.Buffer;
223  return STATUS_SUCCESS;
224  }
225  default:
226  {
227  Irp->IoStatus.Information = 0;
228  return Irp->IoStatus.Status;
229  }
230  }
231 }
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
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
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
unsigned int UINT32
PVOID DeviceExtension
Definition: env_spec_w32.h:418
void DPRINT(...)
Definition: polytest.cpp:61
static ULONG CopyFieldTruncate(IN PUCHAR Name, IN PCHAR Buffer, IN ULONG MaxLength)
Definition: pdo.c:150
_Must_inspect_result_ _In_ PDEVICE_DESCRIPTION DeviceDescription
Definition: iofuncs.h:1015
__wchar_t WCHAR
Definition: xmlstorage.h:180
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
unsigned short USHORT
Definition: pedump.c:61
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
#define ULONG_PTR
Definition: config.h:101
WCHAR * LPWSTR
Definition: xmlstorage.h:184
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
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 323 of file pdo.c.

326 {
327  PPDO_DEVICE_EXTENSION PDODeviceExtension;
328  PFDO_DEVICE_EXTENSION FDODeviceExtension;
329  LPCSTR GenericType, DeviceType;
330  LPWSTR Buffer;
331  CHAR Id1[50], Id2[50], Id3[50], Id4[50], Id5[50], Id6[50], Id7[50];
332  ULONG Id1Length, Id2Length, Id3Length, Id4Length, Id5Length, Id6Length, Id7Length;
334  PINQUIRYDATA InquiryData;
335 
336  PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
337  FDODeviceExtension = (PFDO_DEVICE_EXTENSION)PDODeviceExtension->LowerDeviceObject->DeviceExtension;
338  ASSERT(FDODeviceExtension->DeviceDescriptor);
339  InquiryData = PDODeviceExtension->InquiryData;
340 
341  DeviceType = USBSTOR_GetDeviceType(InquiryData, PDODeviceExtension->IsFloppy);
342  GenericType = USBSTOR_GetGenericType(InquiryData, PDODeviceExtension->IsFloppy);
343 
344  ASSERT(GenericType);
345 
346  // generate id 1
347  // USBSTOR\SCSIType_VendorId(8)_ProductId(16)_Revision(4)
348  RtlZeroMemory(Id1, sizeof(Id1));
349  Offset = 0;
350  Offset = sprintf(&Id1[Offset], "USBSTOR\\");
351  Offset += sprintf(&Id1[Offset], DeviceType);
352  Offset += CopyField(InquiryData->VendorId, &Id1[Offset], 8);
353  Offset += CopyField(InquiryData->ProductId, &Id1[Offset], 16);
354  Offset += CopyField(InquiryData->ProductRevisionLevel, &Id1[Offset], 4);
355  Id1Length = strlen(Id1) + 1;
356  DPRINT("USBSTOR_PdoHandleQueryHardwareId HardwareId1 %s\n", Id1);
357 
358  // generate id 2
359  // USBSTOR\SCSIType_VendorId(8)_ProductId(16)
360  RtlZeroMemory(Id2, sizeof(Id2));
361  Offset = 0;
362  Offset = sprintf(&Id2[Offset], "USBSTOR\\");
363  Offset += sprintf(&Id2[Offset], DeviceType);
364  Offset += CopyField(InquiryData->VendorId, &Id2[Offset], 8);
365  Offset += CopyField(InquiryData->ProductId, &Id2[Offset], 16);
366  Id2Length = strlen(Id2) + 1;
367  DPRINT("USBSTOR_PdoHandleQueryHardwareId HardwareId2 %s\n", Id2);
368 
369  // generate id 3
370  // USBSTOR\SCSIType_VendorId(8)
371  RtlZeroMemory(Id3, sizeof(Id3));
372  Offset = 0;
373  Offset = sprintf(&Id3[Offset], "USBSTOR\\");
374  Offset += sprintf(&Id3[Offset], DeviceType);
375  Offset += CopyField(InquiryData->VendorId, &Id3[Offset], 8);
376  Id3Length = strlen(Id3) + 1;
377  DPRINT("USBSTOR_PdoHandleQueryHardwareId HardwareId3 %s\n", Id3);
378 
379  // generate id 4
380  // USBSTOR\SCSIType_VendorId(8)_ProductId(16)_Revision(1)
381  RtlZeroMemory(Id4, sizeof(Id4));
382  Offset = 0;
383  Offset = sprintf(&Id4[Offset], "USBSTOR\\");
384  Offset += sprintf(&Id4[Offset], DeviceType);
385  Offset += CopyField(InquiryData->VendorId, &Id4[Offset], 8);
386  Offset += CopyField(InquiryData->ProductId, &Id4[Offset], 16);
387  Offset += CopyField(InquiryData->ProductRevisionLevel, &Id4[Offset], 1);
388  Id4Length = strlen(Id4) + 1;
389  DPRINT("USBSTOR_PdoHandleQueryHardwareId HardwareId4 %s\n", Id4);
390 
391  // generate id 5
392  // SCSIType_VendorId(8)_ProductId(16)_Revision(1)
393  RtlZeroMemory(Id5, sizeof(Id5));
394  Offset = 0;
395  Offset = sprintf(&Id5[Offset], DeviceType);
396  Offset += CopyField(InquiryData->VendorId, &Id5[Offset], 8);
397  Offset += CopyField(InquiryData->ProductId, &Id5[Offset], 16);
398  Offset += CopyField(InquiryData->ProductRevisionLevel, &Id5[Offset], 1);
399  Id5Length = strlen(Id5) + 1;
400  DPRINT("USBSTOR_PdoHandleQueryHardwareId HardwareId5 %s\n", Id5);
401 
402  // generate id 6
403  // USBSTOR\SCSIType
404  RtlZeroMemory(Id6, sizeof(Id6));
405  Offset = 0;
406  Offset = sprintf(&Id6[Offset], "USBSTOR\\");
407  Offset += sprintf(&Id6[Offset], GenericType);
408  Id6Length = strlen(Id6) + 1;
409  DPRINT("USBSTOR_PdoHandleQueryHardwareId HardwareId6 %s\n", Id6);
410 
411  // generate id 7
412  // SCSIType
413  RtlZeroMemory(Id7, sizeof(Id7));
414  Offset = 0;
415  Offset = sprintf(&Id7[Offset], GenericType);
416  Id7Length = strlen(Id7) + 1;
417  DPRINT("USBSTOR_PdoHandleQueryHardwareId HardwareId7 %s\n", Id7);
418 
419  TotalLength = Id1Length + Id2Length + Id3Length + Id4Length + Id5Length + Id6Length + Id7Length + 1;
420 
422  if (!Buffer)
423  {
424  Irp->IoStatus.Information = 0;
426  }
427 
428  // reset offset
429  Offset = 0;
431 
439 
440  ASSERT(Offset + 1 == Length);
441 
442  Irp->IoStatus.Information = (ULONG_PTR)Buffer;
443  return STATUS_SUCCESS;
444 }
#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:288
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:124
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
UCHAR ProductId[16]
Definition: cdrw_hw.h:1133
UCHAR VendorId[8]
Definition: cdrw_hw.h:1132
_In_ ULONG TotalLength
Definition: usbdlib.h:145
LPCSTR USBSTOR_GetDeviceType(IN PINQUIRYDATA InquiryData, IN UCHAR IsFloppy)
Definition: pdo.c:19
#define sprintf(buf, format,...)
Definition: sprintf.c:55
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
LPCSTR USBSTOR_GetGenericType(IN PINQUIRYDATA InquiryData, IN UCHAR IsFloppy)
Definition: pdo.c:71
PVOID DeviceExtension
Definition: env_spec_w32.h:418
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)
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#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 484 of file pdo.c.

487 {
488  PPDO_DEVICE_EXTENSION PDODeviceExtension;
489  PFDO_DEVICE_EXTENSION FDODeviceExtension;
490  WCHAR Buffer[100];
491  ULONG Length;
493 
494  PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
495  FDODeviceExtension = (PFDO_DEVICE_EXTENSION)PDODeviceExtension->LowerDeviceObject->DeviceExtension;
496 
497  // format instance id
498  if (FDODeviceExtension->SerialNumber)
499  {
500  // using serial number from device
501  swprintf(Buffer, L"%s&%c", FDODeviceExtension->SerialNumber->bString, PDODeviceExtension->LUN);
502  }
503  else
504  {
505  // use instance count and LUN
506  swprintf(Buffer, L"%04lu&%c", FDODeviceExtension->InstanceCount, PDODeviceExtension->LUN);
507  }
508 
509  Length = wcslen(Buffer) + 1;
510 
512  if (!InstanceId)
513  {
514  Irp->IoStatus.Information = 0;
516  }
517 
519 
520  DPRINT("USBSTOR_PdoHandleQueryInstanceId %S\n", InstanceId);
521 
522  Irp->IoStatus.Information = (ULONG_PTR)InstanceId;
523  return STATUS_SUCCESS;
524 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PIRP Irp
Definition: csq.h:116
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:30
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
_Must_inspect_result_ _In_opt_ PVOID _In_opt_ PVOID InstanceId
Definition: fsrtlfuncs.h:907
PVOID DeviceExtension
Definition: env_spec_w32.h:418
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
_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
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
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 723 of file pdo.c.

730 {
732  PSENSE_DATA SenseBuffer;
733  PIO_STACK_LOCATION IoStack;
734  KEVENT Event;
735  PIRP Irp = NULL;
736  PMDL Mdl = NULL;
737  ULONG ix = 0;
739  UCHAR SrbStatus;
740 
741  DPRINT("USBSTOR_SendInternalCdb SCSIOP %x\n", Cdb->CDB6GENERIC.OperationCode);
742 
744  sizeof(SCSI_REQUEST_BLOCK),
745  USB_STOR_TAG);
746 
747  if (Srb)
748  {
749  SenseBuffer = ExAllocatePoolWithTag(NonPagedPool,
751  USB_STOR_TAG);
752 
753  if (SenseBuffer)
754  {
755  Mdl = IoAllocateMdl(OutDataBuffer,
756  *OutDataTransferLength,
757  FALSE,
758  FALSE,
759  NULL);
760 
761  if (!Mdl)
762  {
763  ExFreePoolWithTag(SenseBuffer, USB_STOR_TAG);
765  return Status;
766  }
767 
769 
770  // make 3 attempts - the device may be in STALL state after the first one
771  do
772  {
773  Irp = IoAllocateIrp(PdoDevice->StackSize, FALSE);
774 
775  if (!Irp)
776  {
777  break;
778  }
779 
780  IoStack = IoGetNextIrpStackLocation(Irp);
782  IoStack->Parameters.Scsi.Srb = Srb;
783 
785 
786  Srb->Length = sizeof(SCSI_REQUEST_BLOCK);
787  Srb->Function = SRB_FUNCTION_EXECUTE_SCSI;
788  Srb->CdbLength = CdbLength;
789  Srb->SenseInfoBufferLength = SENSE_BUFFER_SIZE;
791  Srb->DataTransferLength = *OutDataTransferLength;
792  Srb->TimeOutValue = TimeOutValue;
793  Srb->DataBuffer = OutDataBuffer;
794  Srb->SenseInfoBuffer = SenseBuffer;
795 
796  RtlCopyMemory(Srb->Cdb, Cdb, CdbLength);
797 
798  Irp->MdlAddress = Mdl;
799 
801 
804  &Event,
805  TRUE,
806  TRUE,
807  TRUE);
808 
809  if (IoCallDriver(PdoDevice, Irp) == STATUS_PENDING)
810  {
812  Executive,
813  KernelMode,
814  FALSE,
815  NULL);
816  }
817 
818  SrbStatus = SRB_STATUS(Srb->SrbStatus);
819 
820  IoFreeIrp(Irp);
821  Irp = NULL;
822 
823  if (SrbStatus == SRB_STATUS_SUCCESS ||
824  SrbStatus == SRB_STATUS_DATA_OVERRUN)
825  {
827  *OutDataTransferLength = Srb->DataTransferLength;
828  break;
829  }
830 
832 
833  ++ix;
834  } while (ix < 3);
835 
836  if (Mdl)
837  {
838  IoFreeMdl(Mdl);
839  }
840 
841  ExFreePoolWithTag(SenseBuffer, USB_STOR_TAG);
842  }
843 
845  }
846 
847  return Status;
848 }
#define TRUE
Definition: types.h:120
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
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
_In_ PVOID _In_ ULONG Event
Definition: iotypes.h:435
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define STATUS_PENDING
Definition: ntstatus.h:82
#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
#define USB_STOR_TAG
Definition: usbstor.h:10
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2647
Status
Definition: gdiplustypes.h:24
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
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:706
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#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:2772
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 706 of file pdo.c.

710 {
713 }
#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 IO_NO_INCREMENT
Definition: iotypes.h:566

Referenced by USBSTOR_SendInternalCdb().