-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvdskcmd.h
471 lines (362 loc) · 12.3 KB
/
vdskcmd.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
/*************************************************************************/
/* */
/* Copyright (c) 2000-2010 NT KERNEL RESOURCES, All Rights Reserved. */
/* http://www.ntkernel.com */
/* */
/* Module Name: vdskcmd.h */
/* */
/* Abstract: This is the include file that defines Virtual Disk driver */
/* interface. */
/* */
/* Environment: */
/* */
/* User mode, Virtual Disk SDK */
/* */
/* Revision History: */
/* */
/*************************************************************************/
#ifndef __VDSKCMD_H_
#define __VDSKCMD_H_
#ifdef _WINDOWS
#include <winioctl.h> // Compiling Win32 Applications Or DLL's
#endif // _WINDOWS
#include "macros.h"
#pragma warning(disable:4200) //nonstandard extension used : zero-sized array in struct/union
// current vdsk driver version.
#define NTVDSK_DRIVER_VERSION 0x00000001
//driver name
#define VDSK_DRIVER_NAMEW L"Vdsk"
#define VDSK_DRIVER_NAMEA "Vdsk"
#define VDSK_VOLUME_DEVICE_NAMEW VDSK_DRIVER_NAMEW L"Volume"
#define VDSK_VOLUME_DEVICE_NAMEA VDSK_DRIVER_NAMEW "Volume"
//Control device
#define NT_VDSK_DEVICE_NAME_W L"\\Device\\" VDSK_DRIVER_NAMEW
#define NT_VDSK_DEVICE_NAME_A "\\Device\\" VDSK_DRIVER_NAMEA
#define DOS_VDSK_DEVICE_NAME_W L"\\DosDevices\\" VDSK_DRIVER_NAMEW
#define DOS_VDSK_DEVICE_NAME_A "\\DosDevices\\" VDSK_DRIVER_NAMEA
#define WIN32_VDSK_DEVICE_NAME_W L"\\\\.\\" VDSK_DRIVER_NAMEW
#define WIN32_VDSK_DEVICE_NAME_A "\\\\.\\" VDSK_DRIVER_NAMEA
//Volume device: \\Device\\VdskVolume1
#define NT_VDSK_VOLUME_NAME_W L"\\Device\\" VDSK_VOLUME_DEVICE_NAMEW
#define NT_VDSK_VOLUME_NAME_A "\\Device\\" VDSK_VOLUME_DEVICE_NAMEA
//
// define notification event codes
//
#define VDSK_DISK_EVENT_NONE 0 // no events
#define VDSK_DISK_EVENT_DEADLOCK 1 // disk detected user-app hang
//
// Storage properties
//
#define VDSK_VENDOR_ID "NTKERNEL"
#define VDSK_VENDOR_ID_SIZE sizeof(VDSK_VENDOR_ID)
#define VDSK_PRODUCT_ID "VDSK1-0"
#define VDSK_PRODUCT_ID_SIZE sizeof(VDSK_PRODUCT_ID)
#define VDSK_PRODUCT_REV "VDSK10"
#define VDSK_PRODUCT_REV_SIZE sizeof(VDSK_PRODUCT_REV)
#define VDSK_SERIAL_NUMBER "87654321"
#define VDSK_SERIAL_NUMBER_SIZE sizeof(VDSK_SERIAL_NUMBER)
#define VDSK_VOLUME_LINK L"\\??\\Volume{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"
#define VDSK_VOLUME_LINK_SIZE sizeof(VDSK_VOLUME_LINK)
//values for disk I/O processing timeout by user app
#define VDSK_DISK_IO_TIMEOUT SECONDS(30)
// the maximum allowed disk i/o timeout value
#define VDSK_DISK_IO_TIMEOUT_MAX SECONDS(120)
#define FILE_DEVICE_VDSK 0x8800
#define IOCTL_VDSK_BASE 0x800
#ifndef FUNCTION_FROM_CTL_CODE
#define FUNCTION_FROM_CTL_CODE(ctlCode) (((ULONG)((ctlCode) & 0x00003fff)) >> 2)
#endif //FUNCTION_FROM_CTL_CODE
//
// virtual disk flags
//
#define VDSK_DISK_READ_ONLY 0x00000001
#define VDSK_DISK_REMOVABLE 0x00000002
#define VDSK_DISK_CDROM 0x00000004
#define VDSK_DISK_FLOPPY 0x00000008
#define VDSK_DISK_MEDIA_IN_DEVICE 0x00000010
#define VDSK_DISK_VALID_MASK 0x0000001F
//
// IOCTL_VDSK_CREATE_DISK
//
typedef struct _VDSK_DISK_PARAMETERS
{
// device flags
union{
struct{
// device is read only
ULONG ReadOnly : 1;
//media is removable
ULONG Removable : 1;
// device is cd-rom
ULONG IsCDRom : 1;
//device is floppy disk
ULONG IsFloppy : 1;
//media in device after device creation
ULONG IsMediaInDevice : 1;
};
ULONG Flags;
};
// Drive Letter (if used, otherwise zero).
WCHAR DriveLetter;
//
// Drive geometry
//
// Drive size in bytes
LARGE_INTEGER DiskSize;
//Indicates the number of tracks in a cylinder.
ULONG TracksPerCylinder;
//Indicates the number of sectors in each track.
ULONG SectorsPerTrack;
//Indicates the number of bytes in a disk sector.
ULONG BytesPerSector;
//
// disk I/O timeout
// specifies the absolute time, in units of 100 nanoseconds,
// for which the disk IO should be handled. If the disk IO
// was not handled in specified timeframe, driver reports deadlock
// (it stores VDSK_DISK_EVENT_DEADLOCK in LastDiskNotificationEvent and sets
// DiskNotificationEvent provided by user-mode)
// Then virtual disk goes offline:
// - no media in device
// - all io operations completes with status 'device is not ready'
LARGE_INTEGER DiskIoTimeout;
//
// user provided handle to event
// that disk use to notify user-space
// about disk events:
// 1. deadlock occurred
// 2.
//
// Note: this parameter is ignored for IOCTL_VDSK_SET_DISK
union{
HANDLE hDiskNotificationEvent;
UINT32 Handle32; //for wow64
UINT64 Handle64;
};
} VDSK_DISK_PARAMETERS, *PVDSK_DISK_PARAMETERS;
// the result of disk device creation operation
typedef struct _VDSK_DISK_CREATE_RESULT
{
// Device handle
LONG DeviceID;
}VDSK_DISK_CREATE_RESULT,*PVDSK_DISK_CREATE_RESULT;
//
// IOCTL_VDSK_START_DISK
//
typedef struct _VDSK_DISK_START_PARAMETERS
{
// FALSE, if drive has no media
// TRUE, otherwise
LONG MediaInDevice;
}VDSK_DISK_START_PARAMETERS,*PVDSK_DISK_START_PARAMETERS;
// disk 'open' request parameters
typedef struct _VDSK_DISK_OPEN_PARAMETERS
{
// Device handle, returned on device creation
LONG DeviceID;
}VDSK_DISK_OPEN_PARAMETERS,*PVDSK_DISK_OPEN_PARAMETERS;
//disk information structure
typedef struct _VDSK_DISK_INFORMATION
{
// device is read only
LONG ReadOnly : 1;
//media is removable
LONG Removable : 1;
// device is cd-rom
LONG IsCDRom : 1;
//device is floppy disk
LONG IsFloppy : 1;
//media in device after device creation
LONG IsMediaInDevice : 1;
//device deletion is in progress
LONG DeletePending : 1;
// disk io is disabled,
// we terminate disk io thread and cancel all pending requests
LONG IsOffline : 1;
//volume link within mount mgr
LONG IsVolumeLinkCreated : 1;
// the number of mount mgr links/ mount points
LONG LinksCount;
//////////////////////////////////////////////////////////////////////////
// disk interface
// Specifies the number of the disk that contains this extent.
// This is the same disk number that is used to construct the name of the disk
// (for example, PhysicalDriveX or HarddiskX, where X is the disk number).
// for IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS
ULONG DiskNumber;
//Specifies one of the system-defined FILE_DEVICE_XXX
// FILE_DEVICE_DISK, FILE_DEVICE_CD_ROM, FILE_DEVICE_VIRTUAL_DISK,
DEVICE_TYPE DeviceType;
//
// Drive geometry
//
// Drive size in bytes
LARGE_INTEGER DiskSize;
//Indicates the number of tracks in a cylinder.
ULONG TracksPerCylinder;
//Indicates the number of sectors in each track.
ULONG SectorsPerTrack;
//Indicates the number of bytes in a disk sector.
ULONG BytesPerSector;
//////////////////////////////////////////////////////////////////////////
//
// last disk notification event
LONG LastDiskNotificationEvent; //VDSK_DISK_EVENT_DEADLOCK
//////////////////////////////////////////////////////////////////////////
// Disk statistics
// number of read operations
LARGE_INTEGER IoReadCount;
//the number of bytes read
LARGE_INTEGER IoReadBytes;
// number of write operations
LARGE_INTEGER IoWriteCount;
// number of write bytes
LARGE_INTEGER IoWriteBytes;
// number of failed read operations
LARGE_INTEGER IoReadFailed;
// number of failed write operations
LARGE_INTEGER IoWriteFailed;
// device volume link in mount mgr
WCHAR VolumeLinkName[VDSK_VOLUME_LINK_SIZE/sizeof(WCHAR)];
}VDSK_DISK_INFORMATION,*PVDSK_DISK_INFORMATION;
//
// Provides information about all mounted disks
//
typedef struct _VDSK_ALL_INFORMATION
{
// number of disks
ULONG Number;
// array of disk information structures
VDSK_DISK_INFORMATION DiskInformation[0];
}VDSK_ALL_INFORMATION,*PVDSK_ALL_INFORMATION;
//
// disk IO operation identifiers
//
typedef enum _VDSK_IO_OP
{
IO_OP_NONE, // nothing
IO_OP_READ, // disk IO read
IO_OP_WRITE, // disk IO write
IO_OP_FORMAT_TRACKS, // format tracks requests (for floppy only), optional
IO_OP_NOTIFY_EJECT // media eject request, optional
}VDSK_IO_OP,*PVDSK_IO_OP;
//
// user operation status codes
//
// operation completed successfully
#define IO_OP_STATUS_SUCCESS 0L
// operation failed
#define IO_OP_STATUS_UNSUCCESSFUL 1L
// operation is not implemented
// use default processing handler
// valid for IO_OP_FORMAT_TRACKS, IO_OP_NOTIFY_EJECT
#define IO_OP_STATUS_NOT_IMPLEMENTED 2L
typedef struct _VDSK_IO_OPEARTION
{
// user io operation
VDSK_IO_OP Operation;
union{
// IO_OP_READ
struct {
// specifies if it's paging io operation
// user app MUST NOT use any file IO operations diring this request handling
LONG PagingIo;
// Length in bytes of the data to be read.
// If the read operation is successful,
// the number of bytes read is returned in the BytesProcessed member
ULONG Length;
// LARGE_INTEGER variable that specifies the starting byte
// offset within the file of the data to be read.
LARGE_INTEGER ByteOffset;
}Read;
// IO_OP_WRITE
struct {
// specifies if it's paging io operation
// user app MUST NOT use any file IO operations diring this request handling
LONG PagingIo;
// Length in bytes of the data to be written.
// If the read operation is successful,
// the number of bytes written is returned in the BytesProcessed member
ULONG Length;
// LARGE_INTEGER variable that specifies the starting byte
// offset within the file of the data to be written.
LARGE_INTEGER ByteOffset;
}Write;
//IO_OP_FORMAT_TRACKS
struct {
// Indicates format information, such as the disk size and the number
// of bytes per sector. For a list of the values that can be assigned
// to this member, see MEDIA_TYPE in WDK.
MEDIA_TYPE MediaType;
//Indicates the number of the cylinder where the formatting should begin.
ULONG StartCylinderNumber;
//Indicates the number of the cylinder where the formatting should end.
ULONG EndCylinderNumber;
//Indicates the number of the head where the formatting should begin.
ULONG StartHeadNumber;
//Indicates the number of the head where the formatting should end.
ULONG EndHeadNumber;
}Format;
};
// operation sequence number
LONG OpeartionID;
//operation result
LONG Status; //IO_OP_STATUS_XXX
//actual bytes r/w
ULONG BytesProcessed;
// operation data mapped to user application
union{
CHAR* DataBuffer;
UINT32 DataBuffer32; //for wow64
UINT64 DataBuffer64;
};
#ifndef _VDSK_MAP_USER_MEMORY
ULONG DataBufferSize;
#endif //_VDSK_MAP_USER_MEMORY
}VDSK_IO_OPEARTION,*PVDSK_IO_OPEARTION;
//Main device I/O controls
#define _VDSK_CTRL_CODE(_FUNC) \
CTL_CODE(FILE_DEVICE_VDSK, IOCTL_VDSK_BASE + (_FUNC), METHOD_BUFFERED, FILE_ANY_ACCESS )
//
// driver version
//
#define IOCTL_VDSK_VERSION _VDSK_CTRL_CODE(1)
//
// create new virtual disk associated with the current thread
//
#define IOCTL_VDSK_CREATE_DISK _VDSK_CTRL_CODE(2)
//
// create new virtual disk associated with the current thread
//
#define IOCTL_VDSK_START_DISK _VDSK_CTRL_CODE(3)
//
// open virtual disk by id
//
#define IOCTL_VDSK_OPEN_DISK _VDSK_CTRL_CODE(4)
//
// unmount virtual disk drive
//
#define IOCTL_VDSK_DELETE_DISK _VDSK_CTRL_CODE(5)
//
// virtual disk drive ejection control
//
#define IOCTL_VDSK_INJECT_DISK _VDSK_CTRL_CODE(6)
//
// query virtual disk information
//
#define IOCTL_VDSK_QUERY_DISK _VDSK_CTRL_CODE(7)
//
// set virtual disk information
//
#define IOCTL_VDSK_SET_DISK _VDSK_CTRL_CODE(8)
//
// query all virtual disks information
//
#define IOCTL_VDSK_QUERY_INFORMATION _VDSK_CTRL_CODE(9)
//
// disk IO operation
// on call it provides results of the previous operation
// on return it contains the parameters of the next operation
//
#define IOCTL_VDSK_DISK_IO_OP _VDSK_CTRL_CODE(10)
#endif //__VDSKCMD_H_