4 * Disk IOCTL interface.
6 * This file is part of the w32api package.
9 * Created by Casper S. Hornstrup <chorns@users.sourceforge.net>
11 * THIS SOFTWARE IS NOT COPYRIGHTED
13 * This source code is offered for use in the public domain. You may
14 * use, modify or distribute it freely.
16 * This code is distributed in the hope that it will be useful but
17 * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
18 * DISCLAIMED. This includes but is not limited to warranties of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27 #pragma GCC system_header
37 #define DD_DISK_DEVICE_NAME "\\Device\\UNKNOWN"
38 #define DD_DISK_DEVICE_NAME_U L"\\Device\\UNKNOWN"
40 #define IOCTL_DISK_BASE FILE_DEVICE_DISK
42 #define IOCTL_DISK_CHECK_VERIFY \
43 CTL_CODE(IOCTL_DISK_BASE, 0x0200, METHOD_BUFFERED, FILE_READ_ACCESS)
45 #define IOCTL_DISK_CONTROLLER_NUMBER \
46 CTL_CODE(IOCTL_DISK_BASE, 0x0011, METHOD_BUFFERED, FILE_ANY_ACCESS)
48 #define IOCTL_DISK_CREATE_DISK \
49 CTL_CODE(IOCTL_DISK_BASE, 0x0016, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
51 #define IOCTL_DISK_DELETE_DRIVE_LAYOUT \
52 CTL_CODE(IOCTL_DISK_BASE, 0x0040, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
54 #define IOCTL_DISK_FIND_NEW_DEVICES \
55 CTL_CODE(IOCTL_DISK_BASE, 0x0206, METHOD_BUFFERED, FILE_READ_ACCESS)
57 #define IOCTL_DISK_FORMAT_TRACKS \
58 CTL_CODE(IOCTL_DISK_BASE, 0x0006, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
60 #define IOCTL_DISK_FORMAT_TRACKS_EX \
61 CTL_CODE(IOCTL_DISK_BASE, 0x000b, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
63 #define IOCTL_DISK_GET_CACHE_INFORMATION \
64 CTL_CODE(IOCTL_DISK_BASE, 0x0035, METHOD_BUFFERED, FILE_READ_ACCESS)
66 #define IOCTL_DISK_GET_DRIVE_GEOMETRY \
67 CTL_CODE(IOCTL_DISK_BASE, 0x0000, METHOD_BUFFERED, FILE_ANY_ACCESS)
69 #define IOCTL_DISK_GET_DRIVE_GEOMETRY_EX \
70 CTL_CODE(IOCTL_DISK_BASE, 0x0028, METHOD_BUFFERED, FILE_ANY_ACCESS)
72 #define IOCTL_DISK_GET_DRIVE_LAYOUT \
73 CTL_CODE(IOCTL_DISK_BASE, 0x0003, METHOD_BUFFERED, FILE_READ_ACCESS)
75 #define IOCTL_DISK_GET_DRIVE_LAYOUT_EX \
76 CTL_CODE(IOCTL_DISK_BASE, 0x0014, METHOD_BUFFERED, FILE_ANY_ACCESS)
78 #define IOCTL_DISK_GET_MEDIA_TYPES \
79 CTL_CODE(IOCTL_DISK_BASE, 0x0300, METHOD_BUFFERED, FILE_ANY_ACCESS)
81 #define IOCTL_DISK_GET_LENGTH_INFO \
82 CTL_CODE(IOCTL_DISK_BASE, 0x0017, METHOD_BUFFERED, FILE_READ_ACCESS)
84 #define IOCTL_DISK_GET_PARTITION_INFO \
85 CTL_CODE(IOCTL_DISK_BASE, 0x0001, METHOD_BUFFERED, FILE_READ_ACCESS)
87 #define IOCTL_DISK_GET_PARTITION_INFO_EX \
88 CTL_CODE(IOCTL_DISK_BASE, 0x0012, METHOD_BUFFERED, FILE_ANY_ACCESS)
90 #define IOCTL_DISK_GROW_PARTITION \
91 CTL_CODE(IOCTL_DISK_BASE, 0x0034, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
93 #define IOCTL_DISK_INTERNAL_CLEAR_VERIFY \
94 CTL_CODE(IOCTL_DISK_BASE, 0x0101, METHOD_NEITHER, FILE_ANY_ACCESS)
96 #define IOCTL_DISK_INTERNAL_SET_VERIFY \
97 CTL_CODE(IOCTL_DISK_BASE, 0x0100, METHOD_NEITHER, FILE_ANY_ACCESS)
99 #define IOCTL_DISK_IS_WRITABLE \
100 CTL_CODE(IOCTL_DISK_BASE, 0x0009, METHOD_BUFFERED, FILE_ANY_ACCESS)
102 #define IOCTL_DISK_PERFORMANCE \
103 CTL_CODE(IOCTL_DISK_BASE, 0x0008, METHOD_BUFFERED, FILE_ANY_ACCESS)
105 #define IOCTL_DISK_PERFORMANCE_OFF \
106 CTL_CODE(IOCTL_DISK_BASE, 0x0018, METHOD_BUFFERED, FILE_ANY_ACCESS)
108 #define IOCTL_DISK_REASSIGN_BLOCKS \
109 CTL_CODE(IOCTL_DISK_BASE, 0x0007, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
111 #define IOCTL_DISK_RESERVE \
112 CTL_CODE(IOCTL_DISK_BASE, 0x0204, METHOD_BUFFERED, FILE_READ_ACCESS)
114 #define IOCTL_DISK_SET_CACHE_INFORMATION \
115 CTL_CODE(IOCTL_DISK_BASE, 0x0036, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
117 #define IOCTL_DISK_SET_DRIVE_LAYOUT \
118 CTL_CODE(IOCTL_DISK_BASE, 0x0004, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
120 #define IOCTL_DISK_SET_DRIVE_LAYOUT_EX \
121 CTL_CODE(IOCTL_DISK_BASE, 0x0015, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
123 #define IOCTL_DISK_SET_PARTITION_INFO \
124 CTL_CODE(IOCTL_DISK_BASE, 0x0002, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
126 #define IOCTL_DISK_SET_PARTITION_INFO_EX \
127 CTL_CODE(IOCTL_DISK_BASE, 0x0013, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
129 #define IOCTL_DISK_UPDATE_DRIVE_SIZE \
130 CTL_CODE(IOCTL_DISK_BASE, 0x0032, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
132 #define IOCTL_DISK_VERIFY \
133 CTL_CODE(IOCTL_DISK_BASE, 0x0005, METHOD_BUFFERED, FILE_ANY_ACCESS)
135 #define SMART_GET_VERSION \
136 CTL_CODE(IOCTL_DISK_BASE, 0x0020, METHOD_BUFFERED, FILE_READ_ACCESS)
138 #define SMART_RCV_DRIVE_DATA \
139 CTL_CODE(IOCTL_DISK_BASE, 0x0022, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
141 #define SMART_SEND_DRIVE_COMMAND \
142 CTL_CODE(IOCTL_DISK_BASE, 0x0021, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
145 #define PARTITION_ENTRY_UNUSED 0x00
146 #define PARTITION_FAT_12 0x01
147 #define PARTITION_XENIX_1 0x02
148 #define PARTITION_XENIX_2 0x03
149 #define PARTITION_FAT_16 0x04
150 #define PARTITION_EXTENDED 0x05
151 #define PARTITION_HUGE 0x06
152 #define PARTITION_IFS 0x07
153 #define PARTITION_OS2BOOTMGR 0x0A
154 #define PARTITION_FAT32 0x0B
155 #define PARTITION_FAT32_XINT13 0x0C
156 #define PARTITION_XINT13 0x0E
157 #define PARTITION_XINT13_EXTENDED 0x0F
158 #define PARTITION_PREP 0x41
159 #define PARTITION_LDM 0x42
160 #define PARTITION_UNIX 0x63
161 #define VALID_NTFT 0xC0
162 #define PARTITION_NTFT 0x80
164 #define IsFTPartition( PartitionType ) \
165 (((PartitionType) & PARTITION_NTFT) && \
166 IsRecognizedPartition(PartitionType))
168 #define IsContainerPartition(PartitionType) \
169 (((PartitionType) == PARTITION_EXTENDED) || \
170 ((PartitionType) == PARTITION_XINT13_EXTENDED))
172 #define IsRecognizedPartition(PartitionType) ( \
173 (((PartitionType) & PARTITION_NTFT) && (((PartitionType) & ~0xC0) == PARTITION_FAT_12)) || \
174 (((PartitionType) & PARTITION_NTFT) && (((PartitionType) & ~0xC0) == PARTITION_HUGE)) || \
175 (((PartitionType) & PARTITION_NTFT) && (((PartitionType) & ~0xC0) == PARTITION_IFS)) || \
176 (((PartitionType) & PARTITION_NTFT) && (((PartitionType) & ~0xC0) == PARTITION_FAT32)) || \
177 (((PartitionType) & PARTITION_NTFT) && (((PartitionType) & ~0xC0) == PARTITION_FAT32_XINT13)) || \
178 (((PartitionType) & PARTITION_NTFT) && (((PartitionType) & ~0xC0) == PARTITION_XINT13)) || \
179 ((PartitionType) == PARTITION_FAT_12) || \
180 ((PartitionType) == PARTITION_FAT_16) || \
181 ((PartitionType) == PARTITION_HUGE) || \
182 ((PartitionType) == PARTITION_IFS) || \
183 ((PartitionType) == PARTITION_FAT32) || \
184 ((PartitionType) == PARTITION_FAT32_XINT13) || \
185 ((PartitionType) == PARTITION_XINT13))
187 #define WMI_DISK_GEOMETRY_GUID \
188 {0x25007f51, 0x57c2, 0x11d1, {0xa5, 0x28, 0x0, 0xa0, 0xc9, 0x6, 0x29, 0x10}}
190 typedef USHORT BAD_TRACK_NUMBER
;
191 typedef USHORT
*PBAD_TRACK_NUMBER
;
193 typedef enum _MEDIA_TYPE
{
217 } MEDIA_TYPE
, *PMEDIA_TYPE
;
219 typedef enum _DETECTION_TYPE
{
225 typedef struct _DISK_CONTROLLER_NUMBER
{
226 ULONG ControllerNumber
;
228 } DISK_CONTROLLER_NUMBER
, *PDISK_CONTROLLER_NUMBER
;
230 typedef struct _DISK_INT13_INFO
{
233 USHORT SectorsPerTrack
;
236 } DISK_INT13_INFO
, *PDISK_INT13_INFO
;
238 typedef struct _DISK_EX_INT13_INFO
{
243 ULONG ExSectorsPerTrack
;
244 ULONG64 ExSectorsPerDrive
;
247 } DISK_EX_INT13_INFO
, *PDISK_EX_INT13_INFO
;
249 typedef struct _DISK_DETECTION_INFO
{
250 ULONG SizeOfDetectInfo
;
251 DETECTION_TYPE DetectionType
;
252 _ANONYMOUS_UNION
union {
253 _ANONYMOUS_STRUCT
struct {
254 DISK_INT13_INFO Int13
;
255 DISK_EX_INT13_INFO ExInt13
;
258 } DISK_DETECTION_INFO
, *PDISK_DETECTION_INFO
;
260 typedef struct _DISK_GEOMETRY
{
261 LARGE_INTEGER Cylinders
;
262 MEDIA_TYPE MediaType
;
263 ULONG TracksPerCylinder
;
264 ULONG SectorsPerTrack
;
265 ULONG BytesPerSector
;
266 } DISK_GEOMETRY
, *PDISK_GEOMETRY
;
268 typedef struct _DISK_GEOMETRY_EX
{
269 DISK_GEOMETRY Geometry
;
270 LARGE_INTEGER DiskSize
;
272 } DISK_GEOMETRY_EX
, *PDISK_GEOMETRY_EX
;
274 #define DiskGeometryGetPartition(Geometry) \
275 ((PDISK_PARTITION_INFO)((Geometry) + 1))
277 #define DiskGeometryGetDetect(Geometry)\
278 ((PDISK_DETECTION_INFO)(((PBYTE)DiskGeometryGetPartition(Geometry) + \
279 DiskGeometryGetPartition(Geometry)->SizeOfPartitionInfo)))
281 typedef struct _PARTITION_INFORMATION
{
282 LARGE_INTEGER StartingOffset
;
283 LARGE_INTEGER PartitionLength
;
285 DWORD PartitionNumber
;
287 BOOLEAN BootIndicator
;
288 BOOLEAN RecognizedPartition
;
289 BOOLEAN RewritePartition
;
290 } PARTITION_INFORMATION
, *PPARTITION_INFORMATION
;
292 typedef struct _PARTITION_INFORMATION_GPT
{
297 } PARTITION_INFORMATION_GPT
, *PPARTITION_INFORMATION_GPT
;
299 typedef struct _DISK_PARTITION_INFO
{
300 ULONG SizeOfPartitionInfo
;
301 PARTITION_STYLE PartitionStyle
;
302 _ANONYMOUS_UNION
union {
311 } DISK_PARTITION_INFO
, *PDISK_PARTITION_INFO
;
313 typedef struct _DISK_PERFORMANCE
{
314 LARGE_INTEGER BytesRead
;
315 LARGE_INTEGER BytesWritten
;
316 LARGE_INTEGER ReadTime
;
317 LARGE_INTEGER WriteTime
;
318 LARGE_INTEGER IdleTime
;
323 LARGE_INTEGER QueryTime
;
324 ULONG StorageDeviceNumber
;
325 WCHAR StorageManagerName
[8];
326 } DISK_PERFORMANCE
, *PDISK_PERFORMANCE
;
328 typedef struct _PARTITION_INFORMATION_EX
{
329 PARTITION_STYLE PartitionStyle
;
330 LARGE_INTEGER StartingOffset
;
331 LARGE_INTEGER PartitionLength
;
332 ULONG PartitionNumber
;
333 BOOLEAN RewritePartition
;
334 _ANONYMOUS_UNION
union {
335 PARTITION_INFORMATION_MBR Mbr
;
336 PARTITION_INFORMATION_GPT Gpt
;
338 } PARTITION_INFORMATION_EX
, *PPARTITION_INFORMATION_EX
;
340 typedef struct _FORMAT_EX_PARAMETERS
{
341 MEDIA_TYPE MediaType
;
342 ULONG StartCylinderNumber
;
343 ULONG EndCylinderNumber
;
344 ULONG StartHeadNumber
;
346 USHORT FormatGapLength
;
347 USHORT SectorsPerTrack
;
348 USHORT SectorNumber
[1];
349 } FORMAT_EX_PARAMETERS
, *PFORMAT_EX_PARAMETERS
;
351 typedef struct _FORMAT_PARAMETERS
{
352 MEDIA_TYPE MediaType
;
353 ULONG StartCylinderNumber
;
354 ULONG EndCylinderNumber
;
355 ULONG StartHeadNumber
;
357 } FORMAT_PARAMETERS
, *PFORMAT_PARAMETERS
;
359 typedef struct _GET_LENGTH_INFORMATION
{
360 LARGE_INTEGER Length
;
361 } GET_LENGTH_INFORMATION
, *PGET_LENGTH_INFORMATION
;
363 typedef struct _REASSIGN_BLOCKS
{
366 DWORD BlockNumber
[1];
367 } REASSIGN_BLOCKS
, *PREASSIGN_BLOCKS
;
369 typedef struct _SET_PARTITION_INFORMATION
{
371 } SET_PARTITION_INFORMATION
, *PSET_PARTITION_INFORMATION
;
373 typedef SET_PARTITION_INFORMATION SET_PARTITION_INFORMATION_MBR
;
374 typedef PARTITION_INFORMATION_GPT SET_PARTITION_INFORMATION_GPT
;
376 typedef struct _SET_PARTITION_INFORMATION_EX
{
377 PARTITION_STYLE PartitionStyle
;
378 _ANONYMOUS_UNION
union {
379 SET_PARTITION_INFORMATION_MBR Mbr
;
380 SET_PARTITION_INFORMATION_GPT Gpt
;
382 } SET_PARTITION_INFORMATION_EX
, *PSET_PARTITION_INFORMATION_EX
;
384 typedef struct _VERIFY_INFORMATION
{
385 LARGE_INTEGER StartingOffset
;
387 } VERIFY_INFORMATION
, *PVERIFY_INFORMATION
;
393 } DISK_CACHE_RETENTION_PRIORITY
;
395 typedef struct _DISK_CACHE_INFORMATION
{
396 BOOLEAN ParametersSavable
;
397 BOOLEAN ReadCacheEnabled
;
398 BOOLEAN WriteCacheEnabled
;
399 DISK_CACHE_RETENTION_PRIORITY ReadRetentionPriority
;
400 DISK_CACHE_RETENTION_PRIORITY WriteRetentionPriority
;
401 USHORT DisablePrefetchTransferLength
;
402 BOOLEAN PrefetchScalar
;
403 _ANONYMOUS_UNION
union {
407 USHORT MaximumBlocks
;
414 } DISK_CACHE_INFORMATION
, *PDISK_CACHE_INFORMATION
;
416 typedef struct _DISK_GROW_PARTITION
{
417 ULONG PartitionNumber
;
418 LARGE_INTEGER BytesToGrow
;
419 } DISK_GROW_PARTITION
, *PDISK_GROW_PARTITION
;
421 /* GETVERSIONINPARAMS.fCapabilities constants */
422 #define CAP_ATA_ID_CMD 1
423 #define CAP_ATAPI_ID_CMD 2
424 #define CAP_SMART_CMD 4
426 typedef struct _GETVERSIONINPARAMS
{
433 } GETVERSIONINPARAMS
, *PGETVERSIONINPARAMS
, *LPGETVERSIONINPARAMS
;
435 /* IDEREGS.bCommandReg constants */
436 #define ATAPI_ID_CMD 0xA1
438 #define SMART_CMD 0xB0
440 #define SMART_CYL_LOW 0x4F
441 #define SMART_CYL_HI 0xC2
443 typedef struct _IDEREGS
{
445 UCHAR bSectorCountReg
;
446 UCHAR bSectorNumberReg
;
452 } IDEREGS
, *PIDEREGS
, *LPIDEREGS
;
454 #include <pshpack1.h>
455 typedef struct _SENDCMDINPARAMS
{
462 } SENDCMDINPARAMS
, *PSENDCMDINPARAMS
, *LPSENDCMDINPARAMS
;
465 /* DRIVERSTATUS.bDriverError constants */
466 #define SMART_NO_ERROR 0
467 #define SMART_IDE_ERROR 1
468 #define SMART_INVALID_FLAG 2
469 #define SMART_INVALID_COMMAND 3
470 #define SMART_INVALID_BUFFER 4
471 #define SMART_INVALID_DRIVE 5
472 #define SMART_INVALID_IOCTL 6
473 #define SMART_ERROR_NO_MEM 7
474 #define SMART_INVALID_REGISTER 8
475 #define SMART_NOT_SUPPORTED 9
476 #define SMART_NO_IDE_DEVICE 10
478 #define SMART_OFFLINE_ROUTINE_OFFLINE 0
479 #define SMART_SHORT_SELFTEST_OFFLINE 1
480 #define SMART_EXTENDED_SELFTEST_OFFLINE 2
481 #define SMART_ABORT_OFFLINE_SELFTEST 127
482 #define SMART_SHORT_SELFTEST_CAPTIVE 129
483 #define SMART_EXTENDED_SELFTEST_CAPTIVE 130
485 typedef struct _DRIVERSTATUS
{
490 } DRIVERSTATUS
, *PDRIVERSTATUS
, *LPDRIVERSTATUS
;
492 #define READ_ATTRIBUTE_BUFFER_SIZE 512
493 #define IDENTIFY_BUFFER_SIZE 512
494 #define READ_THRESHOLD_BUFFER_SIZE 512
495 #define SMART_LOG_SECTOR_SIZE 512
497 #include <pshpack1.h>
498 typedef struct _SENDCMDOUTPARAMS
{
500 DRIVERSTATUS DriverStatus
;
502 } SENDCMDOUTPARAMS
, *PSENDCMDOUTPARAMS
, *LPSENDCMDOUTPARAMS
;
505 #define READ_ATTRIBUTES 0xD0
506 #define READ_THRESHOLDS 0xD1
507 #define ENABLE_DISABLE_AUTOSAVE 0xD2
508 #define SAVE_ATTRIBUTE_VALUES 0xD3
509 #define EXECUTE_OFFLINE_DIAGS 0xD4
510 #define SMART_READ_LOG 0xD5
511 #define SMART_WRITE_LOG 0xd6
512 #define ENABLE_SMART 0xD8
513 #define DISABLE_SMART 0xD9
514 #define RETURN_SMART_STATUS 0xDA
515 #define ENABLE_DISABLE_AUTO_OFFLINE 0xDB
521 #endif /* __NTDDDISK_H */