summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
f133d01)
This allows us having more accurate statistics regarding available clusters
count. Even though FastFAT and chkdsk still don't agree!
CORE-3877
}
return STATUS_DISK_FULL;
}
}
return STATUS_DISK_FULL;
}
+
+ if (DeviceExt->FatInfo.FatType == FAT32)
+ {
+ FAT32UpdateFreeClustersCount(DeviceExt);
+ }
/* In case of moving, don't delete data */
if (MoveContext == NULL)
{
/* In case of moving, don't delete data */
if (MoveContext == NULL)
{
- ULONG ClusterCount = 0;
-
while (CurrentCluster && CurrentCluster != 0xffffffff)
{
GetNextCluster(DeviceExt, CurrentCluster, &NextCluster);
/* FIXME: check status */
WriteCluster(DeviceExt, CurrentCluster, 0);
CurrentCluster = NextCluster;
while (CurrentCluster && CurrentCluster != 0xffffffff)
{
GetNextCluster(DeviceExt, CurrentCluster, &NextCluster);
/* FIXME: check status */
WriteCluster(DeviceExt, CurrentCluster, 0);
CurrentCluster = NextCluster;
- if (ClusterCount != 0 && DeviceExt->FatInfo.FatType == FAT32)
+ if (DeviceExt->FatInfo.FatType == FAT32)
- FAT32UpdateFreeClustersCount(DeviceExt, ClusterCount, TRUE);
+ FAT32UpdateFreeClustersCount(DeviceExt);
else
Status = FAT32CountAvailableClusters(DeviceExt);
}
else
Status = FAT32CountAvailableClusters(DeviceExt);
}
- Clusters->QuadPart = DeviceExt->AvailableClusters;
+ if (Clusters != NULL)
+ {
+ Clusters->QuadPart = DeviceExt->AvailableClusters;
+ }
ExReleaseResourceLite (&DeviceExt->FatResource);
return Status;
ExReleaseResourceLite (&DeviceExt->FatResource);
return Status;
NTSTATUS
FAT32UpdateFreeClustersCount(
NTSTATUS
FAT32UpdateFreeClustersCount(
- PDEVICE_EXTENSION DeviceExt,
- ULONG Count,
- BOOLEAN Freed)
+ PDEVICE_EXTENSION DeviceExt)
{
LARGE_INTEGER Offset;
ULONG Length;
{
LARGE_INTEGER Offset;
ULONG Length;
#endif
struct _FsInfoSector * Sector;
#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;
/* 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 */
}
/* 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 */
#ifndef VOLUME_IS_NOT_CACHED_WORK_AROUND_IT
/* Mark FSINFO sector dirty so that it gets written to the disk */
}
else if (NewSize + ClusterSize <= Fcb->RFCB.AllocationSize.u.LowPart)
{
}
else if (NewSize + ClusterSize <= Fcb->RFCB.AllocationSize.u.LowPart)
{
DPRINT("Check for the ability to set file size\n");
if (!MmCanFileBeTruncated(FileObject->SectionObjectPointer,
(PLARGE_INTEGER)AllocationSize))
DPRINT("Check for the ability to set file size\n");
if (!MmCanFileBeTruncated(FileObject->SectionObjectPointer,
(PLARGE_INTEGER)AllocationSize))
Status = STATUS_SUCCESS;
}
Status = STATUS_SUCCESS;
}
while (NT_SUCCESS(Status) && 0xffffffff != Cluster && Cluster > 1)
{
Status = NextCluster(DeviceExt, FirstCluster, &NCluster, FALSE);
WriteCluster(DeviceExt, Cluster, 0);
Cluster = NCluster;
while (NT_SUCCESS(Status) && 0xffffffff != Cluster && Cluster > 1)
{
Status = NextCluster(DeviceExt, FirstCluster, &NCluster, FALSE);
WriteCluster(DeviceExt, Cluster, 0);
Cluster = NCluster;
- if (ClusterCount != 0 && DeviceExt->FatInfo.FatType == FAT32)
+ if (DeviceExt->FatInfo.FatType == FAT32)
- FAT32UpdateFreeClustersCount(DeviceExt, ClusterCount, TRUE);
+ FAT32UpdateFreeClustersCount(DeviceExt);
_SEH2_END;
DeviceExt->LastAvailableCluster = 2;
_SEH2_END;
DeviceExt->LastAvailableCluster = 2;
+ CountAvailableClusters(DeviceExt, NULL);
ExInitializeResourceLite(&DeviceExt->FatResource);
InitializeListHead(&DeviceExt->FcbListHead);
ExInitializeResourceLite(&DeviceExt->FatResource);
InitializeListHead(&DeviceExt->FcbListHead);
- if (NT_SUCCESS(Status) && ClusterCount != 0 && DeviceExt->FatInfo.FatType == FAT32)
- {
- FAT32UpdateFreeClustersCount(DeviceExt, ClusterCount, FALSE);
- }
-
NTSTATUS
FAT32UpdateFreeClustersCount(
NTSTATUS
FAT32UpdateFreeClustersCount(
- PDEVICE_EXTENSION DeviceExt,
- ULONG Count,
- BOOLEAN Freed);
+ PDEVICE_EXTENSION DeviceExt);