diff --git a/reactos/drivers/filesystems/fastfat/fat.c b/reactos/drivers/filesystems/fastfat/fat.c index c0c74c75ac6..b745c2b6b7c 100644 --- a/reactos/drivers/filesystems/fastfat/fat.c +++ b/reactos/drivers/filesystems/fastfat/fat.c @@ -31,6 +31,7 @@ FAT32GetNextCluster( ULONG CurrentCluster, PULONG NextCluster) { + NTSTATUS Status = STATUS_SUCCESS; PVOID BaseAddress; ULONG FATOffset; ULONG ChunkSize; @@ -49,10 +50,16 @@ FAT32GetNextCluster( if (CurrentCluster >= 0xffffff8 && CurrentCluster <= 0xfffffff) CurrentCluster = 0xffffffff; - ASSERT(CurrentCluster != 0); + if (CurrentCluster == 0) + { + DPRINT1("WARNING: File system corruption detected. You may need to run a disk repair utility.\n"); + Status = STATUS_FILE_CORRUPT_ERROR; + if (VfatGlobalData->Flags & VFAT_BREAK_ON_CORRUPTION) + ASSERT(CurrentCluster != 0); + } CcUnpinData(Context); *NextCluster = CurrentCluster; - return STATUS_SUCCESS; + return Status; } /* @@ -64,6 +71,7 @@ FAT16GetNextCluster( ULONG CurrentCluster, PULONG NextCluster) { + NTSTATUS Status = STATUS_SUCCESS; PVOID BaseAddress; ULONG FATOffset; ULONG ChunkSize; @@ -81,10 +89,18 @@ FAT16GetNextCluster( CurrentCluster = *((PUSHORT)((char*)BaseAddress + (FATOffset % ChunkSize))); if (CurrentCluster >= 0xfff8 && CurrentCluster <= 0xffff) CurrentCluster = 0xffffffff; - ASSERT(CurrentCluster != 0); + + if (CurrentCluster == 0) + { + DPRINT1("WARNING: File system corruption detected. You may need to run a disk repair utility.\n"); + Status = STATUS_FILE_CORRUPT_ERROR; + if (VfatGlobalData->Flags & VFAT_BREAK_ON_CORRUPTION) + ASSERT(CurrentCluster != 0); + } + CcUnpinData(Context); *NextCluster = CurrentCluster; - return STATUS_SUCCESS; + return Status; } /* @@ -671,8 +687,10 @@ GetNextCluster( if (CurrentCluster == 0) { - ASSERT(CurrentCluster != 0); - return STATUS_INVALID_PARAMETER; + DPRINT1("WARNING: File system corruption detected. You may need to run a disk repair utility.\n"); + if (VfatGlobalData->Flags & VFAT_BREAK_ON_CORRUPTION) + ASSERT(CurrentCluster != 0); + return STATUS_FILE_CORRUPT_ERROR; } ExAcquireResourceSharedLite(&DeviceExt->FatResource, TRUE); diff --git a/reactos/drivers/filesystems/fastfat/iface.c b/reactos/drivers/filesystems/fastfat/iface.c index 5ed678db212..8d564489efa 100644 --- a/reactos/drivers/filesystems/fastfat/iface.c +++ b/reactos/drivers/filesystems/fastfat/iface.c @@ -91,6 +91,9 @@ DriverEntry( RtlZeroMemory (VfatGlobalData, sizeof(VFAT_GLOBAL_DATA)); VfatGlobalData->DriverObject = DriverObject; VfatGlobalData->DeviceObject = DeviceObject; + /* Enable this to enter the debugger when file system corruption + * has been detected: + VfatGlobalData->Flags = VFAT_BREAK_ON_CORRUPTION; */ DeviceObject->Flags |= DO_DIRECT_IO; DriverObject->MajorFunction[IRP_MJ_CLOSE] = VfatBuildRequest; diff --git a/reactos/drivers/filesystems/fastfat/vfat.h b/reactos/drivers/filesystems/fastfat/vfat.h index a1e37aead97..fb516a9c6df 100644 --- a/reactos/drivers/filesystems/fastfat/vfat.h +++ b/reactos/drivers/filesystems/fastfat/vfat.h @@ -315,6 +315,8 @@ typedef struct DEVICE_EXTENSION PVPB SpareVPB; } DEVICE_EXTENSION, VCB, *PVCB; +#define VFAT_BREAK_ON_CORRUPTION 1 + typedef struct { PDRIVER_OBJECT DriverObject;