Implemented read support.

Disabled debug messages.

svn path=/trunk/; revision=2901
This commit is contained in:
Eric Kohl 2002-05-01 21:52:05 +00:00
parent 7e9f288b08
commit bff0ad1c2b
2 changed files with 145 additions and 32 deletions

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -29,30 +29,42 @@
/* INCLUDES *****************************************************************/ /* INCLUDES *****************************************************************/
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
#include <ntos/minmax.h>
//#define NDEBUG #define NDEBUG
#include <debug.h> #include <debug.h>
#include "cdfs.h" #include "cdfs.h"
/* GLOBALS *******************************************************************/
#define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))
#define ROUND_DOWN(N, S) ((N) - ((N) % (S)))
/* FUNCTIONS ****************************************************************/ /* FUNCTIONS ****************************************************************/
static NTSTATUS static NTSTATUS
CdfsReadFile(PDEVICE_EXTENSION DeviceExt, CdfsReadFile(PDEVICE_EXTENSION DeviceExt,
PFILE_OBJECT FileObject, PFILE_OBJECT FileObject,
PVOID Buffer, PUCHAR Buffer,
ULONG Length, ULONG Length,
ULONG Offset) ULONG ReadOffset,
PULONG LengthRead)
/* /*
* FUNCTION: Reads data from a file * FUNCTION: Reads data from a file
*/ */
{ {
NTSTATUS Status; NTSTATUS Status = STATUS_SUCCESS;
PUCHAR TempBuffer;
ULONG TempLength;
PCCB Ccb; PCCB Ccb;
PFCB Fcb; 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) if (Length == 0)
return STATUS_SUCCESS; return STATUS_SUCCESS;
@ -60,18 +72,88 @@ CdfsReadFile(PDEVICE_EXTENSION DeviceExt,
Ccb = (PCCB)FileObject->FsContext2; Ccb = (PCCB)FileObject->FsContext2;
Fcb = Ccb->Fcb; Fcb = Ccb->Fcb;
if (Offset + Length > Fcb->Entry.DataLengthL) if (ReadOffset + Length > Fcb->Entry.DataLengthL)
Length = Fcb->Entry.DataLengthL - Offset; 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) if (Length == 0)
return(STATUS_UNSUCCESSFUL); return(STATUS_UNSUCCESSFUL);
Status = CdfsReadSectors(DeviceExt->StorageDevice, #if 0
Fcb->Entry.ExtentLocationL + Offset / BLOCKSIZE, if ((FileObject->Flags & FO_NO_INTERMEDIATE_BUFFERING) == 0)
Length / BLOCKSIZE, {
Buffer); 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); return(Status);
} }
@ -81,25 +163,56 @@ NTSTATUS STDCALL
CdfsRead(PDEVICE_OBJECT DeviceObject, CdfsRead(PDEVICE_OBJECT DeviceObject,
PIRP Irp) PIRP Irp)
{ {
ULONG Length; PDEVICE_EXTENSION DeviceExt;
PIO_STACK_LOCATION Stack;
PFILE_OBJECT FileObject;
PVOID Buffer; PVOID Buffer;
ULONG Offset; ULONG ReadLength;
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp); LARGE_INTEGER ReadOffset;
PFILE_OBJECT FileObject = Stack->FileObject; ULONG ReturnedReadLength = 0;
PDEVICE_EXTENSION DeviceExt = DeviceObject->DeviceExtension; NTSTATUS Status = STATUS_SUCCESS;
NTSTATUS Status;
DPRINT("CdfsRead(DeviceObject %x, Irp %x)\n",DeviceObject,Irp); DPRINT("CdfsRead(DeviceObject %x, Irp %x)\n",DeviceObject,Irp);
Buffer = MmGetSystemAddressForMdl(Irp->MdlAddress); if (Irp->Flags & IRP_PAGING_IO)
Length = Stack->Parameters.Read.Length; {
Offset = Stack->Parameters.Read.ByteOffset.u.LowPart; 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.Status = Status;
Irp->IoStatus.Information = Length;
IoCompleteRequest(Irp,IO_NO_INCREMENT); IoCompleteRequest(Irp,IO_NO_INCREMENT);
return(Status); return(Status);
} }
@ -110,9 +223,9 @@ CdfsWrite(PDEVICE_OBJECT DeviceObject,
{ {
DPRINT("CdfsWrite(DeviceObject %x Irp %x)\n",DeviceObject,Irp); DPRINT("CdfsWrite(DeviceObject %x Irp %x)\n",DeviceObject,Irp);
Irp->IoStatus.Status = STATUS_UNSUCCESSFUL; Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
Irp->IoStatus.Information = 0; Irp->IoStatus.Information = 0;
return(STATUS_UNSUCCESSFUL); return(STATUS_NOT_SUPPORTED);
} }
/* EOF */ /* EOF */

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 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 * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -29,7 +29,7 @@
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
//#define NDEBUG #define NDEBUG
#include <debug.h> #include <debug.h>
#include "cdfs.h" #include "cdfs.h"
@ -131,7 +131,7 @@ CdfsGetFsSizeInformation(PDEVICE_OBJECT DeviceObject,
FsSizeInfo->AvailableAllocationUnits.QuadPart = 0; FsSizeInfo->AvailableAllocationUnits.QuadPart = 0;
FsSizeInfo->TotalAllocationUnits.QuadPart = DeviceExt->CdInfo.VolumeSpaceSize; FsSizeInfo->TotalAllocationUnits.QuadPart = DeviceExt->CdInfo.VolumeSpaceSize;
FsSizeInfo->SectorsPerAllocationUnit = 1; FsSizeInfo->SectorsPerAllocationUnit = 1;
FsSizeInfo->BytesPerSector = 2048; /* ?? */ FsSizeInfo->BytesPerSector = BLOCKSIZE;
DPRINT("Finished FsdGetFsSizeInformation()\n"); DPRINT("Finished FsdGetFsSizeInformation()\n");
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
@ -198,18 +198,18 @@ CdfsQueryVolumeInformation(PDEVICE_OBJECT DeviceObject,
Status = CdfsGetFsAttributeInformation(DeviceObject->DeviceExtension, Status = CdfsGetFsAttributeInformation(DeviceObject->DeviceExtension,
SystemBuffer, SystemBuffer,
&BufferLength); &BufferLength);
break; break;
case FileFsSizeInformation: case FileFsSizeInformation:
Status = CdfsGetFsSizeInformation(DeviceObject, Status = CdfsGetFsSizeInformation(DeviceObject,
SystemBuffer, SystemBuffer,
&BufferLength); &BufferLength);
break; break;
case FileFsDeviceInformation: case FileFsDeviceInformation:
Status = CdfsGetFsDeviceInformation(SystemBuffer, Status = CdfsGetFsDeviceInformation(SystemBuffer,
&BufferLength); &BufferLength);
break; break;
default: default:
Status = STATUS_NOT_SUPPORTED; Status = STATUS_NOT_SUPPORTED;