ReactOS 0.4.16-dev-1946-g52006dd
disk.c File Reference
#include "usbstor.h"
#include <sptilib.h>
#include <debug.h>
Include dependency graph for disk.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define USBSTOR_DEFAULT_MAX_PHYS_PAGES   (USBSTOR_DEFAULT_MAX_TRANSFER_LENGTH / PAGE_SIZE + 1)
 

Functions

static BOOLEAN IsRequestValid (PIRP Irp)
 
NTSTATUS USBSTOR_HandleInternalDeviceControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
ULONG USBSTOR_GetFieldLength (IN PUCHAR Name, IN ULONG MaxLength)
 
NTSTATUS USBSTOR_HandleQueryProperty (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS USBSTOR_HandleDeviceControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file disk.c.

◆ USBSTOR_DEFAULT_MAX_PHYS_PAGES

#define USBSTOR_DEFAULT_MAX_PHYS_PAGES   (USBSTOR_DEFAULT_MAX_TRANSFER_LENGTH / PAGE_SIZE + 1)

Definition at line 18 of file disk.c.

Function Documentation

◆ IsRequestValid()

static BOOLEAN IsRequestValid ( PIRP  Irp)
static

Definition at line 22 of file disk.c.

23{
24 ULONG TransferLength;
25 PIO_STACK_LOCATION IoStack;
27
29 Srb = IoStack->Parameters.Scsi.Srb;
30
32 {
34 {
35 DPRINT1("IsRequestValid: Invalid Srb. Srb->SrbFlags - %X\n", Srb->SrbFlags);
36 return FALSE;
37 }
38
39 TransferLength = Srb->DataTransferLength;
40
41 if (Irp->MdlAddress == NULL)
42 {
43 DPRINT1("IsRequestValid: Invalid Srb. Irp->MdlAddress == NULL\n");
44 return FALSE;
45 }
46
47 if (TransferLength == 0)
48 {
49 DPRINT1("IsRequestValid: Invalid Srb. TransferLength == 0\n");
50 return FALSE;
51 }
52
53 if (TransferLength > USBSTOR_DEFAULT_MAX_TRANSFER_LENGTH)
54 {
55 DPRINT1("IsRequestValid: Invalid Srb. TransferLength > 0x10000\n");
56 return FALSE;
57 }
58 }
59 else
60 {
62 {
63 DPRINT1("IsRequestValid: Invalid Srb. Srb->DataTransferLength != 0\n");
64 return FALSE;
65 }
66
67 if (Srb->DataBuffer)
68 {
69 DPRINT1("IsRequestValid: Invalid Srb. Srb->DataBuffer != NULL\n");
70 return FALSE;
71 }
72
73 if (Irp->MdlAddress)
74 {
75 DPRINT1("IsRequestValid: Invalid Srb. Irp->MdlAddress != NULL\n");
76 return FALSE;
77 }
78 }
79
80 return TRUE;
81}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define DPRINT1
Definition: precomp.h:8
_In_ PSCSI_REQUEST_BLOCK Srb
Definition: cdrom.h:989
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define SRB_FLAGS_DATA_OUT
Definition: srb.h:401
#define SRB_FLAGS_DATA_IN
Definition: srb.h:400
#define SRB_FLAGS_UNSPECIFIED_DIRECTION
Definition: srb.h:403
struct _IO_STACK_LOCATION::@4278::@4300 Scsi
union _IO_STACK_LOCATION::@1694 Parameters
PVOID DataBuffer
Definition: srb.h:263
ULONG DataTransferLength
Definition: srb.h:261
ULONG SrbFlags
Definition: srb.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define USBSTOR_DEFAULT_MAX_TRANSFER_LENGTH
Definition: usbstor.h:63

Referenced by USBSTOR_HandleInternalDeviceControl().

◆ USBSTOR_GetFieldLength()

ULONG USBSTOR_GetFieldLength ( IN PUCHAR  Name,
IN ULONG  MaxLength 
)

Definition at line 202 of file disk.c.

205{
206 ULONG Index;
207 ULONG LastCharacterPosition = 0;
208
209 // scan the field and return last position which contains a valid character
210 for(Index = 0; Index < MaxLength; Index++)
211 {
212 if (Name[Index] != ' ')
213 {
214 // trim white spaces from field
215 LastCharacterPosition = Index;
216 }
217 }
218
219 // convert from zero based index to length
220 return LastCharacterPosition + 1;
221}
LPWSTR Name
Definition: desk.c:124
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by USBSTOR_HandleDeviceControl(), and USBSTOR_HandleQueryProperty().

◆ USBSTOR_HandleDeviceControl()

NTSTATUS USBSTOR_HandleDeviceControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 416 of file disk.c.

419{
420 PIO_STACK_LOCATION IoStack;
422 PPDO_DEVICE_EXTENSION PDODeviceExtension;
424 PSCSI_INQUIRY_DATA ScsiInquiryData;
425 PINQUIRYDATA InquiryData;
426
428
429 switch (IoStack->Parameters.DeviceIoControl.IoControlCode)
430 {
433 break;
436 {
437 PDODeviceExtension = DeviceObject->DeviceExtension;
438
440 ASSERT(PDODeviceExtension);
441 ASSERT(PDODeviceExtension->Common.IsFDO == FALSE);
442
443 /* Skip requests that bypassed the class driver. See also cdrom!RequestHandleScsiPassThrough */
444 if ((IoGetCurrentIrpStackLocation(Irp)->MinorFunction == 0) && PDODeviceExtension->Claimed)
445 {
447 break;
448 }
449
451 Irp,
454 break;
455 }
457 DPRINT1("USBSTOR_HandleDeviceControl IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER NOT implemented\n");
459 break;
461 {
463
464 // Legacy port capability query
465 if (IoStack->Parameters.DeviceIoControl.OutputBufferLength == sizeof(PVOID))
466 {
467 Capabilities = *((PVOID *)Irp->AssociatedIrp.SystemBuffer) = ExAllocatePoolWithTag(NonPagedPool,
468 sizeof(IO_SCSI_CAPABILITIES),
470 Irp->IoStatus.Information = sizeof(PVOID);
471 }
472 else
473 {
474 Capabilities = Irp->AssociatedIrp.SystemBuffer;
475 Irp->IoStatus.Information = sizeof(IO_SCSI_CAPABILITIES);
476 }
477
478 if (Capabilities)
479 {
480 Capabilities->MaximumTransferLength = USBSTOR_DEFAULT_MAX_TRANSFER_LENGTH;
481 Capabilities->MaximumPhysicalPages = USBSTOR_DEFAULT_MAX_PHYS_PAGES;
482 Capabilities->SupportedAsynchronousEvents = 0;
483 Capabilities->AlignmentMask = 0;
484 Capabilities->TaggedQueuing = FALSE;
485 Capabilities->AdapterScansDown = FALSE;
486 Capabilities->AdapterUsesPio = FALSE;
488 }
489 else
490 {
492 }
493
494 break;
495 }
497 {
498 PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
499 ASSERT(PDODeviceExtension);
500 ASSERT(PDODeviceExtension->Common.IsFDO == FALSE);
501
502 // get parameters
503 BusInfo = Irp->AssociatedIrp.SystemBuffer;
504 ScsiInquiryData = (PSCSI_INQUIRY_DATA)(BusInfo + 1);
505 InquiryData = (PINQUIRYDATA)ScsiInquiryData->InquiryData;
506
507
508 BusInfo->NumberOfBuses = 1;
509 BusInfo->BusData[0].NumberOfLogicalUnits = 1; //FIXME
510 BusInfo->BusData[0].InitiatorBusId = 0;
511 BusInfo->BusData[0].InquiryDataOffset = sizeof(SCSI_ADAPTER_BUS_INFO);
512
513 ScsiInquiryData->PathId = 0;
514 ScsiInquiryData->TargetId = 0;
515 ScsiInquiryData->Lun = PDODeviceExtension->LUN & MAX_LUN;
516 ScsiInquiryData->DeviceClaimed = PDODeviceExtension->Claimed;
517 ScsiInquiryData->InquiryDataLength = sizeof(INQUIRYDATA);
518 ScsiInquiryData->NextInquiryDataOffset = 0;
519
520 // Note: INQUIRYDATA structure is larger than INQUIRYDATABUFFERSIZE
521 RtlZeroMemory(InquiryData, sizeof(INQUIRYDATA));
522 RtlCopyMemory(InquiryData, &PDODeviceExtension->InquiryData, sizeof(PDODeviceExtension->InquiryData));
523
524 InquiryData->Versions = 0x04;
525 InquiryData->ResponseDataFormat = 0x02; // some devices set this to 1
526
527 Irp->IoStatus.Information = sizeof(SCSI_ADAPTER_BUS_INFO) + sizeof(SCSI_INQUIRY_DATA) + sizeof(INQUIRYDATA) - 1;
529
530 break;
531 }
533 {
534 PSCSI_ADDRESS Address = Irp->AssociatedIrp.SystemBuffer;
535
536 Address->Length = sizeof(SCSI_ADDRESS);
537 Address->PortNumber = 0;
538 Address->PathId = 0;
539 Address->TargetId = 0;
540 Address->Lun = (((PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LUN & MAX_LUN);
541 Irp->IoStatus.Information = sizeof(SCSI_ADDRESS);
542
544
545 break;
546 }
547 default:
548 DPRINT("USBSTOR_HandleDeviceControl IoControl %x not supported\n", IoStack->Parameters.DeviceIoControl.IoControlCode);
550 break;
551 }
552
553 return Status;
554}
LONG NTSTATUS
Definition: precomp.h:26
struct _INQUIRYDATA * PINQUIRYDATA
struct _INQUIRYDATA INQUIRYDATA
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
NTSTATUS USBSTOR_HandleQueryProperty(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: disk.c:224
#define USBSTOR_DEFAULT_MAX_PHYS_PAGES
Definition: disk.c:18
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define NonPagedPool
Definition: env_spec_w32.h:307
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
Status
Definition: gdiplustypes.h:25
_Must_inspect_result_ typedef _Out_ PHIDP_CAPS Capabilities
Definition: hidclass.h:103
#define ASSERT(a)
Definition: mode.c:44
static WCHAR Address[46]
Definition: ping.c:68
#define IOCTL_STORAGE_QUERY_PROPERTY
Definition: ntddstor.h:178
#define IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER
Definition: ntddstor.h:151
#define IOCTL_SCSI_PASS_THROUGH
Definition: scsi_port.h:47
#define IOCTL_SCSI_GET_ADDRESS
Definition: scsi_port.h:52
#define IOCTL_SCSI_GET_CAPABILITIES
Definition: scsi_port.h:50
struct _SCSI_ADAPTER_BUS_INFO SCSI_ADAPTER_BUS_INFO
#define IOCTL_SCSI_PASS_THROUGH_DIRECT
Definition: scsi_port.h:51
struct _SCSI_INQUIRY_DATA * PSCSI_INQUIRY_DATA
struct _SCSI_ADDRESS SCSI_ADDRESS
#define IOCTL_SCSI_GET_INQUIRY_DATA
Definition: scsi_port.h:49
struct _IO_SCSI_CAPABILITIES IO_SCSI_CAPABILITIES
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
NTSTATUS SptiHandleScsiPassthru(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp, _In_ ULONG MaximumTransferLength, _In_ ULONG MaximumPhysicalPages)
Handler for the IOCTL_SCSI_PASS_THROUGH and IOCTL_SCSI_PASS_THROUGH_DIRECT requests.
Definition: sptilib.c:888
UCHAR Versions
Definition: cdrw_hw.h:1120
UCHAR ResponseDataFormat
Definition: cdrw_hw.h:1121
struct _IO_STACK_LOCATION::@1694::@1695 DeviceIoControl
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:59
SCSI_BUS_DATA BusData[1]
Definition: scsi_port.h:106
ULONG InquiryDataOffset
Definition: scsi_port.h:98
UCHAR NumberOfLogicalUnits
Definition: scsi_port.h:96
UCHAR InitiatorBusId
Definition: scsi_port.h:97
UCHAR InquiryData[1]
Definition: scsi_port.h:119
ULONG NextInquiryDataOffset
Definition: scsi_port.h:118
ULONG InquiryDataLength
Definition: scsi_port.h:117
BOOLEAN DeviceClaimed
Definition: scsi_port.h:116
void * PVOID
Definition: typedefs.h:50
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define MAX_LUN
Definition: usbstor.h:62
#define USB_STOR_TAG
Definition: usbstor.h:11
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2061
_In_ UCHAR _In_ UCHAR MinorFunction
Definition: wdfdevice.h:1705

Referenced by USBSTOR_DispatchDeviceControl().

◆ USBSTOR_HandleInternalDeviceControl()

NTSTATUS USBSTOR_HandleInternalDeviceControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 84 of file disk.c.

87{
88 PIO_STACK_LOCATION IoStack;
90 PPDO_DEVICE_EXTENSION PDODeviceExtension;
92
94 Request = (PSCSI_REQUEST_BLOCK)IoStack->Parameters.Others.Argument1;
96 PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
97 ASSERT(PDODeviceExtension->Common.IsFDO == FALSE);
98
99 switch(Request->Function)
100 {
102 {
103 DPRINT("SRB_FUNCTION_EXECUTE_SCSI\n");
104
105 if (!IsRequestValid(Irp))
106 {
108 break;
109 }
110
111 if (Request->Cdb[0] == SCSIOP_MODE_SENSE)
112 {
113 DPRINT("USBSTOR_Scsi: SRB_FUNCTION_EXECUTE_SCSI - FIXME SCSIOP_MODE_SENSE\n");
114 // FIXME Get from registry WriteProtect for StorageDevicePolicies;
115 // L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\StorageDevicePolicies"
116 // QueryTable[0].Name = L"WriteProtect"
117 }
118
120 Request->SrbStatus = SRB_STATUS_PENDING;
121
122 // add the request
123 if (!USBSTOR_QueueAddIrp(PDODeviceExtension->LowerDeviceObject, Irp))
124 {
125 IoStartPacket(PDODeviceExtension->LowerDeviceObject, Irp, &Request->QueueSortKey, USBSTOR_CancelIo);
126 }
127
128 return STATUS_PENDING;
129 }
131 {
132 DPRINT1("SRB_FUNCTION_RELEASE_DEVICE\n");
133 ASSERT(PDODeviceExtension->Claimed == TRUE);
134
135 // release claim
136 PDODeviceExtension->Claimed = FALSE;
138 break;
139 }
141 {
142 DPRINT1("SRB_FUNCTION_CLAIM_DEVICE\n");
143
144 // check if the device has been claimed
145 if (PDODeviceExtension->Claimed)
146 {
147 // device has already been claimed
149 Request->SrbStatus = SRB_STATUS_BUSY;
150 break;
151 }
152
153 // claim device
154 PDODeviceExtension->Claimed = TRUE;
155
156 // output device object
157 Request->DataBuffer = DeviceObject;
158
160 break;
161 }
163 {
164 DPRINT1("SRB_FUNCTION_RELEASE_QUEUE\n");
165
166 USBSTOR_QueueRelease(PDODeviceExtension->LowerDeviceObject);
167
168 Request->SrbStatus = SRB_STATUS_SUCCESS;
170 break;
171 }
172
176 {
177 DPRINT1("SRB_FUNCTION_FLUSH / SRB_FUNCTION_FLUSH_QUEUE / SRB_FUNCTION_SHUTDOWN\n");
178
179 // wait for pending requests to finish
180 USBSTOR_QueueWaitForPendingRequests(PDODeviceExtension->LowerDeviceObject);
181
182 Request->SrbStatus = SRB_STATUS_SUCCESS;
184 break;
185 }
186 default:
187 {
188 //
189 // not supported
190 //
192 Request->SrbStatus = SRB_STATUS_ERROR;
193 }
194 }
195
196 Irp->IoStatus.Status = Status;
198 return Status;
199}
#define SCSIOP_MODE_SENSE
Definition: cdrw_hw.h:896
#define SRB_FUNCTION_RELEASE_DEVICE
Definition: srb.h:321
#define SRB_FUNCTION_CLAIM_DEVICE
Definition: srb.h:316
#define SRB_FUNCTION_RELEASE_QUEUE
Definition: srb.h:319
#define SRB_FUNCTION_EXECUTE_SCSI
Definition: srb.h:315
#define SRB_STATUS_PENDING
Definition: srb.h:340
#define SRB_FUNCTION_FLUSH
Definition: srb.h:323
#define SRB_FUNCTION_FLUSH_QUEUE
Definition: srb.h:329
#define SRB_FUNCTION_SHUTDOWN
Definition: srb.h:322
struct _SCSI_REQUEST_BLOCK * PSCSI_REQUEST_BLOCK
#define SRB_STATUS_ERROR
Definition: srb.h:344
#define SRB_STATUS_BUSY
Definition: srb.h:345
#define SRB_STATUS_SUCCESS
Definition: srb.h:341
static BOOLEAN IsRequestValid(PIRP Irp)
Definition: disk.c:22
BOOLEAN USBSTOR_QueueAddIrp(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: queue.c:75
VOID USBSTOR_QueueRelease(IN PDEVICE_OBJECT DeviceObject)
Definition: queue.c:262
VOID USBSTOR_QueueWaitForPendingRequests(IN PDEVICE_OBJECT DeviceObject)
Definition: queue.c:171
VOID NTAPI USBSTOR_CancelIo(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: queue.c:28
IoMarkIrpPending(Irp)
VOID NTAPI IoStartPacket(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PULONG Key, IN PDRIVER_CANCEL CancelFunction)
Definition: device.c:1876
#define IoCompleteRequest
Definition: irp.c:1240
struct _IO_STACK_LOCATION::@4278::@4317 Others
#define STATUS_PENDING
Definition: telnetd.h:14
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_DEVICE_BUSY
Definition: udferr_usr.h:129
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
#define IO_NO_INCREMENT
Definition: iotypes.h:598

Referenced by USBSTOR_DispatchScsi().

◆ USBSTOR_HandleQueryProperty()

NTSTATUS USBSTOR_HandleQueryProperty ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 224 of file disk.c.

227{
228 PIO_STACK_LOCATION IoStack;
229 PSTORAGE_PROPERTY_QUERY PropertyQuery;
230 PSTORAGE_DESCRIPTOR_HEADER DescriptorHeader;
231 PSTORAGE_ADAPTER_DESCRIPTOR_WIN8 AdapterDescriptor;
232 ULONG FieldLengthVendor, FieldLengthProduct, FieldLengthRevision, TotalLength, FieldLengthSerialNumber;
233 PPDO_DEVICE_EXTENSION PDODeviceExtension;
234 PINQUIRYDATA InquiryData;
237 PFDO_DEVICE_EXTENSION FDODeviceExtension;
241
242 DPRINT("USBSTOR_HandleQueryProperty\n");
243
245 ASSERT(IoStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(STORAGE_PROPERTY_QUERY));
246 ASSERT(Irp->AssociatedIrp.SystemBuffer);
247
248 PropertyQuery = (PSTORAGE_PROPERTY_QUERY)Irp->AssociatedIrp.SystemBuffer;
249
250 // check property type
251 if (PropertyQuery->PropertyId != StorageDeviceProperty &&
252 PropertyQuery->PropertyId != StorageAdapterProperty)
253 {
254 // only device property / adapter property are supported
256 }
257
258 // check query type
259 if (PropertyQuery->QueryType == PropertyExistsQuery)
260 {
261 // device property / adapter property is supported
262 return STATUS_SUCCESS;
263 }
264
265 if (PropertyQuery->QueryType != PropertyStandardQuery)
266 {
267 // only standard query and exists query are supported
269 }
270
271 // check if it is a device property
272 if (PropertyQuery->PropertyId == StorageDeviceProperty)
273 {
274 DPRINT("USBSTOR_HandleQueryProperty StorageDeviceProperty OutputBufferLength %lu\n", IoStack->Parameters.DeviceIoControl.OutputBufferLength);
275
276 PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
277 ASSERT(PDODeviceExtension);
278 ASSERT(PDODeviceExtension->Common.IsFDO == FALSE);
279
280 FDODeviceExtension = (PFDO_DEVICE_EXTENSION)PDODeviceExtension->LowerDeviceObject->DeviceExtension;
281 ASSERT(FDODeviceExtension);
282 ASSERT(FDODeviceExtension->Common.IsFDO);
283
284 InquiryData = (PINQUIRYDATA)&PDODeviceExtension->InquiryData;
285
286 // compute extra parameters length
287 FieldLengthVendor = USBSTOR_GetFieldLength(InquiryData->VendorId, 8);
288 FieldLengthProduct = USBSTOR_GetFieldLength(InquiryData->ProductId, 16);
289 FieldLengthRevision = USBSTOR_GetFieldLength(InquiryData->ProductRevisionLevel, 4);
290
291 if (FDODeviceExtension->SerialNumber)
292 {
293 FieldLengthSerialNumber = wcslen(FDODeviceExtension->SerialNumber->bString);
294 }
295 else
296 {
297 FieldLengthSerialNumber = 0;
298 }
299
300 // total length required is sizeof(STORAGE_DEVICE_DESCRIPTOR) + FieldLength + 4 extra null bytes - 1
301 // -1 due STORAGE_DEVICE_DESCRIPTOR contains one byte length of parameter data
302 TotalLength = sizeof(STORAGE_DEVICE_DESCRIPTOR) + FieldLengthVendor + FieldLengthProduct + FieldLengthRevision + FieldLengthSerialNumber + 3;
303
304 // check if output buffer is long enough
305 if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < TotalLength)
306 {
307 // buffer too small
308 DescriptorHeader = (PSTORAGE_DESCRIPTOR_HEADER)Irp->AssociatedIrp.SystemBuffer;
309 ASSERT(IoStack->Parameters.DeviceIoControl.OutputBufferLength >= sizeof(STORAGE_DESCRIPTOR_HEADER));
310
311 // return required size
312 DescriptorHeader->Version = TotalLength;
313 DescriptorHeader->Size = TotalLength;
314
315 Irp->IoStatus.Information = sizeof(STORAGE_DESCRIPTOR_HEADER);
316 return STATUS_SUCCESS;
317 }
318
319 // initialize the device descriptor
320 DeviceDescriptor = (PSTORAGE_DEVICE_DESCRIPTOR)Irp->AssociatedIrp.SystemBuffer;
321
324 DeviceDescriptor->DeviceType = InquiryData->DeviceType;
325 DeviceDescriptor->DeviceTypeModifier = InquiryData->DeviceTypeModifier;
326 DeviceDescriptor->RemovableMedia = InquiryData->RemovableMedia;
327 DeviceDescriptor->CommandQueueing = FALSE;
328 DeviceDescriptor->BusType = BusTypeUsb;
329 DeviceDescriptor->VendorIdOffset = sizeof(STORAGE_DEVICE_DESCRIPTOR) - sizeof(UCHAR);
330 DeviceDescriptor->ProductIdOffset = DeviceDescriptor->VendorIdOffset + FieldLengthVendor + 1;
331 DeviceDescriptor->ProductRevisionOffset = DeviceDescriptor->ProductIdOffset + FieldLengthProduct + 1;
332 DeviceDescriptor->SerialNumberOffset = (FieldLengthSerialNumber > 0 ? DeviceDescriptor->ProductRevisionOffset + FieldLengthRevision + 1 : 0);
333 DeviceDescriptor->RawPropertiesLength = FieldLengthVendor + FieldLengthProduct + FieldLengthRevision + FieldLengthSerialNumber + 3 + (FieldLengthSerialNumber > 0 ? + 1 : 0);
334
335 // copy descriptors
337
338 RtlCopyMemory(Buffer, InquiryData->VendorId, FieldLengthVendor);
339 Buffer[FieldLengthVendor] = '\0';
340 Buffer += FieldLengthVendor + 1;
341
342 RtlCopyMemory(Buffer, InquiryData->ProductId, FieldLengthProduct);
343 Buffer[FieldLengthProduct] = '\0';
344 Buffer += FieldLengthProduct + 1;
345
346 RtlCopyMemory(Buffer, InquiryData->ProductRevisionLevel, FieldLengthRevision);
347 Buffer[FieldLengthRevision] = '\0';
348 Buffer += FieldLengthRevision + 1;
349
350 if (FieldLengthSerialNumber)
351 {
352 RtlInitUnicodeString(&SerialNumber, FDODeviceExtension->SerialNumber->bString);
353
354 AnsiString.Buffer = (PCHAR)Buffer;
355 AnsiString.Length = 0;
356 AnsiString.MaximumLength = FieldLengthSerialNumber * sizeof(WCHAR);
357
360 }
361
362 DPRINT("Vendor %s\n", (LPCSTR)((ULONG_PTR)DeviceDescriptor + DeviceDescriptor->VendorIdOffset));
363 DPRINT("Product %s\n", (LPCSTR)((ULONG_PTR)DeviceDescriptor + DeviceDescriptor->ProductIdOffset));
364 DPRINT("Revision %s\n", (LPCSTR)((ULONG_PTR)DeviceDescriptor + DeviceDescriptor->ProductRevisionOffset));
365 DPRINT("Serial %s\n", (LPCSTR)((ULONG_PTR)DeviceDescriptor + DeviceDescriptor->SerialNumberOffset));
366
367 Irp->IoStatus.Information = TotalLength;
368 return STATUS_SUCCESS;
369 }
370 else
371 {
372 // adapter property query request
373
374 DPRINT("USBSTOR_HandleQueryProperty StorageAdapterProperty OutputBufferLength %lu\n", IoStack->Parameters.DeviceIoControl.OutputBufferLength);
375
376 if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(STORAGE_ADAPTER_DESCRIPTOR_WIN8))
377 {
378 // buffer too small
379 DescriptorHeader = (PSTORAGE_DESCRIPTOR_HEADER)Irp->AssociatedIrp.SystemBuffer;
380 ASSERT(IoStack->Parameters.DeviceIoControl.OutputBufferLength >= sizeof(STORAGE_DESCRIPTOR_HEADER));
381
382 // return required size
383 DescriptorHeader->Version = sizeof(STORAGE_ADAPTER_DESCRIPTOR_WIN8);
384 DescriptorHeader->Size = sizeof(STORAGE_ADAPTER_DESCRIPTOR_WIN8);
385
386 Irp->IoStatus.Information = sizeof(STORAGE_DESCRIPTOR_HEADER);
387 return STATUS_SUCCESS;
388 }
389
390 // get adapter descriptor, information is returned in the same buffer
391 AdapterDescriptor = Irp->AssociatedIrp.SystemBuffer;
392
393 // fill out descriptor
394 // NOTE: STORAGE_ADAPTER_DESCRIPTOR_WIN8 may vary in size, so it's important to zero out
395 // all unused fields
396 *AdapterDescriptor = (STORAGE_ADAPTER_DESCRIPTOR_WIN8) {
399 .MaximumTransferLength = USBSTOR_DEFAULT_MAX_TRANSFER_LENGTH,
400 .MaximumPhysicalPages = USBSTOR_DEFAULT_MAX_PHYS_PAGES,
401 .BusType = BusTypeUsb,
402 .BusMajorVersion = 2, //FIXME verify
403 .BusMinorVersion = 0 //FIXME
404 };
405
406 // __debugbreak();
407
408 // store returned length
409 Irp->IoStatus.Information = sizeof(STORAGE_ADAPTER_DESCRIPTOR_WIN8);
410
411 return STATUS_SUCCESS;
412 }
413}
Definition: bufpool.h:45
@ AnsiString
Definition: dnslib.h:19
struct _FDO_DEVICE_EXTENSION * PFDO_DEVICE_EXTENSION
ULONG USBSTOR_GetFieldLength(IN PUCHAR Name, IN ULONG MaxLength)
Definition: disk.c:202
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
if(dx< 0)
Definition: linetemp.h:194
#define PCHAR
Definition: match.c:90
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToAnsiString(PANSI_STRING DestinationString, PUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:570
#define STATUS_INVALID_PARAMETER_1
Definition: ntstatus.h:569
@ BusTypeUsb
Definition: ntddstor.h:445
@ StorageAdapterProperty
Definition: ntddstor.h:513
@ StorageDeviceProperty
Definition: ntddstor.h:512
struct _STORAGE_PROPERTY_QUERY * PSTORAGE_PROPERTY_QUERY
@ PropertyExistsQuery
Definition: ntddstor.h:506
@ PropertyStandardQuery
Definition: ntddstor.h:505
ULONG SerialNumber
Definition: rxce.c:117
struct _STORAGE_ADAPTER_DESCRIPTOR_WIN8 STORAGE_ADAPTER_DESCRIPTOR_WIN8
const KSDEVICE_DESCRIPTOR DeviceDescriptor
Definition: splitter.c:257
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:84
UCHAR RemovableMedia
Definition: cdrw_hw.h:1119
UCHAR ProductId[16]
Definition: cdrw_hw.h:1133
UCHAR ProductRevisionLevel[4]
Definition: cdrw_hw.h:1134
UCHAR DeviceTypeModifier
Definition: cdrw_hw.h:1118
UCHAR VendorId[8]
Definition: cdrw_hw.h:1132
UCHAR DeviceType
Definition: cdrw_hw.h:1116
STORAGE_QUERY_TYPE QueryType
Definition: ntddstor.h:553
STORAGE_PROPERTY_ID PropertyId
Definition: ntddstor.h:552
uint32_t ULONG_PTR
Definition: typedefs.h:65
unsigned char * PUCHAR
Definition: typedefs.h:53
_In_ ULONG TotalLength
Definition: usbdlib.h:158
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539
struct _STORAGE_DESCRIPTOR_HEADER STORAGE_DESCRIPTOR_HEADER
struct _STORAGE_DEVICE_DESCRIPTOR STORAGE_DEVICE_DESCRIPTOR
struct _STORAGE_DESCRIPTOR_HEADER * PSTORAGE_DESCRIPTOR_HEADER
struct _STORAGE_DEVICE_DESCRIPTOR * PSTORAGE_DEVICE_DESCRIPTOR
const char * LPCSTR
Definition: xmlstorage.h:183
unsigned char UCHAR
Definition: xmlstorage.h:181
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by USBSTOR_HandleDeviceControl().