mirror of
https://github.com/reactos/reactos.git
synced 2024-11-01 04:11:30 +00:00
6ff94017e4
(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
155 lines
5.1 KiB
C
155 lines
5.1 KiB
C
/*
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
* PROJECT: ReactOS VFAT filesystem library
|
|
* FILE: vfatlib.h
|
|
*/
|
|
|
|
#ifndef _VFATLIB_H_
|
|
#define _VFATLIB_H_
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#define WIN32_NO_STATUS
|
|
#define _INC_WINDOWS
|
|
#define COM_NO_WINDOWS_H
|
|
#include <windef.h>
|
|
#include <winbase.h>
|
|
#define NTOS_MODE_USER
|
|
#include <ndk/iofuncs.h>
|
|
#include <ndk/kefuncs.h>
|
|
#include <ndk/obfuncs.h>
|
|
#include <ndk/rtlfuncs.h>
|
|
#include <fmifs/fmifs.h>
|
|
|
|
#include "check/dosfsck.h"
|
|
|
|
#include <pshpack1.h>
|
|
typedef struct _FAT16_BOOT_SECTOR
|
|
{
|
|
unsigned char Jump[3]; // 0
|
|
unsigned char OEMName[8]; // 3
|
|
unsigned short BytesPerSector; // 11
|
|
unsigned char SectorsPerCluster; // 13
|
|
unsigned short ReservedSectors; // 14
|
|
unsigned char FATCount; // 16
|
|
unsigned short RootEntries; // 17
|
|
unsigned short Sectors; // 19
|
|
unsigned char Media; // 21
|
|
unsigned short FATSectors; // 22
|
|
unsigned short SectorsPerTrack; // 24
|
|
unsigned short Heads; // 26
|
|
unsigned long HiddenSectors; // 28
|
|
unsigned long SectorsHuge; // 32
|
|
unsigned char Drive; // 36
|
|
unsigned char Res1; // 37
|
|
unsigned char ExtBootSignature; // 38
|
|
unsigned long VolumeID; // 39
|
|
unsigned char VolumeLabel[11]; // 43
|
|
unsigned char SysType[8]; // 54
|
|
unsigned char Res2[446]; // 62
|
|
unsigned long Signature1; // 508
|
|
} FAT16_BOOT_SECTOR, *PFAT16_BOOT_SECTOR;
|
|
|
|
typedef struct _FAT32_BOOT_SECTOR
|
|
{
|
|
unsigned char Jump[3]; // 0
|
|
unsigned char OEMName[8]; // 3
|
|
unsigned short BytesPerSector; // 11
|
|
unsigned char SectorsPerCluster; // 13
|
|
unsigned short ReservedSectors; // 14
|
|
unsigned char FATCount; // 16
|
|
unsigned short RootEntries; // 17
|
|
unsigned short Sectors; // 19
|
|
unsigned char Media; // 21
|
|
unsigned short FATSectors; // 22
|
|
unsigned short SectorsPerTrack; // 24
|
|
unsigned short Heads; // 26
|
|
unsigned long HiddenSectors; // 28
|
|
unsigned long SectorsHuge; // 32
|
|
unsigned long FATSectors32; // 36
|
|
unsigned short ExtFlag; // 40
|
|
unsigned short FSVersion; // 42
|
|
unsigned long RootCluster; // 44
|
|
unsigned short FSInfoSector; // 48
|
|
unsigned short BootBackup; // 50
|
|
unsigned char Res3[12]; // 52
|
|
unsigned char Drive; // 64
|
|
unsigned char Res4; // 65
|
|
unsigned char ExtBootSignature; // 66
|
|
unsigned long VolumeID; // 67
|
|
unsigned char VolumeLabel[11]; // 71
|
|
unsigned char SysType[8]; // 82
|
|
unsigned char Res2[418]; // 90
|
|
unsigned long Signature1; // 508
|
|
} FAT32_BOOT_SECTOR, *PFAT32_BOOT_SECTOR;
|
|
|
|
typedef struct _FAT32_FSINFO
|
|
{
|
|
unsigned long LeadSig; // 0
|
|
unsigned char Res1[480]; // 4
|
|
unsigned long StrucSig; // 484
|
|
unsigned long FreeCount; // 488
|
|
unsigned long NextFree; // 492
|
|
unsigned long Res2[3]; // 496
|
|
unsigned long TrailSig; // 508
|
|
} FAT32_FSINFO, *PFAT32_FSINFO;
|
|
#include <poppack.h>
|
|
|
|
#define FSINFO_SECTOR_BEGIN_SIGNATURE 0x41615252 // 'RRaA'
|
|
#define FSINFO_SECTOR_END_SIGNATURE 0xAA550000
|
|
#define FSINFO_SIGNATURE 0x61417272 // 'rrAa'
|
|
|
|
typedef struct _FORMAT_CONTEXT
|
|
{
|
|
PFMIFSCALLBACK Callback;
|
|
ULONG TotalSectorCount;
|
|
ULONG CurrentSectorCount;
|
|
BOOLEAN Success;
|
|
ULONG Percent;
|
|
} FORMAT_CONTEXT, *PFORMAT_CONTEXT;
|
|
|
|
#include "common.h"
|
|
|
|
|
|
NTSTATUS
|
|
Fat12Format(HANDLE FileHandle,
|
|
PPARTITION_INFORMATION PartitionInfo,
|
|
PDISK_GEOMETRY DiskGeometry,
|
|
PUNICODE_STRING Label,
|
|
BOOLEAN QuickFormat,
|
|
ULONG ClusterSize,
|
|
PFORMAT_CONTEXT Context);
|
|
|
|
NTSTATUS
|
|
Fat16Format(HANDLE FileHandle,
|
|
PPARTITION_INFORMATION PartitionInfo,
|
|
PDISK_GEOMETRY DiskGeometry,
|
|
PUNICODE_STRING Label,
|
|
BOOLEAN QuickFormat,
|
|
ULONG ClusterSize,
|
|
PFORMAT_CONTEXT Context);
|
|
|
|
NTSTATUS
|
|
Fat32Format(HANDLE FileHandle,
|
|
PPARTITION_INFORMATION PartitionInfo,
|
|
PDISK_GEOMETRY DiskGeometry,
|
|
PUNICODE_STRING Label,
|
|
BOOLEAN QuickFormat,
|
|
ULONG ClusterSize,
|
|
PFORMAT_CONTEXT Context);
|
|
|
|
VOID
|
|
UpdateProgress(PFORMAT_CONTEXT Context,
|
|
ULONG Increment);
|
|
|
|
VOID
|
|
VfatPrintV(PCHAR Format, va_list args);
|
|
|
|
VOID
|
|
VfatPrint(PCHAR Format, ...);
|
|
|
|
#endif /* _VFATLIB_H_ */
|
|
|
|
/* EOF */
|