2002-04-15 20:39:49 +00:00
|
|
|
/*
|
2009-02-03 14:50:50 +00:00
|
|
|
* ReactOS kernel
|
|
|
|
* Copyright (C) 2002, 2003 ReactOS Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
2009-10-27 10:34:16 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2009-02-03 14:50:50 +00:00
|
|
|
*/
|
2005-01-06 13:58:04 +00:00
|
|
|
/* $Id$
|
2009-02-03 14:50:50 +00:00
|
|
|
*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
|
|
|
* FILE: drivers/fs/cdfs/rw.c
|
|
|
|
* PURPOSE: CDROM (ISO 9660) filesystem driver
|
|
|
|
* PROGRAMMER: Art Yerkes
|
|
|
|
* Eric Kohl
|
|
|
|
*/
|
2002-04-15 20:39:49 +00:00
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
2005-07-20 02:52:52 +00:00
|
|
|
#include "cdfs.h"
|
2002-04-15 20:39:49 +00:00
|
|
|
|
2002-05-01 21:52:05 +00:00
|
|
|
#define NDEBUG
|
2002-04-15 20:39:49 +00:00
|
|
|
#include <debug.h>
|
|
|
|
|
2005-07-20 02:52:52 +00:00
|
|
|
/* FUNCTIONS ****************************************************************/
|
2002-05-01 21:52:05 +00:00
|
|
|
|
|
|
|
#define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))
|
|
|
|
#define ROUND_DOWN(N, S) ((N) - ((N) % (S)))
|
|
|
|
|
|
|
|
|
2002-04-15 20:39:49 +00:00
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
|
|
|
|
static NTSTATUS
|
|
|
|
CdfsReadFile(PDEVICE_EXTENSION DeviceExt,
|
2009-02-03 14:50:50 +00:00
|
|
|
PFILE_OBJECT FileObject,
|
|
|
|
PUCHAR Buffer,
|
|
|
|
ULONG Length,
|
|
|
|
ULONG ReadOffset,
|
|
|
|
ULONG IrpFlags,
|
|
|
|
PULONG LengthRead)
|
|
|
|
/*
|
|
|
|
* FUNCTION: Reads data from a file
|
|
|
|
*/
|
2002-04-15 20:39:49 +00:00
|
|
|
{
|
2009-02-03 14:50:50 +00:00
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
PCCB Ccb;
|
|
|
|
PFCB Fcb;
|
2002-04-15 20:39:49 +00:00
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
DPRINT("CdfsReadFile(ReadOffset %lu Length %lu)\n", ReadOffset, Length);
|
2002-05-01 21:52:05 +00:00
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
*LengthRead = 0;
|
2002-04-15 20:39:49 +00:00
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
if (Length == 0)
|
|
|
|
return(STATUS_SUCCESS);
|
2002-04-15 20:39:49 +00:00
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
Ccb = (PCCB)FileObject->FsContext2;
|
|
|
|
Fcb = (PFCB)FileObject->FsContext;
|
2002-04-15 20:39:49 +00:00
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
if (ReadOffset >= Fcb->Entry.DataLengthL)
|
|
|
|
return(STATUS_END_OF_FILE);
|
2002-11-20 21:55:25 +00:00
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
DPRINT("Reading %d bytes at %d\n", Length, ReadOffset);
|
2002-04-15 20:39:49 +00:00
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
if (!(IrpFlags & (IRP_NOCACHE|IRP_PAGING_IO)))
|
2002-05-01 21:52:05 +00:00
|
|
|
{
|
2009-02-03 14:50:50 +00:00
|
|
|
LARGE_INTEGER FileOffset;
|
|
|
|
IO_STATUS_BLOCK IoStatus;
|
|
|
|
CC_FILE_SIZES FileSizes;
|
|
|
|
|
|
|
|
if (ReadOffset + Length > Fcb->Entry.DataLengthL)
|
|
|
|
Length = Fcb->Entry.DataLengthL - ReadOffset;
|
|
|
|
|
|
|
|
if (FileObject->PrivateCacheMap == NULL)
|
|
|
|
{
|
|
|
|
FileSizes.AllocationSize = Fcb->RFCB.AllocationSize;
|
|
|
|
FileSizes.FileSize = Fcb->RFCB.FileSize;
|
|
|
|
FileSizes.ValidDataLength = Fcb->RFCB.ValidDataLength;
|
|
|
|
|
|
|
|
DPRINT("Attach FCB to File: Size %08x%08x\n",
|
|
|
|
Fcb->RFCB.ValidDataLength.HighPart,
|
|
|
|
Fcb->RFCB.ValidDataLength.LowPart);
|
|
|
|
|
|
|
|
CcInitializeCacheMap(FileObject,
|
|
|
|
&FileSizes,
|
|
|
|
FALSE,
|
|
|
|
&(CdfsGlobalData->CacheMgrCallbacks),
|
|
|
|
Fcb);
|
|
|
|
}
|
|
|
|
|
|
|
|
FileOffset.QuadPart = (LONGLONG)ReadOffset;
|
|
|
|
CcCopyRead(FileObject,
|
|
|
|
&FileOffset,
|
|
|
|
Length,
|
|
|
|
TRUE,
|
|
|
|
Buffer,
|
|
|
|
&IoStatus);
|
|
|
|
*LengthRead = IoStatus.Information;
|
|
|
|
|
|
|
|
return(IoStatus.Status);
|
2002-05-01 21:52:05 +00:00
|
|
|
}
|
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
if ((ReadOffset % BLOCKSIZE) != 0 || (Length % BLOCKSIZE) != 0)
|
2002-05-01 21:52:05 +00:00
|
|
|
{
|
2009-02-03 14:50:50 +00:00
|
|
|
/* Then we need to do a partial or misaligned read ... */
|
|
|
|
PVOID PageBuf = ExAllocatePool(NonPagedPool, BLOCKSIZE);
|
|
|
|
PCHAR ReadInPage = (PCHAR)PageBuf + (ReadOffset & (BLOCKSIZE - 1));
|
|
|
|
PCHAR TargetRead = (PCHAR)Buffer;
|
|
|
|
ULONG ActualReadOffset, EndOfExtent, ReadLen;
|
2008-11-20 20:02:36 +00:00
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
if (!PageBuf)
|
2008-11-20 20:02:36 +00:00
|
|
|
{
|
2009-02-03 14:50:50 +00:00
|
|
|
return STATUS_NO_MEMORY;
|
|
|
|
}
|
2003-11-13 15:26:34 +00:00
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
ActualReadOffset = ReadOffset & ~(BLOCKSIZE - 1);
|
|
|
|
EndOfExtent = ReadOffset + Length;
|
2008-11-20 20:02:36 +00:00
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
while (ActualReadOffset < EndOfExtent)
|
2008-11-20 20:02:36 +00:00
|
|
|
{
|
2009-02-03 14:50:50 +00:00
|
|
|
Status = CdfsReadSectors
|
|
|
|
(DeviceExt->StorageDevice,
|
|
|
|
Fcb->Entry.ExtentLocationL + (ActualReadOffset / BLOCKSIZE),
|
|
|
|
1,
|
|
|
|
PageBuf,
|
|
|
|
FALSE);
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
break;
|
|
|
|
|
|
|
|
ReadLen = BLOCKSIZE - (ActualReadOffset & (BLOCKSIZE - 1));
|
|
|
|
if (ReadLen > EndOfExtent - ActualReadOffset)
|
|
|
|
{
|
|
|
|
ReadLen = EndOfExtent - ActualReadOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlCopyMemory(TargetRead, ReadInPage, ReadLen);
|
|
|
|
|
|
|
|
ActualReadOffset += ReadLen;
|
|
|
|
TargetRead += ReadLen;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExFreePool(PageBuf);
|
2008-11-20 20:02:36 +00:00
|
|
|
}
|
2009-02-03 14:50:50 +00:00
|
|
|
else
|
2002-05-01 21:52:05 +00:00
|
|
|
{
|
2009-02-03 14:50:50 +00:00
|
|
|
if (ReadOffset + Length > ROUND_UP(Fcb->Entry.DataLengthL, BLOCKSIZE))
|
|
|
|
Length = ROUND_UP(Fcb->Entry.DataLengthL, BLOCKSIZE) - ReadOffset;
|
|
|
|
|
|
|
|
Status = CdfsReadSectors(DeviceExt->StorageDevice,
|
|
|
|
Fcb->Entry.ExtentLocationL + (ReadOffset / BLOCKSIZE),
|
|
|
|
Length / BLOCKSIZE,
|
|
|
|
Buffer,
|
|
|
|
FALSE);
|
|
|
|
if (NT_SUCCESS(Status))
|
2008-11-20 20:02:36 +00:00
|
|
|
{
|
2009-02-03 14:50:50 +00:00
|
|
|
*LengthRead = Length;
|
|
|
|
if (Length + ReadOffset > Fcb->Entry.DataLengthL)
|
|
|
|
{
|
|
|
|
memset(Buffer + Fcb->Entry.DataLengthL - ReadOffset,
|
|
|
|
0,
|
|
|
|
Length + ReadOffset - Fcb->Entry.DataLengthL);
|
|
|
|
}
|
|
|
|
}
|
2002-05-01 21:52:05 +00:00
|
|
|
}
|
2002-04-15 20:39:49 +00:00
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
return Status;
|
2002-04-15 20:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-29 20:14:45 +00:00
|
|
|
NTSTATUS NTAPI
|
2002-04-15 20:39:49 +00:00
|
|
|
CdfsRead(PDEVICE_OBJECT DeviceObject,
|
2009-02-03 14:50:50 +00:00
|
|
|
PIRP Irp)
|
2002-04-15 20:39:49 +00:00
|
|
|
{
|
2009-02-03 14:50:50 +00:00
|
|
|
PDEVICE_EXTENSION DeviceExt;
|
|
|
|
PIO_STACK_LOCATION Stack;
|
|
|
|
PFILE_OBJECT FileObject;
|
|
|
|
PVOID Buffer = NULL;
|
|
|
|
ULONG ReadLength;
|
|
|
|
LARGE_INTEGER ReadOffset;
|
|
|
|
ULONG ReturnedReadLength = 0;
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
|
|
|
|
DPRINT("CdfsRead(DeviceObject %x, Irp %x)\n",DeviceObject,Irp);
|
|
|
|
|
|
|
|
DeviceExt = DeviceObject->DeviceExtension;
|
|
|
|
Stack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
FileObject = Stack->FileObject;
|
|
|
|
|
|
|
|
ReadLength = Stack->Parameters.Read.Length;
|
|
|
|
ReadOffset = Stack->Parameters.Read.ByteOffset;
|
|
|
|
if (ReadLength) Buffer = MmGetSystemAddressForMdl(Irp->MdlAddress);
|
|
|
|
|
|
|
|
Status = CdfsReadFile(DeviceExt,
|
|
|
|
FileObject,
|
|
|
|
Buffer,
|
|
|
|
ReadLength,
|
|
|
|
ReadOffset.u.LowPart,
|
|
|
|
Irp->Flags,
|
|
|
|
&ReturnedReadLength);
|
|
|
|
if (NT_SUCCESS(Status))
|
2002-05-01 21:52:05 +00:00
|
|
|
{
|
2009-02-03 14:50:50 +00:00
|
|
|
if (FileObject->Flags & FO_SYNCHRONOUS_IO)
|
|
|
|
{
|
|
|
|
FileObject->CurrentByteOffset.QuadPart =
|
|
|
|
ReadOffset.QuadPart + ReturnedReadLength;
|
|
|
|
}
|
|
|
|
Irp->IoStatus.Information = ReturnedReadLength;
|
2002-05-01 21:52:05 +00:00
|
|
|
}
|
2009-02-03 14:50:50 +00:00
|
|
|
else
|
2002-05-01 21:52:05 +00:00
|
|
|
{
|
2009-02-03 14:50:50 +00:00
|
|
|
Irp->IoStatus.Information = 0;
|
2002-05-01 21:52:05 +00:00
|
|
|
}
|
2002-04-15 20:39:49 +00:00
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp,IO_NO_INCREMENT);
|
2002-05-01 21:52:05 +00:00
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
return(Status);
|
2002-04-15 20:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-29 20:14:45 +00:00
|
|
|
NTSTATUS NTAPI
|
2002-04-15 20:39:49 +00:00
|
|
|
CdfsWrite(PDEVICE_OBJECT DeviceObject,
|
2009-02-03 14:50:50 +00:00
|
|
|
PIRP Irp)
|
2002-04-15 20:39:49 +00:00
|
|
|
{
|
2009-02-03 14:50:50 +00:00
|
|
|
DPRINT("CdfsWrite(DeviceObject %x Irp %x)\n",DeviceObject,Irp);
|
2002-04-15 20:39:49 +00:00
|
|
|
|
2009-02-03 14:50:50 +00:00
|
|
|
Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
return(STATUS_NOT_SUPPORTED);
|
2002-04-15 20:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|