RAMDISK
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.
Forward Progress
This sample also demonstrates how to add forward progress support in your driver. It shows how to configure a queue for forward progress, the different forward progress callbacks and the forward progress policies. Please refer to the WDK documenation for more information on the callbacks.
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 MSBuild utility.
-
Change to the directory that contains the device source code, such as src\storage\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.
- Copy the KMDF coinstaller (wdfcoinstallerMMmmm.dll) file into the platform specific subdirectory.
Installing the Sample
- To install the driver on Windows 2000:
- Double-click Add New Hardware in Control Panel.
- Click Next.
- Click Add a new device.
- Click No, I Want to Select the Hardware from a list.
- Click Other Devices and then click Next.
- Click Have Disk and point to the directory that contains the Ramdisk.inf and the KMDF coinstaller (wdfcoinstallerMMmmm.dll) file.
- To install the bus driver on Windows XP and later operating systems:
- Double-click Add Hardware in Control Panel.
- At the Welcome to the Add Hardware Wizard, click Next.
- Click Yes, I have already connected the hardware, and then click Next.
- Click Add a new hardware device from the list, and then click Next.
- Click Install the hardware that I manually select from a list(Advanced), and then click Next.
- Click Show All Devices, and then click Next.
- Click Have Disk, make sure that A:\ is in the Copy manufacturer's files from: box, and click OK.
- Click the desired entry, and then click Next.
- At The wizard is ready to install your hardware, click Next.
- Click Finish.
- To install the bus driver on Windows 7:
- Click Start and enter Hdwwiz.exe.
- At the Welcome to the Add Hardware Wizard, click Next.
- Click Install the hardware that I manually select from a list (Advanced), and then click Next.
- Select Show All Devices from the list, and then click Next.
- Click Have Disk, browse to the directory that contains the Ramdisk.inf and the co-installer and click OK.
- Click the desired entry, and then click Next.
- At The wizard is ready to install your hardware, click Next.
- Click Finish.
Alternate Installation
You can use the Devcon.exe from the WDK or DDK to install the driver programmatically, as follows:
DEVCON.EXE INSTALL ramdisk.inf ramdisk
The system copies the WdfRamdisk.sys file to the %systemroot%\system32\drivers directory and loads the driver.
Configuring the RAM Disk Drive
The RAM disk 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 are to be printed. Each bit specifies the component. See Debug.h for a 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 RAM disk drive in bytes.
-
DriveLetter REG_SZ Z:
The default drive letter associated with the RAM disk 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 RAM disk sample driver |
|
Ramdisk.h |
Include file that contains the RAM disk structures |
|
forward_progress.c |
Source file for forward progress |
|
forward_progress.h |
Include file that contains the forward progress 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). |
Send comments about this topic to Microsoft
Build date: 4/5/2012