mirror of
https://github.com/reactos/reactos.git
synced 2025-05-19 17:14:32 +00:00
Fixed from Carl Nettelblad
svn path=/trunk/; revision=1653
This commit is contained in:
parent
c9a6908fb9
commit
a2329a46e9
2 changed files with 99 additions and 36 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* $Id: fat.c,v 1.18 2001/02/06 20:17:35 dwelch Exp $
|
* $Id: fat.c,v 1.19 2001/03/01 07:48:17 dwelch Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include <ntos/minmax.h>
|
#include <ntos/minmax.h>
|
||||||
|
|
||||||
#define NDEBUG
|
#define NDEBUGN
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
#include "vfat.h"
|
#include "vfat.h"
|
||||||
|
@ -75,8 +75,7 @@ Fat16GetNextCluster (PDEVICE_EXTENSION DeviceExt,
|
||||||
ULONG CurrentCluster,
|
ULONG CurrentCluster,
|
||||||
PULONG NextCluster)
|
PULONG NextCluster)
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Retrieve the next FAT16 cluster from the FAT table from the
|
* FUNCTION: Retrieve the next FAT16 cluster from the FAT table
|
||||||
* in-memory FAT
|
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
PVOID BaseAddress;
|
PVOID BaseAddress;
|
||||||
|
@ -169,10 +168,10 @@ Fat12GetNextCluster (PDEVICE_EXTENSION DeviceExt,
|
||||||
Entry = (CBlock[FATOffset] >> 4);
|
Entry = (CBlock[FATOffset] >> 4);
|
||||||
Entry |= (CBlock[FATOffset+1] << 4);
|
Entry |= (CBlock[FATOffset+1] << 4);
|
||||||
}
|
}
|
||||||
DPRINT("Entry %x\n",Entry);
|
// DPRINT("Entry %x\n",Entry);
|
||||||
if (Entry >= 0xff8 && Entry <= 0xfff)
|
if (Entry >= 0xff8 && Entry <= 0xfff)
|
||||||
Entry = 0xffffffff;
|
Entry = 0xffffffff;
|
||||||
DPRINT("Returning %x\n",Entry);
|
// DPRINT("Returning %x\n",Entry);
|
||||||
*NextCluster = Entry;
|
*NextCluster = Entry;
|
||||||
CcReleaseCacheSegment(DeviceExt->Fat12StorageBcb, CacheSeg, TRUE);
|
CcReleaseCacheSegment(DeviceExt->Fat12StorageBcb, CacheSeg, TRUE);
|
||||||
return(STATUS_SUCCESS);
|
return(STATUS_SUCCESS);
|
||||||
|
@ -256,6 +255,7 @@ FAT12FindAvailableCluster (PDEVICE_EXTENSION DeviceExt, PULONG Cluster)
|
||||||
BOOLEAN Valid;
|
BOOLEAN Valid;
|
||||||
PCACHE_SEGMENT CacheSeg;
|
PCACHE_SEGMENT CacheSeg;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
ULONG numberofclusters;
|
||||||
|
|
||||||
*Cluster = 0;
|
*Cluster = 0;
|
||||||
|
|
||||||
|
@ -282,7 +282,9 @@ FAT12FindAvailableCluster (PDEVICE_EXTENSION DeviceExt, PULONG Cluster)
|
||||||
}
|
}
|
||||||
CBlock = (PUCHAR)BaseAddress;
|
CBlock = (PUCHAR)BaseAddress;
|
||||||
|
|
||||||
for (i = 2; i < ((DeviceExt->Boot->FATSectors * 512 * 8) / 12); i++)
|
numberofclusters = ((DeviceExt->Boot->Sectors ? DeviceExt->Boot->Sectors : DeviceExt->Boot->SectorsHuge)-DeviceExt->dataStart)/DeviceExt->Boot->SectorsPerCluster+2;
|
||||||
|
|
||||||
|
for (i = 2; i < numberofclusters; i++)
|
||||||
{
|
{
|
||||||
FATOffset = (i * 12) / 8;
|
FATOffset = (i * 12) / 8;
|
||||||
if ((i % 2) == 0)
|
if ((i % 2) == 0)
|
||||||
|
@ -299,11 +301,11 @@ FAT12FindAvailableCluster (PDEVICE_EXTENSION DeviceExt, PULONG Cluster)
|
||||||
{
|
{
|
||||||
DPRINT("Found available cluster 0x%x\n", i);
|
DPRINT("Found available cluster 0x%x\n", i);
|
||||||
*Cluster = i;
|
*Cluster = i;
|
||||||
CcReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, TRUE);
|
CcReleaseCacheSegment(DeviceExt->Fat12StorageBcb, CacheSeg, TRUE);
|
||||||
return(STATUS_SUCCESS);
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CcReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, TRUE);
|
CcReleaseCacheSegment(DeviceExt->Fat12StorageBcb, CacheSeg, TRUE);
|
||||||
return (STATUS_DISK_FULL);
|
return (STATUS_DISK_FULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,21 +317,36 @@ FAT32FindAvailableCluster (PDEVICE_EXTENSION DeviceExt, PULONG Cluster)
|
||||||
{
|
{
|
||||||
ULONG sector;
|
ULONG sector;
|
||||||
PULONG Block;
|
PULONG Block;
|
||||||
int i;
|
int i,forto;
|
||||||
|
ULONG numberofclusters;
|
||||||
|
NTSTATUS Status;
|
||||||
|
|
||||||
Block = ExAllocatePool (NonPagedPool, BLOCKSIZE);
|
Block = ExAllocatePool (NonPagedPool, BLOCKSIZE);
|
||||||
*Cluster = 0;
|
*Cluster = 0;
|
||||||
|
|
||||||
|
numberofclusters = ((DeviceExt->Boot->Sectors ? DeviceExt->Boot->Sectors : DeviceExt->Boot->SectorsHuge)-DeviceExt->dataStart)/DeviceExt->Boot->SectorsPerCluster+2;
|
||||||
|
numberofclusters %= 128;
|
||||||
|
|
||||||
for (sector = 0;
|
for (sector = 0;
|
||||||
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);
|
||||||
|
|
||||||
for (i = 0; i < 512; i++)
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
ExFreePool (Block);
|
||||||
|
return(Status);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sector==((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32-1)
|
||||||
|
forto=numberofclusters;
|
||||||
|
else
|
||||||
|
forto=128;
|
||||||
|
|
||||||
|
for (i = 0; i < forto; i++)
|
||||||
{
|
{
|
||||||
if (Block[i] == 0)
|
if (Block[i] == 0)
|
||||||
{
|
{
|
||||||
|
@ -344,7 +361,7 @@ FAT32FindAvailableCluster (PDEVICE_EXTENSION DeviceExt, PULONG Cluster)
|
||||||
return (STATUS_DISK_FULL);
|
return (STATUS_DISK_FULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
ULONG
|
ULONG
|
||||||
FAT12CountAvailableClusters (PDEVICE_EXTENSION DeviceExt)
|
FAT12CountAvailableClusters (PDEVICE_EXTENSION DeviceExt)
|
||||||
/*
|
/*
|
||||||
|
@ -353,13 +370,43 @@ FAT12CountAvailableClusters (PDEVICE_EXTENSION DeviceExt)
|
||||||
{
|
{
|
||||||
ULONG FATOffset;
|
ULONG FATOffset;
|
||||||
ULONG Entry;
|
ULONG Entry;
|
||||||
PUCHAR CBlock = DeviceExt->FAT;
|
PUCHAR CBlock;
|
||||||
ULONG ulCount = 0;
|
ULONG ulCount = 0;
|
||||||
ULONG i;
|
ULONG i;
|
||||||
|
PVOID BaseAddress;
|
||||||
|
BOOLEAN Valid;
|
||||||
|
PCACHE_SEGMENT CacheSeg;
|
||||||
|
NTSTATUS Status;
|
||||||
|
ULONG numberofclusters;
|
||||||
|
|
||||||
ExAcquireResourceSharedLite (&DeviceExt->FatResource, TRUE);
|
ExAcquireResourceSharedLite (&DeviceExt->FatResource, TRUE);
|
||||||
|
Status = CcRequestCacheSegment(DeviceExt->Fat12StorageBcb,
|
||||||
|
0,
|
||||||
|
&BaseAddress,
|
||||||
|
&Valid,
|
||||||
|
&CacheSeg);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
ExReleaseResourceLite (&DeviceExt->FatResource);
|
||||||
|
return 0; // Will the caller understand NTSTATUS values?
|
||||||
|
}
|
||||||
|
if (!Valid)
|
||||||
|
{
|
||||||
|
Status = VfatReadSectors(DeviceExt->StorageDevice,
|
||||||
|
DeviceExt->FATStart,
|
||||||
|
DeviceExt->Boot->FATSectors,
|
||||||
|
BaseAddress);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
CcReleaseCacheSegment(DeviceExt->Fat12StorageBcb, CacheSeg, FALSE);
|
||||||
|
ExReleaseResourceLite (&DeviceExt->FatResource);
|
||||||
|
return 0; // Will the caller understand NTSTATUS values?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CBlock = (PUCHAR)BaseAddress;
|
||||||
|
numberofclusters = ((DeviceExt->Boot->Sectors ? DeviceExt->Boot->Sectors : DeviceExt->Boot->SectorsHuge)-DeviceExt->dataStart)/DeviceExt->Boot->SectorsPerCluster+2;
|
||||||
|
|
||||||
for (i = 2; i < ((DeviceExt->Boot->FATSectors * 512 * 8) / 12); i++)
|
for (i = 2; i < numberofclusters; i++)
|
||||||
{
|
{
|
||||||
FATOffset = (i * 12) / 8;
|
FATOffset = (i * 12) / 8;
|
||||||
if ((i % 2) == 0)
|
if ((i % 2) == 0)
|
||||||
|
@ -376,11 +423,13 @@ FAT12CountAvailableClusters (PDEVICE_EXTENSION DeviceExt)
|
||||||
ulCount++;
|
ulCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CcReleaseCacheSegment(DeviceExt->Fat12StorageBcb, CacheSeg, FALSE);
|
||||||
ExReleaseResourceLite (&DeviceExt->FatResource);
|
ExReleaseResourceLite (&DeviceExt->FatResource);
|
||||||
|
|
||||||
return ulCount;
|
return ulCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
ULONG
|
ULONG
|
||||||
FAT16CountAvailableClusters (PDEVICE_EXTENSION DeviceExt)
|
FAT16CountAvailableClusters (PDEVICE_EXTENSION DeviceExt)
|
||||||
/*
|
/*
|
||||||
|
@ -415,11 +464,16 @@ FAT32CountAvailableClusters (PDEVICE_EXTENSION DeviceExt)
|
||||||
ULONG sector;
|
ULONG sector;
|
||||||
PULONG Block;
|
PULONG Block;
|
||||||
ULONG ulCount = 0;
|
ULONG ulCount = 0;
|
||||||
ULONG i;
|
ULONG i,forto;
|
||||||
|
ULONG numberofclusters;
|
||||||
|
|
||||||
ExAcquireResourceSharedLite (&DeviceExt->FatResource, TRUE);
|
ExAcquireResourceSharedLite (&DeviceExt->FatResource, TRUE);
|
||||||
|
|
||||||
Block = ExAllocatePool (NonPagedPool, BLOCKSIZE);
|
Block = ExAllocatePool (NonPagedPool, BLOCKSIZE);
|
||||||
|
|
||||||
|
numberofclusters = ((DeviceExt->Boot->Sectors ? DeviceExt->Boot->Sectors : DeviceExt->Boot->SectorsHuge)-DeviceExt->dataStart)/DeviceExt->Boot->SectorsPerCluster+2;
|
||||||
|
numberofclusters %= 128;
|
||||||
|
|
||||||
for (sector = 0;
|
for (sector = 0;
|
||||||
sector < ((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32;
|
sector < ((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32;
|
||||||
sector++)
|
sector++)
|
||||||
|
@ -429,13 +483,16 @@ FAT32CountAvailableClusters (PDEVICE_EXTENSION DeviceExt)
|
||||||
(ULONG) (DeviceExt->FATStart + sector), 1,
|
(ULONG) (DeviceExt->FATStart + sector), 1,
|
||||||
(UCHAR *) Block);
|
(UCHAR *) Block);
|
||||||
|
|
||||||
for (i = 0; i < 512; i++)
|
if (sector==((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32-1)
|
||||||
|
forto=numberofclusters;
|
||||||
|
else
|
||||||
|
forto=128;
|
||||||
|
for (i = 0; i < forto; i++)
|
||||||
{
|
{
|
||||||
if (Block[i] == 0)
|
if (Block[i] == 0)
|
||||||
ulCount++;
|
ulCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Give an error message (out of disk space) if we reach here) */
|
|
||||||
ExFreePool (Block);
|
ExFreePool (Block);
|
||||||
ExReleaseResourceLite (&DeviceExt->FatResource);
|
ExReleaseResourceLite (&DeviceExt->FatResource);
|
||||||
return ulCount;
|
return ulCount;
|
||||||
|
@ -516,7 +573,7 @@ FAT12WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
|
||||||
1, CBlock + FATsector * 512);
|
1, CBlock + FATsector * 512);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CcReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, TRUE);
|
CcReleaseCacheSegment(DeviceExt->Fat12StorageBcb, CacheSeg, TRUE);
|
||||||
return(STATUS_SUCCESS);
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -729,8 +786,8 @@ GetNextCluster (PDEVICE_EXTENSION DeviceExt,
|
||||||
{
|
{
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
|
||||||
DPRINT ("GetNextCluster(DeviceExt %x, CurrentCluster %x)\n",
|
// DPRINT ("GetNextCluster(DeviceExt %x, CurrentCluster %x)\n",
|
||||||
DeviceExt, CurrentCluster);
|
// DeviceExt, CurrentCluster);
|
||||||
|
|
||||||
if (Extend)
|
if (Extend)
|
||||||
{
|
{
|
||||||
|
@ -760,6 +817,10 @@ GetNextCluster (PDEVICE_EXTENSION DeviceExt,
|
||||||
else if (DeviceExt->FatType == FAT32)
|
else if (DeviceExt->FatType == FAT32)
|
||||||
{
|
{
|
||||||
Status = FAT32FindAvailableCluster (DeviceExt, &NewCluster);
|
Status = FAT32FindAvailableCluster (DeviceExt, &NewCluster);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
return(Status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -810,6 +871,10 @@ GetNextCluster (PDEVICE_EXTENSION DeviceExt,
|
||||||
else if (DeviceExt->FatType == FAT32)
|
else if (DeviceExt->FatType == FAT32)
|
||||||
{
|
{
|
||||||
Status = FAT32FindAvailableCluster (DeviceExt, &NewCluster);
|
Status = FAT32FindAvailableCluster (DeviceExt, &NewCluster);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
return(Status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: volume.c,v 1.6 2001/01/12 21:00:08 dwelch Exp $
|
/* $Id: volume.c,v 1.7 2001/03/01 07:48:17 dwelch Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
|
@ -83,13 +83,11 @@ FsdGetFsSizeInformation (PDEVICE_OBJECT DeviceObject,
|
||||||
struct _BootSector32 *BootSect =
|
struct _BootSector32 *BootSect =
|
||||||
(struct _BootSector32 *) DeviceExt->Boot;
|
(struct _BootSector32 *) DeviceExt->Boot;
|
||||||
|
|
||||||
if (BootSect->Sectors)
|
FsSizeInfo->TotalAllocationUnits.QuadPart = ((BootSect->Sectors ? BootSect->Sectors : BootSect->SectorsHuge)-DeviceExt->dataStart)/BootSect->SectorsPerCluster;
|
||||||
FsSizeInfo->TotalAllocationUnits.QuadPart = BootSect->Sectors;
|
|
||||||
else
|
|
||||||
FsSizeInfo->TotalAllocationUnits.QuadPart = BootSect->SectorsHuge;
|
|
||||||
|
|
||||||
/* FsSizeInfo->AvailableAllocationUnits.QuadPart =
|
|
||||||
FAT32CountAvailableClusters (DeviceExt); */
|
|
||||||
|
FsSizeInfo->AvailableAllocationUnits.QuadPart = FAT32CountAvailableClusters (DeviceExt);
|
||||||
|
|
||||||
FsSizeInfo->SectorsPerAllocationUnit = BootSect->SectorsPerCluster;
|
FsSizeInfo->SectorsPerAllocationUnit = BootSect->SectorsPerCluster;
|
||||||
FsSizeInfo->BytesPerSector = BootSect->BytesPerSector;
|
FsSizeInfo->BytesPerSector = BootSect->BytesPerSector;
|
||||||
|
@ -98,18 +96,18 @@ FsdGetFsSizeInformation (PDEVICE_OBJECT DeviceObject,
|
||||||
{
|
{
|
||||||
struct _BootSector *BootSect = (struct _BootSector *) DeviceExt->Boot;
|
struct _BootSector *BootSect = (struct _BootSector *) DeviceExt->Boot;
|
||||||
|
|
||||||
if (BootSect->Sectors)
|
FsSizeInfo->TotalAllocationUnits.QuadPart = ((BootSect->Sectors ? BootSect->Sectors : BootSect->SectorsHuge)-DeviceExt->dataStart)/BootSect->SectorsPerCluster;
|
||||||
FsSizeInfo->TotalAllocationUnits.QuadPart = BootSect->Sectors;
|
|
||||||
else
|
|
||||||
FsSizeInfo->TotalAllocationUnits.QuadPart = BootSect->SectorsHuge;
|
|
||||||
/*
|
|
||||||
if (DeviceExt->FatType == FAT16)
|
if (DeviceExt->FatType == FAT16)
|
||||||
FsSizeInfo->AvailableAllocationUnits.QuadPart =
|
FsSizeInfo->AvailableAllocationUnits.QuadPart =
|
||||||
|
#if 0
|
||||||
FAT16CountAvailableClusters (DeviceExt);
|
FAT16CountAvailableClusters (DeviceExt);
|
||||||
|
#else
|
||||||
|
0;
|
||||||
|
#endif
|
||||||
else
|
else
|
||||||
FsSizeInfo->AvailableAllocationUnits.QuadPart =
|
FsSizeInfo->AvailableAllocationUnits.QuadPart =
|
||||||
FAT12CountAvailableClusters (DeviceExt);
|
FAT12CountAvailableClusters (DeviceExt);
|
||||||
*/
|
|
||||||
FsSizeInfo->SectorsPerAllocationUnit = BootSect->SectorsPerCluster;
|
FsSizeInfo->SectorsPerAllocationUnit = BootSect->SectorsPerCluster;
|
||||||
FsSizeInfo->BytesPerSector = BootSect->BytesPerSector;
|
FsSizeInfo->BytesPerSector = BootSect->BytesPerSector;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue