ReactOS  0.4.14-dev-358-gbef841c
ext2.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/ext2.c
5  * PURPOSE: EXT2 Recognizer
6  * PROGRAMMER: Eric Kohl
7  * Pierre Schweitzer (pierre@reactos.org)
8  */
9 
10 /* INCLUDES *****************************************************************/
11 
12 #include "fs_rec.h"
13 #include "ext2.h"
14 
15 #define NDEBUG
16 #include <debug.h>
17 
18 /* FUNCTIONS ****************************************************************/
19 
20 BOOLEAN
21 NTAPI
23 {
24  /* Just check for magic */
25  return (SuperBlock->Magic == EXT2_SUPER_MAGIC);
26 }
27 
29 NTAPI
31  IN PIRP Irp)
32 {
33  PIO_STACK_LOCATION Stack;
35  PDEVICE_OBJECT MountDevice;
36  PEXT2_SUPER_BLOCK Spb = NULL;
39  BOOLEAN DeviceError = FALSE;
40  PAGED_CODE();
41 
42  /* Get the I/O Stack and check the function type */
44  switch (Stack->MinorFunction)
45  {
47 
48  /* Assume failure */
50 
51  /* Get the device object and request the sector size */
52  MountDevice = Stack->Parameters.MountVolume.DeviceObject;
53  if (FsRecGetDeviceSectorSize(MountDevice, &SectorSize))
54  {
55  /* Try to read the superblock */
56  Offset.QuadPart = EXT2_SB_OFFSET;
57  if (FsRecReadBlock(MountDevice,
58  &Offset,
60  SectorSize,
61  (PVOID)&Spb,
62  &DeviceError))
63  {
64  /* Check if it's an actual EXT2 volume */
65  if (FsRecIsExt2Volume(Spb))
66  {
67  /* It is! */
69  }
70  }
71 
72  /* Free the boot sector if we have one */
73  ExFreePool(Spb);
74  }
75  else
76  {
77  /* We have some sort of failure in the storage stack */
78  DeviceError = TRUE;
79  }
80 
81  /* Check if we have an error on the stack */
82  if (DeviceError)
83  {
84  /* Was this because of a floppy? */
85  if (MountDevice->Characteristics & FILE_FLOPPY_DISKETTE)
86  {
87  /* Let the FS try anyway */
89  }
90  }
91 
92  break;
93 
95 
96  /* Load the file system */
98  L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\Ext2fs");
99  break;
100 
101  default:
102 
103  /* Invalid request */
105  }
106 
107  /* Return Status */
108  return Status;
109 }
110 
111 /* EOF */
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
_In_ PIRP Irp
Definition: csq.h:116
BOOLEAN NTAPI FsRecGetDeviceSectorSize(IN PDEVICE_OBJECT DeviceObject, OUT PULONG SectorSize)
Definition: blockdev.c:80
NTSTATUS NTAPI FsRecExt2FsControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: ext2.c:30
LONG NTSTATUS
Definition: precomp.h:26
#define IRP_MN_LOAD_FILE_SYSTEM
Definition: iotypes.h:4050
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_FS_DRIVER_REQUIRED
Definition: ntstatus.h:631
#define PAGED_CODE()
Definition: video.h:57
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define EXT2_SUPER_MAGIC
Definition: ext2fs.h:344
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define STATUS_UNRECOGNIZED_VOLUME
Definition: udferr_usr.h:173
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4048
BOOLEAN NTAPI FsRecIsExt2Volume(IN PEXT2_SUPER_BLOCK SuperBlock)
Definition: ext2.c:22
static const WCHAR L[]
Definition: oid.c:1250
#define EXT2_SB_OFFSET
Definition: ext2.h:47
Status
Definition: gdiplustypes.h:24
BOOLEAN NTAPI FsRecReadBlock(IN PDEVICE_OBJECT DeviceObject, IN PLARGE_INTEGER Offset, IN ULONG Length, IN ULONG SectorSize, IN OUT PVOID *Buffer, OUT PBOOLEAN DeviceError OPTIONAL)
Definition: blockdev.c:152
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
NTSTATUS NTAPI FsRecLoadFileSystem(IN PDEVICE_OBJECT DeviceObject, IN PWCHAR DriverServiceName)
Definition: fs_rec.c:23
unsigned int ULONG
Definition: retypes.h:1
#define EXT2_SB_SIZE
Definition: ext2.h:48
_In_ ULONG SectorSize
Definition: halfuncs.h:291
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
#define FILE_FLOPPY_DISKETTE
Definition: nt_native.h:809
#define ExFreePool(addr)
Definition: env_spec_w32.h:352