Enabled caching for FAT32 partitions.

Enabled FAT32 write code.
Various smaller fixes.
Patch by Hartmut Birr (part 2).

svn path=/trunk/; revision=2076
This commit is contained in:
Eric Kohl 2001-07-20 08:00:21 +00:00
parent 7192939c7d
commit 75d57b4fa1
6 changed files with 502 additions and 338 deletions

View file

@ -1,5 +1,5 @@
/*
* $Id: fat.c,v 1.28 2001/07/13 10:31:14 ekohl Exp $
* $Id: fat.c,v 1.29 2001/07/20 08:00:20 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -30,7 +30,7 @@
/* FUNCTIONS ****************************************************************/
NTSTATUS
Fat32GetNextCluster (PDEVICE_EXTENSION DeviceExt,
Fat32GetNextCluster(PDEVICE_EXTENSION DeviceExt,
ULONG CurrentCluster,
PULONG NextCluster)
/*
@ -43,12 +43,15 @@ Fat32GetNextCluster (PDEVICE_EXTENSION DeviceExt,
PCACHE_SEGMENT CacheSeg;
NTSTATUS Status;
ULONG FATOffset;
ULONG ChunkSize;
ChunkSize=CACHEPAGESIZE(DeviceExt);
FATOffset = (DeviceExt->FATStart * BLOCKSIZE) +
(CurrentCluster * sizeof(ULONG));
Status = CcRosRequestCacheSegment(DeviceExt->StorageBcb,
PAGE_ROUND_DOWN(FATOffset),
ROUND_DOWN(FATOffset, ChunkSize),
&BaseAddress,
&Valid,
&CacheSeg);
@ -59,8 +62,8 @@ Fat32GetNextCluster (PDEVICE_EXTENSION DeviceExt,
if (!Valid)
{
Status = VfatReadSectors(DeviceExt->StorageDevice,
PAGE_ROUND_DOWN(FATOffset) / BLOCKSIZE,
PAGESIZE / BLOCKSIZE,
ROUND_DOWN(FATOffset, ChunkSize) / BLOCKSIZE,
ChunkSize / BLOCKSIZE,
BaseAddress);
if (!NT_SUCCESS(Status))
{
@ -69,7 +72,7 @@ Fat32GetNextCluster (PDEVICE_EXTENSION DeviceExt,
}
}
CurrentCluster = *(PULONG)(BaseAddress + (FATOffset % PAGESIZE));
CurrentCluster = *(PULONG)(BaseAddress + (FATOffset % ChunkSize));
if (CurrentCluster >= 0xffffff8 && CurrentCluster <= 0xfffffff)
CurrentCluster = 0xffffffff;
CcRosReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, TRUE);
@ -78,7 +81,7 @@ Fat32GetNextCluster (PDEVICE_EXTENSION DeviceExt,
}
NTSTATUS
Fat16GetNextCluster (PDEVICE_EXTENSION DeviceExt,
Fat16GetNextCluster(PDEVICE_EXTENSION DeviceExt,
ULONG CurrentCluster,
PULONG NextCluster)
/*
@ -127,14 +130,14 @@ Fat16GetNextCluster (PDEVICE_EXTENSION DeviceExt,
}
NTSTATUS
Fat12GetNextCluster (PDEVICE_EXTENSION DeviceExt,
Fat12GetNextCluster(PDEVICE_EXTENSION DeviceExt,
ULONG CurrentCluster,
PULONG NextCluster)
/*
* FUNCTION: Retrieve the next FAT12 cluster from the FAT table
*/
{
unsigned char* CBlock;
PUCHAR CBlock;
ULONG FATOffset;
ULONG Entry;
BOOLEAN Valid;
@ -188,7 +191,7 @@ Fat12GetNextCluster (PDEVICE_EXTENSION DeviceExt,
}
NTSTATUS
FAT16FindAvailableCluster (PDEVICE_EXTENSION DeviceExt,
FAT16FindAvailableCluster(PDEVICE_EXTENSION DeviceExt,
PULONG Cluster)
/*
* FUNCTION: Finds the first available cluster in a FAT16 table
@ -206,7 +209,8 @@ FAT16FindAvailableCluster (PDEVICE_EXTENSION DeviceExt,
ChunkSize = CACHEPAGESIZE(DeviceExt);
FatStart = DeviceExt->FATStart * BLOCKSIZE;
FatLength = DeviceExt->Boot->FATSectors * BLOCKSIZE;
FatLength = (((DeviceExt->Boot->Sectors ? DeviceExt->Boot->Sectors : DeviceExt->Boot->SectorsHuge)-DeviceExt->dataStart)/DeviceExt->Boot->SectorsPerCluster+2)*2;
CacheSeg = NULL;
*Cluster = 0;
@ -255,7 +259,7 @@ FAT16FindAvailableCluster (PDEVICE_EXTENSION DeviceExt,
}
NTSTATUS
FAT12FindAvailableCluster (PDEVICE_EXTENSION DeviceExt, PULONG Cluster)
FAT12FindAvailableCluster(PDEVICE_EXTENSION DeviceExt, PULONG Cluster)
/*
* FUNCTION: Finds the first available cluster in a FAT12 table
*/
@ -328,6 +332,63 @@ FAT32FindAvailableCluster (PDEVICE_EXTENSION DeviceExt, PULONG Cluster)
* FUNCTION: Finds the first available cluster in a FAT32 table
*/
{
ULONG FatLength;
ULONG i;
NTSTATUS Status;
PVOID BaseAddress;
PCACHE_SEGMENT CacheSeg;
BOOLEAN Valid;
ULONG FatStart;
ULONG ChunkSize;
ChunkSize = CACHEPAGESIZE(DeviceExt);
FatStart = DeviceExt->FATStart * BLOCKSIZE;
FatLength = (((DeviceExt->Boot->Sectors ? DeviceExt->Boot->Sectors : DeviceExt->Boot->SectorsHuge)-DeviceExt->dataStart)/DeviceExt->Boot->SectorsPerCluster+2)*4;
CacheSeg = NULL;
*Cluster = 0;
for (i = 4; i < FatLength; i+=4)
{
if (((FatStart + i) % ChunkSize) == 0 || CacheSeg == NULL)
{
if (CacheSeg != NULL)
{
CcRosReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, TRUE);
}
Status = CcRosRequestCacheSegment(DeviceExt->StorageBcb,
ROUND_DOWN(FatStart + i, ChunkSize),
&BaseAddress,
&Valid,
&CacheSeg);
if (!NT_SUCCESS(Status))
{
return(Status);
}
if (!Valid)
{
Status = VfatReadSectors(DeviceExt->StorageDevice,
ROUND_DOWN(FatStart + i, ChunkSize) / BLOCKSIZE,
ChunkSize / BLOCKSIZE,
BaseAddress);
if (!NT_SUCCESS(Status))
{
CcRosReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, FALSE);
return(Status);
}
}
}
if (*((PULONG)(BaseAddress + ((FatStart + i) % ChunkSize))) == 0)
{
DPRINT("Found available cluster 0x%x\n", i);
*Cluster = i / 4;
CcRosReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, TRUE);
return(STATUS_SUCCESS);
}
}
CcRosReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, TRUE);
#if 0
ULONG sector;
PULONG Block;
int i,forto;
@ -371,6 +432,7 @@ FAT32FindAvailableCluster (PDEVICE_EXTENSION DeviceExt, PULONG Cluster)
}
/* Give an error message (out of disk space) if we reach here) */
ExFreePool (Block);
#endif
return (STATUS_DISK_FULL);
}
@ -445,7 +507,7 @@ FAT12CountAvailableClusters(PDEVICE_EXTENSION DeviceExt,
return(STATUS_SUCCESS);
}
#if 0
NTSTATUS
FAT16CountAvailableClusters(PDEVICE_EXTENSION DeviceExt,
PLARGE_INTEGER Clusters)
@ -456,23 +518,50 @@ FAT16CountAvailableClusters(PDEVICE_EXTENSION DeviceExt,
PUSHORT Block;
ULONG ulCount = 0;
ULONG i;
ULONG numberofclusters;
ULONG numberofsectors;
ULONG sector;
ULONG forto;
NTSTATUS Status;
ExAcquireResourceSharedLite (&DeviceExt->FatResource, TRUE);
Block = ExAllocatePool (NonPagedPool, BLOCKSIZE);
Block = (PUSHORT) DeviceExt->FAT;
for (i = 2; i < (DeviceExt->Boot->FATSectors * 256); i++)
numberofclusters = ((DeviceExt->Boot->Sectors ? DeviceExt->Boot->Sectors : DeviceExt->Boot->SectorsHuge)-DeviceExt->dataStart)/DeviceExt->Boot->SectorsPerCluster+2;
numberofsectors = (numberofclusters + 255) / 256;
numberofclusters %= 256;
for (sector = 0; sector < numberofsectors; sector++)
{
Status = VfatReadSectors(DeviceExt->StorageDevice,
DeviceExt->FATStart + sector,
1,
(PUCHAR)Block);
if (!NT_SUCCESS(Status))
{
ExFreePool(Block);
ExReleaseResourceLite(&DeviceExt->FatResource);
return(Status);
}
if (sector == numberofsectors - 1)
forto = numberofclusters;
else
forto = 256;
for (i = 0; i < forto; i++)
{
if (Block[i] == 0)
ulCount++;
}
}
ExReleaseResourceLite (&DeviceExt->FatResource);
Clusters->QuadPart = ulCount;
return(STATUS_SUCCESS);
}
#endif
NTSTATUS
FAT32CountAvailableClusters(PDEVICE_EXTENSION DeviceExt,
@ -486,6 +575,7 @@ FAT32CountAvailableClusters(PDEVICE_EXTENSION DeviceExt,
ULONG ulCount = 0;
ULONG i,forto;
ULONG numberofclusters;
ULONG numberofsectors;
NTSTATUS Status;
ExAcquireResourceSharedLite (&DeviceExt->FatResource, TRUE);
@ -493,11 +583,10 @@ FAT32CountAvailableClusters(PDEVICE_EXTENSION DeviceExt,
Block = ExAllocatePool (NonPagedPool, BLOCKSIZE);
numberofclusters = ((DeviceExt->Boot->Sectors ? DeviceExt->Boot->Sectors : DeviceExt->Boot->SectorsHuge)-DeviceExt->dataStart)/DeviceExt->Boot->SectorsPerCluster+2;
numberofsectors = (numberofclusters +127) / 128;
numberofclusters %= 128;
for (sector = 0;
sector < ((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32;
sector++)
for (sector = 0; sector < numberofsectors; sector++)
{
Status = VfatReadSectors(DeviceExt->StorageDevice,
(ULONG) (DeviceExt->FATStart + sector), 1,
@ -509,7 +598,7 @@ FAT32CountAvailableClusters(PDEVICE_EXTENSION DeviceExt,
return(Status);
}
if (sector==((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32-1)
if (sector == numberofsectors - 1)
forto=numberofclusters;
else
forto=128;
@ -668,7 +757,7 @@ FAT16WriteCluster(PDEVICE_EXTENSION DeviceExt,
FATOffset = FATOffset + DeviceExt->Boot->FATSectors * BLOCKSIZE;
}
return (STATUS_SUCCESS);
return(STATUS_SUCCESS);
}
NTSTATUS
@ -679,37 +768,62 @@ FAT32WriteCluster(PDEVICE_EXTENSION DeviceExt,
* FUNCTION: Writes a cluster to the FAT32 physical tables
*/
{
#if 0
ULONG FATsector;
ULONG FATeis;
PUSHORT Block;
PVOID BaseAddress;
BOOLEAN Valid;
PCACHE_SEGMENT CacheSeg;
NTSTATUS Status;
ULONG FATOffset;
ULONG Start;
int i;
struct _BootSector32 *pBoot;
DbgPrint ("FAT32WriteCluster %u : %u\n", ClusterToWrite, NewValue);
Block = ExAllocatePool (NonPagedPool, BLOCKSIZE);
FATsector = ClusterToWrite / 128;
FATeis = ClusterToWrite - (FATsector * 128);
/* load sector, change value, then rewrite sector */
/* FIXME: Check status */
VfatReadSectors (DeviceExt->StorageDevice,
DeviceExt->FATStart + FATsector, 1, (UCHAR *) Block);
Block[FATeis] = NewValue;
/* Write the changed FAT sector to disk (all FAT's) */
Start = DeviceExt->FATStart + FATsector;
pBoot = (struct _BootSector32 *) DeviceExt->Boot;
for (i = 0; i < pBoot->FATCount; i++)
ULONG i;
ULONG ChunkSize;
ChunkSize = CACHEPAGESIZE(DeviceExt);
Start = DeviceExt->FATStart;
FATOffset = (Start * BLOCKSIZE) + (ClusterToWrite * 4);
for (i = 0; i < DeviceExt->Boot->FATCount; i++)
{
/* FIXME: Check status */
VfatWriteSectors (DeviceExt->StorageDevice, Start, 1, (UCHAR *) Block);
Start += pBoot->FATSectors;
Status = CcRosRequestCacheSegment(DeviceExt->StorageBcb,
ROUND_DOWN(FATOffset, ChunkSize),
&BaseAddress,
&Valid,
&CacheSeg);
if (!NT_SUCCESS(Status))
{
return(Status);
}
if (!Valid)
{
Status = VfatReadSectors(DeviceExt->StorageDevice,
ROUND_DOWN(FATOffset, ChunkSize) / BLOCKSIZE,
ChunkSize / BLOCKSIZE,
BaseAddress);
if (!NT_SUCCESS(Status))
{
CcRosReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, FALSE);
return(Status);
}
}
DPRINT("Writing 0x%x for offset 0x%x 0x%x\n", NewValue, FATOffset,
ClusterToWrite);
*((PULONG)(BaseAddress + (FATOffset % ChunkSize))) = NewValue;
Status = VfatWriteSectors(DeviceExt->StorageDevice,
ROUND_DOWN(FATOffset, ChunkSize) / BLOCKSIZE,
ChunkSize / BLOCKSIZE,
BaseAddress);
CcRosReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, TRUE);
DPRINT("DeviceExt->Boot->FATSectors %d\n",
((struct _BootSector32 *)DeviceExt->Boot)->FATSectors32);
FATOffset += ((struct _BootSector32 *)DeviceExt->Boot)->FATSectors32 * BLOCKSIZE;
}
ExFreePool (Block);
#endif
// KeBugCheck(0);
return(STATUS_SUCCESS);
}
NTSTATUS
WriteCluster(PDEVICE_EXTENSION DeviceExt,
ULONG ClusterToWrite,
@ -722,21 +836,22 @@ WriteCluster(PDEVICE_EXTENSION DeviceExt,
if (DeviceExt->FatType == FAT16)
{
Status = FAT16WriteCluster (DeviceExt, ClusterToWrite, NewValue);
Status = FAT16WriteCluster(DeviceExt, ClusterToWrite, NewValue);
}
else if (DeviceExt->FatType == FAT32)
{
Status = FAT32WriteCluster (DeviceExt, ClusterToWrite, NewValue);
Status = FAT32WriteCluster(DeviceExt, ClusterToWrite, NewValue);
}
else
{
Status = FAT12WriteCluster (DeviceExt, ClusterToWrite, NewValue);
Status = FAT12WriteCluster(DeviceExt, ClusterToWrite, NewValue);
}
return(Status);
}
ULONG
ClusterToSector (PDEVICE_EXTENSION DeviceExt, unsigned long Cluster)
ClusterToSector(PDEVICE_EXTENSION DeviceExt,
ULONG Cluster)
/*
* FUNCTION: Converts the cluster number to a sector number for this physical
* device
@ -759,7 +874,7 @@ VfatRawReadCluster(PDEVICE_EXTENSION DeviceExt,
if (FirstCluster == 1)
{
Status = VfatReadSectors (DeviceExt->StorageDevice,
Status = VfatReadSectors(DeviceExt->StorageDevice,
Cluster,
DeviceExt->Boot->SectorsPerCluster,
Buffer);
@ -769,11 +884,12 @@ VfatRawReadCluster(PDEVICE_EXTENSION DeviceExt,
{
ULONG Sector;
Sector = ClusterToSector (DeviceExt, Cluster);
Sector = ClusterToSector(DeviceExt, Cluster);
Status = VfatReadSectors (DeviceExt->StorageDevice,
Sector, DeviceExt->Boot->SectorsPerCluster,
Status = VfatReadSectors(DeviceExt->StorageDevice,
Sector,
DeviceExt->Boot->SectorsPerCluster,
Buffer);
return(Status);
}
@ -791,7 +907,7 @@ VfatRawWriteCluster(PDEVICE_EXTENSION DeviceExt,
ULONG Sector;
NTSTATUS Status;
DPRINT ("VfatWriteCluster(DeviceExt %x, Buffer %x, Cluster %d)\n",
DPRINT("VfatWriteCluster(DeviceExt %x, Buffer %x, Cluster %d)\n",
DeviceExt, Buffer, Cluster);
if (FirstCluster == 1)
@ -815,7 +931,7 @@ VfatRawWriteCluster(PDEVICE_EXTENSION DeviceExt,
}
NTSTATUS
GetNextCluster (PDEVICE_EXTENSION DeviceExt,
GetNextCluster(PDEVICE_EXTENSION DeviceExt,
ULONG CurrentCluster,
PULONG NextCluster,
BOOLEAN Extend)
@ -825,17 +941,16 @@ GetNextCluster (PDEVICE_EXTENSION DeviceExt,
{
NTSTATUS Status;
// DPRINT ("GetNextCluster(DeviceExt %x, CurrentCluster %x)\n",
// DeviceExt, CurrentCluster);
if (Extend)
{
ExAcquireResourceSharedLite (&DeviceExt->FatResource, TRUE);
ExAcquireResourceSharedLite(&DeviceExt->FatResource, TRUE);
}
else
{
ExAcquireResourceExclusiveLite (&DeviceExt->FatResource, TRUE);
ExAcquireResourceExclusiveLite(&DeviceExt->FatResource, TRUE);
}
/*
@ -848,7 +963,7 @@ GetNextCluster (PDEVICE_EXTENSION DeviceExt,
if (DeviceExt->FatType == FAT16)
{
Status = FAT16FindAvailableCluster (DeviceExt, &NewCluster);
Status = FAT16FindAvailableCluster(DeviceExt, &NewCluster);
if (!NT_SUCCESS(Status))
{
return(Status);
@ -856,7 +971,7 @@ GetNextCluster (PDEVICE_EXTENSION DeviceExt,
}
else if (DeviceExt->FatType == FAT32)
{
Status = FAT32FindAvailableCluster (DeviceExt, &NewCluster);
Status = FAT32FindAvailableCluster(DeviceExt, &NewCluster);
if (!NT_SUCCESS(Status))
{
return(Status);
@ -864,7 +979,7 @@ GetNextCluster (PDEVICE_EXTENSION DeviceExt,
}
else
{
Status = FAT12FindAvailableCluster (DeviceExt, &NewCluster);
Status = FAT12FindAvailableCluster(DeviceExt, &NewCluster);
if (!NT_SUCCESS(Status))
{
return(Status);
@ -884,15 +999,15 @@ GetNextCluster (PDEVICE_EXTENSION DeviceExt,
if (DeviceExt->FatType == FAT16)
{
Status = Fat16GetNextCluster (DeviceExt, CurrentCluster, NextCluster);
Status = Fat16GetNextCluster(DeviceExt, CurrentCluster, NextCluster);
}
else if (DeviceExt->FatType == FAT32)
{
Status = Fat32GetNextCluster (DeviceExt, CurrentCluster, NextCluster);
Status = Fat32GetNextCluster(DeviceExt, CurrentCluster, NextCluster);
}
else
{
Status = Fat12GetNextCluster (DeviceExt, CurrentCluster, NextCluster);
Status = Fat12GetNextCluster(DeviceExt, CurrentCluster, NextCluster);
}
if (Extend && (*NextCluster) == 0xFFFFFFFF)
{
@ -902,7 +1017,7 @@ GetNextCluster (PDEVICE_EXTENSION DeviceExt,
/* Firstly, find the next available open allocation unit */
if (DeviceExt->FatType == FAT16)
{
Status = FAT16FindAvailableCluster (DeviceExt, &NewCluster);
Status = FAT16FindAvailableCluster(DeviceExt, &NewCluster);
if (!NT_SUCCESS(Status))
{
return(Status);
@ -910,7 +1025,7 @@ GetNextCluster (PDEVICE_EXTENSION DeviceExt,
}
else if (DeviceExt->FatType == FAT32)
{
Status = FAT32FindAvailableCluster (DeviceExt, &NewCluster);
Status = FAT32FindAvailableCluster(DeviceExt, &NewCluster);
if (!NT_SUCCESS(Status))
{
return(Status);
@ -918,27 +1033,28 @@ GetNextCluster (PDEVICE_EXTENSION DeviceExt,
}
else
{
Status = FAT12FindAvailableCluster (DeviceExt, &NewCluster);
Status = FAT12FindAvailableCluster(DeviceExt, &NewCluster);
if (!NT_SUCCESS(Status))
{
return(Status);
}
}
/* 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
found AU */
WriteCluster (DeviceExt, CurrentCluster, NewCluster);
WriteCluster(DeviceExt, CurrentCluster, NewCluster);
*NextCluster = NewCluster;
}
ExReleaseResourceLite (&DeviceExt->FatResource);
ExReleaseResourceLite(&DeviceExt->FatResource);
return (Status);
return(Status);
}
NTSTATUS
GetNextSector (PDEVICE_EXTENSION DeviceExt,
GetNextSector(PDEVICE_EXTENSION DeviceExt,
ULONG CurrentSector,
PULONG NextSector,
BOOLEAN Extend)
@ -947,7 +1063,9 @@ GetNextSector (PDEVICE_EXTENSION DeviceExt,
{
NTSTATUS Status;
DPRINT ("GetNextSector(DeviceExt %x, CurrentSector %x)\n",DeviceExt, CurrentSector);
DPRINT("GetNextSector(DeviceExt %x, CurrentSector %x)\n",
DeviceExt,
CurrentSector);
if (CurrentSector<DeviceExt->dataStart || ((CurrentSector - DeviceExt->dataStart + 1) % DeviceExt -> Boot -> SectorsPerCluster))
/* Basically, if the next sequential sector would be on a cluster border, then we'll need to check in the FAT */
{
@ -966,11 +1084,11 @@ GetNextSector (PDEVICE_EXTENSION DeviceExt,
if ((*NextSector) == 0 || (*NextSector) == 0xffffffff)
{
/* The caller wants to know a sector. These FAT codes don't correspond to any sector. */
return (STATUS_UNSUCCESSFUL);
return(STATUS_UNSUCCESSFUL);
}
(*NextSector)=ClusterToSector(DeviceExt,(*NextSector));
return (STATUS_SUCCESS);
(*NextSector) = ClusterToSector(DeviceExt,(*NextSector));
return(STATUS_SUCCESS);
}
}

View file

@ -1,4 +1,4 @@
/* $Id: fcb.c,v 1.5 2001/07/14 18:21:23 ekohl Exp $
/* $Id: fcb.c,v 1.6 2001/07/20 08:00:20 ekohl Exp $
*
*
* FILE: fcb.c
@ -27,7 +27,8 @@
/* -------------------------------------------------------- PUBLICS */
PVFATFCB vfatNewFCB (PWCHAR pFileName)
PVFATFCB
vfatNewFCB(PWCHAR pFileName)
{
PVFATFCB rcFCB;
@ -49,24 +50,26 @@ PVFATFCB vfatNewFCB (PWCHAR pFileName)
return rcFCB;
}
void vfatDestroyFCB (PVFATFCB pFCB)
VOID
vfatDestroyFCB(PVFATFCB pFCB)
{
ExFreePool (pFCB);
}
BOOL
vfatFCBIsDirectory (PDEVICE_EXTENSION pVCB, PVFATFCB FCB)
vfatFCBIsDirectory(PDEVICE_EXTENSION pVCB, PVFATFCB FCB)
{
return FCB->entry.Attrib & FILE_ATTRIBUTE_DIRECTORY;
}
BOOL
vfatFCBIsRoot (PVFATFCB FCB)
vfatFCBIsRoot(PVFATFCB FCB)
{
return wcscmp (FCB->PathName, L"\\") == 0;
}
void vfatGrabFCB (PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
VOID
vfatGrabFCB(PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
{
KIRQL oldIrql;
@ -80,7 +83,8 @@ void vfatGrabFCB (PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
KeReleaseSpinLock (&pVCB->FcbListLock, oldIrql);
}
void vfatReleaseFCB (PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
VOID
vfatReleaseFCB(PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
{
KIRQL oldIrql;
@ -100,7 +104,8 @@ void vfatReleaseFCB (PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
KeReleaseSpinLock (&pVCB->FcbListLock, oldIrql);
}
void vfatAddFCBToTable (PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
VOID
vfatAddFCBToTable(PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
{
KIRQL oldIrql;
@ -111,7 +116,7 @@ void vfatAddFCBToTable (PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
}
PVFATFCB
vfatGrabFCBFromTable (PDEVICE_EXTENSION pVCB, PWSTR pFileName)
vfatGrabFCBFromTable(PDEVICE_EXTENSION pVCB, PWSTR pFileName)
{
KIRQL oldIrql;
PVFATFCB rcFCB;
@ -184,7 +189,7 @@ vfatFCBInitializeCache (PVCB vcb, PVFATFCB fcb)
}
NTSTATUS
vfatRequestAndValidateRegion (PDEVICE_EXTENSION pDeviceExt,
vfatRequestAndValidateRegion(PDEVICE_EXTENSION pDeviceExt,
PVFATFCB pFCB,
ULONG pOffset,
PVOID * pBuffer,
@ -276,17 +281,17 @@ vfatReleaseRegion (PDEVICE_EXTENSION pDeviceExt,
}
PVFATFCB
vfatMakeRootFCB (PDEVICE_EXTENSION pVCB)
vfatMakeRootFCB(PDEVICE_EXTENSION pVCB)
{
PVFATFCB FCB;
FCB = vfatNewFCB (L"\\");
memset (FCB->entry.Filename, ' ', 11);
FCB = vfatNewFCB(L"\\");
memset(FCB->entry.Filename, ' ', 11);
FCB->entry.FileSize = pVCB->rootDirectorySectors * BLOCKSIZE;
FCB->entry.Attrib = FILE_ATTRIBUTE_DIRECTORY;
if (pVCB->FatType == FAT32)
{
FCB->entry.FirstCluster = 2;
FCB->entry.FirstCluster = ((struct _BootSector32*)(pVCB->Boot))->RootCluster;
}
else
{
@ -294,15 +299,15 @@ vfatMakeRootFCB (PDEVICE_EXTENSION pVCB)
}
FCB->RefCount = 1;
vfatFCBInitializeCache (pVCB, FCB);
vfatAddFCBToTable (pVCB, FCB);
vfatFCBInitializeCache(pVCB, FCB);
vfatAddFCBToTable(pVCB, FCB);
vfatGrabFCB(pVCB, FCB);
return FCB;
return(FCB);
}
PVFATFCB
vfatOpenRootFCB (PDEVICE_EXTENSION pVCB)
vfatOpenRootFCB(PDEVICE_EXTENSION pVCB)
{
PVFATFCB FCB;
@ -316,7 +321,7 @@ vfatOpenRootFCB (PDEVICE_EXTENSION pVCB)
}
NTSTATUS
vfatMakeFCBFromDirEntry (PVCB vcb,
vfatMakeFCBFromDirEntry(PVCB vcb,
PVFATFCB directoryFCB,
PWSTR longName,
PFAT_DIR_ENTRY dirEntry,

View file

@ -1,4 +1,4 @@
/* $Id: iface.c,v 1.56 2001/07/17 07:48:06 ekohl Exp $
/* $Id: iface.c,v 1.57 2001/07/20 08:00:20 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -58,7 +58,7 @@ VfatHasFileSystem(PDEVICE_OBJECT DeviceToMount,
Status = VfatReadSectors(DeviceToMount, 0, 1, (UCHAR *) Boot);
if (!NT_SUCCESS(Status))
{
return Status;
return(Status);
}
DPRINT("Boot->SysType %.5s\n", Boot->SysType);
@ -75,12 +75,13 @@ VfatHasFileSystem(PDEVICE_OBJECT DeviceToMount,
ExFreePool(Boot);
return STATUS_SUCCESS;
return(STATUS_SUCCESS);
}
static NTSTATUS
VfatMountDevice (PDEVICE_EXTENSION DeviceExt, PDEVICE_OBJECT DeviceToMount)
VfatMountDevice(PDEVICE_EXTENSION DeviceExt,
PDEVICE_OBJECT DeviceToMount)
/*
* FUNCTION: Mounts the device
*/
@ -95,7 +96,7 @@ VfatMountDevice (PDEVICE_EXTENSION DeviceExt, PDEVICE_OBJECT DeviceToMount)
Status = VfatReadSectors(DeviceToMount, 0, 1, (UCHAR *) DeviceExt->Boot);
if (!NT_SUCCESS(Status))
{
return Status;
return(Status);
}
DeviceExt->FATStart = DeviceExt->Boot->ReservedSectors;
@ -136,10 +137,10 @@ VfatMountDevice (PDEVICE_EXTENSION DeviceExt, PDEVICE_OBJECT DeviceToMount)
DbgPrint("FAT32\n");
DeviceExt->FatType = FAT32;
DeviceExt->rootDirectorySectors = DeviceExt->Boot->SectorsPerCluster;
DeviceExt->rootStart =
DeviceExt->FATStart + DeviceExt->Boot->FATCount
DeviceExt->dataStart = DeviceExt->FATStart + DeviceExt->Boot->FATCount
* ((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32;
DeviceExt->dataStart = DeviceExt->rootStart;
DeviceExt->rootStart = ClusterToSector (DeviceExt,
((struct _BootSector32 *)(DeviceExt->Boot))->RootCluster);
}
else
{
@ -147,7 +148,7 @@ VfatMountDevice (PDEVICE_EXTENSION DeviceExt, PDEVICE_OBJECT DeviceToMount)
DeviceExt->FatType = FAT16;
}
return STATUS_SUCCESS;
return(STATUS_SUCCESS);
}
@ -165,13 +166,13 @@ VfatMount (PDEVICE_OBJECT DeviceToMount)
Status = VfatHasFileSystem (DeviceToMount, &RecognizedFS);
if (!NT_SUCCESS(Status))
{
return Status;
return(Status);
}
if (RecognizedFS == FALSE)
{
DPRINT("VFAT: Unrecognized Volume\n");
return STATUS_UNRECOGNIZED_VOLUME;
return(STATUS_UNRECOGNIZED_VOLUME);
}
DPRINT("VFAT: Recognized volume\n");
@ -185,37 +186,60 @@ VfatMount (PDEVICE_OBJECT DeviceToMount)
&DeviceObject);
if (!NT_SUCCESS(Status))
{
return Status;
return(Status);
}
DeviceObject->Flags = DeviceObject->Flags | DO_DIRECT_IO;
DeviceExt = (PVOID) DeviceObject->DeviceExtension;
/* use same vpb as device disk */
DeviceObject->Vpb = DeviceToMount->Vpb;
Status = VfatMountDevice (DeviceExt, DeviceToMount);
Status = VfatMountDevice(DeviceExt,
DeviceToMount);
if (!NT_SUCCESS(Status))
{
/* FIXME: delete device object */
return Status;
return(Status);
}
#if 1
DbgPrint("BytesPerSector: %d\n", DeviceExt->Boot->BytesPerSector);
DbgPrint("SectorsPerCluster: %d\n", DeviceExt->Boot->SectorsPerCluster);
DbgPrint("ReservedSectors: %d\n", DeviceExt->Boot->ReservedSectors);
DbgPrint("FATCount: %d\n", DeviceExt->Boot->FATCount);
DbgPrint("RootEntries: %d\n", DeviceExt->Boot->RootEntries);
DbgPrint("Sectors: %d\n", DeviceExt->Boot->Sectors);
DbgPrint("FATSectors: %d\n", DeviceExt->Boot->FATSectors);
DbgPrint("SectorsPerTrack: %d\n", DeviceExt->Boot->SectorsPerTrack);
DbgPrint("Heads: %d\n", DeviceExt->Boot->Heads);
DbgPrint("HiddenSectors: %d\n", DeviceExt->Boot->HiddenSectors);
DbgPrint("SectorsHuge: %d\n", DeviceExt->Boot->SectorsHuge);
DbgPrint("RootStart: %d\n", DeviceExt->rootStart);
DbgPrint("DataStart: %d\n", DeviceExt->dataStart);
if (DeviceExt->FatType == FAT32)
{
DbgPrint("FATSectors32: %d\n",
((struct _BootSector32*)(DeviceExt->Boot))->FATSectors32);
DbgPrint("RootCluster: %d\n",
((struct _BootSector32*)(DeviceExt->Boot))->RootCluster);
DbgPrint("FSInfoSector: %d\n",
((struct _BootSector32*)(DeviceExt->Boot))->FSInfoSector);
DbgPrint("BootBackup: %d\n",
((struct _BootSector32*)(DeviceExt->Boot))->BootBackup);
}
#endif
DeviceObject->Vpb->Flags |= VPB_MOUNTED;
DeviceExt->StorageDevice = IoAttachDeviceToDeviceStack(DeviceObject,
DeviceToMount);
DeviceExt->StreamStorageDevice = IoCreateStreamFileObject(NULL,
DeviceExt->StorageDevice);
if (DeviceExt->FatType == FAT16)
Status = CcRosInitializeFileCache(DeviceExt->StreamStorageDevice,
&DeviceExt->StorageBcb,
CACHEPAGESIZE(DeviceExt));
else
Status = CcRosInitializeFileCache(DeviceExt->StreamStorageDevice,
&DeviceExt->StorageBcb,
PAGESIZE);
if (!NT_SUCCESS(Status))
{
/* FIXME: delete device object */
return Status;
return(Status);
}
if (DeviceExt->FatType == FAT12)
@ -228,14 +252,14 @@ VfatMount (PDEVICE_OBJECT DeviceToMount)
if (!NT_SUCCESS(Status))
{
/* FIXME: delete device object */
return Status;
return(Status);
}
}
ExInitializeResourceLite (&DeviceExt->DirResource);
ExInitializeResourceLite (&DeviceExt->FatResource);
ExInitializeResourceLite(&DeviceExt->DirResource);
ExInitializeResourceLite(&DeviceExt->FatResource);
KeInitializeSpinLock (&DeviceExt->FcbListLock);
InitializeListHead (&DeviceExt->FcbListHead);
KeInitializeSpinLock(&DeviceExt->FcbListLock);
InitializeListHead(&DeviceExt->FcbListHead);
/* read serial number */
if (DeviceExt->FatType == FAT12 || DeviceExt->FatType == FAT16)
@ -246,14 +270,16 @@ VfatMount (PDEVICE_OBJECT DeviceToMount)
((struct _BootSector32 *) (DeviceExt->Boot))->VolumeID;
/* read volume label */
ReadVolumeLabel(DeviceExt, DeviceObject->Vpb);
ReadVolumeLabel(DeviceExt,
DeviceObject->Vpb);
return STATUS_SUCCESS;
return(STATUS_SUCCESS);
}
NTSTATUS STDCALL
VfatFileSystemControl (PDEVICE_OBJECT DeviceObject, PIRP Irp)
VfatFileSystemControl(PDEVICE_OBJECT DeviceObject,
PIRP Irp)
/*
* FUNCTION: File system control
*/

View file

@ -1,5 +1,5 @@
/* $Id: rw.c,v 1.24 2001/05/04 01:21:45 rex Exp $
/* $Id: rw.c,v 1.25 2001/07/20 08:00:20 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -369,10 +369,12 @@ VfatReadFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
assert (FileObject != NULL);
assert (FileObject->FsContext != NULL);
DPRINT ("VfatReadFile(DeviceExt %x, FileObject %x, Buffer %x, "
DPRINT("VfatReadFile(DeviceExt %x, FileObject %x, Buffer %x, "
"Length %d, ReadOffset 0x%x)\n", DeviceExt, FileObject, Buffer,
Length, ReadOffset);
*LengthRead = 0;
Fcb = ((PVFATCCB)FileObject->FsContext2)->pFcb;
/*
@ -412,8 +414,6 @@ VfatReadFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
ChunkSize = PAGESIZE;
}
*LengthRead = 0;
/*
* Find the cluster to start the read from
* FIXME: Optimize by remembering the last cluster read and using if

View file

@ -1,8 +1,9 @@
/* $Id: vfat.h,v 1.32 2001/07/05 01:51:53 rex Exp $ */
/* $Id: vfat.h,v 1.33 2001/07/20 08:00:21 ekohl Exp $ */
#include <ddk/ntifs.h>
struct _BootSector {
struct _BootSector
{
unsigned char magic0, res0, magic1;
unsigned char OEMName[8];
unsigned short BytesPerSector;
@ -19,22 +20,43 @@ struct _BootSector {
unsigned char Res2[450];
} __attribute__((packed));
struct _BootSector32 {
unsigned char magic0, res0, magic1;
unsigned char OEMName[8];
unsigned short BytesPerSector;
unsigned char SectorsPerCluster;
unsigned short ReservedSectors;
unsigned char FATCount;
unsigned short RootEntries, Sectors;
unsigned char Media;
unsigned short FATSectors, SectorsPerTrack, Heads;
unsigned long HiddenSectors, SectorsHuge;
unsigned long FATSectors32;
unsigned char x[27];
unsigned long VolumeID;
unsigned char VolumeLabel[11], SysType[8];
unsigned char Res2[422];
struct _BootSector32
{
unsigned char magic0, res0, magic1; // 0
unsigned char OEMName[8]; // 3
unsigned short BytesPerSector; // 11
unsigned char SectorsPerCluster; // 13
unsigned short ReservedSectors; // 14
unsigned char FATCount; // 16
unsigned short RootEntries, Sectors; // 17
unsigned char Media; // 21
unsigned short FATSectors, SectorsPerTrack, Heads; // 22
unsigned long HiddenSectors, SectorsHuge; // 28
unsigned long FATSectors32; // 36
unsigned short ExtFlag; // 40
unsigned short FSVersion; // 42
unsigned long RootCluster; // 44
unsigned short FSInfoSector; // 48
unsigned long BootBackup; // 50
unsigned char Res3[10]; // 54
unsigned char Drive; // 64
unsigned char Res4; // 65
unsigned char ExtBootSignature; // 66
unsigned long VolumeID; // 67
unsigned char VolumeLabel[11], SysType[8]; // 71
unsigned char Res2[418]; // 90
unsigned long Signature1; // 508
} __attribute__((packed));
struct _BootBackupSector
{
unsigned long ExtBootSignature2; // 0
unsigned char Res6[480]; // 4
unsigned long FSINFOSignature; // 484
unsigned long FreeCluster; // 488
unsigned long NextCluster; // 492
unsigned char Res7[12]; // 496
unsigned long Signatur2; // 508
} __attribute__((packed));
typedef struct _BootSector BootSector;

View file

@ -1,4 +1,4 @@
/* $Id: volume.c,v 1.10 2001/06/14 10:02:59 ekohl Exp $
/* $Id: volume.c,v 1.11 2001/07/20 08:00:21 ekohl Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -124,15 +124,8 @@ FsdGetFsSizeInformation(PDEVICE_OBJECT DeviceObject,
FsSizeInfo->TotalAllocationUnits.QuadPart = ((BootSect->Sectors ? BootSect->Sectors : BootSect->SectorsHuge)-DeviceExt->dataStart)/BootSect->SectorsPerCluster;
if (DeviceExt->FatType == FAT16)
#if 0
Status = FAT16CountAvailableClusters(DeviceExt,
&FsSizeInfo->AvailableAllocationUnits);
#else
{
FsSizeInfo->AvailableAllocationUnits.QuadPart = 0;
Status = STATUS_SUCCESS;
}
#endif
else
Status = FAT12CountAvailableClusters(DeviceExt,
&FsSizeInfo->AvailableAllocationUnits);
@ -179,7 +172,7 @@ FsdSetFsLabelInformation(PDEVICE_OBJECT DeviceObject,
{
DPRINT("FsdSetFsLabelInformation()\n");
return STATUS_NOT_IMPLEMENTED;
return(STATUS_NOT_IMPLEMENTED);
}
@ -284,7 +277,7 @@ VfatSetVolumeInformation(PDEVICE_OBJECT DeviceObject,
DeviceObject,
Irp);
Stack = IoGetCurrentIrpStackLocation (Irp);
Stack = IoGetCurrentIrpStackLocation(Irp);
FsInformationClass = Stack->Parameters.SetVolume.FsInformationClass;
BufferLength = Stack->Parameters.SetVolume.Length;
SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
@ -295,7 +288,7 @@ VfatSetVolumeInformation(PDEVICE_OBJECT DeviceObject,
DPRINT("BufferLength %d\n", BufferLength);
DPRINT("SystemBuffer %x\n", SystemBuffer);
switch (FsInformationClass)
switch(FsInformationClass)
{
case FileFsLabelInformation:
Status = FsdSetFsLabelInformation(DeviceObject,