[FS_REC]
authorPierre Schweitzer <pierre@reactos.org>
Sat, 17 Oct 2015 22:39:13 +0000 (22:39 +0000)
committerPierre Schweitzer <pierre@reactos.org>
Sat, 17 Oct 2015 22:39:13 +0000 (22:39 +0000)
Implement ExtX support in FS_REC, this allows it to autoload ext2fs.sys

Starting with this revision, browsing ExtX volumes in ReactOS works without any other modifications.

Thanks to Peter Hater for his initial work and to Thomas for his reviews

svn path=/trunk/; revision=69577

reactos/drivers/filesystems/fs_rec/ext2.c
reactos/drivers/filesystems/fs_rec/ext2.h [new file with mode: 0644]

index fa06eb0..16109ab 100644 (file)
@@ -4,11 +4,13 @@
  * FILE:             drivers/filesystems/fs_rec/ext2.c
  * PURPOSE:          EXT2 Recognizer
  * PROGRAMMER:       Eric Kohl
+ *                   Pierre Schweitzer (pierre@reactos.org)
  */
 
 /* INCLUDES *****************************************************************/
 
 #include "fs_rec.h"
+#include "ext2.h"
 
 #define NDEBUG
 #include <debug.h>
 
 BOOLEAN
 NTAPI
-FsRecIsExt2Volume(IN PVOID PackedBootSector)
+FsRecIsExt2Volume(IN PEXT2_SUPER_BLOCK SuperBlock)
 {
-    UNREFERENCED_PARAMETER(PackedBootSector);
-    /* For now, always return failure... */
-    return FALSE;
+    /* Just check for magic */
+    return (SuperBlock->Magic == EXT2_SUPER_MAGIC);
 }
 
 NTSTATUS
@@ -32,9 +33,9 @@ FsRecExt2FsControl(IN PDEVICE_OBJECT DeviceObject,
     PIO_STACK_LOCATION Stack;
     NTSTATUS Status;
     PDEVICE_OBJECT MountDevice;
-    PVOID Bpb = NULL;
+    PEXT2_SUPER_BLOCK Spb = NULL;
     ULONG SectorSize;
-    LARGE_INTEGER Offset = {{0, 0}};
+    LARGE_INTEGER Offset;
     BOOLEAN DeviceError = FALSE;
     PAGED_CODE();
 
@@ -51,16 +52,17 @@ FsRecExt2FsControl(IN PDEVICE_OBJECT DeviceObject,
             MountDevice = Stack->Parameters.MountVolume.DeviceObject;
             if (FsRecGetDeviceSectorSize(MountDevice, &SectorSize))
             {
-                /* Try to read the BPB */
+                /* Try to read the superblock */
+                Offset.QuadPart = 0x400;
                 if (FsRecReadBlock(MountDevice,
                                    &Offset,
-                                   512,
+                                   0x400,
                                    SectorSize,
-                                   (PVOID)&Bpb,
+                                   (PVOID)&Spb,
                                    &DeviceError))
                 {
                     /* Check if it's an actual EXT2 volume */
-                    if (FsRecIsExt2Volume(Bpb))
+                    if (FsRecIsExt2Volume(Spb))
                     {
                         /* It is! */
                         Status = STATUS_FS_DRIVER_REQUIRED;
@@ -68,7 +70,7 @@ FsRecExt2FsControl(IN PDEVICE_OBJECT DeviceObject,
                 }
 
                 /* Free the boot sector if we have one */
-                ExFreePool(Bpb);
+                ExFreePool(Spb);
             }
             else
             {
diff --git a/reactos/drivers/filesystems/fs_rec/ext2.h b/reactos/drivers/filesystems/fs_rec/ext2.h
new file mode 100644 (file)
index 0000000..12018d1
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * COPYRIGHT:        See COPYING in the top level directory
+ * PROJECT:          ReactOS File System Recognizer
+ * FILE:             drivers/filesystems/fs_rec/ext2.h
+ * PURPOSE:          EXT2 Header File
+ * PROGRAMMER:       Pierre Schweitzer (pierre@reactos.org)
+ */
+
+#include <pshpack1.h>
+typedef struct _EXT2_SUPER_BLOCK {
+    ULONG InodesCount;
+    ULONG BlocksCount;
+    ULONG ReservedBlocksCount;
+    ULONG FreeBlocksCount;
+    ULONG FreeInodesCount;
+    ULONG FirstDataBlock;
+    ULONG LogBlockSize;
+    LONG LogFragSize;
+    ULONG BlocksPerGroup;
+    ULONG FragsPerGroup;
+    ULONG InodesPerGroup;
+    ULONG MountTime;
+    ULONG WriteTime;
+    USHORT MountCount;
+    SHORT MaxMountCount;
+    USHORT Magic;
+    USHORT State;
+    USHORT Errors;
+    USHORT MinorRevLevel;
+    ULONG LastCheck;
+    ULONG CheckInterval;
+    ULONG CreatorOS;
+    ULONG RevLevel;
+    USHORT DefResUid;
+    USHORT DefResGid;
+        // Partial
+} EXT2_SUPER_BLOCK, *PEXT2_SUPER_BLOCK;
+#include <poppack.h>
+
+C_ASSERT(FIELD_OFFSET(EXT2_SUPER_BLOCK, FreeInodesCount) == 0x10);
+C_ASSERT(FIELD_OFFSET(EXT2_SUPER_BLOCK, BlocksPerGroup) == 0x20);
+C_ASSERT(FIELD_OFFSET(EXT2_SUPER_BLOCK, WriteTime) == 0x30);
+C_ASSERT(FIELD_OFFSET(EXT2_SUPER_BLOCK, LastCheck) == 0x40);
+C_ASSERT(FIELD_OFFSET(EXT2_SUPER_BLOCK, DefResUid) == 0x50);
+
+#define EXT2_SUPER_MAGIC 0xEF53