mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 01:55:19 +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
|
||||
|
@ -30,9 +30,9 @@
|
|||
/* FUNCTIONS ****************************************************************/
|
||||
|
||||
NTSTATUS
|
||||
Fat32GetNextCluster (PDEVICE_EXTENSION DeviceExt,
|
||||
ULONG CurrentCluster,
|
||||
PULONG NextCluster)
|
||||
Fat32GetNextCluster(PDEVICE_EXTENSION DeviceExt,
|
||||
ULONG CurrentCluster,
|
||||
PULONG NextCluster)
|
||||
/*
|
||||
* FUNCTION: Retrieve the next FAT32 cluster from the FAT table via a physical
|
||||
* disk read
|
||||
|
@ -43,15 +43,18 @@ Fat32GetNextCluster (PDEVICE_EXTENSION DeviceExt,
|
|||
PCACHE_SEGMENT CacheSeg;
|
||||
NTSTATUS Status;
|
||||
ULONG FATOffset;
|
||||
ULONG ChunkSize;
|
||||
|
||||
FATOffset = (DeviceExt->FATStart * BLOCKSIZE) +
|
||||
ChunkSize=CACHEPAGESIZE(DeviceExt);
|
||||
|
||||
FATOffset = (DeviceExt->FATStart * BLOCKSIZE) +
|
||||
(CurrentCluster * sizeof(ULONG));
|
||||
|
||||
Status = CcRosRequestCacheSegment(DeviceExt->StorageBcb,
|
||||
PAGE_ROUND_DOWN(FATOffset),
|
||||
&BaseAddress,
|
||||
&Valid,
|
||||
&CacheSeg);
|
||||
ROUND_DOWN(FATOffset, ChunkSize),
|
||||
&BaseAddress,
|
||||
&Valid,
|
||||
&CacheSeg);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
return(Status);
|
||||
|
@ -59,9 +62,9 @@ Fat32GetNextCluster (PDEVICE_EXTENSION DeviceExt,
|
|||
if (!Valid)
|
||||
{
|
||||
Status = VfatReadSectors(DeviceExt->StorageDevice,
|
||||
PAGE_ROUND_DOWN(FATOffset) / BLOCKSIZE,
|
||||
PAGESIZE / BLOCKSIZE,
|
||||
BaseAddress);
|
||||
ROUND_DOWN(FATOffset, ChunkSize) / BLOCKSIZE,
|
||||
ChunkSize / BLOCKSIZE,
|
||||
BaseAddress);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
CcRosReleaseCacheSegment(DeviceExt->StorageBcb, CacheSeg, FALSE);
|
||||
|
@ -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,9 +81,9 @@ Fat32GetNextCluster (PDEVICE_EXTENSION DeviceExt,
|
|||
}
|
||||
|
||||
NTSTATUS
|
||||
Fat16GetNextCluster (PDEVICE_EXTENSION DeviceExt,
|
||||
ULONG CurrentCluster,
|
||||
PULONG NextCluster)
|
||||
Fat16GetNextCluster(PDEVICE_EXTENSION DeviceExt,
|
||||
ULONG CurrentCluster,
|
||||
PULONG NextCluster)
|
||||
/*
|
||||
* FUNCTION: Retrieve the next FAT16 cluster from the FAT table
|
||||
*/
|
||||
|
@ -127,28 +130,28 @@ Fat16GetNextCluster (PDEVICE_EXTENSION DeviceExt,
|
|||
}
|
||||
|
||||
NTSTATUS
|
||||
Fat12GetNextCluster (PDEVICE_EXTENSION DeviceExt,
|
||||
ULONG CurrentCluster,
|
||||
PULONG NextCluster)
|
||||
Fat12GetNextCluster(PDEVICE_EXTENSION DeviceExt,
|
||||
ULONG CurrentCluster,
|
||||
PULONG NextCluster)
|
||||
/*
|
||||
* FUNCTION: Retrieve the next FAT12 cluster from the FAT table
|
||||
*/
|
||||
{
|
||||
unsigned char* CBlock;
|
||||
ULONG FATOffset;
|
||||
ULONG Entry;
|
||||
BOOLEAN Valid;
|
||||
PCACHE_SEGMENT CacheSeg;
|
||||
NTSTATUS Status;
|
||||
PVOID BaseAddress;
|
||||
PUCHAR CBlock;
|
||||
ULONG FATOffset;
|
||||
ULONG Entry;
|
||||
BOOLEAN Valid;
|
||||
PCACHE_SEGMENT CacheSeg;
|
||||
NTSTATUS Status;
|
||||
PVOID BaseAddress;
|
||||
|
||||
*NextCluster = 0;
|
||||
*NextCluster = 0;
|
||||
|
||||
Status = CcRosRequestCacheSegment(DeviceExt->Fat12StorageBcb,
|
||||
0,
|
||||
&BaseAddress,
|
||||
&Valid,
|
||||
&CacheSeg);
|
||||
Status = CcRosRequestCacheSegment(DeviceExt->Fat12StorageBcb,
|
||||
0,
|
||||
&BaseAddress,
|
||||
&Valid,
|
||||
&CacheSeg);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
return(Status);
|
||||
|
@ -188,8 +191,8 @@ Fat12GetNextCluster (PDEVICE_EXTENSION DeviceExt,
|
|||
}
|
||||
|
||||
NTSTATUS
|
||||
FAT16FindAvailableCluster (PDEVICE_EXTENSION DeviceExt,
|
||||
PULONG Cluster)
|
||||
FAT16FindAvailableCluster(PDEVICE_EXTENSION DeviceExt,
|
||||
PULONG Cluster)
|
||||
/*
|
||||
* FUNCTION: Finds the first available cluster in a FAT16 table
|
||||
*/
|
||||
|
@ -206,12 +209,13 @@ 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;
|
||||
|
||||
for (i = 2; i < FatLength; i+=2)
|
||||
{
|
||||
{
|
||||
if (((FatStart + i) % ChunkSize) == 0 || CacheSeg == NULL)
|
||||
{
|
||||
if (CacheSeg != NULL)
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -271,7 +275,7 @@ FAT12FindAvailableCluster (PDEVICE_EXTENSION DeviceExt, PULONG Cluster)
|
|||
ULONG numberofclusters;
|
||||
|
||||
*Cluster = 0;
|
||||
|
||||
|
||||
Status = CcRosRequestCacheSegment(DeviceExt->Fat12StorageBcb,
|
||||
0,
|
||||
&BaseAddress,
|
||||
|
@ -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++)
|
||||
{
|
||||
if (Block[i] == 0)
|
||||
ulCount++;
|
||||
}
|
||||
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,10 +598,10 @@ FAT32CountAvailableClusters(PDEVICE_EXTENSION DeviceExt,
|
|||
return(Status);
|
||||
}
|
||||
|
||||
if (sector==((struct _BootSector32 *) (DeviceExt->Boot))->FATSectors32-1)
|
||||
forto=numberofclusters;
|
||||
else
|
||||
forto=128;
|
||||
if (sector == numberofsectors - 1)
|
||||
forto=numberofclusters;
|
||||
else
|
||||
forto=128;
|
||||
for (i = 0; i < forto; i++)
|
||||
{
|
||||
if (Block[i] == 0)
|
||||
|
@ -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,22 +874,23 @@ VfatRawReadCluster(PDEVICE_EXTENSION DeviceExt,
|
|||
|
||||
if (FirstCluster == 1)
|
||||
{
|
||||
Status = VfatReadSectors (DeviceExt->StorageDevice,
|
||||
Cluster,
|
||||
DeviceExt->Boot->SectorsPerCluster,
|
||||
Buffer);
|
||||
Status = VfatReadSectors(DeviceExt->StorageDevice,
|
||||
Cluster,
|
||||
DeviceExt->Boot->SectorsPerCluster,
|
||||
Buffer);
|
||||
return(Status);
|
||||
}
|
||||
else
|
||||
{
|
||||
ULONG Sector;
|
||||
|
||||
Sector = ClusterToSector (DeviceExt, Cluster);
|
||||
Sector = ClusterToSector(DeviceExt, Cluster);
|
||||
|
||||
|
||||
Status = VfatReadSectors (DeviceExt->StorageDevice,
|
||||
Sector, DeviceExt->Boot->SectorsPerCluster,
|
||||
Buffer);
|
||||
Status = VfatReadSectors(DeviceExt->StorageDevice,
|
||||
Sector,
|
||||
DeviceExt->Boot->SectorsPerCluster,
|
||||
Buffer);
|
||||
return(Status);
|
||||
}
|
||||
}
|
||||
|
@ -791,8 +907,8 @@ VfatRawWriteCluster(PDEVICE_EXTENSION DeviceExt,
|
|||
ULONG Sector;
|
||||
NTSTATUS Status;
|
||||
|
||||
DPRINT ("VfatWriteCluster(DeviceExt %x, Buffer %x, Cluster %d)\n",
|
||||
DeviceExt, Buffer, Cluster);
|
||||
DPRINT("VfatWriteCluster(DeviceExt %x, Buffer %x, Cluster %d)\n",
|
||||
DeviceExt, Buffer, Cluster);
|
||||
|
||||
if (FirstCluster == 1)
|
||||
{
|
||||
|
@ -815,27 +931,26 @@ VfatRawWriteCluster(PDEVICE_EXTENSION DeviceExt,
|
|||
}
|
||||
|
||||
NTSTATUS
|
||||
GetNextCluster (PDEVICE_EXTENSION DeviceExt,
|
||||
ULONG CurrentCluster,
|
||||
PULONG NextCluster,
|
||||
BOOLEAN Extend)
|
||||
GetNextCluster(PDEVICE_EXTENSION DeviceExt,
|
||||
ULONG CurrentCluster,
|
||||
PULONG NextCluster,
|
||||
BOOLEAN Extend)
|
||||
/*
|
||||
* FUNCTION: Retrieve the next cluster depending on the FAT type
|
||||
*/
|
||||
{
|
||||
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,60 +1033,63 @@ 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,
|
||||
ULONG CurrentSector,
|
||||
PULONG NextSector,
|
||||
BOOLEAN Extend)
|
||||
GetNextSector(PDEVICE_EXTENSION DeviceExt,
|
||||
ULONG CurrentSector,
|
||||
PULONG NextSector,
|
||||
BOOLEAN Extend)
|
||||
/* Some functions don't have access to the cluster they're really reading from.
|
||||
Maybe this is a dirty solution, but it will allow them to handle fragmentation. */
|
||||
{
|
||||
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 */
|
||||
{
|
||||
(*NextSector)=CurrentSector+1;
|
||||
return (STATUS_SUCCESS);
|
||||
(*NextSector)=CurrentSector+1;
|
||||
return (STATUS_SUCCESS);
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentSector = (CurrentSector - DeviceExt->dataStart) / DeviceExt -> Boot -> SectorsPerCluster + 2;
|
||||
{
|
||||
CurrentSector = (CurrentSector - DeviceExt->dataStart) / DeviceExt -> Boot -> SectorsPerCluster + 2;
|
||||
|
||||
Status = GetNextCluster(DeviceExt, CurrentSector, NextSector, Extend);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
return(Status);
|
||||
}
|
||||
if ((*NextSector) == 0 || (*NextSector) == 0xffffffff)
|
||||
{
|
||||
/* The caller wants to know a sector. These FAT codes don't correspond to any sector. */
|
||||
return (STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
Status = GetNextCluster(DeviceExt, CurrentSector, NextSector, Extend);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
return(Status);
|
||||
}
|
||||
if ((*NextSector) == 0 || (*NextSector) == 0xffffffff)
|
||||
{
|
||||
/* The caller wants to know a sector. These FAT codes don't correspond to any sector. */
|
||||
return(STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
|
||||
(*NextSector)=ClusterToSector(DeviceExt,(*NextSector));
|
||||
return (STATUS_SUCCESS);
|
||||
}
|
||||
(*NextSector) = ClusterToSector(DeviceExt,(*NextSector));
|
||||
return(STATUS_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -110,8 +115,8 @@ void vfatAddFCBToTable (PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
|
|||
KeReleaseSpinLock (&pVCB->FcbListLock, oldIrql);
|
||||
}
|
||||
|
||||
PVFATFCB
|
||||
vfatGrabFCBFromTable (PDEVICE_EXTENSION pVCB, PWSTR pFileName)
|
||||
PVFATFCB
|
||||
vfatGrabFCBFromTable(PDEVICE_EXTENSION pVCB, PWSTR pFileName)
|
||||
{
|
||||
KIRQL oldIrql;
|
||||
PVFATFCB rcFCB;
|
||||
|
@ -184,12 +189,12 @@ vfatFCBInitializeCache (PVCB vcb, PVFATFCB fcb)
|
|||
}
|
||||
|
||||
NTSTATUS
|
||||
vfatRequestAndValidateRegion (PDEVICE_EXTENSION pDeviceExt,
|
||||
PVFATFCB pFCB,
|
||||
ULONG pOffset,
|
||||
PVOID * pBuffer,
|
||||
PCACHE_SEGMENT * pCacheSegment,
|
||||
BOOL pExtend)
|
||||
vfatRequestAndValidateRegion(PDEVICE_EXTENSION pDeviceExt,
|
||||
PVFATFCB pFCB,
|
||||
ULONG pOffset,
|
||||
PVOID * pBuffer,
|
||||
PCACHE_SEGMENT * pCacheSegment,
|
||||
BOOL pExtend)
|
||||
{
|
||||
NTSTATUS status;
|
||||
BOOLEAN valid;
|
||||
|
@ -197,7 +202,7 @@ vfatRequestAndValidateRegion (PDEVICE_EXTENSION pDeviceExt,
|
|||
ULONG currentCluster;
|
||||
ULONG i;
|
||||
|
||||
status = CcRosRequestCacheSegment(pFCB->RFCB.Bcb,
|
||||
status = CcRosRequestCacheSegment(pFCB->RFCB.Bcb,
|
||||
pOffset,
|
||||
pBuffer,
|
||||
&valid,
|
||||
|
@ -275,34 +280,34 @@ vfatReleaseRegion (PDEVICE_EXTENSION pDeviceExt,
|
|||
return CcRosReleaseCacheSegment (pFCB->RFCB.Bcb, pCacheSegment, TRUE);
|
||||
}
|
||||
|
||||
PVFATFCB
|
||||
vfatMakeRootFCB (PDEVICE_EXTENSION pVCB)
|
||||
PVFATFCB
|
||||
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
|
||||
{
|
||||
FCB->entry.FirstCluster = 1;
|
||||
}
|
||||
{
|
||||
FCB->entry.FirstCluster = 1;
|
||||
}
|
||||
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)
|
||||
PVFATFCB
|
||||
vfatOpenRootFCB(PDEVICE_EXTENSION pVCB)
|
||||
{
|
||||
PVFATFCB FCB;
|
||||
|
||||
|
@ -316,16 +321,16 @@ vfatOpenRootFCB (PDEVICE_EXTENSION pVCB)
|
|||
}
|
||||
|
||||
NTSTATUS
|
||||
vfatMakeFCBFromDirEntry (PVCB vcb,
|
||||
PVFATFCB directoryFCB,
|
||||
PWSTR longName,
|
||||
PFAT_DIR_ENTRY dirEntry,
|
||||
PVFATFCB * fileFCB)
|
||||
vfatMakeFCBFromDirEntry(PVCB vcb,
|
||||
PVFATFCB directoryFCB,
|
||||
PWSTR longName,
|
||||
PFAT_DIR_ENTRY dirEntry,
|
||||
PVFATFCB * fileFCB)
|
||||
{
|
||||
PVFATFCB rcFCB;
|
||||
WCHAR pathName [MAX_PATH];
|
||||
|
||||
if (longName [0] != 0 && wcslen (directoryFCB->PathName) +
|
||||
if (longName [0] != 0 && wcslen (directoryFCB->PathName) +
|
||||
sizeof(WCHAR) + wcslen (longName) > MAX_PATH)
|
||||
{
|
||||
return STATUS_OBJECT_NAME_INVALID;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -157,103 +158,128 @@ VfatMount (PDEVICE_OBJECT DeviceToMount)
|
|||
* FUNCTION: Mount the filesystem
|
||||
*/
|
||||
{
|
||||
PDEVICE_OBJECT DeviceObject;
|
||||
PDEVICE_EXTENSION DeviceExt;
|
||||
BOOLEAN RecognizedFS;
|
||||
NTSTATUS Status;
|
||||
PDEVICE_OBJECT DeviceObject;
|
||||
PDEVICE_EXTENSION DeviceExt;
|
||||
BOOLEAN RecognizedFS;
|
||||
NTSTATUS Status;
|
||||
|
||||
Status = VfatHasFileSystem (DeviceToMount, &RecognizedFS);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
return Status;
|
||||
}
|
||||
Status = VfatHasFileSystem (DeviceToMount, &RecognizedFS);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
return(Status);
|
||||
}
|
||||
|
||||
if (RecognizedFS == FALSE)
|
||||
{
|
||||
DPRINT("VFAT: Unrecognized Volume\n");
|
||||
return STATUS_UNRECOGNIZED_VOLUME;
|
||||
}
|
||||
if (RecognizedFS == FALSE)
|
||||
{
|
||||
DPRINT("VFAT: Unrecognized Volume\n");
|
||||
return(STATUS_UNRECOGNIZED_VOLUME);
|
||||
}
|
||||
|
||||
DPRINT("VFAT: Recognized volume\n");
|
||||
DPRINT("VFAT: Recognized volume\n");
|
||||
|
||||
Status = IoCreateDevice(VfatDriverObject,
|
||||
sizeof (DEVICE_EXTENSION),
|
||||
NULL,
|
||||
FILE_DEVICE_FILE_SYSTEM,
|
||||
0,
|
||||
FALSE,
|
||||
&DeviceObject);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
return Status;
|
||||
}
|
||||
Status = IoCreateDevice(VfatDriverObject,
|
||||
sizeof (DEVICE_EXTENSION),
|
||||
NULL,
|
||||
FILE_DEVICE_FILE_SYSTEM,
|
||||
0,
|
||||
FALSE,
|
||||
&DeviceObject);
|
||||
if (!NT_SUCCESS(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);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
/* FIXME: delete device object */
|
||||
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);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
/* FIXME: delete device object */
|
||||
return(Status);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
#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
|
||||
|
||||
if (DeviceExt->FatType == FAT12)
|
||||
{
|
||||
DeviceExt->Fat12StorageDevice =
|
||||
IoCreateStreamFileObject(NULL, DeviceExt->StorageDevice);
|
||||
Status = CcRosInitializeFileCache(DeviceExt->Fat12StorageDevice,
|
||||
&DeviceExt->Fat12StorageBcb,
|
||||
PAGESIZE * 3);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
/* FIXME: delete device object */
|
||||
return Status;
|
||||
}
|
||||
}
|
||||
ExInitializeResourceLite (&DeviceExt->DirResource);
|
||||
ExInitializeResourceLite (&DeviceExt->FatResource);
|
||||
DeviceObject->Vpb->Flags |= VPB_MOUNTED;
|
||||
DeviceExt->StorageDevice = IoAttachDeviceToDeviceStack(DeviceObject,
|
||||
DeviceToMount);
|
||||
DeviceExt->StreamStorageDevice = IoCreateStreamFileObject(NULL,
|
||||
DeviceExt->StorageDevice);
|
||||
Status = CcRosInitializeFileCache(DeviceExt->StreamStorageDevice,
|
||||
&DeviceExt->StorageBcb,
|
||||
CACHEPAGESIZE(DeviceExt));
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
/* FIXME: delete device object */
|
||||
return(Status);
|
||||
}
|
||||
|
||||
KeInitializeSpinLock (&DeviceExt->FcbListLock);
|
||||
InitializeListHead (&DeviceExt->FcbListHead);
|
||||
if (DeviceExt->FatType == FAT12)
|
||||
{
|
||||
DeviceExt->Fat12StorageDevice =
|
||||
IoCreateStreamFileObject(NULL, DeviceExt->StorageDevice);
|
||||
Status = CcRosInitializeFileCache(DeviceExt->Fat12StorageDevice,
|
||||
&DeviceExt->Fat12StorageBcb,
|
||||
PAGESIZE * 3);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
/* FIXME: delete device object */
|
||||
return(Status);
|
||||
}
|
||||
}
|
||||
ExInitializeResourceLite(&DeviceExt->DirResource);
|
||||
ExInitializeResourceLite(&DeviceExt->FatResource);
|
||||
|
||||
/* read serial number */
|
||||
if (DeviceExt->FatType == FAT12 || DeviceExt->FatType == FAT16)
|
||||
DeviceObject->Vpb->SerialNumber =
|
||||
((struct _BootSector *) (DeviceExt->Boot))->VolumeID;
|
||||
else if (DeviceExt->FatType == FAT32)
|
||||
DeviceObject->Vpb->SerialNumber =
|
||||
((struct _BootSector32 *) (DeviceExt->Boot))->VolumeID;
|
||||
KeInitializeSpinLock(&DeviceExt->FcbListLock);
|
||||
InitializeListHead(&DeviceExt->FcbListHead);
|
||||
|
||||
/* read volume label */
|
||||
ReadVolumeLabel(DeviceExt, DeviceObject->Vpb);
|
||||
/* read serial number */
|
||||
if (DeviceExt->FatType == FAT12 || DeviceExt->FatType == FAT16)
|
||||
DeviceObject->Vpb->SerialNumber =
|
||||
((struct _BootSector *) (DeviceExt->Boot))->VolumeID;
|
||||
else if (DeviceExt->FatType == FAT32)
|
||||
DeviceObject->Vpb->SerialNumber =
|
||||
((struct _BootSector32 *) (DeviceExt->Boot))->VolumeID;
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
/* read volume label */
|
||||
ReadVolumeLabel(DeviceExt,
|
||||
DeviceObject->Vpb);
|
||||
|
||||
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
|
||||
|
@ -369,9 +369,11 @@ VfatReadFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
|
|||
assert (FileObject != NULL);
|
||||
assert (FileObject->FsContext != NULL);
|
||||
|
||||
DPRINT ("VfatReadFile(DeviceExt %x, FileObject %x, Buffer %x, "
|
||||
"Length %d, ReadOffset 0x%x)\n", DeviceExt, FileObject, Buffer,
|
||||
Length, ReadOffset);
|
||||
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;
|
||||
|
||||
|
@ -379,7 +381,7 @@ VfatReadFile (PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject,
|
|||
* Find the first cluster
|
||||
*/
|
||||
if (DeviceExt->FatType == FAT32)
|
||||
CurrentCluster = Fcb->entry.FirstCluster
|
||||
CurrentCluster = Fcb->entry.FirstCluster
|
||||
+ Fcb->entry.FirstClusterHigh * 65536;
|
||||
else
|
||||
CurrentCluster = Fcb->entry.FirstCluster;
|
||||
|
@ -412,15 +414,13 @@ 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
|
||||
* possible.
|
||||
*/
|
||||
Status = OffsetToCluster(DeviceExt,
|
||||
FirstCluster,
|
||||
Status = OffsetToCluster(DeviceExt,
|
||||
FirstCluster,
|
||||
ROUND_DOWN(ReadOffset, ChunkSize),
|
||||
&CurrentCluster,
|
||||
FALSE);
|
||||
|
|
|
@ -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);
|
||||
|
@ -177,9 +170,9 @@ static NTSTATUS
|
|||
FsdSetFsLabelInformation(PDEVICE_OBJECT DeviceObject,
|
||||
PFILE_FS_LABEL_INFORMATION FsLabelInfo)
|
||||
{
|
||||
DPRINT("FsdSetFsLabelInformation()\n");
|
||||
|
||||
return STATUS_NOT_IMPLEMENTED;
|
||||
DPRINT("FsdSetFsLabelInformation()\n");
|
||||
|
||||
return(STATUS_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
|
||||
|
@ -268,50 +261,50 @@ VfatSetVolumeInformation(PDEVICE_OBJECT DeviceObject,
|
|||
* FUNCTION: Set the specified volume information
|
||||
*/
|
||||
{
|
||||
PIO_STACK_LOCATION Stack;
|
||||
FS_INFORMATION_CLASS FsInformationClass;
|
||||
// PFILE_OBJECT FileObject = NULL;
|
||||
// PVFATFCB FCB = NULL;
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
PVOID SystemBuffer;
|
||||
ULONG BufferLength;
|
||||
PIO_STACK_LOCATION Stack;
|
||||
FS_INFORMATION_CLASS FsInformationClass;
|
||||
// PFILE_OBJECT FileObject = NULL;
|
||||
// PVFATFCB FCB = NULL;
|
||||
NTSTATUS Status = STATUS_SUCCESS;
|
||||
PVOID SystemBuffer;
|
||||
ULONG BufferLength;
|
||||
|
||||
/* PRECONDITION */
|
||||
assert(DeviceObject != NULL);
|
||||
assert(Irp != NULL);
|
||||
/* PRECONDITION */
|
||||
assert(DeviceObject != NULL);
|
||||
assert(Irp != NULL);
|
||||
|
||||
DPRINT("FsdSetVolumeInformation(DeviceObject %x, Irp %x)\n",
|
||||
DeviceObject,
|
||||
Irp);
|
||||
DPRINT("FsdSetVolumeInformation(DeviceObject %x, Irp %x)\n",
|
||||
DeviceObject,
|
||||
Irp);
|
||||
|
||||
Stack = IoGetCurrentIrpStackLocation (Irp);
|
||||
FsInformationClass = Stack->Parameters.SetVolume.FsInformationClass;
|
||||
BufferLength = Stack->Parameters.SetVolume.Length;
|
||||
SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
|
||||
// FileObject = Stack->FileObject;
|
||||
// FCB = ((PVFATCCB) (FileObject->FsContext2))->pFcb;
|
||||
Stack = IoGetCurrentIrpStackLocation(Irp);
|
||||
FsInformationClass = Stack->Parameters.SetVolume.FsInformationClass;
|
||||
BufferLength = Stack->Parameters.SetVolume.Length;
|
||||
SystemBuffer = Irp->AssociatedIrp.SystemBuffer;
|
||||
// FileObject = Stack->FileObject;
|
||||
// FCB = ((PVFATCCB) (FileObject->FsContext2))->pFcb;
|
||||
|
||||
DPRINT("FsInformationClass %d\n", FsInformationClass);
|
||||
DPRINT("BufferLength %d\n", BufferLength);
|
||||
DPRINT("SystemBuffer %x\n", SystemBuffer);
|
||||
DPRINT("FsInformationClass %d\n", FsInformationClass);
|
||||
DPRINT("BufferLength %d\n", BufferLength);
|
||||
DPRINT("SystemBuffer %x\n", SystemBuffer);
|
||||
|
||||
switch (FsInformationClass)
|
||||
{
|
||||
case FileFsLabelInformation:
|
||||
Status = FsdSetFsLabelInformation(DeviceObject,
|
||||
SystemBuffer);
|
||||
break;
|
||||
switch(FsInformationClass)
|
||||
{
|
||||
case FileFsLabelInformation:
|
||||
Status = FsdSetFsLabelInformation(DeviceObject,
|
||||
SystemBuffer);
|
||||
break;
|
||||
|
||||
default:
|
||||
Status = STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
default:
|
||||
Status = STATUS_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
Irp->IoStatus.Status = Status;
|
||||
Irp->IoStatus.Information = 0;
|
||||
IoCompleteRequest(Irp,
|
||||
IO_NO_INCREMENT);
|
||||
Irp->IoStatus.Status = Status;
|
||||
Irp->IoStatus.Information = 0;
|
||||
IoCompleteRequest(Irp,
|
||||
IO_NO_INCREMENT);
|
||||
|
||||
return(Status);
|
||||
return(Status);
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
|
Loading…
Reference in a new issue