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