📄 rfatsa.cxx
字号:
/*++
Copyright (c) 1990-2001 Microsoft Corporation
Module Name:
rfatsa.cxx
Environment:
ULIB, User Mode
--*/
#include <pch.cxx>
#define _UFAT_MEMBER_
#include "ufat.hxx"
#include "cmem.hxx"
#include "error.hxx"
#include "rtmsg.h"
#include "drive.hxx"
#include "bpb.hxx"
#include "bitvect.hxx"
#if !defined( _EFICHECK_ )
extern "C" {
#include <stdio.h>
}
#endif
#if defined(FE_SB) && defined(_X86_)
// PC98 boot strap code no use disk bios, PC98's boot strap code select.
extern UCHAR PC98FatBootCode[512];
extern UCHAR PC98Fat32BootCode[512*3];
#endif
// vjz extern UCHAR FatBootCode[512];
// vjz extern UCHAR Fat32BootCode[512*3];
//UCHAR FatBootCode[512]; // vjz
//UCHAR Fat32BootCode[512*3]; // vjz
#define FAT32BOOTCODE_SIZE 1536
unsigned char FatBootCode[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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1,0,4,0,0,248,0,0,17,0,4,0,1,0,0,0,
0,0,32,0,224,31,0,0,0,0,0,0,0,0,0,0,
1,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,
128,0,41,0,0,0,0,78,79,32,78,65,77,69,32,32,
32,32,70,65,84,51,50,32,32,32,51,201,142,209,188,244,
123,142,193,142,217,189,0,124,136,78,2,138,86,64,180,8,
205,19,115,5,185,255,255,138,241,102,15,182,198,64,102,15,
182,209,128,226,63,247,226,134,205,192,237,6,65,102,15,183,
201,102,247,225,102,137,70,248,131,126,22,0,117,56,131,126,
42,0,119,50,102,139,70,28,102,131,192,12,187,0,128,185,
1,0,232,43,0,233,72,3,160,250,125,180,125,139,240,172,
132,192,116,23,60,255,116,9,180,14,187,7,0,205,16,235,
238,160,251,125,235,229,160,249,125,235,224,152,205,22,205,25,
102,96,102,59,70,248,15,130,74,0,102,106,0,102,80,6,
83,102,104,16,0,1,0,128,126,2,0,15,133,32,0,180,
65,187,170,85,138,86,64,205,19,15,130,28,0,129,251,85,
170,15,133,20,0,246,193,1,15,132,13,0,254,70,2,180,
66,138,86,64,139,244,205,19,176,249,102,88,102,88,102,88,
102,88,235,42,102,51,210,102,15,183,78,24,102,247,241,254,
194,138,202,102,139,208,102,193,234,16,247,118,26,134,214,138,
86,64,138,232,192,228,6,10,204,184,1,2,205,19,102,97,
15,130,84,255,129,195,0,2,102,64,73,15,133,113,255,195,
78,84,76,68,82,32,32,32,32,32,32,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,13,10,78,84,
76,68,82,32,105,115,32,109,105,115,115,105,110,103,255,13,
10,68,105,115,107,32,101,114,114,111,114,255,13,10,80,114,
101,115,115,32,97,110,121,32,107,101,121,32,116,111,32,114,
101,115,116,97,114,116,13,10,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,172,191,204,0,0,85,170,
82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0,0,0,0,0,0,0,0,0,0,0,0,0,85,170,
102,15,182,70,16,102,139,78,36,102,247,225,102,3,70,28,
102,15,183,86,14,102,3,194,102,137,70,252,102,199,70,244,
255,255,255,255,102,139,70,44,102,131,248,2,15,130,166,252,
102,61,248,255,255,15,15,131,156,252,102,80,102,131,232,2,
102,15,182,94,13,139,243,102,247,227,102,3,70,252,187,0,
130,139,251,185,1,0,232,135,252,56,45,116,30,177,11,86,
190,112,125,243,166,94,116,27,3,249,131,199,21,59,251,114,
232,78,117,218,102,88,232,101,0,114,191,131,196,4,233,85,
252,0,32,131,196,4,139,117,9,139,125,15,139,198,102,193,
224,16,139,199,102,131,248,2,15,130,58,252,102,61,248,255,
255,15,15,131,48,252,102,80,102,131,232,2,102,15,182,78,
13,102,247,225,102,3,70,252,187,0,0,6,142,6,129,128,
232,29,252,7,102,88,193,235,4,1,30,129,128,232,14,0,
15,131,2,0,114,208,138,86,64,234,0,0,0,32,102,193,
224,2,232,17,0,38,102,139,1,102,37,255,255,255,15,102,
61,248,255,255,15,195,191,0,126,102,15,183,78,11,102,51,
210,102,247,241,102,59,70,244,116,58,102,137,70,244,102,3,
70,28,102,15,183,78,14,102,3,193,102,15,183,94,40,131,
227,15,116,22,58,94,16,15,131,171,251,82,102,139,200,102,
139,70,36,102,247,227,102,3,193,90,82,139,223,185,1,0,
232,157,251,90,139,218,195,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,85,170
};
#if !defined(_AUTOCHECK_) && !defined(_SETUP_LOADER_) && !defined( _EFICHECK_ )
#include "timeinfo.hxx"
#endif
// Control-C handling is not necessary for autocheck.
#if !defined( _AUTOCHECK_ ) && !defined(_SETUP_LOADER_) && !defined( _EFICHECK_ )
#include "keyboard.hxx"
#endif
#define CSEC_FAT32MEG 65536
#define CSEC_FAT16BIT 32680
#define MAX_CLUS_SMALL 4086 // Maximum number of clusters for FAT12 2^12 - 8 - 2
#define MAX_CLUS_ENT_SMALL 4087 // Largest fat entry for FAT12
#define MIN_CLUS_BIG 4087
#define MAX_CLUS_BIG 65526 // Maximum number of clusters for FAT16 2^16 - 8 - 2
#define MAX_CLUS_ENT_BIG 65527 // Largest fat entry for FAT16
#define MIN_CLUS_BIG32 65527
#define MAX_CLUS_BIG32 0x0FFFFFF6 // Maximum number of clusters for FAT32 2^28 - 8 - 2
#define MAX_CLUS_ENT_BIG32 0x0FFFFFF7 // Largest fat entry for FAT32
#define sigSUPERSEC1 (UCHAR)0x55 // signature first byte
#define sigSUPERSEC2 (UCHAR)0xAA // signature second byte
#define FAT_FIRST_DATA_CLUSTER_ALIGNMENT (4*1024) // data clusters starting alignment
#define NUMBER_OF_FATS (2)
//
// The following macro computes the rounded up quotient of a number
// divided by another number.
//
#define RoundUpDiv(num,div) ((num) / (div) + ((num) % (div) ? 1 : 0))
//
// The following macros maps a logical sector number to the corresponding
// cluster on a volume based on the starting data Lbn and the number of
// sectors per cluster.
//
#define MapSectorToCluster( sector, sec_per_clus, start_data_lbn ) \
((((sector) - (start_data_lbn)) / (sec_per_clus)) + FirstDiskCluster)
//
// Internal function prototypes
//
ULONG
ComputeClusters(ULONG, ULONG, ULONG, ULONG, ULONG, FATTYPE);
//
// Functions for supporting the reduced memory consumption FAT (Reduced FAT)
// format.
//
VOID SetEarlyEntries( PUCHAR, UCHAR, FATTYPE );
VOID SetEndOfChain( PUCHAR, ULONG, ULONG, FATTYPE );
VOID SetClusterBad( PUCHAR, ULONG, ULONG, FATTYPE );
VOID Set( PUCHAR, ULONG, ULONG, ULONG, FATTYPE );
VOID Set12( PUCHAR, ULONG, ULONG, ULONG);
VOID Set16( PUCHAR, ULONG, ULONG, ULONG);
VOID Set32( PUCHAR, ULONG, ULONG, ULONG);
//
// End of internal function prototypes
//
DEFINE_EXPORTED_CONSTRUCTOR( REAL_FAT_SA, FAT_SA, UFAT_EXPORT );
BOOLEAN
REAL_FAT_SA::DosSaInit(
IN OUT PMEM Mem,
IN OUT PLOG_IO_DP_DRIVE Drive,
IN SECTORCOUNT NumberOfSectors,
IN OUT PMESSAGE Message
)
/*++
Routine Description:
This routine simply initializes the underlying SUPERAREA structure
and sets up a private pointer to the boot sector signature which is
the last two bytes of the first sector. Note that the line for
initializing the boot sector signature assumes that the sector size
is 512 bytes.
Arguments:
Mem - Supplies a pointer to a MEM which provides the memory for the
REAL_FAT_SA object.
Dive - Supplies a pointer the dirve object in which this super
area object is found.
NumberOfSectors - Supplies the total number of sectors on the
volume.
Message - Supplies an outlet for messages.
Return Values:
TRUE - Success.
FALSE - Failure. The failure is probably caused by a lack of
memory.
--*/
{
//
// Class inheritance chain for REAL_FAT_SA:
// OBJECT<-SECRUN<-SUPERAREA<-FAT_SA<-REAL_FAT_SA
//
//
// Note that SUPERAREA::Initialize will initialize the
// _drive member. SUPERAREA::Initialize itself will call
// SECRUN::Initialize which aquires memory from the Mem
// object and marks the boundary of the superarea on the
// disk.
//
if (!SUPERAREA::Initialize(Mem, Drive, NumberOfSectors, Message)) {
Message->Set(MSG_FMT_NO_MEMORY);
Message->Display("");
return FALSE;
}
//
// Note that the following line of code depends on a sector size
// of twelve but changing the code based on the real sector size
// may break the boot code.
//
_sector_sig = (UCHAR *)SECRUN::GetBuf() + 510;
return TRUE;
}
BOOLEAN
REAL_FAT_SA::DosSaSetBpb(
)
/*++
Routine Description:
This routine sets up the common fields in the FAT Bpb. More elaborate
initialization of the Bpb is done in REAL_FAT_SA::SetBpb.
Arguments:
NONE.
Return Values:
TRUE - This method cannot fail.
--*/
{
#if defined _SETUP_LOADER_
return FALSE;
#else
ULONG Sec32Meg; // num sectors in 32mb
DebugAssert(_drive);
DebugAssert(_drive->QuerySectors().GetHighPart() == 0);
DebugAssert(_drive->QueryHiddenSectors().GetHighPart() == 0);
//
// Sets up the bytes per sector field in the Bpb.
//
_sector_zero.Bpb.BytesPerSector = (USHORT)_drive->QuerySectorSize();
//
// Theoretically, having 32megs of 128 bytes sectors will overflow the
// 16-bit integer in the Sectors field of the Bpb so the following
// code is not absolutely fool-proof.
//
Sec32Meg = (32<<20) / _drive->QuerySectorSize();
if (_drive->QuerySectors() >= Sec32Meg) {
//
// >= 32Mb -- set BPB for large partition
//
DEBUG((D_INFO, (CHAR8*)"REAL_FAT_SA::DosSaSetBpb: Large Partition\n"));
_sector_zero.Bpb.Sectors = 0;
_sector_zero.Bpb.LargeSectors = _drive->QuerySectors().GetLowPart();
} else {
//
// Size of DOS0 partition is < 32Mb
//
_sector_zero.Bpb.Sectors = (USHORT)_drive->QuerySectors().GetLowPart();
_sector_zero.Bpb.LargeSectors = 0;
DEBUG((D_INFO, (CHAR8*)"REAL_FAT_SA::DosSaSetBpb: Small Partition %x\n", _sector_zero.Bpb.Sectors));
}
//
// The following block of code sets up the phycical characterics of the
// volume in the bpb.
//
_sector_zero.Bpb.Media = _drive->QueryMediaByte();
_sector_zero.Bpb.SectorsPerTrack = (USHORT)_drive->QuerySectorsPerTrack();
_sector_zero.Bpb.Heads = (USHORT)_drive->QueryHeads();
#if defined(FE_SB) && defined(_X86_)
// PC98 Oct.21.1995 ATAcard add
// PC98 Floppy disk should be treated same as PC/AT
if (IsPC98_N() && !_drive->IsATformat() && !_drive->IsFloppy() && !_drive->IsSuperFloppy()){
_sector_zero.Bpb.HiddenSectors = _drive->QueryPhysicalHiddenSectors().GetLowPart();
} else
#endif
_sector_zero.Bpb.HiddenSectors = _drive->QueryHiddenSectors().GetLowPart();
DEBUG((D_INFO, (CHAR8*)"REAL_FAT_SA::DosSaSetBpb: Media %x\n", _sector_zero.Bpb.Media));
return TRUE;
#endif // _SETUP_LOADER_
}
VOID
REAL_FAT_SA::Construct (
)
/*++
Routine Description:
Constructor for FAT_SA.
Arguments:
None.
Return Value:
None.
--*/
{
_fat = NULL;
_dir = NULL;
_dirF32 = NULL;
_hmem_F32 = NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -