From bff0ad1c2ba6d4669562c187b30c1b742480e4a4 Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Wed, 1 May 2002 21:52:05 +0000 Subject: [PATCH] Implemented read support. Disabled debug messages. svn path=/trunk/; revision=2901 --- reactos/drivers/fs/cdfs/rw.c | 165 +++++++++++++++++++++++++----- reactos/drivers/fs/cdfs/volinfo.c | 12 +-- 2 files changed, 145 insertions(+), 32 deletions(-) diff --git a/reactos/drivers/fs/cdfs/rw.c b/reactos/drivers/fs/cdfs/rw.c index b0a75574bea..b4b209a4c34 100644 --- a/reactos/drivers/fs/cdfs/rw.c +++ b/reactos/drivers/fs/cdfs/rw.c @@ -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: rw.c,v 1.1 2002/04/15 20:39:49 ekohl Exp $ +/* $Id: rw.c,v 1.2 2002/05/01 21:52:05 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -29,30 +29,42 @@ /* INCLUDES *****************************************************************/ #include +#include -//#define NDEBUG +#define NDEBUG #include #include "cdfs.h" +/* GLOBALS *******************************************************************/ + +#define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S)) +#define ROUND_DOWN(N, S) ((N) - ((N) % (S))) + + /* FUNCTIONS ****************************************************************/ static NTSTATUS CdfsReadFile(PDEVICE_EXTENSION DeviceExt, PFILE_OBJECT FileObject, - PVOID Buffer, + PUCHAR Buffer, ULONG Length, - ULONG Offset) + ULONG ReadOffset, + PULONG LengthRead) /* * FUNCTION: Reads data from a file */ { - NTSTATUS Status; + NTSTATUS Status = STATUS_SUCCESS; + PUCHAR TempBuffer; + ULONG TempLength; PCCB Ccb; PFCB Fcb; - DPRINT("CdfsReadFile(Offset %lu Length %lu)\n", Offset, Length); + DPRINT("CdfsReadFile(ReadOffset %lu Length %lu)\n", ReadOffset, Length); + + *LengthRead = 0; if (Length == 0) return STATUS_SUCCESS; @@ -60,18 +72,88 @@ CdfsReadFile(PDEVICE_EXTENSION DeviceExt, Ccb = (PCCB)FileObject->FsContext2; Fcb = Ccb->Fcb; - if (Offset + Length > Fcb->Entry.DataLengthL) - Length = Fcb->Entry.DataLengthL - Offset; + if (ReadOffset + Length > Fcb->Entry.DataLengthL) + Length = Fcb->Entry.DataLengthL - ReadOffset; - DPRINT( "Reading %d bytes at %d\n", Offset, Length ); + DPRINT("Reading %d bytes at %d\n", Length, ReadOffset); if (Length == 0) return(STATUS_UNSUCCESSFUL); - Status = CdfsReadSectors(DeviceExt->StorageDevice, - Fcb->Entry.ExtentLocationL + Offset / BLOCKSIZE, - Length / BLOCKSIZE, - Buffer); +#if 0 + if ((FileObject->Flags & FO_NO_INTERMEDIATE_BUFFERING) == 0) + { + LARGE_INTEGER FileOffset; + IO_STATUS_BLOCK IoStatus; + + FileOffset.QuadPart = ReadOffset; + CcCopyRead(FileObject, + &FileOffset, + Length, + TRUE, + Buffer, + &IoStatus); + *LengthRead = IoStatus.Information; + + return(IoStatus.Status); + } +#endif + + if ((ReadOffset % BLOCKSIZE) != 0) + { + TempLength = min(Length, BLOCKSIZE - (ReadOffset % BLOCKSIZE)); + TempBuffer = ExAllocatePool(NonPagedPool, BLOCKSIZE); + + Status = CdfsReadSectors(DeviceExt->StorageDevice, + Fcb->Entry.ExtentLocationL + (ReadOffset / BLOCKSIZE), + 1, + TempBuffer); + if (NT_SUCCESS(Status)) + { + memcpy(Buffer, TempBuffer + (ReadOffset % BLOCKSIZE), TempLength); + (*LengthRead) = (*LengthRead) + TempLength; + Length = Length - TempLength; + Buffer = Buffer + TempLength; + ReadOffset = ReadOffset + TempLength; + } + ExFreePool(TempBuffer); + } + + DPRINT("Status %lx\n", Status); + + if ((Length / BLOCKSIZE) != 0 && NT_SUCCESS(Status)) + { + TempLength = ROUND_DOWN(Length, BLOCKSIZE); + Status = CdfsReadSectors(DeviceExt->StorageDevice, + Fcb->Entry.ExtentLocationL + (ReadOffset / BLOCKSIZE), + Length / BLOCKSIZE, + Buffer); + if (NT_SUCCESS(Status)) + { + (*LengthRead) = (*LengthRead) + TempLength; + Length = Length - TempLength; + Buffer = Buffer + TempLength; + ReadOffset = ReadOffset + TempLength; + } + } + + DPRINT("Status %lx\n", Status); + + if (Length > 0 && NT_SUCCESS(Status)) + { + TempBuffer = ExAllocatePool(NonPagedPool, BLOCKSIZE); + + Status = CdfsReadSectors(DeviceExt->StorageDevice, + Fcb->Entry.ExtentLocationL + (ReadOffset / BLOCKSIZE), + 1, + TempBuffer); + if (NT_SUCCESS(Status)) + { + memcpy(Buffer, TempBuffer, Length); + (*LengthRead) = (*LengthRead) + Length; + } + ExFreePool(TempBuffer); + } return(Status); } @@ -81,25 +163,56 @@ NTSTATUS STDCALL CdfsRead(PDEVICE_OBJECT DeviceObject, PIRP Irp) { - ULONG Length; + PDEVICE_EXTENSION DeviceExt; + PIO_STACK_LOCATION Stack; + PFILE_OBJECT FileObject; PVOID Buffer; - ULONG Offset; - PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp); - PFILE_OBJECT FileObject = Stack->FileObject; - PDEVICE_EXTENSION DeviceExt = DeviceObject->DeviceExtension; - NTSTATUS Status; + ULONG ReadLength; + LARGE_INTEGER ReadOffset; + ULONG ReturnedReadLength = 0; + NTSTATUS Status = STATUS_SUCCESS; DPRINT("CdfsRead(DeviceObject %x, Irp %x)\n",DeviceObject,Irp); - Buffer = MmGetSystemAddressForMdl(Irp->MdlAddress); - Length = Stack->Parameters.Read.Length; - Offset = Stack->Parameters.Read.ByteOffset.u.LowPart; + if (Irp->Flags & IRP_PAGING_IO) + { + Status = STATUS_NOT_SUPPORTED; + goto ByeBye; + } - Status = CdfsReadFile(DeviceExt,FileObject,Buffer,Length,Offset); + DeviceExt = DeviceObject->DeviceExtension; + Stack = IoGetCurrentIrpStackLocation(Irp); + FileObject = Stack->FileObject; + + ReadLength = Stack->Parameters.Read.Length; + ReadOffset = Stack->Parameters.Read.ByteOffset; + Buffer = MmGetSystemAddressForMdl(Irp->MdlAddress); + + Status = CdfsReadFile(DeviceExt, + FileObject, + Buffer, + ReadLength, + ReadOffset.u.LowPart, + &ReturnedReadLength); + +ByeBye: + if (NT_SUCCESS(Status)) + { + if (FileObject->Flags & FO_SYNCHRONOUS_IO) + { + FileObject->CurrentByteOffset.QuadPart = + ReadOffset.QuadPart + ReturnedReadLength; + } + Irp->IoStatus.Information = ReturnedReadLength; + } + else + { + Irp->IoStatus.Information = 0; + } Irp->IoStatus.Status = Status; - Irp->IoStatus.Information = Length; IoCompleteRequest(Irp,IO_NO_INCREMENT); + return(Status); } @@ -110,9 +223,9 @@ CdfsWrite(PDEVICE_OBJECT DeviceObject, { DPRINT("CdfsWrite(DeviceObject %x Irp %x)\n",DeviceObject,Irp); - Irp->IoStatus.Status = STATUS_UNSUCCESSFUL; + Irp->IoStatus.Status = STATUS_NOT_SUPPORTED; Irp->IoStatus.Information = 0; - return(STATUS_UNSUCCESSFUL); + return(STATUS_NOT_SUPPORTED); } /* EOF */ diff --git a/reactos/drivers/fs/cdfs/volinfo.c b/reactos/drivers/fs/cdfs/volinfo.c index a6ef384b694..0225b9c096e 100644 --- a/reactos/drivers/fs/cdfs/volinfo.c +++ b/reactos/drivers/fs/cdfs/volinfo.c @@ -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: volinfo.c,v 1.1 2002/04/15 20:39:49 ekohl Exp $ +/* $Id: volinfo.c,v 1.2 2002/05/01 21:52:05 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -29,7 +29,7 @@ #include -//#define NDEBUG +#define NDEBUG #include #include "cdfs.h" @@ -131,7 +131,7 @@ CdfsGetFsSizeInformation(PDEVICE_OBJECT DeviceObject, FsSizeInfo->AvailableAllocationUnits.QuadPart = 0; FsSizeInfo->TotalAllocationUnits.QuadPart = DeviceExt->CdInfo.VolumeSpaceSize; FsSizeInfo->SectorsPerAllocationUnit = 1; - FsSizeInfo->BytesPerSector = 2048; /* ?? */ + FsSizeInfo->BytesPerSector = BLOCKSIZE; DPRINT("Finished FsdGetFsSizeInformation()\n"); if (NT_SUCCESS(Status)) @@ -198,18 +198,18 @@ CdfsQueryVolumeInformation(PDEVICE_OBJECT DeviceObject, Status = CdfsGetFsAttributeInformation(DeviceObject->DeviceExtension, SystemBuffer, &BufferLength); - break; + break; case FileFsSizeInformation: Status = CdfsGetFsSizeInformation(DeviceObject, SystemBuffer, &BufferLength); - break; + break; case FileFsDeviceInformation: Status = CdfsGetFsDeviceInformation(SystemBuffer, &BufferLength); - break; + break; default: Status = STATUS_NOT_SUPPORTED;