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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -43,12 +43,15 @@ Fat32GetNextCluster (PDEVICE_EXTENSION DeviceExt,
PCACHE_SEGMENT CacheSeg; PCACHE_SEGMENT CacheSeg;
NTSTATUS Status; NTSTATUS Status;
ULONG FATOffset; ULONG FATOffset;
ULONG ChunkSize;
ChunkSize=CACHEPAGESIZE(DeviceExt);
FATOffset = (DeviceExt->FATStart * BLOCKSIZE) + FATOffset = (DeviceExt->FATStart * BLOCKSIZE) +
(CurrentCluster * sizeof(ULONG)); (CurrentCluster * sizeof(ULONG));
Status = CcRosRequestCacheSegment(DeviceExt->StorageBcb, Status = CcRosRequestCacheSegment(DeviceExt->StorageBcb,
PAGE_ROUND_DOWN(FATOffset), ROUND_DOWN(FATOffset, ChunkSize),
&BaseAddress, &BaseAddress,
&Valid, &Valid,
&CacheSeg); &CacheSeg);
@ -59,8 +62,8 @@ Fat32GetNextCluster (PDEVICE_EXTENSION DeviceExt,
if (!Valid) if (!Valid)
{ {
Status = VfatReadSectors(DeviceExt->StorageDevice, Status = VfatReadSectors(DeviceExt->StorageDevice,
PAGE_ROUND_DOWN(FATOffset) / BLOCKSIZE, ROUND_DOWN(FATOffset, ChunkSize) / BLOCKSIZE,
PAGESIZE / BLOCKSIZE, ChunkSize / BLOCKSIZE,
BaseAddress); BaseAddress);
if (!NT_SUCCESS(Status)) 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) if (CurrentCluster >= 0xffffff8 && CurrentCluster <= 0xfffffff)
CurrentCluster = 0xffffffff; CurrentCluster = 0xffffffff;
CcRosReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, TRUE); CcRosReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, TRUE);
@ -134,7 +137,7 @@ Fat12GetNextCluster (PDEVICE_EXTENSION DeviceExt,
* FUNCTION: Retrieve the next FAT12 cluster from the FAT table * FUNCTION: Retrieve the next FAT12 cluster from the FAT table
*/ */
{ {
unsigned char* CBlock; PUCHAR CBlock;
ULONG FATOffset; ULONG FATOffset;
ULONG Entry; ULONG Entry;
BOOLEAN Valid; BOOLEAN Valid;
@ -206,7 +209,8 @@ FAT16FindAvailableCluster (PDEVICE_EXTENSION DeviceExt,
ChunkSize = CACHEPAGESIZE(DeviceExt); ChunkSize = CACHEPAGESIZE(DeviceExt);
FatStart = DeviceExt->FATStart * BLOCKSIZE; 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; CacheSeg = NULL;
*Cluster = 0; *Cluster = 0;
@ -328,6 +332,63 @@ 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
*/ */
{ {
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; ULONG sector;
PULONG Block; PULONG Block;
int i,forto; 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) */ /* Give an error message (out of disk space) if we reach here) */
ExFreePool (Block); ExFreePool (Block);
#endif
return (STATUS_DISK_FULL); return (STATUS_DISK_FULL);
} }
@ -445,7 +507,7 @@ FAT12CountAvailableClusters(PDEVICE_EXTENSION DeviceExt,
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
#if 0
NTSTATUS NTSTATUS
FAT16CountAvailableClusters(PDEVICE_EXTENSION DeviceExt, FAT16CountAvailableClusters(PDEVICE_EXTENSION DeviceExt,
PLARGE_INTEGER Clusters) PLARGE_INTEGER Clusters)
@ -456,23 +518,50 @@ FAT16CountAvailableClusters(PDEVICE_EXTENSION DeviceExt,
PUSHORT Block; PUSHORT Block;
ULONG ulCount = 0; ULONG ulCount = 0;
ULONG i; ULONG i;
ULONG numberofclusters;
ULONG numberofsectors;
ULONG sector;
ULONG forto;
NTSTATUS Status;
ExAcquireResourceSharedLite (&DeviceExt->FatResource, TRUE); ExAcquireResourceSharedLite (&DeviceExt->FatResource, TRUE);
Block = ExAllocatePool (NonPagedPool, BLOCKSIZE);
Block = (PUSHORT) DeviceExt->FAT; numberofclusters = ((DeviceExt->Boot->Sectors ? DeviceExt->Boot->Sectors : DeviceExt->Boot->SectorsHuge)-DeviceExt->dataStart)/DeviceExt->Boot->SectorsPerCluster+2;
for (i = 2; i < (DeviceExt->Boot->FATSectors * 256); i++) 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) if (Block[i] == 0)
ulCount++; ulCount++;
} }
}
ExReleaseResourceLite (&DeviceExt->FatResource); ExReleaseResourceLite (&DeviceExt->FatResource);
Clusters->QuadPart = ulCount; Clusters->QuadPart = ulCount;
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
#endif
NTSTATUS NTSTATUS
FAT32CountAvailableClusters(PDEVICE_EXTENSION DeviceExt, FAT32CountAvailableClusters(PDEVICE_EXTENSION DeviceExt,
@ -486,6 +575,7 @@ FAT32CountAvailableClusters(PDEVICE_EXTENSION DeviceExt,
ULONG ulCount = 0; ULONG ulCount = 0;
ULONG i,forto; ULONG i,forto;
ULONG numberofclusters; ULONG numberofclusters;
ULONG numberofsectors;
NTSTATUS Status; NTSTATUS Status;
ExAcquireResourceSharedLite (&DeviceExt->FatResource, TRUE); ExAcquireResourceSharedLite (&DeviceExt->FatResource, TRUE);
@ -493,11 +583,10 @@ FAT32CountAvailableClusters(PDEVICE_EXTENSION DeviceExt,
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 = ((DeviceExt->Boot->Sectors ? DeviceExt->Boot->Sectors : DeviceExt->Boot->SectorsHuge)-DeviceExt->dataStart)/DeviceExt->Boot->SectorsPerCluster+2;
numberofsectors = (numberofclusters +127) / 128;
numberofclusters %= 128; numberofclusters %= 128;
for (sector = 0; for (sector = 0; sector < numberofsectors; sector++)
sector < ((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32;
sector++)
{ {
Status = VfatReadSectors(DeviceExt->StorageDevice, Status = VfatReadSectors(DeviceExt->StorageDevice,
(ULONG) (DeviceExt->FATStart + sector), 1, (ULONG) (DeviceExt->FATStart + sector), 1,
@ -509,7 +598,7 @@ FAT32CountAvailableClusters(PDEVICE_EXTENSION DeviceExt,
return(Status); return(Status);
} }
if (sector==((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32-1) if (sector == numberofsectors - 1)
forto=numberofclusters; forto=numberofclusters;
else else
forto=128; forto=128;
@ -679,37 +768,62 @@ FAT32WriteCluster(PDEVICE_EXTENSION DeviceExt,
* FUNCTION: Writes a cluster to the FAT32 physical tables * FUNCTION: Writes a cluster to the FAT32 physical tables
*/ */
{ {
#if 0 PVOID BaseAddress;
ULONG FATsector; BOOLEAN Valid;
ULONG FATeis; PCACHE_SEGMENT CacheSeg;
PUSHORT Block; NTSTATUS Status;
ULONG FATOffset;
ULONG Start; ULONG Start;
int i; ULONG i;
struct _BootSector32 *pBoot; ULONG ChunkSize;
DbgPrint ("FAT32WriteCluster %u : %u\n", ClusterToWrite, NewValue);
Block = ExAllocatePool (NonPagedPool, BLOCKSIZE); ChunkSize = CACHEPAGESIZE(DeviceExt);
FATsector = ClusterToWrite / 128;
FATeis = ClusterToWrite - (FATsector * 128); Start = DeviceExt->FATStart;
/* load sector, change value, then rewrite sector */
/* FIXME: Check status */ FATOffset = (Start * BLOCKSIZE) + (ClusterToWrite * 4);
VfatReadSectors (DeviceExt->StorageDevice,
DeviceExt->FATStart + FATsector, 1, (UCHAR *) Block); for (i = 0; i < DeviceExt->Boot->FATCount; i++)
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++)
{ {
/* FIXME: Check status */ Status = CcRosRequestCacheSegment(DeviceExt->StorageBcb,
VfatWriteSectors (DeviceExt->StorageDevice, Start, 1, (UCHAR *) Block); ROUND_DOWN(FATOffset, ChunkSize),
Start += pBoot->FATSectors; &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); return(STATUS_SUCCESS);
} }
NTSTATUS NTSTATUS
WriteCluster(PDEVICE_EXTENSION DeviceExt, WriteCluster(PDEVICE_EXTENSION DeviceExt,
ULONG ClusterToWrite, ULONG ClusterToWrite,
@ -736,7 +850,8 @@ WriteCluster(PDEVICE_EXTENSION DeviceExt,
} }
ULONG 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 * FUNCTION: Converts the cluster number to a sector number for this physical
* device * device
@ -773,7 +888,8 @@ VfatRawReadCluster(PDEVICE_EXTENSION DeviceExt,
Status = VfatReadSectors(DeviceExt->StorageDevice, Status = VfatReadSectors(DeviceExt->StorageDevice,
Sector, DeviceExt->Boot->SectorsPerCluster, Sector,
DeviceExt->Boot->SectorsPerCluster,
Buffer); Buffer);
return(Status); return(Status);
} }
@ -825,7 +941,6 @@ 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);
@ -937,6 +1052,7 @@ GetNextCluster (PDEVICE_EXTENSION DeviceExt,
return(Status); return(Status);
} }
NTSTATUS NTSTATUS
GetNextSector(PDEVICE_EXTENSION DeviceExt, GetNextSector(PDEVICE_EXTENSION DeviceExt,
ULONG CurrentSector, ULONG CurrentSector,
@ -947,7 +1063,9 @@ GetNextSector (PDEVICE_EXTENSION DeviceExt,
{ {
NTSTATUS Status; 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)) 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 */ /* Basically, if the next sequential sector would be on a cluster border, then we'll need to check in the FAT */
{ {

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 * FILE: fcb.c
@ -27,7 +27,8 @@
/* -------------------------------------------------------- PUBLICS */ /* -------------------------------------------------------- PUBLICS */
PVFATFCB vfatNewFCB (PWCHAR pFileName) PVFATFCB
vfatNewFCB(PWCHAR pFileName)
{ {
PVFATFCB rcFCB; PVFATFCB rcFCB;
@ -49,7 +50,8 @@ PVFATFCB vfatNewFCB (PWCHAR pFileName)
return rcFCB; return rcFCB;
} }
void vfatDestroyFCB (PVFATFCB pFCB) VOID
vfatDestroyFCB(PVFATFCB pFCB)
{ {
ExFreePool (pFCB); ExFreePool (pFCB);
} }
@ -66,7 +68,8 @@ vfatFCBIsRoot (PVFATFCB FCB)
return wcscmp (FCB->PathName, L"\\") == 0; return wcscmp (FCB->PathName, L"\\") == 0;
} }
void vfatGrabFCB (PDEVICE_EXTENSION pVCB, PVFATFCB pFCB) VOID
vfatGrabFCB(PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
{ {
KIRQL oldIrql; KIRQL oldIrql;
@ -80,7 +83,8 @@ void vfatGrabFCB (PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
KeReleaseSpinLock (&pVCB->FcbListLock, oldIrql); KeReleaseSpinLock (&pVCB->FcbListLock, oldIrql);
} }
void vfatReleaseFCB (PDEVICE_EXTENSION pVCB, PVFATFCB pFCB) VOID
vfatReleaseFCB(PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
{ {
KIRQL oldIrql; KIRQL oldIrql;
@ -100,7 +104,8 @@ void vfatReleaseFCB (PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
KeReleaseSpinLock (&pVCB->FcbListLock, oldIrql); KeReleaseSpinLock (&pVCB->FcbListLock, oldIrql);
} }
void vfatAddFCBToTable (PDEVICE_EXTENSION pVCB, PVFATFCB pFCB) VOID
vfatAddFCBToTable(PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
{ {
KIRQL oldIrql; KIRQL oldIrql;
@ -286,7 +291,7 @@ vfatMakeRootFCB (PDEVICE_EXTENSION pVCB)
FCB->entry.Attrib = FILE_ATTRIBUTE_DIRECTORY; FCB->entry.Attrib = FILE_ATTRIBUTE_DIRECTORY;
if (pVCB->FatType == FAT32) if (pVCB->FatType == FAT32)
{ {
FCB->entry.FirstCluster = 2; FCB->entry.FirstCluster = ((struct _BootSector32*)(pVCB->Boot))->RootCluster;
} }
else else
{ {
@ -298,7 +303,7 @@ vfatMakeRootFCB (PDEVICE_EXTENSION pVCB)
vfatAddFCBToTable(pVCB, FCB); vfatAddFCBToTable(pVCB, FCB);
vfatGrabFCB(pVCB, FCB); vfatGrabFCB(pVCB, FCB);
return FCB; return(FCB);
} }
PVFATFCB PVFATFCB

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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -58,7 +58,7 @@ VfatHasFileSystem(PDEVICE_OBJECT DeviceToMount,
Status = VfatReadSectors(DeviceToMount, 0, 1, (UCHAR *) Boot); Status = VfatReadSectors(DeviceToMount, 0, 1, (UCHAR *) Boot);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return Status; return(Status);
} }
DPRINT("Boot->SysType %.5s\n", Boot->SysType); DPRINT("Boot->SysType %.5s\n", Boot->SysType);
@ -75,12 +75,13 @@ VfatHasFileSystem(PDEVICE_OBJECT DeviceToMount,
ExFreePool(Boot); ExFreePool(Boot);
return STATUS_SUCCESS; return(STATUS_SUCCESS);
} }
static NTSTATUS static NTSTATUS
VfatMountDevice (PDEVICE_EXTENSION DeviceExt, PDEVICE_OBJECT DeviceToMount) VfatMountDevice(PDEVICE_EXTENSION DeviceExt,
PDEVICE_OBJECT DeviceToMount)
/* /*
* FUNCTION: Mounts the device * FUNCTION: Mounts the device
*/ */
@ -95,7 +96,7 @@ VfatMountDevice (PDEVICE_EXTENSION DeviceExt, PDEVICE_OBJECT DeviceToMount)
Status = VfatReadSectors(DeviceToMount, 0, 1, (UCHAR *) DeviceExt->Boot); Status = VfatReadSectors(DeviceToMount, 0, 1, (UCHAR *) DeviceExt->Boot);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return Status; return(Status);
} }
DeviceExt->FATStart = DeviceExt->Boot->ReservedSectors; DeviceExt->FATStart = DeviceExt->Boot->ReservedSectors;
@ -136,10 +137,10 @@ VfatMountDevice (PDEVICE_EXTENSION DeviceExt, PDEVICE_OBJECT DeviceToMount)
DbgPrint("FAT32\n"); DbgPrint("FAT32\n");
DeviceExt->FatType = FAT32; DeviceExt->FatType = FAT32;
DeviceExt->rootDirectorySectors = DeviceExt->Boot->SectorsPerCluster; DeviceExt->rootDirectorySectors = DeviceExt->Boot->SectorsPerCluster;
DeviceExt->rootStart = DeviceExt->dataStart = DeviceExt->FATStart + DeviceExt->Boot->FATCount
DeviceExt->FATStart + DeviceExt->Boot->FATCount
* ((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32; * ((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32;
DeviceExt->dataStart = DeviceExt->rootStart; DeviceExt->rootStart = ClusterToSector (DeviceExt,
((struct _BootSector32 *)(DeviceExt->Boot))->RootCluster);
} }
else else
{ {
@ -147,7 +148,7 @@ VfatMountDevice (PDEVICE_EXTENSION DeviceExt, PDEVICE_OBJECT DeviceToMount)
DeviceExt->FatType = FAT16; DeviceExt->FatType = FAT16;
} }
return STATUS_SUCCESS; return(STATUS_SUCCESS);
} }
@ -165,13 +166,13 @@ VfatMount (PDEVICE_OBJECT DeviceToMount)
Status = VfatHasFileSystem (DeviceToMount, &RecognizedFS); Status = VfatHasFileSystem (DeviceToMount, &RecognizedFS);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return Status; return(Status);
} }
if (RecognizedFS == FALSE) if (RecognizedFS == FALSE)
{ {
DPRINT("VFAT: Unrecognized Volume\n"); DPRINT("VFAT: Unrecognized Volume\n");
return STATUS_UNRECOGNIZED_VOLUME; return(STATUS_UNRECOGNIZED_VOLUME);
} }
DPRINT("VFAT: Recognized volume\n"); DPRINT("VFAT: Recognized volume\n");
@ -185,37 +186,60 @@ VfatMount (PDEVICE_OBJECT DeviceToMount)
&DeviceObject); &DeviceObject);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
return Status; return(Status);
} }
DeviceObject->Flags = DeviceObject->Flags | DO_DIRECT_IO; DeviceObject->Flags = DeviceObject->Flags | DO_DIRECT_IO;
DeviceExt = (PVOID) DeviceObject->DeviceExtension; DeviceExt = (PVOID) DeviceObject->DeviceExtension;
/* use same vpb as device disk */ /* use same vpb as device disk */
DeviceObject->Vpb = DeviceToMount->Vpb; DeviceObject->Vpb = DeviceToMount->Vpb;
Status = VfatMountDevice (DeviceExt, DeviceToMount); Status = VfatMountDevice(DeviceExt,
DeviceToMount);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
/* FIXME: delete device object */ /* 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; DeviceObject->Vpb->Flags |= VPB_MOUNTED;
DeviceExt->StorageDevice = IoAttachDeviceToDeviceStack(DeviceObject, DeviceExt->StorageDevice = IoAttachDeviceToDeviceStack(DeviceObject,
DeviceToMount); DeviceToMount);
DeviceExt->StreamStorageDevice = IoCreateStreamFileObject(NULL, DeviceExt->StreamStorageDevice = IoCreateStreamFileObject(NULL,
DeviceExt->StorageDevice); DeviceExt->StorageDevice);
if (DeviceExt->FatType == FAT16)
Status = CcRosInitializeFileCache(DeviceExt->StreamStorageDevice, Status = CcRosInitializeFileCache(DeviceExt->StreamStorageDevice,
&DeviceExt->StorageBcb, &DeviceExt->StorageBcb,
CACHEPAGESIZE(DeviceExt)); CACHEPAGESIZE(DeviceExt));
else
Status = CcRosInitializeFileCache(DeviceExt->StreamStorageDevice,
&DeviceExt->StorageBcb,
PAGESIZE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
/* FIXME: delete device object */ /* FIXME: delete device object */
return Status; return(Status);
} }
if (DeviceExt->FatType == FAT12) if (DeviceExt->FatType == FAT12)
@ -228,7 +252,7 @@ VfatMount (PDEVICE_OBJECT DeviceToMount)
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
/* FIXME: delete device object */ /* FIXME: delete device object */
return Status; return(Status);
} }
} }
ExInitializeResourceLite(&DeviceExt->DirResource); ExInitializeResourceLite(&DeviceExt->DirResource);
@ -246,14 +270,16 @@ VfatMount (PDEVICE_OBJECT DeviceToMount)
((struct _BootSector32 *) (DeviceExt->Boot))->VolumeID; ((struct _BootSector32 *) (DeviceExt->Boot))->VolumeID;
/* read volume label */ /* read volume label */
ReadVolumeLabel(DeviceExt, DeviceObject->Vpb); ReadVolumeLabel(DeviceExt,
DeviceObject->Vpb);
return STATUS_SUCCESS; return(STATUS_SUCCESS);
} }
NTSTATUS STDCALL NTSTATUS STDCALL
VfatFileSystemControl (PDEVICE_OBJECT DeviceObject, PIRP Irp) VfatFileSystemControl(PDEVICE_OBJECT DeviceObject,
PIRP Irp)
/* /*
* FUNCTION: File system control * 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -373,6 +373,8 @@ VfatReadFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
"Length %d, ReadOffset 0x%x)\n", DeviceExt, FileObject, Buffer, "Length %d, ReadOffset 0x%x)\n", DeviceExt, FileObject, Buffer,
Length, ReadOffset); Length, ReadOffset);
*LengthRead = 0;
Fcb = ((PVFATCCB)FileObject->FsContext2)->pFcb; Fcb = ((PVFATCCB)FileObject->FsContext2)->pFcb;
/* /*
@ -412,8 +414,6 @@ VfatReadFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
ChunkSize = PAGESIZE; ChunkSize = PAGESIZE;
} }
*LengthRead = 0;
/* /*
* Find the cluster to start the read from * Find the cluster to start the read from
* FIXME: Optimize by remembering the last cluster read and using if * 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> #include <ddk/ntifs.h>
struct _BootSector { struct _BootSector
{
unsigned char magic0, res0, magic1; unsigned char magic0, res0, magic1;
unsigned char OEMName[8]; unsigned char OEMName[8];
unsigned short BytesPerSector; unsigned short BytesPerSector;
@ -19,22 +20,43 @@ struct _BootSector {
unsigned char Res2[450]; unsigned char Res2[450];
} __attribute__((packed)); } __attribute__((packed));
struct _BootSector32 { struct _BootSector32
unsigned char magic0, res0, magic1; {
unsigned char OEMName[8]; unsigned char magic0, res0, magic1; // 0
unsigned short BytesPerSector; unsigned char OEMName[8]; // 3
unsigned char SectorsPerCluster; unsigned short BytesPerSector; // 11
unsigned short ReservedSectors; unsigned char SectorsPerCluster; // 13
unsigned char FATCount; unsigned short ReservedSectors; // 14
unsigned short RootEntries, Sectors; unsigned char FATCount; // 16
unsigned char Media; unsigned short RootEntries, Sectors; // 17
unsigned short FATSectors, SectorsPerTrack, Heads; unsigned char Media; // 21
unsigned long HiddenSectors, SectorsHuge; unsigned short FATSectors, SectorsPerTrack, Heads; // 22
unsigned long FATSectors32; unsigned long HiddenSectors, SectorsHuge; // 28
unsigned char x[27]; unsigned long FATSectors32; // 36
unsigned long VolumeID; unsigned short ExtFlag; // 40
unsigned char VolumeLabel[11], SysType[8]; unsigned short FSVersion; // 42
unsigned char Res2[422]; 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)); } __attribute__((packed));
typedef struct _BootSector BootSector; 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -124,15 +124,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;
if (DeviceExt->FatType == FAT16) if (DeviceExt->FatType == FAT16)
#if 0
Status = FAT16CountAvailableClusters(DeviceExt, Status = FAT16CountAvailableClusters(DeviceExt,
&FsSizeInfo->AvailableAllocationUnits); &FsSizeInfo->AvailableAllocationUnits);
#else
{
FsSizeInfo->AvailableAllocationUnits.QuadPart = 0;
Status = STATUS_SUCCESS;
}
#endif
else else
Status = FAT12CountAvailableClusters(DeviceExt, Status = FAT12CountAvailableClusters(DeviceExt,
&FsSizeInfo->AvailableAllocationUnits); &FsSizeInfo->AvailableAllocationUnits);
@ -179,7 +172,7 @@ FsdSetFsLabelInformation(PDEVICE_OBJECT DeviceObject,
{ {
DPRINT("FsdSetFsLabelInformation()\n"); DPRINT("FsdSetFsLabelInformation()\n");
return STATUS_NOT_IMPLEMENTED; return(STATUS_NOT_IMPLEMENTED);
} }