From 83aa54b4abb99f01fac329838bc64e62f0babe0e Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Sat, 11 Jul 2026 14:05:26 +0300 Subject: [PATCH] sys: FspFsvolWriteCached: move CcCanIWrite outside the locks This eliminates the deadlock described in PR #677 while at the same time ensuring that CcDeferWrite is called after the file's cache map has been initialized. --- src/sys/write.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/sys/write.c b/src/sys/write.c index 2ebe5074..e78fab70 100644 --- a/src/sys/write.c +++ b/src/sys/write.c @@ -247,8 +247,13 @@ static NTSTATUS FspFsvolWriteCached( FILE_END_OF_FILE_INFORMATION EndOfFileInformation; UINT64 WriteEndOffset; BOOLEAN ExtendingFile; + BOOLEAN DeferWrite; BOOLEAN Success; + /* should we defer the write? */ + Success = DEBUGTEST(90) && CcCanIWrite(FileObject, WriteLength, CanWait, Retrying); + DeferWrite = !Success; + /* try to acquire the FileNode Main exclusive */ Success = DEBUGTEST(90) && FspFileNodeTryAcquireExclusiveF(FileNode, FspFileNodeAcquireMain, CanWait); @@ -306,8 +311,7 @@ static NTSTATUS FspFsvolWriteCached( } /* should we defer the write? */ - Success = DEBUGTEST(90) && CcCanIWrite(FileObject, WriteLength, CanWait, Retrying); - if (!Success) + if (DeferWrite) { Result = FspWqCreateIrpWorkItem(Irp, FspFsvolWriteCached, 0); if (NT_SUCCESS(Result))