Ramdisk Sample Driver

SUMMARY

This sample demonstrates a software only Windows® 2000 Device Driver. This driver creates a RAM disk drive of the specified size. This Ramdisk can be used like any other disk, but the contents of the disk will be lost when the machine is shutdown. Generally the Windows® 2000 cache manager does a much better job of optimizing memory usage than using a Ramdisk.

The driver building and installation instructions given here apply only to Windows® 2000.

Note: This sample provides an example of a minimal driver. Neither the driver nor the sample programs are intended for use in a production environment. Rather, they are intended for educational purposes and as a skeleton driver.

Building the Sample

Click the Free Build Environment or Checked Build Environment icon under your Development Kits program group to set basic environment variables needed by the build utility.

Change to the directory containing the device source code, such as CD C:\Drivers\Ramdisk

Run build -ceZ, or use the macro BLD. This behavior invokes the Microsoft make routines that produce log files called Buildxxx.log, and also Buildxxx.wrn and Buildxxx.err if there are any warnings or errors. Where xxx stands for fre or chk depending on the environment chosen. If the build succeeds, the driver Ramdisk.sys will be placed in a platform specific subdirectory of your %TargetPath% directory specified in the Sources file.

Installing the Sample

To install the driver:

  1. Double-click the Add/Remove Hardware Wizard applet in Control Panel.
  2. Select Add/Troubleshoot a Device.
  3. Select “Add a new device”.
  4. Select “No, I Want to Select the Hardware from a list”.
  5. Select “Other devices” and then click Next.
  6. Click the “Have Disk” button and point to the directory that contains Ramdisk.inf file.

The system copies the Ramdisk.sys file to %systemroot%\system32\drivers directory and loads the driver.

Configuring the Ramdisk Drive

The Ramdisk can be configured using the registry.  The RAMDISK.INF file contains the default values for all the configurable parameters.  A brief description of each parameter follows:

BreakOnEntry        REG_DWORD   0

Boolean value, which determines whether a break point will be generated during the DriverEntry routine.  It has no effect in a free build of the driver.

DebugLevel          REG_DWORD   0

This value specifies the level of diagnostic messages produced.  Larger values result in more verbose messages. It can take values from 0 to 3.  It has no effect in a free build of the driver.

DebugComp          REG_DWORD   0xFFFFFFFF

This value specifies the components in which the debug messages to be printed. Each bit specifies the component. See Debug.h for component list. It has no effect in a free build of the driver.

DiskSize            REG_DWORD   0x100000 (1,048,576 1Mb)

The size of the Ramdisk drive in bytes.

DriveLetter         REG_SZ      Z:

The default drive letter associated with the Ramdisk drive.

RootDirEntries      REG_DWORD   512

The number of entries in the root directory.

SectorsPerCluster   REG_DWORD   2

The granularity of the allocation unit.

 

CODE TOUR

File Manifest

File           Description
 
Ramdisk.c     Source file for the Ramdisk sample driver
Pnp.c         Source file that handles the PnP IRPs
Ramdisk.h     Include file that contains the Ramdisk structures
Debug.h       Include file that contains the debug print definition 
Sources       Generic file for building the code sample.
Ramdisk.inf   Installation file for installing the driver.
Ramdisk.htm   Sample Tour documentation for this sample (this file).