2002-04-15 20:39:49 +00:00
|
|
|
/*
|
2013-03-16 19:49:08 +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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
2015-06-17 20:27:52 +00:00
|
|
|
* FILE: drivers/filesystems/cdfs/rw.c
|
2013-03-16 19:49:08 +00:00
|
|
|
* 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
|
2016-04-09 19:33:42 +00:00
|
|
|
CdfsReadFile(PCDFS_IRP_CONTEXT IrpContext,
|
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;
|
2016-04-09 19:33:42 +00:00
|
|
|
PDEVICE_EXTENSION DeviceExt;
|
2009-02-03 14:50:50 +00:00
|
|
|
PFCB Fcb;
|
2011-10-30 00:58:21 +00:00
|
|
|
ULONG ToRead = Length;
|
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
|
|
|
|
2016-04-09 19:33:42 +00:00
|
|
|
DeviceExt = IrpContext->DeviceObject->DeviceExtension;
|
2009-02-03 14:50:50 +00:00
|
|
|
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);
|
2011-10-30 00:58:21 +00:00
|
|
|
|
|
|
|
if (ReadOffset + Length > Fcb->Entry.DataLengthL)
|
|
|
|
ToRead = Fcb->Entry.DataLengthL - ReadOffset;
|
2002-11-20 21:55:25 +00:00
|
|
|
|
2016-04-09 19:33:42 +00:00
|
|
|
if (!(IrpFlags & IRP_PAGING_IO) &&
|
|
|
|
FsRtlAreThereCurrentFileLocks(&Fcb->FileLock))
|
|
|
|
{
|
|
|
|
if (!FsRtlCheckLockForReadAccess(&Fcb->FileLock, IrpContext->Irp))
|
|
|
|
{
|
|
|
|
return STATUS_FILE_LOCK_CONFLICT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-11 09:24:31 +00:00
|
|
|
DPRINT("Reading %u bytes at %u\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;
|
2011-10-29 20:34:08 +00:00
|
|
|
|
|
|
|
DPRINT("Using cache\n");
|
2009-02-03 14:50:50 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2015-02-27 21:30:09 +00:00
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
CcInitializeCacheMap(FileObject,
|
|
|
|
&FileSizes,
|
|
|
|
FALSE,
|
|
|
|
&(CdfsGlobalData->CacheMgrCallbacks),
|
|
|
|
Fcb);
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
return _SEH2_GetExceptionCode();
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
2009-02-03 14:50:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FileOffset.QuadPart = (LONGLONG)ReadOffset;
|
2015-02-27 21:30:09 +00:00
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
CcCopyRead(FileObject,
|
|
|
|
&FileOffset,
|
|
|
|
ToRead,
|
|
|
|
TRUE,
|
|
|
|
Buffer,
|
|
|
|
&IoStatus);
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
IoStatus.Information = 0;
|
|
|
|
IoStatus.Status = _SEH2_GetExceptionCode();
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
2009-02-03 14:50:50 +00:00
|
|
|
*LengthRead = IoStatus.Information;
|
|
|
|
|
2011-10-30 00:58:21 +00:00
|
|
|
Status = IoStatus.Status;
|
2002-05-01 21:52:05 +00:00
|
|
|
}
|
2011-10-30 00:58:21 +00:00
|
|
|
else
|
2002-05-01 21:52:05 +00:00
|
|
|
{
|
2011-10-30 00:58:21 +00:00
|
|
|
ULONG ActualReadOffset = ROUND_DOWN(ReadOffset, BLOCKSIZE);
|
|
|
|
ULONG nBlocks = (ROUND_UP(ReadOffset + ToRead, BLOCKSIZE) - ActualReadOffset) / BLOCKSIZE;
|
|
|
|
PUCHAR PageBuf;
|
|
|
|
BOOLEAN bFreeBuffer = FALSE;
|
|
|
|
if ((ReadOffset % BLOCKSIZE) != 0 || (ToRead % BLOCKSIZE) != 0)
|
2008-11-20 20:02:36 +00:00
|
|
|
{
|
2015-03-27 18:03:39 +00:00
|
|
|
PageBuf = ExAllocatePoolWithTag(NonPagedPool,
|
|
|
|
nBlocks * BLOCKSIZE,
|
|
|
|
CDFS_TAG);
|
2011-10-30 00:58:21 +00:00
|
|
|
if (!PageBuf)
|
2009-02-03 14:50:50 +00:00
|
|
|
{
|
2011-10-30 00:58:21 +00:00
|
|
|
return STATUS_NO_MEMORY;
|
2009-02-03 14:50:50 +00:00
|
|
|
}
|
2011-10-30 00:58:21 +00:00
|
|
|
bFreeBuffer = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PageBuf = Buffer;
|
2009-02-03 14:50:50 +00:00
|
|
|
}
|
|
|
|
Status = CdfsReadSectors(DeviceExt->StorageDevice,
|
2011-10-30 00:58:21 +00:00
|
|
|
Fcb->Entry.ExtentLocationL + (ActualReadOffset / BLOCKSIZE),
|
|
|
|
nBlocks,
|
|
|
|
(PVOID)PageBuf,
|
2009-02-03 14:50:50 +00:00
|
|
|
FALSE);
|
2011-10-30 00:58:21 +00:00
|
|
|
|
|
|
|
if(NT_SUCCESS(Status))
|
2008-11-20 20:02:36 +00:00
|
|
|
{
|
2011-10-30 00:58:21 +00:00
|
|
|
*LengthRead = ToRead;
|
|
|
|
if(bFreeBuffer)
|
2009-02-03 14:50:50 +00:00
|
|
|
{
|
2011-10-30 00:58:21 +00:00
|
|
|
/* Copy what we've got */
|
|
|
|
RtlCopyMemory(Buffer, PageBuf + (ReadOffset - ActualReadOffset), ToRead);
|
2009-02-03 14:50:50 +00:00
|
|
|
}
|
2011-10-30 00:58:21 +00:00
|
|
|
/* Zero out the rest */
|
|
|
|
if(ToRead != Length)
|
|
|
|
RtlZeroMemory(Buffer + ToRead, Length - ToRead);
|
2009-02-03 14:50:50 +00:00
|
|
|
}
|
2011-10-30 00:58:21 +00:00
|
|
|
|
|
|
|
if(bFreeBuffer)
|
2015-03-27 18:03:39 +00:00
|
|
|
ExFreePoolWithTag(PageBuf, CDFS_TAG);
|
2002-05-01 21:52:05 +00:00
|
|
|
}
|
2011-10-30 00:58:21 +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
|
2015-06-01 17:15:11 +00:00
|
|
|
CdfsRead(
|
|
|
|
PCDFS_IRP_CONTEXT IrpContext)
|
2002-04-15 20:39:49 +00:00
|
|
|
{
|
2015-06-01 17:15:11 +00:00
|
|
|
PIRP Irp;
|
2009-02-03 14:50:50 +00:00
|
|
|
PIO_STACK_LOCATION Stack;
|
|
|
|
PFILE_OBJECT FileObject;
|
|
|
|
PVOID Buffer = NULL;
|
|
|
|
ULONG ReadLength;
|
|
|
|
LARGE_INTEGER ReadOffset;
|
|
|
|
ULONG ReturnedReadLength = 0;
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
|
2015-06-01 17:15:11 +00:00
|
|
|
DPRINT("CdfsRead(%p)\n", IrpContext);
|
|
|
|
|
|
|
|
ASSERT(IrpContext);
|
|
|
|
|
|
|
|
Irp = IrpContext->Irp;
|
|
|
|
Stack = IrpContext->Stack;
|
2009-02-03 14:50:50 +00:00
|
|
|
|
|
|
|
FileObject = Stack->FileObject;
|
|
|
|
|
|
|
|
ReadLength = Stack->Parameters.Read.Length;
|
|
|
|
ReadOffset = Stack->Parameters.Read.ByteOffset;
|
|
|
|
if (ReadLength) Buffer = MmGetSystemAddressForMdl(Irp->MdlAddress);
|
|
|
|
|
2016-04-09 19:33:42 +00:00
|
|
|
Status = CdfsReadFile(IrpContext,
|
2009-02-03 14:50:50 +00:00
|
|
|
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
|
|
|
return(Status);
|
2002-04-15 20:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-29 20:14:45 +00:00
|
|
|
NTSTATUS NTAPI
|
2015-06-01 17:15:11 +00:00
|
|
|
CdfsWrite(
|
|
|
|
PCDFS_IRP_CONTEXT IrpContext)
|
2002-04-15 20:39:49 +00:00
|
|
|
{
|
2015-06-01 17:15:11 +00:00
|
|
|
DPRINT("CdfsWrite(%p)\n", IrpContext);
|
|
|
|
|
|
|
|
ASSERT(IrpContext);
|
2002-04-15 20:39:49 +00:00
|
|
|
|
2015-06-21 14:02:35 +00:00
|
|
|
IrpContext->Irp->IoStatus.Information = 0;
|
2009-02-03 14:50:50 +00:00
|
|
|
return(STATUS_NOT_SUPPORTED);
|
2002-04-15 20:39:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|