ReactOS 0.4.15-dev-8191-gbc6c731
vfddrv.h File Reference
#include "vfdtypes.h"
#include "vfdio.h"
#include "vfdver.h"
Include dependency graph for vfddrv.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _VFD_DRIVER_EXTENSION
 
struct  _DEVICE_EXTENSION
 

Macros

#define VFD_POOL_TAG   'DFVx'
 

Typedefs

typedef struct _VFD_DRIVER_EXTENSION VFD_DRIVER_EXTENSION
 
typedef struct _VFD_DRIVER_EXTENSIONPVFD_DRIVER_EXTENSION
 
typedef struct _DEVICE_EXTENSION DEVICE_EXTENSION
 
typedef struct _DEVICE_EXTENSIONPDEVICE_EXTENSION
 

Functions

NTSTATUS NTAPI DriverEntry (IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
 
VOID NTAPI VfdUnloadDriver (IN PDRIVER_OBJECT DriverObject)
 
NTSTATUS NTAPI VfdCreateClose (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI VfdReadWrite (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI VfdDeviceControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
VOID NTAPI VfdDeviceThread (IN PVOID ThreadContext)
 
PWSTR VfdCopyUnicode (OUT PUNICODE_STRING dst, IN PUNICODE_STRING src)
 
VOID VfdFreeUnicode (IN OUT PUNICODE_STRING str)
 
NTSTATUS VfdCreateDevice (IN PDRIVER_OBJECT DriverObject, OUT PVOID Parameter)
 
VOID VfdDeleteDevice (IN PDEVICE_OBJECT DeviceObject)
 
VOID VfdIoCtlThread (IN PDEVICE_EXTENSION DeviceExtension, IN PIRP Irp, IN ULONG ControlCode)
 
NTSTATUS VfdOpenCheck (IN PDEVICE_EXTENSION DeviceExtension, IN PVFD_IMAGE_INFO ImageInfo, IN ULONG InputLength)
 
NTSTATUS VfdOpenImage (IN PDEVICE_EXTENSION DeviceExtension, IN PVFD_IMAGE_INFO ImageInfo)
 
VOID VfdCloseImage (IN PDEVICE_EXTENSION DeviceExtension)
 
NTSTATUS VfdQueryImage (IN PDEVICE_EXTENSION DeviceExtension, OUT PVFD_IMAGE_INFO ImageInfo, IN ULONG BufferLength, OUT PULONG ReturnLength)
 
VOID VfdReadData (IN PDEVICE_EXTENSION DeviceExtension, IN OUT PIRP Irp, IN ULONG Length, IN PLARGE_INTEGER Offset)
 
VOID VfdWriteData (IN PDEVICE_EXTENSION DeviceExtension, IN OUT PIRP Irp, IN ULONG Length, IN PLARGE_INTEGER Offset)
 
NTSTATUS VfdSetLink (IN PDEVICE_EXTENSION DeviceExtension, IN CHAR DriveLetter)
 
NTSTATUS VfdStoreLink (IN PDEVICE_EXTENSION DeviceExtension)
 
NTSTATUS VfdLoadLink (IN PDEVICE_EXTENSION DeviceExtension, IN PWSTR RegistryPath)
 
NTSTATUS VfdFormatCheck (IN PDEVICE_EXTENSION DeviceExtension, IN PFORMAT_PARAMETERS FormatParams, IN ULONG InputLength, IN ULONG ControlCode)
 
NTSTATUS VfdFormatTrack (IN PDEVICE_EXTENSION DeviceExtension, IN PFORMAT_PARAMETERS FormatParams)
 

Variables

ULONG OsMajorVersion
 
ULONG OsMinorVersion
 
ULONG OsBuildNumber
 
const DISK_GEOMETRY geom_tbl [VFD_MEDIA_MAX]
 

Macro Definition Documentation

◆ VFD_POOL_TAG

#define VFD_POOL_TAG   'DFVx'

Definition at line 25 of file vfddrv.h.

Typedef Documentation

◆ DEVICE_EXTENSION

◆ PDEVICE_EXTENSION

◆ PVFD_DRIVER_EXTENSION

◆ VFD_DRIVER_EXTENSION

Function Documentation

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( IN PDRIVER_OBJECT  DriverObject,
IN PUNICODE_STRING  RegistryPath 
)

Definition at line 367 of file beep.c.

369{
370 PDEVICE_EXTENSION DeviceExtension;
374
376
377 /* Create the device */
379 sizeof(DEVICE_EXTENSION),
380 &DeviceName,
382 0,
383 FALSE,
384 &DeviceObject);
385 if (!NT_SUCCESS(Status)) return Status;
386
387 /* Make it use buffered I/O */
389
390 /* Setup the Driver Object */
391 DriverObject->MajorFunction[IRP_MJ_CREATE] = BeepCreate;
392 DriverObject->MajorFunction[IRP_MJ_CLOSE] = BeepClose;
393 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = BeepCleanup;
395 DriverObject->DriverUnload = BeepUnload;
396 DriverObject->DriverStartIo = BeepStartIo;
397
398 /* Set up device extension */
399 DeviceExtension = DeviceObject->DeviceExtension;
400 DeviceExtension->ReferenceCount = 0;
401 DeviceExtension->TimerActive = FALSE;
403 KeInitializeTimer(&DeviceExtension->Timer);
404 ExInitializeFastMutex(&DeviceExtension->Mutex);
405
406 /* Page the entire driver */
408 return STATUS_SUCCESS;
409}
LONG NTSTATUS
Definition: precomp.h:26
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
DRIVER_STARTIO BeepStartIo
Definition: beep.c:295
VOID NTAPI BeepDPC(IN PKDPC Dpc, IN PDEVICE_OBJECT DeviceObject, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: beep.c:34
DRIVER_DISPATCH BeepClose
Definition: beep.c:78
DRIVER_DISPATCH BeepCleanup
Definition: beep.c:145
DRIVER_UNLOAD BeepUnload
Definition: beep.c:268
DRIVER_DISPATCH BeepCreate
Definition: beep.c:52
DRIVER_DISPATCH BeepDeviceControl
Definition: beep.c:206
DRIVER_INITIALIZE DriverEntry
Definition: condrv.c:21
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
Status
Definition: gdiplustypes.h:25
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
#define L(x)
Definition: ntvdm.h:50
#define FILE_DEVICE_BEEP
Definition: winioctl.h:107
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define STATUS_SUCCESS
Definition: shellext.h:65
FAST_MUTEX Mutex
Definition: beep.c:24
PVOID NTAPI MmPageEntireDriver(IN PVOID AddressWithinSection)
Definition: sysldr.c:3557
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
FORCEINLINE VOID IoInitializeDpcRequest(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIO_DPC_ROUTINE DpcRoutine)
Definition: iofuncs.h:2840
IO_DPC_ROUTINE * PIO_DPC_ROUTINE
Definition: iotypes.h:2847
#define IRP_MJ_CLEANUP

◆ VfdCloseImage()

VOID VfdCloseImage ( IN PDEVICE_EXTENSION  DeviceExtension)

Definition at line 435 of file vfdimg.c.

437{
438 VFDTRACE(0, ("[VFD] VfdCloseImage - IN\n"));
439
440 ASSERT(DeviceExtension);
441
442 DeviceExtension->MediaType = VFD_MEDIA_NONE;
443 DeviceExtension->MediaFlags = 0;
444 DeviceExtension->FileType = 0;
445 DeviceExtension->ImageSize = 0;
446 DeviceExtension->FileName.Length = 0;
447 DeviceExtension->Sectors = 0;
448
449 if (DeviceExtension->FileHandle) {
450 ZwClose(DeviceExtension->FileHandle);
451 DeviceExtension->FileHandle = NULL;
452 }
453
454 if (DeviceExtension->FileBuffer) {
455 ExFreePool(DeviceExtension->FileBuffer);
456 DeviceExtension->FileBuffer = NULL;
457 }
458
459 VFDTRACE(0, ("[VFD] VfdCloseImage - OUT\n"));
460}
#define NULL
Definition: types.h:112
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define ASSERT(a)
Definition: mode.c:44
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
@ VFD_MEDIA_NONE
Definition: vfdtypes.h:27

Referenced by Close(), VfdGuiClose(), and VfdIoCtlThread().

◆ VfdCopyUnicode()

PWSTR VfdCopyUnicode ( OUT PUNICODE_STRING  dst,
IN PUNICODE_STRING  src 
)

◆ VfdCreateClose()

NTSTATUS NTAPI VfdCreateClose ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 312 of file vfddrv.c.

315{
316#if DBG
317 if (DeviceObject && DeviceObject->DeviceExtension &&
318 ((PDEVICE_EXTENSION)DeviceObject->DeviceExtension)->DeviceName.Buffer) {
319
320 VFDTRACE(VFDINFO, ("[VFD] %-40s %ws\n",
322 ((PDEVICE_EXTENSION)DeviceObject->DeviceExtension)->DeviceName.Buffer));
323 }
324 else {
325 VFDTRACE(VFDINFO, ("[VFD] %-40s %p\n",
327 DeviceObject));
328 }
329#endif // DBG
330
331 Irp->IoStatus.Status = STATUS_SUCCESS;
332 Irp->IoStatus.Information = FILE_OPENED;
333
335
336 return STATUS_SUCCESS;
337}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
_In_ PIRP Irp
Definition: csq.h:116
#define FILE_OPENED
Definition: nt_native.h:769
#define IoCompleteRequest
Definition: irp.c:1240
_In_ UCHAR MajorFunction
Definition: wdfdevice.h:1697
#define IO_NO_INCREMENT
Definition: iotypes.h:598

Referenced by DriverEntry().

◆ VfdCreateDevice()

NTSTATUS VfdCreateDevice ( IN PDRIVER_OBJECT  DriverObject,
OUT PVOID  Parameter 
)

Definition at line 23 of file vfddev.c.

26{
28 ULONG physical_num;
29
30 UNICODE_STRING unicode_name;
31 WCHAR name_buffer[40];
32
33 PVFD_DRIVER_EXTENSION driver_extension = NULL;
34 PDEVICE_OBJECT device_object = NULL;
36 HANDLE thread_handle = NULL;
37
38 VFDTRACE(VFDINFO | VFDDEV, ("[VFD] VfdCreateDevice - IN\n"));
39
40#ifdef VFD_PNP
41
42 // Get the driver device_extension for the driver object
43 driver_extension = IoGetDriverObjectExtension(
44 DriverObject, VFD_DRIVER_EXTENSION_ID);
45
46#else // VFD_PNP
47
48 // The driver device_extension is passed as the Parameter
49 driver_extension = (PVFD_DRIVER_EXTENSION)Parameter;
50
51#endif // VFD_PNP
52
53 if (driver_extension == NULL) {
54 VFDTRACE(VFDERR, ("[VFD] Failed to get the driver extension\n"));
56 }
57
58 //
59 // Create a device object
60 // \Device\Floppy<n>
61 //
62 physical_num = 0;
63
64 do {
65#ifndef __REACTOS__
66 name_buffer[sizeof(name_buffer) - 1] = UNICODE_NULL;
67
68 _snwprintf(name_buffer, sizeof(name_buffer) - 1,
69 L"\\Device\\Floppy%lu", physical_num);
70#else
71 name_buffer[ARRAYSIZE(name_buffer) - 1] = UNICODE_NULL;
72
73 _snwprintf(name_buffer, ARRAYSIZE(name_buffer) - 1,
74 L"\\Device\\Floppy%lu", physical_num);
75#endif
76
77 RtlInitUnicodeString(&unicode_name, name_buffer);
78
81 sizeof(DEVICE_EXTENSION),
82 &unicode_name,
85 FALSE,
86 &device_object);
87
90 break;
91 }
92 }
93 while (++physical_num < 100);
94
95 if (!NT_SUCCESS(status)) {
96 VFDTRACE(VFDERR,
97 ("[VFD] IoCreateDevice() %s\n",
98 GetStatusName(status)));
99 return status;
100 }
101
103
104 VFDTRACE(VFDINFO | VFDDEV,
105 ("[VFD] Created a device object %ws\n", name_buffer));
106
107 //
108 // Initialize the device object / device extension
109 //
110
111 device_object->Flags |= DO_DIRECT_IO;
112
114
116
117 // Store the back pointer to the device object
118
119 device_extension->DeviceObject = device_object;
120
121 // Store the logical device number
122
123 device_extension->DeviceNumber = driver_extension->NumberOfDevices;
124
125 // Store the device name
126
127 if (!VfdCopyUnicode(&(device_extension->DeviceName), &unicode_name)) {
128 VFDTRACE(VFDERR,
129 ("[VFD] Failed to allocate device name buffer\n"));
131 goto cleanup;
132 }
133
134 // set the default disk geometry (3.5" 1.44M)
135
136 device_extension->Geometry = &geom_tbl[0];
137
138 // Create the interface link (\??\VirtualFD<n>)
139
140#ifndef __REACTOS__
141 name_buffer[sizeof(name_buffer) - 1] = UNICODE_NULL;
142
143 _snwprintf(name_buffer, sizeof(name_buffer) - 1,
144 L"\\??\\" VFD_DEVICE_BASENAME L"%lu",
145 device_extension->DeviceNumber);
146#else
147 name_buffer[ARRAYSIZE(name_buffer) - 1] = UNICODE_NULL;
148
149 _snwprintf(name_buffer, ARRAYSIZE(name_buffer) - 1,
150 L"\\??\\" VFD_DEVICE_BASENAME L"%lu",
151 device_extension->DeviceNumber);
152#endif
153
154 RtlInitUnicodeString(&unicode_name, name_buffer);
155
157 &unicode_name, &device_extension->DeviceName);
158
159 if (!NT_SUCCESS(status)) {
160 VFDTRACE(VFDERR,
161 ("[VFD] IoCreateSymbolicLink(%ws) %s\n",
162 name_buffer, GetStatusName(status)));
163 goto cleanup;
164 }
165
166 VFDTRACE(VFDINFO|VFDDEV,
167 ("[VFD] Created a symbolic link %ws\n", name_buffer));
168
169 // Prepare the IRP queue list for the device thread
170
172
174
176 &device_extension->RequestEvent,
178 FALSE);
179
180 // Create the device thread
181
182 device_extension->TerminateThread = FALSE;
183
185 &thread_handle,
186 (ACCESS_MASK) 0L,
187 NULL,
188 NULL,
189 NULL,
191 device_object);
192
193 if (!NT_SUCCESS(status)) {
194 VFDTRACE(VFDERR,
195 ("[VFD] PsCreateSystemThread() %s\n",
196 GetStatusName(status)));
197 goto cleanup;
198 }
199
200 // get a reference pointer to the thread
201
203 thread_handle,
205 NULL,
207 &device_extension->ThreadPointer,
208 NULL);
209
210 ZwClose(thread_handle);
211
212 if (!NT_SUCCESS(status)) {
213 VFDTRACE(VFDERR,
214 ("[VFD] ObReferenceObjectByHandle() %s\n",
215 GetStatusName(status)));
216 goto cleanup;
217 }
218
219 //
220 // Load the persistent drive letter from the registry
221 //
222 if (driver_extension->RegistryPath.Buffer) {
224 driver_extension->RegistryPath.Buffer);
225 // error is not fatal here
226 }
227
228 // increment the number of devices in the driver extension
229
230 driver_extension->NumberOfDevices++;
231
232 if (DriverObject->DriverUnload) {
233 // not called from the DriverEntry routine
234 device_object->Flags &= ~DO_DEVICE_INITIALIZING;
235 }
236
237#ifdef VFD_PNP
238 if (Parameter) {
239 // return the device object pointer
240 *(PDEVICE_OBJECT *)Parameter = device_object;
241 }
242#else // VFD_PNP
243 device_extension->DriverExtension = driver_extension;
244#endif // VFD_PNP
245
246 VFDTRACE(VFDINFO | VFDDEV, ("[VFD] VfdCreateDevice - OK\n"));
247
248 return STATUS_SUCCESS;
249
250cleanup:
251 //
252 // Something went wrong at one point
253 // Delete all resources that might be created in this function
254 //
255 if (thread_handle) {
256
257 // terminate the device thread
258 device_extension->TerminateThread = TRUE;
259
261 &device_extension->RequestEvent,
262 (KPRIORITY) 0,
263 FALSE);
264
265 if (device_extension->ThreadPointer) {
267 }
268 }
269
270 VFDTRACE(VFDINFO|VFDDEV,
271 ("[VFD] Deleting symbolic link %ws\n", name_buffer));
272
273 IoDeleteSymbolicLink(&unicode_name);
274
275 if (device_extension->DeviceName.Buffer) {
276 VFDTRACE(VFDINFO|VFDDEV, ("[VFD] Deleting device %ws\n",
277 device_extension->DeviceName.Buffer));
278
279 ExFreePool(device_extension->DeviceName.Buffer);
280 }
281
282 IoDeleteDevice(device_object);
284
285 VFDTRACE(VFDINFO|VFDDEV,
286 ("[VFD] VfdCreateDevice - %s\n",
287 GetStatusName(status)));
288
289 return status;
290}
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
#define TRUE
Definition: types.h:120
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
LONG KPRIORITY
Definition: compat.h:803
static void cleanup(void)
Definition: main.c:1335
struct _BEEP_DEVICE_EXTENSION * PDEVICE_EXTENSION
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
PCONFIGURATION_INFORMATION NTAPI IoGetConfigurationInformation(VOID)
Returns a pointer to the I/O manager's global configuration information structure.
Definition: iorsrce.c:998
int _snwprintf(wchar_t *buffer, size_t count, const wchar_t *format,...)
#define KernelMode
Definition: asm.h:34
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1339
ULONG ACCESS_MASK
Definition: nt_native.h:40
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define FILE_FLOPPY_DISKETTE
Definition: nt_native.h:809
#define FILE_REMOVABLE_MEDIA
Definition: nt_native.h:807
#define UNICODE_NULL
@ SynchronizationEvent
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1904
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
Definition: thread.c:602
#define STATUS_OBJECT_NAME_EXISTS
Definition: ntstatus.h:114
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:494
#define FILE_DEVICE_DISK
Definition: winioctl.h:113
PVOID DeviceExtension
Definition: env_spec_w32.h:418
UNICODE_STRING RegistryPath
Definition: vfddrv.h:64
ULONG NumberOfDevices
Definition: vfddrv.h:65
Definition: ps.c:97
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_DRIVER_INTERNAL_ERROR
Definition: udferr_usr.h:177
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
VOID NTAPI VfdDeviceThread(IN PVOID ThreadContext)
Definition: vfddrv.c:404
PWSTR VfdCopyUnicode(PUNICODE_STRING dst, PUNICODE_STRING src)
Definition: vfddrv.c:489
struct _VFD_DRIVER_EXTENSION * PVFD_DRIVER_EXTENSION
NTSTATUS VfdLoadLink(IN PDEVICE_EXTENSION DeviceExtension, IN PWSTR RegistryPath)
Definition: vfdlink.c:135
const DISK_GEOMETRY geom_tbl[VFD_MEDIA_MAX]
#define VFD_DEVICE_BASENAME
Definition: vfdio.h:35
#define ObDereferenceObject
Definition: obfuncs.h:203
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:336
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by DriverEntry().

◆ VfdDeleteDevice()

VOID VfdDeleteDevice ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 296 of file vfddev.c.

298{
300 PVFD_DRIVER_EXTENSION driver_extension;
301 UNICODE_STRING unicode_name;
302 WCHAR name_buffer[40];
303
304 VFDTRACE(VFDINFO|VFDDEV, ("[VFD] VfdDeleteDevice - IN\n"));
305
307
308 //
309 // decrement the number of device in the driver extension
310 //
311#ifdef VFD_PNP
312 driver_extension = IoGetDriverObjectExtension(
313 DeviceObject->DriverObject, VFD_DRIVER_EXTENSION_ID);
314#else // VFD_PNP
315 driver_extension = device_extension->DriverExtension;
316#endif // VFD_PNP
317
318 if (driver_extension) {
319 driver_extension->NumberOfDevices--;
320 }
321
322 //
323 // cleanup the device object
324 //
325
326 // Terminate the device thread
327
328 device_extension->TerminateThread = TRUE;
329
331 &device_extension->RequestEvent,
332 (KPRIORITY) 0,
333 FALSE);
334
336 device_extension->ThreadPointer,
337 Executive,
339 FALSE,
340 NULL);
341
343 device_extension->ThreadPointer);
344
345 // Delete security context object
346
347 if (device_extension->SecurityContext) {
349 ExFreePool(device_extension->SecurityContext);
350 }
351
352 // Close the image file or free the image buffer
353
354 if (device_extension->FileHandle) {
355 ZwClose(device_extension->FileHandle);
356 }
357
358 if (device_extension->FileBuffer) {
359 ExFreePool(device_extension->FileBuffer);
360 }
361
362 // Release the image path buffer
363
364 if (device_extension->FileName.Buffer) {
365 ExFreePool(device_extension->FileName.Buffer);
366 }
367
368 // Remove the interface symbolic link
369
370#ifndef __REACTOS__
371 name_buffer[sizeof(name_buffer) - 1] = UNICODE_NULL;
372
373 _snwprintf(name_buffer, sizeof(name_buffer) - 1,
374 L"\\??\\" VFD_DEVICE_BASENAME L"%lu",
375 device_extension->DeviceNumber);
376#else
377 name_buffer[ARRAYSIZE(name_buffer) - 1] = UNICODE_NULL;
378
379 _snwprintf(name_buffer, ARRAYSIZE(name_buffer) - 1,
380 L"\\??\\" VFD_DEVICE_BASENAME L"%lu",
381 device_extension->DeviceNumber);
382#endif
383
384 RtlInitUnicodeString(&unicode_name, name_buffer);
385
386 VFDTRACE(VFDINFO|VFDDEV,
387 ("[VFD] Deleting link %ws\n", name_buffer));
388
389 IoDeleteSymbolicLink(&unicode_name);
390
391 // Remove the persistent drive letter
392
393 if (device_extension->DriveLetter) {
394#ifdef VFD_MOUNT_MANAGER
395 if (OsMajorVersion >= 5) {
396 // Request the mount manager to remove the drive letter.
397 // This will cause the mount manager to update its database
398 // and it won't arbitrarily assign the drive letter the next
399 // time the driver starts.
400 VfdMountMgrMountPoint(device_extension, 0);
401 }
402 else
403#endif // VFD_MOUNT_MANAGER
404 {
405 // Windows NT style drive letter handling
406 // Simply remove the symbolic link
408 }
409 }
410
411 // Release the device name buffer
412
413 if (device_extension->DeviceName.Buffer) {
414 VFDTRACE(VFDINFO|VFDDEV,
415 ("[VFD] Deleting device %ws\n",
416 device_extension->DeviceName.Buffer));
417
418 ExFreePool(device_extension->DeviceName.Buffer);
419 }
420
421 // Delete the device object
422
425
426 VFDTRACE(VFDINFO|VFDDEV,
427 ("[VFD] VfdDeleteDevice - OUT\n"));
428
429 return;
430}
struct _device_extension device_extension
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define SeDeleteClientSecurity(C)
Definition: imports.h:320
ULONG OsMajorVersion
NTSTATUS VfdSetLink(IN PDEVICE_EXTENSION DeviceExtension, IN CHAR DriveLetter)
Definition: vfdlink.c:24
@ Executive
Definition: ketypes.h:415

Referenced by VfdUnloadDriver().

◆ VfdDeviceControl()

NTSTATUS NTAPI VfdDeviceControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 29 of file vfdioctl.c.

32{
34 PIO_STACK_LOCATION io_stack;
36
39
40 Irp->IoStatus.Information = 0;
41
42 VFDTRACE(VFDINFO, ("[VFD] %-40s %ws\n",
43 GetIoControlName(IO_CTRLCODE(io_stack)),
44 device_extension->DeviceName.Buffer));
45
46#ifdef VFD_PNP
48
49 if (!NT_SUCCESS(status)) {
50 VFDTRACE(0,
51 ("Acquire RemoveLock failed %s\n", NtStatusToStr(status)));
52
53 Irp->IoStatus.Status = status;
55 return status;
56 }
57#endif // VFD_PNP
58
59/*
60 // Check if volume verification is required
61
62 if ((DeviceObject->Flags & DO_VERIFY_VOLUME) &&
63 !(io_stack->Flags & SL_OVERRIDE_VERIFY_VOLUME)) {
64
65 VFDTRACE(VFDWARN,
66 ("[VFD] %-40s - %s\n",
67 GetIoControlName(IO_CTRLCODE(io_stack)),
68 GetStatusName(STATUS_VERIFY_REQUIRED)));
69
70 Irp->IoStatus.Status = STATUS_VERIFY_REQUIRED;
71
72 IoCompleteRequest(Irp, IO_NO_INCREMENT);
73
74 return STATUS_VERIFY_REQUIRED;
75 }
76*/
77
78 switch (IO_CTRLCODE(io_stack)) {
80 // Open an image file or create an empty RAM disk.
81 // Only a few checks are done here.
82 // Actual operation is done in device thread
83
86 (PVFD_IMAGE_INFO)Irp->AssociatedIrp.SystemBuffer,
87 IO_INPUTLEN(io_stack));
88
89 if (!NT_SUCCESS(status)) {
90 break;
91 }
92
93 // Pass the task to the device thread
95 break;
96
100 // Close the current image file or delete the RAM disk
101 // Only status check is done here.
102 // Actual operation is done in device thread.
103
104 if (!device_extension->FileHandle &&
105 !device_extension->FileBuffer) {
107 break;
108 }
109
110 // Pass the task to the device thread
112 break;
113
115 // Returns current image file information
116
119 (PVFD_IMAGE_INFO)Irp->AssociatedIrp.SystemBuffer,
120 IO_OUTPUTLEN(io_stack),
121 &Irp->IoStatus.Information);
122
123 break;
124
126 // Create / remove a persistent drive letter
127 // and store it in the registry
128
129 if (IO_INPUTLEN(io_stack) < sizeof(CHAR)) {
131 break;
132 }
133
134#ifdef VFD_MOUNT_MANAGER
135 if (OsMajorVersion >= 5) {
136 // Windows 2000/XP
137 // Create a drive letter via the mount manager
138
139 status = VfdMountMgrMountPoint(device_extension,
140 *(PCHAR)Irp->AssociatedIrp.SystemBuffer);
141
142 // The new drive letter will be stored in the device extension
143 // and the registry when IOCTL_MOUNTDEV_LINK_CREATED or
144 // IOCTL_MOUNTDEV_LINK_DELETED is issued from the mount manager.
145 }
146 else
147#else // VFD_MOUNT_MANAGER
148 {
149 // Windows NT style drive letter assignment
150 // Simply create a symbolic link and store the new value
151
153 *(PCHAR)Irp->AssociatedIrp.SystemBuffer);
154
155 if (NT_SUCCESS(status)) {
156 // Store the new drive letter into the registry
158 }
159 }
160#endif // VFD_MOUNT_MANAGER
161 break;
162
164 // Return the current persistent drive letter
165
166 if (IO_OUTPUTLEN(io_stack) < sizeof(CHAR)) {
168 break;
169 }
170
171 *(PCHAR)Irp->AssociatedIrp.SystemBuffer =
172 device_extension->DriveLetter;
173
174 Irp->IoStatus.Information = sizeof(CHAR);
176 break;
177
179 // Set media protect flag
180
181 if (!device_extension->FileHandle &&
182 !device_extension->FileBuffer) {
184 break;
185 }
186
189 break;
190
192 // Clear media protect flag
193
194 if (!device_extension->FileHandle &&
195 !device_extension->FileBuffer) {
197 break;
198 }
199
200 device_extension->MediaFlags &= ~VFD_FLAG_WRITE_PROTECTED;
202 break;
203
205 // Reset the data modify flag
206
207 if (!device_extension->FileHandle &&
208 !device_extension->FileBuffer) {
210 break;
211 }
212
213 device_extension->MediaFlags &= ~VFD_FLAG_DATA_MODIFIED;
215 break;
216
218 // Return VFD device number (\??\VirtualFD<n>)
219
220 if (IO_OUTPUTLEN(io_stack) < sizeof(ULONG)) {
222 break;
223 }
224
225 *(PULONG)Irp->AssociatedIrp.SystemBuffer=
226 device_extension->DeviceNumber;
227
228 Irp->IoStatus.Information = sizeof(ULONG);
230 break;
231
233 // Return VFD device name (\Device\Floppy<n>)
234 // counted unicode string (not null terminated)
235
236 if (IO_OUTPUTLEN(io_stack) < sizeof(USHORT)) {
238 break;
239 }
240
241 {
242 PUSHORT p = (PUSHORT)Irp->AssociatedIrp.SystemBuffer;
243
244 *p = device_extension->DeviceName.Length;
245
246 if (IO_OUTPUTLEN(io_stack) < sizeof(USHORT) + *p) {
247
248 Irp->IoStatus.Information = sizeof(USHORT);
250 break;
251 }
252
253 RtlCopyMemory(p + 1, device_extension->DeviceName.Buffer, *p);
254
255 Irp->IoStatus.Information = sizeof(USHORT) + *p;
256 }
257
259 break;
260
262 // Return the VFD driver version
263
264 if (IO_OUTPUTLEN(io_stack) < sizeof(ULONG)) {
266 break;
267 }
268
269 *(PULONG)Irp->AssociatedIrp.SystemBuffer =
271
272 Irp->IoStatus.Information = sizeof(ULONG);
274 break;
275
276 //
277 // standard disk and storage I/O control requests
278 //
279
283
284 if (IO_OUTPUTLEN(io_stack) >= sizeof(ULONG)) {
285
286 *(PULONG)Irp->AssociatedIrp.SystemBuffer =
287 device_extension->MediaChangeCount;
288
289 Irp->IoStatus.Information = sizeof(ULONG);
290 }
291
293 break;
294
297 // Only parameter checks are performed here
298 // Actual operation is done by the device thread
299
302 (PFORMAT_PARAMETERS)Irp->AssociatedIrp.SystemBuffer,
303 IO_INPUTLEN(io_stack),
304 IO_CTRLCODE(io_stack));
305
306 if (!NT_SUCCESS(status)) {
307 break;
308 }
309
310 // Pass the task to the device thread
312 break;
313
315 // Returns the geometry of current media
316
317 if (!device_extension->FileHandle &&
318 !device_extension->FileBuffer) {
320 break;
321 }
322 // fall through
323
326 // Return *the last mounted* disk geometry, although xxx_GET_MEDIA_TYPES
327 // commands are supposed to return all supported media types.
328 // This makes the matter much simpler...;-)
329 // If no image has been mounted yet, 1.44MB media is assumed.
330
331 if (IO_OUTPUTLEN(io_stack) < sizeof(DISK_GEOMETRY)) {
333 }
334
335 // Copy appropriate DISK_GEOMETRY into the output buffer
336
337 if (device_extension->Geometry) {
339 Irp->AssociatedIrp.SystemBuffer,
340 device_extension->Geometry,
341 sizeof(DISK_GEOMETRY));
342 }
343 else {
344 // default = 3.5" 1.44 MB media
346 Irp->AssociatedIrp.SystemBuffer,
348 sizeof(DISK_GEOMETRY));
349 }
350 Irp->IoStatus.Information = sizeof(DISK_GEOMETRY);
351
353 break;
354
356 // Return disk length information
357 // (Windows XP requires this request to be handled)
358
359 if (!device_extension->FileHandle &&
360 !device_extension->FileBuffer) {
362 break;
363 }
364
365 if (IO_OUTPUTLEN(io_stack) < sizeof(GET_LENGTH_INFORMATION)) {
367 break;
368 }
369
370 ((PGET_LENGTH_INFORMATION)Irp->AssociatedIrp.SystemBuffer)->Length.QuadPart =
372
373 Irp->IoStatus.Information = sizeof(GET_LENGTH_INFORMATION);
374
376 break;
377
379 // Checks if current media is writable
380
381 if (!device_extension->FileHandle &&
382 !device_extension->FileBuffer) {
384 }
385 else if (device_extension->MediaFlags & VFD_FLAG_WRITE_PROTECTED) {
387 }
388 else {
390 }
391 break;
392
393/*
394 case IOCTL_DISK_MEDIA_REMOVAL:
395 case IOCTL_STORAGE_MEDIA_REMOVAL:
396 // Since removal lock is irrelevant for virtual disks,
397 // there's really nothing to do here...
398
399 status = STATUS_SUCCESS;
400 break;
401
402 case IOCTL_STORAGE_GET_HOTPLUG_INFO:
403 {
404 PSTORAGE_HOTPLUG_INFO hotplug;
405
406 if (IO_OUTPUTLEN(io_stack) < sizeof(STORAGE_HOTPLUG_INFO)) {
407 status = STATUS_BUFFER_TOO_SMALL;
408 break;
409 }
410
411 hotplug = (PSTORAGE_HOTPLUG_INFO)Irp->AssociatedIrp.SystemBuffer;
412
413 RtlZeroMemory(hotplug, sizeof(STORAGE_HOTPLUG_INFO));
414
415 hotplug->Size = sizeof(STORAGE_HOTPLUG_INFO);
416 hotplug->MediaRemovable = 1;
417
418 Irp->IoStatus.Information = sizeof(STORAGE_HOTPLUG_INFO);
419 status = STATUS_SUCCESS;
420 }
421 break;
422*/
423
424#ifdef VFD_MOUNT_MANAGER
425 //
426 // IO control requests received from the mount manager
427 // (on Windows 2000 / XP)
428 //
429
431 // Returns a unique ID for the target device
432 status = VfdMountDevUniqueId(
434 Irp->AssociatedIrp.SystemBuffer,
435 IO_OUTPUTLEN(io_stack),
436 &Irp->IoStatus);
437 break;
438
439// case IOCTL_MOUNTDEV_UNIQUE_ID_CHANGE_NOTIFY:
440
442 // Returns the device name of the target device
443 status = VfdMountDevDeviceName(
445 Irp->AssociatedIrp.SystemBuffer,
446 IO_OUTPUTLEN(io_stack),
447 &Irp->IoStatus);
448 break;
449
451 // Returns the drive letter link which we want the mount manager
452 // to create. This request is issued in response to the volume
453 // arrival notification, and the mount manager will create the
454 // symbolic link.
455 status = VfdMountDevSuggestedLink(
457 Irp->AssociatedIrp.SystemBuffer,
458 IO_OUTPUTLEN(io_stack),
459 &Irp->IoStatus);
460 break;
461
464 // Issued after the mount manager created/deleted a symbolic link
465 status = VfdMountDevLinkModified(
467 Irp->AssociatedIrp.SystemBuffer,
468 IO_INPUTLEN(io_stack),
469 IO_CTRLCODE(io_stack));
470 break;
471
472/*
473 case IOCTL_MOUNTDEV_QUERY_STABLE_GUID:
474 {
475 PMOUNTDEV_STABLE_GUID guid;
476
477 if (IO_OUTPUTLEN(io_stack) < sizeof(MOUNTDEV_STABLE_GUID)) {
478 status = STATUS_INVALID_PARAMETER;
479 break;
480 }
481
482 guid = Irp->AssociatedIrp.SystemBuffer;
483
484 RtlCopyMemory(
485 &guid->StableGuid, &VFD_GUID, sizeof(GUID));
486
487 Irp->IoStatus.Information = sizeof(guid);
488 status = STATUS_SUCCESS;
489 }
490 break;
491*/
492#endif // VFD_MOUNT_MANAGER
493
494 default:
495 // Unknown IOCTL request
497 break;
498 }
499
500#if DBG
501 if ((NT_SUCCESS(status) && (TraceFlags & VFDINFO) == VFDINFO) ||
502 (TraceFlags & VFDWARN) == VFDWARN) {
503 VFDTRACE(0,("[VFD] %-40s - %s\n",
504 GetIoControlName(IO_CTRLCODE(io_stack)),
505 GetStatusName(status)));
506 }
507#endif
508
509 if (status == STATUS_PENDING) {
510 // Let the device thread perform the operation
511
513
515 &device_extension->ListHead,
516 &Irp->Tail.Overlay.ListEntry,
517 &device_extension->ListLock);
518
520 &device_extension->RequestEvent,
521 (KPRIORITY) 0,
522 FALSE);
523 }
524 else {
525 // complete the operation
526
527 Irp->IoStatus.Status = status;
529
530#ifdef VFD_PNP
532#endif // VFD_PNP
533 }
534
535 return status;
536}
#define IOCTL_DISK_CHECK_VERIFY
Definition: cdrw_usr.h:175
#define IOCTL_DISK_GET_DRIVE_GEOMETRY
Definition: cdrw_usr.h:169
#define IOCTL_DISK_FORMAT_TRACKS_EX
Definition: cdrw_usr.h:173
#define IOCTL_DISK_EJECT_MEDIA
Definition: cdrw_usr.h:177
#define IOCTL_DISK_GET_MEDIA_TYPES
Definition: cdrw_usr.h:182
#define IOCTL_DISK_IS_WRITABLE
Definition: cdrw_usr.h:172
#define IOCTL_DISK_FORMAT_TRACKS
Definition: cdrw_usr.h:171
#define IOCTL_STORAGE_CHECK_VERIFY2
Definition: ntddk_ex.h:212
GLfloat GLfloat p
Definition: glext.h:8902
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
IoMarkIrpPending(Irp)
if(dx< 0)
Definition: linetemp.h:194
#define PCHAR
Definition: match.c:90
struct _GET_LENGTH_INFORMATION * PGET_LENGTH_INFORMATION
#define IOCTL_MOUNTDEV_LINK_CREATED
Definition: imports.h:106
#define IOCTL_MOUNTDEV_QUERY_DEVICE_NAME
Definition: imports.h:93
#define IOCTL_MOUNTDEV_QUERY_SUGGESTED_LINK_NAME
Definition: imports.h:99
#define IOCTL_DISK_GET_LENGTH_INFO
Definition: imports.h:192
#define IOCTL_MOUNTDEV_QUERY_UNIQUE_ID
Definition: imports.h:80
#define IOCTL_MOUNTDEV_LINK_DELETED
Definition: imports.h:112
struct _DISK_GEOMETRY DISK_GEOMETRY
#define IOCTL_STORAGE_CHECK_VERIFY
Definition: ntddstor.h:98
#define IOCTL_STORAGE_GET_MEDIA_TYPES
Definition: ntddstor.h:131
#define IOCTL_STORAGE_EJECT_MEDIA
Definition: ntddstor.h:107
#define STATUS_PENDING
Definition: ntstatus.h:82
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
uint32_t * PULONG
Definition: typedefs.h:59
uint16_t * PUSHORT
Definition: typedefs.h:56
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
char * PCHAR
Definition: typedefs.h:51
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_MEDIA_WRITE_PROTECTED
Definition: udferr_usr.h:161
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_NO_MEDIA_IN_DEVICE
Definition: udferr_usr.h:141
NTSTATUS VfdFormatCheck(IN PDEVICE_EXTENSION DeviceExtension, IN PFORMAT_PARAMETERS FormatParams, IN ULONG InputLength, IN ULONG ControlCode)
NTSTATUS VfdQueryImage(IN PDEVICE_EXTENSION DeviceExtension, OUT PVFD_IMAGE_INFO ImageInfo, IN ULONG BufferLength, OUT PULONG ReturnLength)
Definition: vfdimg.c:466
NTSTATUS VfdStoreLink(IN PDEVICE_EXTENSION DeviceExtension)
Definition: vfdlink.c:190
NTSTATUS VfdOpenCheck(IN PDEVICE_EXTENSION DeviceExtension, IN PVFD_IMAGE_INFO ImageInfo, IN ULONG InputLength)
#define IOCTL_VFD_RESET_MODIFY
Definition: vfdio.h:299
#define IOCTL_VFD_QUERY_IMAGE
Definition: vfdio.h:163
#define IOCTL_VFD_SET_LINK
Definition: vfdio.h:194
#define IOCTL_VFD_CLOSE_IMAGE
Definition: vfdio.h:133
#define IOCTL_VFD_SET_PROTECT
Definition: vfdio.h:247
#define IOCTL_VFD_QUERY_LINK
Definition: vfdio.h:221
#define IOCTL_VFD_QUERY_VERSION
Definition: vfdio.h:387
#define IOCTL_VFD_CLEAR_PROTECT
Definition: vfdio.h:273
#define IOCTL_VFD_QUERY_NAME
Definition: vfdio.h:358
#define IOCTL_VFD_QUERY_NUMBER
Definition: vfdio.h:325
#define VFD_SECTOR_TO_BYTE(s)
Definition: vfdio.h:45
#define IOCTL_VFD_OPEN_IMAGE
Definition: vfdio.h:107
#define IO_INPUTLEN(p)
Definition: vfdioctl.c:20
#define IO_CTRLCODE(p)
Definition: vfdioctl.c:22
#define IO_OUTPUTLEN(p)
Definition: vfdioctl.c:21
@ VFD_MEDIA_F3_1P4
Definition: vfdtypes.h:39
#define VFD_FLAG_WRITE_PROTECTED
Definition: vfdtypes.h:68
#define VFD_DRIVER_MINOR
Definition: vfdver.h:21
#define VFD_DEBUG_FLAG
Definition: vfdver.h:40
#define VFD_DRIVER_MAJOR
Definition: vfdver.h:20
#define IoAcquireRemoveLock(RemoveLock, Tag)
#define IoReleaseRemoveLock(_RemoveLock, _Tag)
Definition: iofuncs.h:2764
char CHAR
Definition: xmlstorage.h:175

Referenced by DriverEntry().

◆ VfdDeviceThread()

VOID NTAPI VfdDeviceThread ( IN PVOID  ThreadContext)

Definition at line 404 of file vfddrv.c.

406{
407 PDEVICE_OBJECT device_object;
410 PIRP irp;
411 PIO_STACK_LOCATION io_stack;
412
413 ASSERT(ThreadContext != NULL);
414
415 device_object = (PDEVICE_OBJECT)ThreadContext;
416
418
420
421 for (;;) {
422 // wait for the request event to be signalled
424 &device_extension->RequestEvent,
425 Executive,
427 FALSE,
428 NULL);
429
430 // terminate request ?
431 if (device_extension->TerminateThread) {
432 VFDTRACE(0, ("[VFD] Exitting the I/O thread\n"));
434 }
435
436 // perform requested tasks
437
439 &device_extension->ListHead,
440 &device_extension->ListLock)) != NULL)
441 {
442 irp = CONTAINING_RECORD(request, IRP, Tail.Overlay.ListEntry);
443
445
446 irp->IoStatus.Information = 0;
447
448 switch (io_stack->MajorFunction) {
449 case IRP_MJ_READ:
451 io_stack->Parameters.Read.Length,
452 &io_stack->Parameters.Read.ByteOffset);
453 break;
454
455 case IRP_MJ_WRITE:
457 io_stack->Parameters.Write.Length,
458 &io_stack->Parameters.Write.ByteOffset);
459 break;
460
463 io_stack->Parameters.DeviceIoControl.IoControlCode);
464 break;
465
466 default:
467 // This shouldn't happen...
468 VFDTRACE(0,
469 ("[VFD] %s passed to the I/O thread\n",
470 GetMajorFuncName(io_stack->MajorFunction)));
471
472 irp->IoStatus.Status = STATUS_DRIVER_INTERNAL_ERROR;
473 }
474
476 (CCHAR)(NT_SUCCESS(irp->IoStatus.Status) ?
478
479#ifdef VFD_PNP
481#endif // VFD_PNP
482 } // while
483 } // for (;;)
484}
struct _DEVICE_OBJECT * PDEVICE_OBJECT
FxIrp * irp
#define KeGetCurrentThread
Definition: hal.h:55
#define LOW_REALTIME_PRIORITY
PLIST_ENTRY NTAPI ExInterlockedRemoveHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:166
NTSTATUS NTAPI PsTerminateSystemThread(IN NTSTATUS ExitStatus)
Definition: kill.c:1145
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
struct _IO_STACK_LOCATION::@3989::@3994 Write
union _IO_STACK_LOCATION::@1571 Parameters
struct _IO_STACK_LOCATION::@1571::@1572 DeviceIoControl
struct _IO_STACK_LOCATION::@3989::@3993 Read
Definition: typedefs.h:120
Definition: tftpd.h:86
KPRIORITY NTAPI KeSetPriorityThread(IN PKTHREAD Thread, IN KPRIORITY Priority)
Definition: thrdobj.c:1319
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
char CCHAR
Definition: typedefs.h:51
VOID VfdReadData(IN PDEVICE_EXTENSION DeviceExtension, IN OUT PIRP Irp, IN ULONG Length, IN PLARGE_INTEGER Offset)
Definition: vfdrdwr.c:217
VOID VfdIoCtlThread(IN PDEVICE_EXTENSION DeviceExtension, IN PIRP Irp, IN ULONG ControlCode)
Definition: vfdioctl.c:542
VOID VfdWriteData(IN PDEVICE_EXTENSION DeviceExtension, IN OUT PIRP Irp, IN ULONG Length, IN PLARGE_INTEGER Offset)
Definition: vfdrdwr.c:287
#define IO_DISK_INCREMENT
Definition: iotypes.h:600

Referenced by VfdCreateDevice().

◆ VfdFormatCheck()

NTSTATUS VfdFormatCheck ( IN PDEVICE_EXTENSION  DeviceExtension,
IN PFORMAT_PARAMETERS  FormatParams,
IN ULONG  InputLength,
IN ULONG  ControlCode 
)

Referenced by VfdDeviceControl().

◆ VfdFormatTrack()

NTSTATUS VfdFormatTrack ( IN PDEVICE_EXTENSION  DeviceExtension,
IN PFORMAT_PARAMETERS  FormatParams 
)

Definition at line 153 of file vfdfmt.c.

156{
157 const DISK_GEOMETRY *geometry;
158 ULONG track_length;
159 PUCHAR format_buffer;
160 LARGE_INTEGER start_offset;
161 LARGE_INTEGER end_offset;
163
164 VFDTRACE(0, ("[VFD] VfdFormatTrack - IN\n"));
165
166 ASSERT(DeviceExtension != NULL);
167
168 geometry = DeviceExtension->Geometry;
169
170 if (!geometry) {
172 }
173
174 track_length = geometry->BytesPerSector * geometry->SectorsPerTrack;
175
176 format_buffer = (PUCHAR)ExAllocatePoolWithTag(
177 PagedPool, track_length, VFD_POOL_TAG);
178
179 if (format_buffer == NULL) {
180 VFDTRACE(0, ("[VFD] cannot allocate a format buffer\n"));
182 }
183
184 RtlFillMemory(format_buffer, track_length, VFD_FORMAT_FILL_DATA);
185
186 start_offset.QuadPart =
187 FormatParams->StartCylinderNumber * geometry->TracksPerCylinder * track_length +
188 FormatParams->StartHeadNumber * track_length;
189
190 end_offset.QuadPart =
191 FormatParams->EndCylinderNumber * geometry->TracksPerCylinder * track_length +
192 FormatParams->EndHeadNumber * track_length;
193
194 do {
195 if (DeviceExtension->FileHandle) {
197
198 status = ZwWriteFile(
199 DeviceExtension->FileHandle,
200 NULL,
201 NULL,
202 NULL,
203 &io_status,
204 format_buffer,
205 track_length,
206 &start_offset,
207 NULL);
208
209 if (!NT_SUCCESS(status)) {
210 VFDTRACE(0, ("[VFD] ZwWriteFile - %s\n",
211 GetStatusName(status)));
212 break;
213 }
214 }
215 else {
217 DeviceExtension->FileBuffer + start_offset.QuadPart,
218 format_buffer,
219 track_length);
220
222 }
223
224 start_offset.QuadPart += track_length;
225 }
226 while (start_offset.QuadPart <= end_offset.QuadPart);
227
228 ExFreePool(format_buffer);
229
230 VFDTRACE(0, ("[VFD] VfdFormatTrack - OUT\n"));
231
232 return status;
233}
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:599
static HANDLE PIO_APC_ROUTINE void PIO_STATUS_BLOCK io_status
Definition: comm.c:56
ULONG TracksPerCylinder
Definition: ntdddisk.h:407
ULONG SectorsPerTrack
Definition: ntdddisk.h:408
ULONG BytesPerSector
Definition: ntdddisk.h:409
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
unsigned char * PUCHAR
Definition: typedefs.h:53
LONGLONG QuadPart
Definition: typedefs.h:114
#define VFD_POOL_TAG
Definition: vfddrv.h:25
#define VFD_FORMAT_FILL_DATA
Definition: vfdio.h:51

Referenced by VfdIoCtlThread().

◆ VfdFreeUnicode()

VOID VfdFreeUnicode ( IN OUT PUNICODE_STRING  str)

◆ VfdIoCtlThread()

VOID VfdIoCtlThread ( IN PDEVICE_EXTENSION  DeviceExtension,
IN PIRP  Irp,
IN ULONG  ControlCode 
)

Definition at line 542 of file vfdioctl.c.

546{
547 switch (ControlCode) {
549 // open the file from the caller's security context
550 // -- this allows this driver to open network files
551 if (DeviceExtension->SecurityContext) {
552 SeImpersonateClient(DeviceExtension->SecurityContext, NULL);
553 }
554
555 Irp->IoStatus.Status = VfdOpenImage(DeviceExtension,
556 (PVFD_IMAGE_INFO)Irp->AssociatedIrp.SystemBuffer);
557
559 break;
560
564 VfdCloseImage(DeviceExtension);
565 Irp->IoStatus.Status = STATUS_SUCCESS;
566 break;
567
570 Irp->IoStatus.Status = VfdFormatTrack(DeviceExtension,
571 (PFORMAT_PARAMETERS)Irp->AssociatedIrp.SystemBuffer);
572 break;
573
574 default:
575 // This shouldn't happen...
576 VFDTRACE(0,
577 ("[VFD] %s passed to the device thread\n",
578 GetIoControlName(ControlCode)));
579
580 Irp->IoStatus.Status = STATUS_DRIVER_INTERNAL_ERROR;
581 }
582
583#if DBG
584 if ((NT_SUCCESS(Irp->IoStatus.Status) && (TraceFlags & VFDINFO) == VFDINFO) ||
585 (TraceFlags & VFDWARN) == VFDWARN) {
586 VFDTRACE(0,("[VFD] %-40s - %s\n",
587 GetIoControlName(ControlCode),
588 GetStatusName(Irp->IoStatus.Status)));
589 }
590#endif
591}
NTKERNELAPI VOID NTAPI PsRevertToSelf(VOID)
Definition: security.c:556
NTKERNELAPI VOID NTAPI SeImpersonateClient(IN PSECURITY_CLIENT_CONTEXT ClientContext, IN PETHREAD ServerThread OPTIONAL)
NTSTATUS VfdFormatTrack(IN PDEVICE_EXTENSION DeviceExtension, IN PFORMAT_PARAMETERS FormatParams)
Definition: vfdfmt.c:153
VOID VfdCloseImage(IN PDEVICE_EXTENSION DeviceExtension)
Definition: vfdimg.c:435
NTSTATUS VfdOpenImage(IN PDEVICE_EXTENSION DeviceExtension, IN PVFD_IMAGE_INFO ImageInfo)
Definition: vfdimg.c:104
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55

Referenced by VfdDeviceThread().

◆ VfdLoadLink()

NTSTATUS VfdLoadLink ( IN PDEVICE_EXTENSION  DeviceExtension,
IN PWSTR  RegistryPath 
)

Definition at line 135 of file vfdlink.c.

138{
140 WCHAR name_buf[20];
141 ULONG letter;
142 ULONG zero = 0;
144
145 VFDTRACE(VFDINFO, ("[VFD] VfdLoadLink - IN\n"));
146
147 RtlZeroMemory(params, sizeof(params));
148
149#ifndef __REACTOS__
150 name_buf[sizeof(name_buf) - 1] = UNICODE_NULL;
151
152 _snwprintf(name_buf, sizeof(name_buf) - 1,
154 DeviceExtension->DeviceNumber);
155#else
156 name_buf[ARRAYSIZE(name_buf) - 1] = UNICODE_NULL;
157
158 _snwprintf(name_buf, ARRAYSIZE(name_buf) - 1,
160 DeviceExtension->DeviceNumber);
161#endif
162
164 params[0].Name = name_buf;
165 params[0].EntryContext = &letter;
166 params[0].DefaultType = REG_DWORD;
167 params[0].DefaultData = &zero;
168 params[0].DefaultLength = sizeof(ULONG);
169
173
174 VFDTRACE(VFDINFO,
175 ("[VFD] Drive letter '%wc' loaded from the registry\n",
176 letter ? letter : ' '));
177
178 DeviceExtension->DriveLetter = (CHAR)letter;
179
180 VFDTRACE(VFDINFO,
181 ("[VFD] VfdLoadLink - %s\n", GetStatusName(status)));
182
183 return status;
184}
#define CHAR(Char)
GLenum const GLfloat * params
Definition: glext.h:5645
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
#define RTL_REGISTRY_ABSOLUTE
Definition: nt_native.h:161
#define RTL_QUERY_REGISTRY_DIRECT
Definition: nt_native.h:144
#define RTL_REGISTRY_OPTIONAL
Definition: nt_native.h:169
#define REG_DWORD
Definition: sdbapi.c:596
int zero
Definition: sehframes.cpp:29
#define VFD_REG_DRIVE_LETTER
Definition: vfdio.h:30

Referenced by VfdCreateDevice().

◆ VfdOpenCheck()

NTSTATUS VfdOpenCheck ( IN PDEVICE_EXTENSION  DeviceExtension,
IN PVFD_IMAGE_INFO  ImageInfo,
IN ULONG  InputLength 
)

Referenced by VfdDeviceControl().

◆ VfdOpenImage()

NTSTATUS VfdOpenImage ( IN PDEVICE_EXTENSION  DeviceExtension,
IN PVFD_IMAGE_INFO  ImageInfo 
)

Definition at line 104 of file vfdimg.c.

107{
110 const DISK_GEOMETRY *geometry;
112 ULONG alignment;
113
114 VFDTRACE(0, ("[VFD] VfdOpenImage - IN\n"));
115
116 //
117 // Store file name in the device extension
118 //
119 if (ImageInfo->NameLength) {
120
121 if (ImageInfo->NameLength + 1 >
122 DeviceExtension->FileName.MaximumLength) {
123
124 // expand the filename buffer
125
126 if (DeviceExtension->FileName.Buffer) {
127 ExFreePool(DeviceExtension->FileName.Buffer);
129 &DeviceExtension->FileName,
130 sizeof(ANSI_STRING));
131 }
132
133 DeviceExtension->FileName.Buffer = (PCHAR)ExAllocatePoolWithTag(
134 NonPagedPool, ImageInfo->NameLength + 1, VFD_POOL_TAG);
135
136 if (!DeviceExtension->FileName.Buffer) {
137 VFDTRACE(0, ("[VFD] Can't allocate memory for image path\n"));
139 }
140
141 DeviceExtension->FileName.MaximumLength
142 = (USHORT)(ImageInfo->NameLength + 1);
143
145 DeviceExtension->FileName.Buffer,
146 DeviceExtension->FileName.MaximumLength);
147 }
148
149 if (DeviceExtension->FileName.Buffer) {
151 DeviceExtension->FileName.Buffer,
152 ImageInfo->FileName,
153 ImageInfo->NameLength);
154
155 DeviceExtension->FileName.Buffer[ImageInfo->NameLength] = '\0';
156 }
157 }
158
159 DeviceExtension->FileName.Length = ImageInfo->NameLength;
160
161 //
162 // Get DISK_GEOMETRY and calculate the media capacity
163 // -- validity of the ImageInfo->MediaType value is assured in
164 // the VfdOpenCheck function
165 //
166 geometry = &geom_tbl[ImageInfo->MediaType];
167
168 sectors =
169 geometry->Cylinders.LowPart *
170 geometry->TracksPerCylinder *
171 geometry->SectorsPerTrack;
172
173 if (ImageInfo->ImageSize != 0 &&
174 ImageInfo->ImageSize < VFD_SECTOR_TO_BYTE(sectors)) {
175
176 VFDTRACE(0, ("[VFD] Image is smaller than the media\n"));
178 }
179
180 //
181 // Prepare a virtual media according to the ImageInfo
182 //
183 if (ImageInfo->DiskType == VFD_DISKTYPE_FILE) {
184 //
185 // open an existing image file
186 //
188 OBJECT_ATTRIBUTES attributes;
189 UNICODE_STRING unicode_name;
190 FILE_STANDARD_INFORMATION file_standard;
191 FILE_BASIC_INFORMATION file_basic;
192 FILE_ALIGNMENT_INFORMATION file_alignment;
193 PFILE_OBJECT file_object;
194 BOOLEAN network_drive;
195
196 // convert the filename into a unicode string
197
199 &unicode_name, &DeviceExtension->FileName, TRUE);
200
201 if (!NT_SUCCESS(status)) {
202 VFDTRACE(0, ("[VFD] Failed to convert filename to UNICODE\n"));
203 return status;
204 }
205
206 VFDTRACE(VFDINFO,
207 ("[VFD] Opening %s\n", DeviceExtension->FileName.Buffer));
208
209 // prepare an object attribute to open
210
212 &attributes,
213 &unicode_name,
215 NULL,
216 NULL);
217
218 // open the target file
219
220 status = ZwCreateFile(
223 &attributes,
224 &io_status,
225 NULL,
227 0,
228 FILE_OPEN,
233 NULL,
234 0);
235
236 RtlFreeUnicodeString(&unicode_name);
237
238 if (!NT_SUCCESS(status)) {
239 VFDTRACE(0, ("[VFD] ZwCreateFile - %s\n",
240 GetStatusName(status)));
241 return status;
242 }
243
244 // Check the file size
245
246 status = ZwQueryInformationFile(
248 &io_status,
249 &file_standard,
252
253 if (!NT_SUCCESS(status)) {
254 VFDTRACE(0,
255 ("[VFD] ZwQueryInformationFile - FILE_STANDARD_INFORMATION\n"));
256
258 goto exit_func;
259 }
260
261 // Actual file size can be larger than the media capacity
262
263 if (file_standard.EndOfFile.QuadPart < VFD_SECTOR_TO_BYTE(sectors)) {
264
265 VFDTRACE(0, ("[VFD] file is smaller than the media.\n"));
266
268
270 goto exit_func;
271 }
272
273 DeviceExtension->ImageSize = file_standard.EndOfFile.LowPart;
274
275 // Find out whether the file is on a local disk or a network drive
276
277 network_drive = FALSE;
278
282 NULL,
284#ifndef __REACTOS__
285 &file_object,
286#else
287 (PVOID *)&file_object,
288#endif
289 NULL);
290
291 if (NT_SUCCESS(status)) {
292 if (file_object && file_object->DeviceObject) {
293 VFDTRACE(VFDINFO, ("[VFD] Device type is 0x%08x\n",
294 file_object->DeviceObject->DeviceType));
295
296 if (file_object->DeviceObject->DeviceType
298 network_drive = TRUE;
299 }
300
301 // how about these types ?
302 // FILE_DEVICE_NETWORK
303 // FILE_DEVICE_NETWORK_BROWSER
304 // FILE_DEVICE_NETWORK_REDIRECTOR
305 }
306 else {
307 VFDTRACE(VFDWARN, ("[VFD Cannot decide the device type\n"));
308 }
309 ObDereferenceObject(file_object);
310 }
311 else {
312 VFDTRACE(0, ("[VFD] ObReferenceObjectByHandle - %s\n",
313 GetStatusName(status)));
314 }
315
316 if (!network_drive) {
317 // The NT cache manager can deadlock if a filesystem that is using
318 // the cache manager is used in a virtual disk that stores its file
319 // on a file systemthat is also using the cache manager, this is
320 // why we open the file with FILE_NO_INTERMEDIATE_BUFFERING above,
321 // however if the file is compressed or encrypted NT will not honor
322 // this request and cache it anyway since it need to store the
323 // decompressed/unencrypted data somewhere, therefor we put an
324 // extra check here and don't alow disk images to be compressed/
325 // encrypted.
326
327 status = ZwQueryInformationFile(
329 &io_status,
330 &file_basic,
333
334 if (!NT_SUCCESS(status)) {
335 VFDTRACE(0,
336 ("[VFD] ZwQueryInformationFile - FILE_BASIC_INFORMATION\n"));
337
339 goto exit_func;
340 }
341
342 if (file_basic.FileAttributes
344 {
345 VFDTRACE(0,
346 ("[VFD] Image file is compressed and/or encrypted\n"));
347
349
351 goto exit_func;
352 }
353 }
354
355 // Retrieve the file alignment requirement
356
357 status = ZwQueryInformationFile(
359 &io_status,
360 &file_alignment,
363
364 if (!NT_SUCCESS(status)) {
365 VFDTRACE(0,
366 ("[VFD] ZwQueryInformationFile - FILE_ALIGNMENT_INFORMATION\n"));
367
369 goto exit_func;
370 }
371
372 DeviceExtension->FileHandle = file_handle;
373
374 alignment = file_alignment.AlignmentRequirement;
375
376 VFDTRACE(0, ("[VFD] Opened an image file\n"));
377 }
378 else {
379 //
380 // Create an empty RAM disk
381 //
382 DeviceExtension->FileBuffer = (PUCHAR)ExAllocatePoolWithTag(
386
387 if (!DeviceExtension->FileBuffer) {
388 VFDTRACE(0, ("[VFD] Can't allocate memory for RAM disk\n"));
390 }
391
393 DeviceExtension->FileBuffer,
395
396 if (ImageInfo->ImageSize) {
397 DeviceExtension->ImageSize = ImageInfo->ImageSize;
398 }
399 else {
400 DeviceExtension->ImageSize = VFD_SECTOR_TO_BYTE(sectors);
401 }
402
403 alignment = FILE_WORD_ALIGNMENT;
404
405 VFDTRACE(0, ("[VFD] Created an empty RAM disk\n"));
406 }
407
408 DeviceExtension->MediaChangeCount++;
409
410 DeviceExtension->MediaType = ImageInfo->MediaType;
411 DeviceExtension->MediaFlags = ImageInfo->MediaFlags;
412 DeviceExtension->FileType = ImageInfo->FileType;
413 DeviceExtension->Geometry = geometry;
414 DeviceExtension->Sectors = sectors;
415
416 VFDTRACE(0, ("[VFD] Media:%d Flag:0x%02x Size:%lu Capacity:%lu\n",
417 DeviceExtension->MediaType,
418 DeviceExtension->MediaFlags,
419 DeviceExtension->ImageSize,
420 DeviceExtension->Sectors));
421
422 DeviceExtension->DeviceObject->AlignmentRequirement
423 = alignment;
424
425exit_func:
426 VFDTRACE(0, ("[VFD] VfdOpenImage - %s\n", GetStatusName(status)));
427
428 return status;
429}
unsigned char BOOLEAN
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
#define GENERIC_READ
Definition: compat.h:135
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define NonPagedPool
Definition: env_spec_w32.h:307
@ FileAlignmentInformation
Definition: from_kernel.h:78
@ FileBasicInformation
Definition: from_kernel.h:65
#define FILE_OPEN
Definition: from_kernel.h:54
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define FILE_NO_INTERMEDIATE_BUFFERING
Definition: from_kernel.h:28
#define FILE_RANDOM_ACCESS
Definition: from_kernel.h:38
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
__u8 sectors[2]
Definition: mkdosfs.c:8
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define FILE_ATTRIBUTE_COMPRESSED
Definition: nt_native.h:711
#define FILE_WORD_ALIGNMENT
Definition: nt_native.h:787
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define GENERIC_WRITE
Definition: nt_native.h:90
#define FILE_ATTRIBUTE_ENCRYPTED
Definition: ntifs_ex.h:385
#define FileStandardInformation
Definition: propsheet.cpp:61
#define FILE_DEVICE_NETWORK_FILE_SYSTEM
Definition: winioctl.h:126
static FILE * file_handle
Definition: regtests2xml.c:45
LARGE_INTEGER Cylinders
Definition: ntdddisk.h:405
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
ULONG LowPart
Definition: typedefs.h:106
@ VFD_DISKTYPE_FILE
Definition: vfdtypes.h:18
* PFILE_OBJECT
Definition: iotypes.h:1998

Referenced by CVfdShExt::DoVfdDrop(), OnOK(), Open(), and VfdIoCtlThread().

◆ VfdQueryImage()

NTSTATUS VfdQueryImage ( IN PDEVICE_EXTENSION  DeviceExtension,
OUT PVFD_IMAGE_INFO  ImageInfo,
IN ULONG  BufferLength,
OUT PULONG  ReturnLength 
)

Definition at line 466 of file vfdimg.c.

475{
476 // Check output buffer length
477
478 if (BufferLength < sizeof(VFD_IMAGE_INFO)) {
480 }
481
482 RtlZeroMemory(ImageInfo, BufferLength);
483
484 // Store fixed length image information
485
486 ImageInfo->MediaType = DeviceExtension->MediaType;
487
488 if (DeviceExtension->MediaType == VFD_MEDIA_NONE) {
489 *ReturnLength = sizeof(VFD_IMAGE_INFO);
490 return STATUS_SUCCESS;
491 }
492
493 if (DeviceExtension->FileBuffer) {
494 ImageInfo->DiskType = VFD_DISKTYPE_RAM;
495 }
496 else {
497 ImageInfo->DiskType = VFD_DISKTYPE_FILE;
498 }
499
500 ImageInfo->MediaFlags = DeviceExtension->MediaFlags;
501 ImageInfo->FileType = DeviceExtension->FileType;
502 ImageInfo->ImageSize = DeviceExtension->ImageSize;
503
504 ImageInfo->NameLength = DeviceExtension->FileName.Length;
505
506 // output buffer is large enough to hold the file name?
507
508 if (BufferLength < sizeof(VFD_IMAGE_INFO) +
509 DeviceExtension->FileName.Length)
510 {
511 *ReturnLength = sizeof(VFD_IMAGE_INFO);
513 }
514
515 // copy file name
516
517 if (DeviceExtension->FileName.Length &&
518 DeviceExtension->FileName.Buffer) {
519
520 RtlCopyMemory(ImageInfo->FileName,
521 DeviceExtension->FileName.Buffer,
522 DeviceExtension->FileName.Length);
523 }
524
525 // store the actually returned data length
526
527 *ReturnLength = sizeof(VFD_IMAGE_INFO) +
528 DeviceExtension->FileName.Length;
529
530 return STATUS_SUCCESS;
531}
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:43
struct _VFD_IMAGE_INFO VFD_IMAGE_INFO
@ VFD_DISKTYPE_RAM
Definition: vfdtypes.h:19
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771

Referenced by VfdDeviceControl().

◆ VfdReadData()

VOID VfdReadData ( IN PDEVICE_EXTENSION  DeviceExtension,
IN OUT PIRP  Irp,
IN ULONG  Length,
IN PLARGE_INTEGER  Offset 
)

Definition at line 217 of file vfdrdwr.c.

222{
223 PVOID buf;
224
225 VFDTRACE(VFDINFO,("[VFD] VfdReadData - IN\n"));
226
228 Irp->MdlAddress, NormalPagePriority);
229
230 if (!buf) {
231 VFDTRACE(0,
232 ("[VFD] MmGetSystemAddressForMdlPrettySafe\n"));
233
234 Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
235 return;
236 }
237
238 if (DeviceExtension->FileHandle) {
239
240 // Read from image file
241 Irp->IoStatus.Status = ZwReadFile(
242 DeviceExtension->FileHandle,
243 NULL,
244 NULL,
245 NULL,
246 &Irp->IoStatus,
247 buf,
248 Length,
249 Offset,
250 NULL);
251
252 if (NT_SUCCESS(Irp->IoStatus.Status)) {
253 Irp->IoStatus.Information = Length;
254 }
255 else {
256 VFDTRACE(0,
257 ("[VFD] ZwReadFile - %s\n",
258 GetStatusName(Irp->IoStatus.Status)));
259 }
260 }
261 else if (DeviceExtension->FileBuffer) {
262
263 // Copy from RAM disk buffer
265 buf,
266 DeviceExtension->FileBuffer + Offset->QuadPart,
267 Length);
268
269 Irp->IoStatus.Status = STATUS_SUCCESS;
270 Irp->IoStatus.Information = Length;
271 }
272 else {
273 // no image opened
274 Irp->IoStatus.Status = STATUS_NO_MEDIA_IN_DEVICE;
275 }
276
277 VFDTRACE(VFDINFO,("[VFD] VfdReadData - %s\n",
278 GetStatusName(Irp->IoStatus.Status)));
279
280 return;
281}
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
@ NormalPagePriority
Definition: imports.h:56
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
static PVOID MmGetSystemAddressForMdlPrettySafe(IN PMDL Mdl, IN MM_PAGE_PRIORITY Priority)
Definition: vfdrdwr.c:184

Referenced by VfdDeviceThread().

◆ VfdReadWrite()

NTSTATUS NTAPI VfdReadWrite ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 24 of file vfdrdwr.c.

27{
29 PIO_STACK_LOCATION io_stack;
31
33
35
36#if DBG
37 if (DeviceObject && DeviceObject->DeviceExtension &&
38 ((PDEVICE_EXTENSION)DeviceObject->DeviceExtension)->DeviceName.Buffer) {
39
40 VFDTRACE(VFDINFO, ("[VFD] %-40s %ws\n",
41 GetMajorFuncName(io_stack->MajorFunction),
42 ((PDEVICE_EXTENSION)DeviceObject->DeviceExtension)->DeviceName.Buffer));
43 }
44 else {
45 VFDTRACE(VFDINFO, ("[VFD] %-40s %p\n",
46 GetMajorFuncName(io_stack->MajorFunction),
48 }
49#endif // DBG
50
51#ifdef VFD_PNP
52
53 if (device_extension->DeviceState != VFD_WORKING) {
54
55 // Device is not yet started or being removed, reject any IO request
56 // TODO: Queue the IRPs
57
58 VFDTRACE(VFDWARN, ("[VFD] Device not ready\n"));
59
61 goto complete_request;
62 }
63 else {
64 status = IoAcquireRemoveLock(&DeviceExtension->RemoveLock, Irp);
65
66 if (!NT_SUCCESS(status)) {
67 VFDTRACE(0, ("[VFD] Acquire RemoveLock failed: %s\n", GetStatusName(status)));
68
69 goto complete_request;
70 }
71 }
72#endif // VFD_PNP
73
74/*
75 // Check if volume verification is required
76
77 if ((DeviceObject->Flags & DO_VERIFY_VOLUME) &&
78 !(io_stack->Flags & SL_OVERRIDE_VERIFY_VOLUME)) {
79
80 status = STATUS_VERIFY_REQUIRED;
81 goto complete_request;
82 }
83*/
84
85 // Check if an image is opened
86
87 if (!device_extension->FileHandle &&
88 !device_extension->FileBuffer) {
89
91 goto complete_request;
92 }
93
94
95 // Check if write operation is allowed
96
97 if (io_stack->MajorFunction == IRP_MJ_WRITE &&
99
101 goto complete_request;
102 }
103
104
105 // Check for invalid parameters. It is an error for the starting offset
106 // + length to go past the end of the partition, or for the length or
107 // offset to not be a proper multiple of the sector size.
108 //
109 // Others are possible, but we don't check them since we trust the
110 // file system and they aren't deadly.
111
112 if ((IO_READ_OFF(io_stack) + IO_READ_LEN(io_stack)) >
114
115 VFDTRACE(VFDWARN,
116 ("[VFD] Offset:%I64u + Length:%u goes past the media size %lu\n",
117 IO_READ_OFF(io_stack), IO_READ_LEN(io_stack),
119
121 goto complete_request;
122 }
123
124 if (!VFD_SECTOR_ALIGNED((IO_READ_LEN(io_stack))) ||
125 !VFD_SECTOR_ALIGNED((IO_READ_OFF(io_stack)))) {
126
127 VFDTRACE(VFDWARN,
128 ("[VFD] Invalid Alignment Offset:%I64u Length:%u\n",
129 IO_READ_OFF(io_stack), IO_READ_LEN(io_stack)));
130
132 goto complete_request;
133 }
134
135 // If read/write data length is 0, we are done
136
137 if (IO_READ_LEN(io_stack) == 0) {
139 goto complete_request;
140 }
141
142 // It seems that actual read/write operation is going to take place
143 // so mark the IRP as pending, insert the IRP into queue list
144 // then signal the device thread to perform the operation
145
147
149 &device_extension->ListHead,
150 &Irp->Tail.Overlay.ListEntry,
151 &device_extension->ListLock);
152
154 &device_extension->RequestEvent,
155 (KPRIORITY) 0,
156 FALSE);
157
158 VFDTRACE(VFDINFO,("[VFD] %-40s - STATUS_PENDING\n",
159 GetMajorFuncName(io_stack->MajorFunction)));
160
161 return STATUS_PENDING;
162
163complete_request:
164
165 // complete the request immediately
166
167 Irp->IoStatus.Status = status;
168 Irp->IoStatus.Information = 0;
170
171 VFDTRACE(VFDWARN,("[VFD] %-40s - %s\n",
172 GetMajorFuncName(io_stack->MajorFunction),
173 GetStatusName(status)));
174
175 return status;
176}
#define STATUS_INVALID_DEVICE_STATE
Definition: udferr_usr.h:178
#define VFD_SECTOR_ALIGNED(b)
Definition: vfdio.h:46
#define IO_READ_OFF(p)
Definition: vfdrdwr.c:19
#define IO_READ_LEN(p)
Definition: vfdrdwr.c:20

Referenced by DriverEntry().

◆ VfdSetLink()

NTSTATUS VfdSetLink ( IN PDEVICE_EXTENSION  DeviceExtension,
IN CHAR  DriveLetter 
)

Definition at line 24 of file vfdlink.c.

27{
28 UNICODE_STRING unicode_name;
29 WCHAR name_buf[15];
31
32 VFDTRACE(VFDINFO, ("[VFD] VfdSetLink - IN\n"));
33
34 // convert lower case into upper case
35
36 if (DriveLetter >= 'a' && DriveLetter <= 'z') {
37 DriveLetter -= ('a' - 'A');
38 }
39
40 // check the drive letter range
41
42 if (DriveLetter != 0 &&
43 (DriveLetter < 'A' || DriveLetter > 'Z')) {
45 }
46
47 if (DeviceExtension->DriveLetter &&
48 DeviceExtension->DriveLetter != DriveLetter) {
49 //
50 // Delete the old drive letter
51 //
52#ifndef __REACTOS__
53 name_buf[sizeof(name_buf) - 1] = UNICODE_NULL;
54#else
55 name_buf[ARRAYSIZE(name_buf) - 1] = UNICODE_NULL;
56#endif
57
58 _snwprintf(name_buf, sizeof(name_buf) - 1,
59 L"\\??\\%wc:", DeviceExtension->DriveLetter);
60
61 RtlInitUnicodeString(&unicode_name, name_buf);
62
63 status = IoDeleteSymbolicLink(&unicode_name);
64
65 if (NT_SUCCESS(status)) {
66 VFDTRACE(VFDINFO,
67 ("[VFD] Link %ws deleted\n", name_buf));
68
69 DeviceExtension->DriveLetter = 0;
70 }
72 // the driver letter did not exist in the first place
73
74 VFDTRACE(VFDINFO,
75 ("[VFD] Link %ws not found\n", name_buf));
76
77 DeviceExtension->DriveLetter = 0;
79 }
80 else {
81 VFDTRACE(VFDWARN,
82 ("[VFD] IoDeleteSymbolicLink %ws - %s\n",
83 name_buf, GetStatusName(status)));
84 }
85 }
86
87 if (NT_SUCCESS(status) && DriveLetter) {
88 //
89 // Create a new drive letter
90 //
91
92#ifndef __REACTOS__
93 name_buf[sizeof(name_buf) - 1] = UNICODE_NULL;
94
95 _snwprintf(name_buf, sizeof(name_buf) - 1,
96 (OsMajorVersion >= 5) ?
97 L"\\??\\Global\\%wc:" : L"\\??\\%wc:",
98 DriveLetter);
99#else
100 name_buf[ARRAYSIZE(name_buf) - 1] = UNICODE_NULL;
101
102 _snwprintf(name_buf, ARRAYSIZE(name_buf) - 1,
103 (OsMajorVersion >= 5) ?
104 L"\\??\\Global\\%wc:" : L"\\??\\%wc:",
105 DriveLetter);
106#endif
107
108 RtlInitUnicodeString(&unicode_name, name_buf);
109
111 &unicode_name, &(DeviceExtension->DeviceName));
112
113 if (NT_SUCCESS(status)) {
114 VFDTRACE(VFDINFO, ("[VFD] Link %ws created\n", name_buf));
115
116 DeviceExtension->DriveLetter = DriveLetter;
117 }
118 else {
119 VFDTRACE(VFDWARN,
120 ("[VFD] IoCreateSymbolicLink %ws - %s\n",
121 name_buf, GetStatusName(status)));
122 }
123 }
124
125 VFDTRACE(VFDINFO,
126 ("[VFD] VfdSetLink - %s\n", GetStatusName(status)));
127
128 return status;
129}
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149

Referenced by VfdDeleteDevice(), VfdDeviceControl(), and VfdReinitialize().

◆ VfdStoreLink()

NTSTATUS VfdStoreLink ( IN PDEVICE_EXTENSION  DeviceExtension)

Definition at line 190 of file vfdlink.c.

192{
193 PVFD_DRIVER_EXTENSION driver_extension;
194 WCHAR name_buf[20];
195 ULONG letter;
197
198 VFDTRACE(VFDINFO, ("[VFD] VfdStoreLink - IN\n"));
199
200#ifdef VFD_PNP
201 driver_extension = IoGetDriverObjectExtension(
202 DeviceExtension->device_object->DriverObject,
203 VFD_DRIVER_EXTENSION_ID);
204#else // VFD_PNP
205 driver_extension = DeviceExtension->DriverExtension;
206#endif // VFD_PNP
207
208 if (!driver_extension ||
209 !driver_extension->RegistryPath.Buffer) {
210
211 VFDTRACE(VFDWARN, ("[VFD] Registry Path not present.\n"));
212 VFDTRACE(VFDINFO, ("[VFD] VfdStoreLinks - OUT\n"));
214 }
215
216#ifndef __REACTOS__
217 name_buf[sizeof(name_buf) - 1] = UNICODE_NULL;
218
219 _snwprintf(name_buf, sizeof(name_buf) - 1,
221 DeviceExtension->DeviceNumber);
222#else
223 name_buf[ARRAYSIZE(name_buf) - 1] = UNICODE_NULL;
224
225 _snwprintf(name_buf, ARRAYSIZE(name_buf) - 1,
227 DeviceExtension->DeviceNumber);
228#endif
229
230 letter = DeviceExtension->DriveLetter;
231
234 driver_extension->RegistryPath.Buffer,
235 name_buf,
236 REG_DWORD,
237 &letter,
238 sizeof(ULONG));
239
240 if (!NT_SUCCESS(status)) {
241 VFDTRACE(VFDWARN,
242 ("[VFD] RtlWriteRegistryValue - %s\n",
243 GetStatusName(status)));
244 }
245 else {
246 VFDTRACE(VFDINFO,
247 ("[VFD] Drive letter '%wc' stored into the registry\n",
248 letter ? letter : L' '));
249 }
250
251 VFDTRACE(VFDINFO,
252 ("[VFD] VfdStoreLink - %s\n", GetStatusName(status)));
253
254 return status;
255}
NTSYSAPI NTSTATUS WINAPI RtlWriteRegistryValue(ULONG, PCWSTR, PCWSTR, ULONG, PVOID, ULONG)

Referenced by VfdDeviceControl().

◆ VfdUnloadDriver()

VOID NTAPI VfdUnloadDriver ( IN PDRIVER_OBJECT  DriverObject)

Definition at line 250 of file vfddrv.c.

252{
253 PDEVICE_OBJECT device_object;
254 PVFD_DRIVER_EXTENSION driver_extension;
255
256 VFDTRACE(VFDINFO, ("[VFD] VfdUnloadDriver - IN\n"));
257
258 device_object = DriverObject->DeviceObject;
259
260#ifdef VFD_PNP
261 driver_extension = IoGetDriverObjectExtension(
262 DriverObject, VFD_DRIVER_EXTENSION_ID);
263#else
264 if (device_object && device_object->DeviceExtension) {
265 driver_extension =
267 }
268 else {
269 driver_extension = NULL;
270 }
271#endif // VFD_PNP
272
273 //
274 // Delete all remaining device objects
275 //
276 while (device_object) {
277
278 PDEVICE_OBJECT next_device = device_object->NextDevice;
279
280 VfdDeleteDevice(device_object);
281
282 device_object = next_device;
283 }
284
285 //
286 // Release the driver extension and the registry path buffer
287 //
288 if (driver_extension) {
289
290 if (driver_extension->RegistryPath.Buffer) {
291 VFDTRACE(0, ("[VFD] Releasing the registry path buffer\n"));
292 ExFreePool(driver_extension->RegistryPath.Buffer);
293 }
294
295#ifndef VFD_PNP
296 // The system takes care of freeing the driver extension
297 // allocated with IoAllocateDriverObjectExtension in a PnP driver.
298 VFDTRACE(0, ("[VFD] Releasing the driver extension\n"));
299 ExFreePool(driver_extension);
300#endif // VFD_PNP
301 }
302
303 VFDTRACE(VFDINFO, ("[VFD] VfdUnloadDriver - OUT\n"));
304}
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:31
VOID VfdDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: vfddev.c:296

Referenced by DriverEntry().

◆ VfdWriteData()

VOID VfdWriteData ( IN PDEVICE_EXTENSION  DeviceExtension,
IN OUT PIRP  Irp,
IN ULONG  Length,
IN PLARGE_INTEGER  Offset 
)

Definition at line 287 of file vfdrdwr.c.

292{
293 PVOID buf;
294
295 VFDTRACE(VFDINFO,("[VFD] VfdWriteData - IN\n"));
296
298 Irp->MdlAddress, NormalPagePriority);
299
300 if (!buf) {
301 VFDTRACE(0,
302 ("[VFD] MmGetSystemAddressForMdlPrettySafe\n"));
303
304 Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
305 return;
306 }
307
308 if (DeviceExtension->FileHandle) {
309
310 // Write into image file
311 Irp->IoStatus.Status = ZwWriteFile(
312 DeviceExtension->FileHandle,
313 NULL,
314 NULL,
315 NULL,
316 &Irp->IoStatus,
317 buf,
318 Length,
319 Offset,
320 NULL);
321
322 if (NT_SUCCESS(Irp->IoStatus.Status)) {
323 Irp->IoStatus.Information = Length;
324 }
325 else {
326 VFDTRACE(0,
327 ("[VFD] ZwWriteFile - %s\n",
328 GetStatusName(Irp->IoStatus.Status)));
329 }
330 }
331 else if (DeviceExtension->FileBuffer) {
332
333 // Deal with the modify flag
335 DeviceExtension->FileBuffer + Offset->QuadPart,
336 buf, Length) != Length) {
337 DeviceExtension->MediaFlags |= VFD_FLAG_DATA_MODIFIED;
338 }
339
340 // Copy into RAM image buffer
342 DeviceExtension->FileBuffer + Offset->QuadPart,
343 buf, Length);
344
345 Irp->IoStatus.Status = STATUS_SUCCESS;
346 Irp->IoStatus.Information = Length;
347 }
348 else {
349 // no image opened
350 Irp->IoStatus.Status = STATUS_NO_MEDIA_IN_DEVICE;
351 }
352
353 VFDTRACE(VFDINFO,("[VFD] VfdWriteData - %s\n",
354 GetStatusName(Irp->IoStatus.Status)));
355
356 return;
357}
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
#define VFD_FLAG_DATA_MODIFIED
Definition: vfdtypes.h:69

Referenced by VfdDeviceThread().

Variable Documentation

◆ geom_tbl

◆ OsBuildNumber

ULONG OsBuildNumber
extern

◆ OsMajorVersion

ULONG OsMajorVersion
extern

◆ OsMinorVersion

ULONG OsMinorVersion
extern