📄 ramdisk.c
字号:
//=============================================================================
//
// Compuware Corporation
// NuMega Lab
// 9 Townsend West
// Nashua, NH 03060 USA
//
// Copyright (c) 1998 Compuware Corporation. All Rights Reserved.
// Unpublished - rights reserved under the Copyright laws of the
// United States.
//
//=============================================================================
// RAMDISK.C - main module for VxD RAMDISK
// Copyright (c) 1996, Compuware Corporation
// This is the main module for the Registry File System Driver (RFSD).
// RFSD presents the system Registry as file volume mounted on a hard
// drive under Windows 95. It does this by first creating a virtual
// drive, and then installing a file system on that virtual drive. The
// file system maps file i/o calls to the system Registry. Specifically,
// directories are mapped to keys, files to values, and file contents
// to value data.
//
// RFSD is both a file system driver and a layered block device driver.
// As a file system driver, it translates file i/o requests into
// calls to services that access the Registry. As a port driver, it
// simulates the existence of a hard drive, and provides routines to
// handle i/o requests to that drive.
// The driver may be built with either Microsoft Visual C++ 2.0 (or
// later) or Borland C++ 4.02 (or later).
#define DEVICE_MAIN
#include "ramdisk.h"
#undef DEVICE_MAIN
// Here we declare key data structures for the driver. This macro
// invocation defines the Device Data Block for the VxD, the Device
// Registration Packet (DRP), and the IOS Linkage Block (ILB).
// The macro is defined in vtoolsc.h.
Declare_Port_Driver(RAMDISK,DRP_ESDI_PD,RAMDISK_NAME,\
RAMDISK_REV,RAMDISK_FEATURE,RAMDISK_IFR,DRP_BT_ESDI,0)
// Set prototype for control message handler
DefineControlHandler(SYS_DYNAMIC_DEVICE_INIT, OnSysDynamicDeviceInit);
DefineControlHandler(SYS_DYNAMIC_DEVICE_EXIT, OnSysDynamicDeviceExit);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Function
// ControlDispatcher
//
// Purpose
// Handles control messages sent by the system
//
// Parameters
// dwControlMessage message identifier
// register parameters
//
// Return Value
// The meaning of the return value varies depending on the
// message, but in general, TRUE means success.
//
// Remarks
// Like most all layered block device drivers, this driver
// processes only SYS_DYNAMIC_DEVICE_INIT.
//
BOOL __cdecl ControlDispatcher(
DWORD dwControlMessage,
DWORD EBX,
DWORD EDX,
DWORD ESI,
DWORD EDI,
DWORD ECX)
{
START_CONTROL_DISPATCH
ON_SYS_DYNAMIC_DEVICE_INIT(OnSysDynamicDeviceInit);
ON_SYS_DYNAMIC_DEVICE_EXIT(OnSysDynamicDeviceExit);
END_CONTROL_DISPATCH
return TRUE;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Function
// OnSysDynamicDeviceInit
//
// Purpose
// First level initialization of the RFSD
//
// Parameters
// None
//
// Return Value
// Returns TRUE if successful.
//
// Remarks
// There are two tasks to accomplish. First, the driver must
// register with the IFSMgr. If this is successful, the driver
// registers with the I/O Supervisor.
//
char base[DISKSIZE];
BOOL OnSysDynamicDeviceInit()
{
int add_i, nsec;
USHORT fatEntries;
USHORT fatSectorCnt;
PUCHAR firstFatSector;
PBOOTSECT bsp;
PWORD fat;
for(add_i=0;add_i<DISKSIZE;add_i++)
base[add_i]=0;
bsp = (PBOOTSECT) base;
fat = (PWORD) (base + 512);
nsec = DISKSIZE/512;
// Fill in dummy boot sector so we look like a disk
bsp->jmpinst[0] = 0xEB;
bsp->jmpinst[1] = 0x3C;
bsp->jmpinst[2] = 0x90;
memcpy(bsp->vendid, "WALTONEY", 8);
bsp->secsize = 512; // each sector is 512 bytes long
bsp->clustsize = 1; // one sector per cluster
bsp->numrsv = 1; // no reserved sectors besides this one
bsp->numfat = 1; // one FAT should be enough
bsp->numfiles = 128; // more than enough to prove the point!
bsp->numsectors = 0; // fill in totsectors instead
bsp->media = 0xF8; // claim we're a fixed disk
bsp->fatsectors = (WORD) ((nsec + nsec + 511) / 512);
bsp->tracksectors = (WORD) nsec; // only 1 track, so all sectors are on it
bsp->numtracks = 1; // 1 track
bsp->numhidden = 0; // no hidden sectors
bsp->totsectors = nsec; // this many sectors
bsp->drive = 0x80; // flag for a hard drive
bsp->xboot = 0x29; // flag as extended boot sector
bsp->volid = (DWORD) base; // use base address as volume ID
memcpy(bsp->label, "NO NAME ", 11);
memcpy(bsp->fattype, "FAT16 ", 8);
bsp->part[0].indicator = 0x80;
bsp->part[0].parttype = 4; // DOS 16-bit FAT
bsp->part[0].bias = 0;
bsp->part[0].partsize = nsec;
bsp->signature = 0xAA55; // boot sector signature
// Initialize the start of the FAT at sector 1
fat[0] = 0xFFF8; // reserved bytes
fat[1] = 0xFFFF;
// Now register with the IOS, passing a pointer to the Device
// Registration Packet that is declared above using macro
// Declare_Port_Driver. No error returns are defined for this call.
IOS_Register(&RAMDISK_Drp);
// Return TRUE to indicate a successful initialization.
return TRUE;
}
OnSysDynamicDeviceExit()
{
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -