mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 10:04:49 +00:00
More small cluster size fixes
svn path=/trunk/; revision=1509
This commit is contained in:
parent
51772d486a
commit
eda06227b3
4 changed files with 198 additions and 200 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* $Id: fat.c,v 1.12 2001/01/13 18:38:09 dwelch Exp $
|
* $Id: fat.c,v 1.13 2001/01/14 15:05:53 dwelch Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
|
@ -237,124 +237,76 @@ GetNextCluster (PDEVICE_EXTENSION DeviceExt,
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
VfatRequestDiskPage(PDEVICE_EXTENSION DeviceExt,
|
FAT16FindAvailableCluster (PDEVICE_EXTENSION DeviceExt,
|
||||||
ULONG Offset,
|
PULONG Cluster)
|
||||||
PVOID* BaseAddress,
|
|
||||||
PCACHE_SEGMENT* CacheSeg)
|
|
||||||
{
|
|
||||||
NTSTATUS Status;
|
|
||||||
BOOLEAN Valid;
|
|
||||||
|
|
||||||
Status = CcRequestCacheSegment(DeviceExt->StorageBcb,
|
|
||||||
Offset,
|
|
||||||
BaseAddress,
|
|
||||||
&Valid,
|
|
||||||
CacheSeg);
|
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
return(Status);
|
|
||||||
}
|
|
||||||
if (!Valid)
|
|
||||||
{
|
|
||||||
Status = VfatReadSectors(DeviceExt->StorageDevice,
|
|
||||||
Offset,
|
|
||||||
PAGESIZE / BLOCKSIZE,
|
|
||||||
*BaseAddress);
|
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
CcReleaseCacheSegment(DeviceExt->StorageBcb, *CacheSeg, FALSE);
|
|
||||||
return(Status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return(STATUS_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
ULONG
|
|
||||||
Vfat16FindAvailableClusterInPage (PVOID Page, ULONG Offset, ULONG Length)
|
|
||||||
{
|
|
||||||
ULONG j;
|
|
||||||
|
|
||||||
for (j = Offset ; j < Length; j+=2)
|
|
||||||
{
|
|
||||||
if ((*((PUSHORT)(Page + j))) == 0)
|
|
||||||
{
|
|
||||||
return(j);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
ULONG
|
|
||||||
FAT16FindAvailableCluster (PDEVICE_EXTENSION DeviceExt)
|
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Finds the first available cluster in a FAT16 table
|
* FUNCTION: Finds the first available cluster in a FAT16 table
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
ULONG i;
|
|
||||||
PCACHE_SEGMENT CacheSeg;
|
|
||||||
PVOID BaseAddress;
|
|
||||||
ULONG StartOffset;
|
|
||||||
ULONG FatLength;
|
ULONG FatLength;
|
||||||
ULONG Length;
|
ULONG i;
|
||||||
ULONG r;
|
|
||||||
ULONG FatStart;
|
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
|
PVOID BaseAddress;
|
||||||
|
PCACHE_SEGMENT CacheSeg;
|
||||||
|
BOOLEAN Valid;
|
||||||
|
ULONG FatStart;
|
||||||
|
|
||||||
FatStart = DeviceExt->FATStart * BLOCKSIZE;
|
FatStart = DeviceExt->FATStart * BLOCKSIZE;
|
||||||
StartOffset = DeviceExt->FATStart * BLOCKSIZE;
|
|
||||||
FatLength = DeviceExt->Boot->FATSectors * BLOCKSIZE;
|
FatLength = DeviceExt->Boot->FATSectors * BLOCKSIZE;
|
||||||
|
CacheSeg = NULL;
|
||||||
|
*Cluster = 0;
|
||||||
|
|
||||||
if ((StartOffset % PAGESIZE) != 0)
|
for (i = 0; i < FatLength; i+=2)
|
||||||
{
|
{
|
||||||
Status = VfatRequestDiskPage(DeviceExt,
|
if ((i % PAGESIZE) == 0)
|
||||||
PAGE_ROUND_DOWN(StartOffset),
|
|
||||||
&BaseAddress,
|
|
||||||
&CacheSeg);
|
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
{
|
||||||
return(0);
|
if (CacheSeg != NULL)
|
||||||
|
{
|
||||||
|
CcReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, TRUE);
|
||||||
|
}
|
||||||
|
Status = CcRequestCacheSegment(DeviceExt->StorageBcb,
|
||||||
|
FatStart + i,
|
||||||
|
&BaseAddress,
|
||||||
|
&Valid,
|
||||||
|
&CacheSeg);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
return(Status);
|
||||||
|
}
|
||||||
|
if (!Valid)
|
||||||
|
{
|
||||||
|
Status = VfatReadSectors(DeviceExt->StorageDevice,
|
||||||
|
(FatStart + i) / BLOCKSIZE,
|
||||||
|
PAGESIZE / BLOCKSIZE,
|
||||||
|
BaseAddress);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
CcReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg,
|
||||||
|
FALSE);
|
||||||
|
return(Status);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Length = max(PAGESIZE, FatLength);
|
if (*((PUSHORT)(BaseAddress + (i % PAGESIZE))) == 0)
|
||||||
r = Vfat16FindAvailableClusterInPage(BaseAddress,
|
|
||||||
StartOffset % PAGESIZE,
|
|
||||||
Length);
|
|
||||||
if (r != 0)
|
|
||||||
{
|
{
|
||||||
return((r - (StartOffset % PAGESIZE)) / 2);
|
*Cluster = i / 2;
|
||||||
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
CcReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, FALSE);
|
|
||||||
StartOffset = StartOffset + (Length - (StartOffset % PAGESIZE));
|
|
||||||
FatLength = FatLength - (Length - (StartOffset % PAGESIZE));
|
|
||||||
}
|
|
||||||
for (i = 0; i < (FatLength / PAGESIZE); i++)
|
|
||||||
{
|
|
||||||
Status = VfatRequestDiskPage(DeviceExt,
|
|
||||||
PAGE_ROUND_DOWN(StartOffset),
|
|
||||||
&BaseAddress,
|
|
||||||
&CacheSeg);
|
|
||||||
if (!NT_SUCCESS(Status))
|
|
||||||
{
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
r = Vfat16FindAvailableClusterInPage(BaseAddress, 0, PAGESIZE);
|
|
||||||
if (r != 0)
|
|
||||||
{
|
|
||||||
return((r + StartOffset - FatStart) / 2);
|
|
||||||
}
|
|
||||||
CcReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, TRUE);
|
|
||||||
StartOffset = StartOffset + PAGESIZE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return(0);
|
return(STATUS_DISK_FULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
NTSTATUS
|
||||||
ULONG
|
FAT12FindAvailableCluster (PDEVICE_EXTENSION DeviceExt, PULONG Cluster)
|
||||||
FAT12FindAvailableCluster (PDEVICE_EXTENSION DeviceExt)
|
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Finds the first available cluster in a FAT12 table
|
* FUNCTION: Finds the first available cluster in a FAT12 table
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
|
*Cluster = 0;
|
||||||
|
return(STATUS_UNSUCCESSFUL);
|
||||||
|
|
||||||
|
#if 0
|
||||||
ULONG FATOffset;
|
ULONG FATOffset;
|
||||||
ULONG Entry;
|
ULONG Entry;
|
||||||
PUCHAR CBlock = DeviceExt->FAT;
|
PUCHAR CBlock = DeviceExt->FAT;
|
||||||
|
@ -378,10 +330,11 @@ FAT12FindAvailableCluster (PDEVICE_EXTENSION DeviceExt)
|
||||||
/* Give an error message (out of disk space) if we reach here) */
|
/* Give an error message (out of disk space) if we reach here) */
|
||||||
DbgPrint ("Disk full, %d clusters used\n", i);
|
DbgPrint ("Disk full, %d clusters used\n", i);
|
||||||
return 0;
|
return 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
ULONG
|
NTSTATUS
|
||||||
FAT32FindAvailableCluster (PDEVICE_EXTENSION DeviceExt)
|
FAT32FindAvailableCluster (PDEVICE_EXTENSION DeviceExt, PULONG Cluster)
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Finds the first available cluster in a FAT32 table
|
* FUNCTION: Finds the first available cluster in a FAT32 table
|
||||||
*/
|
*/
|
||||||
|
@ -389,7 +342,10 @@ FAT32FindAvailableCluster (PDEVICE_EXTENSION DeviceExt)
|
||||||
ULONG sector;
|
ULONG sector;
|
||||||
PULONG Block;
|
PULONG Block;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
Block = ExAllocatePool (NonPagedPool, BLOCKSIZE);
|
Block = ExAllocatePool (NonPagedPool, BLOCKSIZE);
|
||||||
|
*Cluster = 0;
|
||||||
|
|
||||||
for (sector = 0;
|
for (sector = 0;
|
||||||
sector < ((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32;
|
sector < ((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32;
|
||||||
sector++)
|
sector++)
|
||||||
|
@ -404,15 +360,17 @@ FAT32FindAvailableCluster (PDEVICE_EXTENSION DeviceExt)
|
||||||
if (Block[i] == 0)
|
if (Block[i] == 0)
|
||||||
{
|
{
|
||||||
ExFreePool (Block);
|
ExFreePool (Block);
|
||||||
return (i + sector * 128);
|
*Cluster = (i + sector * 128);
|
||||||
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Give an error message (out of disk space) if we reach here) */
|
/* Give an error message (out of disk space) if we reach here) */
|
||||||
ExFreePool (Block);
|
ExFreePool (Block);
|
||||||
return 0;
|
return (STATUS_DISK_FULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
ULONG
|
ULONG
|
||||||
FAT12CountAvailableClusters (PDEVICE_EXTENSION DeviceExt)
|
FAT12CountAvailableClusters (PDEVICE_EXTENSION DeviceExt)
|
||||||
/*
|
/*
|
||||||
|
@ -472,6 +430,7 @@ FAT16CountAvailableClusters (PDEVICE_EXTENSION DeviceExt)
|
||||||
|
|
||||||
return ulCount;
|
return ulCount;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
ULONG
|
ULONG
|
||||||
FAT32CountAvailableClusters (PDEVICE_EXTENSION DeviceExt)
|
FAT32CountAvailableClusters (PDEVICE_EXTENSION DeviceExt)
|
||||||
|
@ -508,13 +467,16 @@ FAT32CountAvailableClusters (PDEVICE_EXTENSION DeviceExt)
|
||||||
return ulCount;
|
return ulCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID
|
NTSTATUS
|
||||||
FAT12WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
|
FAT12WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
|
||||||
ULONG NewValue)
|
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
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
|
return(STATUS_UNSUCCESSFUL);
|
||||||
|
|
||||||
|
#if 0
|
||||||
ULONG FATsector;
|
ULONG FATsector;
|
||||||
ULONG FATOffset;
|
ULONG FATOffset;
|
||||||
PUCHAR CBlock = DeviceExt->FAT;
|
PUCHAR CBlock = DeviceExt->FAT;
|
||||||
|
@ -553,37 +515,59 @@ FAT12WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
|
||||||
1, CBlock + FATsector * 512);
|
1, CBlock + FATsector * 512);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID
|
NTSTATUS
|
||||||
FAT16WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
|
FAT16WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
|
||||||
ULONG NewValue)
|
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
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
ULONG FATsector;
|
PVOID BaseAddress;
|
||||||
PUSHORT Block;
|
BOOLEAN Valid;
|
||||||
|
PCACHE_SEGMENT CacheSeg;
|
||||||
|
NTSTATUS Status;
|
||||||
|
ULONG FATOffset;
|
||||||
ULONG Start;
|
ULONG Start;
|
||||||
int i;
|
ULONG i;
|
||||||
|
|
||||||
DbgPrint ("FAT16WriteCluster %u : %u\n", ClusterToWrite, NewValue);
|
Start = DeviceExt->FATStart;
|
||||||
|
|
||||||
Block = (PUSHORT) DeviceExt->FAT;
|
|
||||||
FATsector = ClusterToWrite / (512 / sizeof (USHORT));
|
|
||||||
|
|
||||||
/* Update the in-memory FAT */
|
|
||||||
Block[ClusterToWrite] = NewValue;
|
|
||||||
|
|
||||||
/* Write the changed FAT sector to disk (all FAT's) */
|
|
||||||
Start = DeviceExt->FATStart + FATsector;
|
|
||||||
for (i = 0; i < DeviceExt->Boot->FATCount; i++)
|
for (i = 0; i < DeviceExt->Boot->FATCount; i++)
|
||||||
{
|
{
|
||||||
/* FIXME: Check status */
|
FATOffset = (Start * BLOCKSIZE) + (ClusterToWrite * 2);
|
||||||
VfatWriteSectors (DeviceExt->StorageDevice,
|
|
||||||
Start, 1, ((UCHAR *) Block) + FATsector * 512);
|
Status = CcRequestCacheSegment(DeviceExt->StorageBcb,
|
||||||
Start += DeviceExt->Boot->FATSectors;
|
PAGE_ROUND_DOWN(FATOffset),
|
||||||
|
&BaseAddress,
|
||||||
|
&Valid,
|
||||||
|
&CacheSeg);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
return(Status);
|
||||||
|
}
|
||||||
|
if (!Valid)
|
||||||
|
{
|
||||||
|
Status = VfatReadSectors(DeviceExt->StorageDevice,
|
||||||
|
PAGE_ROUND_DOWN(FATOffset) / BLOCKSIZE,
|
||||||
|
PAGESIZE / BLOCKSIZE,
|
||||||
|
BaseAddress);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
CcReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, FALSE);
|
||||||
|
return(Status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*((PUSHORT)(BaseAddress + (FATOffset % PAGESIZE))) = NewValue;
|
||||||
|
CcReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, TRUE);
|
||||||
|
|
||||||
|
Start = Start + DeviceExt->Boot->FATSectors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID
|
VOID
|
||||||
|
@ -620,84 +604,101 @@ FAT32WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
|
||||||
ExFreePool (Block);
|
ExFreePool (Block);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID
|
NTSTATUS
|
||||||
WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
|
WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
|
||||||
ULONG NewValue)
|
ULONG NewValue)
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Write a changed FAT entry
|
* FUNCTION: Write a changed FAT entry
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
|
NTSTATUS Status;
|
||||||
|
|
||||||
if (DeviceExt->FatType == FAT16)
|
if (DeviceExt->FatType == FAT16)
|
||||||
{
|
{
|
||||||
FAT16WriteCluster (DeviceExt, ClusterToWrite, NewValue);
|
Status = FAT16WriteCluster (DeviceExt, ClusterToWrite, NewValue);
|
||||||
}
|
}
|
||||||
else if (DeviceExt->FatType == FAT32)
|
else if (DeviceExt->FatType == FAT32)
|
||||||
{
|
{
|
||||||
FAT32WriteCluster (DeviceExt, ClusterToWrite, NewValue);
|
FAT32WriteCluster (DeviceExt, ClusterToWrite, NewValue);
|
||||||
|
Status = STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FAT12WriteCluster (DeviceExt, ClusterToWrite, NewValue);
|
Status = FAT12WriteCluster (DeviceExt, ClusterToWrite, NewValue);
|
||||||
}
|
}
|
||||||
|
return(Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
ULONG
|
NTSTATUS
|
||||||
GetNextWriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster)
|
GetNextWriteCluster (PDEVICE_EXTENSION DeviceExt,
|
||||||
|
ULONG CurrentCluster,
|
||||||
|
PULONG NextCluster)
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Determines the next cluster to be written
|
* FUNCTION: Determines the next cluster to be written
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
ULONG LastCluster, NewCluster;
|
ULONG LastCluster, NewCluster;
|
||||||
UCHAR *Buffer2;
|
UCHAR *Buffer2;
|
||||||
|
NTSTATUS Status;
|
||||||
|
|
||||||
DPRINT ("GetNextWriteCluster(DeviceExt %x, CurrentCluster %x)\n",
|
DPRINT ("GetNextWriteCluster(DeviceExt %x, CurrentCluster %x)\n",
|
||||||
DeviceExt, CurrentCluster);
|
DeviceExt, CurrentCluster);
|
||||||
|
|
||||||
|
*NextCluster = 0;
|
||||||
|
|
||||||
/* Find out what was happening in the last cluster's AU */
|
/* Find out what was happening in the last cluster's AU */
|
||||||
LastCluster = GetNextCluster (DeviceExt, CurrentCluster);
|
Status = GetNextCluster (DeviceExt, CurrentCluster, &LastCluster);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
return(Status);
|
||||||
|
}
|
||||||
/* Check to see if we must append or overwrite */
|
/* Check to see if we must append or overwrite */
|
||||||
if (LastCluster == 0xffffffff)
|
if (LastCluster == 0xFFFFFFFF)
|
||||||
{
|
{
|
||||||
/* we are after last existing cluster : we must add one to file */
|
/* we are after last existing cluster : we must add one to file */
|
||||||
/* Append */
|
/* Append */
|
||||||
/* Firstly, find the next available open allocation unit */
|
/* Firstly, find the next available open allocation unit */
|
||||||
if (DeviceExt->FatType == FAT16)
|
if (DeviceExt->FatType == FAT16)
|
||||||
{
|
{
|
||||||
NewCluster = FAT16FindAvailableCluster (DeviceExt);
|
Status = FAT16FindAvailableCluster (DeviceExt, &NewCluster);
|
||||||
DPRINT1 ("NewCluster %x\n", NewCluster);
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
return(Status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (DeviceExt->FatType == FAT32)
|
else if (DeviceExt->FatType == FAT32)
|
||||||
{
|
{
|
||||||
NewCluster = FAT32FindAvailableCluster (DeviceExt);
|
Status = FAT32FindAvailableCluster (DeviceExt, &NewCluster);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NewCluster = FAT12FindAvailableCluster (DeviceExt);
|
Status = FAT12FindAvailableCluster (DeviceExt, &NewCluster);
|
||||||
DPRINT ("NewFat12Cluster: %x\n", NewCluster);
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
return(Status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* Mark the new AU as the EOF */
|
/* Mark the new AU as the EOF */
|
||||||
WriteCluster (DeviceExt, NewCluster, 0xFFFFFFFF);
|
WriteCluster (DeviceExt, NewCluster, 0xFFFFFFFF);
|
||||||
/* Now, write the AU of the LastCluster with the value of the newly
|
/* Now, write the AU of the LastCluster with the value of the newly
|
||||||
found AU */
|
found AU */
|
||||||
if (CurrentCluster)
|
WriteCluster (DeviceExt, CurrentCluster, NewCluster);
|
||||||
{
|
/* fill cluster with zero */
|
||||||
WriteCluster (DeviceExt, CurrentCluster, NewCluster);
|
|
||||||
}
|
|
||||||
// fill cluster with zero
|
|
||||||
Buffer2 = ExAllocatePool (NonPagedPool, DeviceExt->BytesPerCluster);
|
Buffer2 = ExAllocatePool (NonPagedPool, DeviceExt->BytesPerCluster);
|
||||||
memset (Buffer2, 0, DeviceExt->BytesPerCluster);
|
memset (Buffer2, 0, DeviceExt->BytesPerCluster);
|
||||||
VFATWriteCluster (DeviceExt, Buffer2, NewCluster);
|
VfatWriteCluster (DeviceExt, Buffer2, NewCluster);
|
||||||
ExFreePool (Buffer2);
|
ExFreePool (Buffer2);
|
||||||
/* Return NewCluster as CurrentCluster */
|
/* Return NewCluster as CurrentCluster */
|
||||||
return NewCluster;
|
*NextCluster = NewCluster;
|
||||||
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Overwrite: Return LastCluster as CurrentCluster */
|
/* Overwrite: Return LastCluster as CurrentCluster */
|
||||||
return LastCluster;
|
*NextCluster = LastCluster;
|
||||||
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
ULONG
|
ULONG
|
||||||
ClusterToSector (PDEVICE_EXTENSION DeviceExt, unsigned long Cluster)
|
ClusterToSector (PDEVICE_EXTENSION DeviceExt, unsigned long Cluster)
|
||||||
|
@ -710,23 +711,37 @@ ClusterToSector (PDEVICE_EXTENSION DeviceExt, unsigned long Cluster)
|
||||||
((Cluster - 2) * DeviceExt->Boot->SectorsPerCluster);
|
((Cluster - 2) * DeviceExt->Boot->SectorsPerCluster);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID
|
NTSTATUS
|
||||||
VFATLoadCluster (PDEVICE_EXTENSION DeviceExt, PVOID Buffer, ULONG Cluster)
|
VfatRawReadCluster (PDEVICE_EXTENSION DeviceExt,
|
||||||
|
ULONG FirstCluster,
|
||||||
|
PVOID Buffer,
|
||||||
|
ULONG Cluster)
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Load a cluster from the physical device
|
* FUNCTION: Load a cluster from the physical device
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
ULONG Sector;
|
NTSTATUS Status;
|
||||||
|
|
||||||
DPRINT ("VFATLoadCluster(DeviceExt %x, Buffer %x, Cluster %d)\n",
|
if (FirstCluster == 1)
|
||||||
DeviceExt, Buffer, Cluster);
|
{
|
||||||
|
Status = VfatReadSectors (DeviceExt->StorageDevice,
|
||||||
|
Cluster,
|
||||||
|
DeviceExt->Boot->SectorsPerCluster,
|
||||||
|
Buffer);
|
||||||
|
return(Status);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ULONG Sector;
|
||||||
|
|
||||||
Sector = ClusterToSector (DeviceExt, Cluster);
|
Sector = ClusterToSector (DeviceExt, Cluster);
|
||||||
|
|
||||||
/* FIXME: Check status */
|
|
||||||
VfatReadSectors (DeviceExt->StorageDevice,
|
Status = VfatReadSectors (DeviceExt->StorageDevice,
|
||||||
Sector, DeviceExt->Boot->SectorsPerCluster, Buffer);
|
Sector, DeviceExt->Boot->SectorsPerCluster,
|
||||||
DPRINT ("Finished VFATReadSectors\n");
|
Buffer);
|
||||||
|
return(Status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
|
@ -743,7 +758,6 @@ VfatWriteCluster (PDEVICE_EXTENSION DeviceExt, PVOID Buffer, ULONG Cluster)
|
||||||
|
|
||||||
Sector = ClusterToSector (DeviceExt, Cluster);
|
Sector = ClusterToSector (DeviceExt, Cluster);
|
||||||
|
|
||||||
/* FIXME: Check status */
|
|
||||||
Status = VfatWriteSectors (DeviceExt->StorageDevice,
|
Status = VfatWriteSectors (DeviceExt->StorageDevice,
|
||||||
Sector, DeviceExt->Boot->SectorsPerCluster,
|
Sector, DeviceExt->Boot->SectorsPerCluster,
|
||||||
Buffer);
|
Buffer);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# $Id: makefile,v 1.26 2001/01/12 21:00:08 dwelch Exp $
|
# $Id: makefile,v 1.27 2001/01/14 15:05:53 dwelch Exp $
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
PATH_TO_TOP = ../../..
|
PATH_TO_TOP = ../../..
|
||||||
|
@ -40,7 +40,8 @@ dist: ../../../$(DIST_DIR)/drivers/$(TARGET).sys
|
||||||
$(CP) $(TARGET).sys ../../../$(DIST_DIR)/drivers/$(TARGET).sys
|
$(CP) $(TARGET).sys ../../../$(DIST_DIR)/drivers/$(TARGET).sys
|
||||||
|
|
||||||
$(TARGET).nostrip.sys: $(OBJECTS) $(LIBS)
|
$(TARGET).nostrip.sys: $(OBJECTS) $(LIBS)
|
||||||
$(CC) -specs=../../svc_specs -mdll -o junk.tmp -Wl,--defsym,_end=end -Wl,--defsym,_edata=__data_end__ -Wl,--defsym,_etext=etext -Wl,--base-file,base.tmp -Wl,"-h vfatfs.sys" $(OBJECTS) $(LIBS)
|
$(LD) -r -o vfat.o $(OBJECTS)
|
||||||
|
$(CC) -specs=../../svc_specs -mdll -o junk.tmp -Wl,--defsym,_end=end -Wl,--defsym,_edata=__data_end__ -Wl,--defsym,_etext=etext -Wl,--base-file,base.tmp -Wl,"-h vfatfs.sys" vfat.o $(LIBS)
|
||||||
- $(RM) junk.tmp
|
- $(RM) junk.tmp
|
||||||
$(DLLTOOL) \
|
$(DLLTOOL) \
|
||||||
--dllname $(TARGET).sys \
|
--dllname $(TARGET).sys \
|
||||||
|
@ -48,13 +49,14 @@ $(TARGET).nostrip.sys: $(OBJECTS) $(LIBS)
|
||||||
--output-exp temp.exp \
|
--output-exp temp.exp \
|
||||||
--def vfatfs.def
|
--def vfatfs.def
|
||||||
- $(RM) base.tmp
|
- $(RM) base.tmp
|
||||||
$(CC) --verbose -Wl,--image-base,0x10000 -Wl,-e,_DriverEntry@8 -Wl,temp.exp -Wl,"-h vfatfs.sys" -specs=../../svc_specs -mdll -o $(TARGET).nostrip.sys $(OBJECTS) $(LIBS)
|
$(CC) -Wl,--image-base,0x10000 -Wl,-e,_DriverEntry@8 -Wl,temp.exp -Wl,"-h vfatfs.sys" -specs=../../svc_specs -mdll -o $(TARGET).nostrip.sys vfat.o $(LIBS)
|
||||||
- $(RM) temp.exp
|
- $(RM) temp.exp
|
||||||
|
|
||||||
|
|
||||||
$(TARGET).sys: $(OBJECTS) $(LIBS)
|
$(TARGET).sys: $(OBJECTS) $(LIBS)
|
||||||
$(STRIP) --strip-debug $(OBJECTS)
|
$(LD) -r -o vfat.o $(OBJECTS)
|
||||||
$(CC) -specs=../../svc_specs -mdll -o junk.tmp -Wl,--defsym,_end=end -Wl,--defsym,_edata=__data_end__ -Wl,--defsym,_etext=etext -Wl,--base-file,base.tmp -Wl,"-h vfatfs.sys" $(OBJECTS) $(LIBS)
|
$(STRIP) --strip-debug vfat.o
|
||||||
|
$(CC) -specs=../../svc_specs -mdll -o junk.tmp -Wl,--defsym,_end=end -Wl,--defsym,_edata=__data_end__ -Wl,--defsym,_etext=etext -Wl,--base-file,base.tmp -Wl,"-h vfatfs.sys" vfat.o $(LIBS)
|
||||||
- $(RM) junk.tmp
|
- $(RM) junk.tmp
|
||||||
$(DLLTOOL) \
|
$(DLLTOOL) \
|
||||||
--dllname $(TARGET).sys \
|
--dllname $(TARGET).sys \
|
||||||
|
@ -62,7 +64,7 @@ $(TARGET).sys: $(OBJECTS) $(LIBS)
|
||||||
--output-exp temp.exp \
|
--output-exp temp.exp \
|
||||||
--def vfatfs.def
|
--def vfatfs.def
|
||||||
- $(RM) base.tmp
|
- $(RM) base.tmp
|
||||||
$(CC) --verbose -Wl,--image-base,0x10000 -Wl,-e,_DriverEntry@8 -Wl,temp.exp -Wl,"-h vfatfs.sys" -specs=../../svc_specs -mdll -o $(TARGET).sys $(OBJECTS) $(LIBS)
|
$(CC) -Wl,--image-base,0x10000 -Wl,-e,_DriverEntry@8 -Wl,temp.exp -Wl,"-h vfatfs.sys" -specs=../../svc_specs -mdll -o $(TARGET).sys vfat.o $(LIBS)
|
||||||
- $(RM) temp.exp
|
- $(RM) temp.exp
|
||||||
|
|
||||||
WITH_DEBUGGING=yes
|
WITH_DEBUGGING=yes
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
/* $Id: rw.c,v 1.17 2001/01/13 18:38:09 dwelch Exp $
|
/* $Id: rw.c,v 1.18 2001/01/14 15:05:53 dwelch Exp $
|
||||||
*
|
*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS kernel
|
* PROJECT: ReactOS kernel
|
||||||
|
@ -79,30 +79,6 @@ OffsetToCluster(PDEVICE_EXTENSION DeviceExt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS
|
|
||||||
VfatRawReadCluster (PDEVICE_EXTENSION DeviceExt,
|
|
||||||
ULONG FirstCluster,
|
|
||||||
PULONG CurrentCluster,
|
|
||||||
PVOID Destination)
|
|
||||||
{
|
|
||||||
NTSTATUS Status;
|
|
||||||
|
|
||||||
if (FirstCluster == 1)
|
|
||||||
{
|
|
||||||
Status = VfatReadSectors (DeviceExt->StorageDevice,
|
|
||||||
(*CurrentCluster),
|
|
||||||
DeviceExt->Boot->SectorsPerCluster,
|
|
||||||
Destination);
|
|
||||||
return(Status);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
VFATLoadCluster (DeviceExt, Destination, (*CurrentCluster));
|
|
||||||
Status = STATUS_SUCCESS;
|
|
||||||
return(Status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
VfatReadCluster(PDEVICE_EXTENSION DeviceExt,
|
VfatReadCluster(PDEVICE_EXTENSION DeviceExt,
|
||||||
PVFATFCB Fcb,
|
PVFATFCB Fcb,
|
||||||
|
@ -149,8 +125,8 @@ VfatReadCluster(PDEVICE_EXTENSION DeviceExt,
|
||||||
/*
|
/*
|
||||||
* If necessary read the cluster from the disk
|
* If necessary read the cluster from the disk
|
||||||
*/
|
*/
|
||||||
Status = VfatRawReadCluster(DeviceExt, FirstCluster, CurrentCluster,
|
Status = VfatRawReadCluster(DeviceExt, FirstCluster, BaseAddress,
|
||||||
BaseAddress);
|
*CurrentCluster);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
if (!NoCache)
|
if (!NoCache)
|
||||||
|
@ -212,8 +188,8 @@ VfatReadCluster(PDEVICE_EXTENSION DeviceExt,
|
||||||
{
|
{
|
||||||
Status = VfatRawReadCluster(DeviceExt,
|
Status = VfatRawReadCluster(DeviceExt,
|
||||||
FirstCluster,
|
FirstCluster,
|
||||||
CurrentCluster,
|
BaseAddress + (i * BytesPerCluster),
|
||||||
BaseAddress + (i * BytesPerCluster));
|
*CurrentCluster);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
if (!NoCache)
|
if (!NoCache)
|
||||||
|
@ -323,7 +299,9 @@ VfatReadFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
|
||||||
* FIXME: Optimize by remembering the last cluster read and using if
|
* FIXME: Optimize by remembering the last cluster read and using if
|
||||||
* possible.
|
* possible.
|
||||||
*/
|
*/
|
||||||
Status = OffsetToCluster(DeviceExt, FirstCluster, ReadOffset,
|
Status = OffsetToCluster(DeviceExt,
|
||||||
|
FirstCluster,
|
||||||
|
ROUND_DOWN(ReadOffset, ChunkSize),
|
||||||
&CurrentCluster);
|
&CurrentCluster);
|
||||||
if (!NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
|
@ -470,7 +448,7 @@ VfatWriteFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
VFATLoadCluster (DeviceExt, Temp, CurrentCluster);
|
VfatRawReadCluster (DeviceExt, FirstCluster, Temp, CurrentCluster);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Overwrite the last parts of the data as necessary */
|
/* Overwrite the last parts of the data as necessary */
|
||||||
|
@ -549,7 +527,7 @@ VfatWriteFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
VFATLoadCluster (DeviceExt, Temp, CurrentCluster);
|
VfatRawReadCluster (DeviceExt, FirstCluster, Temp, CurrentCluster);
|
||||||
CHECKPOINT;
|
CHECKPOINT;
|
||||||
memcpy (Temp, Buffer, Length2);
|
memcpy (Temp, Buffer, Length2);
|
||||||
CHECKPOINT;
|
CHECKPOINT;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: vfat.h,v 1.22 2001/01/13 18:38:09 dwelch Exp $ */
|
/* $Id: vfat.h,v 1.23 2001/01/14 15:05:53 dwelch Exp $ */
|
||||||
|
|
||||||
#include <ddk/ntifs.h>
|
#include <ddk/ntifs.h>
|
||||||
|
|
||||||
|
@ -189,8 +189,9 @@ VfatReadFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
VfatWriteFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
|
VfatWriteFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
|
||||||
PVOID Buffer, ULONG Length, ULONG WriteOffset);
|
PVOID Buffer, ULONG Length, ULONG WriteOffset);
|
||||||
ULONG
|
NTSTATUS
|
||||||
GetNextWriteCluster(PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster);
|
GetNextWriteCluster(PDEVICE_EXTENSION DeviceExt, ULONG CurrentCluster,
|
||||||
|
PULONG NextCluster);
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
IsDeletedEntry(PVOID Block, ULONG Offset);
|
IsDeletedEntry(PVOID Block, ULONG Offset);
|
||||||
BOOLEAN
|
BOOLEAN
|
||||||
|
@ -236,15 +237,18 @@ NTSTATUS
|
||||||
GetNextCluster(PDEVICE_EXTENSION DeviceExt,
|
GetNextCluster(PDEVICE_EXTENSION DeviceExt,
|
||||||
ULONG CurrentCluster,
|
ULONG CurrentCluster,
|
||||||
PULONG NextCluster);
|
PULONG NextCluster);
|
||||||
VOID
|
NTSTATUS
|
||||||
VFATLoadCluster(PDEVICE_EXTENSION DeviceExt, PVOID Buffer, ULONG Cluster);
|
VfatRawReadCluster (PDEVICE_EXTENSION DeviceExt,
|
||||||
|
ULONG FirstCluster,
|
||||||
|
PVOID Buffer,
|
||||||
|
ULONG Cluster);
|
||||||
ULONG
|
ULONG
|
||||||
FAT12CountAvailableClusters(PDEVICE_EXTENSION DeviceExt);
|
FAT12CountAvailableClusters(PDEVICE_EXTENSION DeviceExt);
|
||||||
ULONG
|
ULONG
|
||||||
FAT16CountAvailableClusters(PDEVICE_EXTENSION DeviceExt);
|
FAT16CountAvailableClusters(PDEVICE_EXTENSION DeviceExt);
|
||||||
ULONG
|
ULONG
|
||||||
FAT32CountAvailableClusters(PDEVICE_EXTENSION DeviceExt);
|
FAT32CountAvailableClusters(PDEVICE_EXTENSION DeviceExt);
|
||||||
VOID
|
NTSTATUS
|
||||||
WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
|
WriteCluster (PDEVICE_EXTENSION DeviceExt, ULONG ClusterToWrite,
|
||||||
ULONG NewValue);
|
ULONG NewValue);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue