From e4e3241286c3bcec41c5e5368ec501e0cb237594 Mon Sep 17 00:00:00 2001 From: Pierre Schweitzer Date: Sun, 14 Dec 2014 14:38:44 +0000 Subject: [PATCH] [NTFS] - In the VCB, directly store the total number of clusters available in the volume, this will save a few recurrent divisions - Use this everywhere it is possible - Validate input in GetVolumeBitmap(): make sure we don't want bitmap beyond end of the volume CORE-8725 svn path=/trunk/; revision=65639 --- reactos/drivers/filesystems/ntfs/fsctl.c | 11 ++++++++++- reactos/drivers/filesystems/ntfs/ntfs.h | 1 + reactos/drivers/filesystems/ntfs/volinfo.c | 10 +++++----- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/reactos/drivers/filesystems/ntfs/fsctl.c b/reactos/drivers/filesystems/ntfs/fsctl.c index 5467af12e6a..63e6c62f89a 100644 --- a/reactos/drivers/filesystems/ntfs/fsctl.c +++ b/reactos/drivers/filesystems/ntfs/fsctl.c @@ -226,6 +226,7 @@ NtfsGetVolumeData(PDEVICE_OBJECT DeviceObject, NtfsInfo->SectorsPerCluster = BootSector->BPB.SectorsPerCluster; NtfsInfo->BytesPerCluster = BootSector->BPB.BytesPerSector * BootSector->BPB.SectorsPerCluster; NtfsInfo->SectorCount = BootSector->EBPB.SectorCount; + NtfsInfo->ClusterCount = DeviceExt->NtfsInfo.SectorCount / (ULONGLONG)DeviceExt->NtfsInfo.SectorsPerCluster; NtfsInfo->MftStart.QuadPart = BootSector->EBPB.MftLocation; NtfsInfo->MftMirrStart.QuadPart = BootSector->EBPB.MftMirrLocation; @@ -547,7 +548,7 @@ GetNfsVolumeData(PDEVICE_EXTENSION DeviceExt, DataBuffer->VolumeSerialNumber.QuadPart = DeviceExt->NtfsInfo.SerialNumber; DataBuffer->NumberSectors.QuadPart = DeviceExt->NtfsInfo.SectorCount; - DataBuffer->TotalClusters.QuadPart = DeviceExt->NtfsInfo.SectorCount / DeviceExt->NtfsInfo.SectorsPerCluster; + DataBuffer->TotalClusters.QuadPart = DeviceExt->NtfsInfo.ClusterCount; DataBuffer->FreeClusters.QuadPart = NtfsGetFreeClusters(DeviceExt); DataBuffer->TotalReserved.QuadPart = 0LL; // FIXME DataBuffer->BytesPerSector = DeviceExt->NtfsInfo.BytesPerSector; @@ -664,6 +665,7 @@ GetVolumeBitmap(PDEVICE_EXTENSION DeviceExt, NTSTATUS Status = STATUS_SUCCESS; PIO_STACK_LOCATION Stack; PVOLUME_BITMAP_BUFFER BitmapBuffer; + LONGLONG StartingLcn; DPRINT1("GetVolumeBitmap(%p, %p)\n", DeviceExt, Irp); @@ -713,6 +715,13 @@ GetVolumeBitmap(PDEVICE_EXTENSION DeviceExt, return Status; } + StartingLcn = ((PSTARTING_LCN_INPUT_BUFFER)Stack->Parameters.FileSystemControl.Type3InputBuffer)->StartingLcn.QuadPart; + if (StartingLcn > DeviceExt->NtfsInfo.ClusterCount) + { + DPRINT1("Requested bitmap start beyond partition end: %I64x %I64x\n", DeviceExt->NtfsInfo.ClusterCount, StartingLcn); + return STATUS_INVALID_PARAMETER; + } + UNIMPLEMENTED; return STATUS_NOT_IMPLEMENTED; } diff --git a/reactos/drivers/filesystems/ntfs/ntfs.h b/reactos/drivers/filesystems/ntfs/ntfs.h index 2c812b086dc..14963982f98 100644 --- a/reactos/drivers/filesystems/ntfs/ntfs.h +++ b/reactos/drivers/filesystems/ntfs/ntfs.h @@ -62,6 +62,7 @@ typedef struct _NTFS_INFO ULONG SectorsPerCluster; ULONG BytesPerCluster; ULONGLONG SectorCount; + ULONGLONG ClusterCount; ULARGE_INTEGER MftStart; ULARGE_INTEGER MftMirrStart; ULONG BytesPerFileRecord; diff --git a/reactos/drivers/filesystems/ntfs/volinfo.c b/reactos/drivers/filesystems/ntfs/volinfo.c index 794c39e8292..41823e10b40 100644 --- a/reactos/drivers/filesystems/ntfs/volinfo.c +++ b/reactos/drivers/filesystems/ntfs/volinfo.c @@ -70,7 +70,7 @@ NtfsGetFreeClusters(PDEVICE_EXTENSION DeviceExt) } BitmapDataSize = AttributeDataLength(&DataContext->Record); - ASSERT((BitmapDataSize * 8) >= (DeviceExt->NtfsInfo.SectorCount / DeviceExt->NtfsInfo.SectorsPerCluster)); + ASSERT((BitmapDataSize * 8) >= DeviceExt->NtfsInfo.ClusterCount); BitmapData = ExAllocatePoolWithTag(NonPagedPool, ROUND_UP(BitmapDataSize, DeviceExt->NtfsInfo.BytesPerSector), TAG_NTFS); if (BitmapData == NULL) { @@ -86,11 +86,11 @@ NtfsGetFreeClusters(PDEVICE_EXTENSION DeviceExt) } ReleaseAttributeContext(DataContext); - DPRINT1("Total clusters: %I64x\n", DeviceExt->NtfsInfo.SectorCount / DeviceExt->NtfsInfo.SectorsPerCluster); + DPRINT1("Total clusters: %I64x\n", DeviceExt->NtfsInfo.ClusterCount); DPRINT1("Total clusters in bitmap: %I64x\n", BitmapDataSize * 8); - DPRINT1("Diff in size: %I64d B\n", ((BitmapDataSize * 8) - (DeviceExt->NtfsInfo.SectorCount / DeviceExt->NtfsInfo.SectorsPerCluster)) * DeviceExt->NtfsInfo.SectorsPerCluster * DeviceExt->NtfsInfo.BytesPerSector); + DPRINT1("Diff in size: %I64d B\n", ((BitmapDataSize * 8) - DeviceExt->NtfsInfo.ClusterCount) * DeviceExt->NtfsInfo.SectorsPerCluster * DeviceExt->NtfsInfo.BytesPerSector); - RtlInitializeBitMap(&Bitmap, (PULONG)BitmapData, DeviceExt->NtfsInfo.SectorCount / DeviceExt->NtfsInfo.SectorsPerCluster); + RtlInitializeBitMap(&Bitmap, (PULONG)BitmapData, DeviceExt->NtfsInfo.ClusterCount); FreeClusters = RtlNumberOfClearBits(&Bitmap); ExFreePoolWithTag(BitmapData, TAG_NTFS); @@ -198,7 +198,7 @@ NtfsGetFsSizeInformation(PDEVICE_OBJECT DeviceObject, DeviceExt = DeviceObject->DeviceExtension; FsSizeInfo->AvailableAllocationUnits.QuadPart = NtfsGetFreeClusters(DeviceExt); - FsSizeInfo->TotalAllocationUnits.QuadPart = DeviceExt->NtfsInfo.SectorCount / DeviceExt->NtfsInfo.SectorsPerCluster; + FsSizeInfo->TotalAllocationUnits.QuadPart = DeviceExt->NtfsInfo.ClusterCount; FsSizeInfo->SectorsPerAllocationUnit = DeviceExt->NtfsInfo.SectorsPerCluster; FsSizeInfo->BytesPerSector = DeviceExt->NtfsInfo.BytesPerSector;