else
Status = FAT32CountAvailableClusters(DeviceExt);
}
- Clusters->QuadPart = DeviceExt->AvailableClusters;
+ if (Clusters != NULL)
+ {
+ Clusters->QuadPart = DeviceExt->AvailableClusters;
+ }
ExReleaseResourceLite (&DeviceExt->FatResource);
return Status;
NTSTATUS
FAT32UpdateFreeClustersCount(
- PDEVICE_EXTENSION DeviceExt,
- ULONG Count,
- BOOLEAN Freed)
+ PDEVICE_EXTENSION DeviceExt)
{
LARGE_INTEGER Offset;
ULONG Length;
#endif
struct _FsInfoSector * Sector;
+ if (!DeviceExt->AvailableClustersValid)
+ {
+ return STATUS_INVALID_PARAMETER;
+ }
+
/* We'll read (and then write) the fsinfo sector */
Offset.QuadPart = DeviceExt->FatInfo.FSInfoSector * DeviceExt->FatInfo.BytesPerSector;
Length = DeviceExt->FatInfo.BytesPerSector;
}
/* Update the free clusters count */
- if (Freed)
- {
- Sector->FreeCluster += Count;
- }
- else
- {
- Sector->FreeCluster -= Count;
- }
+ Sector->FreeCluster = InterlockedCompareExchange((PLONG)&DeviceExt->AvailableClusters, 0, 0);
#ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
/* Mark FSINFO sector dirty so that it gets written to the disk */