mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 10:04:49 +00:00
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:
parent
7192939c7d
commit
75d57b4fa1
6 changed files with 502 additions and 338 deletions
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -134,7 +137,7 @@ Fat12GetNextCluster (PDEVICE_EXTENSION DeviceExt,
|
|||
* FUNCTION: Retrieve the next FAT12 cluster from the FAT table
|
||||
*/
|
||||
{
|
||||
unsigned char* CBlock;
|
||||
PUCHAR CBlock;
|
||||
ULONG FATOffset;
|
||||
ULONG Entry;
|
||||
BOOLEAN Valid;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -736,7 +850,8 @@ WriteCluster(PDEVICE_EXTENSION DeviceExt,
|
|||
}
|
||||
|
||||
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
|
||||
|
@ -773,7 +888,8 @@ VfatRawReadCluster(PDEVICE_EXTENSION DeviceExt,
|
|||
|
||||
|
||||
Status = VfatReadSectors(DeviceExt->StorageDevice,
|
||||
Sector, DeviceExt->Boot->SectorsPerCluster,
|
||||
Sector,
|
||||
DeviceExt->Boot->SectorsPerCluster,
|
||||
Buffer);
|
||||
return(Status);
|
||||
}
|
||||
|
@ -825,7 +941,6 @@ GetNextCluster (PDEVICE_EXTENSION DeviceExt,
|
|||
{
|
||||
NTSTATUS Status;
|
||||
|
||||
|
||||
// DPRINT ("GetNextCluster(DeviceExt %x, CurrentCluster %x)\n",
|
||||
// DeviceExt, CurrentCluster);
|
||||
|
||||
|
@ -937,6 +1052,7 @@ GetNextCluster (PDEVICE_EXTENSION DeviceExt,
|
|||
return(Status);
|
||||
}
|
||||
|
||||
|
||||
NTSTATUS
|
||||
GetNextSector(PDEVICE_EXTENSION DeviceExt,
|
||||
ULONG CurrentSector,
|
||||
|
@ -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 */
|
||||
{
|
||||
|
|
|
@ -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,7 +50,8 @@ PVFATFCB vfatNewFCB (PWCHAR pFileName)
|
|||
return rcFCB;
|
||||
}
|
||||
|
||||
void vfatDestroyFCB (PVFATFCB pFCB)
|
||||
VOID
|
||||
vfatDestroyFCB(PVFATFCB pFCB)
|
||||
{
|
||||
ExFreePool (pFCB);
|
||||
}
|
||||
|
@ -66,7 +68,8 @@ 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;
|
||||
|
||||
|
@ -286,7 +291,7 @@ vfatMakeRootFCB (PDEVICE_EXTENSION pVCB)
|
|||
FCB->entry.Attrib = FILE_ATTRIBUTE_DIRECTORY;
|
||||
if (pVCB->FatType == FAT32)
|
||||
{
|
||||
FCB->entry.FirstCluster = 2;
|
||||
FCB->entry.FirstCluster = ((struct _BootSector32*)(pVCB->Boot))->RootCluster;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -298,7 +303,7 @@ vfatMakeRootFCB (PDEVICE_EXTENSION pVCB)
|
|||
vfatAddFCBToTable(pVCB, FCB);
|
||||
vfatGrabFCB(pVCB, FCB);
|
||||
|
||||
return FCB;
|
||||
return(FCB);
|
||||
}
|
||||
|
||||
PVFATFCB
|
||||
|
|
|
@ -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,7 +252,7 @@ VfatMount (PDEVICE_OBJECT DeviceToMount)
|
|||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
/* FIXME: delete device object */
|
||||
return Status;
|
||||
return(Status);
|
||||
}
|
||||
}
|
||||
ExInitializeResourceLite(&DeviceExt->DirResource);
|
||||
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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
|
||||
|
@ -373,6 +373,8 @@ VfatReadFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
|
|||
"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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue