mirror of
				https://github.com/winfsp/winfsp.git
				synced 2025-10-30 19:48:38 -05:00 
			
		
		
		
	sys: FspFsvolReadCached, FspFsvolWriteCached: cleanup improvements
This commit is contained in:
		| @@ -139,6 +139,10 @@ static NTSTATUS FspFsvolReadCached( | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /* | ||||||
|  |      * From this point forward we must jump to the CLEANUP label on failure. | ||||||
|  |      */ | ||||||
|  |  | ||||||
|     /* are we using the copy or MDL interface? */ |     /* are we using the copy or MDL interface? */ | ||||||
|     if (!FlagOn(IrpSp->MinorFunction, IRP_MN_MDL)) |     if (!FlagOn(IrpSp->MinorFunction, IRP_MN_MDL)) | ||||||
|     { |     { | ||||||
| @@ -148,22 +152,14 @@ static NTSTATUS FspFsvolReadCached( | |||||||
|             Irp->UserBuffer : MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority); |             Irp->UserBuffer : MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority); | ||||||
|         if (0 == Buffer) |         if (0 == Buffer) | ||||||
|         { |         { | ||||||
|             FspFileNodeRelease(FileNode, Main); |             Result = STATUS_INSUFFICIENT_RESOURCES; | ||||||
|             return STATUS_INSUFFICIENT_RESOURCES; |             goto cleanup; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         Result = FspCcCopyRead(FileObject, &ReadOffset, ReadLength, CanWait, Buffer, |         Result = FspCcCopyRead(FileObject, &ReadOffset, ReadLength, CanWait, Buffer, | ||||||
|             &Irp->IoStatus); |             &Irp->IoStatus); | ||||||
|         if (!NT_SUCCESS(Result)) |         if (!NT_SUCCESS(Result) || STATUS_PENDING == Result) | ||||||
|         { |             goto cleanup; | ||||||
|             FspFileNodeRelease(FileNode, Main); |  | ||||||
|             return Result; |  | ||||||
|         } |  | ||||||
|         if (STATUS_PENDING == Result) |  | ||||||
|         { |  | ||||||
|             FspFileNodeRelease(FileNode, Main); |  | ||||||
|             return FspWqRepostIrpWorkItem(Irp, FspFsvolReadCached, 0); |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
|     else |     else | ||||||
|     { |     { | ||||||
| @@ -172,10 +168,8 @@ static NTSTATUS FspFsvolReadCached( | |||||||
|         Result = FspCcMdlRead(FileObject, &ReadOffset, ReadLength, &Irp->MdlAddress, |         Result = FspCcMdlRead(FileObject, &ReadOffset, ReadLength, &Irp->MdlAddress, | ||||||
|             &Irp->IoStatus); |             &Irp->IoStatus); | ||||||
|         if (!NT_SUCCESS(Result)) |         if (!NT_SUCCESS(Result)) | ||||||
|         { |             goto cleanup; | ||||||
|             FspFileNodeRelease(FileNode, Main); |         ASSERT(STATUS_PENDING != Result); | ||||||
|             return Result; |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /* update the current file offset if synchronous I/O */ |     /* update the current file offset if synchronous I/O */ | ||||||
| @@ -185,6 +179,14 @@ static NTSTATUS FspFsvolReadCached( | |||||||
|     FspFileNodeRelease(FileNode, Main); |     FspFileNodeRelease(FileNode, Main); | ||||||
|  |  | ||||||
|     return STATUS_SUCCESS; |     return STATUS_SUCCESS; | ||||||
|  |  | ||||||
|  | cleanup: | ||||||
|  |     FspFileNodeRelease(FileNode, Main); | ||||||
|  |  | ||||||
|  |     if (STATUS_PENDING == Result) | ||||||
|  |         return FspWqRepostIrpWorkItem(Irp, FspFsvolReadCached, 0); | ||||||
|  |  | ||||||
|  |     return Result; | ||||||
| } | } | ||||||
|  |  | ||||||
| static NTSTATUS FspFsvolReadNonCached( | static NTSTATUS FspFsvolReadNonCached( | ||||||
|   | |||||||
| @@ -106,6 +106,7 @@ static NTSTATUS FspFsvolWriteCached( | |||||||
|     BOOLEAN SynchronousIo = BooleanFlagOn(FileObject->Flags, FO_SYNCHRONOUS_IO); |     BOOLEAN SynchronousIo = BooleanFlagOn(FileObject->Flags, FO_SYNCHRONOUS_IO); | ||||||
|     FSP_FSCTL_FILE_INFO FileInfo; |     FSP_FSCTL_FILE_INFO FileInfo; | ||||||
|     CC_FILE_SIZES FileSizes; |     CC_FILE_SIZES FileSizes; | ||||||
|  |     UINT64 OriginalFileSize; | ||||||
|     UINT64 WriteEndOffset; |     UINT64 WriteEndOffset; | ||||||
|     BOOLEAN ExtendingFile; |     BOOLEAN ExtendingFile; | ||||||
|     BOOLEAN Success; |     BOOLEAN Success; | ||||||
| @@ -136,6 +137,7 @@ static NTSTATUS FspFsvolWriteCached( | |||||||
|     ASSERT(FspTimeoutInfinity32 == |     ASSERT(FspTimeoutInfinity32 == | ||||||
|         FspFsvolDeviceExtension(FsvolDeviceObject)->VolumeParams.FileInfoTimeout); |         FspFsvolDeviceExtension(FsvolDeviceObject)->VolumeParams.FileInfoTimeout); | ||||||
|     FspFileNodeGetFileInfo(FileNode, &FileInfo); |     FspFileNodeGetFileInfo(FileNode, &FileInfo); | ||||||
|  |     OriginalFileSize = FileInfo.FileSize; | ||||||
|     WriteEndOffset = WriteToEndOfFile ? |     WriteEndOffset = WriteToEndOfFile ? | ||||||
|         FileInfo.FileSize + WriteLength : WriteOffset.QuadPart + WriteLength; |         FileInfo.FileSize + WriteLength : WriteOffset.QuadPart + WriteLength; | ||||||
|     ExtendingFile = FileInfo.FileSize < WriteEndOffset; |     ExtendingFile = FileInfo.FileSize < WriteEndOffset; | ||||||
| @@ -183,6 +185,10 @@ static NTSTATUS FspFsvolWriteCached( | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /* | ||||||
|  |      * From this point forward we must jump to the CLEANUP label on failure. | ||||||
|  |      */ | ||||||
|  |  | ||||||
|     /* are we using the copy or MDL interface? */ |     /* are we using the copy or MDL interface? */ | ||||||
|     if (!FlagOn(IrpSp->MinorFunction, IRP_MN_MDL)) |     if (!FlagOn(IrpSp->MinorFunction, IRP_MN_MDL)) | ||||||
|     { |     { | ||||||
| @@ -192,21 +198,13 @@ static NTSTATUS FspFsvolWriteCached( | |||||||
|             Irp->UserBuffer : MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority); |             Irp->UserBuffer : MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority); | ||||||
|         if (0 == Buffer) |         if (0 == Buffer) | ||||||
|         { |         { | ||||||
|             FspFileNodeRelease(FileNode, Main); |             Result = STATUS_INSUFFICIENT_RESOURCES; | ||||||
|             return STATUS_INSUFFICIENT_RESOURCES; |             goto cleanup; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         Result = FspCcCopyWrite(FileObject, &WriteOffset, WriteLength, CanWait, Buffer); |         Result = FspCcCopyWrite(FileObject, &WriteOffset, WriteLength, CanWait, Buffer); | ||||||
|         if (!NT_SUCCESS(Result)) |         if (!NT_SUCCESS(Result) || STATUS_PENDING == Result) | ||||||
|         { |             goto cleanup; | ||||||
|             FspFileNodeRelease(FileNode, Main); |  | ||||||
|             return Result; |  | ||||||
|         } |  | ||||||
|         if (STATUS_PENDING == Result) |  | ||||||
|         { |  | ||||||
|             FspFileNodeRelease(FileNode, Main); |  | ||||||
|             return FspWqRepostIrpWorkItem(Irp, FspFsvolWriteCached, 0); |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         Irp->IoStatus.Information = WriteLength; |         Irp->IoStatus.Information = WriteLength; | ||||||
|     } |     } | ||||||
| @@ -217,10 +215,8 @@ static NTSTATUS FspFsvolWriteCached( | |||||||
|         Result = FspCcPrepareMdlWrite(FileObject, &WriteOffset, WriteLength, &Irp->MdlAddress, |         Result = FspCcPrepareMdlWrite(FileObject, &WriteOffset, WriteLength, &Irp->MdlAddress, | ||||||
|             &Irp->IoStatus); |             &Irp->IoStatus); | ||||||
|         if (!NT_SUCCESS(Result)) |         if (!NT_SUCCESS(Result)) | ||||||
|         { |             goto cleanup; | ||||||
|             FspFileNodeRelease(FileNode, Main); |         ASSERT(STATUS_PENDING != Result); | ||||||
|             return Result; |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /* update the current file offset if synchronous I/O */ |     /* update the current file offset if synchronous I/O */ | ||||||
| @@ -233,6 +229,16 @@ static NTSTATUS FspFsvolWriteCached( | |||||||
|     FspFileNodeRelease(FileNode, Main); |     FspFileNodeRelease(FileNode, Main); | ||||||
|  |  | ||||||
|     return STATUS_SUCCESS; |     return STATUS_SUCCESS; | ||||||
|  |  | ||||||
|  | cleanup: | ||||||
|  |     CcGetFileSizePointer(FileObject)->QuadPart = OriginalFileSize; | ||||||
|  |  | ||||||
|  |     FspFileNodeRelease(FileNode, Main); | ||||||
|  |  | ||||||
|  |     if (STATUS_PENDING == Result) | ||||||
|  |         return FspWqRepostIrpWorkItem(Irp, FspFsvolWriteCached, 0); | ||||||
|  |  | ||||||
|  |     return Result; | ||||||
| } | } | ||||||
|  |  | ||||||
| static VOID FspFsvolWriteCachedDeferred(PVOID Context1, PVOID Context2) | static VOID FspFsvolWriteCachedDeferred(PVOID Context1, PVOID Context2) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user