ReactOS  0.4.15-dev-3287-gfec35dc
fs_rec.c File Reference
#include "fs_rec.h"
#include <debug.h>
Include dependency graph for fs_rec.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI FsRecLoadFileSystem (IN PDEVICE_OBJECT DeviceObject, IN PWCHAR DriverServiceName)
 
NTSTATUS NTAPI FsRecCreate (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI FsRecClose (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI FsRecFsControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
VOID NTAPI FsRecUnload (IN PDRIVER_OBJECT DriverObject)
 
NTSTATUS NTAPI FsRecRegisterFs (IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT ParentObject OPTIONAL, OUT PDEVICE_OBJECT *NewDeviceObject OPTIONAL, IN PCWSTR FsName, IN PCWSTR RecognizerName, IN ULONG FsType, IN DEVICE_TYPE DeviceType, IN ULONG AdditionalFlags)
 
NTSTATUS NTAPI DriverEntry (IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
 

Variables

PKEVENT FsRecLoadSync
 
DRIVER_DISPATCH FsRecCreate
 
DRIVER_DISPATCH FsRecClose
 
DRIVER_DISPATCH FsRecFsControl
 
DRIVER_UNLOAD FsRecUnload
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file fs_rec.c.

Function Documentation

◆ DriverEntry()

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

Definition at line 318 of file fs_rec.c.

320 {
322  ULONG DeviceCount = 0;
323  PDEVICE_OBJECT CdfsObject;
324  PDEVICE_OBJECT UdfsObject;
325  PDEVICE_OBJECT FatObject;
326 
327  PAGED_CODE();
328 
330 
331  /* Page the entire driver */
333 
334  /* Allocate the lock */
336  sizeof(KEVENT),
337  FSREC_TAG);
339 
340  /* Initialize it */
342 
343  /* Setup the major functions */
344  DriverObject->MajorFunction[IRP_MJ_CREATE] = FsRecCreate;
345  DriverObject->MajorFunction[IRP_MJ_CLOSE] = FsRecClose;
346  DriverObject->MajorFunction[IRP_MJ_CLEANUP] = FsRecClose;
348  DriverObject->DriverUnload = FsRecUnload;
349 
350  /* Register CDFS for CDs */
352  NULL,
353  &CdfsObject,
354  L"\\Cdfs",
355  L"\\FileSystem\\CdfsRecognizer",
356  FS_TYPE_CDFS,
359  if (NT_SUCCESS(Status)) DeviceCount++;
360 
361  /* Register CDFS for HDDs */
363  CdfsObject,
364  NULL,
365  L"\\CdfsHdd",
366  L"\\FileSystem\\CdfsHddRecognizer",
367  FS_TYPE_CDFS,
370  if (NT_SUCCESS(Status)) DeviceCount++;
371 
372  /* Register UDFS for CDs */
374  NULL,
375  &UdfsObject,
376  L"\\UdfsCdRom",
377  L"\\FileSystem\\UdfsCdRomRecognizer",
378  FS_TYPE_UDFS,
380  0);
381  if (NT_SUCCESS(Status)) DeviceCount++;
382 
383  /* Register UDFS for HDDs */
385  UdfsObject,
386  NULL,
387  L"\\UdfsDisk",
388  L"\\FileSystem\\UdfsDiskRecognizer",
389  FS_TYPE_UDFS,
391  0);
392  if (NT_SUCCESS(Status)) DeviceCount++;
393 
394  /* Register FAT */
396  NULL,
397  &FatObject,
398  L"\\Fat",
399  L"\\FileSystem\\FatRecognizer",
400  FS_TYPE_VFAT,
402  0);
403  if (NT_SUCCESS(Status)) DeviceCount++;
404 
405  /* Register FAT for CDs */
407  FatObject,
408  NULL,
409  L"\\FatCdrom",
410  L"\\FileSystem\\FatCdRomRecognizer",
411  FS_TYPE_VFAT,
413  0);
414  if (NT_SUCCESS(Status)) DeviceCount++;
415 
416  /* Register NTFS */
418  NULL,
419  NULL,
420  L"\\Ntfs",
421  L"\\FileSystem\\NtfsRecognizer",
422  FS_TYPE_NTFS,
424  0);
425  if (NT_SUCCESS(Status)) DeviceCount++;
426 
427  /* Register EXT2 */
429  NULL,
430  NULL,
431  L"\\Ext2fs",
432  L"\\FileSystem\\Ext2Recognizer",
433  FS_TYPE_EXT2,
435  0);
436  if (NT_SUCCESS(Status)) DeviceCount++;
437 
438  /* Register BTRFS */
440  NULL,
441  NULL,
442  L"\\Btrfs",
443  L"\\FileSystem\\BtrfsRecognizer",
446  0);
447  if (NT_SUCCESS(Status)) DeviceCount++;
448 
449  /* Register REISERFS */
451  NULL,
452  NULL,
453  L"\\Reiserfs",
454  L"\\FileSystem\\ReiserfsRecognizer",
457  0);
458  if (NT_SUCCESS(Status)) DeviceCount++;
459 
460  /* Register FFS */
462  NULL,
463  NULL,
464  L"\\ffs",
465  L"\\FileSystem\\FfsRecognizer",
466  FS_TYPE_FFS,
468  0);
469  if (NT_SUCCESS(Status)) DeviceCount++;
470 
471  /* Return appropriate Status */
473 }
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
DRIVER_DISPATCH FsRecFsControl
Definition: fs_rec.c:124
#define TRUE
Definition: types.h:120
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:213
NTSTATUS NTAPI DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
Definition: fs_rec.c:318
PKEVENT FsRecLoadSync
Definition: fs_rec.c:17
ULONG DeviceCount
Definition: mpu401.c:26
DRIVER_DISPATCH FsRecClose
Definition: fs_rec.c:109
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
#define FILE_DEVICE_DISK_FILE_SYSTEM
Definition: winioctl.h:114
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IRP_MJ_FILE_SYSTEM_CONTROL
PVOID NTAPI MmPageEntireDriver(IN PVOID AddressWithinSection)
Definition: sysldr.c:3467
#define FSREC_TAG
Definition: fs_rec.h:16
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
DRIVER_UNLOAD FsRecUnload
Definition: fs_rec.c:197
static const WCHAR L[]
Definition: oid.c:1250
DRIVER_DISPATCH FsRecCreate
Definition: fs_rec.c:78
#define DO_LOW_PRIORITY_FILESYSTEM
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define NULL
Definition: types.h:112
NTSTATUS NTAPI FsRecRegisterFs(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT ParentObject OPTIONAL, OUT PDEVICE_OBJECT *NewDeviceObject OPTIONAL, IN PCWSTR FsName, IN PCWSTR RecognizerName, IN ULONG FsType, IN DEVICE_TYPE DeviceType, IN ULONG AdditionalFlags)
Definition: fs_rec.c:217
#define IRP_MJ_CLEANUP
#define FILE_DEVICE_CD_ROM_FILE_SYSTEM
Definition: winioctl.h:109
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_IMAGE_ALREADY_LOADED
Definition: ntstatus.h:506
#define PAGED_CODE()

◆ FsRecClose()

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

Definition at line 112 of file fs_rec.c.

114 {
115  PAGED_CODE();
116 
118 
119  /* Just complete the IRP and return success */
121  return STATUS_SUCCESS;
122 }
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define STATUS_SUCCESS
Definition: shellext.h:65
#define PAGED_CODE()

◆ FsRecCreate()

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

Definition at line 81 of file fs_rec.c.

83 {
86  PAGED_CODE();
87 
89 
90  /* Make sure we have a file name */
91  if (IoStack->FileObject->FileName.Length)
92  {
93  /* Fail the request */
95  }
96  else
97  {
98  /* Let it through */
100  }
101 
102  /* Complete the IRP */
103  Irp->IoStatus.Status = Status;
104  Irp->IoStatus.Information = FILE_OPENED;
106  return Status;
107 }
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_OPENED
Definition: nt_native.h:769
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
Status
Definition: gdiplustypes.h:24
#define STATUS_OBJECT_PATH_NOT_FOUND
Definition: udferr_usr.h:151
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define STATUS_SUCCESS
Definition: shellext.h:65
#define PAGED_CODE()

◆ FsRecFsControl()

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

Definition at line 127 of file fs_rec.c.

129 {
130  PDEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
132  PAGED_CODE();
133 
134  /* Check the file system type */
135  switch (DeviceExtension->FsType)
136  {
137  case FS_TYPE_VFAT:
138 
139  /* Send FAT command */
141  break;
142 
143  case FS_TYPE_NTFS:
144 
145  /* Send NTFS command */
147  break;
148 
149  case FS_TYPE_CDFS:
150 
151  /* Send CDFS command */
153  break;
154 
155  case FS_TYPE_UDFS:
156 
157  /* Send UDFS command */
159  break;
160 
161  case FS_TYPE_EXT2:
162 
163  /* Send EXT2 command */
165  break;
166 
167  case FS_TYPE_BTRFS:
168 
169  /* Send BTRFS command */
171  break;
172 
173  case FS_TYPE_REISERFS:
174 
175  /* Send REISERFS command */
177  break;
178 
179  case FS_TYPE_FFS:
180 
181  /* Send FFS command */
183  break;
184 
185  default:
186 
187  /* Unrecognized FS */
189  }
190 
191  /* Complete the IRP */
192  Irp->IoStatus.Status = Status;
194  return Status;
195 }
NTSTATUS NTAPI FsRecVfatFsControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fat.c:100
NTSTATUS NTAPI FsRecExt2FsControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: ext2.c:30
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
NTSTATUS NTAPI FsRecUdfsFsControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: udfs.c:106
NTSTATUS NTAPI FsRecNtfsFsControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: ntfs.c:52
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS NTAPI FsRecCdfsFsControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: cdfs.c:66
#define IoCompleteRequest
Definition: irp.c:1240
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI FsRecFfsFsControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: ffs.c:43
#define IO_NO_INCREMENT
Definition: iotypes.h:598
NTSTATUS NTAPI FsRecBtrfsFsControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: btrfs.c:30
NTSTATUS NTAPI FsRecReiserfsFsControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: reiserfs.c:43
#define PAGED_CODE()

◆ FsRecLoadFileSystem()

NTSTATUS NTAPI FsRecLoadFileSystem ( IN PDEVICE_OBJECT  DeviceObject,
IN PWCHAR  DriverServiceName 
)

Definition at line 23 of file fs_rec.c.

25 {
27  PDEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
28  UNICODE_STRING DriverName;
29 
30  PAGED_CODE();
31 
32  /* Make sure we haven't already been called */
33  if (DeviceExtension->State != Loaded)
34  {
35  /* Acquire the load lock */
38  Executive,
39  KernelMode,
40  FALSE,
41  NULL);
42 
43  /* Make sure we're active */
44  if (DeviceExtension->State == Pending)
45  {
46  /* Load the FS driver */
47  RtlInitUnicodeString(&DriverName, DriverServiceName);
48  Status = ZwLoadDriver(&DriverName);
49 
50  /* Loop all the linked recognizer objects */
51  while (DeviceExtension->State != Unloading)
52  {
53  /* Set them to the unload state */
54  DeviceExtension->State = Unloading;
55 
56  /* Go to the next one */
57  DeviceObject = DeviceExtension->Alternate;
58  DeviceExtension = DeviceObject->DeviceExtension;
59  }
60  }
61 
62  /* Make sure that we haven't already loaded the FS */
63  if (DeviceExtension->State != Loaded)
64  {
65  /* Unregister us, and set us as loaded */
67  DeviceExtension->State = Loaded;
68  }
69 
70  /* Release the lock */
73  }
74 
75  return Status;
76 }
VOID NTAPI IoUnregisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:1056
LONG NTSTATUS
Definition: precomp.h:26
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
Definition: fs_rec.h:186
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
PKEVENT FsRecLoadSync
Definition: fs_rec.c:17
Status
Definition: gdiplustypes.h:24
#define KeEnterCriticalRegion()
Definition: ke_x.h:88
#define KeLeaveCriticalRegion()
Definition: ke_x.h:119
#define NULL
Definition: types.h:112
#define IO_NO_INCREMENT
Definition: iotypes.h:598
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define STATUS_IMAGE_ALREADY_LOADED
Definition: ntstatus.h:506
#define PAGED_CODE()

Referenced by FsRecBtrfsFsControl(), FsRecCdfsFsControl(), FsRecExt2FsControl(), FsRecFfsFsControl(), FsRecNtfsFsControl(), FsRecReiserfsFsControl(), FsRecUdfsFsControl(), and FsRecVfatFsControl().

◆ FsRecRegisterFs()

NTSTATUS NTAPI FsRecRegisterFs ( IN PDRIVER_OBJECT  DriverObject,
IN PDEVICE_OBJECT ParentObject  OPTIONAL,
OUT PDEVICE_OBJECT *NewDeviceObject  OPTIONAL,
IN PCWSTR  FsName,
IN PCWSTR  RecognizerName,
IN ULONG  FsType,
IN DEVICE_TYPE  DeviceType,
IN ULONG  AdditionalFlags 
)

Definition at line 217 of file fs_rec.c.

225 {
228  PDEVICE_EXTENSION DeviceExtension;
233 
234  /* Assume failure */
235  if (NewDeviceObject) *NewDeviceObject = NULL;
236 
237  /* Setup the attributes */
240  &DeviceName,
242  0,
243  NULL);
244 
245  /* Open the device */
246  Status = ZwCreateFile(&FileHandle,
247  SYNCHRONIZE,
249  &IoStatus,
250  NULL,
251  0,
253  FILE_OPEN,
254  0,
255  NULL,
256  0);
257  if (NT_SUCCESS(Status))
258  {
259  /* We succeeded, close the handle */
261  }
263  {
264  /* We failed with anything else then what we want to fail with */
266  }
267 
268  /* If we succeeded, there's no point in trying this again */
270 
271  /* Create recognizer device object */
272  RtlInitUnicodeString(&DeviceName, RecognizerName);
274  sizeof(DEVICE_EXTENSION),
275  &DeviceName,
276  DeviceType,
277  0,
278  FALSE,
279  &DeviceObject);
280  if (NT_SUCCESS(Status))
281  {
282  /* Set additional flags in the device object */
283  DeviceObject->Flags |= AdditionalFlags;
284 
285  /* Get the device extension and set it up */
286  DeviceExtension = DeviceObject->DeviceExtension;
287  DeviceExtension->FsType = FsType;
288  DeviceExtension->State = Pending;
289 
290  /* Do we have a parent? */
291  if (ParentObject)
292  {
293  /* Link it in */
294  DeviceExtension->Alternate =
295  ((PDEVICE_EXTENSION)ParentObject->DeviceExtension)->Alternate;
296  ((PDEVICE_EXTENSION)ParentObject->DeviceExtension)->Alternate =
297  DeviceObject;
298  }
299  else
300  {
301  /* Otherwise, we're the only one */
302  DeviceExtension->Alternate = DeviceObject;
303  }
304 
305  /* Return the DO if needed */
306  if (NewDeviceObject) *NewDeviceObject = DeviceObject;
307 
308  /* Register the file system */
310  }
311 
312  /* Return Status */
313  return Status;
314 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:136
HANDLE FileHandle
Definition: stats.c:38
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3272
#define FALSE
Definition: types.h:117
DeviceType
Definition: mmdrv.h:41
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SYNCHRONIZE
Definition: nt_native.h:61
#define FILE_OPEN
Definition: from_kernel.h:54
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
#define NULL
Definition: types.h:112
VOID NTAPI IoRegisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:987
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:155
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 InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _BEEP_DEVICE_EXTENSION * PDEVICE_EXTENSION
#define STATUS_IMAGE_ALREADY_LOADED
Definition: ntstatus.h:506

Referenced by DriverEntry().

◆ FsRecUnload()

VOID NTAPI FsRecUnload ( IN PDRIVER_OBJECT  DriverObject)

Definition at line 200 of file fs_rec.c.

201 {
202  PAGED_CODE();
203 
204  /* Loop all driver device objects */
205  while (DriverObject->DeviceObject)
206  {
207  /* Delete this device */
208  IoDeleteDevice(DriverObject->DeviceObject);
209  }
210 
211  /* Free the lock */
213 }
PKEVENT FsRecLoadSync
Definition: fs_rec.c:17
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define PAGED_CODE()

Variable Documentation

◆ FsRecClose

DRIVER_DISPATCH FsRecClose

Definition at line 109 of file fs_rec.c.

Referenced by DriverEntry().

◆ FsRecCreate

DRIVER_DISPATCH FsRecCreate

Definition at line 78 of file fs_rec.c.

Referenced by DriverEntry().

◆ FsRecFsControl

DRIVER_DISPATCH FsRecFsControl

Definition at line 124 of file fs_rec.c.

Referenced by DriverEntry().

◆ FsRecLoadSync

PKEVENT FsRecLoadSync

Definition at line 17 of file fs_rec.c.

Referenced by DriverEntry(), FsRecLoadFileSystem(), and FsRecUnload().

◆ FsRecUnload

DRIVER_UNLOAD FsRecUnload

Definition at line 197 of file fs_rec.c.

Referenced by DriverEntry().