📄 drive.hpp
字号:
/*
Drive Tools for DOS(V32) Prgram v1.1.0 write by 瀛欏疂寤?
10-7-2002
*/
#ifndef _DRIVE_H
#define _DRIVE_H
const DWORD c_DRV_MAX_FILE_SUM =32;
const unsigned int c_uMAX_FAT_CACHE_BUF_SIZE =63*1024;
#ifndef _WIN32
#define PARTITION_ENTRY_UNUSED 0x00 // Entry unused
#define PARTITION_FAT_12 0x01 // 12-bit FAT entries
#define PARTITION_XENIX_1 0x02 // Xenix
#define PARTITION_XENIX_2 0x03 // Xenix
#define PARTITION_FAT_16 0x04 // 16-bit FAT entries
#define PARTITION_EXTENDED 0x05 // Extended partition entry
#define PARTITION_HUGE 0x06 // Huge partition MS-DOS V4
#define PARTITION_IFS 0x07 // IFS Partition
#define PARTITION_OS2BOOTMGR 0x0A // OS/2 Boot Manager/OPUS/Coherent swap
#define PARTITION_FAT32 0x0B // FAT32
#define PARTITION_FAT32_XINT13 0x0C // FAT32 using extended int13 services
#define PARTITION_XINT13 0x0E // Win95 partition using extended int13 services
#define PARTITION_XINT13_EXTENDED 0x0F // Same as type 5 but uses extended int13 services
#define PARTITION_PREP 0x41 // PowerPC Reference Platform (PReP) Boot Partition
#define PARTITION_LDM 0x42 // Logical Disk Manager partition
#define PARTITION_UNIX 0x63 // Unix
#define VALID_NTFT 0xC0 // NTFT uses high order bits
//
// The high bit of the partition type code indicates that a partition
// is part of an NTFT mirror or striped array.
//
#define PARTITION_NTFT 0x80 // NTFT partition
//
// The following macro is used to determine which partitions should be
// assigned drive letters.
//
//++
//
// BOOLEAN
// IsRecognizedPartition(
// IN DWORD PartitionType
// )
//
// Routine Description:
//
// This macro is used to determine to which partitions drive letters
// should be assigned.
//
// Arguments:
//
// PartitionType - Supplies the type of the partition being examined.
//
// Return Value:
//
// The return value is TRUE if the partition type is recognized,
// otherwise FALSE is returned.
//
//--
#define IsRecognizedPartition( PartitionType ) ( \
((PartitionType & PARTITION_NTFT) && ((PartitionType & ~0xC0) == PARTITION_FAT_12)) || \
((PartitionType & PARTITION_NTFT) && ((PartitionType & ~0xC0) == PARTITION_IFS)) || \
((PartitionType & PARTITION_NTFT) && ((PartitionType & ~0xC0) == PARTITION_HUGE)) || \
((PartitionType & PARTITION_NTFT) && ((PartitionType & ~0xC0) == PARTITION_FAT32)) || \
((PartitionType & PARTITION_NTFT) && ((PartitionType & ~0xC0) == PARTITION_FAT32_XINT13)) || \
((PartitionType & PARTITION_NTFT) && ((PartitionType & ~0xC0) == PARTITION_XINT13)) || \
((PartitionType) == PARTITION_FAT_12) || \
((PartitionType) == PARTITION_FAT_16) || \
((PartitionType) == PARTITION_IFS) || \
((PartitionType) == PARTITION_HUGE) || \
((PartitionType) == PARTITION_FAT32) || \
((PartitionType) == PARTITION_FAT32_XINT13) || \
((PartitionType) == PARTITION_XINT13) )
//++
//
// BOOLEAN
// IsContainerPartition(
// IN DWORD PartitionType
// )
//
// Routine Description:
//
// This macro is used to determine to which partition types are actually
// containers for other partitions (ie, extended partitions).
//
// Arguments:
//
// PartitionType - Supplies the type of the partition being examined.
//
// Return Value:
//
// The return value is TRUE if the partition type is a container,
// otherwise FALSE is returned.
//
//--
#define IsContainerPartition( PartitionType ) \
((PartitionType == PARTITION_EXTENDED) || (PartitionType == PARTITION_XINT13_EXTENDED))
//++
//
// BOOLEAN
// IsFTPartition(
// IN DWORD PartitionType
// )
//
// Routine Description:
//
// This macro is used to determine if the given partition is an FT
// partition.
//
// Arguments:
//
// PartitionType - Supplies the type of the partition being examined.
//
// Return Value:
//
// The return value is TRUE if the partition type is an FT partition,
// otherwise FALSE is returned.
//
//--
#define IsFTPartition( PartitionType ) \
(((PartitionType)&PARTITION_NTFT) && IsRecognizedPartition(PartitionType))
//
// Define the media types supported by the driver.
//
#endif //_WIN32
//#pragma pack(push)
#pragma pack(1)
typedef struct tagMbr
{
public:
BYTE ByBootFlag;
BYTE ByBeginHead;
BYTE ByBeginSector;
BYTE ByBeginCyl;
BYTE ByPartitionType;
BYTE ByEndHead;
BYTE ByEndSector;
BYTE ByEndCyl;
DWORD dwPreservedSector;
DWORD dwSumSector;
}MBR,*PMBR;
typedef struct tagFdt32
{
public:
BYTE byFileNumber;
BYTE byFileName1[10]; //unicode
BYTE byAttrib; //0fh
BYTE byLongFileName; //0
BYTE byByCheckSum;
BYTE byFileName2[12]; //unicode
BYTE byUnused[2];
BYTE byFileName3[4]; //unicode/
}FDT32,*PFDT32;
typedef struct tagFdt
{
public:
BYTE cFileName[8];
// BYTE cFileNameDot;
BYTE cFileNameExt[3];
BYTE ByAttrib;
BYTE cUnused[8];
WORD wHightCustorByte;
WORD wTime;
WORD wDate;
WORD wLowCustorByte;
DWORD dwFileLength;
}FDT,*PFDT;
typedef struct tagCluster
{
public:
WORD wClusterLowByte;
WORD wClusterHightByte;
}CLUSTER,*PCLUSTER;
typedef union tagFirstCluster
{
CLUSTER m_Cluster;
DWORD dwFirstCluster;
}FIRSTCLUSTER,*PFIRSTCLUSTER;
typedef struct tagPartition
{
BYTE ByCode[446];
MBR m_Mbr[4];
WORD wPartitionFlag;
}PARTITION,*PPARTITION;
typedef struct tagBoot16
{
BYTE cJmpCode[3];
BYTE cOEM[8];
WORD wBytesPerSector;
BYTE BySectorsPerCluster;
WORD wPreserveSectors;
BYTE BySumFat;
WORD wNumberFdb;
WORD wSumSector;
BYTE ByMediaType;
WORD wSectorPerFat;
WORD wSectorPerTrack;
WORD wSumHead;
DWORD dwHideSector;
DWORD dwTotalSector;// BYTE BySectorIo;
BYTE ByDiskNumber;// Argument[11];
BYTE cPreserve;
BYTE cBootFlagEx;
DWORD dwDiskID;
BYTE cVolume[11];
BYTE cFileSystemType[8];
BYTE ByBootCode[448];
WORD wBootFlag;
}BOOT16,*PBOOT16;
/*
typedef struct tagBoot32
{
BYTE cJmpCode[3];
BYTE cOEM[8];
WORD wBytePerSector;
BYTE BySectorPerCluster;
WORD wPreserveSector;
BYTE BySumFat;
WORD wReserved1;
BYTE ByMediaType;
WORD wReserved2;
// WORD wSectorPerFat;
WORD wSectorPerTrack;
WORD wSumHead;
DWORD dwHideSector;
DWORD dwSumSector;
DWORD dwSectorPerFat; //?????????
BYTE byCNofFdt;
// WORD wFlagExtend;
BYTE byPhyDiskNumber;
BYTE byFileSystemVersion; //==0x29
// DWORD dwClusterPerFdt;
// WORD wFileSystemSector;
// WORD wBootSector;
// BYTE ByPreserve[12];
// BYTE ByDiskID;
// BYTE ByPreserve2;
// BYTE ByBootFlagEx;
DWORD dwDiskSerial;;
BYTE cVolume[8];
BYTE cFileSystemType[8];
BYTE ByBootCode[422];
WORD wBootFlag;
}BOOT32,*PBOOT32;
*/
/*
typedef struct tagBoot32
{
BYTE cJmpCode[3];
BYTE cOEM[8];
WORD wBytePerSector;
BYTE BySectorPerCluster;
WORD wPreserveSector;
BYTE BySumFat;
WORD wNumberDirectory;
WORD wSumSector;
BYTE ByMediaType;
WORD wSectorPerFat;
WORD wSectorPerTrack;
WORD wSumHead;
DWORD dwHideSector;
DWORD dwSumSector;
DWORD dwSectorPerFat; //?????????
WORD wFlagExtend;
WORD wFileSystemVersion;
DWORD dwClusterPerFdt;
WORD wFileSystemSector;
WORD wBootSector;
BYTE ByPreserve[12];
BYTE ByDiskID;
BYTE ByPreserve2;
BYTE ByBootFlagEx;
DWORD dwFiskNumber;
BYTE cVolume[11];
BYTE cFileSystemType[8];
BYTE ByBootCode[420];
WORD wBootFlag;
}BOOT32,*PBOOT32;
*/
/*
A_BF_BPB STRUC
A_BF_BPB_BytesPerSector DW ?
A_BF_BPB_SectorsPerCluster DB ?
A_BF_BPB_ReservedSectors DW ?
A_BF_BPB_NumberOfFATs DB ?
A_BF_BPB_RootEntries DW ?
A_BF_BPB_TotalSectors DW ?
A_BF_BPB_MediaDescriptor DB ?
A_BF_BPB_SectorsPerFAT DW ?
A_BF_BPB_SectorsPerTrack DW ?
A_BF_BPB_Heads DW ?
A_BF_BPB_HiddenSectors DW ?
A_BF_BPB_HiddenSectorsHigh DW ?
A_BF_BPB_BigTotalSectors DW ?
A_BF_BPB_BigTotalSectorsHigh DW ?
A_BF_BPB_BigSectorsPerFat DW ?
A_BF_BPB_BigSectorsPerFatHi DW ?
A_BF_BPB_ExtFlags DW ?
A_BF_BPB_FS_Version DW ?
A_BF_BPB_RootDirStrtClus DW ?
A_BF_BPB_RootDirStrtClusHi DW ?
A_BF_BPB_FSInfoSec DW ?
A_BF_BPB_BkUpBootSec DW ?
A_BF_BPB_Reserved DW 6 DUP (?)
A_BF_BPB ENDS
*/
typedef struct tagBoot32
{
BYTE cJmpCode[3];
BYTE cOEM[8];
WORD wBytePerSector;
BYTE BySectorPerCluster;
WORD wPreserveSector;
BYTE NumberofFATs; //The number of copies of the FAT on the volume. The value of this field is always 2
/*
(FAT12/FAT16 only). For FAT32 volumes, this field must be set to zero.
*/
WORD RootEntries ;
/*
(FAT12/FAT16 only). For FAT32 volumes, this field must be set to zero.
*/
WORD SmallSectors ;
BYTE MediaDescriptor;
WORD wSectorPerFat;
WORD wSectorPerTrack;
WORD wSumHead;
DWORD dwHideSector;
DWORD LargeSectors; //Contains the total number of sectors in the FAT32 volume.
DWORD dwSectorPerFat;
/*
(FAT32 only). The value of the bits in this two-byte structure are:
Bits 0–3: Number of the active FAT (starting count at 0, not 1). It is only valid if mirroring is disabled.
Bits 4–6: Reserved.
Bit 7: A value of 0 means the FAT is mirrored at run time into all FATs. A value of 1 means only one FAT is active (referenced in bits 0-3).
Bits 8–15: Reserved
BGBPB_F_ActiveFATMsk (000Fh) Mask for low four bits.
BGBPB_F_NoFATMirror (0080h) Mask indicating FAT mirroring state.
If set, FAT mirroring is disabled. If clear, FAT mirroring is enabled
*/
WORD ExtendedFlags;
/*
(FAT32 only). The high byte is the major revision number, whereas the low byte is the minor revision number. This field supports the ability to extend the FAT32 media type in the future with concern for old FAT32 drivers mounting the volume. If the field is non-zero, back-level Windows versions will not mount the volume.
*/
WORD wFileSystemVersion;
/*
(FAT32 only). The cluster number of the first cluster of the root directory.
This value is typically, but not always, 2
*/
DWORD RootClusterNumber ;
/*
(FAT32 only). The sector number of the File System Information (FSINFO) structure in the reserved area
of the FAT32 volume. The value is typically 1. A copy of the FSINFO structure is kept
in the Backup Boot Sector, but it is not kept up-to-date
The sector number of the file system information sector. The file system info sector contains a BIGFATBOOTFSINFO structure.
This member is set to 0FFFFh if there is no FSINFO sector.
Otherwise, this value must be non-zero and less than the reserved sector count
*/
WORD FileSystemInformationSectorNumber ;
/*
Backup Boot Sector (FAT32 only).
A non-zero value indicates the sector number in the reserved area of the volume
in which a copy of the boot sector is stored. The value of this field is typically 6.
No other value is recommended
*/
WORD BackupBootSector ;
BYTE ByPreserve[12];
/*
Related to the BIOS physical drive number. Floppy disk drives are identified as 0x00
and physical hard disks are identified as 0x80, regardless of the number of physical disk drives.
Typically, this value is set prior to issuing an INT 13h BIOS call to specify the device to access.
It is only relevant if the device is a boot device
*/
BYTE PhysicalDriveNumber;//
BYTE ByPreserve2;
BYTE ExtendedBootSignature; //A field that must have the value 0x28 or 0x29 to be recognized by Windows 2000
DWORD VolumeSerialNumber;
BYTE VolumeLabel[11];
/*
A field once used to store the volume label.
The volume label is now stored as a special file in the root directory
*/
BYTE SystemID[8];
BYTE ByBootCode[420];
WORD wBootFlag;
}BOOT32,*PBOOT32;
class CFat32
{
protected:
CSError *m_pError;
DWORD64 m_dqFat32StartSector;
DWORD m_ulCurSectors; //相对于fat表的偏移数,以扇区数计算
unsigned int m_ulFat32Size; //nsectors 以扇区数计算
unsigned int m_ulBufSize; //bytes计算
BYTE *m_pbyFat32;
CInt13 *m_pInt13;
public:
virtual ~CFat32();
CFat32(CSError *pError);
BOOL LoadFat32(CInt13 *pInt13,IN DWORD64 ulFat32StartSector,IN unsigned int ulFat32Size);
BOOL GetCluster(IN DWORD Clustor,OUT DWORD &nextCluster);
};
class CLogicalDisk32
{
protected:
CSError *m_pError;
DWORD64 m_dqPartitionPos; //逻辑盘分区表所在的扇区,它指向m_dqStartSector //绝对扇区号
DWORD64 m_dqBootPosition; //它指向的是BPB扇区,//绝对扇区号
DWORD64 m_dqBeginFatSector; //绝对扇区号
DWORD64 m_dqBeginFdtSector; //绝对始扇区号
DWORD64 m_dqBeginDataSector; //绝对扇区号
PARTITION m_Partition;
MBR m_Mbr;
BOOT32 m_Boot32;
FDT m_Fdt;
CInt13 *m_pInt13;
CFat32 *m_pFat32;
public:
/* BOOL m_bData;
BOOL m_bFat;
BOOL m_bDir;
BOOL m_bBpb;
BOOL m_bPartition;
BOOL m_bMbr;
*/
BOOL LoadPartition(DWORD64 sectorPos);
BOOL LoadMbr(DWORD64 sectorPos,int MbrNumber=0);
BOOL LoadBoot(DWORD64 sectorPos);
BOOL LoadFat32(DWORD64 sectorPos,unsigned int ulFat32Size);
void LoadFdt(BYTE *pfdtBuf);
DWORD64 m_dqLogicalSector;
int m_iDirLen;
//unsigned int m_ulParentPartition;
CLogicalDisk32(CInt13 *pInt13,CSError *pError);
~CLogicalDisk32();
void Calcute(void);
DWORD64 CtoS(DWORD Clustor);
void CaculateData(void);
BOOL GetCluster(IN DWORD Clustor,OUT DWORD &newCluster);
string PartitionToString(void);
string MbrToString(void);
string Boot32ToString(void);
string Fat32ToString(void);
string DirToString(BYTE *pfdtBuf,unsigned int len,unsigned int ulPos);
string FdtToString(void);
};
//#pragma pack(pop)
// void SearchInSector(unsigned int ulSectors,UCHAR *argv,unsigned int ulLen,unsigned int ulBegginPos);
#endif //_DRIVE_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -