Driver Framework Ramdisk Sample Driver

SUMMARY

This sample demonstrates how to write a PnP software only function driver using Windows Driver Framework. 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® 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 and later operating systems.

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 src\wdf\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 wdframdisk.sys and the generated inf file ramdisk.inf will be placed in a platform specific subdirectory of your %TargetPath% directory specified in the Sources file.

Installing the Sample

To install the driver on Windows 2000:

  1. Double-click the Add New Hardware Wizard applet in Control Panel.
  2. Click Next.
  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 Have Disk and point to the directory that contains wdframdisk.sys, RAMDISK.inf and the KMDF coinstaller (wdfcoinstallerMMmmm.dll) file. NOTE: You will need to manually copy the coinstaller (wdfcoinstallerMMmmm.dll) file from %wdkroot%\redist\wdf\(platform specific) folder to your install folder.

To install the bus driver on Windows XP and Windows Server 2003:

  1. Double-click the ‘Add Hardware’ wizard in Control Panel.
  2. At the 'Welcome to the Add Hardware Wizard', click ‘Next’.
  3. Select 'Yes, I have already connected the hardware', then click Next.
  4. Select ‘Add a new hardware device’ from the list, then click Next.
  5. Select ‘Install the hardware that I manually select from a list(Advanced),' and then click next.
  6. Select ‘Show All Devices’, then click Next.
  7. Click 'Have Disk', make sure that 'A:\' is in the "Copy manufacturer's files from:" box, and click OK.
  8. Click on the desired entry, and then click Next.
  9. At 'The wizard is ready to install your hardware', click Next.
  10. Click Finish at 'Completing the Add/Remove Hardware Wizard.'

Alternatively, you can use the DEVCON.EXE from the DDK to install the driver programmatically.

c:\>DEVCON.EXE INSTALL ramdisk.inf ramdisk

The system copies the WdfRamdisk.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
Ramdisk.h     Include file that contains the Ramdisk structures
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).