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.

1262 lines
43 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. ntdddisk.h
  5. Abstract:
  6. This is the include file that defines all constants and types for
  7. accessing the Disk device.
  8. Revision History:
  9. --*/
  10. #ifndef _NTDDDISK_H_
  11. #define _NTDDDISK_H_
  12. #if _MSC_VER > 1000
  13. #pragma once
  14. #endif
  15. #include <diskguid.h>
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. //
  20. // Device Name - this string is the name of the device. It is the name
  21. // that should be passed to NtOpenFile when accessing the device.
  22. //
  23. // Note: For devices that support multiple units, it should be suffixed
  24. // with the Ascii representation of the unit number.
  25. //
  26. #define DD_DISK_DEVICE_NAME "\\Device\\UNKNOWN"
  27. //
  28. // NtDeviceIoControlFile
  29. // begin_winioctl
  30. //
  31. // IoControlCode values for disk devices.
  32. //
  33. #define IOCTL_DISK_BASE FILE_DEVICE_DISK
  34. #define IOCTL_DISK_GET_DRIVE_GEOMETRY CTL_CODE(IOCTL_DISK_BASE, 0x0000, METHOD_BUFFERED, FILE_ANY_ACCESS)
  35. #define IOCTL_DISK_GET_PARTITION_INFO CTL_CODE(IOCTL_DISK_BASE, 0x0001, METHOD_BUFFERED, FILE_READ_ACCESS)
  36. #define IOCTL_DISK_SET_PARTITION_INFO CTL_CODE(IOCTL_DISK_BASE, 0x0002, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  37. #define IOCTL_DISK_GET_DRIVE_LAYOUT CTL_CODE(IOCTL_DISK_BASE, 0x0003, METHOD_BUFFERED, FILE_READ_ACCESS)
  38. #define IOCTL_DISK_SET_DRIVE_LAYOUT CTL_CODE(IOCTL_DISK_BASE, 0x0004, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  39. #define IOCTL_DISK_VERIFY CTL_CODE(IOCTL_DISK_BASE, 0x0005, METHOD_BUFFERED, FILE_ANY_ACCESS)
  40. #define IOCTL_DISK_FORMAT_TRACKS CTL_CODE(IOCTL_DISK_BASE, 0x0006, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  41. #define IOCTL_DISK_REASSIGN_BLOCKS CTL_CODE(IOCTL_DISK_BASE, 0x0007, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  42. #define IOCTL_DISK_PERFORMANCE CTL_CODE(IOCTL_DISK_BASE, 0x0008, METHOD_BUFFERED, FILE_ANY_ACCESS)
  43. #define IOCTL_DISK_IS_WRITABLE CTL_CODE(IOCTL_DISK_BASE, 0x0009, METHOD_BUFFERED, FILE_ANY_ACCESS)
  44. #define IOCTL_DISK_LOGGING CTL_CODE(IOCTL_DISK_BASE, 0x000a, METHOD_BUFFERED, FILE_ANY_ACCESS)
  45. #define IOCTL_DISK_FORMAT_TRACKS_EX CTL_CODE(IOCTL_DISK_BASE, 0x000b, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  46. #define IOCTL_DISK_HISTOGRAM_STRUCTURE CTL_CODE(IOCTL_DISK_BASE, 0x000c, METHOD_BUFFERED, FILE_ANY_ACCESS)
  47. #define IOCTL_DISK_HISTOGRAM_DATA CTL_CODE(IOCTL_DISK_BASE, 0x000d, METHOD_BUFFERED, FILE_ANY_ACCESS)
  48. #define IOCTL_DISK_HISTOGRAM_RESET CTL_CODE(IOCTL_DISK_BASE, 0x000e, METHOD_BUFFERED, FILE_ANY_ACCESS)
  49. #define IOCTL_DISK_REQUEST_STRUCTURE CTL_CODE(IOCTL_DISK_BASE, 0x000f, METHOD_BUFFERED, FILE_ANY_ACCESS)
  50. #define IOCTL_DISK_REQUEST_DATA CTL_CODE(IOCTL_DISK_BASE, 0x0010, METHOD_BUFFERED, FILE_ANY_ACCESS)
  51. #define IOCTL_DISK_PERFORMANCE_OFF CTL_CODE(IOCTL_DISK_BASE, 0x0018, METHOD_BUFFERED, FILE_ANY_ACCESS)
  52. #if(_WIN32_WINNT >= 0x0400)
  53. #define IOCTL_DISK_CONTROLLER_NUMBER CTL_CODE(IOCTL_DISK_BASE, 0x0011, METHOD_BUFFERED, FILE_ANY_ACCESS)
  54. //
  55. // IOCTL support for SMART drive fault prediction.
  56. //
  57. #define SMART_GET_VERSION CTL_CODE(IOCTL_DISK_BASE, 0x0020, METHOD_BUFFERED, FILE_READ_ACCESS)
  58. #define SMART_SEND_DRIVE_COMMAND CTL_CODE(IOCTL_DISK_BASE, 0x0021, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  59. #define SMART_RCV_DRIVE_DATA CTL_CODE(IOCTL_DISK_BASE, 0x0022, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  60. #endif /* _WIN32_WINNT >= 0x0400 */
  61. #if (_WIN32_WINNT >= 0x500)
  62. //
  63. // New IOCTLs for GUID Partition tabled disks.
  64. //
  65. #define IOCTL_DISK_GET_PARTITION_INFO_EX CTL_CODE(IOCTL_DISK_BASE, 0x0012, METHOD_BUFFERED, FILE_ANY_ACCESS)
  66. #define IOCTL_DISK_SET_PARTITION_INFO_EX CTL_CODE(IOCTL_DISK_BASE, 0x0013, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  67. #define IOCTL_DISK_GET_DRIVE_LAYOUT_EX CTL_CODE(IOCTL_DISK_BASE, 0x0014, METHOD_BUFFERED, FILE_ANY_ACCESS)
  68. #define IOCTL_DISK_SET_DRIVE_LAYOUT_EX CTL_CODE(IOCTL_DISK_BASE, 0x0015, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  69. #define IOCTL_DISK_CREATE_DISK CTL_CODE(IOCTL_DISK_BASE, 0x0016, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  70. #define IOCTL_DISK_GET_LENGTH_INFO CTL_CODE(IOCTL_DISK_BASE, 0x0017, METHOD_BUFFERED, FILE_READ_ACCESS)
  71. #define IOCTL_DISK_GET_DRIVE_GEOMETRY_EX CTL_CODE(IOCTL_DISK_BASE, 0x0028, METHOD_BUFFERED, FILE_ANY_ACCESS)
  72. #endif /* _WIN32_WINNT >= 0x0500 */
  73. #if(_WIN32_WINNT >= 0x0500)
  74. #define IOCTL_DISK_UPDATE_DRIVE_SIZE CTL_CODE(IOCTL_DISK_BASE, 0x0032, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  75. #define IOCTL_DISK_GROW_PARTITION CTL_CODE(IOCTL_DISK_BASE, 0x0034, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  76. #define IOCTL_DISK_GET_CACHE_INFORMATION CTL_CODE(IOCTL_DISK_BASE, 0x0035, METHOD_BUFFERED, FILE_READ_ACCESS)
  77. #define IOCTL_DISK_SET_CACHE_INFORMATION CTL_CODE(IOCTL_DISK_BASE, 0x0036, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  78. #define OBSOLETE_DISK_GET_WRITE_CACHE_STATE CTL_CODE(IOCTL_DISK_BASE, 0x0037, METHOD_BUFFERED, FILE_READ_ACCESS)
  79. #define IOCTL_DISK_DELETE_DRIVE_LAYOUT CTL_CODE(IOCTL_DISK_BASE, 0x0040, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  80. //
  81. // Called to flush cached information that the driver may have about this
  82. // device's characteristics. Not all drivers cache characteristics, and not
  83. // cached properties can be flushed. This simply serves as an update to the
  84. // driver that it may want to do an expensive reexamination of the device's
  85. // characteristics now (fixed media size, partition table, etc...)
  86. //
  87. #define IOCTL_DISK_UPDATE_PROPERTIES CTL_CODE(IOCTL_DISK_BASE, 0x0050, METHOD_BUFFERED, FILE_ANY_ACCESS)
  88. //
  89. // Special IOCTLs needed to support PC-98 machines in Japan
  90. //
  91. #define IOCTL_DISK_FORMAT_DRIVE CTL_CODE(IOCTL_DISK_BASE, 0x00f3, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  92. #define IOCTL_DISK_SENSE_DEVICE CTL_CODE(IOCTL_DISK_BASE, 0x00f8, METHOD_BUFFERED, FILE_ANY_ACCESS)
  93. #endif /* _WIN32_WINNT >= 0x0500 */
  94. // end_winioctl
  95. //
  96. // IOCTLs to report and modify our caching behavior
  97. //
  98. #define IOCTL_DISK_GET_CACHE_SETTING CTL_CODE(IOCTL_DISK_BASE, 0x0038, METHOD_BUFFERED, FILE_READ_ACCESS)
  99. #define IOCTL_DISK_SET_CACHE_SETTING CTL_CODE(IOCTL_DISK_BASE, 0x0039, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  100. typedef enum _DISK_CACHE_STATE
  101. {
  102. DiskCacheNormal,
  103. DiskCacheWriteThroughNotSupported,
  104. DiskCacheModifyUnsuccessful
  105. } DISK_CACHE_STATE, *PDISK_CACHE_STATE;
  106. typedef struct _DISK_CACHE_SETTING
  107. {
  108. //
  109. // The size of this structure is used for versioning
  110. //
  111. ULONG Version;
  112. //
  113. // Indicates whether there are any issues with the disk cache
  114. //
  115. DISK_CACHE_STATE State;
  116. //
  117. // Indicates whether the disk cache is power protected or not
  118. //
  119. BOOLEAN IsPowerProtected;
  120. } DISK_CACHE_SETTING, *PDISK_CACHE_SETTING;
  121. //
  122. // IOCTL for moving copying a run of sectors from one location of the disk
  123. // to another. The caller of this IOCTL needs to be prepared for the call to
  124. // fail and do the copy manually since this IOCTL will only rarely be
  125. // implemented.
  126. //
  127. #define IOCTL_DISK_COPY_DATA CTL_CODE(IOCTL_DISK_BASE, 0x0019, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  128. //
  129. // This structure is passed in for a IOCTL_DISK_COPY_DATA call.
  130. //
  131. typedef struct _DISK_COPY_DATA_PARAMETERS {
  132. LARGE_INTEGER SourceOffset;
  133. LARGE_INTEGER DestinationOffset;
  134. LARGE_INTEGER CopyLength;
  135. ULONGLONG Reserved; // Must be 0.
  136. } DISK_COPY_DATA_PARAMETERS, *PDISK_COPY_DATA_PARAMETERS;
  137. //
  138. // Internal disk driver device controls to maintain the verify status bit
  139. // for the device object.
  140. //
  141. #define IOCTL_DISK_INTERNAL_SET_VERIFY CTL_CODE(IOCTL_DISK_BASE, 0x0100, METHOD_NEITHER, FILE_ANY_ACCESS)
  142. #define IOCTL_DISK_INTERNAL_CLEAR_VERIFY CTL_CODE(IOCTL_DISK_BASE, 0x0101, METHOD_NEITHER, FILE_ANY_ACCESS)
  143. //
  144. // Internal disk driver device control to set notification routine for
  145. // the device object. Used in DiskPerf.
  146. //
  147. #define IOCTL_DISK_INTERNAL_SET_NOTIFY CTL_CODE(IOCTL_DISK_BASE, 0x0102, METHOD_BUFFERED, FILE_ANY_ACCESS)
  148. // begin_winioctl
  149. //
  150. // The following device control codes are common for all class drivers. The
  151. // functions codes defined here must match all of the other class drivers.
  152. //
  153. // Warning: these codes will be replaced in the future by equivalent
  154. // IOCTL_STORAGE codes
  155. //
  156. #define IOCTL_DISK_CHECK_VERIFY CTL_CODE(IOCTL_DISK_BASE, 0x0200, METHOD_BUFFERED, FILE_READ_ACCESS)
  157. #define IOCTL_DISK_MEDIA_REMOVAL CTL_CODE(IOCTL_DISK_BASE, 0x0201, METHOD_BUFFERED, FILE_READ_ACCESS)
  158. #define IOCTL_DISK_EJECT_MEDIA CTL_CODE(IOCTL_DISK_BASE, 0x0202, METHOD_BUFFERED, FILE_READ_ACCESS)
  159. #define IOCTL_DISK_LOAD_MEDIA CTL_CODE(IOCTL_DISK_BASE, 0x0203, METHOD_BUFFERED, FILE_READ_ACCESS)
  160. #define IOCTL_DISK_RESERVE CTL_CODE(IOCTL_DISK_BASE, 0x0204, METHOD_BUFFERED, FILE_READ_ACCESS)
  161. #define IOCTL_DISK_RELEASE CTL_CODE(IOCTL_DISK_BASE, 0x0205, METHOD_BUFFERED, FILE_READ_ACCESS)
  162. #define IOCTL_DISK_FIND_NEW_DEVICES CTL_CODE(IOCTL_DISK_BASE, 0x0206, METHOD_BUFFERED, FILE_READ_ACCESS)
  163. #define IOCTL_DISK_GET_MEDIA_TYPES CTL_CODE(IOCTL_DISK_BASE, 0x0300, METHOD_BUFFERED, FILE_ANY_ACCESS)
  164. // end_winioctl
  165. //
  166. // The following file contains the IOCTL_STORAGE class ioctls
  167. //
  168. #include <ntddstor.h>
  169. // begin_winioctl
  170. //
  171. // Define the partition types returnable by known disk drivers.
  172. //
  173. #define PARTITION_ENTRY_UNUSED 0x00 // Entry unused
  174. #define PARTITION_FAT_12 0x01 // 12-bit FAT entries
  175. #define PARTITION_XENIX_1 0x02 // Xenix
  176. #define PARTITION_XENIX_2 0x03 // Xenix
  177. #define PARTITION_FAT_16 0x04 // 16-bit FAT entries
  178. #define PARTITION_EXTENDED 0x05 // Extended partition entry
  179. #define PARTITION_HUGE 0x06 // Huge partition MS-DOS V4
  180. #define PARTITION_IFS 0x07 // IFS Partition
  181. #define PARTITION_OS2BOOTMGR 0x0A // OS/2 Boot Manager/OPUS/Coherent swap
  182. #define PARTITION_FAT32 0x0B // FAT32
  183. #define PARTITION_FAT32_XINT13 0x0C // FAT32 using extended int13 services
  184. #define PARTITION_XINT13 0x0E // Win95 partition using extended int13 services
  185. #define PARTITION_XINT13_EXTENDED 0x0F // Same as type 5 but uses extended int13 services
  186. #define PARTITION_PREP 0x41 // PowerPC Reference Platform (PReP) Boot Partition
  187. #define PARTITION_LDM 0x42 // Logical Disk Manager partition
  188. #define PARTITION_UNIX 0x63 // Unix
  189. #define VALID_NTFT 0xC0 // NTFT uses high order bits
  190. //
  191. // The high bit of the partition type code indicates that a partition
  192. // is part of an NTFT mirror or striped array.
  193. //
  194. #define PARTITION_NTFT 0x80 // NTFT partition
  195. //
  196. // The following macro is used to determine which partitions should be
  197. // assigned drive letters.
  198. //
  199. //++
  200. //
  201. // BOOLEAN
  202. // IsRecognizedPartition(
  203. // IN ULONG PartitionType
  204. // )
  205. //
  206. // Routine Description:
  207. //
  208. // This macro is used to determine to which partitions drive letters
  209. // should be assigned.
  210. //
  211. // Arguments:
  212. //
  213. // PartitionType - Supplies the type of the partition being examined.
  214. //
  215. // Return Value:
  216. //
  217. // The return value is TRUE if the partition type is recognized,
  218. // otherwise FALSE is returned.
  219. //
  220. //--
  221. #define IsRecognizedPartition( PartitionType ) ( \
  222. ((PartitionType & PARTITION_NTFT) && ((PartitionType & ~0xC0) == PARTITION_FAT_12)) || \
  223. ((PartitionType & PARTITION_NTFT) && ((PartitionType & ~0xC0) == PARTITION_IFS)) || \
  224. ((PartitionType & PARTITION_NTFT) && ((PartitionType & ~0xC0) == PARTITION_HUGE)) || \
  225. ((PartitionType & PARTITION_NTFT) && ((PartitionType & ~0xC0) == PARTITION_FAT32)) || \
  226. ((PartitionType & PARTITION_NTFT) && ((PartitionType & ~0xC0) == PARTITION_FAT32_XINT13)) || \
  227. ((PartitionType & PARTITION_NTFT) && ((PartitionType & ~0xC0) == PARTITION_XINT13)) || \
  228. ((PartitionType) == PARTITION_FAT_12) || \
  229. ((PartitionType) == PARTITION_FAT_16) || \
  230. ((PartitionType) == PARTITION_IFS) || \
  231. ((PartitionType) == PARTITION_HUGE) || \
  232. ((PartitionType) == PARTITION_FAT32) || \
  233. ((PartitionType) == PARTITION_FAT32_XINT13) || \
  234. ((PartitionType) == PARTITION_XINT13) )
  235. //++
  236. //
  237. // BOOLEAN
  238. // IsContainerPartition(
  239. // IN ULONG PartitionType
  240. // )
  241. //
  242. // Routine Description:
  243. //
  244. // This macro is used to determine to which partition types are actually
  245. // containers for other partitions (ie, extended partitions).
  246. //
  247. // Arguments:
  248. //
  249. // PartitionType - Supplies the type of the partition being examined.
  250. //
  251. // Return Value:
  252. //
  253. // The return value is TRUE if the partition type is a container,
  254. // otherwise FALSE is returned.
  255. //
  256. //--
  257. #define IsContainerPartition( PartitionType ) \
  258. ((PartitionType == PARTITION_EXTENDED) || (PartitionType == PARTITION_XINT13_EXTENDED))
  259. //++
  260. //
  261. // BOOLEAN
  262. // IsFTPartition(
  263. // IN ULONG PartitionType
  264. // )
  265. //
  266. // Routine Description:
  267. //
  268. // This macro is used to determine if the given partition is an FT
  269. // partition.
  270. //
  271. // Arguments:
  272. //
  273. // PartitionType - Supplies the type of the partition being examined.
  274. //
  275. // Return Value:
  276. //
  277. // The return value is TRUE if the partition type is an FT partition,
  278. // otherwise FALSE is returned.
  279. //
  280. //--
  281. #define IsFTPartition( PartitionType ) \
  282. (((PartitionType)&PARTITION_NTFT) && IsRecognizedPartition(PartitionType))
  283. //
  284. // Define the media types supported by the driver.
  285. //
  286. typedef enum _MEDIA_TYPE {
  287. Unknown, // Format is unknown
  288. F5_1Pt2_512, // 5.25", 1.2MB, 512 bytes/sector
  289. F3_1Pt44_512, // 3.5", 1.44MB, 512 bytes/sector
  290. F3_2Pt88_512, // 3.5", 2.88MB, 512 bytes/sector
  291. F3_20Pt8_512, // 3.5", 20.8MB, 512 bytes/sector
  292. F3_720_512, // 3.5", 720KB, 512 bytes/sector
  293. F5_360_512, // 5.25", 360KB, 512 bytes/sector
  294. F5_320_512, // 5.25", 320KB, 512 bytes/sector
  295. F5_320_1024, // 5.25", 320KB, 1024 bytes/sector
  296. F5_180_512, // 5.25", 180KB, 512 bytes/sector
  297. F5_160_512, // 5.25", 160KB, 512 bytes/sector
  298. RemovableMedia, // Removable media other than floppy
  299. FixedMedia, // Fixed hard disk media
  300. F3_120M_512, // 3.5", 120M Floppy
  301. F3_640_512, // 3.5" , 640KB, 512 bytes/sector
  302. F5_640_512, // 5.25", 640KB, 512 bytes/sector
  303. F5_720_512, // 5.25", 720KB, 512 bytes/sector
  304. F3_1Pt2_512, // 3.5" , 1.2Mb, 512 bytes/sector
  305. F3_1Pt23_1024, // 3.5" , 1.23Mb, 1024 bytes/sector
  306. F5_1Pt23_1024, // 5.25", 1.23MB, 1024 bytes/sector
  307. F3_128Mb_512, // 3.5" MO 128Mb 512 bytes/sector
  308. F3_230Mb_512, // 3.5" MO 230Mb 512 bytes/sector
  309. F8_256_128, // 8", 256KB, 128 bytes/sector
  310. F3_200Mb_512, // 3.5", 200M Floppy (HiFD)
  311. F3_240M_512, // 3.5", 240Mb Floppy (HiFD)
  312. F3_32M_512 // 3.5", 32Mb Floppy
  313. } MEDIA_TYPE, *PMEDIA_TYPE;
  314. //
  315. // Define the input buffer structure for the driver, when
  316. // it is called with IOCTL_DISK_FORMAT_TRACKS.
  317. //
  318. typedef struct _FORMAT_PARAMETERS {
  319. MEDIA_TYPE MediaType;
  320. ULONG StartCylinderNumber;
  321. ULONG EndCylinderNumber;
  322. ULONG StartHeadNumber;
  323. ULONG EndHeadNumber;
  324. } FORMAT_PARAMETERS, *PFORMAT_PARAMETERS;
  325. //
  326. // Define the BAD_TRACK_NUMBER type. An array of elements of this type is
  327. // returned by the driver on IOCTL_DISK_FORMAT_TRACKS requests, to indicate
  328. // what tracks were bad during formatting. The length of that array is
  329. // reported in the `Information' field of the I/O Status Block.
  330. //
  331. typedef USHORT BAD_TRACK_NUMBER;
  332. typedef USHORT *PBAD_TRACK_NUMBER;
  333. //
  334. // Define the input buffer structure for the driver, when
  335. // it is called with IOCTL_DISK_FORMAT_TRACKS_EX.
  336. //
  337. typedef struct _FORMAT_EX_PARAMETERS {
  338. MEDIA_TYPE MediaType;
  339. ULONG StartCylinderNumber;
  340. ULONG EndCylinderNumber;
  341. ULONG StartHeadNumber;
  342. ULONG EndHeadNumber;
  343. USHORT FormatGapLength;
  344. USHORT SectorsPerTrack;
  345. USHORT SectorNumber[1];
  346. } FORMAT_EX_PARAMETERS, *PFORMAT_EX_PARAMETERS;
  347. //
  348. // The following structure is returned on an IOCTL_DISK_GET_DRIVE_GEOMETRY
  349. // request and an array of them is returned on an IOCTL_DISK_GET_MEDIA_TYPES
  350. // request.
  351. //
  352. typedef struct _DISK_GEOMETRY {
  353. LARGE_INTEGER Cylinders;
  354. MEDIA_TYPE MediaType;
  355. ULONG TracksPerCylinder;
  356. ULONG SectorsPerTrack;
  357. ULONG BytesPerSector;
  358. } DISK_GEOMETRY, *PDISK_GEOMETRY;
  359. //
  360. // This wmi guid returns a DISK_GEOMETRY structure
  361. //
  362. #define WMI_DISK_GEOMETRY_GUID { 0x25007f51, 0x57c2, 0x11d1, { 0xa5, 0x28, 0x0, 0xa0, 0xc9, 0x6, 0x29, 0x10 } }
  363. //
  364. // The following structure is returned on an IOCTL_DISK_GET_PARTITION_INFO
  365. // and an IOCTL_DISK_GET_DRIVE_LAYOUT request. It is also used in a request
  366. // to change the drive layout, IOCTL_DISK_SET_DRIVE_LAYOUT.
  367. //
  368. typedef struct _PARTITION_INFORMATION {
  369. LARGE_INTEGER StartingOffset;
  370. LARGE_INTEGER PartitionLength;
  371. ULONG HiddenSectors;
  372. ULONG PartitionNumber;
  373. UCHAR PartitionType;
  374. BOOLEAN BootIndicator;
  375. BOOLEAN RecognizedPartition;
  376. BOOLEAN RewritePartition;
  377. } PARTITION_INFORMATION, *PPARTITION_INFORMATION;
  378. //
  379. // The following structure is used to change the partition type of a
  380. // specified disk partition using an IOCTL_DISK_SET_PARTITION_INFO
  381. // request.
  382. //
  383. typedef struct _SET_PARTITION_INFORMATION {
  384. UCHAR PartitionType;
  385. } SET_PARTITION_INFORMATION, *PSET_PARTITION_INFORMATION;
  386. //
  387. // The following structures is returned on an IOCTL_DISK_GET_DRIVE_LAYOUT
  388. // request and given as input to an IOCTL_DISK_SET_DRIVE_LAYOUT request.
  389. //
  390. typedef struct _DRIVE_LAYOUT_INFORMATION {
  391. ULONG PartitionCount;
  392. ULONG Signature;
  393. PARTITION_INFORMATION PartitionEntry[1];
  394. } DRIVE_LAYOUT_INFORMATION, *PDRIVE_LAYOUT_INFORMATION;
  395. //
  396. // The following structure is passed in on an IOCTL_DISK_VERIFY request.
  397. // The offset and length parameters are both given in bytes.
  398. //
  399. typedef struct _VERIFY_INFORMATION {
  400. LARGE_INTEGER StartingOffset;
  401. ULONG Length;
  402. } VERIFY_INFORMATION, *PVERIFY_INFORMATION;
  403. //
  404. // The following structure is passed in on an IOCTL_DISK_REASSIGN_BLOCKS
  405. // request.
  406. //
  407. typedef struct _REASSIGN_BLOCKS {
  408. USHORT Reserved;
  409. USHORT Count;
  410. ULONG BlockNumber[1];
  411. } REASSIGN_BLOCKS, *PREASSIGN_BLOCKS;
  412. #if(_WIN32_WINNT >= 0x500)
  413. //
  414. // Support for GUID Partition Table (GPT) disks.
  415. //
  416. //
  417. // There are currently two ways a disk can be partitioned. With a traditional
  418. // AT-style master boot record (PARTITION_STYLE_MBR) and with a new, GPT
  419. // partition table (PARTITION_STYLE_GPT). RAW is for an unrecognizable
  420. // partition style. There are a very limited number of things you can
  421. // do with a RAW partititon.
  422. //
  423. typedef enum _PARTITION_STYLE {
  424. PARTITION_STYLE_MBR,
  425. PARTITION_STYLE_GPT,
  426. PARTITION_STYLE_RAW
  427. } PARTITION_STYLE;
  428. //
  429. // The following structure defines information in a GPT partition that is
  430. // not common to both GPT and MBR partitions.
  431. //
  432. typedef struct _PARTITION_INFORMATION_GPT {
  433. GUID PartitionType; // Partition type. See table 16-3.
  434. GUID PartitionId; // Unique GUID for this partition.
  435. ULONG64 Attributes; // See table 16-4.
  436. WCHAR Name [36]; // Partition Name in Unicode.
  437. } PARTITION_INFORMATION_GPT, *PPARTITION_INFORMATION_GPT;
  438. //
  439. // The following are GPT partition attributes applicable for any
  440. // partition type. These attributes are not OS-specific
  441. //
  442. #define GPT_ATTRIBUTE_PLATFORM_REQUIRED (0x0000000000000001)
  443. //
  444. // The following are GPT partition attributes applicable when the
  445. // PartitionType is PARTITION_BASIC_DATA_GUID.
  446. //
  447. #define GPT_BASIC_DATA_ATTRIBUTE_NO_DRIVE_LETTER (0x8000000000000000)
  448. #define GPT_BASIC_DATA_ATTRIBUTE_HIDDEN (0x4000000000000000)
  449. #define GPT_BASIC_DATA_ATTRIBUTE_READ_ONLY (0x1000000000000000)
  450. //
  451. // The following structure defines information in an MBR partition that is not
  452. // common to both GPT and MBR partitions.
  453. //
  454. typedef struct _PARTITION_INFORMATION_MBR {
  455. UCHAR PartitionType;
  456. BOOLEAN BootIndicator;
  457. BOOLEAN RecognizedPartition;
  458. ULONG HiddenSectors;
  459. } PARTITION_INFORMATION_MBR, *PPARTITION_INFORMATION_MBR;
  460. //
  461. // The structure SET_PARTITION_INFO_EX is used with the ioctl
  462. // IOCTL_SET_PARTITION_INFO_EX to set information about a specific
  463. // partition. Note that for MBR partitions, you can only set the partition
  464. // signature, whereas GPT partitions allow setting of all fields that
  465. // you can get.
  466. //
  467. typedef SET_PARTITION_INFORMATION SET_PARTITION_INFORMATION_MBR;
  468. typedef PARTITION_INFORMATION_GPT SET_PARTITION_INFORMATION_GPT;
  469. typedef struct _SET_PARTITION_INFORMATION_EX {
  470. PARTITION_STYLE PartitionStyle;
  471. union {
  472. SET_PARTITION_INFORMATION_MBR Mbr;
  473. SET_PARTITION_INFORMATION_GPT Gpt;
  474. };
  475. } SET_PARTITION_INFORMATION_EX, *PSET_PARTITION_INFORMATION_EX;
  476. //
  477. // The structure CREATE_DISK_GPT with the ioctl IOCTL_DISK_CREATE_DISK
  478. // to initialize an virgin disk with an empty GPT partition table.
  479. //
  480. typedef struct _CREATE_DISK_GPT {
  481. GUID DiskId; // Unique disk id for the disk.
  482. ULONG MaxPartitionCount; // Maximim number of partitions allowable.
  483. } CREATE_DISK_GPT, *PCREATE_DISK_GPT;
  484. //
  485. // The structure CREATE_DISK_MBR with the ioctl IOCTL_DISK_CREATE_DISK
  486. // to initialize an virgin disk with an empty MBR partition table.
  487. //
  488. typedef struct _CREATE_DISK_MBR {
  489. ULONG Signature;
  490. } CREATE_DISK_MBR, *PCREATE_DISK_MBR;
  491. typedef struct _CREATE_DISK {
  492. PARTITION_STYLE PartitionStyle;
  493. union {
  494. CREATE_DISK_MBR Mbr;
  495. CREATE_DISK_GPT Gpt;
  496. };
  497. } CREATE_DISK, *PCREATE_DISK;
  498. //
  499. // The structure GET_LENGTH_INFORMATION is used with the ioctl
  500. // IOCTL_DISK_GET_LENGTH_INFO to obtain the length, in bytes, of the
  501. // disk, partition, or volume.
  502. //
  503. typedef struct _GET_LENGTH_INFORMATION {
  504. LARGE_INTEGER Length;
  505. } GET_LENGTH_INFORMATION, *PGET_LENGTH_INFORMATION;
  506. //
  507. // The PARTITION_INFORMATION_EX structure is used with the
  508. // IOCTL_DISK_GET_DRIVE_LAYOUT_EX, IOCTL_DISK_SET_DRIVE_LAYOUT_EX,
  509. // IOCTL_DISK_GET_PARTITION_INFO_EX and IOCTL_DISK_GET_PARTITION_INFO_EX calls.
  510. //
  511. typedef struct _PARTITION_INFORMATION_EX {
  512. PARTITION_STYLE PartitionStyle;
  513. LARGE_INTEGER StartingOffset;
  514. LARGE_INTEGER PartitionLength;
  515. ULONG PartitionNumber;
  516. BOOLEAN RewritePartition;
  517. union {
  518. PARTITION_INFORMATION_MBR Mbr;
  519. PARTITION_INFORMATION_GPT Gpt;
  520. };
  521. } PARTITION_INFORMATION_EX, *PPARTITION_INFORMATION_EX;
  522. //
  523. // GPT specific drive layout information.
  524. //
  525. typedef struct _DRIVE_LAYOUT_INFORMATION_GPT {
  526. GUID DiskId;
  527. LARGE_INTEGER StartingUsableOffset;
  528. LARGE_INTEGER UsableLength;
  529. ULONG MaxPartitionCount;
  530. } DRIVE_LAYOUT_INFORMATION_GPT, *PDRIVE_LAYOUT_INFORMATION_GPT;
  531. //
  532. // MBR specific drive layout information.
  533. //
  534. typedef struct _DRIVE_LAYOUT_INFORMATION_MBR {
  535. ULONG Signature;
  536. } DRIVE_LAYOUT_INFORMATION_MBR, *PDRIVE_LAYOUT_INFORMATION_MBR;
  537. //
  538. // The structure DRIVE_LAYOUT_INFORMATION_EX is used with the
  539. // IOCTL_SET_DRIVE_LAYOUT_EX and IOCTL_GET_DRIVE_LAYOUT_EX calls.
  540. //
  541. typedef struct _DRIVE_LAYOUT_INFORMATION_EX {
  542. ULONG PartitionStyle;
  543. ULONG PartitionCount;
  544. union {
  545. DRIVE_LAYOUT_INFORMATION_MBR Mbr;
  546. DRIVE_LAYOUT_INFORMATION_GPT Gpt;
  547. };
  548. PARTITION_INFORMATION_EX PartitionEntry[1];
  549. } DRIVE_LAYOUT_INFORMATION_EX, *PDRIVE_LAYOUT_INFORMATION_EX;
  550. #endif // (_WIN32_WINNT >= 0x0500)
  551. #if(_WIN32_WINNT >= 0x0500)
  552. //
  553. // The DISK_GEOMETRY_EX structure is returned on issuing an
  554. // IOCTL_DISK_GET_DRIVE_GEOMETRY_EX ioctl.
  555. //
  556. typedef enum _DETECTION_TYPE {
  557. DetectNone,
  558. DetectInt13,
  559. DetectExInt13
  560. } DETECTION_TYPE;
  561. typedef struct _DISK_INT13_INFO {
  562. USHORT DriveSelect;
  563. ULONG MaxCylinders;
  564. USHORT SectorsPerTrack;
  565. USHORT MaxHeads;
  566. USHORT NumberDrives;
  567. } DISK_INT13_INFO, *PDISK_INT13_INFO;
  568. typedef struct _DISK_EX_INT13_INFO {
  569. USHORT ExBufferSize;
  570. USHORT ExFlags;
  571. ULONG ExCylinders;
  572. ULONG ExHeads;
  573. ULONG ExSectorsPerTrack;
  574. ULONG64 ExSectorsPerDrive;
  575. USHORT ExSectorSize;
  576. USHORT ExReserved;
  577. } DISK_EX_INT13_INFO, *PDISK_EX_INT13_INFO;
  578. typedef struct _DISK_DETECTION_INFO {
  579. ULONG SizeOfDetectInfo;
  580. DETECTION_TYPE DetectionType;
  581. union {
  582. struct {
  583. //
  584. // If DetectionType == DETECTION_INT13 then we have just the Int13
  585. // information.
  586. //
  587. DISK_INT13_INFO Int13;
  588. //
  589. // If DetectionType == DETECTION_EX_INT13, then we have the
  590. // extended int 13 information.
  591. //
  592. DISK_EX_INT13_INFO ExInt13; // If DetectionType == DetectExInt13
  593. };
  594. };
  595. } DISK_DETECTION_INFO, *PDISK_DETECTION_INFO;
  596. typedef struct _DISK_PARTITION_INFO {
  597. ULONG SizeOfPartitionInfo;
  598. PARTITION_STYLE PartitionStyle; // PartitionStyle = RAW, GPT or MBR
  599. union {
  600. struct { // If PartitionStyle == MBR
  601. ULONG Signature; // MBR Signature
  602. ULONG CheckSum; // MBR CheckSum
  603. } Mbr;
  604. struct { // If PartitionStyle == GPT
  605. GUID DiskId;
  606. } Gpt;
  607. };
  608. } DISK_PARTITION_INFO, *PDISK_PARTITION_INFO;
  609. //
  610. // The Geometry structure is a variable length structure composed of a
  611. // DISK_GEOMETRY_EX structure followed by a DISK_PARTITION_INFO structure
  612. // followed by a DISK_DETECTION_DATA structure.
  613. //
  614. #define DiskGeometryGetPartition(Geometry)\
  615. ((PDISK_PARTITION_INFO)((Geometry)->Data))
  616. #define DiskGeometryGetDetect(Geometry)\
  617. ((PDISK_DETECTION_INFO)(((ULONG_PTR)DiskGeometryGetPartition(Geometry)+\
  618. DiskGeometryGetPartition(Geometry)->SizeOfPartitionInfo)))
  619. typedef struct _DISK_GEOMETRY_EX {
  620. DISK_GEOMETRY Geometry; // Standard disk geometry: may be faked by driver.
  621. LARGE_INTEGER DiskSize; // Must always be correct
  622. UCHAR Data[1]; // Partition, Detect info
  623. } DISK_GEOMETRY_EX, *PDISK_GEOMETRY_EX;
  624. #endif // (_WIN32_WINNT > 0x0500)
  625. #if(_WIN32_WINNT >= 0x0400)
  626. //
  627. // IOCTL_DISK_CONTROLLER_NUMBER returns the controller and disk
  628. // number for the handle. This is used to determine if a disk
  629. // is attached to the primary or secondary IDE controller.
  630. //
  631. typedef struct _DISK_CONTROLLER_NUMBER {
  632. ULONG ControllerNumber;
  633. ULONG DiskNumber;
  634. } DISK_CONTROLLER_NUMBER, *PDISK_CONTROLLER_NUMBER;
  635. #endif /* _WIN32_WINNT >= 0x0400 */
  636. #if(_WIN32_WINNT >= 0x0500)
  637. //
  638. // IOCTL_DISK_SET_CACHE allows the caller to get or set the state of the disk
  639. // read/write caches.
  640. //
  641. // If the structure is provided as the input buffer for the ioctl the read &
  642. // write caches will be enabled or disabled depending on the parameters
  643. // provided.
  644. //
  645. // If the structure is provided as an output buffer for the ioctl the state
  646. // of the read & write caches will be returned. If both input and outut buffers
  647. // are provided the output buffer will contain the cache state BEFORE any
  648. // changes are made
  649. //
  650. typedef enum {
  651. EqualPriority,
  652. KeepPrefetchedData,
  653. KeepReadData
  654. } DISK_CACHE_RETENTION_PRIORITY;
  655. typedef struct _DISK_CACHE_INFORMATION {
  656. //
  657. // on return indicates that the device is capable of saving any parameters
  658. // in non-volatile storage. On send indicates that the device should
  659. // save the state in non-volatile storage.
  660. //
  661. BOOLEAN ParametersSavable;
  662. //
  663. // Indicates whether the write and read caches are enabled.
  664. //
  665. BOOLEAN ReadCacheEnabled;
  666. BOOLEAN WriteCacheEnabled;
  667. //
  668. // Controls the likelyhood of data remaining in the cache depending on how
  669. // it got there. Data cached from a READ or WRITE operation may be given
  670. // higher, lower or equal priority to data entered into the cache for other
  671. // means (like prefetch)
  672. //
  673. DISK_CACHE_RETENTION_PRIORITY ReadRetentionPriority;
  674. DISK_CACHE_RETENTION_PRIORITY WriteRetentionPriority;
  675. //
  676. // Requests for a larger number of blocks than this may have prefetching
  677. // disabled. If this value is set to 0 prefetch will be disabled.
  678. //
  679. USHORT DisablePrefetchTransferLength;
  680. //
  681. // If TRUE then ScalarPrefetch (below) will be valid. If FALSE then
  682. // the minimum and maximum values should be treated as a block count
  683. // (BlockPrefetch)
  684. //
  685. BOOLEAN PrefetchScalar;
  686. //
  687. // Contains the minimum and maximum amount of data which will be
  688. // will be prefetched into the cache on a disk operation. This value
  689. // may either be a scalar multiplier of the transfer length of the request,
  690. // or an abolute number of disk blocks. PrefetchScalar (above) indicates
  691. // which interpretation is used.
  692. //
  693. union {
  694. struct {
  695. USHORT Minimum;
  696. USHORT Maximum;
  697. //
  698. // The maximum number of blocks which will be prefetched - useful
  699. // with the scalar limits to set definite upper limits.
  700. //
  701. USHORT MaximumBlocks;
  702. } ScalarPrefetch;
  703. struct {
  704. USHORT Minimum;
  705. USHORT Maximum;
  706. } BlockPrefetch;
  707. };
  708. } DISK_CACHE_INFORMATION, *PDISK_CACHE_INFORMATION;
  709. //
  710. // IOCTL_DISK_GROW_PARTITION will update the size of a partition
  711. // by adding sectors to the length. The number of sectors must be
  712. // predetermined by examining PARTITION_INFORMATION.
  713. //
  714. typedef struct _DISK_GROW_PARTITION {
  715. ULONG PartitionNumber;
  716. LARGE_INTEGER BytesToGrow;
  717. } DISK_GROW_PARTITION, *PDISK_GROW_PARTITION;
  718. #endif /* _WIN32_WINNT >= 0x0500 */
  719. ///////////////////////////////////////////////////////
  720. // //
  721. // The following structures define disk performance //
  722. // statistics: specifically the locations of all the //
  723. // reads and writes which have occured on the disk. //
  724. // //
  725. // To use these structures, you must issue an IOCTL_ //
  726. // DISK_HIST_STRUCTURE (with a DISK_HISTOGRAM) to //
  727. // obtain the basic histogram information. The //
  728. // number of buckets which must allocated is part of //
  729. // this structure. Allocate the required number of //
  730. // buckets and call an IOCTL_DISK_HIST_DATA to fill //
  731. // in the data //
  732. // //
  733. ///////////////////////////////////////////////////////
  734. #define HIST_NO_OF_BUCKETS 24
  735. typedef struct _HISTOGRAM_BUCKET {
  736. ULONG Reads;
  737. ULONG Writes;
  738. } HISTOGRAM_BUCKET, *PHISTOGRAM_BUCKET;
  739. #define HISTOGRAM_BUCKET_SIZE sizeof(HISTOGRAM_BUCKET)
  740. typedef struct _DISK_HISTOGRAM {
  741. LARGE_INTEGER DiskSize;
  742. LARGE_INTEGER Start;
  743. LARGE_INTEGER End;
  744. LARGE_INTEGER Average;
  745. LARGE_INTEGER AverageRead;
  746. LARGE_INTEGER AverageWrite;
  747. ULONG Granularity;
  748. ULONG Size;
  749. ULONG ReadCount;
  750. ULONG WriteCount;
  751. PHISTOGRAM_BUCKET Histogram;
  752. } DISK_HISTOGRAM, *PDISK_HISTOGRAM;
  753. #define DISK_HISTOGRAM_SIZE sizeof(DISK_HISTOGRAM)
  754. ///////////////////////////////////////////////////////
  755. // //
  756. // The following structures define disk debugging //
  757. // capabilities. The IOCTLs are directed to one of //
  758. // the two disk filter drivers. //
  759. // //
  760. // DISKPERF is a utilty for collecting disk request //
  761. // statistics. //
  762. // //
  763. // SIMBAD is a utility for injecting faults in //
  764. // IO requests to disks. //
  765. // //
  766. ///////////////////////////////////////////////////////
  767. //
  768. // The following structure is exchanged on an IOCTL_DISK_GET_PERFORMANCE
  769. // request. This ioctl collects summary disk request statistics used
  770. // in measuring performance.
  771. //
  772. typedef struct _DISK_PERFORMANCE {
  773. LARGE_INTEGER BytesRead;
  774. LARGE_INTEGER BytesWritten;
  775. LARGE_INTEGER ReadTime;
  776. LARGE_INTEGER WriteTime;
  777. LARGE_INTEGER IdleTime;
  778. ULONG ReadCount;
  779. ULONG WriteCount;
  780. ULONG QueueDepth;
  781. ULONG SplitCount;
  782. LARGE_INTEGER QueryTime;
  783. ULONG StorageDeviceNumber;
  784. WCHAR StorageManagerName[8];
  785. } DISK_PERFORMANCE, *PDISK_PERFORMANCE;
  786. //
  787. // This structure defines the disk logging record. When disk logging
  788. // is enabled, one of these is written to an internal buffer for each
  789. // disk request.
  790. //
  791. typedef struct _DISK_RECORD {
  792. LARGE_INTEGER ByteOffset;
  793. LARGE_INTEGER StartTime;
  794. LARGE_INTEGER EndTime;
  795. PVOID VirtualAddress;
  796. ULONG NumberOfBytes;
  797. UCHAR DeviceNumber;
  798. BOOLEAN ReadRequest;
  799. } DISK_RECORD, *PDISK_RECORD;
  800. //
  801. // The following structure is exchanged on an IOCTL_DISK_LOG request.
  802. // Not all fields are valid with each function type.
  803. //
  804. typedef struct _DISK_LOGGING {
  805. UCHAR Function;
  806. PVOID BufferAddress;
  807. ULONG BufferSize;
  808. } DISK_LOGGING, *PDISK_LOGGING;
  809. //
  810. // Disk logging functions
  811. //
  812. // Start disk logging. Only the Function and BufferSize fields are valid.
  813. //
  814. #define DISK_LOGGING_START 0
  815. //
  816. // Stop disk logging. Only the Function field is valid.
  817. //
  818. #define DISK_LOGGING_STOP 1
  819. //
  820. // Return disk log. All fields are valid. Data will be copied from internal
  821. // buffer to buffer specified for the number of bytes requested.
  822. //
  823. #define DISK_LOGGING_DUMP 2
  824. //
  825. // DISK BINNING
  826. //
  827. // DISKPERF will keep counters for IO that falls in each of these ranges.
  828. // The application determines the number and size of the ranges.
  829. // Joe Lin wanted me to keep it flexible as possible, for instance, IO
  830. // sizes are interesting in ranges like 0-4096, 4097-16384, 16385-65536, 65537+.
  831. //
  832. #define DISK_BINNING 3
  833. //
  834. // Bin types
  835. //
  836. typedef enum _BIN_TYPES {
  837. RequestSize,
  838. RequestLocation
  839. } BIN_TYPES;
  840. //
  841. // Bin ranges
  842. //
  843. typedef struct _BIN_RANGE {
  844. LARGE_INTEGER StartValue;
  845. LARGE_INTEGER Length;
  846. } BIN_RANGE, *PBIN_RANGE;
  847. //
  848. // Bin definition
  849. //
  850. typedef struct _PERF_BIN {
  851. ULONG NumberOfBins;
  852. ULONG TypeOfBin;
  853. BIN_RANGE BinsRanges[1];
  854. } PERF_BIN, *PPERF_BIN ;
  855. //
  856. // Bin count
  857. //
  858. typedef struct _BIN_COUNT {
  859. BIN_RANGE BinRange;
  860. ULONG BinCount;
  861. } BIN_COUNT, *PBIN_COUNT;
  862. //
  863. // Bin results
  864. //
  865. typedef struct _BIN_RESULTS {
  866. ULONG NumberOfBins;
  867. BIN_COUNT BinCounts[1];
  868. } BIN_RESULTS, *PBIN_RESULTS;
  869. #if(_WIN32_WINNT >= 0x0400)
  870. //
  871. // Data structures for SMART drive fault prediction.
  872. //
  873. // GETVERSIONINPARAMS contains the data returned from the
  874. // Get Driver Version function.
  875. //
  876. #include <pshpack1.h>
  877. typedef struct _GETVERSIONINPARAMS {
  878. UCHAR bVersion; // Binary driver version.
  879. UCHAR bRevision; // Binary driver revision.
  880. UCHAR bReserved; // Not used.
  881. UCHAR bIDEDeviceMap; // Bit map of IDE devices.
  882. ULONG fCapabilities; // Bit mask of driver capabilities.
  883. ULONG dwReserved[4]; // For future use.
  884. } GETVERSIONINPARAMS, *PGETVERSIONINPARAMS, *LPGETVERSIONINPARAMS;
  885. #include <poppack.h>
  886. //
  887. // Bits returned in the fCapabilities member of GETVERSIONINPARAMS
  888. //
  889. #define CAP_ATA_ID_CMD 1 // ATA ID command supported
  890. #define CAP_ATAPI_ID_CMD 2 // ATAPI ID command supported
  891. #define CAP_SMART_CMD 4 // SMART commannds supported
  892. //
  893. // IDE registers
  894. //
  895. #include <pshpack1.h>
  896. typedef struct _IDEREGS {
  897. UCHAR bFeaturesReg; // Used for specifying SMART "commands".
  898. UCHAR bSectorCountReg; // IDE sector count register
  899. UCHAR bSectorNumberReg; // IDE sector number register
  900. UCHAR bCylLowReg; // IDE low order cylinder value
  901. UCHAR bCylHighReg; // IDE high order cylinder value
  902. UCHAR bDriveHeadReg; // IDE drive/head register
  903. UCHAR bCommandReg; // Actual IDE command.
  904. UCHAR bReserved; // reserved for future use. Must be zero.
  905. } IDEREGS, *PIDEREGS, *LPIDEREGS;
  906. #include <poppack.h>
  907. //
  908. // Valid values for the bCommandReg member of IDEREGS.
  909. //
  910. #define ATAPI_ID_CMD 0xA1 // Returns ID sector for ATAPI.
  911. #define ID_CMD 0xEC // Returns ID sector for ATA.
  912. #define SMART_CMD 0xB0 // Performs SMART cmd.
  913. // Requires valid bFeaturesReg,
  914. // bCylLowReg, and bCylHighReg
  915. //
  916. // Cylinder register defines for SMART command
  917. //
  918. #define SMART_CYL_LOW 0x4F
  919. #define SMART_CYL_HI 0xC2
  920. //
  921. // SENDCMDINPARAMS contains the input parameters for the
  922. // Send Command to Drive function.
  923. //
  924. #include <pshpack1.h>
  925. typedef struct _SENDCMDINPARAMS {
  926. ULONG cBufferSize; // Buffer size in bytes
  927. IDEREGS irDriveRegs; // Structure with drive register values.
  928. UCHAR bDriveNumber; // Physical drive number to send
  929. // command to (0,1,2,3).
  930. UCHAR bReserved[3]; // Reserved for future expansion.
  931. ULONG dwReserved[4]; // For future use.
  932. UCHAR bBuffer[1]; // Input buffer.
  933. } SENDCMDINPARAMS, *PSENDCMDINPARAMS, *LPSENDCMDINPARAMS;
  934. #include <poppack.h>
  935. //
  936. // Status returned from driver
  937. //
  938. #include <pshpack1.h>
  939. typedef struct _DRIVERSTATUS {
  940. UCHAR bDriverError; // Error code from driver,
  941. // or 0 if no error.
  942. UCHAR bIDEError; // Contents of IDE Error register.
  943. // Only valid when bDriverError
  944. // is SMART_IDE_ERROR.
  945. UCHAR bReserved[2]; // Reserved for future expansion.
  946. ULONG dwReserved[2]; // Reserved for future expansion.
  947. } DRIVERSTATUS, *PDRIVERSTATUS, *LPDRIVERSTATUS;
  948. #include <poppack.h>
  949. //
  950. // bDriverError values
  951. //
  952. #define SMART_NO_ERROR 0 // No error
  953. #define SMART_IDE_ERROR 1 // Error from IDE controller
  954. #define SMART_INVALID_FLAG 2 // Invalid command flag
  955. #define SMART_INVALID_COMMAND 3 // Invalid command byte
  956. #define SMART_INVALID_BUFFER 4 // Bad buffer (null, invalid addr..)
  957. #define SMART_INVALID_DRIVE 5 // Drive number not valid
  958. #define SMART_INVALID_IOCTL 6 // Invalid IOCTL
  959. #define SMART_ERROR_NO_MEM 7 // Could not lock user's buffer
  960. #define SMART_INVALID_REGISTER 8 // Some IDE Register not valid
  961. #define SMART_NOT_SUPPORTED 9 // Invalid cmd flag set
  962. #define SMART_NO_IDE_DEVICE 10 // Cmd issued to device not present
  963. // although drive number is valid
  964. //
  965. // SMART sub commands for execute offline diags
  966. //
  967. #define SMART_OFFLINE_ROUTINE_OFFLINE 0
  968. #define SMART_SHORT_SELFTEST_OFFLINE 1
  969. #define SMART_EXTENDED_SELFTEST_OFFLINE 2
  970. #define SMART_ABORT_OFFLINE_SELFTEST 127
  971. #define SMART_SHORT_SELFTEST_CAPTIVE 129
  972. #define SMART_EXTENDED_SELFTEST_CAPTIVE 130
  973. #include <pshpack1.h>
  974. typedef struct _SENDCMDOUTPARAMS {
  975. ULONG cBufferSize; // Size of bBuffer in bytes
  976. DRIVERSTATUS DriverStatus; // Driver status structure.
  977. UCHAR bBuffer[1]; // Buffer of arbitrary length in which to store the data read from the // drive.
  978. } SENDCMDOUTPARAMS, *PSENDCMDOUTPARAMS, *LPSENDCMDOUTPARAMS;
  979. #include <poppack.h>
  980. #define READ_ATTRIBUTE_BUFFER_SIZE 512
  981. #define IDENTIFY_BUFFER_SIZE 512
  982. #define READ_THRESHOLD_BUFFER_SIZE 512
  983. #define SMART_LOG_SECTOR_SIZE 512
  984. //
  985. // Feature register defines for SMART "sub commands"
  986. //
  987. #define READ_ATTRIBUTES 0xD0
  988. #define READ_THRESHOLDS 0xD1
  989. #define ENABLE_DISABLE_AUTOSAVE 0xD2
  990. #define SAVE_ATTRIBUTE_VALUES 0xD3
  991. #define EXECUTE_OFFLINE_DIAGS 0xD4
  992. #define SMART_READ_LOG 0xD5
  993. #define SMART_WRITE_LOG 0xd6
  994. #define ENABLE_SMART 0xD8
  995. #define DISABLE_SMART 0xD9
  996. #define RETURN_SMART_STATUS 0xDA
  997. #define ENABLE_DISABLE_AUTO_OFFLINE 0xDB
  998. #endif /* _WIN32_WINNT >= 0x0400 */
  999. // end_winioctl
  1000. //
  1001. // The following device control code is for the SIMBAD simulated bad
  1002. // sector facility. See SIMBAD.H in this directory for related structures.
  1003. //
  1004. #define IOCTL_DISK_SIMBAD CTL_CODE(IOCTL_DISK_BASE, 0x0400, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
  1005. //
  1006. // Queue link for mapped addresses stored for unmapping.
  1007. //
  1008. typedef struct _MAPPED_ADDRESS {
  1009. struct _MAPPED_ADDRESS *NextMappedAddress;
  1010. PVOID MappedAddress;
  1011. ULONG NumberOfBytes;
  1012. LARGE_INTEGER IoAddress;
  1013. ULONG BusNumber;
  1014. } MAPPED_ADDRESS, *PMAPPED_ADDRESS;
  1015. #ifdef __cplusplus
  1016. }
  1017. #endif
  1018. #endif // _NTDDDISK_H_