[FASTFAT] When extending a file, also lock the DirResource.
authorPierre Schweitzer <pierre@reactos.org>
Mon, 21 May 2018 08:28:44 +0000 (10:28 +0200)
committerPierre Schweitzer <pierre@reactos.org>
Mon, 21 May 2018 08:30:14 +0000 (10:30 +0200)
This avoids race conditions under high IOs and thus corruption on
the FS, or assertions failures in the kernel.
Easily triggered by building ReactOS on ReactOS ;-).

drivers/filesystems/fastfat/rw.c

index 76ffff9..ad65628 100644 (file)
@@ -1064,9 +1064,18 @@ VfatWrite(
         ByteOffset.u.LowPart + Length > Fcb->RFCB.FileSize.u.LowPart)
     {
         LARGE_INTEGER AllocationSize;
+
+        if (!ExAcquireResourceExclusiveLite(&IrpContext->DeviceExt->DirResource, CanWait))
+        {
+            goto ByeBye;
+        }
+
         AllocationSize.QuadPart = ByteOffset.u.LowPart + Length;
         Status = VfatSetAllocationSizeInformation(IrpContext->FileObject, Fcb,
                                                   IrpContext->DeviceExt, &AllocationSize);
+
+        ExReleaseResourceLite(&IrpContext->DeviceExt->DirResource);
+
         if (!NT_SUCCESS (Status))
         {
             goto ByeBye;