Source code of Windows XP (NT5)
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.

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