#include "partlist.h"
#include <fslib/vfatlib.h>
+#include <fslib/btrfslib.h>
// #include <fslib/ext2lib.h>
// #include <fslib/ntfslib.h>
{ L"EXT2" , Ext2Format, Ext2Chkdsk },
{ L"EXT3" , Ext2Format, Ext2Chkdsk },
{ L"EXT4" , Ext2Format, Ext2Chkdsk },
+#endif
{ L"BTRFS", BtrfsFormatEx, BtrfsChkdskEx },
+#if 0
{ L"FFS" , FfsFormat , FfsChkdsk },
{ L"REISERFS", ReiserfsFormat, ReiserfsChkdsk },
#endif
{
FileSystemName = L"FAT";
}
- else if (PartEntry->PartitionType == PARTITION_EXT2)
+ else if (PartEntry->PartitionType == PARTITION_LINUX)
{
// WARNING: See the warning above.
- FileSystemName = L"EXT2";
- // FIXME: We may have EXT3, 4 too...
+ FileSystemName = L"BTRFS";
}
else if (PartEntry->PartitionType == PARTITION_IFS)
{
// HACK: WARNING: We cannot write on this FS yet!
if (FileSystemName)
{
- if (PartEntry->PartitionType == PARTITION_EXT2 || PartEntry->PartitionType == PARTITION_IFS)
+ if (PartEntry->PartitionType == PARTITION_IFS)
DPRINT1("Recognized file system %S that doesn't support write support yet!\n", FileSystemName);
}
}
}
}
+ else if (wcscmp(FileSystem->FileSystemName, L"BTRFS") == 0)
+ {
+ SetPartitionType(PartEntry, PARTITION_LINUX);
+ }
#if 0
else if (wcscmp(FileSystem->FileSystemName, L"EXT2") == 0)
{
} FAT32_BOOTSECTOR, *PFAT32_BOOTSECTOR;
-typedef struct _EXT2_BOOTSECTOR
+typedef struct _BTRFS_BOOTSECTOR
{
- // The EXT2 bootsector is completely user-specific.
- // No FS data is stored there.
- UCHAR Fill[1024];
-} EXT2_BOOTSECTOR, *PEXT2_BOOTSECTOR;
+ UCHAR JumpBoot[3];
+ UCHAR ChunkMapSize;
+ UCHAR BootDrive;
+ ULONGLONG PartitionStartLBA;
+ UCHAR Fill[1521]; // 1536 - 15
+ USHORT BootSectorMagic;
+} BTRFS_BOOTSECTOR, *PBTRFS_BOOTSECTOR;
+C_ASSERT(sizeof(BTRFS_BOOTSECTOR) == 3 * 512);
// TODO: Add more bootsector structures!
static
NTSTATUS
-InstallExt2BootCodeToDisk(
+InstallBtrfsBootCodeToDisk(
PWSTR SrcPath,
PWSTR RootPath)
{
HANDLE FileHandle;
LARGE_INTEGER FileOffset;
// PEXT2_BOOTSECTOR OrigBootSector;
- PEXT2_BOOTSECTOR NewBootSector;
+ PBTRFS_BOOTSECTOR NewBootSector;
// USHORT BackupBootSector;
+ PARTITION_INFORMATION_EX PartInfo;
#if 0
/* Allocate buffer for original bootsector */
#endif
/* Allocate buffer for new bootsector */
- NewBootSector = RtlAllocateHeap(ProcessHeap, 0, sizeof(EXT2_BOOTSECTOR));
+ NewBootSector = RtlAllocateHeap(ProcessHeap, 0, sizeof(BTRFS_BOOTSECTOR));
if (NewBootSector == NULL)
{
// RtlFreeHeap(ProcessHeap, 0, OrigBootSector);
NULL,
&IoStatusBlock,
NewBootSector,
- sizeof(EXT2_BOOTSECTOR),
+ sizeof(BTRFS_BOOTSECTOR),
NULL,
NULL);
NtClose(FileHandle);
return Status;
}
+ /* Obtaining partition info and writing it to bootsector */
+ Status = NtDeviceIoControlFile(FileHandle,
+ NULL,
+ NULL,
+ NULL,
+ &IoStatusBlock,
+ IOCTL_DISK_GET_PARTITION_INFO_EX,
+ NULL,
+ 0,
+ &PartInfo,
+ sizeof(PartInfo));
+
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("IOCTL_DISK_GET_PARTITION_INFO_EX failed (Status %lx)\n", Status);
+ NtClose(FileHandle);
+ RtlFreeHeap(ProcessHeap, 0, NewBootSector);
+ return Status;
+ }
+
+ NewBootSector->PartitionStartLBA = PartInfo.StartingOffset.QuadPart / SECTORSIZE;
+
/* Write sector 0 */
FileOffset.QuadPart = 0ULL;
Status = NtWriteFile(FileHandle,
NULL,
&IoStatusBlock,
NewBootSector,
- sizeof(EXT2_BOOTSECTOR),
+ sizeof(BTRFS_BOOTSECTOR),
&FileOffset,
NULL);
#if 0
static
NTSTATUS
-InstallExt2BootcodeToPartition(
+InstallBtrfsBootcodeToPartition(
PUNICODE_STRING SystemRootPath,
PUNICODE_STRING SourceRootPath,
PUNICODE_STRING DestinationArcPath,
WCHAR SrcPath[MAX_PATH];
WCHAR DstPath[MAX_PATH];
- /* EXT2 partition */
+ /* BTRFS partition */
DPRINT("System path: '%wZ'\n", SystemRootPath);
/* Copy FreeLoader to the system partition, always overwriting the older version */
CombinePaths(DstPath, ARRAYSIZE(DstPath), 2, SystemRootPath->Buffer, BootSector);
DPRINT1("Save bootsector: %S ==> %S\n", SystemRootPath->Buffer, DstPath);
- Status = SaveBootSector(SystemRootPath->Buffer, DstPath, sizeof(EXT2_BOOTSECTOR));
+ Status = SaveBootSector(SystemRootPath->Buffer, DstPath, sizeof(BTRFS_BOOTSECTOR));
if (!NT_SUCCESS(Status))
{
DPRINT1("SaveBootSector() failed (Status %lx)\n", Status);
/* Install new bootsector on the disk */
// if (PartitionType == PARTITION_EXT2)
{
- /* Install EXT2 bootcode */
- CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\ext2.bin");
+ /* Install BTRFS bootcode */
+ CombinePaths(SrcPath, ARRAYSIZE(SrcPath), 2, SourceRootPath->Buffer, L"\\loader\\btrfs.bin");
- DPRINT1("Install EXT2 bootcode: %S ==> %S\n", SrcPath, SystemRootPath->Buffer);
- Status = InstallExt2BootCodeToDisk(SrcPath, SystemRootPath->Buffer);
+ DPRINT1("Install BTRFS bootcode: %S ==> %S\n", SrcPath, SystemRootPath->Buffer);
+ Status = InstallBtrfsBootCodeToDisk(SrcPath, SystemRootPath->Buffer);
if (!NT_SUCCESS(Status))
{
- DPRINT1("InstallExt2BootCodeToDisk() failed (Status %lx)\n", Status);
+ DPRINT1("InstallBtrfsBootCodeToDisk() failed (Status %lx)\n", Status);
return Status;
}
}
PartitionType);
}
- case PARTITION_EXT2:
+ case PARTITION_LINUX:
{
- return InstallExt2BootcodeToPartition(SystemRootPath,
- SourceRootPath,
- DestinationArcPath,
- PartitionType);
+ return InstallBtrfsBootcodeToPartition(SystemRootPath,
+ SourceRootPath,
+ DestinationArcPath,
+ PartitionType);
}
case PARTITION_IFS:
scsiport.sys=,,,,,,x,,,,,,4
storport.sys=,,,,,,x,,,,,,4
fastfat.sys=,,,,,,x,,,,,,4
+btrfs.sys=,,,,,,x,,,,,,4
ramdisk.sys=,,,,,,x,,,,,,4
classpnp.sys=,,,,,,,,,,,,4
pciide.sys=,,,,,,,,,,,,4