Added some error checks.

svn path=/trunk/; revision=1968
This commit is contained in:
Eric Kohl 2001-06-14 10:02:59 +00:00
parent d8f25b3cb8
commit e180745ffa
3 changed files with 112 additions and 75 deletions

View file

@ -1,5 +1,5 @@
/* /*
* $Id: fat.c,v 1.25 2001/05/04 01:21:45 rex Exp $ * $Id: fat.c,v 1.26 2001/06/14 10:02:59 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -362,8 +362,9 @@ FAT32FindAvailableCluster (PDEVICE_EXTENSION DeviceExt, PULONG Cluster)
} }
ULONG NTSTATUS
FAT12CountAvailableClusters (PDEVICE_EXTENSION DeviceExt) FAT12CountAvailableClusters(PDEVICE_EXTENSION DeviceExt,
PLARGE_INTEGER Clusters)
/* /*
* FUNCTION: Counts free cluster in a FAT12 table * FUNCTION: Counts free cluster in a FAT12 table
*/ */
@ -388,7 +389,7 @@ FAT12CountAvailableClusters (PDEVICE_EXTENSION DeviceExt)
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
ExReleaseResourceLite (&DeviceExt->FatResource); ExReleaseResourceLite (&DeviceExt->FatResource);
return 0; // Will the caller understand NTSTATUS values? return(Status);
} }
if (!Valid) if (!Valid)
{ {
@ -399,8 +400,8 @@ FAT12CountAvailableClusters (PDEVICE_EXTENSION DeviceExt)
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
CcRosReleaseCacheSegment(DeviceExt->Fat12StorageBcb, CacheSeg, FALSE); CcRosReleaseCacheSegment(DeviceExt->Fat12StorageBcb, CacheSeg, FALSE);
ExReleaseResourceLite (&DeviceExt->FatResource); ExReleaseResourceLite (&DeviceExt->FatResource);
return 0; // Will the caller understand NTSTATUS values? return(Status);
} }
} }
CBlock = (PUCHAR)BaseAddress; CBlock = (PUCHAR)BaseAddress;
@ -426,12 +427,15 @@ FAT12CountAvailableClusters (PDEVICE_EXTENSION DeviceExt)
CcRosReleaseCacheSegment(DeviceExt->Fat12StorageBcb, CacheSeg, FALSE); CcRosReleaseCacheSegment(DeviceExt->Fat12StorageBcb, CacheSeg, FALSE);
ExReleaseResourceLite (&DeviceExt->FatResource); ExReleaseResourceLite (&DeviceExt->FatResource);
return ulCount; Clusters->QuadPart = ulCount;
return(STATUS_SUCCESS);
} }
#if 0 #if 0
ULONG NTSTATUS
FAT16CountAvailableClusters (PDEVICE_EXTENSION DeviceExt) FAT16CountAvailableClusters(PDEVICE_EXTENSION DeviceExt,
PLARGE_INTEGER Clusters)
/* /*
* FUNCTION: Counts free clusters in a FAT16 table * FUNCTION: Counts free clusters in a FAT16 table
*/ */
@ -451,12 +455,15 @@ FAT16CountAvailableClusters (PDEVICE_EXTENSION DeviceExt)
ExReleaseResourceLite (&DeviceExt->FatResource); ExReleaseResourceLite (&DeviceExt->FatResource);
return ulCount; Clusters->QuadPart = ulCount;
return(STATUS_SUCCESS);
} }
#endif #endif
ULONG NTSTATUS
FAT32CountAvailableClusters (PDEVICE_EXTENSION DeviceExt) FAT32CountAvailableClusters(PDEVICE_EXTENSION DeviceExt,
PLARGE_INTEGER Clusters)
/* /*
* FUNCTION: Counts free clusters in a FAT32 table * FUNCTION: Counts free clusters in a FAT32 table
*/ */
@ -466,6 +473,7 @@ FAT32CountAvailableClusters (PDEVICE_EXTENSION DeviceExt)
ULONG ulCount = 0; ULONG ulCount = 0;
ULONG i,forto; ULONG i,forto;
ULONG numberofclusters; ULONG numberofclusters;
NTSTATUS Status;
ExAcquireResourceSharedLite (&DeviceExt->FatResource, TRUE); ExAcquireResourceSharedLite (&DeviceExt->FatResource, TRUE);
@ -478,10 +486,15 @@ FAT32CountAvailableClusters (PDEVICE_EXTENSION DeviceExt)
sector < ((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32; sector < ((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32;
sector++) sector++)
{ {
/* FIXME: Check status */ Status = VfatReadSectors(DeviceExt->StorageDevice,
VfatReadSectors (DeviceExt->StorageDevice, (ULONG) (DeviceExt->FATStart + sector), 1,
(ULONG) (DeviceExt->FATStart + sector), 1, (UCHAR *) Block);
(UCHAR *) Block); if (!NT_SUCCESS(Status))
{
ExFreePool(Block);
ExReleaseResourceLite(&DeviceExt->FatResource);
return(Status);
}
if (sector==((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32-1) if (sector==((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32-1)
forto=numberofclusters; forto=numberofclusters;
@ -495,12 +508,16 @@ FAT32CountAvailableClusters (PDEVICE_EXTENSION DeviceExt)
} }
ExFreePool (Block); ExFreePool (Block);
ExReleaseResourceLite (&DeviceExt->FatResource); ExReleaseResourceLite (&DeviceExt->FatResource);
return ulCount;
Clusters->QuadPart = ulCount;
return(STATUS_SUCCESS);
} }
NTSTATUS NTSTATUS
FAT12WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite, FAT12WriteCluster(PDEVICE_EXTENSION DeviceExt,
ULONG NewValue) ULONG ClusterToWrite,
ULONG NewValue)
/* /*
* FUNCTION: Writes a cluster to the FAT12 physical and in-memory tables * FUNCTION: Writes a cluster to the FAT12 physical and in-memory tables
*/ */
@ -578,8 +595,9 @@ FAT12WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
} }
NTSTATUS NTSTATUS
FAT16WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite, FAT16WriteCluster(PDEVICE_EXTENSION DeviceExt,
ULONG NewValue) ULONG ClusterToWrite,
ULONG NewValue)
/* /*
* FUNCTION: Writes a cluster to the FAT16 physical and in-memory tables * FUNCTION: Writes a cluster to the FAT16 physical and in-memory tables
*/ */
@ -637,9 +655,10 @@ FAT16WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
return (STATUS_SUCCESS); return (STATUS_SUCCESS);
} }
VOID NTSTATUS
FAT32WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite, FAT32WriteCluster(PDEVICE_EXTENSION DeviceExt,
ULONG NewValue) ULONG ClusterToWrite,
ULONG NewValue)
/* /*
* FUNCTION: Writes a cluster to the FAT32 physical tables * FUNCTION: Writes a cluster to the FAT32 physical tables
*/ */
@ -672,11 +691,13 @@ FAT32WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
ExFreePool (Block); ExFreePool (Block);
#endif #endif
KeBugCheck(0); KeBugCheck(0);
return(STATUS_SUCCESS);
} }
NTSTATUS NTSTATUS
WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite, WriteCluster(PDEVICE_EXTENSION DeviceExt,
ULONG NewValue) ULONG ClusterToWrite,
ULONG NewValue)
/* /*
* FUNCTION: Write a changed FAT entry * FUNCTION: Write a changed FAT entry
*/ */
@ -689,8 +710,7 @@ WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
} }
else if (DeviceExt->FatType == FAT32) else if (DeviceExt->FatType == FAT32)
{ {
FAT32WriteCluster (DeviceExt, ClusterToWrite, NewValue); Status = FAT32WriteCluster (DeviceExt, ClusterToWrite, NewValue);
Status = STATUS_SUCCESS;
} }
else else
{ {
@ -711,10 +731,10 @@ ClusterToSector (PDEVICE_EXTENSION DeviceExt, unsigned long Cluster)
} }
NTSTATUS NTSTATUS
VfatRawReadCluster (PDEVICE_EXTENSION DeviceExt, VfatRawReadCluster(PDEVICE_EXTENSION DeviceExt,
ULONG FirstCluster, ULONG FirstCluster,
PVOID Buffer, PVOID Buffer,
ULONG Cluster) ULONG Cluster)
/* /*
* FUNCTION: Load a cluster from the physical device * FUNCTION: Load a cluster from the physical device
*/ */
@ -744,10 +764,10 @@ VfatRawReadCluster (PDEVICE_EXTENSION DeviceExt,
} }
NTSTATUS NTSTATUS
VfatRawWriteCluster (PDEVICE_EXTENSION DeviceExt, VfatRawWriteCluster(PDEVICE_EXTENSION DeviceExt,
ULONG FirstCluster, ULONG FirstCluster,
PVOID Buffer, PVOID Buffer,
ULONG Cluster) ULONG Cluster)
/* /*
* FUNCTION: Write a cluster to the physical device * FUNCTION: Write a cluster to the physical device
*/ */
@ -760,17 +780,20 @@ VfatRawWriteCluster (PDEVICE_EXTENSION DeviceExt,
if (FirstCluster == 1) if (FirstCluster == 1)
{ {
Status = VfatWriteSectors (DeviceExt->StorageDevice, Status = VfatWriteSectors(DeviceExt->StorageDevice,
Cluster, Cluster,
DeviceExt->Boot->SectorsPerCluster, Buffer); DeviceExt->Boot->SectorsPerCluster,
Buffer);
} }
else else
{ {
Sector = ClusterToSector (DeviceExt, Cluster); Sector = ClusterToSector(DeviceExt,
Cluster);
Status = VfatWriteSectors (DeviceExt->StorageDevice, Status = VfatWriteSectors(DeviceExt->StorageDevice,
Sector, DeviceExt->Boot->SectorsPerCluster, Sector,
Buffer); DeviceExt->Boot->SectorsPerCluster,
Buffer);
} }
return(Status); return(Status);
} }

View file

@ -1,4 +1,4 @@
/* $Id: vfat.h,v 1.30 2001/06/11 19:52:22 ekohl Exp $ */ /* $Id: vfat.h,v 1.31 2001/06/14 10:02:59 ekohl Exp $ */
#include <ddk/ntifs.h> #include <ddk/ntifs.h>
@ -249,41 +249,52 @@ BOOL vfatIsFileNameValid (PWCHAR pFileName);
/* /*
* functions from fat.c * functions from fat.c
*/ */
ULONG ULONG
ClusterToSector(PDEVICE_EXTENSION DeviceExt, ULONG Cluster); ClusterToSector(PDEVICE_EXTENSION DeviceExt,
ULONG Cluster);
NTSTATUS NTSTATUS
GetNextCluster(PDEVICE_EXTENSION DeviceExt, GetNextCluster(PDEVICE_EXTENSION DeviceExt,
ULONG CurrentCluster, ULONG CurrentCluster,
PULONG NextCluster, PULONG NextCluster,
BOOLEAN Extend); BOOLEAN Extend);
NTSTATUS NTSTATUS
GetNextSector (PDEVICE_EXTENSION DeviceExt, GetNextSector(PDEVICE_EXTENSION DeviceExt,
ULONG CurrentSector, ULONG CurrentSector,
PULONG NextSector, PULONG NextSector,
BOOLEAN Extend); BOOLEAN Extend);
NTSTATUS NTSTATUS
VfatRawReadCluster (PDEVICE_EXTENSION DeviceExt, VfatRawReadCluster(PDEVICE_EXTENSION DeviceExt,
ULONG FirstCluster,
PVOID Buffer,
ULONG Cluster);
NTSTATUS
VfatRawWriteCluster(PDEVICE_EXTENSION DeviceExt,
ULONG FirstCluster, ULONG FirstCluster,
PVOID Buffer, PVOID Buffer,
ULONG Cluster); ULONG Cluster);
ULONG
FAT12CountAvailableClusters(PDEVICE_EXTENSION DeviceExt);
ULONG
FAT16CountAvailableClusters(PDEVICE_EXTENSION DeviceExt);
ULONG
FAT32CountAvailableClusters(PDEVICE_EXTENSION DeviceExt);
NTSTATUS NTSTATUS
WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite, FAT12CountAvailableClusters(PDEVICE_EXTENSION DeviceExt,
ULONG NewValue); PLARGE_INTEGER Clusters);
NTSTATUS
FAT16CountAvailableClusters(PDEVICE_EXTENSION DeviceExt,
PLARGE_INTEGER Clusters);
NTSTATUS
FAT32CountAvailableClusters(PDEVICE_EXTENSION DeviceExt,
PLARGE_INTEGER Clusters);
NTSTATUS
WriteCluster(PDEVICE_EXTENSION DeviceExt,
ULONG ClusterToWrite,
ULONG NewValue);
/* /*
* From create.c * From create.c
*/ */
NTSTATUS NTSTATUS
ReadVolumeLabel(PDEVICE_EXTENSION DeviceExt, PVPB Vpb); ReadVolumeLabel(PDEVICE_EXTENSION DeviceExt, PVPB Vpb);
NTSTATUS NTSTATUS
VfatOpenFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, VfatOpenFile(PDEVICE_EXTENSION DeviceExt,
PWSTR FileName); PFILE_OBJECT FileObject,
PWSTR FileName);
/* ----------------------------------------------------- FCB Functions */ /* ----------------------------------------------------- FCB Functions */

View file

@ -1,4 +1,4 @@
/* $Id: volume.c,v 1.9 2001/06/12 12:35:42 ekohl Exp $ /* $Id: volume.c,v 1.10 2001/06/14 10:02:59 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -93,6 +93,7 @@ FsdGetFsSizeInformation(PDEVICE_OBJECT DeviceObject,
PULONG BufferLength) PULONG BufferLength)
{ {
PDEVICE_EXTENSION DeviceExt; PDEVICE_EXTENSION DeviceExt;
NTSTATUS Status;
DPRINT("FsdGetFsSizeInformation()\n"); DPRINT("FsdGetFsSizeInformation()\n");
DPRINT("FsSizeInfo = %p\n", FsSizeInfo); DPRINT("FsSizeInfo = %p\n", FsSizeInfo);
@ -110,9 +111,8 @@ FsdGetFsSizeInformation(PDEVICE_OBJECT DeviceObject,
FsSizeInfo->TotalAllocationUnits.QuadPart = ((BootSect->Sectors ? BootSect->Sectors : BootSect->SectorsHuge)-DeviceExt->dataStart)/BootSect->SectorsPerCluster; FsSizeInfo->TotalAllocationUnits.QuadPart = ((BootSect->Sectors ? BootSect->Sectors : BootSect->SectorsHuge)-DeviceExt->dataStart)/BootSect->SectorsPerCluster;
Status = FAT32CountAvailableClusters(DeviceExt,
&FsSizeInfo->AvailableAllocationUnits);
FsSizeInfo->AvailableAllocationUnits.QuadPart = FAT32CountAvailableClusters (DeviceExt);
FsSizeInfo->SectorsPerAllocationUnit = BootSect->SectorsPerCluster; FsSizeInfo->SectorsPerAllocationUnit = BootSect->SectorsPerCluster;
FsSizeInfo->BytesPerSector = BootSect->BytesPerSector; FsSizeInfo->BytesPerSector = BootSect->BytesPerSector;
@ -124,24 +124,27 @@ FsdGetFsSizeInformation(PDEVICE_OBJECT DeviceObject,
FsSizeInfo->TotalAllocationUnits.QuadPart = ((BootSect->Sectors ? BootSect->Sectors : BootSect->SectorsHuge)-DeviceExt->dataStart)/BootSect->SectorsPerCluster; FsSizeInfo->TotalAllocationUnits.QuadPart = ((BootSect->Sectors ? BootSect->Sectors : BootSect->SectorsHuge)-DeviceExt->dataStart)/BootSect->SectorsPerCluster;
if (DeviceExt->FatType == FAT16) if (DeviceExt->FatType == FAT16)
FsSizeInfo->AvailableAllocationUnits.QuadPart =
#if 0 #if 0
FAT16CountAvailableClusters (DeviceExt); Status = FAT16CountAvailableClusters(DeviceExt,
&FsSizeInfo->AvailableAllocationUnits);
#else #else
0; {
FsSizeInfo->AvailableAllocationUnits.QuadPart = 0;
Status = STATUS_SUCCESS;
}
#endif #endif
else else
FsSizeInfo->AvailableAllocationUnits.QuadPart = Status = FAT12CountAvailableClusters(DeviceExt,
FAT12CountAvailableClusters (DeviceExt); &FsSizeInfo->AvailableAllocationUnits);
FsSizeInfo->SectorsPerAllocationUnit = BootSect->SectorsPerCluster; FsSizeInfo->SectorsPerAllocationUnit = BootSect->SectorsPerCluster;
FsSizeInfo->BytesPerSector = BootSect->BytesPerSector; FsSizeInfo->BytesPerSector = BootSect->BytesPerSector;
} }
DPRINT("Finished FsdGetFsSizeInformation()\n"); DPRINT("Finished FsdGetFsSizeInformation()\n");
if (NT_SUCCESS(Status))
*BufferLength -= sizeof(FILE_FS_SIZE_INFORMATION);
*BufferLength -= sizeof(FILE_FS_SIZE_INFORMATION); return(Status);
return(STATUS_SUCCESS);
} }