Author: pschweitzer Date: Sun Dec 14 14:38:44 2014 New Revision: 65639
URL: http://svn.reactos.org/svn/reactos?rev=65639&view=rev Log: [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
Modified: trunk/reactos/drivers/filesystems/ntfs/fsctl.c trunk/reactos/drivers/filesystems/ntfs/ntfs.h trunk/reactos/drivers/filesystems/ntfs/volinfo.c
Modified: trunk/reactos/drivers/filesystems/ntfs/fsctl.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/ntfs/fs... ============================================================================== --- trunk/reactos/drivers/filesystems/ntfs/fsctl.c [iso-8859-1] (original) +++ trunk/reactos/drivers/filesystems/ntfs/fsctl.c [iso-8859-1] Sun Dec 14 14:38:44 2014 @@ -226,6 +226,7 @@ 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 @@
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 @@ 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 @@ 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; }
Modified: trunk/reactos/drivers/filesystems/ntfs/ntfs.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/ntfs/nt... ============================================================================== --- trunk/reactos/drivers/filesystems/ntfs/ntfs.h [iso-8859-1] (original) +++ trunk/reactos/drivers/filesystems/ntfs/ntfs.h [iso-8859-1] Sun Dec 14 14:38:44 2014 @@ -62,6 +62,7 @@ ULONG SectorsPerCluster; ULONG BytesPerCluster; ULONGLONG SectorCount; + ULONGLONG ClusterCount; ULARGE_INTEGER MftStart; ULARGE_INTEGER MftMirrStart; ULONG BytesPerFileRecord;
Modified: trunk/reactos/drivers/filesystems/ntfs/volinfo.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/ntfs/vo... ============================================================================== --- trunk/reactos/drivers/filesystems/ntfs/volinfo.c [iso-8859-1] (original) +++ trunk/reactos/drivers/filesystems/ntfs/volinfo.c [iso-8859-1] Sun Dec 14 14:38:44 2014 @@ -70,7 +70,7 @@ }
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 @@ } 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); - - RtlInitializeBitMap(&Bitmap, (PULONG)BitmapData, DeviceExt->NtfsInfo.SectorCount / DeviceExt->NtfsInfo.SectorsPerCluster); + DPRINT1("Diff in size: %I64d B\n", ((BitmapDataSize * 8) - DeviceExt->NtfsInfo.ClusterCount) * DeviceExt->NtfsInfo.SectorsPerCluster * DeviceExt->NtfsInfo.BytesPerSector); + + RtlInitializeBitMap(&Bitmap, (PULONG)BitmapData, DeviceExt->NtfsInfo.ClusterCount); FreeClusters = RtlNumberOfClearBits(&Bitmap);
ExFreePoolWithTag(BitmapData, TAG_NTFS); @@ -198,7 +198,7 @@ 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;