Hello all,
I am newbie and manage to write one driver. i wrote one simple driver on
pseudo drive, who will write some data on its IRP and read from that IRP and
display the data.
Now can someone tell how to attach my filter driver to Filesystem driver (so
that when my driver is installed and if i write something on notepad and
save the file my driver IRP should read the data).
Also is it possible to format partition drive from filter driver.
The code goes something like this…
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject, PUNICODE_STRING
pRegistryPath)
{
NTSTATUS NtStatus = STATUS_SUCCESS;
UINT uiIndex = 0;
ULONG ulDeviceNumber = 0;
PDEVICE_OBJECT pDeviceObject = NULL, pFilteredDevice = NULL;
PEXAMPLE_DEVICE_CONTEXT pExampleDeviceContext = NULL;
PIO_STACK_LOCATION pIoStackIrp = NULL;
PDEVICE_OBJECT pPhysicalDeviceObject = NULL;
PFILE_OBJECT *pFileObject = NULL;
pDriverObject->MajorFunction[IRP_MJ_CREATE] =
FirstDriver_Create;
pDriverObject->MajorFunction[IRP_MJ_READ] =
FirstDriver_Read;
pDriverObject->MajorFunction[IRP_MJ_CLOSE] =
FirstDriver_Close;
pDriverObject->MajorFunction[IRP_MJ_WRITE] =
FirstDriver_Write;
NtStatus = CreateDevice(pDriverObject, ulDeviceNumber);
return NtStatus;
}
NTSTATUS CreateDevice (PDRIVER_OBJECT pDriverObject, ULONG
ulDeviceNumber )
{
NTSTATUS status;
PDEVICE_OBJECT pDevObj;
PDEVICE_EXTENSION pDeviceExtn;
UNICODE_STRING devName;
UNICODE_STRING symLinkName;
RtlInitUnicodeString(&devName, L"\Device\FILESYSTEM");
RtlInitUnicodeString(&symLinkName, L"\DosDevices\DCP");
status = IoCreateDevice( pDriverObject,
sizeof(DEVICE_EXTENSION),
&devName,
FILE_DEVICE_UNKNOWN,
0, FALSE,
&pDevObj );
if (!NT_SUCCESS(status))
{
DbgPrint(“CreateDevice: Unsuccessfull Attempt Sorry
… \r\n”);
return status;
}
pDevObj->Flags |= DO_BUFFERED_IO;
pDeviceExtn = (PDEVICE_EXTENSION)pDevObj->DeviceExtension;
pDeviceExtn->pDevice = pDevObj; // back pointer
pDeviceExtn->devName = devName;
pDeviceExtn->symLinkName = symLinkName;
pDeviceExtn->DeviceNumber = ulDeviceNumber;
pDeviceExtn->deviceBuffer = NULL;
pDeviceExtn->deviceBufferSize = 0;
status = IoCreateSymbolicLink( &symLinkName, &devName );
if (!NT_SUCCESS(status))
{
IoDeleteDevice( pDevObj );
return status;
}
return STATUS_SUCCESS;
}
If all here can flash light on some of these issues will be appreciable.