ReactOS  0.4.14-dev-98-gb0d4763
fs_rec.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS File System Recognizer
4  * FILE: drivers/filesystems/fs_rec/fs_rec.c
5  * PURPOSE: Main Driver Entrypoint and FS Registration
6  * PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
7  * Eric Kohl
8  */
9 
10 /* INCLUDES *****************************************************************/
11 
12 #include "fs_rec.h"
13 
14 #define NDEBUG
15 #include <debug.h>
16 
18 
19 /* FUNCTIONS ****************************************************************/
20 
22 NTAPI
24  IN PWCHAR DriverServiceName)
25 {
26  UNICODE_STRING DriverName;
29  PAGED_CODE();
30 
31  /* Make sure we haven't already been called */
32  if (DeviceExtension->State != Loaded)
33  {
34  /* Acquire the load lock */
36  Executive,
37  KernelMode,
38  FALSE,
39  NULL);
41 
42  /* Make sure we're active */
43  if (DeviceExtension->State == Pending)
44  {
45  /* Load the FS driver */
46  RtlInitUnicodeString(&DriverName, DriverServiceName);
47  Status = ZwLoadDriver(&DriverName);
48 
49  /* Loop all the linked recognizer objects */
50  while (DeviceExtension->State != Unloading)
51  {
52  /* Set them to the unload state */
53  DeviceExtension->State = Unloading;
54 
55  /* Go to the next one */
56  DeviceObject = DeviceExtension->Alternate;
57  DeviceExtension = DeviceObject->DeviceExtension;
58  }
59  }
60 
61  /* Make sure that we haven't already loaded the FS */
62  if (DeviceExtension->State != Loaded)
63  {
64  /* Unregister us, and set us as loaded */
66  DeviceExtension->State = Loaded;
67  }
68 
69  /* Release the lock */
72  }
73 
74  /* Return */
75  return Status;
76 }
77 
80 NTAPI
82  IN PIRP Irp)
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 }
108 
110 NTSTATUS
111 NTAPI
113  IN PIRP Irp)
114 {
115  PAGED_CODE();
116 
118 
119  /* Just complete the IRP and return success */
121  return STATUS_SUCCESS;
122 }
123 
125 NTSTATUS
126 NTAPI
128  IN PIRP Irp)
129 {
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 }
196 
197 DRIVER_UNLOAD FsRecUnload;
198 VOID
199 NTAPI
201 {
202  PAGED_CODE();
203 
204  /* Loop all driver device objects */
205  while (DriverObject->DeviceObject)
206  {
207  /* Delete this device */
209  }
210 
211  /* Free the lock */
213 }
214 
215 NTSTATUS
216 NTAPI
218  IN PDEVICE_OBJECT ParentObject OPTIONAL,
219  OUT PDEVICE_OBJECT *NewDeviceObject OPTIONAL,
220  IN PCWSTR FsName,
221  IN PCWSTR RecognizerName,
222  IN ULONG FsType,
224  IN ULONG AdditionalFlags)
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 }
315 
316 NTSTATUS
317 NTAPI
320 {
321  ULONG DeviceCount = 0;
323  PDEVICE_OBJECT CdfsObject;
324  PDEVICE_OBJECT UdfsObject;
325  PAGED_CODE();
326 
328 
329  /* Page the entire driver */
331 
332  /* Allocate the lock */
334  sizeof(KEVENT),
335  FSREC_TAG);
337 
338  /* Initialize it */
340 
341  /* Setup the major functions */
347 
348  /* Register CDFS for CDs */
350  NULL,
351  &CdfsObject,
352  L"\\Cdfs",
353  L"\\FileSystem\\CdfsRecognizer",
354  FS_TYPE_CDFS,
357  if (NT_SUCCESS(Status)) DeviceCount++;
358 
359  /* Register CDFS for HDDs */
361  CdfsObject,
362  NULL,
363  L"\\CdfsHdd",
364  L"\\FileSystem\\CdfsHddRecognizer",
365  FS_TYPE_CDFS,
368  if (NT_SUCCESS(Status)) DeviceCount++;
369 
370  /* Register UDFS for CDs */
372  NULL,
373  &UdfsObject,
374  L"\\UdfsCdRom",
375  L"\\FileSystem\\UdfsCdRomRecognizer",
376  FS_TYPE_UDFS,
378  0);
379  if (NT_SUCCESS(Status)) DeviceCount++;
380 
381  /* Register UDFS for HDDs */
383  UdfsObject,
384  NULL,
385  L"\\UdfsDisk",
386  L"\\FileSystem\\UdfsDiskRecognizer",
387  FS_TYPE_UDFS,
389  0);
390  if (NT_SUCCESS(Status)) DeviceCount++;
391 
392  /* Register FAT */
394  NULL,
395  NULL,
396  L"\\Fat",
397  L"\\FileSystem\\FatRecognizer",
398  FS_TYPE_VFAT,
400  0);
401  if (NT_SUCCESS(Status)) DeviceCount++;
402 
403  /* Register NTFS */
405  NULL,
406  NULL,
407  L"\\Ntfs",
408  L"\\FileSystem\\NtfsRecognizer",
409  FS_TYPE_NTFS,
411  0);
412  if (NT_SUCCESS(Status)) DeviceCount++;
413 
414  /* Register EXT2 */
416  NULL,
417  NULL,
418  L"\\Ext2fs",
419  L"\\FileSystem\\Ext2Recognizer",
420  FS_TYPE_EXT2,
422  0);
423  if (NT_SUCCESS(Status)) DeviceCount++;
424 
425  /* Register BTRFS */
427  NULL,
428  NULL,
429  L"\\Btrfs",
430  L"\\FileSystem\\BtrfsRecognizer",
433  0);
434  if (NT_SUCCESS(Status)) DeviceCount++;
435 
436  /* Register REISERFS */
438  NULL,
439  NULL,
440  L"\\Reiserfs",
441  L"\\FileSystem\\ReiserfsRecognizer",
444  0);
445  if (NT_SUCCESS(Status)) DeviceCount++;
446 
447  /* Register FFS */
449  NULL,
450  NULL,
451  L"\\ffs",
452  L"\\FileSystem\\FfsRecognizer",
453  FS_TYPE_FFS,
455  0);
456  if (NT_SUCCESS(Status)) DeviceCount++;
457 
458  /* Return appropriate Status */
460 }
461 
462 /* EOF */
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
const uint16_t * PCWSTR
Definition: typedefs.h:55
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
#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
NTSTATUS NTAPI FsRecVfatFsControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: fat.c:100
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
DeviceType
Definition: mmdrv.h:41
NTSTATUS NTAPI FsRecExt2FsControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: ext2.c:30
VOID NTAPI IoUnregisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:1061
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_OPENED
Definition: nt_native.h:769
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
NTSTATUS NTAPI FsRecUdfsFsControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: udfs.c:106
uint16_t * PWCHAR
Definition: typedefs.h:54
NTSTATUS NTAPI DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
Definition: fs_rec.c:318
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
WCHAR DeviceName[]
Definition: adapter.cpp:21
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
#define PAGED_CODE()
Definition: video.h:57
#define FILE_SHARE_READ
Definition: compat.h:125
Definition: fs_rec.h:186
NTSTATUS NTAPI FsRecNtfsFsControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: ntfs.c:52
HANDLE FileHandle
Definition: stats.c:38
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
PKEVENT FsRecLoadSync
Definition: fs_rec.c:17
NTSTATUS NTAPI FsRecCdfsFsControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: cdfs.c:66
ULONG DeviceCount
Definition: mpu401.c:26
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
DRIVER_DISPATCH FsRecClose
Definition: fs_rec.c:109
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define IoCompleteRequest
Definition: irp.c:1240
#define FILE_DEVICE_DISK_FILE_SYSTEM
Definition: winioctl.h:113
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IRP_MJ_FILE_SYSTEM_CONTROL
PVOID NTAPI MmPageEntireDriver(IN PVOID AddressWithinSection)
Definition: sysldr.c:3370
#define FSREC_TAG
Definition: fs_rec.h:16
#define STATUS_OBJECT_PATH_NOT_FOUND
Definition: udferr_usr.h:151
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#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
NTSTATUS NTAPI FsRecFfsFsControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: ffs.c:43
static const WCHAR L[]
Definition: oid.c:1250
DRIVER_DISPATCH FsRecCreate
Definition: fs_rec.c:78
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2180
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
#define SYNCHRONIZE
Definition: nt_native.h:61
DRIVER_DISPATCH(nfs41_FsdDispatch)
#define DO_LOW_PRIORITY_FILESYSTEM
Status
Definition: gdiplustypes.h:24
#define FILE_OPEN
Definition: from_kernel.h:54
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
#define DEVICE_TYPE
Definition: guid.c:10
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
VOID NTAPI IoRegisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:992
NTSTATUS NTAPI FsRecLoadFileSystem(IN PDEVICE_OBJECT DeviceObject, IN PWCHAR DriverServiceName)
Definition: fs_rec.c:23
#define IRP_MJ_CLEANUP
#define OUT
Definition: typedefs.h:39
#define FILE_DEVICE_CD_ROM_FILE_SYSTEM
Definition: winioctl.h:108
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2181
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
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
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
return STATUS_SUCCESS
Definition: btrfs.c:2966
NTSTATUS NTAPI FsRecBtrfsFsControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: btrfs.c:30
struct _BEEP_DEVICE_EXTENSION * PDEVICE_EXTENSION
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
NTSTATUS NTAPI FsRecReiserfsFsControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: reiserfs.c:43
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2169
#define STATUS_IMAGE_ALREADY_LOADED
Definition: ntstatus.h:492
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68