ReactOS  0.4.15-dev-1377-ga59cecd
ioctl.c File Reference
#include "scsiport.h"
#include <debug.h>
Include dependency graph for ioctl.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

static NTSTATUS SpiGetInquiryData (_In_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, _In_ PIRP Irp)
 
NTSTATUS NTAPI ScsiPortDeviceControl (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file ioctl.c.

Function Documentation

◆ ScsiPortDeviceControl()

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

Definition at line 150 of file ioctl.c.

153 {
155  PSCSI_PORT_DEVICE_EXTENSION DeviceExtension;
156  PDUMP_POINTERS DumpPointers;
158 
159  DPRINT("ScsiPortDeviceControl()\n");
160 
161  Irp->IoStatus.Information = 0;
162 
164  DeviceExtension = DeviceObject->DeviceExtension;
165 
166  switch (Stack->Parameters.DeviceIoControl.IoControlCode)
167  {
169  DPRINT(" IOCTL_SCSI_GET_DUMP_POINTERS\n");
170 
171  if (Stack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(DUMP_POINTERS))
172  {
174  Irp->IoStatus.Information = sizeof(DUMP_POINTERS);
175  break;
176  }
177 
178  DumpPointers = Irp->AssociatedIrp.SystemBuffer;
179  DumpPointers->DeviceObject = DeviceObject;
180  /* More data.. ? */
181 
183  Irp->IoStatus.Information = sizeof(DUMP_POINTERS);
184  break;
185 
187  DPRINT(" IOCTL_SCSI_GET_CAPABILITIES\n");
188  if (Stack->Parameters.DeviceIoControl.OutputBufferLength == sizeof(PVOID))
189  {
190  *((PVOID *)Irp->AssociatedIrp.SystemBuffer) = &DeviceExtension->PortCapabilities;
191 
192  Irp->IoStatus.Information = sizeof(PVOID);
194  break;
195  }
196 
197  if (Stack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(IO_SCSI_CAPABILITIES))
198  {
200  break;
201  }
202 
203  RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer,
204  &DeviceExtension->PortCapabilities,
205  sizeof(IO_SCSI_CAPABILITIES));
206 
207  Irp->IoStatus.Information = sizeof(IO_SCSI_CAPABILITIES);
209  break;
210 
212  DPRINT(" IOCTL_SCSI_GET_INQUIRY_DATA\n");
213 
214  /* Copy inquiry data to the port device extension */
215  Status = SpiGetInquiryData(DeviceExtension, Irp);
216  break;
217 
218  case IOCTL_SCSI_MINIPORT:
219  DPRINT1("IOCTL_SCSI_MINIPORT unimplemented!\n");
221  break;
222 
224  DPRINT1("IOCTL_SCSI_PASS_THROUGH unimplemented!\n");
226  break;
227 
228  default:
229  if (DEVICE_TYPE_FROM_CTL_CODE(Stack->Parameters.DeviceIoControl.IoControlCode) == MOUNTDEVCONTROLTYPE)
230  {
231  switch (Stack->Parameters.DeviceIoControl.IoControlCode)
232  {
234  DPRINT1("Got unexpected IOCTL_MOUNTDEV_QUERY_DEVICE_NAME\n");
235  break;
237  DPRINT1("Got unexpected IOCTL_MOUNTDEV_QUERY_UNIQUE_ID\n");
238  break;
239  default:
240  DPRINT(" got ioctl intended for the mount manager: 0x%lX\n", Stack->Parameters.DeviceIoControl.IoControlCode);
241  break;
242  }
243  } else {
244  DPRINT1(" unknown ioctl code: 0x%lX\n", Stack->Parameters.DeviceIoControl.IoControlCode);
245  }
247  break;
248  }
249 
250  /* Complete the request with the given status */
251  Irp->IoStatus.Status = Status;
253 
254  return Status;
255 }
#define IOCTL_SCSI_MINIPORT
Definition: scsi_port.h:48
IO_SCSI_CAPABILITIES PortCapabilities
Definition: scsiport.c:79
#define IOCTL_SCSI_GET_DUMP_POINTERS
Definition: scsi_port.h:54
LONG NTSTATUS
Definition: precomp.h:26
struct _DUMP_POINTERS DUMP_POINTERS
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:636
#define IOCTL_MOUNTDEV_QUERY_DEVICE_NAME
Definition: imports.h:93
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
return STATUS_NOT_IMPLEMENTED
#define IOCTL_MOUNTDEV_QUERY_UNIQUE_ID
Definition: imports.h:80
_In_ PIRP Irp
Definition: csq.h:116
static NTSTATUS SpiGetInquiryData(_In_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, _In_ PIRP Irp)
Definition: ioctl.c:17
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
void * PVOID
Definition: retypes.h:9
Status
Definition: gdiplustypes.h:24
#define MOUNTDEVCONTROLTYPE
Definition: imports.h:78
#define IOCTL_SCSI_PASS_THROUGH
Definition: scsi_port.h:47
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
#define IOCTL_SCSI_GET_INQUIRY_DATA
Definition: scsi_port.h:49
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
#define DEVICE_TYPE_FROM_CTL_CODE(c)
Definition: winioctl.h:176
#define DPRINT1
Definition: precomp.h:8
#define IOCTL_SCSI_GET_CAPABILITIES
Definition: scsi_port.h:50
#define IO_NO_INCREMENT
Definition: iotypes.h:581
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _IO_SCSI_CAPABILITIES IO_SCSI_CAPABILITIES
PVOID DeviceObject
Definition: ntddscsi.h:321

Referenced by ScsiPortInitialize().

◆ SpiGetInquiryData()

static NTSTATUS SpiGetInquiryData ( _In_ PSCSI_PORT_DEVICE_EXTENSION  DeviceExtension,
_In_ PIRP  Irp 
)
static

Definition at line 17 of file ioctl.c.

20 {
21  ULONG InquiryDataSize;
22  PSCSI_LUN_INFO LunInfo;
23  ULONG BusCount, LunCount, Length;
24  PIO_STACK_LOCATION IrpStack;
25  PSCSI_ADAPTER_BUS_INFO AdapterBusInfo;
26  PSCSI_INQUIRY_DATA InquiryData;
27  PSCSI_BUS_DATA BusData;
28  ULONG Bus;
29  PUCHAR Buffer;
30 
31  DPRINT("SpiGetInquiryData() called\n");
32 
33  /* Get pointer to the buffer */
35  Buffer = Irp->AssociatedIrp.SystemBuffer;
36 
37  /* Initialize bus and LUN counters */
38  BusCount = DeviceExtension->BusesConfig->NumberOfBuses;
39  LunCount = 0;
40 
41  /* Calculate total number of LUNs */
42  for (Bus = 0; Bus < BusCount; Bus++)
43  LunCount += DeviceExtension->BusesConfig->BusScanInfo[Bus]->LogicalUnitsCount;
44 
45  /* Calculate size of inquiry data, rounding up to sizeof(ULONG) */
46  InquiryDataSize =
48  sizeof(ULONG) - 1) & ~(sizeof(ULONG) - 1));
49 
50  /* Calculate data size */
51  Length = sizeof(SCSI_ADAPTER_BUS_INFO) + (BusCount - 1) * sizeof(SCSI_BUS_DATA);
52 
53  Length += InquiryDataSize * LunCount;
54 
55  /* Check, if all data is going to fit into provided buffer */
56  if (IrpStack->Parameters.DeviceIoControl.OutputBufferLength < Length)
57  {
58  Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
60  }
61 
62  /* Store data size in the IRP */
63  Irp->IoStatus.Information = Length;
64 
65  DPRINT("Data size: %lu\n", Length);
66 
67  AdapterBusInfo = (PSCSI_ADAPTER_BUS_INFO)Buffer;
68 
69  AdapterBusInfo->NumberOfBuses = (UCHAR)BusCount;
70 
71  /* Point InquiryData to the corresponding place inside Buffer */
72  InquiryData = (PSCSI_INQUIRY_DATA)(Buffer + sizeof(SCSI_ADAPTER_BUS_INFO) +
73  (BusCount - 1) * sizeof(SCSI_BUS_DATA));
74 
75  /* Loop each bus */
76  for (Bus = 0; Bus < BusCount; Bus++)
77  {
78  BusData = &AdapterBusInfo->BusData[Bus];
79 
80  /* Calculate and save an offset of the inquiry data */
81  BusData->InquiryDataOffset = (ULONG)((PUCHAR)InquiryData - Buffer);
82 
83  /* Get a pointer to the LUN information structure */
84  LunInfo = DeviceExtension->BusesConfig->BusScanInfo[Bus]->LunInfo;
85 
86  /* Store Initiator Bus Id */
87  BusData->InitiatorBusId =
88  DeviceExtension->BusesConfig->BusScanInfo[Bus]->BusIdentifier;
89 
90  /* Store LUN count */
91  BusData->NumberOfLogicalUnits =
92  DeviceExtension->BusesConfig->BusScanInfo[Bus]->LogicalUnitsCount;
93 
94  /* Loop all LUNs */
95  while (LunInfo != NULL)
96  {
97  DPRINT("(Bus %lu Target %lu Lun %lu)\n",
98  Bus, LunInfo->TargetId, LunInfo->Lun);
99 
100  /* Fill InquiryData with values */
101  InquiryData->PathId = LunInfo->PathId;
102  InquiryData->TargetId = LunInfo->TargetId;
103  InquiryData->Lun = LunInfo->Lun;
105  InquiryData->DeviceClaimed = LunInfo->DeviceClaimed;
106  InquiryData->NextInquiryDataOffset =
107  (ULONG)((PUCHAR)InquiryData + InquiryDataSize - Buffer);
108 
109  /* Copy data in it */
110  RtlCopyMemory(InquiryData->InquiryData,
111  LunInfo->InquiryData,
113 
114  /* Move to the next LUN */
115  LunInfo = LunInfo->Next;
116  InquiryData = (PSCSI_INQUIRY_DATA) ((PCHAR)InquiryData + InquiryDataSize);
117  }
118 
119  /* Either mark the end, or set offset to 0 */
120  if (BusData->NumberOfLogicalUnits != 0)
121  ((PSCSI_INQUIRY_DATA) ((PCHAR)InquiryData - InquiryDataSize))->NextInquiryDataOffset = 0;
122  else
123  BusData->InquiryDataOffset = 0;
124  }
125 
126  /* Finish with success */
127  Irp->IoStatus.Status = STATUS_SUCCESS;
128  return STATUS_SUCCESS;
129 }
signed char * PCHAR
Definition: retypes.h:7
struct _SCSI_ADAPTER_BUS_INFO SCSI_ADAPTER_BUS_INFO
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
unsigned char * PUCHAR
Definition: retypes.h:3
ULONG NextInquiryDataOffset
Definition: scsi_port.h:118
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
SCSI_BUS_DATA BusData[1]
Definition: scsi_port.h:106
_In_ PIRP Irp
Definition: csq.h:116
struct _SCSI_INQUIRY_DATA * PSCSI_INQUIRY_DATA
#define INQUIRYDATABUFFERSIZE
Definition: cdrw_hw.h:1113
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
ULONG InquiryDataOffset
Definition: scsi_port.h:98
UCHAR InquiryData[INQUIRYDATABUFFERSIZE]
Definition: scsiport.h:164
BOOLEAN DeviceClaimed
Definition: scsiport.h:161
UCHAR PathId
Definition: scsiport.h:158
unsigned char UCHAR
Definition: xmlstorage.h:181
UCHAR InquiryData[1]
Definition: scsi_port.h:119
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
UCHAR TargetId
Definition: scsiport.h:159
struct _SCSI_BUS_DATA SCSI_BUS_DATA
ULONG InquiryDataLength
Definition: scsi_port.h:117
UCHAR InitiatorBusId
Definition: scsi_port.h:97
#define NULL
Definition: types.h:112
struct _SCSI_LUN_INFO * Next
Definition: scsiport.h:163
BOOLEAN DeviceClaimed
Definition: scsi_port.h:116
unsigned int ULONG
Definition: retypes.h:1
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _SCSI_ADAPTER_BUS_INFO * PSCSI_ADAPTER_BUS_INFO
UCHAR NumberOfLogicalUnits
Definition: scsi_port.h:96
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3107

Referenced by ScsiPortDeviceControl().