这段时间想写一个RAMDISK,参考了不少网上的文章,和新版的WDK的RAMDISK示例,都是要额外加DLL文件的,很不爽。
其实微软早期(WDK)之前,出过RAMDISK的示例,编译好后就能使用,而且兼容性非常好,到现在的WIN7还能使用。
这个早期的示例很好,只有一个问题,编译后产生的RAMDISK不能超过32M…………
翻阅了不少文章,发现问题所在,总结一下:
问题所在:
其限制是在RAMDISK.H文件里的一个结构定义上
typedef struct _BOOT_SECTOR
{
UCHAR bsJump[3]; // x86 jmp instruction, checked by FS
CCHAR bsOemName[8]; // OEM name of formatter
USHORT bsBytesPerSec; // Bytes per Sector
UCHAR bsSecPerClus; // Sectors per Cluster
USHORT bsResSectors; // Reserved Sectors
UCHAR bsFATs; // Number of FATs - we always use 1
USHORT bsRootDirEnts; // Number of Root Dir Entries
USHORT bsSectors; // Number of Sectors
UCHAR bsMedia; // Media type - we use RAMDISK_MEDIA_TYPE
USHORT bsFATsecs; // Number of FAT sectors
USHORT bsSecPerTrack; // Sectors per Track - we use 32
USHORT bsHeads; // Number of Heads - we use 2
ULONG bsHiddenSecs; // Hidden Sectors - we set to 0
ULONG bsHugeSectors; // Number of Sectors if > 32 MB size
UCHAR bsDriveNumber; // Drive Number - not used
UCHAR bsReserved1; // Reserved
UCHAR bsBootSignature; // New Format Boot Signature - 0x29
ULONG bsVolumeID; // VolumeID - set to 0x12345678
CCHAR bsLabel[11]; // Label - set to RamDisk
CCHAR bsFileSystemType[8];// File System Type - FAT12 or FAT16
CCHAR bsReserved2[448]; // Reserved
UCHAR bsSig2[2]; // Originial Boot Signature - 0x55, 0xAA
} BOOT_SECTOR, *PBOOT_SECTOR;
USHORT bsFATsecs 最大值65535,512Byte一个Sector,最大当然32M了,悲剧了……
但是看看下面,还有一个ULONG bsHugeSectors,貌似这里才是正道。
然后在RAMDISK.C里,修改一下:(注释掉的是原来的代码,注释跟着的是修改后的代码)
//bootSector->bsSectors = (USHORT)( devExt->DiskRegInfo.DiskSize / devExt->DiskGeometry.BytesPerSector );
if( devExt->DiskRegInfo.DiskSize/devExt->DiskGeometry.BytesPerSector < 65536 ) {
bootSector->bsSectors = (USHORT)(devExt->DiskRegInfo.DiskSize / devExt->DiskGeometry.BytesPerSector);
} else {
bootSector->bsSectors = 0;
bootSector->bsHugeSectors = devExt->DiskRegInfo.DiskSize / devExt->DiskGeometry.BytesPerSector;
}
//fatEntries =
// (bootSector->bsSectors - bootSector->bsResSectors -
// bootSector->bsRootDirEnts / DIR_ENTRIES_PER_SECTOR) /
// bootSector->bsSecPerClus + 2;
if(bootSector->bsSectors) {
fatEntries =
(bootSector->bsSectors - bootSector->bsResSectors -
bootSector->bsRootDirEnts / DIR_ENTRIES_PER_SECTOR) /
bootSector->bsSecPerClus + 2;
} else {
fatEntries =
(USHORT)((bootSector->bsHugeSectors - bootSector->bsResSectors -
bootSector->bsRootDirEnts / DIR_ENTRIES_PER_SECTOR) /
bootSector->bsSecPerClus + 2);
}
这样就可以突破32M到128M了。
但是悲剧的是,还是无法突破128M……
这里要请教高手了。
我修改了一些地方,但是还是突破不了,而且偶尔会蓝屏!
本文介绍了如何修改微软WDK早期RAMDISK示例以突破32MB大小限制。通过调整BOOT_SECTOR结构中的bsFATsecs和bsHugeSectors字段,可以将RAMDISK容量扩大到128MB。然而,尝试进一步扩大容量会导致问题,有时甚至会出现蓝屏。作者寻求解决超过128MB限制的方法。

4909

被折叠的 条评论
为什么被折叠?



