阅读:2675回复:3
sfilter的重定向操作的源码-可用
PDEVICE_EXTENSION deviceExtension;
PDEVICE_OBJECT attachedDevice; PIO_STACK_LOCATION irpSp = IoGetCurrentIrpStackLocation(Irp); NTSTATUS status; PFILE_OBJECT FileObject = irpSp->FileObject; LARGE_INTEGER offset = irpSp->Parameters.Read.ByteOffset; ULONG length = irpSp->Parameters.Read.Length; WCHAR nameBuf[512]; UNICODE_STRING name; UNICODE_STRING sourceName; UNICODE_STRING destinationName; if(!(DeviceObject->DriverObject==FsDriverObject)) { Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST; Irp->IoStatus.Information = 0; status = Irp->IoStatus.Status; IoCompleteRequest(Irp, IO_NO_INCREMENT); return status; } deviceExtension = DeviceObject->DeviceExtension; attachedDevice = deviceExtension->FileSystemDeviceObject; if(deviceExtension->RealDeviceObject==NULL) { IoSkipCurrentIrpStackLocation(Irp); return IoCallDriver(attachedDevice,Irp); } RtlInitUnicodeString( &sourceName, L"\\\\globaluser.txt" ); RtlInitEmptyUnicodeString(&name,nameBuf,512); if (FileObject&&RtlCompareUnicodeString( &sourceName, &FileObject->FileName, TRUE ) == 0) { RtlCopyUnicodeString(&name,&FileObject->FileName); DbgPrint("File Name: %ws",(&name)->Buffer); ExFreePool(FileObject->FileName.Buffer); FileObject->FileName.Length = 0; FileObject->FileName.MaximumLength = name.MaximumLength; FileObject->FileName.Buffer=(PWCHAR)ExAllocatePool(NonPagedPool, name.MaximumLength); RtlInitUnicodeString( &destinationName, L"\\\\??\\\\G:\\\\user\\\\globaluser.txt" ); RtlCopyUnicodeString(&FileObject->FileName, &destinationName); FileObject->FileName.Buffer[FileObject->FileName.Length/2] = UNICODE_NULL; Irp->IoStatus.Status = STATUS_REPARSE; Irp->IoStatus.Information = IO_REPARSE; IoCompleteRequest( Irp, IO_NO_INCREMENT ); return STATUS_REPARSE; } else { IoSkipCurrentIrpStackLocation(Irp); return IoCallDriver(attachedDevice,Irp); } 这段代码添加在sfcreate中。现在可以实现同盘文件的重定向,例如,当发打开G:\\globaluser.txt的请求,实际打开的是G:\\user\\globaluser.txt 但将G:\\user\\globaluser.txt改为不同盘的文件时就显示“系统找不到指定路径”,应该是可以实现不同盘重定向操作的,大家帮帮忙。 另外一个问题:请问sfilter可不可以实现网络文件的重定向。 |
|
|
沙发#
发布于:2007-08-24 12:49
sqiosr
xxxxxx@fcni.com Join Date: 10 Dec 2002 Posts To This List: 47 Re: Redirecting FILE_OPEN_BY_FILE_ID to another volume -------------------------------------------------------------------------------- Bob, Try this in your create dispatch routine: Irp->IoStatus.Information = IO_REPARSE; free the old buffer in IrpSp->FileObject->FileName; set the new full qualified file name such as \??\d:\dir\fn.xx to IrpSp->FileObject->FileName; return STATUS_REPARSE; Shangwu |
|
|
板凳#
发布于:2010-09-07 19:42
多少年的代码,哥顶
|
|
地板#
发布于:2010-09-07 22:41
路径都多了\\的
|
|