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