Increasing RAM Memory

Hi All,

I am implementing the standard ramdisk driver provided by microsoft.

this ramdisk driver was developed for windows 2000 and windows xp .

i have successfully implement the driver on my windows xp machine

Problem

the maximum disksize supported is 32MB . If i try to set it more than 32 , the disk size automatically gets reset to 3 MB.

Troubleshooting So far

I checked the Header file of ramdisk and found the following

bssector is used which is a Ushort ( 16bits ) which might be the major reason for not holding the greater value. And also there is another structure member defined called as bshugesector which is ULONG but when i used bshugesector instead of bssector , no luck

i check the code again and changed the following value
devExt->DiskGeometry.BytesPerSector = 1024; earlier it was set to 512

now , i am able to extend till 50 MB .

I understand without calculation many other factors, i have modified bytespersector. But please help me in setting my ramdisk to any dynamic value not pertaining to only 50 mb or 75 mb

what are the values i should take consideration ? , please suggest me

I am attaching the formatdisk function used in my driver.

RamDiskFormatDisk(
IN PDEVICE_OBJECT DeviceObject
)

/*++

Routine Description:

This routine formats the new disk.

Arguments:

DeviceObject - Supplies a pointer to the device object that represents
the device whose capacity is to be read.

Return Value:

status is returned.

–*/
{

PDEVICE_EXTENSION devExt = DeviceObject->DeviceExtension;
PBOOT_SECTOR bootSector = (PBOOT_SECTOR) devExt->DiskImage;
PUCHAR firstFatSector;
ULONG rootDirEntries;
ULONG sectorsPerCluster;
USHORT fatType; // Type FAT 12 or 16
USHORT fatEntries; // Number of cluster entries in FAT
USHORT fatSectorCnt; // Number of sectors for FAT
PDIR_ENTRY rootDir; // Pointer to first entry in root dir
NTSTATUS status = STATUS_SUCCESS;

DBGPRINT( DBG_COMP_INIT, DBG_LEVEL_VERBOSE, (“FormatDisk\n” ) );

PAGED_CODE();
ASSERT( sizeof(BOOT_SECTOR) == 512);
ASSERT( devExt->DiskImage != NULL );

RtlZeroMemory( devExt->DiskImage, devExt->DiskRegInfo.DiskSize );

devExt->DiskGeometry.BytesPerSector = 1024;
devExt->DiskGeometry.SectorsPerTrack = 32; // Using Ramdisk value
devExt->DiskGeometry.TracksPerCylinder = 2; // Using Ramdisk value

//
// Calculate number of cylinders.
//

devExt->DiskGeometry.Cylinders.QuadPart = devExt->DiskRegInfo.DiskSize / 1024 / 32 / 2;

//
// Our media type is RAMDISK_MEDIA_TYPE
//

devExt->DiskGeometry.MediaType = RAMDISK_MEDIA_TYPE;

DBGPRINT( DBG_COMP_INIT, DBG_LEVEL_INFO,
(“Cylinders: %ld\n TracksPerCylinder: %ld\n SectorsPerTrack: %ld\n BytesPerSector: %ld\n”,
devExt->DiskGeometry.Cylinders.QuadPart, devExt->DiskGeometry.TracksPerCylinder,
devExt->DiskGeometry.SectorsPerTrack, devExt->DiskGeometry.BytesPerSector ) );

rootDirEntries = devExt->DiskRegInfo.RootDirEntries;
sectorsPerCluster = devExt->DiskRegInfo.SectorsPerCluster;

//
// Round Root Directory entries up if necessary
//
if (rootDirEntries & (DIR_ENTRIES_PER_SECTOR - 1)) {
DBGPRINT( DBG_COMP_INIT, DBG_LEVEL_WARN, (“Adjusting RootDirEntries \n” ) );

rootDirEntries =
(rootDirEntries + ( DIR_ENTRIES_PER_SECTOR - 1 )) &
~ ( DIR_ENTRIES_PER_SECTOR - 1 );
}

DBGPRINT( DBG_COMP_INIT, DBG_LEVEL_INFO,
(“Root dir entries: %ld\n Sectors/cluster: %ld\n”,
rootDirEntries, sectorsPerCluster ) );
//
// We need to have the 0xeb and 0x90 since this is one of the
// checks the file system recognizer uses
//
bootSector->bsJump[0] = 0xeb;
bootSector->bsJump[1] = 0x3c;
bootSector->bsJump[2] = 0x90;

strncpy(bootSector->bsOemName, “WyseRamdisk”, 8);
bootSector->bsBytesPerSec = (SHORT)devExt->DiskGeometry.BytesPerSector;
bootSector->bsResSectors = 1;
bootSector->bsFATs = 1;
bootSector->bsRootDirEnts = (USHORT)rootDirEntries;

bootSector->bsSectors = (USHORT)( devExt->DiskRegInfo.DiskSize / devExt->DiskGeometry.BytesPerSector );
//bootSector->bsHugeSectors =(ULONG)( devExt->DiskRegInfo.DiskSize / devExt->DiskGeometry.BytesPerSector );
bootSector->bsMedia = (UCHAR) devExt->DiskGeometry.MediaType;
bootSector->bsSecPerClus = (UCHAR)sectorsPerCluster;

//
// Calculate number of sectors required for FAT
//
fatEntries =
(bootSector->bsSectors - bootSector->bsResSectors -
bootSector->bsRootDirEnts / DIR_ENTRIES_PER_SECTOR) /
bootSector->bsSecPerClus + 2;

//
// Choose between 12 and 16 bit FAT based on number of clusters we
// need to map
//
if (fatEntries > 4087) {
fatType = 16;
fatSectorCnt = (fatEntries * 2 + 511) / 512;
fatEntries -= fatSectorCnt;
fatSectorCnt = (fatEntries * 2 + 511) / 512;
}
else {
fatType = 12;
fatSectorCnt = (((fatEntries * 3 + 1) / 2) + 511) / 512;
fatEntries -= fatSectorCnt;
fatSectorCnt = (((fatEntries * 3 + 1) / 2) + 511) / 512;
}

bootSector->bsFATsecs = fatSectorCnt;
bootSector->bsSecPerTrack = (USHORT)devExt->DiskGeometry.SectorsPerTrack;
bootSector->bsHeads = (USHORT)devExt->DiskGeometry.TracksPerCylinder;
bootSector->bsBootSignature = 0x29;
bootSector->bsVolumeID = 0x12345678;
strncpy(bootSector->bsLabel, "RamDisk ", 11);
strncpy(bootSector->bsFileSystemType, "FAT1? ", 8);
bootSector->bsFileSystemType[4] = ( fatType == 16 ) ? ‘6’ : ‘2’;

bootSector->bsSig2[0] = 0x55;
bootSector->bsSig2[1] = 0xAA;

//
// The FAT is located immediately following the boot sector.
//
firstFatSector = (PUCHAR)(bootSector + 1);
firstFatSector[0] = (UCHAR) devExt->DiskGeometry.MediaType;
firstFatSector[1] = 0xFF;
firstFatSector[2] = 0xFF;

if (fatType == 16) {
firstFatSector[3] = 0xFF;
}

//
// The Root Directory follows the FAT
//
rootDir = (PDIR_ENTRY)(bootSector + 1 + fatSectorCnt);
strcpy(rootDir->deName, "RAMDisk ");
strcpy(rootDir->deExtension, " ");
rootDir->deAttributes = DIR_ATTR_VOLUME;

return status;
} // end RamDiskFormatDisk()

> the maximum disksize supported is 32MB

Search the archives, this was discussed around 1 month ago.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

Consider searching the lists. There have been multiple discussions on RAMDISK and allocating large amount of memory. Discussions even include why the RAMDISK is actually needed in first place and the limitations on large memory allocation.

Regards,
Ayush Gupta

Hi All,

When i search with the Tag RAM DISK i found nothing.

I have changed the following parameters and the disk size has increased which is a good news, below is the value which i changed

"from the above code "

devExt->DiskGeometry.BytesPerSector = 1024;
devExt->DiskGeometry.SectorsPerTrack = 32; // Using Ramdisk value
devExt->DiskGeometry.TracksPerCylinder = 2; // Using Ramdisk value

//
// Calculate number of cylinders.
//

devExt->DiskGeometry.Cylinders.QuadPart = devExt->DiskRegInfo.DiskSize /
1024 / 32 / 2;

Earlier bytespersector was 512 , and i changed it to 1024 , and my disk is able to hold 60 MB instead of 32

Problem : when i change the value , and install the driver, under My computer , the label for the disk is displaying as Local Disk Z: , instead of RAMDisk Z:.

with 512 value everything works fine.

I am getting no where as to why Label name should change.

Please assist.

I found that this label ( RAMDisk) gets created under

HKLM\ccs\software\microsoft\windows\explore\driveicon

but for non working this key is not getting generated.