Hi all,
i used File System Filter driver example which belong's to "Sergey Podobry"
and i want to send some data from driver to my application using "DeviceIoControl".
Actually i got handle to the device object in right way ,but when i call "DeviceIoControl" i got blue screen .
Here what i have done.
NTSTATUS FsFilterDispatchControl(
__in PDEVICE_OBJECT DeviceObject,
__in PIRP Irp
)
{
PIO_STACK_LOCATION ioStack = IoGetCurrentIrpStackLocation(Irp);
ULONG operation;
NTSTATUS status=STATUS_SUCCESS;
if(DeviceObject==g_PDeviceObject)
{
operation = ioStack->Parameters.DeviceIoControl.IoControlCode;
switch (operation)
{
case IOCTL_OPEN_EVENT:
DbgPrint("IOCTL_OPEN_EVENT \n");
break;
default:
status=STATUS_INVALID_DEVICE_REQUEST;
break;
}
Irp->IoStatus.Status = status;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return status;
}
else
{
return FsFilterDispatchPassThrough(DeviceObject, Irp);
}
}
In user mode Application :
DeviceDriver = CreateFile(
\\\\.\\example,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL
);
if (DeviceDriver == INVALID_HANDLE_VALUE) {
printf("Unable to open handle to the device driver\n");
return 1;
}
if (!DeviceIoControl(DeviceDriver,
IOCTL_OPEN_EVENT,
NULL,0,
NULL,0 ,
&bytesReturned,
NULL)) {
printf("The driver failed to open the named event!\n");
return 1;
}
printf("you have successfully called the device !\n");
CloseHandle(DeviceDriver);
In Driver Entry :
RtlInitUnicodeString(&usDriverName, L"\\Device\\example");
RtlInitUnicodeString(&usDosDeviceName, L"\\DosDevices\\example");
NtStatus = IoCreateDevice (
DriverObject,
0,
&usDriverName,
FILE_DEVICE_UNKNOWN,
FILE_DEVICE_SECURE_OPEN,
FALSE,
&g_PDeviceObject
);
NtStatus=IoCreateSymbolicLink(&usDosDeviceName, &usDriverName);
if(!NT_SUCCESS(NtStatus))
{
return NtStatus;
}
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = FsFilterDispatchControl;
VOID FsFilterUnload(
__in PDRIVER_OBJECT DriverObject
)
{
UNICODE_STRING usDosDeviceName;
RtlInitUnicodeString(&usDosDeviceName, L"\\DosDevices\\example");
IoDeleteSymbolicLink(&usDosDeviceName);
IoDeleteDevice(g_PDeviceObject);
}
finally,what i posted is only the changes i have made on the file system filter driver .
please , help me i don't know why i got blue screen during calling "DeviceIoControl".