Hi all!
I am a new guy for driver development. I had written a drive to implement a virtual disk through file. The DriverEntry routine is as below:
NTSTATUS DriverEntry(PDRIVER_OBJECT drvObject, PUNICODE_STRING usRegPath)
{
PKEY_VALUE_PARTIAL_INFORMATION startKeyValue;
ULONG version;
int i;
Dump("DriverEntry " DRIVER_NAME " " DRIVER_VERSION "\n");
memset(&OsVersion, 0, sizeof(RTL_OSVERSIONINFOW));
OsVersion.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOW);
RtlGetVersion(&OsVersion);
if (NT_SUCCESS (FDDeviceIoControl (NT_ROOT_PREFIX, FD_IOCTL_GET_DRIVER_VERSION, NULL, 0, &version, sizeof (version))))
return DumpFilterEntry ((PFILTER_EXTENSION) drvObject, (PFILTER_INITIALIZATION_DATA) usRegPath);
FDDriverObject = drvObject;
memset(VirtualVolumeDeviceObjects, 0, sizeof(VirtualVolumeDeviceObjects));
if(NT_SUCCESS(FDReadRegistryKey(usRegPath, L"Start", &startKeyValue)))
{
if(startKeyValue->Type == REG_DWORD && *((uint32 *)startKeyValue->Data) == SERVICE_BOOT_START)
{
LoadBootArguments();
}
FDfree(startKeyValue);
}
else
{
Dump("Read registry key value failure!\n");
}
VolumeClassFilterRegistered = IsVolumeClassFilterRegistered();
ReportBOOL("VolumeClassFilterRegistered", VolumeClassFilterRegistered);
for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; ++i)
{
FDDriverObject->MajorFunction[i] = FDDispatchQueueIRP;
}
FDDriverObject->DriverExtension->AddDevice = FileDiskAddDevice;
drvObject->DriverUnload = UnloadDriver;
return FDCreateRootDeviceObject(FDDriverObject);
}
In the code above, I had register a AddDevice routine named FileDiskAddDevice. Through the message output by DebugPrint, I look my driver can be loaded successfully by system. Next, I want to make IO manager call my AddDevice routine. But I don't know how to do it. My driver is just for a virtual device. No real device fits it. So I can't add device by unplug and plug again. I hope someone can be kind to tell me what I should do. Thank you! Smile | :)
Be regards!