[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
This commit is contained in:
Pierre Schweitzer 2018-02-21 00:16:36 +01:00
parent e1bd79e3df
commit 6ff94017e4
No known key found for this signature in database
GPG key ID: 7545556C3D585B0B
4 changed files with 23 additions and 15 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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