00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
#ifndef _CLASS_
00024
00025
#include <ntdddisk.h>
00026
#include <ntddcdrm.h>
00027
#include <ntddtape.h>
00028
#include "ntddscsi.h"
00029
#include <stdio.h>
00030
00031
#if DBG
00032
00033
#define DebugPrint(x) ScsiDebugPrint x
00034
00035
#else
00036
00037 #define DebugPrint(x)
00038
00039
#endif // DBG
00040
00041
#ifdef POOL_TAGGING
00042
#undef ExAllocatePool
00043
#undef ExAllocatePoolWithQuota
00044
#define ExAllocatePool(a,b) ExAllocatePoolWithTag(a,b,'HscS')
00045
#define ExAllocatePoolWithQuota(a,b) ExAllocatePoolWithQuotaTag(a,b,'HscS')
00046
#endif
00047
00048 #define MAXIMUM_RETRIES 4
00049
00050
struct _CLASS_INIT_DATA;
00051
00052
typedef
00053
VOID
00054 (*PCLASS_ERROR) (
00055 IN
PDEVICE_OBJECT DeviceObject,
00056 IN PSCSI_REQUEST_BLOCK Srb,
00057 IN OUT
NTSTATUS *
Status,
00058 IN OUT BOOLEAN *Retry
00059 );
00060
00061
typedef
00062 BOOLEAN
00063 (*PCLASS_DEVICE_CALLBACK) (
00064 IN PINQUIRYDATA
00065 );
00066
00067
typedef
00068
NTSTATUS
00069 (*PCLASS_READ_WRITE) (
00070 IN
PDEVICE_OBJECT DeviceObject,
00071 IN
PIRP Irp
00072 );
00073
00074
typedef
00075 BOOLEAN
00076 (*PCLASS_FIND_DEVICES) (
00077 IN
PDRIVER_OBJECT DriverObject,
00078 IN PUNICODE_STRING RegistryPath,
00079 IN
struct _CLASS_INIT_DATA *InitializationData,
00080 IN
PDEVICE_OBJECT PortDeviceObject,
00081 IN ULONG PortNumber
00082 );
00083
00084
typedef
00085
NTSTATUS
00086 (*PCLASS_DEVICE_CONTROL) (
00087 IN
PDEVICE_OBJECT DeviceObject,
00088 IN
PIRP Irp
00089 );
00090
00091
typedef
00092
NTSTATUS
00093 (*PCLASS_SHUTDOWN_FLUSH) (
00094 IN
PDEVICE_OBJECT DeviceObject,
00095 IN
PIRP Irp
00096 );
00097
00098
typedef
00099
NTSTATUS
00100 (*PCLASS_CREATE_CLOSE) (
00101 IN
PDEVICE_OBJECT DeviceObject,
00102 IN
PIRP Irp
00103 );
00104
00105 typedef struct _CLASS_INIT_DATA {
00106
00107
00108
00109
00110
00111 ULONG
InitializationDataSize;
00112
00113
00114
00115
00116
00117
00118 ULONG
DeviceExtensionSize;
00119
00120 DEVICE_TYPE
DeviceType;
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135 ULONG
DeviceCharacteristics;
00136
00137
00138
00139
00140
00141 PCLASS_ERROR ClassError;
00142 PCLASS_READ_WRITE ClassReadWriteVerification;
00143 PCLASS_DEVICE_CALLBACK ClassFindDeviceCallBack;
00144 PCLASS_FIND_DEVICES ClassFindDevices;
00145 PCLASS_DEVICE_CONTROL ClassDeviceControl;
00146 PCLASS_SHUTDOWN_FLUSH ClassShutdownFlush;
00147 PCLASS_CREATE_CLOSE ClassCreateClose;
00148 PDRIVER_STARTIO ClassStartIo;
00149
00150 }
CLASS_INIT_DATA, *
PCLASS_INIT_DATA;
00151
00152
typedef struct _DEVICE_EXTENSION {
00153
00154
00155
00156
00157
00158
PDEVICE_OBJECT DeviceObject;
00159
00160
00161
00162
00163
00164 PDEVICE_OBJECT PortDeviceObject;
00165
00166
00167
00168
00169
00170 LARGE_INTEGER
PartitionLength;
00171
00172
00173
00174
00175
00176 LARGE_INTEGER
StartingOffset;
00177
00178
00179
00180
00181
00182 ULONG
DMByteSkew;
00183
00184
00185
00186
00187
00188 ULONG
DMSkew;
00189
00190
00191
00192
00193
00194 BOOLEAN
DMActive;
00195
00196
00197
00198
00199
00200 PCLASS_ERROR ClassError;
00201 PCLASS_READ_WRITE ClassReadWriteVerification;
00202 PCLASS_FIND_DEVICES ClassFindDevices;
00203 PCLASS_DEVICE_CONTROL ClassDeviceControl;
00204 PCLASS_SHUTDOWN_FLUSH ClassShutdownFlush;
00205 PCLASS_CREATE_CLOSE ClassCreateClose;
00206 PDRIVER_STARTIO ClassStartIo;
00207
00208
00209
00210
00211
00212 PIO_SCSI_CAPABILITIES
PortCapabilities;
00213
00214
00215
00216
00217
00218 PDISK_GEOMETRY
DiskGeometry;
00219
00220
00221
00222
00223
00224
00225 PDEVICE_OBJECT PhysicalDevice;
00226
00227
00228
00229
00230
00231 PSENSE_DATA
SenseData;
00232
00233
00234
00235
00236
00237 ULONG
TimeOutValue;
00238
00239
00240
00241
00242
00243 ULONG
DeviceNumber;
00244
00245
00246
00247
00248
00249 ULONG
SrbFlags;
00250
00251
00252
00253
00254
00255 ULONG
ErrorCount;
00256
00257
00258
00259
00260
00261 KSPIN_LOCK
SplitRequestSpinLock;
00262
00263
00264
00265
00266
00267 NPAGED_LOOKASIDE_LIST SrbLookasideListHead;
00268
00269
00270
00271
00272
00273 LONG
LockCount;
00274
00275
00276
00277
00278
00279 UCHAR
PortNumber;
00280
00281
00282
00283
00284
00285 UCHAR
PathId;
00286
00287
00288
00289
00290
00291 UCHAR
TargetId;
00292
00293
00294
00295
00296
00297 UCHAR
Lun;
00298
00299
00300
00301
00302
00303 UCHAR
SectorShift;
00304 UCHAR
ReservedByte;
00305
00306
00307
00308
00309
00310 USHORT DeviceFlags;
00311
00312
00313
00314
00315
00316
00317
00318
00319 PKEVENT MediaChangeEvent;
00320 HANDLE
MediaChangeEventHandle;
00321 BOOLEAN
MediaChangeNoMedia;
00322
00323
00324
00325
00326
00327
00328 ULONG
MediaChangeCount;
00329
00330
00331 }
DEVICE_EXTENSION, *
PDEVICE_EXTENSION;
00332
00333
00334
00335
00336
00337 #define DEV_WRITE_CACHE 0x00000001
00338
00339
00340
00341
00342
00343
00344 #define DEV_USE_SCSI1 0x00000002
00345
00346
00347
00348
00349
00350
00351 #define DEV_SAFE_START_UNIT 0x00000004
00352
00353
00354
00355
00356
00357
00358 #define DEV_NO_12BYTE_CDB 0x00000008
00359
00360
00361
00362
00363
00364
typedef struct _COMPLETION_CONTEXT {
00365 PDEVICE_OBJECT DeviceObject;
00366 SCSI_REQUEST_BLOCK Srb;
00367 }
COMPLETION_CONTEXT, *
PCOMPLETION_CONTEXT;
00368
00369
#ifndef _NTDDK_
00370 #define SCSIPORT_API DECLSPEC_IMPORT
00371
#else
00372
#define SCSIPORT_API
00373
#endif
00374
00375
00376
00377
00378
00379
SCSIPORT_API
00380 ULONG
00381
ScsiClassInitialize(
00382 IN PVOID Argument1,
00383 IN PVOID Argument2,
00384 IN PCLASS_INIT_DATA InitializationData
00385 );
00386
00387
SCSIPORT_API
00388
NTSTATUS
00389
ScsiClassCreateDeviceObject(
00390 IN
PDRIVER_OBJECT DriverObject,
00391 IN PCCHAR ObjectNameBuffer,
00392 IN OPTIONAL
PDEVICE_OBJECT PhysicalDeviceObject,
00393 IN OUT
PDEVICE_OBJECT *DeviceObject,
00394 IN PCLASS_INIT_DATA InitializationData
00395 );
00396
00397
SCSIPORT_API
00398 ULONG
00399
ScsiClassFindUnclaimedDevices(
00400 IN PCLASS_INIT_DATA InitializationData,
00401 IN PSCSI_ADAPTER_BUS_INFO AdapterInformation
00402 );
00403
00404
SCSIPORT_API
00405
NTSTATUS
00406
ScsiClassGetCapabilities(
00407 IN
PDEVICE_OBJECT PortDeviceObject,
00408 OUT PIO_SCSI_CAPABILITIES *PortCapabilities
00409 );
00410
00411
SCSIPORT_API
00412
NTSTATUS
00413
ScsiClassGetInquiryData(
00414 IN
PDEVICE_OBJECT PortDeviceObject,
00415 IN PSCSI_ADAPTER_BUS_INFO *ConfigInfo
00416 );
00417
00418
SCSIPORT_API
00419
NTSTATUS
00420
ScsiClassReadDriveCapacity(
00421 IN
PDEVICE_OBJECT DeviceObject
00422 );
00423
00424
SCSIPORT_API
00425
VOID
00426
ScsiClassReleaseQueue(
00427 IN
PDEVICE_OBJECT DeviceObject
00428 );
00429
00430
SCSIPORT_API
00431
NTSTATUS
00432
ScsiClassRemoveDevice(
00433 IN
PDEVICE_OBJECT PortDeviceObject,
00434 IN UCHAR PathId,
00435 IN UCHAR TargetId,
00436 IN UCHAR Lun
00437 );
00438
00439
SCSIPORT_API
00440
NTSTATUS
00441
ScsiClassAsynchronousCompletion(
00442
PDEVICE_OBJECT DeviceObject,
00443
PIRP Irp,
00444 PVOID Context
00445 );
00446
00447
SCSIPORT_API
00448
VOID
00449
ScsiClassSplitRequest(
00450 IN
PDEVICE_OBJECT DeviceObject,
00451 IN
PIRP Irp,
00452 IN ULONG MaximumBytes
00453 );
00454
00455
SCSIPORT_API
00456
NTSTATUS
00457
ScsiClassDeviceControl(
00458
PDEVICE_OBJECT DeviceObject,
00459
PIRP Irp
00460 );
00461
00462
SCSIPORT_API
00463
NTSTATUS
00464
ScsiClassIoComplete(
00465 IN
PDEVICE_OBJECT DeviceObject,
00466 IN
PIRP Irp,
00467 IN PVOID Context
00468 );
00469
00470
SCSIPORT_API
00471
NTSTATUS
00472
ScsiClassCheckVerifyComplete(
00473 IN
PDEVICE_OBJECT DeviceObject,
00474 IN
PIRP Irp,
00475 IN PVOID Context
00476 );
00477
00478
SCSIPORT_API
00479
NTSTATUS
00480
ScsiClassIoCompleteAssociated(
00481 IN
PDEVICE_OBJECT DeviceObject,
00482 IN
PIRP Irp,
00483 IN PVOID Context
00484 );
00485
00486
SCSIPORT_API
00487 BOOLEAN
00488
ScsiClassInterpretSenseInfo(
00489 IN
PDEVICE_OBJECT DeviceObject,
00490 IN PSCSI_REQUEST_BLOCK Srb,
00491 IN UCHAR MajorFunctionCode,
00492 IN ULONG IoDeviceCode,
00493 IN ULONG RetryCount,
00494 OUT NTSTATUS *Status
00495 );
00496
00497
SCSIPORT_API
00498
NTSTATUS
00499
ScsiClassSendSrbSynchronous(
00500
PDEVICE_OBJECT DeviceObject,
00501 PSCSI_REQUEST_BLOCK Srb,
00502 PVOID BufferAddress,
00503 ULONG BufferLength,
00504 BOOLEAN WriteToDevice
00505 );
00506
00507
SCSIPORT_API
00508
NTSTATUS
00509
ScsiClassSendSrbAsynchronous(
00510
PDEVICE_OBJECT DeviceObject,
00511 PSCSI_REQUEST_BLOCK Srb,
00512
PIRP Irp,
00513 PVOID BufferAddress,
00514 ULONG BufferLength,
00515 BOOLEAN WriteToDevice
00516 );
00517
00518
SCSIPORT_API
00519
VOID
00520
ScsiClassBuildRequest(
00521
PDEVICE_OBJECT DeviceObject,
00522
PIRP Irp
00523 );
00524
00525
SCSIPORT_API
00526 ULONG
00527
ScsiClassModeSense(
00528 IN
PDEVICE_OBJECT DeviceObject,
00529 IN PCHAR ModeSenseBuffer,
00530 IN ULONG Length,
00531 IN UCHAR PageMode
00532 );
00533
00534
SCSIPORT_API
00535 BOOLEAN
00536
ScsiClassModeSelect(
00537 IN
PDEVICE_OBJECT DeviceObject,
00538 IN PCHAR ModeSelectBuffer,
00539 IN ULONG Length,
00540 IN BOOLEAN SavePage
00541 );
00542
00543
SCSIPORT_API
00544 PVOID
00545
ScsiClassFindModePage(
00546 IN PCHAR ModeSenseBuffer,
00547 IN ULONG Length,
00548 IN UCHAR PageMode,
00549 IN BOOLEAN Use6Byte
00550 );
00551
00552
SCSIPORT_API
00553
NTSTATUS
00554
ScsiClassClaimDevice(
00555 IN
PDEVICE_OBJECT PortDeviceObject,
00556 IN PSCSI_INQUIRY_DATA LunInfo,
00557 IN BOOLEAN Release,
00558 OUT
PDEVICE_OBJECT *NewPortDeviceObject OPTIONAL
00559 );
00560
00561
SCSIPORT_API
00562
NTSTATUS
00563
ScsiClassInternalIoControl (
00564 IN
PDEVICE_OBJECT DeviceObject,
00565 IN
PIRP Irp
00566 );
00567
00568
SCSIPORT_API
00569
VOID
00570
ScsiClassInitializeSrbLookasideList(
00571 IN PDEVICE_EXTENSION DeviceExtension,
00572 IN ULONG NumberElements
00573 );
00574
00575
SCSIPORT_API
00576 ULONG
00577
ScsiClassQueryTimeOutRegistryValue(
00578 IN PUNICODE_STRING RegistryPath
00579 );
00580
00581
SCSIPORT_API
00582 BOOLEAN
00583
ScsiClassIsFloppyDevice(
00584 IN
PDEVICE_OBJECT DeviceObject,
00585 IN PSCSI_INQUIRY_DATA LunInfo
00586 );
00587
00588
#endif