[FS_REC]
[reactos.git] / reactos / drivers / filesystems / fs_rec / ext2.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS File System Recognizer
4 * FILE: drivers/filesystems/fs_rec/ext2.c
5 * PURPOSE: EXT2 Recognizer
6 * PROGRAMMER: Eric Kohl
7 */
8
9 /* INCLUDES *****************************************************************/
10
11 #include "fs_rec.h"
12
13 #define NDEBUG
14 #include <debug.h>
15
16 /* FUNCTIONS ****************************************************************/
17
18 BOOLEAN
19 NTAPI
20 FsRecIsExt2Volume(IN PVOID PackedBootSector)
21 {
22 UNREFERENCED_PARAMETER(PackedBootSector);
23 /* For now, always return failure... */
24 return FALSE;
25 }
26
27 NTSTATUS
28 NTAPI
29 FsRecExt2FsControl(IN PDEVICE_OBJECT DeviceObject,
30 IN PIRP Irp)
31 {
32 PIO_STACK_LOCATION Stack;
33 NTSTATUS Status;
34 PDEVICE_OBJECT MountDevice;
35 PVOID Bpb = NULL;
36 ULONG SectorSize;
37 LARGE_INTEGER Offset = {{0, 0}};
38 BOOLEAN DeviceError = FALSE;
39 PAGED_CODE();
40
41 /* Get the I/O Stack and check the function type */
42 Stack = IoGetCurrentIrpStackLocation(Irp);
43 switch (Stack->MinorFunction)
44 {
45 case IRP_MN_MOUNT_VOLUME:
46
47 /* Assume failure */
48 Status = STATUS_UNRECOGNIZED_VOLUME;
49
50 /* Get the device object and request the sector size */
51 MountDevice = Stack->Parameters.MountVolume.DeviceObject;
52 if (FsRecGetDeviceSectorSize(MountDevice, &SectorSize))
53 {
54 /* Try to read the BPB */
55 if (FsRecReadBlock(MountDevice,
56 &Offset,
57 512,
58 SectorSize,
59 (PVOID)&Bpb,
60 &DeviceError))
61 {
62 /* Check if it's an actual EXT2 volume */
63 if (FsRecIsExt2Volume(Bpb))
64 {
65 /* It is! */
66 Status = STATUS_FS_DRIVER_REQUIRED;
67 }
68 }
69
70 /* Free the boot sector if we have one */
71 ExFreePool(Bpb);
72 }
73 else
74 {
75 /* We have some sort of failure in the storage stack */
76 DeviceError = TRUE;
77 }
78
79 /* Check if we have an error on the stack */
80 if (DeviceError)
81 {
82 /* Was this because of a floppy? */
83 if (MountDevice->Characteristics & FILE_FLOPPY_DISKETTE)
84 {
85 /* Let the FS try anyway */
86 Status = STATUS_FS_DRIVER_REQUIRED;
87 }
88 }
89
90 break;
91
92 case IRP_MN_LOAD_FILE_SYSTEM:
93
94 /* Load the file system */
95 Status = FsRecLoadFileSystem(DeviceObject,
96 L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\Ext2");
97 break;
98
99 default:
100
101 /* Invalid request */
102 Status = STATUS_INVALID_DEVICE_REQUEST;
103 }
104
105 /* Return Status */
106 return Status;
107 }
108
109 /* EOF */