[FASTFAT]

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
This commit is contained in:
Pierre Schweitzer 2016-06-11 09:32:00 +00:00
parent a44dfe6c76
commit 4746de9066
5 changed files with 12 additions and 6 deletions

View 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))
{

View 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
{

View 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;

View 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);

View file

@ -25,6 +25,12 @@
#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
{