ReactOS 0.4.16-dev-329-g9223134
pdo.c File Reference
#include "scsiport.h"
#include "scsitypes.h"
#include <debug.h>
Include dependency graph for pdo.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

PDEVICE_OBJECT PdoCreateLunDevice (_In_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension)
 
PSCSI_PORT_LUN_EXTENSION GetLunByPath (_In_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, _In_ UCHAR PathId, _In_ UCHAR TargetId, _In_ UCHAR Lun)
 
PSCSI_REQUEST_BLOCK_INFO SpiGetSrbData (_In_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, _In_ PSCSI_PORT_LUN_EXTENSION LunExtension, _In_ UCHAR QueueTag)
 
static ULONG CopyField (IN PUCHAR Name, IN PCHAR Buffer, IN ULONG MaxLength, IN CHAR DefaultCharacter, IN BOOLEAN Trim)
 
static NTSTATUS PdoHandleQueryDeviceText (_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
 
static NTSTATUS PdoHandleQueryDeviceId (_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
 
static VOID ConvertToUnicodeString (IN CHAR *Buffer, IN ULONG ResultBufferLength, IN ULONG ResultBufferOffset, OUT LPWSTR ResultBuffer, OUT PULONG NewResultBufferOffset)
 
static NTSTATUS PdoHandleQueryHardwareId (_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
 
static NTSTATUS PdoHandleQueryCompatibleId (_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
 
static NTSTATUS PdoHandleQueryInstanceId (_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
 
static NTSTATUS PdoHandleDeviceRelations (_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
 
NTSTATUS PdoDispatchPnp (_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file pdo.c.

Function Documentation

◆ ConvertToUnicodeString()

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

Definition at line 309 of file pdo.c.

315{
316 UNICODE_STRING DeviceString;
319
320 ASSERT(ResultBufferLength);
321 ASSERT(ResultBufferLength > ResultBufferOffset);
322
323 DPRINT("ResultBufferOffset %lu ResultBufferLength %lu Buffer %s Length %lu\n",
324 ResultBufferOffset, ResultBufferLength, Buffer, strlen(Buffer));
325
326 // construct destination string
327 DeviceString.Buffer = &ResultBuffer[ResultBufferOffset];
328 DeviceString.Length = 0;
329 DeviceString.MaximumLength = (ResultBufferLength - ResultBufferOffset) * sizeof(WCHAR);
330
331 // initialize source string
333
336
337 // subtract consumed bytes
338 ResultBufferLength -= (DeviceString.Length + sizeof(WCHAR)) / sizeof(WCHAR);
339 ResultBufferOffset += (DeviceString.Length + sizeof(WCHAR)) / sizeof(WCHAR);
340
341 *NewResultBufferOffset = ResultBufferOffset;
342}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
#define FALSE
Definition: types.h:117
@ AnsiString
Definition: dnslib.h:19
Status
Definition: gdiplustypes.h:25
PKMT_RESULTBUFFER ResultBuffer
#define ASSERT(a)
Definition: mode.c:44
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
USHORT MaximumLength
Definition: env_spec_w32.h:370
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by PdoHandleQueryCompatibleId(), and PdoHandleQueryHardwareId().

◆ CopyField()

static ULONG CopyField ( IN PUCHAR  Name,
IN PCHAR  Buffer,
IN ULONG  MaxLength,
IN CHAR  DefaultCharacter,
IN BOOLEAN  Trim 
)
static

Definition at line 124 of file pdo.c.

130{
131 ULONG Index;
132
133 for (Index = 0; Index < MaxLength; Index++)
134 {
135 if (Name[Index] <= ' ' || Name[Index] >= 0x7F /* last printable ascii character */ || Name[Index] == ',')
136 {
137 // convert to underscore
138 Buffer[Index] = DefaultCharacter;
139 }
140 else
141 {
142 // just copy character
144 }
145 }
146
147 /* Trim trailing default characters */
148 if (Trim)
149 {
150 Index = MaxLength - 1;
151 for (;;)
152 {
153 if (Buffer[Index] != DefaultCharacter)
154 {
155 Index++;
156 break;
157 }
158
159 Index--;
160 }
161 }
162
163 return Index;
164}
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by PdoHandleQueryDeviceId(), PdoHandleQueryDeviceText(), PdoHandleQueryHardwareId(), USBSTOR_PdoHandleQueryDeviceId(), and USBSTOR_PdoHandleQueryHardwareId().

◆ GetLunByPath()

PSCSI_PORT_LUN_EXTENSION GetLunByPath ( _In_ PSCSI_PORT_DEVICE_EXTENSION  DeviceExtension,
_In_ UCHAR  PathId,
_In_ UCHAR  TargetId,
_In_ UCHAR  Lun 
)

Definition at line 68 of file pdo.c.

73{
74 if (PathId >= DeviceExtension->NumberOfBuses)
75 {
76 DPRINT1("Invalid PathId: %u\n", PathId);
77 return NULL;
78 }
79
80 PSCSI_BUS_INFO bus = &DeviceExtension->Buses[PathId];
81
82 for (PLIST_ENTRY lunEntry = bus->LunsListHead.Flink;
83 lunEntry != &bus->LunsListHead;
84 lunEntry = lunEntry->Flink)
85 {
87 CONTAINING_RECORD(lunEntry, SCSI_PORT_LUN_EXTENSION, LunEntry);
88
89 if (lunExt->PathId == PathId &&
90 lunExt->TargetId == TargetId &&
91 lunExt->Lun == Lun)
92 {
93 return lunExt;
94 }
95 }
96
97 DPRINT("SCSI LUN (%u, %u, %u) was not found\n", PathId, TargetId, Lun);
98 return NULL;
99}
#define DPRINT1
Definition: precomp.h:8
_In_ ULONG _In_ BOOLEAN _In_ ULONG _In_ UCHAR _In_ UCHAR _In_ UCHAR Lun
Definition: classpnp.h:1315
_In_ ULONG _In_ BOOLEAN _In_ ULONG _In_ UCHAR PathId
Definition: classpnp.h:1313
_In_ ULONG _In_ BOOLEAN _In_ ULONG _In_ UCHAR _In_ UCHAR TargetId
Definition: classpnp.h:1314
#define NULL
Definition: types.h:112
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
LIST_ENTRY LunsListHead
Definition: scsiport.h:187
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by FdoScanAdapter(), ScsiPortGetLogicalUnit(), and ScsiPortNotification().

◆ PdoCreateLunDevice()

PDEVICE_OBJECT PdoCreateLunDevice ( _In_ PSCSI_PORT_DEVICE_EXTENSION  DeviceExtension)

Definition at line 18 of file pdo.c.

20{
21 PSCSI_PORT_LUN_EXTENSION LunExtension;
22 PDEVICE_OBJECT LunPDO;
23
24 ULONG LunExtensionSize = DeviceExtension->LunExtensionSize + sizeof(SCSI_PORT_LUN_EXTENSION);
25
26 NTSTATUS Status = IoCreateDevice(DeviceExtension->Common.DeviceObject->DriverObject,
27 LunExtensionSize,
28 NULL,
31 FALSE,
32 &LunPDO);
33
34 if (!NT_SUCCESS(Status))
35 {
36 DPRINT1("Failed to create a Lun PDO, status: %x\n", Status);
37 return NULL;
38 }
39
40 LunExtension = LunPDO->DeviceExtension;
41
42 /* Zero everything */
43 RtlZeroMemory(LunExtension, LunExtensionSize);
44
45 LunExtension->Common.IsFDO = FALSE;
46 LunExtension->Common.DeviceObject = LunPDO;
47 LunExtension->Common.LowerDevice = DeviceExtension->Common.DeviceObject;
48
49 /* Initialize a list of requests */
50 InitializeListHead(&LunExtension->SrbInfo.Requests);
51
52 /* Initialize timeout counter */
53 LunExtension->RequestTimeout = -1;
54
55 /* Set maximum queue size */
56 LunExtension->MaxQueueCount = 256;
57
58 /* Initialize request queue */
60
61 LunPDO->Flags |= DO_DIRECT_IO;
62 LunPDO->Flags &= ~DO_DEVICE_INITIALIZING;
63
64 return LunPDO;
65}
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
VOID NTAPI KeInitializeDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue)
Definition: devqueue.c:22
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define FILE_AUTOGENERATED_DEVICE_NAME
Definition: iotypes.h:138
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 FILE_DEVICE_DISK
Definition: winioctl.h:52
struct _SCSI_PORT_LUN_EXTENSION SCSI_PORT_LUN_EXTENSION
PVOID DeviceExtension
Definition: env_spec_w32.h:418
PDEVICE_OBJECT LowerDevice
Definition: scsiport.h:139
PDEVICE_OBJECT DeviceObject
Definition: scsiport.h:138
KDEVICE_QUEUE DeviceQueue
Definition: scsiport.h:160
SCSI_PORT_COMMON_EXTENSION Common
Definition: scsiport.h:146
SCSI_REQUEST_BLOCK_INFO SrbInfo
Definition: scsiport.h:174
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

Referenced by FdoScanAdapter().

◆ PdoDispatchPnp()

NTSTATUS PdoDispatchPnp ( _In_ PDEVICE_OBJECT  DeviceObject,
_Inout_ PIRP  Irp 
)

Definition at line 554 of file pdo.c.

557{
559 PSCSI_PORT_LUN_EXTENSION lunExt = DeviceObject->DeviceExtension;
561
562 DPRINT("PDO PnP request %s\n", GetIRPMinorFunctionString(ioStack->MinorFunction));
563
564 ASSERT(!lunExt->Common.IsFDO);
565
566 switch (ioStack->MinorFunction)
567 {
569 {
570 RegistryInitLunKey(lunExt);
572 break;
573 }
579 {
581 break;
582 }
584 {
586 break;
587 }
589 {
591 break;
592 }
593 case IRP_MN_QUERY_ID:
594 {
595 DPRINT("IRP_MN_QUERY_ID IdType %s\n",
596 DbgGetDeviceIDString(ioStack->Parameters.QueryId.IdType));
597
598 if (ioStack->Parameters.QueryId.IdType == BusQueryDeviceID)
599 {
601 break;
602 }
603 else if (ioStack->Parameters.QueryId.IdType == BusQueryHardwareIDs)
604 {
606 break;
607 }
608 else if (ioStack->Parameters.QueryId.IdType == BusQueryInstanceID)
609 {
611 break;
612 }
613 else if (ioStack->Parameters.QueryId.IdType == BusQueryCompatibleIDs)
614 {
616 break;
617 }
618
619 // fallthrough
620 }
621 default:
622 {
623 // do nothing
624 status = Irp->IoStatus.Status;
625 }
626 }
627
628 if (status != STATUS_PENDING)
629 {
630 Irp->IoStatus.Status = status;
632 }
633
634 return status;
635}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_PENDING
Definition: d3dkmdt.h:43
FORCEINLINE PCHAR GetIRPMinorFunctionString(UCHAR MinorFunction)
Definition: driverdbg.h:13
PCHAR DbgGetDeviceIDString(BUS_QUERY_ID_TYPE Type)
Definition: driverdbg.h:93
NTSTATUS RegistryInitLunKey(_Inout_ PSCSI_PORT_LUN_EXTENSION LunExtension)
Definition: registry.c:359
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
#define IoCompleteRequest
Definition: irp.c:1240
static NTSTATUS PdoHandleDeviceRelations(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: pdo.c:524
static NTSTATUS PdoHandleQueryDeviceText(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: pdo.c:168
static NTSTATUS PdoHandleQueryHardwareId(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: pdo.c:346
static NTSTATUS PdoHandleQueryInstanceId(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: pdo.c:493
static NTSTATUS PdoHandleQueryCompatibleId(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: pdo.c:457
static NTSTATUS PdoHandleQueryDeviceId(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: pdo.c:263
union _IO_STACK_LOCATION::@1581 Parameters
struct _IO_STACK_LOCATION::@3980::@4011 QueryId
Definition: ps.c:97
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MN_START_DEVICE
#define IRP_MN_QUERY_ID
#define IRP_MN_REMOVE_DEVICE
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define IRP_MN_QUERY_STOP_DEVICE
#define IRP_MN_QUERY_DEVICE_TEXT
#define IRP_MN_QUERY_CAPABILITIES
@ BusQueryCompatibleIDs
Definition: iotypes.h:2938
@ BusQueryInstanceID
Definition: iotypes.h:2939
@ BusQueryDeviceID
Definition: iotypes.h:2936
@ BusQueryHardwareIDs
Definition: iotypes.h:2937
#define IRP_MN_QUERY_REMOVE_DEVICE

Referenced by ScsiPortDispatchPnp().

◆ PdoHandleDeviceRelations()

static NTSTATUS PdoHandleDeviceRelations ( _In_ PDEVICE_OBJECT  DeviceObject,
_Inout_ PIRP  Irp 
)
static

Definition at line 524 of file pdo.c.

527{
528 PDEVICE_RELATIONS deviceRelations;
530
531 // check if relation type is BusRelations
533 {
534 // PDO handles only target device relation
535 return Irp->IoStatus.Status;
536 }
537
539 if (!deviceRelations)
540 {
542 }
543
544 // initialize device relations
545 deviceRelations->Count = 1;
546 deviceRelations->Objects[0] = DeviceObject;
548
549 Irp->IoStatus.Information = (ULONG_PTR)deviceRelations;
550 return STATUS_SUCCESS;
551}
#define ULONG_PTR
Definition: config.h:101
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
#define TAG_SCSIPORT
Definition: scsiport.h:21
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2163
struct _IO_STACK_LOCATION::@3980::@4005 QueryDeviceRelations
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
@ TargetDeviceRelation
Definition: iotypes.h:2156
#define ObReferenceObject
Definition: obfuncs.h:204

Referenced by PdoDispatchPnp().

◆ PdoHandleQueryCompatibleId()

static NTSTATUS PdoHandleQueryCompatibleId ( _In_ PDEVICE_OBJECT  DeviceObject,
_Inout_ PIRP  Irp 
)
static

Definition at line 457 of file pdo.c.

460{
461 PSCSI_PORT_LUN_EXTENSION PDODeviceExtension = DeviceObject->DeviceExtension;
462 CHAR Buffer[100] = {0};
466
467 DeviceType = GetDeviceType(&PDODeviceExtension->InquiryData);
468
469 // format instance id
470 Length = sprintf(Buffer, "SCSI\\%s", DeviceType) + 1;
471 Length += sprintf(&Buffer[Length], "SCSI\\%s", "RAW") + 2;
472
474 if (!InstanceId)
475 {
476 Irp->IoStatus.Information = 0;
478 }
479
482
484
485 DPRINT("PdoHandleQueryCompatibleId %S\n", InstanceId);
486
487 Irp->IoStatus.Information = (ULONG_PTR)InstanceId;
488 return STATUS_SUCCESS;
489}
_Must_inspect_result_ _In_opt_ PVOID _In_opt_ PVOID InstanceId
Definition: fsrtlfuncs.h:908
DeviceType
Definition: mmdrv.h:42
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define UNICODE_NULL
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
FORCEINLINE PCSTR GetDeviceType(_In_ PINQUIRYDATA InquiryData)
Definition: scsitypes.h:7
static VOID ConvertToUnicodeString(IN CHAR *Buffer, IN ULONG ResultBufferLength, IN ULONG ResultBufferOffset, OUT LPWSTR ResultBuffer, OUT PULONG NewResultBufferOffset)
Definition: pdo.c:309
INQUIRYDATA InquiryData
Definition: scsiport.h:158
const char * LPCSTR
Definition: xmlstorage.h:183
WCHAR * LPWSTR
Definition: xmlstorage.h:184
char CHAR
Definition: xmlstorage.h:175

Referenced by PdoDispatchPnp().

◆ PdoHandleQueryDeviceId()

static NTSTATUS PdoHandleQueryDeviceId ( _In_ PDEVICE_OBJECT  DeviceObject,
_Inout_ PIRP  Irp 
)
static

Definition at line 263 of file pdo.c.

266{
267 PSCSI_PORT_LUN_EXTENSION DeviceExtension;
269 CHAR Buffer[100] = {0};
271 ULONG Offset = 0;
272 PINQUIRYDATA InquiryData;
274 UNICODE_STRING DeviceId;
275
276 DeviceExtension = DeviceObject->DeviceExtension;
277 InquiryData = &DeviceExtension->InquiryData;
278
279 DeviceType = GetDeviceType(InquiryData);
280
281 // lets create device string
282 Offset = sprintf(&Buffer[Offset], "SCSI\\");
284 Offset += sprintf(&Buffer[Offset], "&Ven_");
285 Offset += CopyField(InquiryData->VendorId, &Buffer[Offset], 8, '_', TRUE);
286 Offset += sprintf(&Buffer[Offset], "&Prod_");
287 Offset += CopyField(InquiryData->ProductId, &Buffer[Offset], 16, '_', TRUE);
288 Offset += sprintf(&Buffer[Offset], "&Rev_");
289 Offset += CopyField(InquiryData->ProductRevisionLevel, &Buffer[Offset], 4, '_', TRUE);
290 Buffer[Offset] = '\0';
291
293
294 // allocate DeviceId string
296
297 if (NT_SUCCESS(Status))
298 {
299 Irp->IoStatus.Information = (ULONG_PTR)DeviceId.Buffer;
300 }
301
302 DPRINT("DeviceId %wZ Status %x\n", &DeviceId, Status);
303
304 return Status;
305}
#define TRUE
Definition: types.h:120
static ULONG CopyField(IN PUCHAR Name, IN PCHAR Buffer, IN ULONG MaxLength, IN CHAR DefaultCharacter, IN BOOLEAN Trim)
Definition: pdo.c:124
UCHAR ProductId[16]
Definition: cdrw_hw.h:1133
UCHAR ProductRevisionLevel[4]
Definition: cdrw_hw.h:1134
UCHAR VendorId[8]
Definition: cdrw_hw.h:1132
CONST char * PCSZ
Definition: umtypes.h:125

Referenced by PdoDispatchPnp().

◆ PdoHandleQueryDeviceText()

static NTSTATUS PdoHandleQueryDeviceText ( _In_ PDEVICE_OBJECT  DeviceObject,
_Inout_ PIRP  Irp 
)
static

Definition at line 168 of file pdo.c.

171{
172 PSCSI_PORT_LUN_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
173 PIO_STACK_LOCATION IoStack;
174 UINT32 Offset = 0;
175 PINQUIRYDATA InquiryData;
176 CHAR LocalBuffer[64];
179
180 DPRINT("PdoHandleQueryDeviceText\n");
181
183
184 InquiryData = &DeviceExtension->InquiryData;
185
186 switch (IoStack->Parameters.QueryDeviceText.DeviceTextType)
187 {
189 {
190 DPRINT("DeviceTextDescription\n");
191
192 Offset += CopyField(InquiryData->VendorId,
193 &LocalBuffer[Offset],
194 sizeof(InquiryData->VendorId),
195 ' ',
196 TRUE);
197 LocalBuffer[Offset++] = ' ';
198 Offset += CopyField(InquiryData->ProductId,
199 &LocalBuffer[Offset],
200 sizeof(InquiryData->ProductId),
201 ' ',
202 TRUE);
203 Offset += sprintf(&LocalBuffer[Offset],
204 " SCSI %s Device",
205 GetDeviceType(InquiryData));
206 LocalBuffer[Offset++] = '\0';
207
208 RtlInitAnsiString(&AnsiString, (PCSZ)&LocalBuffer);
209
210 DeviceDescription.Length = 0;
211 DeviceDescription.MaximumLength = (USHORT)(Offset * sizeof(WCHAR));
213 DeviceDescription.MaximumLength,
215 if (!DeviceDescription.Buffer)
216 {
217 Irp->IoStatus.Information = 0;
219 }
220
222
223 Irp->IoStatus.Information = (ULONG_PTR)DeviceDescription.Buffer;
224 return STATUS_SUCCESS;
225 }
226
228 {
229 DPRINT("DeviceTextLocationInformation\n");
230
231 sprintf(LocalBuffer, "Bus Number %d, Target ID %d, LUN %d",
232 DeviceExtension->PathId, DeviceExtension->TargetId, DeviceExtension->Lun);
233
234 RtlInitAnsiString(&AnsiString, (PCSZ)&LocalBuffer);
235
236 DeviceDescription.Length = 0;
237 DeviceDescription.MaximumLength = (USHORT)((strlen(LocalBuffer) + 1) * sizeof(WCHAR));
239 DeviceDescription.MaximumLength,
241 if (!DeviceDescription.Buffer)
242 {
243 Irp->IoStatus.Information = 0;
245 }
246
248
249 Irp->IoStatus.Information = (ULONG_PTR)DeviceDescription.Buffer;
250 return STATUS_SUCCESS;
251 }
252
253 default:
254 {
255 Irp->IoStatus.Information = 0;
256 return Irp->IoStatus.Status;
257 }
258 }
259}
unsigned int UINT32
unsigned short USHORT
Definition: pedump.c:61
struct _IO_STACK_LOCATION::@3980::@4012 QueryDeviceText
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ PCUNICODE_STRING DeviceDescription
Definition: wdfpdo.h:432
@ DeviceTextLocationInformation
Definition: iotypes.h:2946
@ DeviceTextDescription
Definition: iotypes.h:2945

Referenced by PdoDispatchPnp().

◆ PdoHandleQueryHardwareId()

static NTSTATUS PdoHandleQueryHardwareId ( _In_ PDEVICE_OBJECT  DeviceObject,
_Inout_ PIRP  Irp 
)
static

Definition at line 346 of file pdo.c.

349{
350 PSCSI_PORT_LUN_EXTENSION PDODeviceExtension = DeviceObject->DeviceExtension;
351 LPCSTR GenericType, DeviceType;
353 CHAR Id1[50], Id2[50], Id3[50], Id4[50], Id5[50], Id6[50];
354 ULONG Id1Length, Id2Length, Id3Length, Id4Length, Id5Length, Id6Length;
356 PINQUIRYDATA InquiryData;
357
358 InquiryData = &PDODeviceExtension->InquiryData;
359
360 DeviceType = GetDeviceType(InquiryData);
361 GenericType = GetGenericType(InquiryData);
362
363 ASSERT(GenericType);
364
365 // generate id 1
366 // SCSI\SCSIType_VendorId(8)_ProductId(16)_Revision(4)
367 RtlZeroMemory(Id1, sizeof(Id1));
368 Offset = 0;
369 Offset = sprintf(&Id1[Offset], "SCSI\\");
370 Offset += sprintf(&Id1[Offset], DeviceType);
371 Offset += CopyField(InquiryData->VendorId, &Id1[Offset], 8, '_', FALSE);
372 Offset += CopyField(InquiryData->ProductId, &Id1[Offset], 16, '_', FALSE);
373 Offset += CopyField(InquiryData->ProductRevisionLevel, &Id1[Offset], 4, '_', FALSE);
374 Id1Length = strlen(Id1) + 1;
375 DPRINT("PdoHandleQueryHardwareId HardwareId1 %s\n", Id1);
376
377 // generate id 2
378 // SCSI\SCSIType_VendorId(8)_ProductId(16)
379 RtlZeroMemory(Id2, sizeof(Id2));
380 Offset = 0;
381 Offset = sprintf(&Id2[Offset], "SCSI\\");
382 Offset += sprintf(&Id2[Offset], DeviceType);
383 Offset += CopyField(InquiryData->VendorId, &Id2[Offset], 8, '_', FALSE);
384 Offset += CopyField(InquiryData->ProductId, &Id2[Offset], 16, '_', FALSE);
385 Id2Length = strlen(Id2) + 1;
386 DPRINT("PdoHandleQueryHardwareId HardwareId2 %s\n", Id2);
387
388 // generate id 3
389 // SCSI\SCSIType_VendorId(8)
390 RtlZeroMemory(Id3, sizeof(Id3));
391 Offset = 0;
392 Offset = sprintf(&Id3[Offset], "SCSI\\");
393 Offset += sprintf(&Id3[Offset], DeviceType);
394 Offset += CopyField(InquiryData->VendorId, &Id3[Offset], 8, '_', FALSE);
395 Id3Length = strlen(Id3) + 1;
396 DPRINT("PdoHandleQueryHardwareId HardwareId3 %s\n", Id3);
397
398 // generate id 4
399 // SCSI\VendorId(8)_ProductId(16)_Revision(1)
400 RtlZeroMemory(Id4, sizeof(Id4));
401 Offset = 0;
402 Offset = sprintf(&Id4[Offset], "SCSI\\");
403 Offset += CopyField(InquiryData->VendorId, &Id4[Offset], 8, '_', FALSE);
404 Offset += CopyField(InquiryData->ProductId, &Id4[Offset], 16, '_', FALSE);
405 Offset += CopyField(InquiryData->ProductRevisionLevel, &Id4[Offset], 1, '_', FALSE);
406 Id4Length = strlen(Id4) + 1;
407 DPRINT("PdoHandleQueryHardwareId HardwareId4 %s\n", Id4);
408
409 // generate id 5
410 // VendorId(8)_ProductId(16)_Revision(1)
411 RtlZeroMemory(Id5, sizeof(Id5));
412 Offset = 0;
413 Offset = CopyField(InquiryData->VendorId, &Id5[Offset], 8, '_', FALSE);
414 Offset += CopyField(InquiryData->ProductId, &Id5[Offset], 16, '_', FALSE);
415 Offset += CopyField(InquiryData->ProductRevisionLevel, &Id5[Offset], 1, '_', FALSE);
416 Id5Length = strlen(Id5) + 1;
417 DPRINT("PdoHandleQueryHardwareId HardwareId5 %s\n", Id5);
418
419 // generate id 6
420 // SCSIType
421 RtlZeroMemory(Id6, sizeof(Id6));
422 Offset = 0;
423 Offset = sprintf(&Id6[Offset], GenericType);
424 Id6Length = strlen(Id6) + 1;
425 DPRINT("PdoHandleQueryHardwareId HardwareId6 %s\n", Id6);
426
427 TotalLength = Id1Length + Id2Length + Id3Length + Id4Length + Id5Length + Id6Length + 1;
428
430 if (!Buffer)
431 {
432 Irp->IoStatus.Information = 0;
434 }
435
436 // reset offset
437 Offset = 0;
439
446
448
449 ASSERT(Offset + 1 == Length);
450
451 Irp->IoStatus.Information = (ULONG_PTR)Buffer;
452 return STATUS_SUCCESS;
453}
FORCEINLINE PCSTR GetGenericType(_In_ PINQUIRYDATA InquiryData)
Definition: scsitypes.h:49
_In_ ULONG TotalLength
Definition: usbdlib.h:158

Referenced by PdoDispatchPnp().

◆ PdoHandleQueryInstanceId()

static NTSTATUS PdoHandleQueryInstanceId ( _In_ PDEVICE_OBJECT  DeviceObject,
_Inout_ PIRP  Irp 
)
static

Definition at line 493 of file pdo.c.

496{
497 PSCSI_PORT_LUN_EXTENSION lunExt = DeviceObject->DeviceExtension;
498 WCHAR Buffer[26];
501
502 // use instance count and LUN
503 swprintf(Buffer, L"%x%x%x", lunExt->PathId, lunExt->TargetId, lunExt->Lun);
504
505 Length = wcslen(Buffer) + 1;
506
508 if (!InstanceId)
509 {
510 Irp->IoStatus.Information = 0;
512 }
513
515
516 DPRINT("PdoHandleQueryInstanceId %S\n", InstanceId);
517
518 Irp->IoStatus.Information = (ULONG_PTR)InstanceId;
519 return STATUS_SUCCESS;
520}
#define swprintf
Definition: precomp.h:40
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define L(x)
Definition: ntvdm.h:50
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)

Referenced by PdoDispatchPnp().

◆ SpiGetSrbData()

PSCSI_REQUEST_BLOCK_INFO SpiGetSrbData ( _In_ PSCSI_PORT_DEVICE_EXTENSION  DeviceExtension,
_In_ PSCSI_PORT_LUN_EXTENSION  LunExtension,
_In_ UCHAR  QueueTag 
)

Definition at line 102 of file pdo.c.

106{
107 if (QueueTag == SP_UNTAGGED)
108 {
109 /* Return the pointer to SrbInfo */
110 return &LunExtension->SrbInfo;
111 }
112 else
113 {
114 /* Make sure the tag is valid, if it is - return the data */
115 if (QueueTag > DeviceExtension->SrbDataCount || QueueTag < 1)
116 return NULL;
117 else
118 return &DeviceExtension->SrbInfo[QueueTag -1];
119 }
120}
#define SP_UNTAGGED
Definition: srb.h:233

Referenced by ScsiPortGetPhysicalAddress(), ScsiPortNotification(), ScsiPortStartPacket(), and SpiAllocateSrbStructures().