ReactOS 0.4.17-dev-1268-g5608ce5
srbex.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Storport Driver
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Storport extended request block translation
5 */
6
7/* INCLUDES *******************************************************************/
8
9#include "precomp.h"
10
11#define NDEBUG
12#include <debug.h>
13
14
15/* A miniport walks to the address and the command block by offset */
19
20
21/* FUNCTIONS ******************************************************************/
22
26VOID
31{
32 RtlZeroMemory(Address, sizeof(*Address));
33
36 Address->Path = (UCHAR)PdoExtension->Bus;
37 Address->Target = (UCHAR)PdoExtension->Target;
38 Address->Lun = (UCHAR)PdoExtension->Lun;
39}
40
41
49{
51
52 return (Header->Function == SRB_FUNCTION_STORAGE_REQUEST_BLOCK);
53}
54
55
63{
65 {
67
69 }
70
72}
73
74
82{
84 {
86
87 return Extended->DataBuffer;
88 }
89
90 return Srb->DataBuffer;
91}
92
93
100VOID
101NTAPI
105{
106 PSTORAGE_REQUEST_BLOCK Extended = &Request->Srb;
107
108 Extended->Length = sizeof(*Extended);
109 Extended->Function = SRB_FUNCTION_STORAGE_REQUEST_BLOCK;
110 Extended->SrbStatus = SRB_STATUS_PENDING;
111 Extended->Signature = SRB_SIGNATURE;
112 Extended->Version = STORAGE_REQUEST_BLOCK_VERSION_1;
113 Extended->SrbLength = sizeof(*Request);
114 Extended->SrbFunction = Srb->Function;
115 Extended->SrbFlags = Srb->SrbFlags;
116 Extended->RequestTag = Srb->QueueTag;
117 Extended->RequestAttribute = Srb->QueueAction;
118 Extended->TimeOutValue = Srb->TimeOutValue;
119 Extended->DataTransferLength = Srb->DataTransferLength;
120 Extended->DataBuffer = Srb->DataBuffer;
121
122 /* The miniport hands this straight back to us on completion */
123 Extended->OriginalRequest = Srb->OriginalRequest;
124 Extended->MiniportContext = Srb->SrbExtension;
125
126 Extended->AddressOffset = FIELD_OFFSET(EXTENDED_REQUEST, Address);
127
128 Request->Address.Type = STOR_ADDRESS_TYPE_BTL8;
129 Request->Address.AddressLength = STOR_ADDR_BTL8_ADDRESS_LENGTH;
130 Request->Address.Path = Srb->PathId;
131 Request->Address.Target = Srb->TargetId;
132 Request->Address.Lun = Srb->Lun;
133
134 /* Only SRB_FUNCTION_EXECUTE_SCSI carries a CDB */
136 return;
137
138 Extended->NumSrbExData = 1;
139 Extended->SrbExDataOffset[0] = FIELD_OFFSET(EXTENDED_REQUEST, Cdb);
140
143 Request->Cdb.ScsiStatus = Srb->ScsiStatus;
144 Request->Cdb.SenseInfoBufferLength = Srb->SenseInfoBufferLength;
145 Request->Cdb.CdbLength = Srb->CdbLength;
146 Request->Cdb.SenseInfoBuffer = Srb->SenseInfoBuffer;
147
148 RtlCopyMemory(Request->Cdb.Cdb, Srb->Cdb, sizeof(Request->Cdb.Cdb));
149}
150
151
155VOID
156NTAPI
160{
161 PSTORAGE_REQUEST_BLOCK Extended = &Request->Srb;
162
163 Srb->SrbStatus = Extended->SrbStatus;
164 Srb->DataTransferLength = Extended->DataTransferLength;
165
166 if (Extended->NumSrbExData == 0)
167 return;
168
169 Srb->ScsiStatus = Request->Cdb.ScsiStatus;
170 Srb->SenseInfoBufferLength = Request->Cdb.SenseInfoBufferLength;
171}
unsigned char BOOLEAN
Definition: actypes.h:127
_In_ PSCSI_REQUEST_BLOCK Srb
Definition: cdrom.h:989
Definition: Header.h:9
#define SRB_FUNCTION_EXECUTE_SCSI
Definition: srb.h:315
#define SRB_STATUS_PENDING
Definition: srb.h:340
@ PdoExtension
Definition: precomp.h:62
#define C_ASSERT(e)
Definition: intsafe.h:73
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
static WCHAR Address[46]
Definition: ping.c:68
_In_opt_ WDFREQUEST _In_ ULONG _In_ BOOLEAN _In_ PCDB Cdb
Definition: scratch.h:159
struct STOR_ADDRESS_ALIGN _STOR_ADDR_BTL8 * PSTOR_ADDR_BTL8
#define STOR_ADDRESS_TYPE_BTL8
Definition: scsi.h:3571
struct STOR_ADDRESS_ALIGN _STOR_ADDR_BTL8 STOR_ADDR_BTL8
#define STOR_ADDR_BTL8_ADDRESS_LENGTH
Definition: scsi.h:3574
#define SRB_SIGNATURE
Definition: srb.h:616
#define STORAGE_REQUEST_BLOCK_VERSION_1
Definition: srb.h:617
#define SRB_FUNCTION_STORAGE_REQUEST_BLOCK
Definition: srb.h:108
* PSTORAGE_REQUEST_BLOCK
Definition: srb.h:661
@ SrbExDataTypeScsiCdb16
Definition: srb.h:459
STORAGE_REQUEST_BLOCK
Definition: srb.h:661
struct SRB_ALIGN _STORAGE_REQUEST_BLOCK_HEADER * PSTORAGE_REQUEST_BLOCK_HEADER
#define SRBEX_DATA_SCSI_CDB16_LENGTH
Definition: srb.h:489
VOID NTAPI StorpCompleteExtendedSrb(_In_ PSCSI_REQUEST_BLOCK Srb, _In_ PEXTENDED_REQUEST Request)
Carries the miniport's answer back to the original request block.
Definition: srbex.c:157
BOOLEAN NTAPI StorpIsExtendedSrb(_In_ PVOID Srb)
Tells whether a request block is in the extended format.
Definition: srbex.c:47
VOID NTAPI StorpBuildUnitAddress(_In_ PPDO_DEVICE_EXTENSION PdoExtension, _Out_ PSTOR_ADDR_BTL8 Address)
Fills in the bus, target and LUN address of a logical unit.
Definition: srbex.c:28
PQUEUED_REQUEST_REFERENCE NTAPI StorpRequestReference(_In_ PSCSI_REQUEST_BLOCK Srb)
Finds the request reference behind an SRB in either format.
Definition: srbex.c:61
PVOID NTAPI StorpSrbDataBuffer(_In_ PSCSI_REQUEST_BLOCK Srb)
Finds the data buffer of a request in either format.
Definition: srbex.c:80
VOID NTAPI StorpBuildExtendedSrb(_In_ PSCSI_REQUEST_BLOCK Srb, _Out_ PEXTENDED_REQUEST Request)
Fills in the extended request a miniport will be given.
Definition: srbex.c:102
UCHAR QueueTag
Definition: srb.h:256
ULONG TimeOutValue
Definition: srb.h:262
UCHAR TargetId
Definition: srb.h:254
PVOID OriginalRequest
Definition: srb.h:266
UCHAR SenseInfoBufferLength
Definition: srb.h:259
PVOID DataBuffer
Definition: srb.h:263
UCHAR PathId
Definition: srb.h:253
UCHAR QueueAction
Definition: srb.h:257
UCHAR CdbLength
Definition: srb.h:258
UCHAR Cdb[16]
Definition: srb.h:279
PVOID SenseInfoBuffer
Definition: srb.h:264
UCHAR Function
Definition: srb.h:250
UCHAR ScsiStatus
Definition: srb.h:252
ULONG DataTransferLength
Definition: srb.h:261
PVOID SrbExtension
Definition: srb.h:267
ULONG SrbFlags
Definition: srb.h:260
UCHAR SrbStatus
Definition: srb.h:251
unsigned char UCHAR
Definition: typedefs.h:53
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define NTAPI
Definition: typedefs.h:36
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFREQUEST Request