https://git.reactos.org/?p=reactos.git;a=commitdiff;h=6ff94017e45a810acf73e…
commit 6ff94017e45a810acf73e0b5e4f39b3c8f822c83
Author: Pierre Schweitzer <pierre(a)reactos.org>
AuthorDate: Wed Feb 21 00:16:36 2018 +0100
Commit: Pierre Schweitzer <pierre(a)reactos.org>
CommitDate: Wed Feb 21 00:26:13 2018 +0100
[VFATLIB] Fix FAT partitions formatting in a non clean fashion.
(So the fun begins)
In spite of what VFATLIB headers pretend, there's not magic in FAT boot sector.
The 3 first bytes are just the jump instruction (to the boot code). No jump, no boot.
Also, some (many?) FAT implementations rely on the jump code to help detecting that
a FAT volume is really a FAT volume. Like MS FastFAT. Or our own FAT recognizer in
FS_REC.
The story is that, up to that commit, we zeroed the 3 first bytes; leading to broken
FAT volumes.
This got hidden in most cases by the fact that during setup, when we install boot
loader, we erase parts of the boot sector, including the jump instruction, making the
volume valid again. But that wouldn't fix secondary volumes where the boot loader
isn't
installed.
And, also, imagine a scenario where you want to install ReactOS on a newly formatted
volume
with MS FastFAT instead of our own implementation... That would simply not work to
the fact that the driver wouldn't recognize the fresh formatted volume!
(So the non fashion begins)
Fix this by putting a not that valid jump into the boot sector when formatting our
partitions. That way, our volume is always regarding a FAT view point. But, instead
of
putting values that mean (nearly) nothing. We should also put a dummy bootloader
displaying the user and error message, as done by dosfstools.
(So the hope begins)
This opens the way for trying to install ReactOS with MS FastFAT (doesn't work
yet).
CORE-11819
CORE-14362
---
sdk/lib/fslib/vfatlib/fat12.c | 10 +++++++---
sdk/lib/fslib/vfatlib/fat16.c | 10 +++++++---
sdk/lib/fslib/vfatlib/fat32.c | 10 +++++++---
sdk/lib/fslib/vfatlib/vfatlib.h | 8 ++------
4 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/sdk/lib/fslib/vfatlib/fat12.c b/sdk/lib/fslib/vfatlib/fat12.c
index d3cffdd145..bf96f8d2ec 100644
--- a/sdk/lib/fslib/vfatlib/fat12.c
+++ b/sdk/lib/fslib/vfatlib/fat12.c
@@ -38,9 +38,9 @@ Fat12WriteBootSector(IN HANDLE FileHandle,
RtlZeroMemory(NewBootSector, BootSector->BytesPerSector);
/* Copy FAT16 BPB to new bootsector */
- memcpy(&NewBootSector->OEMName[0],
- &BootSector->OEMName[0],
- FIELD_OFFSET(FAT16_BOOT_SECTOR, Res2) - FIELD_OFFSET(FAT16_BOOT_SECTOR,
OEMName));
+ memcpy(&NewBootSector->Jump[0],
+ &BootSector->Jump[0],
+ FIELD_OFFSET(FAT16_BOOT_SECTOR, Res2) - FIELD_OFFSET(FAT16_BOOT_SECTOR,
Jump));
/* FAT16 BPB length (up to (not including) Res2) */
/* Write the boot sector signature */
@@ -276,6 +276,10 @@ Fat12Format(IN HANDLE FileHandle,
RtlZeroMemory(&BootSector, sizeof(FAT16_BOOT_SECTOR));
memcpy(&BootSector.OEMName[0], "MSWIN4.1", 8);
+ /* FIXME: Add dummy bootloader for real */
+ BootSector.Jump[0] = 0xeb;
+ BootSector.Jump[1] = 0x3c;
+ BootSector.Jump[2] = 0x90;
BootSector.BytesPerSector = DiskGeometry->BytesPerSector;
BootSector.SectorsPerCluster = ClusterSize / BootSector.BytesPerSector;
BootSector.ReservedSectors = 1;
diff --git a/sdk/lib/fslib/vfatlib/fat16.c b/sdk/lib/fslib/vfatlib/fat16.c
index d0beaa3945..1438532390 100644
--- a/sdk/lib/fslib/vfatlib/fat16.c
+++ b/sdk/lib/fslib/vfatlib/fat16.c
@@ -38,9 +38,9 @@ Fat16WriteBootSector(IN HANDLE FileHandle,
RtlZeroMemory(NewBootSector, BootSector->BytesPerSector);
/* Copy FAT16 BPB to new bootsector */
- memcpy(&NewBootSector->OEMName[0],
- &BootSector->OEMName[0],
- FIELD_OFFSET(FAT16_BOOT_SECTOR, Res2) - FIELD_OFFSET(FAT16_BOOT_SECTOR,
OEMName));
+ memcpy(&NewBootSector->Jump[0],
+ &BootSector->Jump[0],
+ FIELD_OFFSET(FAT16_BOOT_SECTOR, Res2) - FIELD_OFFSET(FAT16_BOOT_SECTOR,
Jump));
/* FAT16 BPB length (up to (not including) Res2) */
/* Write the boot sector signature */
@@ -283,6 +283,10 @@ Fat16Format(IN HANDLE FileHandle,
RtlZeroMemory(&BootSector, sizeof(FAT16_BOOT_SECTOR));
memcpy(&BootSector.OEMName[0], "MSWIN4.1", 8);
+ /* FIXME: Add dummy bootloader for real */
+ BootSector.Jump[0] = 0xeb;
+ BootSector.Jump[1] = 0x3c;
+ BootSector.Jump[2] = 0x90;
BootSector.BytesPerSector = DiskGeometry->BytesPerSector;
BootSector.SectorsPerCluster = ClusterSize / BootSector.BytesPerSector;
BootSector.ReservedSectors = 1;
diff --git a/sdk/lib/fslib/vfatlib/fat32.c b/sdk/lib/fslib/vfatlib/fat32.c
index 030f1206b6..1987af4fdd 100644
--- a/sdk/lib/fslib/vfatlib/fat32.c
+++ b/sdk/lib/fslib/vfatlib/fat32.c
@@ -38,9 +38,9 @@ Fat32WriteBootSector(IN HANDLE FileHandle,
RtlZeroMemory(NewBootSector, BootSector->BytesPerSector);
/* Copy FAT32 BPB to new bootsector */
- memcpy(&NewBootSector->OEMName[0],
- &BootSector->OEMName[0],
- FIELD_OFFSET(FAT32_BOOT_SECTOR, Res2) - FIELD_OFFSET(FAT32_BOOT_SECTOR,
OEMName));
+ memcpy(&NewBootSector->Jump[0],
+ &BootSector->Jump[0],
+ FIELD_OFFSET(FAT32_BOOT_SECTOR, Res2) - FIELD_OFFSET(FAT32_BOOT_SECTOR,
Jump));
/* FAT32 BPB length (up to (not including) Res2) */
/* Write the boot sector signature */
@@ -428,6 +428,10 @@ Fat32Format(IN HANDLE FileHandle,
RtlZeroMemory(&BootSector, sizeof(FAT32_BOOT_SECTOR));
memcpy(&BootSector.OEMName[0], "MSWIN4.1", 8);
+ /* FIXME: Add dummy bootloader for real */
+ BootSector.Jump[0] = 0xeb;
+ BootSector.Jump[1] = 0x58;
+ BootSector.Jump[2] = 0x90;
BootSector.BytesPerSector = DiskGeometry->BytesPerSector;
BootSector.SectorsPerCluster = ClusterSize / BootSector.BytesPerSector;
BootSector.ReservedSectors = 32;
diff --git a/sdk/lib/fslib/vfatlib/vfatlib.h b/sdk/lib/fslib/vfatlib/vfatlib.h
index 40b1de376e..20788510a7 100644
--- a/sdk/lib/fslib/vfatlib/vfatlib.h
+++ b/sdk/lib/fslib/vfatlib/vfatlib.h
@@ -27,9 +27,7 @@
#include <pshpack1.h>
typedef struct _FAT16_BOOT_SECTOR
{
- unsigned char magic0; // 0
- unsigned char res0; // 1
- unsigned char magic1; // 2
+ unsigned char Jump[3]; // 0
unsigned char OEMName[8]; // 3
unsigned short BytesPerSector; // 11
unsigned char SectorsPerCluster; // 13
@@ -55,9 +53,7 @@ typedef struct _FAT16_BOOT_SECTOR
typedef struct _FAT32_BOOT_SECTOR
{
- unsigned char magic0; // 0
- unsigned char res0; // 1
- unsigned char magic1; // 2
+ unsigned char Jump[3]; // 0
unsigned char OEMName[8]; // 3
unsigned short BytesPerSector; // 11
unsigned char SectorsPerCluster; // 13