ReactOS 0.4.17-dev-1268-g5608ce5
ioctl.c File Reference
#include "precomp.h"
#include <debug.h>
Include dependency graph for ioctl.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static UINT32 GetFieldLength (_In_ PUCHAR Name, _In_ UINT32 MaxLength)
 
static NTSTATUS FdoDeviceControlQueryProperty (_In_ PFDO_DEVICE_EXTENSION FdoExtension, _In_ PIRP Irp)
 
NTSTATUS NTAPI PortFdoDeviceControl (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
 
static NTSTATUS PdoDeviceControlQueryProperty (_In_ PPDO_DEVICE_EXTENSION PdoExtension, _In_ PIRP Irp)
 
static NTSTATUS PdoDeviceControlScsiGetAddress (_In_ PPDO_DEVICE_EXTENSION DeviceExtension, _In_ PIRP Irp)
 
NTSTATUS NTAPI PortPdoDeviceControl (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file ioctl.c.

Function Documentation

◆ FdoDeviceControlQueryProperty()

static NTSTATUS FdoDeviceControlQueryProperty ( _In_ PFDO_DEVICE_EXTENSION  FdoExtension,
_In_ PIRP  Irp 
)
static

Definition at line 44 of file ioctl.c.

47{
48 PIO_STACK_LOCATION IoStack;
49 PMINIPORT Miniport;
50 PSTORAGE_ADAPTER_DESCRIPTOR AdapterDescriptor;
53
55 Query = (PSTORAGE_PROPERTY_QUERY)Irp->AssociatedIrp.SystemBuffer;
56 Miniport = &FdoExtension->Miniport;
57
58 do
59 {
60 /* check property type (handle only StorageAdapterProperty) */
61 if (Query->PropertyId != StorageAdapterProperty)
62 {
63 if (Query->PropertyId == StorageDeviceProperty ||
64 Query->PropertyId == StorageDeviceIdProperty)
65 {
67 }
68 else
69 {
71 }
72
73 break;
74 }
75
76 /* check query type */
77 if (Query->QueryType == PropertyExistsQuery)
78 {
79 /* device property / adapter property is supported */
81 break;
82 }
83
84 if (Query->QueryType != PropertyStandardQuery)
85 {
86 /* only standard query and exists query are supported */
88 break;
89 }
90
91 /* Check buffer length */
92 if (IoStack->Parameters.DeviceIoControl.OutputBufferLength <
93 sizeof(*AdapterDescriptor))
94 {
95 PSTORAGE_DESCRIPTOR_HEADER DescriptorHeader = Irp->AssociatedIrp.SystemBuffer;
96
97 /* Fail request if the buffer is simply too small */
98 if (IoStack->Parameters.DeviceIoControl.OutputBufferLength <
100 {
101 Status = STATUS_BUFFER_TOO_SMALL; /* FIXME: Is this code appropriate? */
102 break;
103 }
104
105 /* Return required size */
106 DescriptorHeader->Version = sizeof(*AdapterDescriptor);
107 DescriptorHeader->Size = sizeof(*AdapterDescriptor);
108 Irp->IoStatus.Information = sizeof(STORAGE_DESCRIPTOR_HEADER);
110 break;
111 }
112
113 /* Return AdapterDescriptor */
114 AdapterDescriptor = Irp->AssociatedIrp.SystemBuffer;
115 RtlZeroMemory(AdapterDescriptor, sizeof(*AdapterDescriptor));
116
117 AdapterDescriptor->Version = sizeof(*AdapterDescriptor);
118 AdapterDescriptor->Size = sizeof(*AdapterDescriptor);
119 AdapterDescriptor->MaximumTransferLength = Miniport->PortConfig.MaximumTransferLength;
120 AdapterDescriptor->MaximumPhysicalPages = Miniport->PortConfig.NumberOfPhysicalBreaks;
121 AdapterDescriptor->AlignmentMask = Miniport->PortConfig.AlignmentMask;
122 AdapterDescriptor->AdapterUsesPio = FALSE; /* Storport requirement */
123 AdapterDescriptor->AdapterScansDown = Miniport->PortConfig.AdapterScansDown;
124 AdapterDescriptor->CommandQueueing = TRUE; /* Storport requirement */
125 AdapterDescriptor->AcceleratedTransfer = TRUE;
126 AdapterDescriptor->BusType = BusTypeSata; /* FIXME: READ FROM REGISTRY */
127 AdapterDescriptor->BusMajorVersion = 2;
128 AdapterDescriptor->BusMinorVersion = 0;
129 /* TODO: Report PortConfig SrbType and AddressType once PortPdoScsi accepts extended SRBs */
130 AdapterDescriptor->SrbType = SRB_TYPE_SCSI_REQUEST_BLOCK;
131 AdapterDescriptor->AddressType = STORAGE_ADDRESS_TYPE_BTL8;
132
133 Irp->IoStatus.Information = sizeof(*AdapterDescriptor);
135 }
136 while (0);
137
138 Irp->IoStatus.Status = Status;
140
141 return Status;
142}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
LONG NTSTATUS
Definition: precomp.h:26
BOOL Query(LPCTSTR *ServiceArgs, DWORD ArgCount, BOOL bExtended)
Definition: query.c:292
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
@ FdoExtension
Definition: precomp.h:61
Status
Definition: gdiplustypes.h:24
_In_ PIRP Irp
Definition: kse.h:79
if(dx< 0)
Definition: linetemp.h:194
#define IoCompleteRequest
Definition: irp.c:1272
#define STATUS_INVALID_PARAMETER_2
Definition: ntstatus.h:570
#define STATUS_INVALID_PARAMETER_1
Definition: ntstatus.h:569
@ BusTypeSata
Definition: ntddstor.h:449
@ StorageDeviceIdProperty
Definition: ntddstor.h:514
@ 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
#define STORAGE_ADDRESS_TYPE_BTL8
Definition: srb.h:666
#define SRB_TYPE_SCSI_REQUEST_BLOCK
Definition: srb.h:663
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
union _IO_STACK_LOCATION::@1814 Parameters
struct _IO_STACK_LOCATION::@1814::@1815 DeviceIoControl
PORT_CONFIGURATION_INFORMATION PortConfig
Definition: precomp.h:99
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
struct _STORAGE_DESCRIPTOR_HEADER STORAGE_DESCRIPTOR_HEADER
#define IO_NO_INCREMENT
Definition: iotypes.h:598

Referenced by PortFdoDeviceControl().

◆ GetFieldLength()

static UINT32 GetFieldLength ( _In_ PUCHAR  Name,
_In_ UINT32  MaxLength 
)
static

Definition at line 20 of file ioctl.c.

23{
25 UINT32 LastCharacterPosition = 0;
26
27 // scan the field and return last position which contains a valid character
28 for (Index = 0; Index < MaxLength; Index++)
29 {
30 if (Name[Index] != ' ')
31 {
32 // trim white spaces from field
33 LastCharacterPosition = Index;
34 }
35 }
36
37 // convert from zero based index to length
38 return LastCharacterPosition + 1;
39}
LPWSTR Name
Definition: desk.c:124
uint32_t UINT32
Definition: typedefs.h:59
_In_ WDFCOLLECTION _In_ ULONG Index

◆ PdoDeviceControlQueryProperty()

static NTSTATUS PdoDeviceControlQueryProperty ( _In_ PPDO_DEVICE_EXTENSION  PdoExtension,
_In_ PIRP  Irp 
)
static

Definition at line 177 of file ioctl.c.

180{
181 PIO_STACK_LOCATION IoStack;
184
186 Query = (PSTORAGE_PROPERTY_QUERY)Irp->AssociatedIrp.SystemBuffer;
187
188 do
189 {
190 /* check property type */
191 if (Query->PropertyId != StorageDeviceProperty &&
192 Query->PropertyId != StorageAdapterProperty)
193 {
194 // only device property / adapter property are supported
196 }
197
198 /* check query type */
199 if (Query->QueryType == PropertyExistsQuery)
200 {
201 /* device property / adapter property is supported */
203 break;
204 }
205
206 if (Query->QueryType != PropertyStandardQuery)
207 {
208 /* only standard query and exists query are supported */
210 break;
211 }
212
213
214
215 /* For different property types... */
216 switch (Query->PropertyId)
217 {
219 {
221 PINQUIRYDATA InquiryData = PdoExtension->InquiryBuffer;
222 ULONG VendorIdLength = GetFieldLength(InquiryData->VendorId, 8);
223 ULONG ProductIdLength = GetFieldLength(InquiryData->ProductId, 16);
224 ULONG RevisionLength = GetFieldLength(InquiryData->ProductRevisionLevel, 4);
226 PUCHAR Dest;
227
228 /*
229 * total length required is
230 * sizeof(STORAGE_DEVICE_DESCRIPTOR) + (String + NullByte) + (...) + ... - 1
231 * STORAGE_DEVICE_DESCRIPTOR contains 1 byte at the end already
232 */
234 VendorIdLength + 1 +
235 ProductIdLength + 1 +
236 RevisionLength + /* Null byte omitted */
237 1; /* Null byte for serial number */
238
239 /* Check buffer length */
240 if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < TotalLength)
241 {
242 PSTORAGE_DESCRIPTOR_HEADER DescriptorHeader = Irp->AssociatedIrp.SystemBuffer;
243
244 /* Fail request if the buffer is simply too small */
245 if (IoStack->Parameters.DeviceIoControl.OutputBufferLength <
247 {
248 Status = STATUS_BUFFER_TOO_SMALL; /* FIXME: Is this code appropriate? */
249 break;
250 }
251
252 /* Return required size */
253 DescriptorHeader->Version = TotalLength;
254 DescriptorHeader->Size = TotalLength;
255 Irp->IoStatus.Information = sizeof(STORAGE_DESCRIPTOR_HEADER);
257 break;
258 }
259
260 /* Fill in data */
261 DeviceDescriptor = Irp->AssociatedIrp.SystemBuffer;
263 .Version = sizeof(STORAGE_DEVICE_DESCRIPTOR),
264 .Size = TotalLength,
265 .DeviceType = InquiryData->DeviceType,
266 .DeviceTypeModifier = InquiryData->DeviceTypeModifier,
267 .RemovableMedia = InquiryData->RemovableMedia,
268 .CommandQueueing = InquiryData->CommandQueue,
269 .BusType = BusTypeSata, /* FIXME: USE FDO BUS TYPE FROM REGISTRY */
270 };
271
272 /* Arbitrary data offsets, set them cascading */
273 DeviceDescriptor->VendorIdOffset =
274 FIELD_OFFSET(STORAGE_DEVICE_DESCRIPTOR, RawDeviceProperties);
275 DeviceDescriptor->ProductIdOffset = DeviceDescriptor->VendorIdOffset +
276 VendorIdLength + 1;
277 DeviceDescriptor->ProductRevisionOffset = DeviceDescriptor->ProductIdOffset +
278 ProductIdLength + 1;
279 DeviceDescriptor->SerialNumberOffset = DeviceDescriptor->ProductRevisionOffset +
280 RevisionLength + 1;
281
282 /* Fill the arbitrary data */
283 Dest = DeviceDescriptor->RawDeviceProperties;
284
285 RtlCopyMemory(Dest, InquiryData->VendorId, VendorIdLength);
286 Dest[VendorIdLength] = '\0';
287 Dest += VendorIdLength + 1;
288
289 RtlCopyMemory(Dest, InquiryData->ProductId, ProductIdLength);
290 Dest[ProductIdLength] = '\0';
291 Dest += ProductIdLength + 1;
292
293 RtlCopyMemory(Dest, InquiryData->ProductRevisionLevel, RevisionLength);
294 Dest[RevisionLength] = '\0';
295 Dest += RevisionLength + 1;
296
297 /* FIXME: Read serial number when enumerating devices */
298 *Dest = '\0';
299
300 /* TODO: Verify this doesnt overflow */
301 Irp->IoStatus.Information = TotalLength;
303 break;
304 }
306 {
308 return IoCallDriver(PdoExtension->FdoExtension->Device, Irp);
309 }
311 default:
312 {
314 break;
315 }
316 }
317 }
318 while (0);
319
320 Irp->IoStatus.Status = Status;
322
323 return Status;
324}
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
_Check_return_ _In_ ULONG _Inout_ PDXGK_DEVICE_DESCRIPTOR DeviceDescriptor
Definition: dispmprt.h:1263
static UINT32 GetFieldLength(_In_ PUCHAR Name, _In_ UINT32 MaxLength)
Definition: ioctl.c:125
@ PdoExtension
Definition: precomp.h:62
DeviceType
Definition: mmdrv.h:42
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IoCallDriver
Definition: irp.c:1257
@ StorageDevicePowerProperty
Definition: ntddstor.h:524
UCHAR CommandQueue
Definition: cdrw_hw.h:1125
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
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
_In_ ULONG TotalLength
Definition: usbdlib.h:185
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539
struct _STORAGE_DEVICE_DESCRIPTOR STORAGE_DEVICE_DESCRIPTOR

Referenced by PortPdoDeviceControl().

◆ PdoDeviceControlScsiGetAddress()

static NTSTATUS PdoDeviceControlScsiGetAddress ( _In_ PPDO_DEVICE_EXTENSION  DeviceExtension,
_In_ PIRP  Irp 
)
static

Definition at line 329 of file ioctl.c.

332{
334 PSCSI_ADDRESS ScsiAddress;
335 PIO_STACK_LOCATION IoStack;
336 PFDO_DEVICE_EXTENSION FdoDeviceExtension;
337
338 DPRINT("PdoDeviceControlScsiGetAddress(%p %p)\n", DeviceExtension, Irp);
339
341
342 NT_ASSERT(DeviceExtension->ExtensionType == PdoExtension);
343 FdoDeviceExtension = DeviceExtension->FdoExtension;
344
345 do
346 {
347 /* Check buffer length */
348 if (IoStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(SCSI_ADDRESS))
349 {
351 Irp->IoStatus.Information = 0;
352 break;
353 }
354
355 ScsiAddress = (PSCSI_ADDRESS)Irp->AssociatedIrp.SystemBuffer;
356 ScsiAddress->Length = sizeof(SCSI_ADDRESS);
357 ScsiAddress->PortNumber = FdoDeviceExtension->ScsiPortNumber;
358 ScsiAddress->PathId = DeviceExtension->Bus;
359 ScsiAddress->TargetId = DeviceExtension->Target;
360 ScsiAddress->Lun = DeviceExtension->Lun;
361
363 Irp->IoStatus.Information = sizeof(SCSI_ADDRESS);
364
365 DPRINT("SCSI Address for PDO %p : (Path Target Lun)(%d %d %d)\n",
366 DeviceExtension->Device, ScsiAddress->PathId, ScsiAddress->TargetId, ScsiAddress->Lun);
367 }
368 while (0);
369
370 Irp->IoStatus.Status = Status;
372
373 return Status;
374}
struct _SCSI_ADDRESS * PSCSI_ADDRESS
struct _SCSI_ADDRESS SCSI_ADDRESS
#define DPRINT
Definition: sndvol32.h:73
UCHAR PathId
Definition: scsi_port.h:149
UCHAR TargetId
Definition: scsi_port.h:150
ULONG Length
Definition: scsi_port.h:147
UCHAR PortNumber
Definition: scsi_port.h:148
#define NT_ASSERT
Definition: rtlfuncs.h:3334

Referenced by PortPdoDeviceControl().

◆ PortFdoDeviceControl()

NTSTATUS NTAPI PortFdoDeviceControl ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ PIRP  Irp 
)

Definition at line 147 of file ioctl.c.

150{
151 PIO_STACK_LOCATION IoStack;
153
155
156 switch (IoStack->Parameters.DeviceIoControl.IoControlCode)
157 {
159 return FdoDeviceControlQueryProperty(DeviceObject->DeviceExtension, Irp);
160
161 default:
162 // __debugbreak();
163 Status = Irp->IoStatus.Status;
164 break;
165 }
166
167 Irp->IoStatus.Status = Status;
168 Irp->IoStatus.Information = 0;
170
171 return Status;
172}
static NTSTATUS FdoDeviceControlQueryProperty(_In_ PFDO_DEVICE_EXTENSION FdoExtension, _In_ PIRP Irp)
Definition: ioctl.c:44
#define IOCTL_STORAGE_QUERY_PROPERTY
Definition: ntddstor.h:178
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2061

Referenced by PortDispatchDeviceControl().

◆ PortPdoDeviceControl()

NTSTATUS NTAPI PortPdoDeviceControl ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ PIRP  Irp 
)

Definition at line 379 of file ioctl.c.

382{
384 PIO_STACK_LOCATION IoStack;
385
387
388 switch (IoStack->Parameters.DeviceIoControl.IoControlCode)
389 {
391 return PdoDeviceControlQueryProperty(DeviceObject->DeviceExtension, Irp);
392
394 return PdoDeviceControlScsiGetAddress(DeviceObject->DeviceExtension, Irp);
395
396 default:
397 // DbgBreakPoint();
399 break;
400 }
401
402 Irp->IoStatus.Status = Status;
403 Irp->IoStatus.Information = 0;
405
406 return Status;
407}
static NTSTATUS PdoDeviceControlQueryProperty(_In_ PPDO_DEVICE_EXTENSION PdoExtension, _In_ PIRP Irp)
Definition: ioctl.c:177
static NTSTATUS PdoDeviceControlScsiGetAddress(_In_ PPDO_DEVICE_EXTENSION DeviceExtension, _In_ PIRP Irp)
Definition: ioctl.c:329
#define IOCTL_SCSI_GET_ADDRESS
Definition: scsi_port.h:52

Referenced by PortDispatchDeviceControl().