Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2926 lines
65 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. classpnp.h
  5. Abstract:
  6. These are the structures and defines that are used in the
  7. SCSI class drivers.
  8. Author:
  9. Mike Glass (mglass)
  10. Jeff Havens (jhavens)
  11. Revision History:
  12. --*/
  13. #ifndef _CLASS_
  14. #define _CLASS_
  15. #include <ntdddisk.h>
  16. #include <ntddcdrm.h>
  17. #include <ntddtape.h>
  18. #include <ntddscsi.h>
  19. #include "ntddstor.h"
  20. #include <stdio.h>
  21. #include <scsi.h>
  22. #if defined DebugPrint
  23. #undef DebugPrint
  24. #endif
  25. #ifdef TRY
  26. #undef TRY
  27. #endif
  28. #ifdef LEAVE
  29. #undef LEAVE
  30. #endif
  31. #ifdef FINALLY
  32. #undef FINALLY
  33. #endif
  34. #define TRY
  35. #define LEAVE goto __tryLabel;
  36. #define FINALLY __tryLabel:
  37. // #define ALLOCATE_SRB_FROM_POOL
  38. //
  39. // describes the well-known bit masks for ClassDebug, and describes the bits
  40. // to enable in the debugger to view just those messages. ClassDebugExternalX
  41. // are reserved for third-party components' debugging use. Anything above
  42. // 16 will only be printed if the lower two bytes of ClassDebug are higher
  43. // than the given level (no masking will be available).
  44. //
  45. typedef enum _CLASS_DEBUG_LEVEL {
  46. ClassDebugError = 0, // always printed
  47. ClassDebugWarning = 1, // set bit 0x00010000 in ClassDebug
  48. ClassDebugTrace = 2, // set bit 0x00020000 in ClassDebug
  49. ClassDebugInfo = 3, // set bit 0x00040000 in ClassDebug
  50. #if 0
  51. ClassDebug Internal = 4, // set bit 0x00080000 in ClassDebug
  52. ClassDebug Internal = 5, // set bit 0x00100000 in ClassDebug
  53. ClassDebug Internal = 6, // set bit 0x00200000 in ClassDebug
  54. ClassDebug Internal = 7, // set bit 0x00400000 in ClassDebug
  55. #endif // 0
  56. ClassDebugMediaLocks = 8, // set bit 0x00800000 in ClassDebug
  57. ClassDebugMCN = 9, // set bit 0x01000000 in ClassDebug
  58. ClassDebugDelayedRetry = 10, // set bit 0x02000000 in ClassDebug
  59. ClassDebugSenseInfo = 11, // set bit 0x04000000 in ClassDebug
  60. ClassDebugRemoveLock = 12, // set bit 0x08000000 in ClassDebug
  61. ClassDebugExternal4 = 13, // set bit 0x10000000 in ClassDebug
  62. ClassDebugExternal3 = 14, // set bit 0x20000000 in ClassDebug
  63. ClassDebugExternal2 = 15, // set bit 0x40000000 in ClassDebug
  64. ClassDebugExternal1 = 16 // set bit 0x80000000 in ClassDebug
  65. } CLASS_DEBUG_LEVEL, *PCLASS_DEBUG_LEVEL;
  66. #if DBG
  67. #define DebugPrint(x) ClassDebugPrint x
  68. #else
  69. #define DebugPrint(x)
  70. #endif // DBG
  71. #define DEBUG_BUFFER_LENGTH 256
  72. //
  73. // Define our private SRB flags. The high nibble of the flag field is
  74. // reserved for class drivers's private use.
  75. //
  76. //
  77. // Used to indicate that this request shouldn't invoke any power type operations
  78. // like spinning up the drive.
  79. //
  80. #define SRB_CLASS_FLAGS_LOW_PRIORITY 0x10000000
  81. //
  82. // Used to indicate that the completion routine should not free the srb.
  83. //
  84. #define SRB_CLASS_FLAGS_PERSISTANT 0x20000000
  85. //
  86. // Used to indicate that an SRB is the result of a paging operation.
  87. //
  88. #define SRB_CLASS_FLAGS_PAGING 0x40000000
  89. //
  90. // Random macros which should probably be in the system header files
  91. // somewhere.
  92. //
  93. #define max(a,b) (((a) > (b)) ? (a) : (b))
  94. #define min(a,b) (((a) < (b)) ? (a) : (b))
  95. //
  96. // Bit Flag Macros
  97. //
  98. #define SET_FLAG(Flags, Bit) ((Flags) |= (Bit))
  99. #define CLEAR_FLAG(Flags, Bit) ((Flags) &= ~(Bit))
  100. #define TEST_FLAG(Flags, Bit) (((Flags) & (Bit)) != 0)
  101. //
  102. // neat little hacks to count number of bits set efficiently
  103. //
  104. __inline ULONG CountOfSetBitsUChar(UCHAR _X)
  105. { ULONG i = 0; while (_X) { _X &= _X - 1; i++; } return i; }
  106. __inline ULONG CountOfSetBitsULong(ULONG _X)
  107. { ULONG i = 0; while (_X) { _X &= _X - 1; i++; } return i; }
  108. __inline ULONG CountOfSetBitsULong32(ULONG32 _X)
  109. { ULONG i = 0; while (_X) { _X &= _X - 1; i++; } return i; }
  110. __inline ULONG CountOfSetBitsULong64(ULONG64 _X)
  111. { ULONG i = 0; while (_X) { _X &= _X - 1; i++; } return i; }
  112. __inline ULONG CountOfSetBitsUlongPtr(ULONG_PTR _X)
  113. { ULONG i = 0; while (_X) { _X &= _X - 1; i++; } return i; }
  114. //
  115. // Helper macros to verify data types and cleanup the code.
  116. //
  117. #define ASSERT_FDO(x) \
  118. ASSERT(((PCOMMON_DEVICE_EXTENSION) (x)->DeviceExtension)->IsFdo)
  119. #define ASSERT_PDO(x) \
  120. ASSERT(!(((PCOMMON_DEVICE_EXTENSION) (x)->DeviceExtension)->IsFdo))
  121. #define IS_CLEANUP_REQUEST(majorFunction) \
  122. ((majorFunction == IRP_MJ_CLOSE) || \
  123. (majorFunction == IRP_MJ_CLEANUP) || \
  124. (majorFunction == IRP_MJ_SHUTDOWN))
  125. #define DO_MCD(fdoExtension) \
  126. (((fdoExtension)->MediaChangeDetectionInfo != NULL) && \
  127. ((fdoExtension)->MediaChangeDetectionInfo->MediaChangeDetectionDisableCount == 0))
  128. #ifdef POOL_TAGGING
  129. #undef ExAllocatePool
  130. #undef ExAllocatePoolWithQuota
  131. #define ExAllocatePool(a,b) ExAllocatePoolWithTag(a,b,'nUcS')
  132. //#define ExAllocatePool(a,b) #assert(0)
  133. #define ExAllocatePoolWithQuota(a,b) ExAllocatePoolWithQuotaTag(a,b,'nUcS')
  134. #endif
  135. #define CLASS_TAG_AUTORUN_DISABLE 'ALcS'
  136. #define CLASS_TAG_FILE_OBJECT_EXTENSION 'FLcS'
  137. #define CLASS_TAG_MEDIA_CHANGE_DETECTION 'MLcS'
  138. #define CLASS_TAG_MOUNT 'mLcS'
  139. #define CLASS_TAG_RELEASE_QUEUE 'qLcS'
  140. #define CLASS_TAG_POWER 'WLcS'
  141. #define CLASS_TAG_WMI 'wLcS'
  142. #define CLASS_TAG_FAILURE_PREDICT 'fLcS'
  143. #define CLASS_TAG_DEVICE_CONTROL 'OIcS'
  144. #define MAXIMUM_RETRIES 4
  145. #define CLASS_DRIVER_EXTENSION_KEY ((PVOID) ClassInitialize)
  146. struct _CLASS_INIT_DATA;
  147. typedef struct _CLASS_INIT_DATA
  148. CLASS_INIT_DATA,
  149. *PCLASS_INIT_DATA;
  150. //
  151. // our first attempt at keeping private data actually private....
  152. //
  153. struct _CLASS_PRIVATE_FDO_DATA;
  154. typedef struct _CLASS_PRIVATE_FDO_DATA
  155. CLASS_PRIVATE_FDO_DATA,
  156. *PCLASS_PRIVATE_FDO_DATA;
  157. struct _CLASS_PRIVATE_PDO_DATA;
  158. typedef struct _CLASS_PRIVATE_PDO_DATA
  159. CLASS_PRIVATE_PDO_DATA,
  160. *PCLASS_PRIVATE_PDO_DATA;
  161. struct _CLASS_PRIVATE_COMMON_DATA;
  162. typedef struct _CLASS_PRIVATE_COMMON_DATA
  163. CLASS_PRIVATE_COMMON_DATA,
  164. *PCLASS_PRIVATE_COMMON_DATA;
  165. //
  166. // Possible values for the IsRemoved flag
  167. //
  168. #define NO_REMOVE 0
  169. #define REMOVE_PENDING 1
  170. #define REMOVE_COMPLETE 2
  171. #define ClassAcquireRemoveLock(devobj, tag) \
  172. ClassAcquireRemoveLockEx(devobj, tag, __FILE__, __LINE__)
  173. //
  174. // Define start unit timeout to be 4 minutes.
  175. //
  176. #define START_UNIT_TIMEOUT (60 * 4)
  177. //
  178. // Define media change test time to be 1 second for quicker response
  179. #define MEDIA_CHANGE_DEFAULT_TIME 1
  180. #ifdef DBG
  181. //
  182. // Used to detect the loss of the autorun irp. The driver prints out a message
  183. // (debug level 0) if this timeout ever occurs
  184. //
  185. #define MEDIA_CHANGE_TIMEOUT_TIME 300
  186. #endif
  187. //
  188. // Define the various states that media can be in for autorun.
  189. //
  190. typedef enum _MEDIA_CHANGE_DETECTION_STATE {
  191. MediaUnknown,
  192. MediaPresent,
  193. MediaNotPresent,
  194. MediaUnavailable // e.g. cd-r media undergoing burn
  195. } MEDIA_CHANGE_DETECTION_STATE, *PMEDIA_CHANGE_DETECTION_STATE;
  196. struct _MEDIA_CHANGE_DETECTION_INFO;
  197. typedef struct _MEDIA_CHANGE_DETECTION_INFO
  198. MEDIA_CHANGE_DETECTION_INFO, *PMEDIA_CHANGE_DETECTION_INFO;
  199. //
  200. // Structures for maintaining a dictionary list (list of objects
  201. // referenced by a key value)
  202. //
  203. struct _DICTIONARY_HEADER;
  204. typedef struct _DICTIONARY_HEADER DICTIONARY_HEADER, *PDICTIONARY_HEADER;
  205. typedef struct _DICTIONARY {
  206. ULONGLONG Signature;
  207. PDICTIONARY_HEADER List;
  208. KSPIN_LOCK SpinLock;
  209. } DICTIONARY, *PDICTIONARY;
  210. //
  211. // structures to simplify matching devices, ids, and hacks required for
  212. // these ids.
  213. //
  214. typedef struct _CLASSPNP_SCAN_FOR_SPECIAL_INFO {
  215. //
  216. // * NULL pointers indicates that no match is required.
  217. // * empty string will only match an empty string. non-existant strings
  218. // in the device descriptor are considered empty strings for this match.
  219. // (ie. "" will only match "")
  220. // * all other strings will do partial matches, based upon
  221. // string provided (ie. "hi" will match "hitazen" and "higazui")
  222. // * array must end with all three PCHARs being set to NULL.
  223. //
  224. PCHAR VendorId;
  225. PCHAR ProductId;
  226. PCHAR ProductRevision;
  227. //
  228. // marked as a ULONG_PTR to allow use as either a ptr to a data block
  229. // or 32 bits worth of flags. (64 bits on 64 bit systems) no longer a
  230. // const so that it may be dynamically built.
  231. //
  232. ULONG_PTR Data;
  233. } CLASSPNP_SCAN_FOR_SPECIAL_INFO, *PCLASSPNP_SCAN_FOR_SPECIAL_INFO;
  234. #ifdef ALLOCATE_SRB_FROM_POOL
  235. #define ClasspAllocateSrb(ext)
  236. ExAllocatePoolWithTag(NonPagedPool, \
  237. sizeof(SCSI_REQUEST_BLOCK), \
  238. 'sBRS')
  239. #define ClasspFreeSrb(ext, srb) ExFreePool((srb));
  240. #else
  241. #define ClasspAllocateSrb(ext) \
  242. ExAllocateFromNPagedLookasideList( \
  243. &((ext)->CommonExtension.SrbLookasideList))
  244. #define ClasspFreeSrb(ext, srb) \
  245. ExFreeToNPagedLookasideList( \
  246. &((ext)->CommonExtension.SrbLookasideList), \
  247. (srb))
  248. #endif
  249. /*++////////////////////////////////////////////////////////////////////////////
  250. PCLASS_ERROR()
  251. Routine Description:
  252. This routine is a callback into the driver to handle errors. The queue
  253. shall not be unfrozen when this error handler is called, even though the
  254. SRB flags may mark the queue as having been frozen due to this SRB.
  255. Irql:
  256. This routine will be called at KIRQL <= DISPATCH_LEVEL
  257. Arguments:
  258. DeviceObject is the device object the error occurred on.
  259. Srb is the Srb that was being processed when the error occurred.
  260. Status may be overwritten by the routine if it decides that the error
  261. was benign, or otherwise wishes to change the returned status code
  262. for this command
  263. Retry may be overwritten to specify that this command should or should
  264. not be retried (if the callee supports retrying commands)
  265. Return Value:
  266. status
  267. --*/
  268. typedef
  269. VOID
  270. (*PCLASS_ERROR) (
  271. IN PDEVICE_OBJECT DeviceObject,
  272. IN PSCSI_REQUEST_BLOCK Srb,
  273. OUT NTSTATUS *Status,
  274. IN OUT BOOLEAN *Retry
  275. );
  276. /*++////////////////////////////////////////////////////////////////////////////
  277. PCLASS_ADD_DEVICE()
  278. Routine Description:
  279. This routine is a callback into the driver to create and initialize a new
  280. FDO for the corresponding PDO. It may perform property queries on the PDO
  281. but cannot do any media access operations.
  282. Irql:
  283. This routine will be called at PASSIVE_LEVEL.
  284. Its code may be safely paged.
  285. Arguments:
  286. DriverObject is the class driver object this callback is registered for.
  287. PDO is the physical device object being added to.
  288. Return Value:
  289. status
  290. --*/
  291. typedef
  292. NTSTATUS
  293. (*PCLASS_ADD_DEVICE) (
  294. IN PDRIVER_OBJECT DriverObject,
  295. IN PDEVICE_OBJECT Pdo
  296. );
  297. /*++////////////////////////////////////////////////////////////////////////////
  298. CLASS_POWER_DEVICE()
  299. Routine Description:
  300. This routine is a callback into the driver to handle power up and
  301. power down requests. Most drivers can set this to ClassPowerHandler,
  302. which will send a STOP_UNIT on powerdown, and a START_UNIT on powerup.
  303. ClassMinimalPowerHandler() may also be used to do nothing for power
  304. operations (except succeed them). Please see the DDK for proper handling
  305. of IRP_MN_DEVICE_USAGE_NOTIFICATION for details regarding interaction
  306. of paging device notifications and the IRQL at which this routine will
  307. be called.
  308. Irql:
  309. This routine will be called at PASSIVE_LEVEL if DO_POWER_PAGABLE is set.
  310. This code should NOT be pagable to prevent race conditions during the
  311. setting and clearing of the DO_POWER_PAGABLE bit.
  312. Arguments:
  313. DeviceObject is the device that has the pending power request
  314. Irp is the power irp that needs to be handled
  315. Return Value:
  316. status
  317. --*/
  318. typedef
  319. NTSTATUS
  320. (*PCLASS_POWER_DEVICE) (
  321. IN PDEVICE_OBJECT DeviceObject,
  322. IN PIRP Irp
  323. );
  324. /*++////////////////////////////////////////////////////////////////////////////
  325. CLASS_START_DEVICE()
  326. Routine Description:
  327. This routine is a callback into the driver to initialize the FDO or PDO for
  328. all requests, typically due to a IRP_MN_START_DEVICE.
  329. Irql:
  330. This routine will be called at PASSIVE_LEVEL.
  331. Its code may be safely paged.
  332. Arguments:
  333. DeviceObject is the device object being started
  334. Return Value:
  335. status
  336. --*/
  337. typedef
  338. NTSTATUS
  339. (*PCLASS_START_DEVICE) (
  340. IN PDEVICE_OBJECT DeviceObject
  341. );
  342. /*++////////////////////////////////////////////////////////////////////////////
  343. CLASS_STOP_DEVICE()
  344. Routine Description:
  345. This routine is a callback into the driver to stop the device.
  346. For the storage stack, unless there are known issues, this routine
  347. need only return. All queueing shall be handled by the lower device
  348. drivers.
  349. Irql:
  350. This routine will be called at PASSIVE_LEVEL.
  351. Its code may be safely paged.
  352. Arguments:
  353. DeviceObject is the device object being stopped/query stopped.
  354. Type is the IRP_MN_ type that must be handled.
  355. Return Value:
  356. status
  357. --*/
  358. typedef
  359. NTSTATUS
  360. (*PCLASS_STOP_DEVICE) (
  361. IN PDEVICE_OBJECT DeviceObject,
  362. IN UCHAR Type
  363. );
  364. /*++////////////////////////////////////////////////////////////////////////////
  365. CLASS_INIT_DEVICE()
  366. Routine Description:
  367. This routine is a callback into the driver to do one-time initialization
  368. of new device objects. It shall be called exactly once per device object,
  369. and it shall be called prior to CLASS_START_DEVICE() routine.
  370. Irql:
  371. This routine will be called at PASSIVE_LEVEL.
  372. Its code may be safely paged.
  373. Arguments:
  374. DeviceObject is the device object to be initialized
  375. Return Value:
  376. status
  377. --*/
  378. typedef
  379. NTSTATUS
  380. (*PCLASS_INIT_DEVICE) (
  381. IN PDEVICE_OBJECT DeviceObject
  382. );
  383. /*++////////////////////////////////////////////////////////////////////////////
  384. CLASS_ENUM_DEVICE()
  385. Routine Description:
  386. This routine is a callback into the driver to update the list of PDOs for
  387. a given FDO. See DISK.SYS's DiskEnumerateDevice for an example of use.
  388. Irql:
  389. This routine will be called at PASSIVE_LEVEL.
  390. Its code may be safely paged.
  391. Arguments:
  392. DeviceObject is the FDO which is being enumerated.
  393. Return Value:
  394. status
  395. --*/
  396. typedef
  397. NTSTATUS
  398. (*PCLASS_ENUM_DEVICE) (
  399. IN PDEVICE_OBJECT DeviceObject
  400. );
  401. /*++////////////////////////////////////////////////////////////////////////////
  402. PCLASS_READ_WRITE()
  403. Routine Description:
  404. This routine is a callback into the driver to verify READ and WRITE irps.
  405. If the READ or WRITE request is failed, this routine shall set the Irp's
  406. IoStatus.Status to the returned error code and the IoStatus.Information
  407. field as appropriate for the given error.
  408. Irql:
  409. This routine will be called at KIRQL <= DISPATCH_LEVEL
  410. Arguments:
  411. DeviceObject is the device object being read from or written to
  412. Irp is the read or write request being processed
  413. Return Value:
  414. status
  415. --*/
  416. typedef
  417. NTSTATUS
  418. (*PCLASS_READ_WRITE) (
  419. IN PDEVICE_OBJECT DeviceObject,
  420. IN PIRP Irp
  421. );
  422. /*++////////////////////////////////////////////////////////////////////////////
  423. PCLASS_DEVICE_CONTROL()
  424. Routine Description:
  425. This routine is a callback into the driver to
  426. Irql:
  427. This routine will only be called at PASSIVE_LEVEL for storage IOCTLs.
  428. The code must therefore not be paged, but may call paged code for those
  429. ioctls which have been defined to be sent at PASSIVE_LEVEL, such as the
  430. storage IOCTLS. Otherwise KIRQL <= DISPATCH_LEVEL.
  431. Arguments:
  432. DeviceObject is the device object the IOCTL may be for
  433. Irp is the IOCTL request currently being processed
  434. Return Value:
  435. status
  436. --*/
  437. typedef
  438. NTSTATUS
  439. (*PCLASS_DEVICE_CONTROL) (
  440. IN PDEVICE_OBJECT DeviceObject,
  441. IN PIRP Irp
  442. );
  443. /*++////////////////////////////////////////////////////////////////////////////
  444. PCLASS_SHUTDOWN_FLUSH()
  445. Routine Description:
  446. This routine is a callback into the driver to handle shutdown and flush
  447. irps. These are sent by the system before it actually shuts down or when
  448. the file system does a flush.
  449. This routine may synchronize the device's media / cache and ensure the
  450. device is not locked if the system is in the process of shutting down.
  451. Irql:
  452. This routine will be called at KIRQL <= DISPATCH_LEVEL
  453. Arguments:
  454. DeviceObject is the device object that needs to be flushed
  455. Irp is the shutdown or flush request currently being processed
  456. Return Value:
  457. status
  458. --*/
  459. typedef
  460. NTSTATUS
  461. (*PCLASS_SHUTDOWN_FLUSH) (
  462. IN PDEVICE_OBJECT DeviceObject,
  463. IN PIRP Irp
  464. );
  465. /*++////////////////////////////////////////////////////////////////////////////
  466. PCLASS_CREATE_CLOSE()
  467. Routine Description:
  468. This routine is a callback into the driver when the device is opened or
  469. closed.
  470. Irql:
  471. This routine will be called at PASSIVE_LEVEL.
  472. Its code may be safely paged.
  473. Arguments:
  474. DeviceObject that is handling the request
  475. Irp is the create or close request currently being processed
  476. Return Value:
  477. status
  478. --*/
  479. typedef
  480. NTSTATUS
  481. (*PCLASS_CREATE_CLOSE) (
  482. IN PDEVICE_OBJECT DeviceObject,
  483. IN PIRP Irp
  484. );
  485. /*++////////////////////////////////////////////////////////////////////////////
  486. PCLASS_QUERY_ID()
  487. Routine Description:
  488. This routine generates the PNP id's for the device's enumerated PDOs.
  489. If the specified ID is one that cannot be generated, then the return
  490. status shall be STATUS_NOT_IMPLEMENTED so that classpnp shall not
  491. handle the request. This routine shall allocate the buffer in the unicode
  492. string "IdString" upon success; it is the caller's responsibility to free
  493. this buffer when it is done.
  494. Irql:
  495. This routine will be called at PASSIVE_LEVEL.
  496. Its code may be safely paged.
  497. Arguments:
  498. DeviceObject is the PDO to generate an ID for
  499. IdType is the type of ID to be generated
  500. UnicodeIdString is the string to place the results into
  501. Return Value:
  502. status
  503. --*/
  504. typedef
  505. NTSTATUS
  506. (*PCLASS_QUERY_ID) (
  507. IN PDEVICE_OBJECT DeviceObject,
  508. IN BUS_QUERY_ID_TYPE IdType,
  509. IN PUNICODE_STRING IdString
  510. );
  511. /*++////////////////////////////////////////////////////////////////////////////
  512. PCLASS_REMOVE_DEVICE()
  513. Routine Description:
  514. This routine is a callback into the driver to release any resources the
  515. device may have allocated for the device object.
  516. Irql:
  517. This routine will be called at PASSIVE_LEVEL.
  518. Its code may be safely paged.
  519. Arguments:
  520. DeviceObject is the device object being removed/query removed/etc.
  521. Return Value:
  522. status
  523. --*/
  524. typedef
  525. NTSTATUS
  526. (*PCLASS_REMOVE_DEVICE) (
  527. IN PDEVICE_OBJECT DeviceObject,
  528. IN UCHAR Type
  529. );
  530. /*++////////////////////////////////////////////////////////////////////////////
  531. PCLASS_UNLOAD()
  532. Routine Description:
  533. This routine is a callback into the driver to unload itself. It must free
  534. any resources allocated in the DriverEntry portion of the driver.
  535. Irql:
  536. This routine will be called at PASSIVE_LEVEL.
  537. Its code may be safely paged.
  538. Arguments:
  539. X
  540. Irp is the IOCTL request currently being processed
  541. Return Value:
  542. status
  543. --*/
  544. typedef
  545. VOID
  546. (*PCLASS_UNLOAD) (
  547. IN PDRIVER_OBJECT DriverObject
  548. );
  549. /*++////////////////////////////////////////////////////////////////////////////
  550. PCLASS_QUERY_PNP_CAPABILITIES()
  551. Routine Description:
  552. ISSUE-2000/02/18-henrygab - description required
  553. Irql:
  554. This routine will be called at PASSIVE_LEVEL.
  555. Its code may be safely paged.
  556. Arguments:
  557. PhysicalDeviceObject is the PDO for which this query shall occur
  558. Capabilities is a structure that shall be modified by this routine
  559. to report the device's capabilities.
  560. Return Value:
  561. status
  562. --*/
  563. typedef
  564. NTSTATUS
  565. (*PCLASS_QUERY_PNP_CAPABILITIES) (
  566. IN PDEVICE_OBJECT PhysicalDeviceObject,
  567. IN PDEVICE_CAPABILITIES Capabilities
  568. );
  569. /*++////////////////////////////////////////////////////////////////////////////
  570. PCLASS_TICK()
  571. Routine Description:
  572. This routine is a callback into the driver that is called once per second.
  573. Irql:
  574. This routine will be called at DISPATCH_LEVEL
  575. Arguments:
  576. DeviceObject is the device object for which the timer has fired
  577. Return Value:
  578. status
  579. --*/
  580. typedef
  581. VOID
  582. (*PCLASS_TICK) (
  583. IN PDEVICE_OBJECT DeviceObject
  584. );
  585. /*++////////////////////////////////////////////////////////////////////////////
  586. PCLASS_QUERY_WMI_REGINFO_EX()
  587. Routine Description:
  588. This routine is a callback into the driver to retrieve information about
  589. the guids being registered.
  590. Irql:
  591. This routine will be called at PASSIVE_LEVEL.
  592. Its code may be safely paged.
  593. Arguments:
  594. DeviceObject is the device whose registration information is needed
  595. *RegFlags returns with a set of flags that describe the guids being
  596. registered for this device. If the device wants enable and disable
  597. collection callbacks before receiving queries for the registered
  598. guids then it should return the WMIREG_FLAG_EXPENSIVE flag. Also the
  599. returned flags may specify WMIREG_FLAG_INSTANCE_PDO in which case
  600. the instance name is determined from the PDO associated with the
  601. device object. Note that the PDO must have an associated devnode. If
  602. WMIREG_FLAG_INSTANCE_PDO is not set then Name must return a unique
  603. name for the device.
  604. Name returns with the instance name for the guids if
  605. WMIREG_FLAG_INSTANCE_PDO is not set in the returned *RegFlags. The
  606. caller will call ExFreePool with the buffer returned.
  607. MofResourceName returns filled with a static string that contains
  608. the name of the MOF resource attached to the drivers image. The
  609. caller does not free the buffer as it is expected that the
  610. caller will use RtlInitializeUnicodeString to populate it.
  611. Return Value:
  612. status
  613. --*/
  614. typedef
  615. NTSTATUS
  616. (*PCLASS_QUERY_WMI_REGINFO_EX) (
  617. IN PDEVICE_OBJECT DeviceObject,
  618. OUT ULONG *RegFlags,
  619. OUT PUNICODE_STRING Name,
  620. OUT PUNICODE_STRING MofResouceName
  621. );
  622. /*++////////////////////////////////////////////////////////////////////////////
  623. PCLASS_QUERY_WMI_REGINFO()
  624. Routine Description:
  625. This routine is a callback into the driver to retrieve information about
  626. the guids being registered.
  627. Irql:
  628. This routine will be called at PASSIVE_LEVEL.
  629. Its code may be safely paged.
  630. Arguments:
  631. DeviceObject is the device whose registration information is needed
  632. *RegFlags returns with a set of flags that describe the guids being
  633. registered for this device. If the device wants enable and disable
  634. collection callbacks before receiving queries for the registered
  635. guids then it should return the WMIREG_FLAG_EXPENSIVE flag. Also the
  636. returned flags may specify WMIREG_FLAG_INSTANCE_PDO in which case
  637. the instance name is determined from the PDO associated with the
  638. device object. Note that the PDO must have an associated devnode. If
  639. WMIREG_FLAG_INSTANCE_PDO is not set then Name must return a unique
  640. name for the device.
  641. Name returns with the instance name for the guids if
  642. WMIREG_FLAG_INSTANCE_PDO is not set in the returned *RegFlags. The
  643. caller will call ExFreePool with the buffer returned.
  644. Return Value:
  645. status
  646. --*/
  647. typedef
  648. NTSTATUS
  649. (*PCLASS_QUERY_WMI_REGINFO) (
  650. IN PDEVICE_OBJECT DeviceObject,
  651. OUT ULONG *RegFlags,
  652. OUT PUNICODE_STRING Name
  653. );
  654. /*++////////////////////////////////////////////////////////////////////////////
  655. PCLASS_QUERY_WMI_DATABLOCK()
  656. Routine Description:
  657. This routine is a callback into the driver to query for the contents of
  658. a data block. When the driver has finished filling the data block it
  659. must call ClassWmiCompleteRequest to complete the irp. The driver can
  660. return STATUS_PENDING if the irp cannot be completed immediately.
  661. Irql:
  662. This routine will be called at PASSIVE_LEVEL.
  663. Its code may be safely paged.
  664. Arguments:
  665. DeviceObject is the device whose data block is being queried
  666. Irp is the Irp that makes this request
  667. GuidIndex is the index into the list of guids provided when the
  668. device registered
  669. BufferAvail on has the maximum size available to write the data
  670. block.
  671. Buffer on return is filled with the returned data block
  672. Return Value:
  673. status
  674. --*/
  675. typedef
  676. NTSTATUS
  677. (*PCLASS_QUERY_WMI_DATABLOCK) (
  678. IN PDEVICE_OBJECT DeviceObject,
  679. IN PIRP Irp,
  680. IN ULONG GuidIndex,
  681. IN ULONG BufferAvail,
  682. OUT PUCHAR Buffer
  683. );
  684. /*++////////////////////////////////////////////////////////////////////////////
  685. PCLASS_SET_WMI_DATABLOCK()
  686. Routine Description:
  687. This routine is a callback into the driver to query for the contents of
  688. a data block. When the driver has finished filling the data block it
  689. must call ClassWmiCompleteRequest to complete the irp. The driver can
  690. return STATUS_PENDING if the irp cannot be completed immediately.
  691. Irql:
  692. This routine will be called at PASSIVE_LEVEL.
  693. Its code may be safely paged.
  694. Arguments:
  695. DeviceObject is the device whose data block is being queried
  696. Irp is the Irp that makes this request
  697. GuidIndex is the index into the list of guids provided when the
  698. device registered
  699. BufferSize has the size of the data block passed
  700. Buffer has the new values for the data block
  701. Return Value:
  702. status
  703. --*/
  704. typedef
  705. NTSTATUS
  706. (*PCLASS_SET_WMI_DATABLOCK) (
  707. IN PDEVICE_OBJECT DeviceObject,
  708. IN PIRP Irp,
  709. IN ULONG GuidIndex,
  710. IN ULONG BufferSize,
  711. IN PUCHAR Buffer
  712. );
  713. /*++////////////////////////////////////////////////////////////////////////////
  714. PCLASS_SET_WMI_DATAITEM()
  715. Routine Description:
  716. This routine is a callback into the driver to query for the contents of
  717. a data block. When the driver has finished filling the data block it
  718. must call ClassWmiCompleteRequest to complete the irp. The driver can
  719. return STATUS_PENDING if the irp cannot be completed immediately.
  720. Irql:
  721. This routine will be called at PASSIVE_LEVEL.
  722. Its code may be safely paged.
  723. Arguments:
  724. DeviceObject is the device whose data block is being queried
  725. Irp is the Irp that makes this request
  726. GuidIndex is the index into the list of guids provided when the
  727. device registered
  728. DataItemId has the id of the data item being set
  729. BufferSize has the size of the data item passed
  730. Buffer has the new values for the data item
  731. Return Value:
  732. status
  733. --*/
  734. typedef
  735. NTSTATUS
  736. (*PCLASS_SET_WMI_DATAITEM) (
  737. IN PDEVICE_OBJECT DeviceObject,
  738. IN PIRP Irp,
  739. IN ULONG GuidIndex,
  740. IN ULONG DataItemId,
  741. IN ULONG BufferSize,
  742. IN PUCHAR Buffer
  743. );
  744. /*++////////////////////////////////////////////////////////////////////////////
  745. PCLASS_EXECUTE_WMI_METHOD()
  746. Routine Description:
  747. This routine is a callback into the driver to execute a method. When the
  748. driver has finished filling the data block it must call
  749. ClassWmiCompleteRequest to complete the irp. The driver can
  750. return STATUS_PENDING if the irp cannot be completed immediately.
  751. Irql:
  752. This routine will be called at PASSIVE_LEVEL.
  753. Its code may be safely paged.
  754. Arguments:
  755. DeviceObject is the device whose data block is being queried
  756. Irp is the Irp that makes this request
  757. GuidIndex is the index into the list of guids provided when the
  758. device registered
  759. MethodId has the id of the method being called
  760. InBufferSize has the size of the data block passed in as the input to
  761. the method.
  762. OutBufferSize on entry has the maximum size available to write the
  763. returned data block.
  764. Buffer is filled with the returned data block
  765. Return Value:
  766. status
  767. --*/
  768. typedef
  769. NTSTATUS
  770. (*PCLASS_EXECUTE_WMI_METHOD) (
  771. IN PDEVICE_OBJECT DeviceObject,
  772. IN PIRP Irp,
  773. IN ULONG GuidIndex,
  774. IN ULONG MethodId,
  775. IN ULONG InBufferSize,
  776. IN ULONG OutBufferSize,
  777. IN PUCHAR Buffer
  778. );
  779. //
  780. // used by PCLASS_WMI_FUNCTION_CONTROL
  781. //
  782. typedef enum {
  783. EventGeneration,
  784. DataBlockCollection
  785. } CLASSENABLEDISABLEFUNCTION;
  786. /*++////////////////////////////////////////////////////////////////////////////
  787. PCLASS_WMI_FUNCTION_CONTROL()
  788. Routine Description:
  789. This routine is a callback into the driver to enabled or disable event
  790. generation or data block collection. A device should only expect a
  791. single enable when the first event or data consumer enables events or
  792. data collection and a single disable when the last event or data
  793. consumer disables events or data collection. Data blocks will only
  794. receive collection enable/disable if they were registered as requiring
  795. it.
  796. Irql:
  797. This routine will be called at PASSIVE_LEVEL.
  798. Its code may be safely paged.
  799. Arguments:
  800. DeviceObject is the device whose data block is being queried
  801. GuidIndex is the index into the list of guids provided when the
  802. device registered
  803. Function specifies which functionality is being enabled or disabled
  804. Enable is TRUE then the function is being enabled else disabled
  805. Return Value:
  806. status
  807. --*/
  808. typedef
  809. NTSTATUS
  810. (*PCLASS_WMI_FUNCTION_CONTROL) (
  811. IN PDEVICE_OBJECT DeviceObject,
  812. IN PIRP Irp,
  813. IN ULONG GuidIndex,
  814. IN CLASSENABLEDISABLEFUNCTION Function,
  815. IN BOOLEAN Enable
  816. );
  817. //
  818. // Restricted - May only append to this structure for backwards compatibility
  819. //
  820. typedef struct {
  821. GUID Guid; // Guid to registered
  822. ULONG InstanceCount; // Count of Instances of Datablock
  823. ULONG Flags; // Additional flags (see WMIREGINFO in wmistr.h)
  824. } GUIDREGINFO, *PGUIDREGINFO;
  825. //
  826. // Restricted - May only append to this structure for backwards compatibility
  827. //
  828. typedef struct _CLASS_WMI_INFO {
  829. ULONG GuidCount;
  830. PGUIDREGINFO GuidRegInfo;
  831. PCLASS_QUERY_WMI_REGINFO ClassQueryWmiRegInfo;
  832. PCLASS_QUERY_WMI_DATABLOCK ClassQueryWmiDataBlock;
  833. PCLASS_SET_WMI_DATABLOCK ClassSetWmiDataBlock;
  834. PCLASS_SET_WMI_DATAITEM ClassSetWmiDataItem;
  835. PCLASS_EXECUTE_WMI_METHOD ClassExecuteWmiMethod;
  836. PCLASS_WMI_FUNCTION_CONTROL ClassWmiFunctionControl;
  837. } CLASS_WMI_INFO, *PCLASS_WMI_INFO;
  838. //
  839. // Restricted - May only append to this structure for backwards compatibility
  840. //
  841. typedef struct _CLASS_DEV_INFO {
  842. //
  843. // Bytes needed by the class driver
  844. // for it's extension.
  845. // If this is zero, the driver does not expect to have any PDO's
  846. //
  847. ULONG DeviceExtensionSize;
  848. DEVICE_TYPE DeviceType;
  849. UCHAR StackSize;
  850. //
  851. // Device Characteristics flags
  852. // eg.:
  853. //
  854. // FILE_REMOVABLE_MEDIA
  855. // FILE_READ_ONLY_DEVICE
  856. // FILE_FLOPPY_DISKETTE
  857. // FILE_WRITE_ONCE_MEDIA
  858. // FILE_REMOTE_DEVICE
  859. // FILE_DEVICE_IS_MOUNTED
  860. // FILE_VIRTUAL_VOLUME
  861. //
  862. ULONG DeviceCharacteristics;
  863. PCLASS_ERROR ClassError;
  864. PCLASS_READ_WRITE ClassReadWriteVerification;
  865. PCLASS_DEVICE_CONTROL ClassDeviceControl;
  866. PCLASS_SHUTDOWN_FLUSH ClassShutdownFlush;
  867. PCLASS_CREATE_CLOSE ClassCreateClose;
  868. PCLASS_INIT_DEVICE ClassInitDevice;
  869. PCLASS_START_DEVICE ClassStartDevice;
  870. PCLASS_POWER_DEVICE ClassPowerDevice;
  871. PCLASS_STOP_DEVICE ClassStopDevice;
  872. PCLASS_REMOVE_DEVICE ClassRemoveDevice;
  873. PCLASS_QUERY_PNP_CAPABILITIES ClassQueryPnpCapabilities;
  874. //
  875. // Registered Data Block info for wmi
  876. //
  877. CLASS_WMI_INFO ClassWmiInfo;
  878. } CLASS_DEV_INFO, *PCLASS_DEV_INFO;
  879. //
  880. // Restricted - May only append to this structure for backwards compatibility
  881. //
  882. struct _CLASS_INIT_DATA {
  883. //
  884. // This structure size - version checking.
  885. //
  886. ULONG InitializationDataSize;
  887. //
  888. // Specific init data for functional and physical device objects.
  889. //
  890. CLASS_DEV_INFO FdoData;
  891. CLASS_DEV_INFO PdoData;
  892. //
  893. // Device-specific driver routines
  894. //
  895. PCLASS_ADD_DEVICE ClassAddDevice;
  896. PCLASS_ENUM_DEVICE ClassEnumerateDevice;
  897. PCLASS_QUERY_ID ClassQueryId;
  898. PDRIVER_STARTIO ClassStartIo;
  899. PCLASS_UNLOAD ClassUnload;
  900. PCLASS_TICK ClassTick;
  901. };
  902. //
  903. // this is a private structure, but must be kept here
  904. // to properly compile size of FUNCTIONAL_DEVICE_EXTENSION
  905. //
  906. typedef struct _FILE_OBJECT_EXTENSION {
  907. PFILE_OBJECT FileObject;
  908. PDEVICE_OBJECT DeviceObject;
  909. ULONG LockCount;
  910. ULONG McnDisableCount;
  911. } FILE_OBJECT_EXTENSION, *PFILE_OBJECT_EXTENSION;
  912. //
  913. // Restricted - May only append to this structure for backwards compatibility
  914. //
  915. typedef struct _CLASS_DRIVER_EXTENSION {
  916. UNICODE_STRING RegistryPath;
  917. CLASS_INIT_DATA InitData;
  918. ULONG DeviceCount;
  919. PCLASS_QUERY_WMI_REGINFO_EX ClassFdoQueryWmiRegInfoEx;
  920. PCLASS_QUERY_WMI_REGINFO_EX ClassPdoQueryWmiRegInfoEx;
  921. } CLASS_DRIVER_EXTENSION, *PCLASS_DRIVER_EXTENSION;
  922. typedef struct _COMMON_DEVICE_EXTENSION COMMON_DEVICE_EXTENSION, *PCOMMON_DEVICE_EXTENSION;
  923. typedef struct _FUNCTIONAL_DEVICE_EXTENSION FUNCTIONAL_DEVICE_EXTENSION, *PFUNCTIONAL_DEVICE_EXTENSION;
  924. typedef struct _PHYSICAL_DEVICE_EXTENSION PHYSICAL_DEVICE_EXTENSION, *PPHYSICAL_DEVICE_EXTENSION;
  925. //
  926. // Restricted - May only append to this structure for backwards compatibility
  927. //
  928. typedef struct _COMMON_DEVICE_EXTENSION {
  929. //
  930. // Version control field
  931. //
  932. // Note - this MUST be the first thing in the device extension
  933. // for any class driver using classpnp or a later version.
  934. //
  935. ULONG Version;
  936. //
  937. // Back pointer to device object
  938. //
  939. // NOTE - this MUST be the second field in the common device extension.
  940. // Users of this structure will include it in a union with the DeviceObject
  941. // pointer so they can reference this with a bit of syntactic sugar.
  942. //
  943. PDEVICE_OBJECT DeviceObject;
  944. //
  945. // Pointer to lower device object - send all requests through this
  946. //
  947. PDEVICE_OBJECT LowerDeviceObject;
  948. //
  949. // Pointer to the partition zero device extension.
  950. // There are several flags stored there that pdo
  951. // routines need to access
  952. //
  953. PFUNCTIONAL_DEVICE_EXTENSION PartitionZeroExtension;
  954. //
  955. // Pointer to the initialization data for this driver. This is more
  956. // efficient than constantly getting the driver extension.
  957. //
  958. PCLASS_DRIVER_EXTENSION DriverExtension;
  959. //
  960. // INTERLOCKED counter of the number of requests/function calls outstanding
  961. // which will need to use this device object. When this count goes to
  962. // zero the RemoveEvent will be set.
  963. //
  964. // This variable is only manipulated by ClassIncrementRemoveLock and
  965. // ClassDecrementRemoveLock.
  966. //
  967. LONG RemoveLock;
  968. //
  969. // This event will be signalled when it is safe to remove the device object
  970. //
  971. KEVENT RemoveEvent;
  972. //
  973. // The spinlock and the list are only used in checked builds to track
  974. // who has acquired the remove lock. Free systems will leave these
  975. // initialized to ff
  976. //
  977. KSPIN_LOCK RemoveTrackingSpinlock;
  978. PVOID RemoveTrackingList;
  979. LONG RemoveTrackingUntrackedCount;
  980. //
  981. // Pointer to the driver specific data area
  982. //
  983. PVOID DriverData;
  984. //
  985. // Flag indicates whether this device object is
  986. // an FDO or a PDO
  987. //
  988. struct {
  989. BOOLEAN IsFdo : 1;
  990. BOOLEAN IsInitialized : 1;
  991. //
  992. // Flag indicating whether the lookaside listhead for srbs has been
  993. // initialized.
  994. //
  995. BOOLEAN IsSrbLookasideListInitialized : 1;
  996. };
  997. //
  998. // Contains the IRP_MN_CODE of the last state-changing pnp irps we
  999. // recieved (XXX_STOP, XXX_REMOVE, START, etc...). Used in concert
  1000. // with IsRemoved.
  1001. //
  1002. UCHAR PreviousState;
  1003. UCHAR CurrentState;
  1004. //
  1005. // interlocked flag indicating that the device has been removed.
  1006. //
  1007. ULONG IsRemoved;
  1008. //
  1009. // The name of the object
  1010. //
  1011. UNICODE_STRING DeviceName;
  1012. //
  1013. // The next child device (or if this is an FDO, the first child device).
  1014. //
  1015. PPHYSICAL_DEVICE_EXTENSION ChildList;
  1016. //
  1017. // Number of the partition or -1L if not partitionable.
  1018. //
  1019. ULONG PartitionNumber;
  1020. //
  1021. // Length of partition in bytes
  1022. //
  1023. LARGE_INTEGER PartitionLength;
  1024. //
  1025. // Number of bytes before start of partition
  1026. //
  1027. LARGE_INTEGER StartingOffset;
  1028. //
  1029. // Dev-Info structure for this type of device object
  1030. // Contains call-out routines for the class driver.
  1031. //
  1032. PCLASS_DEV_INFO DevInfo;
  1033. //
  1034. // Count of page files going through this device object
  1035. // and event to synchronize them with.
  1036. //
  1037. ULONG PagingPathCount;
  1038. ULONG DumpPathCount;
  1039. ULONG HibernationPathCount;
  1040. KEVENT PathCountEvent;
  1041. #ifndef ALLOCATE_SRB_FROM_POOL
  1042. //
  1043. // Lookaside listhead for srbs.
  1044. //
  1045. NPAGED_LOOKASIDE_LIST SrbLookasideList;
  1046. #endif
  1047. //
  1048. // Interface name string returned by IoRegisterDeviceInterface.
  1049. //
  1050. UNICODE_STRING MountedDeviceInterfaceName;
  1051. //
  1052. // Registered Data Block info for wmi
  1053. //
  1054. ULONG GuidCount;
  1055. PGUIDREGINFO GuidRegInfo;
  1056. //
  1057. // File object dictionary for this device object. Extensions are stored
  1058. // in here rather than off the actual file object.
  1059. //
  1060. DICTIONARY FileObjectDictionary;
  1061. //
  1062. // The following will be in the released product as reserved.
  1063. // Leave these at the end of the structure.
  1064. //
  1065. PCLASS_PRIVATE_COMMON_DATA PrivateCommonData;
  1066. ULONG_PTR Reserved2;
  1067. ULONG_PTR Reserved3;
  1068. ULONG_PTR Reserved4;
  1069. } COMMON_DEVICE_EXTENSION, *PCOMMON_DEVICE_EXTENSION;
  1070. typedef enum {
  1071. FailurePredictionNone = 0, // No failure detection polling needed
  1072. FailurePredictionIoctl, // Do failure detection via IOCTL
  1073. FailurePredictionSmart, // Do failure detection via SMART
  1074. FailurePredictionSense // Do failure detection via sense data
  1075. } FAILURE_PREDICTION_METHOD, *PFAILURE_PREDICTION_METHOD;
  1076. //
  1077. // Default failure prediction polling interval is every hour
  1078. //
  1079. #define DEFAULT_FAILURE_PREDICTION_PERIOD 60 * 60 * 1
  1080. //
  1081. // The failure prediction structure is internal to classpnp - drivers do not
  1082. // need to know what it contains.
  1083. //
  1084. struct _FAILURE_PREDICTION_INFO;
  1085. typedef struct _FAILURE_PREDICTION_INFO *PFAILURE_PREDICTION_INFO;
  1086. //
  1087. // this is to allow for common code to handle
  1088. // every option.
  1089. //
  1090. typedef struct _CLASS_POWER_OPTIONS {
  1091. ULONG PowerDown : 1;
  1092. ULONG LockQueue : 1;
  1093. ULONG HandleSpinDown : 1;
  1094. ULONG HandleSpinUp : 1;
  1095. ULONG Reserved : 27;
  1096. } CLASS_POWER_OPTIONS, *PCLASS_POWER_OPTIONS;
  1097. //
  1098. // this is a private structure, but must be kept here
  1099. // to properly compile size of FUNCTIONAL_DEVICE_EXTENSION
  1100. //
  1101. typedef enum {
  1102. PowerDownDeviceInitial,
  1103. PowerDownDeviceLocked,
  1104. PowerDownDeviceStopped,
  1105. PowerDownDeviceOff,
  1106. PowerDownDeviceUnlocked
  1107. } CLASS_POWER_DOWN_STATE;
  1108. //
  1109. // same as above, but with an extra state for whistler
  1110. // should be ok to change the above structure, but that
  1111. // would break someone somewhere who ignore the PRIVATE
  1112. // nature of the structure.
  1113. //
  1114. typedef enum {
  1115. PowerDownDeviceInitial2,
  1116. PowerDownDeviceLocked2,
  1117. PowerDownDeviceFlushed2,
  1118. PowerDownDeviceStopped2,
  1119. PowerDownDeviceOff2,
  1120. PowerDownDeviceUnlocked2
  1121. } CLASS_POWER_DOWN_STATE2;
  1122. //
  1123. // this is a private enum, but must be kept here
  1124. // to properly compile size of FUNCTIONAL_DEVICE_EXTENSION
  1125. //
  1126. typedef enum {
  1127. PowerUpDeviceInitial,
  1128. PowerUpDeviceLocked,
  1129. PowerUpDeviceOn,
  1130. PowerUpDeviceStarted,
  1131. PowerUpDeviceUnlocked
  1132. } CLASS_POWER_UP_STATE;
  1133. //
  1134. // this is a private structure, but must be kept here
  1135. // to properly compile size of FUNCTIONAL_DEVICE_EXTENSION
  1136. //
  1137. typedef struct _CLASS_POWER_CONTEXT {
  1138. union {
  1139. CLASS_POWER_DOWN_STATE PowerDown;
  1140. CLASS_POWER_DOWN_STATE2 PowerDown2; // whistler
  1141. CLASS_POWER_UP_STATE PowerUp;
  1142. } PowerChangeState;
  1143. CLASS_POWER_OPTIONS Options;
  1144. BOOLEAN InUse;
  1145. BOOLEAN QueueLocked;
  1146. NTSTATUS FinalStatus;
  1147. ULONG RetryCount;
  1148. ULONG RetryInterval;
  1149. PIO_COMPLETION_ROUTINE CompletionRoutine;
  1150. PDEVICE_OBJECT DeviceObject;
  1151. PIRP Irp;
  1152. SCSI_REQUEST_BLOCK Srb;
  1153. } CLASS_POWER_CONTEXT, *PCLASS_POWER_CONTEXT;
  1154. //
  1155. // Restricted - May only append to this structure for backwards compatibility
  1156. //
  1157. typedef struct _FUNCTIONAL_DEVICE_EXTENSION {
  1158. //
  1159. // Common device extension header
  1160. //
  1161. union {
  1162. struct {
  1163. ULONG Version;
  1164. PDEVICE_OBJECT DeviceObject;
  1165. };
  1166. COMMON_DEVICE_EXTENSION CommonExtension;
  1167. };
  1168. //
  1169. // Pointer to the physical device object we attached to - use this
  1170. // for Pnp calls which need a PDO
  1171. //
  1172. PDEVICE_OBJECT LowerPdo;
  1173. //
  1174. // Device capabilities
  1175. //
  1176. PSTORAGE_DEVICE_DESCRIPTOR DeviceDescriptor;
  1177. //
  1178. // SCSI port driver capabilities
  1179. //
  1180. PSTORAGE_ADAPTER_DESCRIPTOR AdapterDescriptor;
  1181. //
  1182. // Current Power state of the device
  1183. //
  1184. DEVICE_POWER_STATE DevicePowerState;
  1185. //
  1186. // DM Driver for IDE drives hack (ie. OnTrack)
  1187. // Bytes to skew all requests
  1188. //
  1189. ULONG DMByteSkew;
  1190. //
  1191. // DM Driver for IDE drives hack (ie. OnTrack)
  1192. // Sectors to skew all requests.
  1193. //
  1194. ULONG DMSkew;
  1195. //
  1196. // DM Driver for IDE drives hack (ie. OnTrack)
  1197. // Flag to indicate whether DM driver has been located on an IDE drive.
  1198. //
  1199. BOOLEAN DMActive;
  1200. //
  1201. // Buffer for drive parameters returned in IO device control.
  1202. //
  1203. DISK_GEOMETRY DiskGeometry;
  1204. //
  1205. // Request Sense Buffer
  1206. //
  1207. PSENSE_DATA SenseData;
  1208. //
  1209. // Request timeout in seconds;
  1210. //
  1211. ULONG TimeOutValue;
  1212. //
  1213. // System device number
  1214. //
  1215. ULONG DeviceNumber;
  1216. //
  1217. // Add default Srb Flags.
  1218. //
  1219. ULONG SrbFlags;
  1220. //
  1221. // Total number of SCSI protocol errors on the device.
  1222. //
  1223. ULONG ErrorCount;
  1224. //
  1225. // Lock count for removable media.
  1226. //
  1227. LONG LockCount;
  1228. LONG ProtectedLockCount;
  1229. LONG InternalLockCount;
  1230. KEVENT EjectSynchronizationEvent;
  1231. //
  1232. // Values for the flags are below.
  1233. //
  1234. USHORT DeviceFlags;
  1235. //
  1236. // Log2 of sector size
  1237. //
  1238. UCHAR SectorShift;
  1239. UCHAR ReservedByte;
  1240. //
  1241. // Indicates that the necessary data structures for media change
  1242. // detection have been initialized.
  1243. //
  1244. PMEDIA_CHANGE_DETECTION_INFO MediaChangeDetectionInfo;
  1245. PKEVENT Unused1;
  1246. HANDLE Unused2;
  1247. //
  1248. // File system context. Used for kernel-mode requests to disable autorun.
  1249. //
  1250. FILE_OBJECT_EXTENSION KernelModeMcnContext;
  1251. //
  1252. // Count of media changes. This field is only valid for the root partition
  1253. // (ie. if PhysicalDevice == NULL).
  1254. //
  1255. ULONG MediaChangeCount;
  1256. //
  1257. // Storage for a handle to the directory the PDO's are placed in
  1258. //
  1259. HANDLE DeviceDirectory;
  1260. //
  1261. // Storage for a release queue request.
  1262. //
  1263. KSPIN_LOCK ReleaseQueueSpinLock;
  1264. PIRP ReleaseQueueIrp;
  1265. SCSI_REQUEST_BLOCK ReleaseQueueSrb;
  1266. BOOLEAN ReleaseQueueNeeded;
  1267. BOOLEAN ReleaseQueueInProgress;
  1268. BOOLEAN ReleaseQueueIrpFromPool;
  1269. //
  1270. // Failure detection storage
  1271. //
  1272. BOOLEAN FailurePredicted;
  1273. ULONG FailureReason;
  1274. PFAILURE_PREDICTION_INFO FailurePredictionInfo;
  1275. BOOLEAN PowerDownInProgress;
  1276. //
  1277. // Interlock for ensuring we don't recurse during enumeration.
  1278. //
  1279. ULONG EnumerationInterlock;
  1280. //
  1281. // Synchronization object for manipulating the child list.
  1282. //
  1283. KEVENT ChildLock;
  1284. //
  1285. // The thread which currently owns the ChildLock. This is used to
  1286. // avoid recursive acquisition.
  1287. //
  1288. PKTHREAD ChildLockOwner;
  1289. //
  1290. // The number of times this event has been acquired.
  1291. //
  1292. ULONG ChildLockAcquisitionCount;
  1293. //
  1294. // Flags for special behaviour required by
  1295. // different hardware, such as never spinning down
  1296. // or disabling advanced features such as write cache
  1297. //
  1298. ULONG ScanForSpecialFlags;
  1299. //
  1300. // For delayed retry of power requests at DPC level
  1301. //
  1302. KDPC PowerRetryDpc;
  1303. KTIMER PowerRetryTimer;
  1304. //
  1305. // Context structure for power operations. Since we can only have
  1306. // one D irp at any time in the stack we don't need to worry about
  1307. // allocating multiple of these structures.
  1308. //
  1309. CLASS_POWER_CONTEXT PowerContext;
  1310. //
  1311. // Hold new private data that only classpnp should modify
  1312. // in this structure.
  1313. //
  1314. PCLASS_PRIVATE_FDO_DATA PrivateFdoData;
  1315. //
  1316. // For future expandability
  1317. // leave these at the end of the structure.
  1318. //
  1319. ULONG_PTR Reserved2;
  1320. ULONG_PTR Reserved3;
  1321. ULONG_PTR Reserved4;
  1322. } FUNCTIONAL_DEVICE_EXTENSION, *PFUNCTIONAL_DEVICE_EXTENSION;
  1323. //
  1324. // The following CLASS_SPECIAL_ flags are set in ScanForSpecialFlags
  1325. // in the FdoExtension
  1326. //
  1327. // Never Spin Up/Down the drive (may not handle properly)
  1328. #define CLASS_SPECIAL_DISABLE_SPIN_DOWN 0x00000001
  1329. #define CLASS_SPECIAL_DISABLE_SPIN_UP 0x00000002
  1330. // Don't bother to lock the queue when powering down
  1331. // (used mostly to send a quick stop to a cdrom to abort audio playback)
  1332. #define CLASS_SPECIAL_NO_QUEUE_LOCK 0x00000008
  1333. // Disable write cache due to known bugs
  1334. #define CLASS_SPECIAL_DISABLE_WRITE_CACHE 0x00000010
  1335. //
  1336. // Special interpretation of "device not ready / cause not reportable" for
  1337. // devices which don't tell us they need to be spun up manually after they
  1338. // spin themselves down behind our back.
  1339. //
  1340. // The down side of this is that if the drive chooses to report
  1341. // "device not ready / cause not reportable" to mean "no media in device"
  1342. // or any other error which really does require user intervention NT will
  1343. // waste a large amount of time trying to spin up a disk which can't be spun
  1344. // up.
  1345. //
  1346. #define CLASS_SPECIAL_CAUSE_NOT_REPORTABLE_HACK 0x00000020
  1347. #define CLASS_SPECIAL_MODIFY_CACHE_UNSUCCESSFUL 0x00000040
  1348. #define CLASS_SPECIAL_FUA_NOT_SUPPORTED 0x00000080
  1349. #define CLASS_SPECIAL_VALID_MASK 0x000000FB
  1350. #define CLASS_SPECIAL_RESERVED (~CLASS_SPECIAL_VALID_MASK)
  1351. //
  1352. // Restricted - May only append to this structure for backwards compatibility
  1353. //
  1354. typedef struct _PHYSICAL_DEVICE_EXTENSION {
  1355. //
  1356. // Common extension data
  1357. //
  1358. union {
  1359. struct {
  1360. ULONG Version;
  1361. PDEVICE_OBJECT DeviceObject;
  1362. };
  1363. COMMON_DEVICE_EXTENSION CommonExtension;
  1364. };
  1365. //
  1366. // Indicates that the pdo no longer physically exits.
  1367. //
  1368. BOOLEAN IsMissing;
  1369. //
  1370. // Indicates that the PDO has been handed out to the PNP system.
  1371. //
  1372. BOOLEAN IsEnumerated;
  1373. //
  1374. // Hold new private data that only classpnp should modify
  1375. // in this structure.
  1376. //
  1377. PCLASS_PRIVATE_PDO_DATA PrivatePdoData;
  1378. //
  1379. // for future expandability
  1380. // leave these at the end of the structure.
  1381. //
  1382. ULONG_PTR Reserved2;
  1383. ULONG_PTR Reserved3;
  1384. ULONG_PTR Reserved4;
  1385. } PHYSICAL_DEVICE_EXTENSION, *PPHYSICAL_DEVICE_EXTENSION;
  1386. //
  1387. // Indicates that the device has write caching enabled.
  1388. //
  1389. #define DEV_WRITE_CACHE 0x00000001
  1390. //
  1391. // Build SCSI 1 or SCSI 2 CDBs
  1392. //
  1393. #define DEV_USE_SCSI1 0x00000002
  1394. //
  1395. // Indicates whether is is safe to send StartUnit commands
  1396. // to this device. It will only be off for some removeable devices.
  1397. //
  1398. #define DEV_SAFE_START_UNIT 0x00000004
  1399. //
  1400. // Indicates whether it is unsafe to send SCSIOP_MECHANISM_STATUS commands to
  1401. // this device. Some devices don't like these 12 byte commands
  1402. //
  1403. #define DEV_NO_12BYTE_CDB 0x00000008
  1404. //
  1405. // Indicates that the device is connected to a backup power supply
  1406. // and hence write-through and synch cache requests may be ignored
  1407. //
  1408. #define DEV_POWER_PROTECTED 0x00000010
  1409. //
  1410. // Define context structure for asynchronous completions.
  1411. //
  1412. typedef struct _COMPLETION_CONTEXT {
  1413. PDEVICE_OBJECT DeviceObject;
  1414. SCSI_REQUEST_BLOCK Srb;
  1415. }COMPLETION_CONTEXT, *PCOMPLETION_CONTEXT;
  1416. /*++
  1417. Internal function - described in classpnp\class.c in ddk sources
  1418. --*/
  1419. SCSIPORT_API
  1420. ULONG
  1421. ClassInitialize(
  1422. IN PVOID Argument1,
  1423. IN PVOID Argument2,
  1424. IN PCLASS_INIT_DATA InitializationData
  1425. );
  1426. /*++
  1427. Internal function - described in classpnp\class.c in ddk sources
  1428. --*/
  1429. //
  1430. // The Data Parameter contains a pointer to a CLASS_QUERY_WMI_REGINFO_EX_LIST
  1431. // structure that specifies callbacks that are used instead of the
  1432. // PCLASS_QUERY_WMI_REGINFO callbacks.
  1433. //
  1434. // {00E34B11-2444-4745-A53D-620100CD82F7}
  1435. #define GUID_CLASSPNP_QUERY_REGINFOEX { 0xe34b11, 0x2444, 0x4745, { 0xa5, 0x3d, 0x62, 0x1, 0x0, 0xcd, 0x82, 0xf7 } }
  1436. typedef struct _CLASS_QUERY_WMI_REGINFO_EX_LIST
  1437. {
  1438. ULONG Size; // Should be sizeof(CLASS_QUERY_REGINFO_EX_LIST)
  1439. PCLASS_QUERY_WMI_REGINFO_EX ClassFdoQueryWmiRegInfoEx;
  1440. PCLASS_QUERY_WMI_REGINFO_EX ClassPdoQueryWmiRegInfoEx;
  1441. } CLASS_QUERY_WMI_REGINFO_EX_LIST, *PCLASS_QUERY_WMI_REGINFO_EX_LIST;
  1442. SCSIPORT_API
  1443. ULONG
  1444. ClassInitializeEx(
  1445. IN PDRIVER_OBJECT DriverObject,
  1446. IN LPGUID Guid,
  1447. IN PVOID Data
  1448. );
  1449. /*++
  1450. Internal function - described in classpnp\class.c in ddk sources
  1451. --*/
  1452. SCSIPORT_API
  1453. NTSTATUS
  1454. ClassCreateDeviceObject(
  1455. IN PDRIVER_OBJECT DriverObject,
  1456. IN PCCHAR ObjectNameBuffer,
  1457. IN PDEVICE_OBJECT LowerDeviceObject,
  1458. IN BOOLEAN IsFdo,
  1459. IN OUT PDEVICE_OBJECT *DeviceObject
  1460. );
  1461. /*++
  1462. Internal function - described in classpnp\class.c in ddk sources
  1463. --*/
  1464. SCSIPORT_API
  1465. NTSTATUS
  1466. ClassReadDriveCapacity(
  1467. IN PDEVICE_OBJECT DeviceObject
  1468. );
  1469. /*++
  1470. Internal function - described in classpnp\class.c in ddk sources
  1471. --*/
  1472. SCSIPORT_API
  1473. VOID
  1474. ClassReleaseQueue(
  1475. IN PDEVICE_OBJECT DeviceObject
  1476. );
  1477. /*++
  1478. Internal function - described in classpnp\class.c in ddk sources
  1479. --*/
  1480. SCSIPORT_API
  1481. VOID
  1482. ClassSplitRequest(
  1483. IN PDEVICE_OBJECT DeviceObject,
  1484. IN PIRP Irp,
  1485. IN ULONG MaximumBytes
  1486. );
  1487. /*++
  1488. Internal function - described in classpnp\class.c in ddk sources
  1489. --*/
  1490. SCSIPORT_API
  1491. NTSTATUS
  1492. ClassDeviceControl(
  1493. PDEVICE_OBJECT DeviceObject,
  1494. PIRP Irp
  1495. );
  1496. /*++
  1497. Internal function - described in classpnp\class.c in ddk sources
  1498. --*/
  1499. SCSIPORT_API
  1500. NTSTATUS
  1501. ClassIoComplete(
  1502. IN PDEVICE_OBJECT DeviceObject,
  1503. IN PIRP Irp,
  1504. IN PVOID Context
  1505. );
  1506. /*++
  1507. Internal function - described in classpnp\class.c in ddk sources
  1508. --*/
  1509. SCSIPORT_API
  1510. NTSTATUS
  1511. ClassIoCompleteAssociated(
  1512. IN PDEVICE_OBJECT DeviceObject,
  1513. IN PIRP Irp,
  1514. IN PVOID Context
  1515. );
  1516. /*++
  1517. Internal function - described in classpnp\class.c in ddk sources
  1518. --*/
  1519. SCSIPORT_API
  1520. BOOLEAN
  1521. ClassInterpretSenseInfo(
  1522. IN PDEVICE_OBJECT DeviceObject,
  1523. IN PSCSI_REQUEST_BLOCK Srb,
  1524. IN UCHAR MajorFunctionCode,
  1525. IN ULONG IoDeviceCode,
  1526. IN ULONG RetryCount,
  1527. OUT NTSTATUS *Status,
  1528. OUT ULONG *RetryInterval
  1529. );
  1530. /*++
  1531. Internal function - described in classpnp\class.c in ddk sources
  1532. --*/
  1533. VOID
  1534. ClassSendDeviceIoControlSynchronous(
  1535. IN ULONG IoControlCode,
  1536. IN PDEVICE_OBJECT TargetDeviceObject,
  1537. IN OUT PVOID Buffer OPTIONAL,
  1538. IN ULONG InputBufferLength,
  1539. IN ULONG OutputBufferLength,
  1540. IN BOOLEAN InternalDeviceIoControl,
  1541. OUT PIO_STATUS_BLOCK IoStatus
  1542. );
  1543. /*++
  1544. Internal function - described in classpnp\class.c in ddk sources
  1545. --*/
  1546. SCSIPORT_API
  1547. NTSTATUS
  1548. ClassSendIrpSynchronous(
  1549. IN PDEVICE_OBJECT TargetDeviceObject,
  1550. IN PIRP Irp
  1551. );
  1552. /*++
  1553. Internal function - described in classpnp\class.c in ddk sources
  1554. --*/
  1555. SCSIPORT_API
  1556. NTSTATUS
  1557. ClassForwardIrpSynchronous(
  1558. IN PCOMMON_DEVICE_EXTENSION CommonExtension,
  1559. IN PIRP Irp
  1560. );
  1561. /*++
  1562. Internal function - described in classpnp\class.c in ddk sources
  1563. --*/
  1564. SCSIPORT_API
  1565. NTSTATUS
  1566. ClassSendSrbSynchronous(
  1567. PDEVICE_OBJECT DeviceObject,
  1568. PSCSI_REQUEST_BLOCK Srb,
  1569. PVOID BufferAddress,
  1570. ULONG BufferLength,
  1571. BOOLEAN WriteToDevice
  1572. );
  1573. /*++
  1574. Internal function - described in classpnp\class.c in ddk sources
  1575. --*/
  1576. SCSIPORT_API
  1577. NTSTATUS
  1578. ClassSendSrbAsynchronous(
  1579. PDEVICE_OBJECT DeviceObject,
  1580. PSCSI_REQUEST_BLOCK Srb,
  1581. PIRP Irp,
  1582. PVOID BufferAddress,
  1583. ULONG BufferLength,
  1584. BOOLEAN WriteToDevice
  1585. );
  1586. /*++
  1587. Internal function - described in classpnp\class.c in ddk sources
  1588. --*/
  1589. SCSIPORT_API
  1590. NTSTATUS
  1591. ClassBuildRequest(
  1592. PDEVICE_OBJECT DeviceObject,
  1593. PIRP Irp
  1594. );
  1595. /*++
  1596. Internal function - described in classpnp\class.c in ddk sources
  1597. --*/
  1598. SCSIPORT_API
  1599. ULONG
  1600. ClassModeSense(
  1601. IN PDEVICE_OBJECT DeviceObject,
  1602. IN PCHAR ModeSenseBuffer,
  1603. IN ULONG Length,
  1604. IN UCHAR PageMode
  1605. );
  1606. /*++
  1607. Internal function - described in classpnp\class.c in ddk sources
  1608. --*/
  1609. SCSIPORT_API
  1610. PVOID
  1611. ClassFindModePage(
  1612. IN PCHAR ModeSenseBuffer,
  1613. IN ULONG Length,
  1614. IN UCHAR PageMode,
  1615. IN BOOLEAN Use6Byte
  1616. );
  1617. /*++
  1618. Internal function - described in classpnp\class.c in ddk sources
  1619. --*/
  1620. SCSIPORT_API
  1621. NTSTATUS
  1622. ClassClaimDevice(
  1623. IN PDEVICE_OBJECT LowerDeviceObject,
  1624. IN BOOLEAN Release
  1625. );
  1626. /*++
  1627. Internal function - described in classpnp\class.c in ddk sources
  1628. --*/
  1629. SCSIPORT_API
  1630. NTSTATUS
  1631. ClassInternalIoControl (
  1632. IN PDEVICE_OBJECT DeviceObject,
  1633. IN PIRP Irp
  1634. );
  1635. /*++
  1636. Internal function - described in classpnp\utils.c in ddk sources
  1637. --*/
  1638. SCSIPORT_API
  1639. VOID
  1640. ClassInitializeSrbLookasideList(
  1641. IN PCOMMON_DEVICE_EXTENSION CommonExtension,
  1642. IN ULONG NumberElements
  1643. );
  1644. /*++
  1645. Internal function - described in classpnp\utils.c in ddk sources
  1646. --*/
  1647. SCSIPORT_API
  1648. VOID
  1649. ClassDeleteSrbLookasideList(
  1650. IN PCOMMON_DEVICE_EXTENSION CommonExtension
  1651. );
  1652. /*++
  1653. Internal function - described in classpnp\class.c in ddk sources
  1654. --*/
  1655. SCSIPORT_API
  1656. ULONG
  1657. ClassQueryTimeOutRegistryValue(
  1658. IN PDEVICE_OBJECT DeviceObject
  1659. );
  1660. /*++
  1661. Internal function - described in classpnp\class.c in ddk sources
  1662. --*/
  1663. SCSIPORT_API
  1664. NTSTATUS
  1665. ClassGetDescriptor(
  1666. IN PDEVICE_OBJECT DeviceObject,
  1667. IN PSTORAGE_PROPERTY_ID PropertyId,
  1668. OUT PVOID *Descriptor
  1669. );
  1670. /*++
  1671. Internal function - described in classpnp\class.c in ddk sources
  1672. --*/
  1673. SCSIPORT_API
  1674. VOID
  1675. ClassInvalidateBusRelations(
  1676. IN PDEVICE_OBJECT Fdo
  1677. );
  1678. /*++
  1679. Internal function - described in classpnp\class.c in ddk sources
  1680. --*/
  1681. SCSIPORT_API
  1682. VOID
  1683. ClassMarkChildrenMissing(
  1684. IN PFUNCTIONAL_DEVICE_EXTENSION Fdo
  1685. );
  1686. /*++
  1687. Internal function - described in classpnp\class.c in ddk sources
  1688. --*/
  1689. SCSIPORT_API
  1690. BOOLEAN
  1691. ClassMarkChildMissing(
  1692. IN PPHYSICAL_DEVICE_EXTENSION PdoExtension,
  1693. IN BOOLEAN AcquireChildLock
  1694. );
  1695. /*++
  1696. Internal function - described in classpnp\class.c in ddk sources
  1697. --*/
  1698. SCSIPORT_API
  1699. VOID
  1700. ClassDebugPrint(
  1701. CLASS_DEBUG_LEVEL DebugPrintLevel,
  1702. PCCHAR DebugMessage,
  1703. ...
  1704. );
  1705. /*++
  1706. Internal function - described in classpnp\class.c in ddk sources
  1707. --*/
  1708. SCSIPORT_API
  1709. PCLASS_DRIVER_EXTENSION
  1710. ClassGetDriverExtension(
  1711. IN PDRIVER_OBJECT DriverObject
  1712. );
  1713. /*++
  1714. Internal function - described in classpnp\lock.c in ddk sources
  1715. --*/
  1716. SCSIPORT_API
  1717. VOID
  1718. ClassCompleteRequest(
  1719. IN PDEVICE_OBJECT DeviceObject,
  1720. IN PIRP Irp,
  1721. IN CCHAR PriorityBoost
  1722. );
  1723. /*++
  1724. Internal function - described in classpnp\lock.c in ddk sources
  1725. --*/
  1726. SCSIPORT_API
  1727. VOID
  1728. ClassReleaseRemoveLock(
  1729. IN PDEVICE_OBJECT DeviceObject,
  1730. IN OPTIONAL PIRP Irp
  1731. );
  1732. /*++
  1733. Internal function - described in classpnp\lock.c in ddk sources
  1734. --*/
  1735. SCSIPORT_API
  1736. ULONG
  1737. ClassAcquireRemoveLockEx(
  1738. IN PDEVICE_OBJECT DeviceObject,
  1739. IN OPTIONAL PVOID Tag,
  1740. IN PCSTR File,
  1741. IN ULONG Line
  1742. );
  1743. /*++
  1744. Internal function - described in classpnp\class.c in ddk sources
  1745. --*/
  1746. SCSIPORT_API
  1747. VOID
  1748. ClassUpdateInformationInRegistry(
  1749. IN PDEVICE_OBJECT Fdo,
  1750. IN PCHAR DeviceName,
  1751. IN ULONG DeviceNumber,
  1752. IN PINQUIRYDATA InquiryData,
  1753. IN ULONG InquiryDataLength
  1754. );
  1755. /*++
  1756. Internal function - described in classpnp\classwmi.c in ddk sources
  1757. --*/
  1758. SCSIPORT_API
  1759. NTSTATUS
  1760. ClassWmiCompleteRequest(
  1761. IN PDEVICE_OBJECT DeviceObject,
  1762. IN PIRP Irp,
  1763. IN NTSTATUS Status,
  1764. IN ULONG BufferUsed,
  1765. IN CCHAR PriorityBoost
  1766. );
  1767. /*++
  1768. Internal function - described in classpnp\classwmi.c in ddk sources
  1769. --*/
  1770. SCSIPORT_API
  1771. NTSTATUS
  1772. ClassWmiFireEvent(
  1773. IN PDEVICE_OBJECT DeviceObject,
  1774. IN LPGUID Guid,
  1775. IN ULONG InstanceIndex,
  1776. IN ULONG EventDataSize,
  1777. IN PVOID EventData
  1778. );
  1779. /*++
  1780. Internal function - described in classpnp\autorun.c in ddk sources
  1781. --*/
  1782. SCSIPORT_API
  1783. VOID
  1784. ClassResetMediaChangeTimer(
  1785. IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension
  1786. );
  1787. /*++
  1788. Internal function - described in classpnp\autorun.c in ddk sources
  1789. --*/
  1790. SCSIPORT_API
  1791. VOID
  1792. ClassInitializeMediaChangeDetection(
  1793. IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension,
  1794. IN PUCHAR EventPrefix
  1795. );
  1796. /*++
  1797. Internal function - described in classpnp\autorun.c in ddk sources
  1798. --*/
  1799. SCSIPORT_API
  1800. NTSTATUS
  1801. ClassInitializeTestUnitPolling(
  1802. IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension,
  1803. IN BOOLEAN AllowDriveToSleep
  1804. );
  1805. /*++
  1806. Internal function - described in classpnp\class.c in ddk sources
  1807. --*/
  1808. SCSIPORT_API
  1809. PVPB
  1810. ClassGetVpb(
  1811. IN PDEVICE_OBJECT DeviceObject
  1812. );
  1813. /*++
  1814. Internal function - described in classpnp\power.c in ddk sources
  1815. --*/
  1816. SCSIPORT_API
  1817. NTSTATUS
  1818. ClassSpinDownPowerHandler(
  1819. IN PDEVICE_OBJECT DeviceObject,
  1820. IN PIRP Irp
  1821. );
  1822. /*++
  1823. Internal function - described in classpnp\power.c in ddk sources
  1824. --*/
  1825. NTSTATUS
  1826. ClassStopUnitPowerHandler(
  1827. IN PDEVICE_OBJECT DeviceObject,
  1828. IN PIRP Irp
  1829. );
  1830. /*++
  1831. Internal function - described in classpnp\autorun.c in ddk sources
  1832. --*/
  1833. NTSTATUS
  1834. ClassSetFailurePredictionPoll(
  1835. PFUNCTIONAL_DEVICE_EXTENSION FdoExtension,
  1836. FAILURE_PREDICTION_METHOD FailurePredictionMethod,
  1837. ULONG PollingPeriod
  1838. );
  1839. /*++
  1840. Internal function - described in classpnp\autorun.c in ddk sources
  1841. --*/
  1842. VOID
  1843. ClassNotifyFailurePredicted(
  1844. PFUNCTIONAL_DEVICE_EXTENSION FdoExtension,
  1845. PUCHAR Buffer,
  1846. ULONG BufferSize,
  1847. BOOLEAN LogError,
  1848. ULONG UniqueErrorValue,
  1849. UCHAR PathId,
  1850. UCHAR TargetId,
  1851. UCHAR Lun
  1852. );
  1853. /*++
  1854. Internal function - described in classpnp\class.c in ddk sources
  1855. --*/
  1856. SCSIPORT_API
  1857. VOID
  1858. ClassAcquireChildLock(
  1859. IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension
  1860. );
  1861. /*++
  1862. Internal function - described in classpnp\class.c in ddk sources
  1863. --*/
  1864. SCSIPORT_API
  1865. VOID
  1866. ClassReleaseChildLock(
  1867. IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension
  1868. );
  1869. /*++
  1870. Internal function - described in classpnp\class.c in ddk sources
  1871. --*/
  1872. NTSTATUS
  1873. ClassSignalCompletion(
  1874. IN PDEVICE_OBJECT DeviceObject,
  1875. IN PIRP Irp,
  1876. IN PKEVENT Event
  1877. );
  1878. /*++
  1879. Internal function - described in classpnp\class.c in ddk sources
  1880. --*/
  1881. VOID
  1882. ClassSendStartUnit(
  1883. IN PDEVICE_OBJECT DeviceObject
  1884. );
  1885. /*++
  1886. Internal function - described in classpnp\class.c in ddk sources
  1887. --*/
  1888. SCSIPORT_API
  1889. NTSTATUS
  1890. ClassRemoveDevice(
  1891. IN PDEVICE_OBJECT DeviceObject,
  1892. IN UCHAR RemoveType
  1893. );
  1894. /*++
  1895. Internal function - described in classpnp\class.c in ddk sources
  1896. --*/
  1897. SCSIPORT_API
  1898. NTSTATUS
  1899. ClassAsynchronousCompletion(
  1900. PDEVICE_OBJECT DeviceObject,
  1901. PIRP Irp,
  1902. PVOID Context
  1903. );
  1904. /*++
  1905. Internal function - described in classpnp\autorun.c in ddk sources
  1906. --*/
  1907. SCSIPORT_API
  1908. VOID
  1909. ClassCheckMediaState(
  1910. IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension
  1911. );
  1912. /*++
  1913. Internal function - described in classpnp\class.c in ddk sources
  1914. --*/
  1915. SCSIPORT_API
  1916. NTSTATUS
  1917. ClassCheckVerifyComplete(
  1918. IN PDEVICE_OBJECT DeviceObject,
  1919. IN PIRP Irp,
  1920. IN PVOID Context
  1921. );
  1922. /*++
  1923. Internal function - described in classpnp\autorun.c in ddk sources
  1924. --*/
  1925. SCSIPORT_API
  1926. VOID
  1927. ClassSetMediaChangeState(
  1928. IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension,
  1929. IN MEDIA_CHANGE_DETECTION_STATE State,
  1930. IN BOOLEAN Wait
  1931. );
  1932. /*++
  1933. Internal function - described in classpnp\autorun.c in ddk sources
  1934. --*/
  1935. SCSIPORT_API
  1936. VOID
  1937. ClassEnableMediaChangeDetection(
  1938. IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension
  1939. );
  1940. /*++
  1941. Internal function - described in classpnp\autorun.c in ddk sources
  1942. --*/
  1943. SCSIPORT_API
  1944. VOID
  1945. ClassDisableMediaChangeDetection(
  1946. IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension
  1947. );
  1948. /*++
  1949. Internal function - described in classpnp\autorun.c in ddk sources
  1950. --*/
  1951. SCSIPORT_API
  1952. VOID
  1953. ClassCleanupMediaChangeDetection(
  1954. IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension
  1955. );
  1956. /*++
  1957. Internal function - described in classpnp\utils.c in ddk sources
  1958. --*/
  1959. VOID
  1960. ClassGetDeviceParameter(
  1961. IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension,
  1962. IN PWSTR SubkeyName OPTIONAL,
  1963. IN PWSTR ParameterName,
  1964. IN OUT PULONG ParameterValue
  1965. );
  1966. /*++
  1967. Internal function - described in classpnp\utils.c in ddk sources
  1968. --*/
  1969. NTSTATUS
  1970. ClassSetDeviceParameter(
  1971. IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension,
  1972. IN PWSTR SubkeyName OPTIONAL,
  1973. IN PWSTR ParameterName,
  1974. IN ULONG ParameterValue
  1975. );
  1976. //
  1977. // could be #define, but this allows typechecking
  1978. //
  1979. __inline
  1980. BOOLEAN
  1981. PORT_ALLOCATED_SENSE(
  1982. IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension,
  1983. IN PSCSI_REQUEST_BLOCK Srb
  1984. )
  1985. {
  1986. return ((BOOLEAN)((TEST_FLAG(Srb->SrbFlags, SRB_FLAGS_PORT_DRIVER_ALLOCSENSE) &&
  1987. TEST_FLAG(Srb->SrbFlags, SRB_FLAGS_FREE_SENSE_BUFFER)) &&
  1988. (Srb->SenseInfoBuffer != FdoExtension->SenseData))
  1989. );
  1990. }
  1991. __inline
  1992. VOID
  1993. FREE_PORT_ALLOCATED_SENSE_BUFFER(
  1994. IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension,
  1995. IN PSCSI_REQUEST_BLOCK Srb
  1996. )
  1997. {
  1998. ASSERT(TEST_FLAG(Srb->SrbFlags, SRB_FLAGS_PORT_DRIVER_ALLOCSENSE));
  1999. ASSERT(TEST_FLAG(Srb->SrbFlags, SRB_FLAGS_FREE_SENSE_BUFFER));
  2000. ASSERT(Srb->SenseInfoBuffer != FdoExtension->SenseData);
  2001. ExFreePool(Srb->SenseInfoBuffer);
  2002. Srb->SenseInfoBuffer = FdoExtension->SenseData;
  2003. Srb->SenseInfoBufferLength = SENSE_BUFFER_SIZE; // should be variable?
  2004. CLEAR_FLAG(Srb->SrbFlags, SRB_FLAGS_FREE_SENSE_BUFFER);
  2005. return;
  2006. }
  2007. /*++////////////////////////////////////////////////////////////////////////////
  2008. PCLASS_SCAN_FOR_SPECIAL_HANDLER()
  2009. Routine Description:
  2010. This routine is a callback into the driver to set device-specific
  2011. flags based upon matches made to the device's inquiry data. Drivers
  2012. register for this callback using ClassRegisterScanForSpecial().
  2013. Irql:
  2014. This routine will be called at KIRQL == PASSIVE_LEVEL
  2015. Arguments:
  2016. DeviceObject is the device object the error occurred on.
  2017. Srb is the Srb that was being processed when the error occurred.
  2018. Status may be overwritten by the routine if it decides that the error
  2019. was benign, or otherwise wishes to change the returned status code
  2020. for this command
  2021. Retry may be overwritten to specify that this command should or should
  2022. not be retried (if the callee supports retrying commands)
  2023. Return Value:
  2024. status
  2025. --*/
  2026. typedef
  2027. VOID
  2028. (*PCLASS_SCAN_FOR_SPECIAL_HANDLER) (
  2029. IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension,
  2030. IN ULONG_PTR Data
  2031. );
  2032. VOID
  2033. ClassScanForSpecial(
  2034. IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension,
  2035. IN CLASSPNP_SCAN_FOR_SPECIAL_INFO DeviceList[],
  2036. IN PCLASS_SCAN_FOR_SPECIAL_HANDLER Function
  2037. );
  2038. #endif /* _CLASS_ */