如何让IO管理器在我的驱动程序中调用我的AddDevice例程? [英] How to make IO Manager call my AddDevice routine in my driver?

查看:86
本文介绍了如何让IO管理器在我的驱动程序中调用我的AddDevice例程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我是司机开发的新人。我写了一个通过文件实现虚拟磁盘的驱动器。 DriverEntry例程如下:

 NTSTATUS DriverEntry(PDRIVER_OBJECT drvObject,PUNICODE_STRING usRegPath)
{
PKEY_VALUE_PARTIAL_INFORMATION startKeyValue;
ULONG版;
int i;

转储( DriverEntry DRIVER_NAME DRIVER_VERSION \ N);

memset(& OsVersion, 0 sizeof (RTL_OSVERSIONINFOW));
OsVersion.dwOSVersionInfoSize = sizeof (RTL_OSVERSIONINFOW);
RtlGetVersion(& OsVersion);
// 转储(RtlGetVersion:%d,%d \\\\ n,OsVersion。 dwMajorVersion,OsVersion.dwMinorVersion);
// 如果主驱动程序已经加载转储过滤器已加载
如果(NT_SUCCESS(FDDeviceIoControl(NT_ROOT_PREFIX,FD_IOCTL_GET_DRIVER_VERSION,NULL, 0 ,& version, sizeof (版本))))
return DumpFilterEntry((PFILTER_EXTENSION) drvObject,(PFILTER_INITIALIZATION_DATA)usRegPath);

FDDriverObject = drvObject;
memset(VirtualVolumeDeviceObjects, 0 sizeof (VirtualVolumeDeviceObjects));

if (NT_SUCCESS(FDReadRegistryKey(usRegPath,L 开始,& startKeyValue)))
{
if (startKeyValue-> Type = = REG_DWORD&& *((uint32 *)startKeyValue-> Data)== SERVICE_BOOT_START)
{
LoadBootArguments();
}
FDfree(startKeyValue);
}
else
{
转储( 读取注册表项值失败!\ 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);
}



在上面的代码中,我注册了一个名为FileDiskAddDevice的AddDevice例程。通过DebugPrint输出的消息,我看我的驱动程序可以被系统成功加载。接下来,我想让IO管理器调用我的AddDevice例程。但我不知道该怎么做。我的驱动程序仅用于虚拟设备。没有真正的设备适合它。所以我不能通过拔下插头再添加设备。我希望有人能够善意地告诉我应该做些什么。谢谢!微笑| :)



问候!

解决方案

请不要在多个论坛中发布相同的问题。

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);
	//Dump("RtlGetVersion:%d,%d\r\n", OsVersion.dwMajorVersion, OsVersion.dwMinorVersion);
	// Load dump filter if the main driver is already loaded
	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!

解决方案

Please do not post the same question in multiple forums.


这篇关于如何让IO管理器在我的驱动程序中调用我的AddDevice例程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆