-
Notifications
You must be signed in to change notification settings - Fork 53
/
srbcompat.h
374 lines (319 loc) · 7.21 KB
/
srbcompat.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
/**
* @file sys/srbcompat.h
*
* @copyright 2018-2020 Bill Zissimopoulos
*/
/*
* This file is part of WinSpd.
*
* You can redistribute it and/or modify it under the terms of the GNU
* General Public License version 3 as published by the Free Software
* Foundation.
*
* Licensees holding a valid commercial license may use this software
* in accordance with the commercial license agreement provided in
* conjunction with the software. The terms and conditions of any such
* commercial license agreement shall govern, supersede, and render
* ineffective any application of the GPLv3 license to this software,
* notwithstanding of any reference thereto in the software or
* associated repository.
*/
#ifndef WINSPD_SYS_SRBCOMPAT_H_INCLUDED
#define WINSPD_SYS_SRBCOMPAT_H_INCLUDED
#define SRBHELPER_ASSERT ASSERT
#include <srbhelper.h>
/* SRB compatiblity functions (missing when NTDDI_VERSION < NTDDI_WIN8) */
#if NTDDI_VERSION < NTDDI_WIN8
FORCEINLINE BOOLEAN
SrbCopySrb(
_In_ PVOID DestinationSrb,
_In_ ULONG DestinationSrbLength,
_In_ PVOID SourceSrb)
{
BOOLEAN Result = FALSE;
if (DestinationSrbLength >= SCSI_REQUEST_BLOCK_SIZE)
{
RtlCopyMemory(DestinationSrb, SourceSrb, SCSI_REQUEST_BLOCK_SIZE);
Result = TRUE;
}
return Result;
}
FORCEINLINE VOID
SrbZeroSrb(
_In_ PVOID Srb)
{
UCHAR Function = ((PSCSI_REQUEST_BLOCK)Srb)->Function;
USHORT Length = ((PSCSI_REQUEST_BLOCK)Srb)->Length;
RtlZeroMemory(Srb, sizeof(SCSI_REQUEST_BLOCK));
((PSCSI_REQUEST_BLOCK)Srb)->Function = Function;
((PSCSI_REQUEST_BLOCK)Srb)->Length = Length;
}
FORCEINLINE ULONG
SrbGetSrbLength(
_In_ PVOID Srb)
{
UNREFERENCED_PARAMETER(Srb);
return sizeof(SCSI_REQUEST_BLOCK);
}
FORCEINLINE PCDB
SrbGetCdb(
_In_ PVOID Srb)
{
return (PCDB)((PSCSI_REQUEST_BLOCK)Srb)->Cdb;
}
FORCEINLINE ULONG
SrbGetSrbFunction(
_In_ PVOID Srb)
{
return (ULONG)((PSCSI_REQUEST_BLOCK)Srb)->Function;
}
FORCEINLINE PVOID
SrbGetSenseInfoBuffer(
_In_ PVOID Srb)
{
return ((PSCSI_REQUEST_BLOCK)Srb)->SenseInfoBuffer;
}
FORCEINLINE UCHAR
SrbGetSenseInfoBufferLength(
_In_ PVOID Srb)
{
return ((PSCSI_REQUEST_BLOCK)Srb)->SenseInfoBufferLength;
}
FORCEINLINE VOID
SrbSetSenseInfoBuffer(
_In_ PVOID Srb,
_In_opt_ PVOID SenseInfoBuffer)
{
((PSCSI_REQUEST_BLOCK)Srb)->SenseInfoBuffer = SenseInfoBuffer;
}
FORCEINLINE VOID
SrbSetSenseInfoBufferLength(
_In_ PVOID Srb,
_In_ UCHAR SenseInfoBufferLength)
{
((PSCSI_REQUEST_BLOCK)Srb)->SenseInfoBufferLength = SenseInfoBufferLength;
}
FORCEINLINE PVOID
SrbGetOriginalRequest(
_In_ PVOID Srb)
{
return ((PSCSI_REQUEST_BLOCK)Srb)->OriginalRequest;
}
FORCEINLINE VOID
SrbSetOriginalRequest(
_In_ PVOID Srb,
_In_opt_ PVOID OriginalRequest)
{
((PSCSI_REQUEST_BLOCK)Srb)->OriginalRequest = OriginalRequest;
}
FORCEINLINE PVOID
SrbGetDataBuffer(
_In_ PVOID Srb)
{
return ((PSCSI_REQUEST_BLOCK)Srb)->DataBuffer;
}
FORCEINLINE VOID
SrbSetDataBuffer(
_In_ PVOID Srb,
_In_opt_ __drv_aliasesMem PVOID DataBuffer)
{
((PSCSI_REQUEST_BLOCK)Srb)->DataBuffer = DataBuffer;
}
FORCEINLINE ULONG
SrbGetDataTransferLength(
_In_ PVOID Srb)
{
return ((PSCSI_REQUEST_BLOCK)Srb)->DataTransferLength;
}
FORCEINLINE VOID
SrbSetDataTransferLength(
_In_ PVOID Srb,
_In_ ULONG DataTransferLength)
{
((PSCSI_REQUEST_BLOCK)Srb)->DataTransferLength = DataTransferLength;
}
FORCEINLINE ULONG
SrbGetTimeOutValue(
_In_ PVOID Srb)
{
return ((PSCSI_REQUEST_BLOCK)Srb)->TimeOutValue;
}
FORCEINLINE VOID
SrbSetTimeOutValue(
_In_ PVOID Srb,
_In_ ULONG TimeOutValue)
{
((PSCSI_REQUEST_BLOCK)Srb)->TimeOutValue = TimeOutValue;
}
FORCEINLINE VOID
SrbSetQueueSortKey(
_In_ PVOID Srb,
_In_ ULONG QueueSortKey)
{
((PSCSI_REQUEST_BLOCK)Srb)->QueueSortKey = QueueSortKey;
}
FORCEINLINE VOID
SrbSetQueueTag(
_In_ PVOID Srb,
_In_ ULONG QueueTag)
{
((PSCSI_REQUEST_BLOCK)Srb)->QueueTag = (UCHAR)QueueTag;
}
#define SrbSetRequestTag SrbSetQueueTag
FORCEINLINE ULONG
SrbGetQueueTag(
_In_ PVOID Srb)
{
return ((PSCSI_REQUEST_BLOCK)Srb)->QueueTag;
}
#define SrbGetRequestTag SrbGetQueueTag
FORCEINLINE PVOID
SrbGetNextSrb(
_In_ PVOID Srb)
{
return (PVOID)((PSCSI_REQUEST_BLOCK)Srb)->NextSrb;
}
FORCEINLINE VOID
SrbSetNextSrb(
_In_ PVOID Srb,
_In_opt_ PVOID NextSrb)
{
((PSCSI_REQUEST_BLOCK)Srb)->NextSrb = (PSCSI_REQUEST_BLOCK)NextSrb;
}
FORCEINLINE ULONG
SrbGetSrbFlags(
_In_ PVOID Srb)
{
return ((PSCSI_REQUEST_BLOCK)Srb)->SrbFlags;
}
FORCEINLINE VOID
SrbAssignSrbFlags(
_In_ PVOID Srb,
_In_ ULONG Flags)
{
((PSCSI_REQUEST_BLOCK)Srb)->SrbFlags = Flags;
}
FORCEINLINE VOID
SrbSetSrbFlags(
_In_ PVOID Srb,
_In_ ULONG Flags)
{
((PSCSI_REQUEST_BLOCK)Srb)->SrbFlags |= Flags;
}
FORCEINLINE VOID
SrbClearSrbFlags(
_In_ PVOID Srb,
_In_ ULONG Flags)
{
((PSCSI_REQUEST_BLOCK)Srb)->SrbFlags &= ~Flags;
}
FORCEINLINE ULONG
SrbGetSystemStatus(
_In_ PVOID Srb)
{
return ((PSCSI_REQUEST_BLOCK)Srb)->InternalStatus;
}
FORCEINLINE VOID
SrbSetSystemStatus(
_In_ PVOID Srb,
_In_ ULONG Status)
{
((PSCSI_REQUEST_BLOCK)Srb)->InternalStatus = Status;
}
FORCEINLINE UCHAR
SrbGetScsiStatus(
_In_ PVOID Srb)
{
return ((PSCSI_REQUEST_BLOCK)Srb)->ScsiStatus;
}
FORCEINLINE VOID
SrbSetScsiStatus(
_In_ PVOID Srb,
_In_ UCHAR ScsiStatus)
{
((PSCSI_REQUEST_BLOCK)Srb)->ScsiStatus = ScsiStatus;
}
FORCEINLINE UCHAR
SrbGetCdbLength(
_In_ PVOID Srb)
{
return ((PSCSI_REQUEST_BLOCK)Srb)->CdbLength;
}
FORCEINLINE VOID
SrbSetCdbLength(
_In_ PVOID Srb,
_In_ UCHAR CdbLength)
{
((PSCSI_REQUEST_BLOCK)Srb)->CdbLength = CdbLength;
}
FORCEINLINE ULONG
SrbGetRequestAttribute(
_In_ PVOID Srb)
{
return ((PSCSI_REQUEST_BLOCK)Srb)->QueueAction;
}
#define SrbGetQueueAction SrbGetRequestAttribute
FORCEINLINE VOID
SrbSetRequestAttribute(
_In_ PVOID Srb,
_In_ UCHAR RequestAttribute)
{
((PSCSI_REQUEST_BLOCK)Srb)->QueueAction = RequestAttribute;
}
#define SrbSetQueueAction SrbSetRequestAttribute
FORCEINLINE UCHAR
SrbGetPathId(
_In_ PVOID Srb)
{
return ((PSCSI_REQUEST_BLOCK)Srb)->PathId;
}
FORCEINLINE UCHAR
SrbGetTargetId(
_In_ PVOID Srb)
{
return ((PSCSI_REQUEST_BLOCK)Srb)->TargetId;
}
FORCEINLINE UCHAR
SrbGetLun(
_In_ PVOID Srb)
{
return ((PSCSI_REQUEST_BLOCK)Srb)->Lun;
}
FORCEINLINE VOID
SrbGetPathTargetLun(
_In_ PVOID Srb,
_In_opt_ PUCHAR PathId,
_In_opt_ PUCHAR TargetId,
_In_opt_ PUCHAR Lun)
{
if (PathId != NULL)
*PathId = ((PSCSI_REQUEST_BLOCK)Srb)->PathId;
if (TargetId != NULL)
*TargetId = ((PSCSI_REQUEST_BLOCK)Srb)->TargetId;
if (Lun != NULL)
*Lun = ((PSCSI_REQUEST_BLOCK)Srb)->Lun;
}
FORCEINLINE PVOID
SrbGetMiniportContext(
_In_ PVOID Srb)
{
return ((PSCSI_REQUEST_BLOCK)Srb)->SrbExtension;
}
FORCEINLINE UCHAR
SrbGetSrbStatus(
_In_ PVOID Srb)
{
return ((PSCSI_REQUEST_BLOCK)Srb)->SrbStatus;
}
FORCEINLINE VOID
SrbSetSrbStatus(
_In_ PVOID Srb,
_In_ UCHAR Status)
{
if (((PSCSI_REQUEST_BLOCK)Srb)->SrbStatus & SRB_STATUS_AUTOSENSE_VALID)
((PSCSI_REQUEST_BLOCK)Srb)->SrbStatus = Status | SRB_STATUS_AUTOSENSE_VALID;
else
((PSCSI_REQUEST_BLOCK)Srb)->SrbStatus = Status;
}
#endif
#endif