Changed the sector size from BLOCKSIZE to the size from the boot sector.

svn path=/trunk/; revision=3148
This commit is contained in:
Hartmut Birr 2002-06-26 18:36:41 +00:00
parent 40fe11fc2b
commit 518b1b7a13
8 changed files with 116 additions and 210 deletions

View file

@ -19,37 +19,27 @@
/* FUNCTIONS ***************************************************************/
NTSTATUS
VfatReadSectors (IN PDEVICE_OBJECT pDeviceObject,
IN ULONG DiskSector,
IN ULONG SectorCount,
VfatReadDisk (IN PDEVICE_OBJECT pDeviceObject,
IN PLARGE_INTEGER ReadOffset,
IN ULONG ReadLength,
IN OUT PUCHAR Buffer)
{
LARGE_INTEGER sectorNumber;
PIRP Irp;
IO_STATUS_BLOCK IoStatus;
KEVENT event;
NTSTATUS Status;
ULONG sectorSize;
sectorNumber.u.LowPart = DiskSector << 9;
sectorNumber.u.HighPart = DiskSector >> 23;
KeInitializeEvent (&event, NotificationEvent, FALSE);
sectorSize = BLOCKSIZE * SectorCount;
DPRINT ("VfatReadSectors(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
pDeviceObject, DiskSector, Buffer);
DPRINT ("sectorNumber %08lx:%08lx sectorSize %ld\n",
(unsigned long int) sectorNumber.u.LowPart,
(unsigned long int) sectorNumber.u.HighPart, sectorSize);
DPRINT ("VfatReadSectors(pDeviceObject %x, Offset %I64x, Length %d, Buffer %x)\n",
pDeviceObject, ReadOffset->QuadPart, ReadLength, Buffer);
DPRINT ("Building synchronous FSD Request...\n");
Irp = IoBuildSynchronousFsdRequest (IRP_MJ_READ,
pDeviceObject,
Buffer,
sectorSize,
&sectorNumber,
ReadLength,
ReadOffset,
&event,
&IoStatus);
@ -74,9 +64,8 @@ VfatReadSectors (IN PDEVICE_OBJECT pDeviceObject,
if (!NT_SUCCESS (Status))
{
DPRINT ("IO failed!!! VfatReadSectors : Error code: %x\n", Status);
DPRINT ("(pDeviceObject %x, DiskSector %x, Buffer %x, offset 0x%x%x)\n",
pDeviceObject, DiskSector, Buffer, sectorNumber.u.HighPart,
sectorNumber.u.LowPart);
DPRINT ("(pDeviceObject %x, Offset %I64x, Size %d, Buffer %x\n",
pDeviceObject, ReadOffset->QuadPart, ReadLength, Buffer);
return (Status);
}
DPRINT ("Block request succeeded for %x\n", Irp);
@ -84,34 +73,27 @@ VfatReadSectors (IN PDEVICE_OBJECT pDeviceObject,
}
NTSTATUS
VfatWriteSectors (IN PDEVICE_OBJECT pDeviceObject,
IN ULONG DiskSector,
IN ULONG SectorCount,
VfatWriteDisk (IN PDEVICE_OBJECT pDeviceObject,
IN PLARGE_INTEGER WriteOffset,
IN ULONG WriteLength,
IN PUCHAR Buffer)
{
LARGE_INTEGER sectorNumber;
PIRP Irp;
IO_STATUS_BLOCK IoStatus;
KEVENT event;
NTSTATUS Status;
ULONG sectorSize;
DPRINT ("VfatWriteSectors(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
pDeviceObject, DiskSector, Buffer);
sectorNumber.u.LowPart = DiskSector << 9;
sectorNumber.u.HighPart = DiskSector >> 23;
DPRINT ("VfatWriteSectors(pDeviceObject %x, Offset %I64x, Size %d, Buffer %x)\n",
pDeviceObject, WriteOffset->QuadPart, WriteLength, Buffer);
KeInitializeEvent (&event, NotificationEvent, FALSE);
sectorSize = BLOCKSIZE * SectorCount;
DPRINT ("Building synchronous FSD Request...\n");
Irp = IoBuildSynchronousFsdRequest (IRP_MJ_WRITE,
pDeviceObject,
Buffer,
sectorSize,
&sectorNumber,
WriteLength,
WriteOffset,
&event,
&IoStatus);

View file

@ -1,4 +1,4 @@
/* $Id: create.c,v 1.41 2002/05/15 18:05:00 ekohl Exp $
/* $Id: create.c,v 1.42 2002/06/26 18:36:41 hbirr Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -346,7 +346,7 @@ FindFile (PDEVICE_EXTENSION DeviceExt,
CHECKPOINT;
Fcb->PathName[0]='\\';
Fcb->ObjectName = &Fcb->PathName[1];
Fcb->entry.FileSize = DeviceExt->FatInfo.rootDirectorySectors * BLOCKSIZE;
Fcb->entry.FileSize = DeviceExt->FatInfo.rootDirectorySectors * DeviceExt->FatInfo.BytesPerSector;
Fcb->entry.Attrib = FILE_ATTRIBUTE_DIRECTORY;
if (DeviceExt->FatInfo.FatType == FAT32)
{

View file

@ -1,5 +1,5 @@
/*
* $Id: fat.c,v 1.36 2002/03/18 22:37:12 hbirr Exp $
* $Id: fat.c,v 1.37 2002/06/26 18:36:41 hbirr Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -110,7 +110,7 @@ Fat12GetNextCluster(PDEVICE_EXTENSION DeviceExt,
*NextCluster = 0;
Offset.QuadPart = 0;
if(!CcMapData(DeviceExt->FATFileObject, &Offset, DeviceExt->FatInfo.FATSectors * BLOCKSIZE, 1, &Context, &BaseAddress))
if(!CcMapData(DeviceExt->FATFileObject, &Offset, DeviceExt->FatInfo.FATSectors * DeviceExt->FatInfo.BytesPerSector, 1, &Context, &BaseAddress))
{
return STATUS_UNSUCCESSFUL;
}
@ -216,9 +216,9 @@ FAT12FindAvailableCluster(PDEVICE_EXTENSION DeviceExt, PULONG Cluster)
*Cluster = 0;
StartCluster = DeviceExt->LastAvailableCluster;
Offset.QuadPart = 0;
if(!CcMapData(DeviceExt->FATFileObject, &Offset, DeviceExt->FatInfo.FATSectors * BLOCKSIZE, 1, &Context, &BaseAddress))
if(!CcMapData(DeviceExt->FATFileObject, &Offset, DeviceExt->FatInfo.FATSectors * DeviceExt->FatInfo.BytesPerSector, 1, &Context, &BaseAddress))
{
DPRINT1("CcMapData(Offset %x, Length %d) failed\n", (ULONG)Offset.QuadPart, DeviceExt->FatInfo.FATSectors * BLOCKSIZE);
DPRINT1("CcMapData(Offset %x, Length %d) failed\n", (ULONG)Offset.QuadPart, DeviceExt->FatInfo.FATSectors * DeviceExt->FatInfo.BytesPerSector);
return STATUS_UNSUCCESSFUL;
}
@ -328,7 +328,7 @@ FAT12CountAvailableClusters(PDEVICE_EXTENSION DeviceExt)
PUSHORT CBlock;
Offset.QuadPart = 0;
if(!CcMapData(DeviceExt->FATFileObject, &Offset, DeviceExt->FatInfo.FATSectors * BLOCKSIZE, 1, &Context, &BaseAddress))
if(!CcMapData(DeviceExt->FATFileObject, &Offset, DeviceExt->FatInfo.FATSectors * DeviceExt->FatInfo.BytesPerSector, 1, &Context, &BaseAddress))
{
return STATUS_UNSUCCESSFUL;
}
@ -494,7 +494,7 @@ FAT12WriteCluster(PDEVICE_EXTENSION DeviceExt,
LARGE_INTEGER Offset;
Offset.QuadPart = 0;
if(!CcMapData(DeviceExt->FATFileObject, &Offset, DeviceExt->FatInfo.FATSectors * BLOCKSIZE, 1, &Context, &BaseAddress))
if(!CcMapData(DeviceExt->FATFileObject, &Offset, DeviceExt->FatInfo.FATSectors * DeviceExt->FatInfo.BytesPerSector, 1, &Context, &BaseAddress))
{
return STATUS_UNSUCCESSFUL;
}
@ -518,7 +518,7 @@ FAT12WriteCluster(PDEVICE_EXTENSION DeviceExt,
CBlock[FATOffset + 1] = NewValue >> 4;
}
/* Write the changed FAT sector(s) to disk */
FATsector = FATOffset / BLOCKSIZE;
FATsector = FATOffset / DeviceExt->FatInfo.BytesPerSector;
CcSetDirtyPinnedData(Context, NULL);
CcUnpinData(Context);
return(STATUS_SUCCESS);
@ -644,63 +644,6 @@ ClusterToSector(PDEVICE_EXTENSION DeviceExt,
((Cluster - 2) * DeviceExt->FatInfo.SectorsPerCluster);
}
NTSTATUS
VfatRawReadCluster(PDEVICE_EXTENSION DeviceExt,
ULONG FirstCluster,
PVOID Buffer,
ULONG Cluster,
ULONG Count)
/*
* FUNCTION: Load one ore more continus clusters from the physical device
*/
{
if (FirstCluster == 1)
{
return VfatReadSectors(DeviceExt->StorageDevice, Cluster,
DeviceExt->FatInfo.SectorsPerCluster * Count, Buffer);
}
else
{
ULONG Sector;
Sector = ClusterToSector(DeviceExt, Cluster);
return VfatReadSectors(DeviceExt->StorageDevice, Sector,
DeviceExt->FatInfo.SectorsPerCluster * Count, Buffer);
}
}
NTSTATUS
VfatRawWriteCluster(PDEVICE_EXTENSION DeviceExt,
ULONG FirstCluster,
PVOID Buffer,
ULONG Cluster,
ULONG Count)
/*
* FUNCTION: Write a cluster to the physical device
*/
{
ULONG Sector;
NTSTATUS Status;
DPRINT("VfatWriteCluster(DeviceExt %x, Buffer %x, Cluster %d)\n",
DeviceExt, Buffer, Cluster);
if (FirstCluster == 1)
{
Status = VfatWriteSectors(DeviceExt->StorageDevice, Cluster,
DeviceExt->FatInfo.SectorsPerCluster * Count, Buffer);
}
else
{
Sector = ClusterToSector(DeviceExt, Cluster);
Status = VfatWriteSectors(DeviceExt->StorageDevice, Sector,
DeviceExt->FatInfo.SectorsPerCluster * Count, Buffer);
}
return(Status);
}
NTSTATUS
GetNextCluster(PDEVICE_EXTENSION DeviceExt,
ULONG CurrentCluster,

View file

@ -1,4 +1,4 @@
/* $Id: fcb.c,v 1.14 2002/03/18 22:37:12 hbirr Exp $
/* $Id: fcb.c,v 1.15 2002/06/26 18:36:41 hbirr Exp $
*
*
* FILE: fcb.c
@ -206,7 +206,7 @@ vfatMakeRootFCB(PDEVICE_EXTENSION pVCB)
FCB = vfatNewFCB(L"\\");
memset(FCB->entry.Filename, ' ', 11);
FCB->entry.FileSize = pVCB->FatInfo.rootDirectorySectors * BLOCKSIZE;
FCB->entry.FileSize = pVCB->FatInfo.rootDirectorySectors * pVCB->FatInfo.BytesPerSector;
FCB->entry.Attrib = FILE_ATTRIBUTE_DIRECTORY;
if (pVCB->FatInfo.FatType == FAT32)
{
@ -224,7 +224,7 @@ vfatMakeRootFCB(PDEVICE_EXTENSION pVCB)
else
{
FCB->entry.FirstCluster = 1;
Size = pVCB->FatInfo.rootDirectorySectors * BLOCKSIZE;
Size = pVCB->FatInfo.rootDirectorySectors * pVCB->FatInfo.BytesPerSector;
}
FCB->RefCount = 1;
FCB->dirIndex = 0;
@ -296,7 +296,7 @@ vfatMakeFCBFromDirEntry(PVCB vcb,
FirstCluster = vfatDirEntryGetFirstCluster (vcb, &rcFCB->entry);
if (FirstCluster == 1)
{
Size = vcb->FatInfo.rootDirectorySectors * BLOCKSIZE;
Size = vcb->FatInfo.rootDirectorySectors * vcb->FatInfo.BytesPerSector;
}
else
{

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: fsctl.c,v 1.7 2002/06/07 16:53:18 hbirr Exp $
/* $Id: fsctl.c,v 1.8 2002/06/26 18:36:41 hbirr Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -51,6 +51,7 @@ VfatHasFileSystem(PDEVICE_OBJECT DeviceToMount,
FATINFO FatInfo;
ULONG Size;
ULONG Sectors;
LARGE_INTEGER Offset;
struct _BootSector* Boot;
*RecognizedFS = FALSE;
@ -111,14 +112,15 @@ VfatHasFileSystem(PDEVICE_OBJECT DeviceToMount,
{
return STATUS_SUCCESS;
}
ReadSector:
Boot = ExAllocatePool(NonPagedPool, BLOCKSIZE);
Boot = ExAllocatePool(NonPagedPool, DiskGeometry.BytesPerSector);
if (Boot == NULL)
{
*RecognizedFS=FALSE;
return STATUS_INSUFFICIENT_RESOURCES;
}
Status = VfatReadSectors(DeviceToMount, 0, 1, (PUCHAR) Boot);
Offset.QuadPart = 0;
Status = VfatReadDisk(DeviceToMount, &Offset, DiskGeometry.BytesPerSector, (PUCHAR) Boot);
if (NT_SUCCESS(Status))
{
FatInfo.VolumeID = Boot->VolumeID;
@ -311,7 +313,7 @@ VfatMount (PVFAT_IRP_CONTEXT IrpContext)
Fcb->Flags = FCB_IS_FAT;
Fcb->RFCB.FileSize.QuadPart = DeviceExt->FatInfo.FATSectors * BLOCKSIZE;
Fcb->RFCB.FileSize.QuadPart = DeviceExt->FatInfo.FATSectors * DeviceExt->FatInfo.BytesPerSector;
Fcb->RFCB.ValidDataLength = Fcb->RFCB.FileSize;
Fcb->RFCB.AllocationSize = Fcb->RFCB.FileSize;
@ -344,7 +346,7 @@ VfatMount (PVFAT_IRP_CONTEXT IrpContext)
wcscpy(VolumeFcb->PathName, L"$$Volume$$");
VolumeFcb->ObjectName = VolumeFcb->PathName;
VolumeFcb->Flags = FCB_IS_VOLUME;
VolumeFcb->RFCB.FileSize.QuadPart = DeviceExt->FatInfo.Sectors * BLOCKSIZE;
VolumeFcb->RFCB.FileSize.QuadPart = DeviceExt->FatInfo.Sectors * DeviceExt->FatInfo.BytesPerSector;
VolumeFcb->RFCB.ValidDataLength = VolumeFcb->RFCB.FileSize;
VolumeFcb->RFCB.AllocationSize = VolumeFcb->RFCB.FileSize;
VolumeFcb->pDevExt = (PDEVICE_EXTENSION)DeviceExt->StorageDevice;

View file

@ -1,4 +1,4 @@
# $Id: makefile,v 1.38 2002/03/18 22:37:13 hbirr Exp $
# $Id: makefile,v 1.39 2002/06/26 18:36:41 hbirr Exp $
PATH_TO_TOP = ../../..
@ -6,6 +6,8 @@ TARGET_TYPE = driver
TARGET_NAME = vfatfs
TARGET_GCCLIBS = gcc
TARGET_OBJECTS = \
blockdev.o \
cleanup.o \
@ -27,6 +29,8 @@ TARGET_OBJECTS = \
DEP_OBJECTS = $(TARGET_OBJECTS)
TARGET_CLEAN = $(DEP_FILES) *.o *.sys *.sym
TARGET_CFLAGS = -g
include $(PATH_TO_TOP)/rules.mak

View file

@ -1,5 +1,5 @@
/* $Id: rw.c,v 1.42 2002/06/10 21:17:57 hbirr Exp $
/* $Id: rw.c,v 1.43 2002/06/26 18:36:41 hbirr Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -270,14 +270,15 @@ VfatReadFileData (PVFAT_IRP_CONTEXT IrpContext, PVOID Buffer,
ULONG FirstCluster;
ULONG StartCluster;
ULONG ClusterCount;
ULONG StartSector;
ULONG SectorCount;
LARGE_INTEGER StartOffset;
PDEVICE_EXTENSION DeviceExt;
BOOLEAN First = TRUE;
PVFATFCB Fcb;
PVFATCCB Ccb;
NTSTATUS Status;
ULONG BytesDone;
ULONG BytesPerSector;
ULONG BytesPerCluster;
/* PRECONDITION */
assert (IrpContext);
@ -295,17 +296,18 @@ VfatReadFileData (PVFAT_IRP_CONTEXT IrpContext, PVOID Buffer,
Ccb = (PVFATCCB)IrpContext->FileObject->FsContext2;
Fcb = Ccb->pFcb;
BytesPerSector = DeviceExt->FatInfo.BytesPerSector;
BytesPerCluster = DeviceExt->FatInfo.BytesPerCluster;
assert(ReadOffset.QuadPart + Length <= ROUND_UP(Fcb->RFCB.FileSize.QuadPart, BLOCKSIZE));
assert(ReadOffset.QuadPart % BLOCKSIZE == 0);
assert(Length % BLOCKSIZE == 0);
assert(ReadOffset.QuadPart + Length <= ROUND_UP(Fcb->RFCB.FileSize.QuadPart, BytesPerSector));
assert(ReadOffset.u.LowPart % BytesPerSector == 0);
assert(Length % BytesPerSector == 0);
/* Is this a read of the FAT? */
if (Fcb->Flags & FCB_IS_FAT)
{
Status = VfatReadSectors(DeviceExt->StorageDevice,
DeviceExt->FatInfo.FATStart + ReadOffset.u.LowPart / BLOCKSIZE,
Length / BLOCKSIZE, Buffer);
ReadOffset.QuadPart += DeviceExt->FatInfo.FATStart * BytesPerSector;
Status = VfatReadDisk(DeviceExt->StorageDevice, &ReadOffset, Length, Buffer);
if (NT_SUCCESS(Status))
{
@ -317,12 +319,10 @@ VfatReadFileData (PVFAT_IRP_CONTEXT IrpContext, PVOID Buffer,
}
return Status;
}
/* Is this a read of the Volume */
/* Is this a read of the Volume ? */
if (Fcb->Flags & FCB_IS_VOLUME)
{
Status = VfatReadSectors(DeviceExt->StorageDevice,
ReadOffset.QuadPart / BLOCKSIZE,
Length / BLOCKSIZE, Buffer);
Status = VfatReadDisk(DeviceExt->StorageDevice, &ReadOffset, Length, Buffer);
if (NT_SUCCESS(Status))
{
*LengthRead = Length;
@ -344,16 +344,15 @@ VfatReadFileData (PVFAT_IRP_CONTEXT IrpContext, PVOID Buffer,
{
// Directory of FAT12/16 needs a special handling
CHECKPOINT;
if (ReadOffset.u.LowPart + Length > DeviceExt->FatInfo.rootDirectorySectors * BLOCKSIZE)
if (ReadOffset.u.LowPart + Length > DeviceExt->FatInfo.rootDirectorySectors * BytesPerSector)
{
Length = DeviceExt->FatInfo.rootDirectorySectors * BLOCKSIZE - ReadOffset.u.LowPart;
Length = DeviceExt->FatInfo.rootDirectorySectors * BytesPerSector - ReadOffset.u.LowPart;
}
StartSector = DeviceExt->FatInfo.rootStart + ReadOffset.u.LowPart / BLOCKSIZE;
SectorCount = Length / BLOCKSIZE;
ReadOffset.u.LowPart += DeviceExt->FatInfo.rootStart * BytesPerSector;
// Fire up the read command
Status = VfatReadSectors (DeviceExt->StorageDevice, StartSector,
SectorCount, Buffer);
Status = VfatReadDisk (DeviceExt->StorageDevice, &ReadOffset, Length, Buffer);
if (NT_SUCCESS(Status))
{
*LengthRead += Length;
@ -368,7 +367,7 @@ VfatReadFileData (PVFAT_IRP_CONTEXT IrpContext, PVOID Buffer,
CurrentCluster = Ccb->LastCluster;
}
Status = OffsetToCluster(DeviceExt, Fcb, FirstCluster,
ROUND_DOWN(ReadOffset.u.LowPart, DeviceExt->FatInfo.BytesPerCluster),
ROUND_DOWN(ReadOffset.u.LowPart, BytesPerCluster),
&CurrentCluster, FALSE);
if (!NT_SUCCESS(Status))
{
@ -376,13 +375,12 @@ VfatReadFileData (PVFAT_IRP_CONTEXT IrpContext, PVOID Buffer,
}
Ccb->LastCluster = CurrentCluster;
Ccb->LastOffset = ROUND_DOWN (ReadOffset.u.LowPart, DeviceExt->FatInfo.BytesPerCluster);
Ccb->LastOffset = ROUND_DOWN (ReadOffset.u.LowPart, BytesPerCluster);
while (Length > 0 && CurrentCluster != 0xffffffff && NT_SUCCESS(Status))
{
StartCluster = CurrentCluster;
StartSector = ClusterToSector(DeviceExt, StartCluster);
SectorCount = 0;
StartOffset.QuadPart = ClusterToSector(DeviceExt, StartCluster) * BytesPerSector;
BytesDone = 0;
ClusterCount = 0;
@ -391,21 +389,18 @@ VfatReadFileData (PVFAT_IRP_CONTEXT IrpContext, PVOID Buffer,
ClusterCount++;
if (First)
{
BytesDone = min (Length, DeviceExt->FatInfo.BytesPerCluster - (ReadOffset.u.LowPart % DeviceExt->FatInfo.BytesPerCluster));
SectorCount += BytesDone / BLOCKSIZE;
StartSector += (ReadOffset.u.LowPart % DeviceExt->FatInfo.BytesPerCluster) / BLOCKSIZE;
BytesDone = min (Length, BytesPerCluster - (ReadOffset.u.LowPart % BytesPerCluster));
StartOffset.QuadPart += ReadOffset.u.LowPart % BytesPerCluster;
First = FALSE;
}
else
{
if (Length - BytesDone > DeviceExt->FatInfo.BytesPerCluster)
if (Length - BytesDone > BytesPerCluster)
{
BytesDone += DeviceExt->FatInfo.BytesPerCluster;
SectorCount += DeviceExt->FatInfo.BytesPerCluster / BLOCKSIZE;
BytesDone += BytesPerCluster;
}
else
{
SectorCount += (Length - BytesDone) / BLOCKSIZE;
BytesDone = Length;
}
}
@ -416,11 +411,10 @@ VfatReadFileData (PVFAT_IRP_CONTEXT IrpContext, PVOID Buffer,
StartCluster, CurrentCluster, ClusterCount);
Ccb->LastCluster = StartCluster + (ClusterCount - 1);
Ccb->LastOffset = ReadOffset.u.LowPart + (ClusterCount - 1) * DeviceExt->FatInfo.BytesPerCluster;
Ccb->LastOffset = ReadOffset.u.LowPart + (ClusterCount - 1) * BytesPerCluster;
// Fire up the read command
Status = VfatReadSectors (DeviceExt->StorageDevice, StartSector,
SectorCount, Buffer);
Status = VfatReadDisk (DeviceExt->StorageDevice, &StartOffset, BytesDone, Buffer);
if (NT_SUCCESS(Status))
{
@ -444,13 +438,14 @@ NTSTATUS VfatWriteFileData(PVFAT_IRP_CONTEXT IrpContext,
ULONG Count;
ULONG FirstCluster;
ULONG CurrentCluster;
ULONG StartSector;
ULONG SectorCount;
ULONG BytesDone;
ULONG StartCluster;
ULONG ClusterCount;
NTSTATUS Status;
BOOLEAN First = TRUE;
ULONG BytesPerSector;
ULONG BytesPerCluster;
LARGE_INTEGER StartOffset;
/* PRECONDITION */
assert (IrpContext);
@ -462,22 +457,22 @@ NTSTATUS VfatWriteFileData(PVFAT_IRP_CONTEXT IrpContext,
Ccb = (PVFATCCB)IrpContext->FileObject->FsContext2;
Fcb = Ccb->pFcb;
BytesPerCluster = DeviceExt->FatInfo.BytesPerCluster;
BytesPerSector = DeviceExt->FatInfo.BytesPerSector;
DPRINT("VfatWriteFileData(DeviceExt %x, FileObject %x, Buffer %x, "
"Length %d, WriteOffset 0x%I64x), '%S'\n", DeviceExt,
IrpContext->FileObject, Buffer, Length, WriteOffset,
Fcb->PathName);
assert(WriteOffset.QuadPart + Length <= ROUND_UP(Fcb->RFCB.AllocationSize.QuadPart, BLOCKSIZE));
assert(WriteOffset.u.LowPart % BLOCKSIZE == 0);
assert(Length % BLOCKSIZE == 0)
assert(WriteOffset.QuadPart + Length <= Fcb->RFCB.AllocationSize.QuadPart);
assert(WriteOffset.u.LowPart % BytesPerSector == 0);
assert(Length % BytesPerSector == 0)
// Is this a write of the volume ?
if (Fcb->Flags & FCB_IS_VOLUME)
{
Status = VfatWriteSectors(DeviceExt->StorageDevice,
WriteOffset.QuadPart / BLOCKSIZE,
Length / BLOCKSIZE, Buffer);
Status = VfatWriteDisk(DeviceExt->StorageDevice, &WriteOffset, Length, Buffer);
if (!NT_SUCCESS(Status))
{
DPRINT1("Volume writing failed, Status %x\n", Status);
@ -488,15 +483,15 @@ NTSTATUS VfatWriteFileData(PVFAT_IRP_CONTEXT IrpContext,
// Is this a write to the FAT ?
if (Fcb->Flags & FCB_IS_FAT)
{
WriteOffset.u.LowPart += DeviceExt->FatInfo.FATStart * BytesPerSector;
for (Count = 0; Count < DeviceExt->FatInfo.FATCount; Count++)
{
Status = VfatWriteSectors(DeviceExt->StorageDevice,
DeviceExt->FatInfo.FATStart + (Count * (ULONG)Fcb->RFCB.FileSize.u.LowPart + WriteOffset.u.LowPart) / BLOCKSIZE,
Length / BLOCKSIZE, Buffer);
Status = VfatWriteDisk(DeviceExt->StorageDevice, &WriteOffset, Length, Buffer);
if (!NT_SUCCESS(Status))
{
DPRINT1("FAT writing failed, Status %x\n", Status);
}
WriteOffset.u.LowPart += Fcb->RFCB.FileSize.u.LowPart;
}
return Status;
}
@ -509,14 +504,11 @@ NTSTATUS VfatWriteFileData(PVFAT_IRP_CONTEXT IrpContext,
if (FirstCluster == 1)
{
assert(WriteOffset.u.LowPart + Length <= DeviceExt->FatInfo.rootDirectorySectors * BLOCKSIZE);
assert(WriteOffset.u.LowPart + Length <= DeviceExt->FatInfo.rootDirectorySectors * BytesPerSector);
// Directory of FAT12/16 needs a special handling
StartSector = DeviceExt->FatInfo.rootStart + WriteOffset.u.LowPart / BLOCKSIZE;
SectorCount = Length / BLOCKSIZE;
WriteOffset.u.LowPart += DeviceExt->FatInfo.rootStart * BytesPerSector;
// Fire up the write command
Status = VfatWriteSectors (DeviceExt->StorageDevice, StartSector,
SectorCount, Buffer);
Status = VfatWriteDisk (DeviceExt->StorageDevice, &WriteOffset, Length, Buffer);
return Status;
}
@ -529,7 +521,7 @@ NTSTATUS VfatWriteFileData(PVFAT_IRP_CONTEXT IrpContext,
}
Status = OffsetToCluster(DeviceExt, Fcb, FirstCluster,
ROUND_DOWN(WriteOffset.u.LowPart, DeviceExt->FatInfo.BytesPerCluster),
ROUND_DOWN(WriteOffset.u.LowPart, BytesPerCluster),
&CurrentCluster, FALSE);
if (!NT_SUCCESS(Status))
@ -538,13 +530,12 @@ NTSTATUS VfatWriteFileData(PVFAT_IRP_CONTEXT IrpContext,
}
Ccb->LastCluster = CurrentCluster;
Ccb->LastOffset = ROUND_DOWN (WriteOffset.u.LowPart, DeviceExt->FatInfo.BytesPerCluster);
Ccb->LastOffset = ROUND_DOWN (WriteOffset.u.LowPart, BytesPerCluster);
while (Length > 0 && CurrentCluster != 0xffffffff && NT_SUCCESS(Status))
{
StartCluster = CurrentCluster;
StartSector = ClusterToSector(DeviceExt, StartCluster);
SectorCount = 0;
StartOffset.QuadPart = ClusterToSector(DeviceExt, StartCluster) * BytesPerSector;
BytesDone = 0;
ClusterCount = 0;
@ -553,21 +544,18 @@ NTSTATUS VfatWriteFileData(PVFAT_IRP_CONTEXT IrpContext,
ClusterCount++;
if (First)
{
BytesDone = min (Length, DeviceExt->FatInfo.BytesPerCluster - (WriteOffset.u.LowPart % DeviceExt->FatInfo.BytesPerCluster));
SectorCount += BytesDone / BLOCKSIZE;
StartSector += (WriteOffset.u.LowPart % DeviceExt->FatInfo.BytesPerCluster) / BLOCKSIZE;
BytesDone = min (Length, BytesPerCluster - (WriteOffset.u.LowPart % BytesPerCluster));
StartOffset.QuadPart += WriteOffset.u.LowPart % BytesPerCluster;
First = FALSE;
}
else
{
if (Length - BytesDone > DeviceExt->FatInfo.BytesPerCluster)
if (Length - BytesDone > BytesPerCluster)
{
BytesDone += DeviceExt->FatInfo.BytesPerCluster;
SectorCount += DeviceExt->FatInfo.BytesPerCluster / BLOCKSIZE;
BytesDone += BytesPerCluster;
}
else
{
SectorCount += (Length - BytesDone) / BLOCKSIZE;
BytesDone = Length;
}
}
@ -578,11 +566,10 @@ NTSTATUS VfatWriteFileData(PVFAT_IRP_CONTEXT IrpContext,
StartCluster, CurrentCluster, ClusterCount);
Ccb->LastCluster = StartCluster + (ClusterCount - 1);
Ccb->LastOffset = WriteOffset.u.LowPart + (ClusterCount - 1) * DeviceExt->FatInfo.BytesPerCluster;
Ccb->LastOffset = WriteOffset.u.LowPart + (ClusterCount - 1) * BytesPerCluster;
// Fire up the write command
Status = VfatWriteSectors (DeviceExt->StorageDevice, StartSector,
SectorCount, Buffer);
Status = VfatWriteDisk (DeviceExt->StorageDevice, &StartOffset, BytesDone, Buffer);
if (NT_SUCCESS(Status))
{
Buffer += BytesDone;
@ -722,6 +709,7 @@ VfatRead(PVFAT_IRP_CONTEXT IrpContext)
LARGE_INTEGER ByteOffset;
PVOID Buffer;
PDEVICE_OBJECT DeviceToVerify;
ULONG BytesPerSector;
assert(IrpContext);
@ -748,6 +736,7 @@ VfatRead(PVFAT_IRP_CONTEXT IrpContext)
ByteOffset = IrpContext->Stack->Parameters.Read.ByteOffset;
Length = IrpContext->Stack->Parameters.Read.Length;
BytesPerSector = IrpContext->DeviceExt->FatInfo.BytesPerSector;
/* fail if file is a directory and no paged read */
if (Fcb->entry.Attrib & FILE_ATTRIBUTE_DIRECTORY && !(IrpContext->Irp->Flags & IRP_PAGING_IO))
@ -772,7 +761,7 @@ VfatRead(PVFAT_IRP_CONTEXT IrpContext)
}
if (IrpContext->Irp->Flags & (IRP_PAGING_IO | IRP_NOCACHE) || (Fcb->Flags & FCB_IS_VOLUME))
{
if (ByteOffset.u.LowPart % BLOCKSIZE != 0 || Length % BLOCKSIZE != 0)
if (ByteOffset.u.LowPart % BytesPerSector != 0 || Length % BytesPerSector != 0)
{
DPRINT("%d %d\n", ByteOffset.u.LowPart, Length);
// non chached read must be sector aligned
@ -842,9 +831,9 @@ VfatRead(PVFAT_IRP_CONTEXT IrpContext)
{
// non cached read
CHECKPOINT;
if (ByteOffset.QuadPart + Length > ROUND_UP(Fcb->RFCB.FileSize.QuadPart, BLOCKSIZE))
if (ByteOffset.QuadPart + Length > ROUND_UP(Fcb->RFCB.FileSize.QuadPart, BytesPerSector))
{
Length = ROUND_UP(Fcb->RFCB.FileSize.QuadPart, BLOCKSIZE) - ByteOffset.QuadPart;
Length = ROUND_UP(Fcb->RFCB.FileSize.QuadPart, BytesPerSector) - ByteOffset.QuadPart;
}
Buffer = VfatGetUserBuffer(IrpContext->Irp);
@ -854,8 +843,7 @@ VfatRead(PVFAT_IRP_CONTEXT IrpContext)
goto ByeBye;
}
Status = VfatReadFileData(IrpContext, Buffer, Length,
ByteOffset, &ReturnedLength);
Status = VfatReadFileData(IrpContext, Buffer, Length, ByteOffset, &ReturnedLength);
/*
if (Status == STATUS_VERIFY_REQUIRED)
{
@ -927,6 +915,7 @@ NTSTATUS VfatWrite (PVFAT_IRP_CONTEXT IrpContext)
ULONG Length;
ULONG OldAllocationSize;
PVOID Buffer;
ULONG BytesPerSector;
assert (IrpContext);
@ -960,6 +949,7 @@ NTSTATUS VfatWrite (PVFAT_IRP_CONTEXT IrpContext)
ByteOffset = IrpContext->Stack->Parameters.Write.ByteOffset;
Length = IrpContext->Stack->Parameters.Write.Length;
BytesPerSector = IrpContext->DeviceExt->FatInfo.BytesPerSector;
if (ByteOffset.u.HighPart && !(Fcb->Flags & FCB_IS_VOLUME))
{
@ -967,7 +957,6 @@ NTSTATUS VfatWrite (PVFAT_IRP_CONTEXT IrpContext)
goto ByeBye;
}
if (Fcb->Flags & (FCB_IS_FAT | FCB_IS_VOLUME) ||
1 == vfatDirEntryGetFirstCluster (IrpContext->DeviceExt, &Fcb->entry))
{
@ -981,7 +970,7 @@ NTSTATUS VfatWrite (PVFAT_IRP_CONTEXT IrpContext)
if (IrpContext->Irp->Flags & (IRP_PAGING_IO|IRP_NOCACHE) || (Fcb->Flags & FCB_IS_VOLUME))
{
if (ByteOffset.u.LowPart % BLOCKSIZE != 0 || Length % BLOCKSIZE != 0)
if (ByteOffset.u.LowPart % BytesPerSector != 0 || Length % BytesPerSector != 0)
{
// non chached write must be sector aligned
Status = STATUS_INVALID_PARAMETER;
@ -1003,9 +992,9 @@ NTSTATUS VfatWrite (PVFAT_IRP_CONTEXT IrpContext)
Status = STATUS_INVALID_PARAMETER;
goto ByeBye;
}
if (ByteOffset.u.LowPart + Length > ROUND_UP(Fcb->RFCB.AllocationSize.u.LowPart, BLOCKSIZE))
if (ByteOffset.u.LowPart + Length > ROUND_UP(Fcb->RFCB.AllocationSize.u.LowPart, BytesPerSector))
{
Length = ROUND_UP(Fcb->RFCB.FileSize.u.LowPart, BLOCKSIZE) - ByteOffset.u.LowPart;
Length = ROUND_UP(Fcb->RFCB.FileSize.u.LowPart, BytesPerSector) - ByteOffset.u.LowPart;
}
}
@ -1108,9 +1097,7 @@ NTSTATUS VfatWrite (PVFAT_IRP_CONTEXT IrpContext)
goto ByeBye;
}
Status = VfatWriteFileData(IrpContext, Buffer, Length,
ByteOffset);
Status = VfatWriteFileData(IrpContext, Buffer, Length, ByteOffset);
if (NT_SUCCESS(Status))
{
IrpContext->Irp->IoStatus.Information = Length;

View file

@ -1,4 +1,4 @@
/* $Id: vfat.h,v 1.42 2002/06/10 21:15:58 hbirr Exp $ */
/* $Id: vfat.h,v 1.43 2002/06/26 18:36:41 hbirr Exp $ */
#include <ddk/ntifs.h>
@ -248,14 +248,14 @@ NTSTATUS VfatSetVolumeInformation (PVFAT_IRP_CONTEXT IrpContext);
/* ------------------------------------------------------ blockdev.c */
NTSTATUS VfatReadSectors(IN PDEVICE_OBJECT pDeviceObject,
IN ULONG DiskSector,
IN ULONG SectorCount,
NTSTATUS VfatReadDisk(IN PDEVICE_OBJECT pDeviceObject,
IN PLARGE_INTEGER ReadOffset,
IN ULONG ReadLength,
IN PUCHAR Buffer);
NTSTATUS VfatWriteSectors(IN PDEVICE_OBJECT pDeviceObject,
IN ULONG DiskSector,
IN ULONG SectorCount,
NTSTATUS VfatWriteDisk(IN PDEVICE_OBJECT pDeviceObject,
IN PLARGE_INTEGER WriteOffset,
IN ULONG WriteLength,
IN PUCHAR Buffer);
NTSTATUS VfatBlockDeviceIoControl (IN PDEVICE_OBJECT DeviceObject,
@ -398,18 +398,6 @@ NTSTATUS GetNextSector (PDEVICE_EXTENSION DeviceExt,
PULONG NextSector,
BOOLEAN Extend);
NTSTATUS VfatRawReadCluster (PDEVICE_EXTENSION DeviceExt,
ULONG FirstCluster,
PVOID Buffer,
ULONG Cluster,
ULONG Count);
NTSTATUS VfatRawWriteCluster (PDEVICE_EXTENSION DeviceExt,
ULONG FirstCluster,
PVOID Buffer,
ULONG Cluster,
ULONG Count);
NTSTATUS CountAvailableClusters (PDEVICE_EXTENSION DeviceExt,
PLARGE_INTEGER Clusters);