[FASTFAT]
authorPierre Schweitzer <pierre@reactos.org>
Sat, 11 Jun 2016 09:32:00 +0000 (09:32 +0000)
committerPierre Schweitzer <pierre@reactos.org>
Sat, 11 Jun 2016 09:32:00 +0000 (09:32 +0000)
Properly round up 64b values.
This fixes reads on 4GB+ volumes.

Patch by Wim Hueskes.

CORE-10932 #resolve #comment Thanks for the patch! Commited in r71610

svn path=/trunk/; revision=71610

reactos/drivers/filesystems/fastfat/fcb.c
reactos/drivers/filesystems/fastfat/finfo.c
reactos/drivers/filesystems/fastfat/fsctl.c
reactos/drivers/filesystems/fastfat/rw.c
reactos/drivers/filesystems/fastfat/vfat.h

index 7f75c74..62c4653 100644 (file)
@@ -668,7 +668,7 @@ vfatMakeFCBFromDirEntry(
     }
     rcFCB->RFCB.FileSize.QuadPart = Size;
     rcFCB->RFCB.ValidDataLength.QuadPart = Size;
-    rcFCB->RFCB.AllocationSize.QuadPart = ROUND_UP(Size, vcb->FatInfo.BytesPerCluster);
+    rcFCB->RFCB.AllocationSize.QuadPart = ROUND_UP_64(Size, vcb->FatInfo.BytesPerCluster);
     rcFCB->RefCount = 1;
     if (vfatFCBIsDirectory(rcFCB))
     {
index a7e6171..83e691c 100644 (file)
@@ -1114,7 +1114,7 @@ UpdateFileSize(
 {
     if (Size > 0)
     {
-        Fcb->RFCB.AllocationSize.QuadPart = ROUND_UP(Size, ClusterSize);
+        Fcb->RFCB.AllocationSize.QuadPart = ROUND_UP_64(Size, ClusterSize);
     }
     else
     {
index 873b0fc..cf1e22a 100644 (file)
@@ -576,7 +576,7 @@ VfatMount(
     }
 
     VolumeFcb->Flags = FCB_IS_VOLUME;
-    VolumeFcb->RFCB.FileSize.QuadPart = DeviceExt->FatInfo.Sectors * DeviceExt->FatInfo.BytesPerSector;
+    VolumeFcb->RFCB.FileSize.QuadPart = (LONGLONG) DeviceExt->FatInfo.Sectors * DeviceExt->FatInfo.BytesPerSector;
     VolumeFcb->RFCB.ValidDataLength = VolumeFcb->RFCB.FileSize;
     VolumeFcb->RFCB.AllocationSize = VolumeFcb->RFCB.FileSize;
     DeviceExt->VolumeFcb = VolumeFcb;
index b9fea99..8dbad17 100644 (file)
@@ -150,7 +150,7 @@ VfatReadFileData(
     BytesPerSector = DeviceExt->FatInfo.BytesPerSector;
     BytesPerCluster = DeviceExt->FatInfo.BytesPerCluster;
 
-    ASSERT(ReadOffset.QuadPart + Length <= ROUND_UP(Fcb->RFCB.FileSize.QuadPart, BytesPerSector));
+    ASSERT(ReadOffset.QuadPart + Length <= ROUND_UP_64(Fcb->RFCB.FileSize.QuadPart, BytesPerSector));
     ASSERT(ReadOffset.u.LowPart % BytesPerSector == 0);
     ASSERT(Length % BytesPerSector == 0);
 
@@ -711,9 +711,9 @@ VfatRead(
     else
     {
         // non cached read
-        if (ByteOffset.QuadPart + Length > ROUND_UP(Fcb->RFCB.FileSize.QuadPart, BytesPerSector))
+        if (ByteOffset.QuadPart + Length > ROUND_UP_64(Fcb->RFCB.FileSize.QuadPart, BytesPerSector))
         {
-            Length = (ULONG)(ROUND_UP(Fcb->RFCB.FileSize.QuadPart, BytesPerSector) - ByteOffset.QuadPart);
+            Length = (ULONG)(ROUND_UP_64(Fcb->RFCB.FileSize.QuadPart, BytesPerSector) - ByteOffset.QuadPart);
         }
 
         Status = VfatReadFileData(IrpContext, Length, ByteOffset, &ReturnedLength);
index 941f9d7..f077eac 100644 (file)
 #define ROUND_UP(n, align) \
     ROUND_DOWN(((ULONG)n) + (align) - 1, (align))
 
+#define ROUND_DOWN_64(n, align) \
+    (((ULONGLONG)n) & ~((align) - 1LL))
+
+#define ROUND_UP_64(n, align) \
+    ROUND_DOWN_64(((ULONGLONG)n) + (align) - 1LL, (align))
+
 #include <pshpack1.h>
 struct _BootSector
 {