- 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
This commit is contained in:
Pierre Schweitzer 2014-12-14 14:38:44 +00:00
parent c16d33beae
commit e4e3241286
3 changed files with 16 additions and 6 deletions

View file

@ -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;
}

View file

@ -62,6 +62,7 @@ typedef struct _NTFS_INFO
ULONG SectorsPerCluster;
ULONG BytesPerCluster;
ULONGLONG SectorCount;
ULONGLONG ClusterCount;
ULARGE_INTEGER MftStart;
ULARGE_INTEGER MftMirrStart;
ULONG BytesPerFileRecord;

View file

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