ReactOS  0.4.13-dev-259-g5ca9c9c
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;
372  UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\Beep");
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 */
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 }
DRIVER_DISPATCH BeepClose
Definition: beep.c:78
FORCEINLINE VOID IoInitializeDpcRequest(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIO_DPC_ROUTINE DpcRoutine)
Definition: iofuncs.h:2792
DRIVER_STARTIO BeepStartIo
Definition: beep.c:295
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
LONG NTSTATUS
Definition: precomp.h:26
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define FILE_DEVICE_BEEP
Definition: winioctl.h:106
DRIVER_DISPATCH BeepDeviceControl
Definition: beep.c:206
NTSTATUS NTAPI DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
Definition: beep.c:367
PVOID DeviceExtension
Definition: env_spec_w32.h:418
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
DRIVER_DISPATCH BeepCreate
Definition: beep.c:52
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DO_BUFFERED_IO
Definition: env_spec_w32.h:394
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
PVOID NTAPI MmPageEntireDriver(IN PVOID AddressWithinSection)
Definition: sysldr.c:3322
IO_DPC_ROUTINE * PIO_DPC_ROUTINE
Definition: iotypes.h:2491
VOID NTAPI BeepDPC(IN PKDPC Dpc, IN PDEVICE_OBJECT DeviceObject, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: beep.c:34
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
static const WCHAR L[]
Definition: oid.c:1250
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2179
DRIVER_DISPATCH BeepCleanup
Definition: beep.c:145
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
FAST_MUTEX Mutex
Definition: beep.c:24
DRIVER_UNLOAD BeepUnload
Definition: beep.c:268
#define IRP_MJ_CLEANUP
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2180
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
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
PDRIVER_STARTIO DriverStartIo
Definition: iotypes.h:2178
return STATUS_SUCCESS
Definition: btrfs.c:2745
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14

Referenced by DriverEntry(), ScsiClassDeviceControl(), and ScsiDiskDeviceControl().

◆ 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 }
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
smooth NULL
Definition: ftsmooth.c:416
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

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
318  ((PDEVICE_EXTENSION)DeviceObject->DeviceExtension)->DeviceName.Buffer) {
319 
320  VFDTRACE(VFDINFO, ("[VFD] %-40s %ws\n",
321  GetMajorFuncName(IoGetCurrentIrpStackLocation(Irp)->MajorFunction),
322  ((PDEVICE_EXTENSION)DeviceObject->DeviceExtension)->DeviceName.Buffer));
323  }
324  else {
325  VFDTRACE(VFDINFO, ("[VFD] %-40s %p\n",
326  GetMajorFuncName(IoGetCurrentIrpStackLocation(Irp)->MajorFunction),
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 }
_In_ PIRP Irp
Definition: csq.h:116
#define FILE_OPENED
Definition: nt_native.h:769
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define IoCompleteRequest
Definition: irp.c:1240
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#define IO_NO_INCREMENT
Definition: iotypes.h:565
return STATUS_SUCCESS
Definition: btrfs.c:2745

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,
206  KernelMode,
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 
250 cleanup:
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 
260  KeSetEvent(
261  &device_extension->RequestEvent,
262  (KPRIORITY) 0,
263  FALSE);
264 
265  if (device_extension->ThreadPointer) {
266  ObDereferenceObject(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 DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
#define FILE_DEVICE_DISK
Definition: winioctl.h:112
VOID NTAPI VfdDeviceThread(IN PVOID ThreadContext)
Definition: vfddrv.c:404
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1339
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
PCONFIGURATION_INFORMATION NTAPI IoGetConfigurationInformation(VOID)
Definition: iorsrce.c:830
NTSTATUS VfdLoadLink(IN PDEVICE_EXTENSION DeviceExtension, IN PWSTR RegistryPath)
Definition: vfdlink.c:135
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define STATUS_OBJECT_NAME_EXISTS
Definition: ntstatus.h:114
LONG NTSTATUS
Definition: precomp.h:26
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
_In_ PVOID Parameter
Definition: ldrtypes.h:240
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
ULONG NumberOfDevices
Definition: vfddrv.h:65
LONG KPRIORITY
Definition: compat.h:454
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
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:496
#define UNICODE_NULL
#define FILE_REMOVABLE_MEDIA
Definition: nt_native.h:807
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
PVOID DeviceExtension
Definition: env_spec_w32.h:418
int _snwprintf(wchar_t *buffer, size_t count, const wchar_t *format,...)
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PWSTR VfdCopyUnicode(PUNICODE_STRING dst, PUNICODE_STRING src)
Definition: vfddrv.c:489
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
#define STATUS_DRIVER_INTERNAL_ERROR
Definition: udferr_usr.h:177
static const WCHAR L[]
Definition: oid.c:1250
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2179
const DISK_GEOMETRY geom_tbl[VFD_MEDIA_MAX]
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1842
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1250
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
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
UNICODE_STRING RegistryPath
Definition: vfddrv.h:64
struct _VFD_DRIVER_EXTENSION * PVFD_DRIVER_EXTENSION
unsigned int ULONG
Definition: retypes.h:1
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
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
char * cleanup(char *str)
Definition: wpickclick.c:99
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
#define FILE_FLOPPY_DISKETTE
Definition: nt_native.h:809
return STATUS_SUCCESS
Definition: btrfs.c:2745
static SERVICE_STATUS status
Definition: service.c:31
struct _BEEP_DEVICE_EXTENSION * PDEVICE_EXTENSION
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define VFD_DEVICE_BASENAME
Definition: vfdio.h:35
Definition: ps.c:97

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 
330  KeSetEvent(
331  &device_extension->RequestEvent,
332  (KPRIORITY) 0,
333  FALSE);
334 
336  device_extension->ThreadPointer,
337  Executive,
338  KernelMode,
339  FALSE,
340  NULL);
341 
343  device_extension->ThreadPointer);
344 
345  // Delete security context object
346 
347  if (device_extension->SecurityContext) {
348  SeDeleteClientSecurity(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 }
ULONG OsMajorVersion
#define TRUE
Definition: types.h:120
PCONFIGURATION_INFORMATION NTAPI IoGetConfigurationInformation(VOID)
Definition: iorsrce.c:830
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
struct _device_extension device_extension
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
ULONG NumberOfDevices
Definition: vfddrv.h:65
LONG KPRIORITY
Definition: compat.h:454
#define UNICODE_NULL
#define SeDeleteClientSecurity(C)
Definition: imports.h:320
PVOID DeviceExtension
Definition: env_spec_w32.h:418
int _snwprintf(wchar_t *buffer, size_t count, const wchar_t *format,...)
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
static const WCHAR L[]
Definition: oid.c:1250
NTSTATUS VfdSetLink(IN PDEVICE_EXTENSION DeviceExtension, IN CHAR DriveLetter)
Definition: vfdlink.c:24
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1842
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1250
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
struct _BEEP_DEVICE_EXTENSION * PDEVICE_EXTENSION
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define VFD_DEVICE_BASENAME
Definition: vfdio.h:35

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 
125  case IOCTL_VFD_SET_LINK:
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 
202  break;
203 
205  // Reset the data modify flag
206 
207  if (!device_extension->FileHandle &&
208  !device_extension->FileBuffer) {
210  break;
211  }
212 
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 
519  KeSetEvent(
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 }
signed char * PCHAR
Definition: retypes.h:7
ULONG OsMajorVersion
#define STATUS_NO_MEDIA_IN_DEVICE
Definition: udferr_usr.h:141
#define IOCTL_DISK_EJECT_MEDIA
Definition: cdrw_usr.h:177
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define IOCTL_MOUNTDEV_LINK_DELETED
Definition: imports.h:112
_In_ PIRP Irp
Definition: csq.h:116
#define IOCTL_VFD_SET_PROTECT
Definition: vfdio.h:247
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define IOCTL_VFD_QUERY_NAME
Definition: vfdio.h:358
struct _device_extension device_extension
char CHAR
Definition: xmlstorage.h:175
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
LONG NTSTATUS
Definition: precomp.h:26
#define IOCTL_DISK_CHECK_VERIFY
Definition: cdrw_usr.h:175
#define VFD_SECTOR_TO_BYTE(s)
Definition: vfdio.h:45
#define IoReleaseRemoveLock(_RemoveLock, _Tag)
Definition: iofuncs.h:2716
NTSTATUS VfdQueryImage(IN PDEVICE_EXTENSION DeviceExtension, OUT PVFD_IMAGE_INFO ImageInfo, IN ULONG BufferLength, OUT PULONG ReturnLength)
Definition: vfdimg.c:466
#define IOCTL_VFD_CLEAR_PROTECT
Definition: vfdio.h:273
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define IOCTL_DISK_IS_WRITABLE
Definition: cdrw_usr.h:172
NTSTATUS VfdStoreLink(IN PDEVICE_EXTENSION DeviceExtension)
Definition: vfdlink.c:190
#define VFD_DEBUG_FLAG
Definition: vfdver.h:40
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
LONG KPRIORITY
Definition: compat.h:454
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
#define IOCTL_VFD_QUERY_VERSION
Definition: vfdio.h:387
#define IOCTL_MOUNTDEV_QUERY_DEVICE_NAME
Definition: imports.h:93
#define IOCTL_MOUNTDEV_QUERY_UNIQUE_ID
Definition: imports.h:80
#define IOCTL_DISK_FORMAT_TRACKS
Definition: cdrw_usr.h:171
#define VFD_FLAG_DATA_MODIFIED
Definition: vfdtypes.h:69
struct _GET_LENGTH_INFORMATION GET_LENGTH_INFORMATION
#define IOCTL_STORAGE_EJECT_MEDIA
Definition: ntddstor.h:96
#define IO_INPUTLEN(p)
Definition: vfdioctl.c:20
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_MEDIA_WRITE_PROTECTED
Definition: udferr_usr.h:161
#define IOCTL_DISK_GET_MEDIA_TYPES
Definition: cdrw_usr.h:182
#define IOCTL_VFD_SET_LINK
Definition: vfdio.h:194
#define IOCTL_VFD_QUERY_NUMBER
Definition: vfdio.h:325
#define IOCTL_DISK_GET_LENGTH_INFO
Definition: imports.h:192
#define PCHAR
Definition: match.c:90
#define IOCTL_STORAGE_CHECK_VERIFY
Definition: ntddstor.h:87
#define VFD_FLAG_WRITE_PROTECTED
Definition: vfdtypes.h:68
#define VFD_DRIVER_MINOR
Definition: vfdver.h:21
#define IOCTL_VFD_QUERY_IMAGE
Definition: vfdio.h:163
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IOCTL_VFD_QUERY_LINK
Definition: vfdio.h:221
NTSTATUS VfdFormatCheck(IN PDEVICE_EXTENSION DeviceExtension, IN PFORMAT_PARAMETERS FormatParams, IN ULONG InputLength, IN ULONG ControlCode)
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
struct _GET_LENGTH_INFORMATION * PGET_LENGTH_INFORMATION
NTSTATUS VfdSetLink(IN PDEVICE_EXTENSION DeviceExtension, IN CHAR DriveLetter)
Definition: vfdlink.c:24
#define IOCTL_VFD_OPEN_IMAGE
Definition: vfdio.h:107
const DISK_GEOMETRY geom_tbl[VFD_MEDIA_MAX]
#define IOCTL_STORAGE_CHECK_VERIFY2
Definition: ntddk_ex.h:212
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
struct _DISK_GEOMETRY DISK_GEOMETRY
#define IOCTL_STORAGE_GET_MEDIA_TYPES
Definition: ntddstor.h:120
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:61
unsigned short USHORT
Definition: pedump.c:61
#define IOCTL_MOUNTDEV_QUERY_SUGGESTED_LINK_NAME
Definition: imports.h:99
#define IOCTL_VFD_CLOSE_IMAGE
Definition: vfdio.h:133
unsigned int * PULONG
Definition: retypes.h:1
#define IOCTL_VFD_RESET_MODIFY
Definition: vfdio.h:299
#define IOCTL_DISK_FORMAT_TRACKS_EX
Definition: cdrw_usr.h:173
#define IO_OUTPUTLEN(p)
Definition: vfdioctl.c:21
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define VFD_DRIVER_MAJOR
Definition: vfdver.h:20
GLfloat GLfloat p
Definition: glext.h:8902
return STATUS_SUCCESS
Definition: btrfs.c:2745
IoMarkIrpPending(Irp)
static SERVICE_STATUS status
Definition: service.c:31
struct _BEEP_DEVICE_EXTENSION * PDEVICE_EXTENSION
#define IoAcquireRemoveLock(RemoveLock, Tag)
unsigned short * PUSHORT
Definition: retypes.h:2
NTSTATUS VfdOpenCheck(IN PDEVICE_EXTENSION DeviceExtension, IN PVFD_IMAGE_INFO ImageInfo, IN ULONG InputLength)
#define IOCTL_DISK_GET_DRIVE_GEOMETRY
Definition: cdrw_usr.h:169
#define IO_CTRLCODE(p)
Definition: vfdioctl.c:22
#define IOCTL_MOUNTDEV_LINK_CREATED
Definition: imports.h:106
Definition: ps.c:97

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,
426  KernelMode,
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 
444  io_stack = IoGetCurrentIrpStackLocation(irp);
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 
475  IoCompleteRequest(irp,
476  (CCHAR)(NT_SUCCESS(irp->IoStatus.Status) ?
478 
479 #ifdef VFD_PNP
480  IoReleaseRemoveLock(&device_extension->RemoveLock, irp);
481 #endif // VFD_PNP
482  } // while
483  } // for (;;)
484 }
struct _DEVICE_OBJECT * PDEVICE_OBJECT
struct _device_extension device_extension
#define IoReleaseRemoveLock(_RemoveLock, _Tag)
Definition: iofuncs.h:2716
VOID VfdReadData(IN PDEVICE_EXTENSION DeviceExtension, IN OUT PIRP Irp, IN ULONG Length, IN PLARGE_INTEGER Offset)
Definition: vfdrdwr.c:217
#define LOW_REALTIME_PRIORITY
IRP
Definition: iotypes.h:2462
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define IO_DISK_INCREMENT
Definition: iotypes.h:567
PLIST_ENTRY NTAPI ExInterlockedRemoveHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:166
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
VOID VfdIoCtlThread(IN PDEVICE_EXTENSION DeviceExtension, IN PIRP Irp, IN ULONG ControlCode)
Definition: vfdioctl.c:542
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
char CCHAR
Definition: typedefs.h:50
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
VOID VfdWriteData(IN PDEVICE_EXTENSION DeviceExtension, IN OUT PIRP Irp, IN ULONG Length, IN PLARGE_INTEGER Offset)
Definition: vfdrdwr.c:287
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_DRIVER_INTERNAL_ERROR
Definition: udferr_usr.h:177
Definition: typedefs.h:117
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
KPRIORITY NTAPI KeSetPriorityThread(IN PKTHREAD Thread, IN KPRIORITY Priority)
Definition: thrdobj.c:1327
NTSTATUS NTAPI PsTerminateSystemThread(IN NTSTATUS ExitStatus)
Definition: kill.c:1144
Definition: tftpd.h:85
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define KeGetCurrentThread
Definition: hal.h:44
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
return STATUS_SUCCESS
Definition: btrfs.c:2745
struct _BEEP_DEVICE_EXTENSION * PDEVICE_EXTENSION
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52

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 STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
static HANDLE PIO_APC_ROUTINE void PIO_STATUS_BLOCK io_status
Definition: comm.c:54
ULONG BytesPerSector
Definition: ntdddisk.h:376
ULONG TracksPerCylinder
Definition: ntdddisk.h:374
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
smooth NULL
Definition: ftsmooth.c:416
#define VFD_FORMAT_FILL_DATA
Definition: vfdio.h:51
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
ULONG SectorsPerTrack
Definition: ntdddisk.h:375
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define STATUS_DRIVER_INTERNAL_ERROR
Definition: udferr_usr.h:177
#define VFD_POOL_TAG
Definition: vfddrv.h:25
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2745
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
static SERVICE_STATUS status
Definition: service.c:31
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
LONGLONG QuadPart
Definition: typedefs.h:112
Definition: ps.c:97

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 
558  PsRevertToSelf();
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 }
#define IOCTL_DISK_EJECT_MEDIA
Definition: cdrw_usr.h:177
_In_ PIRP Irp
Definition: csq.h:116
NTKERNELAPI VOID NTAPI PsRevertToSelf(VOID)
Definition: security.c:548
#define IOCTL_DISK_FORMAT_TRACKS
Definition: cdrw_usr.h:171
#define IOCTL_STORAGE_EJECT_MEDIA
Definition: ntddstor.h:96
smooth NULL
Definition: ftsmooth.c:416
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55
NTSTATUS VfdFormatTrack(IN PDEVICE_EXTENSION DeviceExtension, IN PFORMAT_PARAMETERS FormatParams)
Definition: vfdfmt.c:153
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
#define STATUS_DRIVER_INTERNAL_ERROR
Definition: udferr_usr.h:177
#define IOCTL_VFD_OPEN_IMAGE
Definition: vfdio.h:107
VOID VfdCloseImage(IN PDEVICE_EXTENSION DeviceExtension)
Definition: vfdimg.c:435
NTKERNELAPI VOID NTAPI SeImpersonateClient(IN PSECURITY_CLIENT_CONTEXT ClientContext, IN PETHREAD ServerThread OPTIONAL)
Definition: access.c:623
#define IOCTL_VFD_CLOSE_IMAGE
Definition: vfdio.h:133
NTSTATUS VfdOpenImage(IN PDEVICE_EXTENSION DeviceExtension, IN PVFD_IMAGE_INFO ImageInfo)
Definition: vfdimg.c:104
#define IOCTL_DISK_FORMAT_TRACKS_EX
Definition: cdrw_usr.h:173
return STATUS_SUCCESS
Definition: btrfs.c:2745

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,
153  VFD_REG_DRIVE_LETTER L"%lu",
154  DeviceExtension->DeviceNumber);
155 #else
156  name_buf[ARRAYSIZE(name_buf) - 1] = UNICODE_NULL;
157 
158  _snwprintf(name_buf, ARRAYSIZE(name_buf) - 1,
159  VFD_REG_DRIVE_LETTER L"%lu",
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 
172  RegistryPath, &params[0], NULL, NULL);
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 VFD_REG_DRIVE_LETTER
Definition: vfdio.h:30
LONG NTSTATUS
Definition: precomp.h:26
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define UNICODE_NULL
GLenum const GLfloat * params
Definition: glext.h:5645
int _snwprintf(wchar_t *buffer, size_t count, const wchar_t *format,...)
smooth NULL
Definition: ftsmooth.c:416
#define RTL_REGISTRY_OPTIONAL
Definition: nt_native.h:169
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
static double zero
Definition: j0_y0.c:96
static const WCHAR L[]
Definition: oid.c:1250
#define RTL_REGISTRY_ABSOLUTE
Definition: nt_native.h:161
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
#define REG_DWORD
Definition: sdbapi.c:596
#define CHAR(Char)
static SERVICE_STATUS status
Definition: service.c:31
#define RTL_QUERY_REGISTRY_DIRECT
Definition: nt_native.h:144
Definition: ps.c:97

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;
111  ULONG sectors;
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(
221  &file_handle,
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(
247  file_handle,
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 
280  file_handle,
281  GENERIC_READ,
282  NULL,
283  KernelMode,
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(
328  file_handle,
329  &io_status,
330  &file_basic,
331  sizeof(FILE_BASIC_INFORMATION),
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(
358  file_handle,
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(
383  NonPagedPool,
385  VFD_POOL_TAG);
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 
425 exit_func:
426  VFDTRACE(0, ("[VFD] VfdOpenImage - %s\n", GetStatusName(status)));
427 
428  return status;
429 }
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
#define VFD_SECTOR_TO_BYTE(s)
Definition: vfdio.h:45
static HANDLE PIO_APC_ROUTINE void PIO_STATUS_BLOCK io_status
Definition: comm.c:54
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
ULONG TracksPerCylinder
Definition: ntdddisk.h:374
#define FILE_NO_INTERMEDIATE_BUFFERING
Definition: from_kernel.h:28
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:496
#define GENERIC_WRITE
Definition: nt_native.h:90
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define PCHAR
Definition: match.c:90
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
LARGE_INTEGER Cylinders
Definition: ntdddisk.h:372
ULONG SectorsPerTrack
Definition: ntdddisk.h:375
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
* PFILE_OBJECT
Definition: iotypes.h:1954
#define FILE_ATTRIBUTE_COMPRESSED
Definition: nt_native.h:711
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
const DISK_GEOMETRY geom_tbl[VFD_MEDIA_MAX]
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
ULONG LowPart
Definition: typedefs.h:104
#define GENERIC_READ
Definition: compat.h:124
#define FILE_WORD_ALIGNMENT
Definition: nt_native.h:787
#define FILE_OPEN
Definition: from_kernel.h:54
#define VFD_POOL_TAG
Definition: vfddrv.h:25
#define FILE_ATTRIBUTE_ENCRYPTED
Definition: ntifs_ex.h:385
unsigned short USHORT
Definition: pedump.c:61
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
#define FILE_RANDOM_ACCESS
Definition: from_kernel.h:38
#define FILE_DEVICE_NETWORK_FILE_SYSTEM
Definition: winioctl.h:125
__u8 sectors[2]
Definition: mkdosfs.c:366
#define FileStandardInformation
Definition: propsheet.cpp:61
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
return STATUS_SUCCESS
Definition: btrfs.c:2745
static SERVICE_STATUS status
Definition: service.c:31
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
static FILE * file_handle
Definition: regtests2xml.c:45
LONGLONG QuadPart
Definition: typedefs.h:112
Definition: ps.c:97

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);
512  return STATUS_BUFFER_OVERFLOW;
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:39
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
struct _VFD_IMAGE_INFO VFD_IMAGE_INFO
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
_In_ ULONG BufferLength
Definition: usbdlib.h:225
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:61
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
return STATUS_SUCCESS
Definition: btrfs.c:2745

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 }
#define STATUS_NO_MEDIA_IN_DEVICE
Definition: udferr_usr.h:141
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
_In_ PIRP Irp
Definition: csq.h:116
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
static PVOID MmGetSystemAddressForMdlPrettySafe(IN PMDL Mdl, IN MM_PAGE_PRIORITY Priority)
Definition: vfdrdwr.c:184
return STATUS_SUCCESS
Definition: btrfs.c:2745

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
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),
47  DeviceObject));
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 
153  KeSetEvent(
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 
163 complete_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_NO_MEDIA_IN_DEVICE
Definition: udferr_usr.h:141
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
struct _device_extension device_extension
PLIST_ENTRY NTAPI ExInterlockedInsertTailList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:140
LONG NTSTATUS
Definition: precomp.h:26
#define VFD_SECTOR_TO_BYTE(s)
Definition: vfdio.h:45
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
LONG KPRIORITY
Definition: compat.h:454
#define STATUS_INVALID_DEVICE_STATE
Definition: udferr_usr.h:178
PVOID DeviceExtension
Definition: env_spec_w32.h:418
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_MEDIA_WRITE_PROTECTED
Definition: udferr_usr.h:161
#define VFD_FLAG_WRITE_PROTECTED
Definition: vfdtypes.h:68
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
#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
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
return STATUS_SUCCESS
Definition: btrfs.c:2745
IoMarkIrpPending(Irp)
static SERVICE_STATUS status
Definition: service.c:31
struct _BEEP_DEVICE_EXTENSION * PDEVICE_EXTENSION
#define IoAcquireRemoveLock(RemoveLock, Tag)
Definition: ps.c:97

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 }
ULONG OsMajorVersion
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define UNICODE_NULL
int _snwprintf(wchar_t *buffer, size_t count, const wchar_t *format,...)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
static const WCHAR L[]
Definition: oid.c:1250
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
return STATUS_SUCCESS
Definition: btrfs.c:2745
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

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,
220  VFD_REG_DRIVE_LETTER L"%lu",
221  DeviceExtension->DeviceNumber);
222 #else
223  name_buf[ARRAYSIZE(name_buf) - 1] = UNICODE_NULL;
224 
225  _snwprintf(name_buf, ARRAYSIZE(name_buf) - 1,
226  VFD_REG_DRIVE_LETTER L"%lu",
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 }
#define VFD_REG_DRIVE_LETTER
Definition: vfdio.h:30
LONG NTSTATUS
Definition: precomp.h:26
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define UNICODE_NULL
int _snwprintf(wchar_t *buffer, size_t count, const wchar_t *format,...)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
#define STATUS_DRIVER_INTERNAL_ERROR
Definition: udferr_usr.h:177
NTSYSAPI NTSTATUS WINAPI RtlWriteRegistryValue(ULONG, PCWSTR, PCWSTR, ULONG, PVOID, ULONG)
static const WCHAR L[]
Definition: oid.c:1250
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1842
#define RTL_REGISTRY_ABSOLUTE
Definition: nt_native.h:161
UNICODE_STRING RegistryPath
Definition: vfddrv.h:64
unsigned int ULONG
Definition: retypes.h:1
#define REG_DWORD
Definition: sdbapi.c:596
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

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 }
VOID VfdDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: vfddev.c:296
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
PVOID NTAPI IoGetDriverObjectExtension(IN PDRIVER_OBJECT DriverObject, IN PVOID ClientIdentificationAddress)
Definition: driver.c:1842
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:41
UNICODE_STRING RegistryPath
Definition: vfddrv.h:64
struct _BEEP_DEVICE_EXTENSION * PDEVICE_EXTENSION
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2168

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
334  if (RtlCompareMemory(
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 STATUS_NO_MEDIA_IN_DEVICE
Definition: udferr_usr.h:141
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
_In_ PIRP Irp
Definition: csq.h:116
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define VFD_FLAG_DATA_MODIFIED
Definition: vfdtypes.h:69
smooth NULL
Definition: ftsmooth.c:416
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
static PVOID MmGetSystemAddressForMdlPrettySafe(IN PMDL Mdl, IN MM_PAGE_PRIORITY Priority)
Definition: vfdrdwr.c:184
return STATUS_SUCCESS
Definition: btrfs.c:2745
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465

Referenced by VfdDeviceThread().

Variable Documentation

◆ geom_tbl

◆ OsBuildNumber

ULONG OsBuildNumber

◆ OsMajorVersion

ULONG OsMajorVersion

◆ OsMinorVersion

ULONG OsMinorVersion