diff --git a/reactos/drivers/filesystems/fastfat/cleanup.c b/reactos/drivers/filesystems/fastfat/cleanup.c index 69e32810e4b..1f3bdcdc62c 100644 --- a/reactos/drivers/filesystems/fastfat/cleanup.c +++ b/reactos/drivers/filesystems/fastfat/cleanup.c @@ -66,7 +66,7 @@ VfatCleanupFile( pFcb->OpenHandleCount--; DeviceExt->OpenHandleCount--; - if (!(*pFcb->Attributes & FILE_ATTRIBUTE_DIRECTORY) && + if (!vfatFCBIsDirectory(pFcb) && FsRtlAreThereCurrentFileLocks(&pFcb->FileLock)) { /* remove all locks this process have on this file */ @@ -84,18 +84,26 @@ VfatCleanupFile( if (pFcb->Flags & FCB_DELETE_PENDING && pFcb->OpenHandleCount == 0) { - PFILE_OBJECT tmpFileObject; - tmpFileObject = pFcb->FileObject; - if (tmpFileObject != NULL) + if (vfatFCBIsDirectory(pFcb) && + !VfatIsDirectoryEmpty(pFcb)) { - pFcb->FileObject = NULL; - CcUninitializeCacheMap(tmpFileObject, NULL, NULL); - ObDereferenceObject(tmpFileObject); + pFcb->Flags &= ~FCB_DELETE_PENDING; } + else + { + PFILE_OBJECT tmpFileObject; + tmpFileObject = pFcb->FileObject; + if (tmpFileObject != NULL) + { + pFcb->FileObject = NULL; + CcUninitializeCacheMap(tmpFileObject, NULL, NULL); + ObDereferenceObject(tmpFileObject); + } - pFcb->RFCB.ValidDataLength.QuadPart = 0; - pFcb->RFCB.FileSize.QuadPart = 0; - pFcb->RFCB.AllocationSize.QuadPart = 0; + pFcb->RFCB.ValidDataLength.QuadPart = 0; + pFcb->RFCB.FileSize.QuadPart = 0; + pFcb->RFCB.AllocationSize.QuadPart = 0; + } } /* Uninitialize the cache (should be done even if caching was never initialized) */