ReactOS 0.4.15-dev-7659-ga55345b
srblib.c File Reference
#include "classp.h"
Include dependency graph for srblib.c:

Go to the source code of this file.

Functions

PVOID DefaultStorageRequestBlockAllocateRoutine (_In_ CLONG ByteSize)
 
NTSTATUS pInitializeStorageRequestBlock (_Inout_bytecount_(ByteSize) PSTORAGE_REQUEST_BLOCK Srb, _In_ USHORT AddressType, _In_ ULONG ByteSize, _In_ ULONG NumSrbExData, _In_ va_list ap)
 
NTSTATUS InitializeStorageRequestBlock (_Inout_bytecount_(ByteSize) PSTORAGE_REQUEST_BLOCK Srb, _In_ USHORT AddressType, _In_ ULONG ByteSize, _In_ ULONG NumSrbExData,...)
 
NTSTATUS CreateStorageRequestBlock (_Inout_ PSTORAGE_REQUEST_BLOCK *Srb, _In_ USHORT AddressType, _In_opt_ PSRB_ALLOCATE_ROUTINE AllocateRoutine, _Inout_opt_ ULONG *ByteSize, _In_ ULONG NumSrbExData,...)
 

Function Documentation

◆ CreateStorageRequestBlock()

NTSTATUS CreateStorageRequestBlock ( _Inout_ PSTORAGE_REQUEST_BLOCK Srb,
_In_ USHORT  AddressType,
_In_opt_ PSRB_ALLOCATE_ROUTINE  AllocateRoutine,
_Inout_opt_ ULONG ByteSize,
_In_ ULONG  NumSrbExData,
  ... 
)

Definition at line 249 of file srblib.c.

283{
284 ULONG sizeNeeded = 0;
285 va_list ap;
286 ULONG i;
288
289 // Ensure SrbExData offsets are pointer type aligned
290 sizeNeeded = sizeof(STORAGE_REQUEST_BLOCK);
291 if (NumSrbExData > 0) {
292 sizeNeeded += ((NumSrbExData - 1) * sizeof(ULONG));
293 if (sizeNeeded % sizeof(PVOID)) {
294 sizeNeeded += (sizeof(PVOID) - (sizeNeeded % sizeof(PVOID)));
295 }
296 }
297
298 if (AddressType == STORAGE_ADDRESS_TYPE_BTL8)
299 {
300 sizeNeeded += sizeof(STOR_ADDR_BTL8);
301 } else
302 {
304 }
305
306 va_start(ap, NumSrbExData);
307
308 for (i = 0; i < NumSrbExData && status == STATUS_SUCCESS; i++)
309 {
310 switch (va_arg(ap, SRBEXDATATYPE))
311 {
313 sizeNeeded += sizeof(SRBEX_DATA_BIDIRECTIONAL);
314 break;
316 sizeNeeded += sizeof(SRBEX_DATA_SCSI_CDB16);
317 break;
319 sizeNeeded += sizeof(SRBEX_DATA_SCSI_CDB32);
320 break;
322 sizeNeeded += sizeof(SRBEX_DATA_SCSI_CDB_VAR) + va_arg(ap, ULONG);
323 break;
324 case SrbExDataTypeWmi:
325 sizeNeeded += sizeof(SRBEX_DATA_WMI);
326 break;
328 sizeNeeded += sizeof(SRBEX_DATA_POWER);
329 break;
330 case SrbExDataTypePnP:
331 sizeNeeded += sizeof(SRBEX_DATA_PNP);
332 break;
334 sizeNeeded += sizeof(SRBEX_DATA_IO_INFO);
335 break;
336 default:
338 break;
339 }
340 }
341 va_end(ap);
342
343 if (status == STATUS_SUCCESS)
344 {
345 if (AllocateRoutine)
346 {
347 *Srb = AllocateRoutine(sizeNeeded);
348 if (*Srb == NULL)
349 {
351 }
352 }
353
354 if (ByteSize != NULL)
355 {
356 *ByteSize = sizeNeeded;
357 }
358
359 if (*Srb)
360 {
361 va_start(ap, NumSrbExData);
362#ifdef _MSC_VER
363 #pragma prefast(suppress:26015, "pInitializeStorageRequestBlock will set the SrbLength field")
364#endif
365 status = pInitializeStorageRequestBlock(*Srb, AddressType, sizeNeeded, NumSrbExData, ap);
366 va_end(ap);
367 }
368
369 }
370
371 return status;
372}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define va_arg(ap, T)
Definition: acmsvcex.h:89
LONG NTSTATUS
Definition: precomp.h:26
_In_ PSCSI_REQUEST_BLOCK Srb
Definition: cdrom.h:989
#define NULL
Definition: types.h:112
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
struct STOR_ADDRESS_ALIGN _STOR_ADDR_BTL8 STOR_ADDR_BTL8
struct SRB_ALIGN _SRBEX_DATA_SCSI_CDB_VAR SRBEX_DATA_SCSI_CDB_VAR
struct SRB_ALIGN _SRBEX_DATA_IO_INFO SRBEX_DATA_IO_INFO
struct SRB_ALIGN _SRBEX_DATA_SCSI_CDB16 SRBEX_DATA_SCSI_CDB16
#define STORAGE_ADDRESS_TYPE_BTL8
Definition: srb.h:666
struct SRB_ALIGN _SRBEX_DATA_PNP SRBEX_DATA_PNP
struct SRB_ALIGN _SRBEX_DATA_WMI SRBEX_DATA_WMI
struct SRB_ALIGN _SRBEX_DATA_POWER SRBEX_DATA_POWER
@ SrbExDataTypeWmi
Definition: srb.h:462
@ SrbExDataTypeScsiCdb32
Definition: srb.h:460
@ SrbExDataTypeBidirectional
Definition: srb.h:458
@ SrbExDataTypeScsiCdb16
Definition: srb.h:459
@ SrbExDataTypePower
Definition: srb.h:463
@ SrbExDataTypeScsiCdbVar
Definition: srb.h:461
@ SrbExDataTypePnP
Definition: srb.h:464
@ SrbExDataTypeIoInfo
Definition: srb.h:465
struct SRB_ALIGN _SRBEX_DATA_BIDIRECTIONAL SRBEX_DATA_BIDIRECTIONAL
STORAGE_REQUEST_BLOCK
Definition: srb.h:661
struct SRB_ALIGN _SRBEX_DATA_SCSI_CDB32 SRBEX_DATA_SCSI_CDB32
enum _SRBEXDATATYPE SRBEXDATATYPE
#define STATUS_SUCCESS
Definition: shellext.h:65
NTSTATUS pInitializeStorageRequestBlock(_Inout_bytecount_(ByteSize) PSTORAGE_REQUEST_BLOCK Srb, _In_ USHORT AddressType, _In_ ULONG ByteSize, _In_ ULONG NumSrbExData, _In_ va_list ap)
Definition: srblib.c:52
Definition: ps.c:97
void * PVOID
Definition: typedefs.h:50
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36
_In_ PRTL_GENERIC_COMPARE_ROUTINE _In_ PRTL_GENERIC_ALLOCATE_ROUTINE AllocateRoutine
Definition: rtlfuncs.h:1089
_IRQL_requires_same_ _In_ CLONG ByteSize
Definition: rtltypes.h:399

Referenced by __drv_allocatesMem(), and InitializeTransferPackets().

◆ DefaultStorageRequestBlockAllocateRoutine()

PVOID DefaultStorageRequestBlockAllocateRoutine ( _In_ CLONG  ByteSize)

Definition at line 28 of file srblib.c.

46{
47 return ExAllocatePoolWithTag(NonPagedPoolNx, ByteSize, '+brs');
48}
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350

Referenced by __drv_allocatesMem(), and InitializeTransferPackets().

◆ InitializeStorageRequestBlock()

◆ pInitializeStorageRequestBlock()

NTSTATUS pInitializeStorageRequestBlock ( _Inout_bytecount_(ByteSize) PSTORAGE_REQUEST_BLOCK  Srb,
_In_ USHORT  AddressType,
_In_ ULONG  ByteSize,
_In_ ULONG  NumSrbExData,
_In_ va_list  ap 
)

Definition at line 52 of file srblib.c.

83{
86 PSRBEX_DATA srbExData;
88 ULONG length = (ULONG)-1;
90 ULONG srbExDataLength = (ULONG)-1;
91 ULONG varLength;
92 ULONG i;
93
94 if (ByteSize < sizeof(STORAGE_REQUEST_BLOCK)) {
96 }
97
99
102 Srb->Signature = SRB_SIGNATURE;
104 Srb->SrbLength = ByteSize;
105 Srb->NumSrbExData = NumSrbExData;
106
108 if (NumSrbExData > 0) {
109 offset += ((NumSrbExData - 1) * sizeof(ULONG));
110
111 // Ensure offset is pointer type aligned
112 if (offset % sizeof(PVOID)) {
113 offset += (sizeof(PVOID) - (offset % sizeof(PVOID)));
114 }
115 }
116 Srb->AddressOffset = offset;
117
118 if (AddressType == STORAGE_ADDRESS_TYPE_BTL8)
119 {
120 if ((ByteSize < offset) ||
121 (ByteSize < (offset + sizeof(STOR_ADDR_BTL8)))) {
123 }
126 address->AddressLength = STOR_ADDR_BTL8_ADDRESS_LENGTH;
127 offset += sizeof(STOR_ADDR_BTL8);
128 } else
129 {
131 }
132
133 for (i = 0; i < NumSrbExData && status == STATUS_SUCCESS; i++)
134 {
135 if (ByteSize <= offset) {
137 break;
138 }
139 srbExData = (PSRBEX_DATA)((PUCHAR)Srb + offset);
140 Srb->SrbExDataOffset[i] = offset;
141
143
144 switch (type)
145 {
148 srbExDataLength = SRBEX_DATA_BIDIRECTIONAL_LENGTH;
149 break;
152 srbExDataLength = SRBEX_DATA_SCSI_CDB16_LENGTH;
153 break;
156 srbExDataLength = SRBEX_DATA_SCSI_CDB32_LENGTH;
157 break;
159 varLength = va_arg(ap, ULONG);
160 length = sizeof(SRBEX_DATA_SCSI_CDB_VAR) + varLength;
161 srbExDataLength = SRBEX_DATA_SCSI_CDB_VAR_LENGTH_MIN + varLength;
162 break;
163 case SrbExDataTypeWmi:
164 length = sizeof(SRBEX_DATA_WMI);
165 srbExDataLength = SRBEX_DATA_WMI_LENGTH;
166 break;
168 length = sizeof(SRBEX_DATA_POWER);
169 srbExDataLength = SRBEX_DATA_POWER_LENGTH;
170 break;
171 case SrbExDataTypePnP:
172 length = sizeof(SRBEX_DATA_PNP);
173 srbExDataLength = SRBEX_DATA_PNP_LENGTH;
174 break;
176 length = sizeof(SRBEX_DATA_IO_INFO);
177 srbExDataLength = SRBEX_DATA_IO_INFO_LENGTH;
178 break;
179 default:
181 break;
182 }
183
184 if (status == STATUS_SUCCESS)
185 {
186 NT_ASSERT(length != (ULONG)-1);
187
188 if (ByteSize < (offset + length)) {
190 break;
191 }
192
193 NT_ASSERT(srbExDataLength != (ULONG)-1);
194
195 srbExData->Type = type;
196 srbExData->Length = srbExDataLength;
197 offset += length;
198 }
199 }
200
201 return status;
202}
static const WCHAR Signature[]
Definition: parser.c:141
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint address
Definition: glext.h:9393
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLintptr offset
Definition: glext.h:5920
#define STOR_ADDRESS_TYPE_BTL8
Definition: scsi.h:3525
#define STOR_ADDR_BTL8_ADDRESS_LENGTH
Definition: scsi.h:3528
struct STOR_ADDRESS_ALIGN _STOR_ADDRESS * PSTOR_ADDRESS
#define SRB_SIGNATURE
Definition: srb.h:616
#define SRBEX_DATA_SCSI_CDB32_LENGTH
Definition: srb.h:506
#define STORAGE_REQUEST_BLOCK_VERSION_1
Definition: srb.h:617
#define SRBEX_DATA_SCSI_CDB_VAR_LENGTH_MIN
Definition: srb.h:523
#define SRBEX_DATA_IO_INFO_LENGTH
Definition: srb.h:583
#define SRB_FUNCTION_STORAGE_REQUEST_BLOCK
Definition: srb.h:108
#define SRBEX_DATA_BIDIRECTIONAL_LENGTH
Definition: srb.h:476
struct SRB_ALIGN _SRBEX_DATA * PSRBEX_DATA
#define SRBEX_DATA_PNP_LENGTH
Definition: srb.h:569
#define SRBEX_DATA_POWER_LENGTH
Definition: srb.h:556
#define SRBEX_DATA_WMI_LENGTH
Definition: srb.h:542
#define SRBEX_DATA_SCSI_CDB16_LENGTH
Definition: srb.h:489
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
UCHAR Function
Definition: srb.h:250
USHORT Length
Definition: srb.h:249
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
unsigned char * PUCHAR
Definition: typedefs.h:53
#define NT_ASSERT
Definition: rtlfuncs.h:3310

Referenced by CreateStorageRequestBlock(), and InitializeStorageRequestBlock().