Author: pschweitzer
Date: Sat Mar 5 13:01:11 2016
New Revision: 70955
URL:
http://svn.reactos.org/svn/reactos?rev=70955&view=rev
Log:
[FS_REC]
Implement support for recognizing the Btrfs volumes.
Patch by Peter Hater.
CORE-10892 #comment The fs_rec part has been committed, thanks!
Added:
trunk/reactos/drivers/filesystems/fs_rec/btrfs.c (with props)
trunk/reactos/drivers/filesystems/fs_rec/btrfs.h (with props)
Modified:
trunk/reactos/drivers/filesystems/fs_rec/CMakeLists.txt
trunk/reactos/drivers/filesystems/fs_rec/fs_rec.c
trunk/reactos/drivers/filesystems/fs_rec/fs_rec.h
Modified: trunk/reactos/drivers/filesystems/fs_rec/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/fs_rec…
==============================================================================
--- trunk/reactos/drivers/filesystems/fs_rec/CMakeLists.txt [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/fs_rec/CMakeLists.txt [iso-8859-1] Sat Mar 5
13:01:11 2016
@@ -1,6 +1,6 @@
-
list(APPEND SOURCE
blockdev.c
+ btrfs.c
cdfs.c
ext2.c
fat.c
Added: trunk/reactos/drivers/filesystems/fs_rec/btrfs.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/fs_rec…
==============================================================================
--- trunk/reactos/drivers/filesystems/fs_rec/btrfs.c (added)
+++ trunk/reactos/drivers/filesystems/fs_rec/btrfs.c [iso-8859-1] Sat Mar 5 13:01:11
2016
@@ -0,0 +1,109 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS File System Recognizer
+ * FILE: drivers/filesystems/fs_rec/btrfs.c
+ * PURPOSE: Btrfs Recognizer
+ * PROGRAMMER: Peter Hater
+ * Pierre Schweitzer (pierre(a)reactos.org)
+ */
+
+/* INCLUDES *****************************************************************/
+
+#include "fs_rec.h"
+#include "btrfs.h"
+
+#define NDEBUG
+#include <debug.h>
+
+/* FUNCTIONS ****************************************************************/
+
+BOOLEAN
+NTAPI
+FsRecIsBtrfsVolume(IN PBTRFS_SUPER_BLOCK SuperBlock)
+{
+ /* Just check for magic */
+ return (SuperBlock->magic == BTRFS_MAGIC);
+}
+
+NTSTATUS
+NTAPI
+FsRecBtrfsFsControl(IN PDEVICE_OBJECT DeviceObject,
+ IN PIRP Irp)
+{
+ PIO_STACK_LOCATION Stack;
+ NTSTATUS Status;
+ PDEVICE_OBJECT MountDevice;
+ PBTRFS_SUPER_BLOCK Spb = NULL;
+ ULONG SectorSize;
+ LARGE_INTEGER Offset;
+ BOOLEAN DeviceError = FALSE;
+ PAGED_CODE();
+
+ /* Get the I/O Stack and check the function type */
+ Stack = IoGetCurrentIrpStackLocation(Irp);
+ switch (Stack->MinorFunction)
+ {
+ case IRP_MN_MOUNT_VOLUME:
+
+ /* Assume failure */
+ Status = STATUS_UNRECOGNIZED_VOLUME;
+
+ /* Get the device object and request the sector size */
+ MountDevice = Stack->Parameters.MountVolume.DeviceObject;
+ if (FsRecGetDeviceSectorSize(MountDevice, &SectorSize))
+ {
+ /* Try to read the superblock */
+ Offset.QuadPart = BTRFS_SB_OFFSET;
+ if (FsRecReadBlock(MountDevice,
+ &Offset,
+ BTRFS_SB_SIZE,
+ SectorSize,
+ (PVOID)&Spb,
+ &DeviceError))
+ {
+ /* Check if it's an actual BTRFS volume */
+ if (FsRecIsBtrfsVolume(Spb))
+ {
+ /* It is! */
+ Status = STATUS_FS_DRIVER_REQUIRED;
+ }
+ }
+
+ /* Free the boot sector if we have one */
+ ExFreePool(Spb);
+ }
+ else
+ {
+ /* We have some sort of failure in the storage stack */
+ DeviceError = TRUE;
+ }
+
+ /* Check if we have an error on the stack */
+ if (DeviceError)
+ {
+ /* Was this because of a floppy? */
+ if (MountDevice->Characteristics & FILE_FLOPPY_DISKETTE)
+ {
+ /* Let the FS try anyway */
+ Status = STATUS_FS_DRIVER_REQUIRED;
+ }
+ }
+
+ break;
+
+ case IRP_MN_LOAD_FILE_SYSTEM:
+
+ /* Load the file system */
+ Status = FsRecLoadFileSystem(DeviceObject,
+
L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\btrfs");
+ break;
+
+ default:
+
+ /* Invalid request */
+ Status = STATUS_INVALID_DEVICE_REQUEST;
+ }
+
+ /* Return Status */
+ return Status;
+}
Propchange: trunk/reactos/drivers/filesystems/fs_rec/btrfs.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/reactos/drivers/filesystems/fs_rec/btrfs.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/fs_rec…
==============================================================================
--- trunk/reactos/drivers/filesystems/fs_rec/btrfs.h (added)
+++ trunk/reactos/drivers/filesystems/fs_rec/btrfs.h [iso-8859-1] Sat Mar 5 13:01:11
2016
@@ -0,0 +1,31 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS File System Recognizer
+ * FILE: drivers/filesystems/fs_rec/btrfs.h
+ * PURPOSE: BTRFS Header File
+ * PROGRAMMER: Peter Hater
+ * Pierre Schweitzer (pierre(a)reactos.org)
+ */
+
+#include <pshpack1.h>
+typedef struct {
+ UINT8 uuid[16];
+} BTRFS_UUID;
+
+typedef struct _BTRFS_SUPER_BLOCK {
+ UINT8 checksum[32];
+ BTRFS_UUID uuid;
+ UINT64 sb_phys_addr;
+ UINT64 flags;
+ UINT64 magic;
+ // Partial
+} BTRFS_SUPER_BLOCK, *PBTRFS_SUPER_BLOCK;
+#include <poppack.h>
+
+C_ASSERT(FIELD_OFFSET(BTRFS_SUPER_BLOCK, uuid) == 0x20);
+C_ASSERT(FIELD_OFFSET(BTRFS_SUPER_BLOCK, sb_phys_addr) == 0x30);
+C_ASSERT(FIELD_OFFSET(BTRFS_SUPER_BLOCK, magic) == 0x40);
+
+#define BTRFS_MAGIC 0x4d5f53665248425f
+#define BTRFS_SB_OFFSET 0x10000
+#define BTRFS_SB_SIZE 0x1000
Propchange: trunk/reactos/drivers/filesystems/fs_rec/btrfs.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/reactos/drivers/filesystems/fs_rec/fs_rec.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/fs_rec…
==============================================================================
--- trunk/reactos/drivers/filesystems/fs_rec/fs_rec.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/fs_rec/fs_rec.c [iso-8859-1] Sat Mar 5 13:01:11
2016
@@ -162,6 +162,12 @@
/* Send EXT2 command */
Status = FsRecExt2FsControl(DeviceObject, Irp);
+ break;
+
+ case FS_TYPE_BTRFS:
+
+ /* Send BTRFS command */
+ Status = FsRecBtrfsFsControl(DeviceObject, Irp);
break;
default:
@@ -382,6 +388,16 @@
FILE_DEVICE_DISK_FILE_SYSTEM);
if (NT_SUCCESS(Status)) DeviceCount++;
+ /* Register BTRFS */
+ Status = FsRecRegisterFs(DriverObject,
+ NULL,
+ NULL,
+ L"\\Btrfs",
+ L"\\FileSystem\\BtrfsRecognizer",
+ FS_TYPE_BTRFS,
+ FILE_DEVICE_DISK_FILE_SYSTEM);
+ if (NT_SUCCESS(Status)) DeviceCount++;
+
/* Return appropriate Status */
return (DeviceCount > 0) ? STATUS_SUCCESS : STATUS_IMAGE_ALREADY_LOADED;
}
Modified: trunk/reactos/drivers/filesystems/fs_rec/fs_rec.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/fs_rec…
==============================================================================
--- trunk/reactos/drivers/filesystems/fs_rec/fs_rec.h [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/fs_rec/fs_rec.h [iso-8859-1] Sat Mar 5 13:01:11
2016
@@ -174,6 +174,7 @@
FS_TYPE_CDFS,
FS_TYPE_UDFS,
FS_TYPE_EXT2,
+ FS_TYPE_BTRFS,
} FILE_SYSTEM_TYPE, *PFILE_SYSTEM_TYPE;
/* FS Recognizer State */
@@ -224,6 +225,13 @@
NTSTATUS
NTAPI
FsRecExt2FsControl(
+ IN PDEVICE_OBJECT DeviceObject,
+ IN PIRP Irp
+);
+
+NTSTATUS
+NTAPI
+FsRecBtrfsFsControl(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
);