21,600
社区成员
发帖
与我相关
我的任务
分享
NTSTATUS
SfCreate (
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
{
PIO_STACK_LOCATION IrpSp;
PUNICODE_STRING FileName;
PVOID FileNameBuffer;
UNICODE_STRING NewFileName;
BOOLEAN bRedirectFileOpen = FALSE;
//
// If the device being opened is the primary device object instead of a
// filter device object, just indicate that the operation worked.
//
if (DeviceObject == FsDeviceObject)
{
//
// Allow users to open the device that represents our driver.
//
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = FILE_OPENED;
IoCompleteRequest( Irp, IO_NO_INCREMENT );
return STATUS_SUCCESS;
}
IrpSp = IoGetCurrentIrpStackLocation(Irp);
//
// At this point, you must determine whether you want to redirect
// the file open/create for this particular file.
// Beware that the file name from the FILE_OBJECT in the current
// IRP stack location is not always the file name with the full
// path, nor the long file name or even a name. The way the file is
// opened (with full path, relatively to another file, with short
// or long file name, by ID, ...) affects this name.
//
// TODO: Put your code here to check whether you have to redirect the operation.
// If so, set bRedirectFileOpen to TRUE and initialize the NewFileName
// UNICODE_STRING to the full file name of the destination file.
//
if ( bRedirectFileOpen )
{
FileName = &(IrpSp->FileObject->FileName);
FileNameBuffer = ExAllocatePool( NonPagedPool, NewFileName.MaximumLength );
if (!FileNameBuffer)
{
//
// Not enough resources. Complete the IRP with the appropriate status.
//
Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
Irp->IoStatus.Information = 0;
IoCompleteRequest( Irp, IO_NO_INCREMENT );
return STATUS_INSUFFICIENT_RESOURCES;
}
ExFreePool( FileName->Buffer );
FileName->Buffer = FileNameBuffer;
FileName->MaximumLength = NewFileName.MaximumLength;
RtlCopyUnicodeString( FileName, &NewFileName );
//
// Instruct the IO Manager to reparse this file.
//
Irp->IoStatus.Status = STATUS_REPARSE;
Irp->IoStatus.Information = IO_REPARSE;
IoCompleteRequest( Irp, IO_NO_INCREMENT );
return STATUS_REPARSE;
}
else
{
//
// Pass the request "as is" down the device stack.
//
//
// The next driver will get the IO_STACK_LOCATION
// that you received.
//
IoSkipCurrentIrpStackLocation( Irp );
//
// Call the appropriate file system driver with the request.
//
// TODO: Replace AttachedToDeviceObject by the device
// object pointer your device object is attached to (the
// lower device object in the stack).
// Typically, this device object pointer is saved by your
// filter in your device extension.
//
return IoCallDriver( AttachedToDeviceObject, Irp );
}
}