2009-01-11 11:12:55 +00:00
|
|
|
/*
|
2009-01-11 14:10:54 +00:00
|
|
|
* PROJECT: ReactOS FAT file system driver
|
2009-10-20 10:12:49 +00:00
|
|
|
* LICENSE: GNU GPLv3 as published by the Free Software Foundation
|
2009-01-11 14:10:54 +00:00
|
|
|
* FILE: drivers/filesystems/fastfat/rw.c
|
|
|
|
* PURPOSE: Read/write support
|
|
|
|
* PROGRAMMERS: Aleksey Bragin (aleksey@reactos.org)
|
2009-01-11 11:12:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *****************************************************************/
|
|
|
|
|
|
|
|
#define NDEBUG
|
2009-01-11 11:26:20 +00:00
|
|
|
#include "fastfat.h"
|
2009-01-11 11:12:55 +00:00
|
|
|
|
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
|
2009-01-23 09:41:30 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
FatiRead(PFAT_IRP_CONTEXT IrpContext)
|
|
|
|
{
|
|
|
|
ULONG NumberOfBytes;
|
2009-09-30 16:16:18 +00:00
|
|
|
LARGE_INTEGER ByteOffset;
|
|
|
|
PFILE_OBJECT FileObject;
|
|
|
|
TYPE_OF_OPEN OpenType;
|
|
|
|
PIO_STACK_LOCATION IrpSp = IrpContext->Stack;
|
|
|
|
PFCB Fcb;
|
|
|
|
PVCB Vcb;
|
|
|
|
PCCB Ccb;
|
2009-10-01 16:08:11 +00:00
|
|
|
PVOID Buffer;
|
|
|
|
LONG BytesRead;
|
2009-09-30 16:16:18 +00:00
|
|
|
|
|
|
|
FileObject = IrpSp->FileObject;
|
|
|
|
NumberOfBytes = IrpSp->Parameters.Read.Length;
|
|
|
|
ByteOffset = IrpSp->Parameters.Read.ByteOffset;
|
2009-01-23 09:41:30 +00:00
|
|
|
if (NumberOfBytes == 0)
|
|
|
|
{
|
|
|
|
FatCompleteRequest(IrpContext, IrpContext->Irp, STATUS_SUCCESS);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2009-09-30 16:16:18 +00:00
|
|
|
|
|
|
|
OpenType = FatDecodeFileObject(FileObject, &Vcb, &Fcb, &Ccb);
|
2009-01-23 09:41:30 +00:00
|
|
|
|
2009-10-10 09:13:39 +00:00
|
|
|
DPRINT("FatiRead() Fcb %p, Name %wZ, Offset %d, Length %d, Handle %p\n",
|
2009-10-01 13:21:28 +00:00
|
|
|
Fcb, &FileObject->FileName, ByteOffset.LowPart, NumberOfBytes, Fcb->FatHandle);
|
2009-10-01 16:08:11 +00:00
|
|
|
|
|
|
|
/* Perform actual read */
|
|
|
|
|
|
|
|
if (IrpContext->MinorFunction & IRP_MN_MDL)
|
|
|
|
{
|
|
|
|
DPRINT1("MDL read\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Buffer = FatMapUserBuffer(IrpContext->Irp);
|
2009-10-10 09:13:39 +00:00
|
|
|
DPRINT("Normal cached read, buffer %p\n");
|
2009-10-01 16:08:11 +00:00
|
|
|
|
2009-10-02 10:49:57 +00:00
|
|
|
/* Set offset */
|
|
|
|
FF_Seek(Fcb->FatHandle, ByteOffset.LowPart, FF_SEEK_SET);
|
|
|
|
|
|
|
|
/* Read */
|
2009-10-01 16:08:11 +00:00
|
|
|
BytesRead = FF_Read(Fcb->FatHandle, NumberOfBytes, 1, Buffer);
|
2009-10-10 09:13:39 +00:00
|
|
|
DPRINT("Read %d bytes\n", BytesRead);
|
2009-10-01 16:08:11 +00:00
|
|
|
|
|
|
|
/* Indicate we read requested amount of bytes */
|
|
|
|
IrpContext->Irp->IoStatus.Information = BytesRead;
|
|
|
|
IrpContext->Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Complete the request */
|
|
|
|
FatCompleteRequest(IrpContext, IrpContext->Irp, STATUS_SUCCESS);
|
|
|
|
return STATUS_SUCCESS;
|
2009-01-23 09:41:30 +00:00
|
|
|
}
|
|
|
|
|
2009-01-11 11:12:55 +00:00
|
|
|
NTSTATUS
|
2009-01-12 17:04:13 +00:00
|
|
|
NTAPI
|
|
|
|
FatRead(PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
2009-01-11 11:12:55 +00:00
|
|
|
{
|
2009-01-23 09:41:30 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
BOOLEAN TopLevel, CanWait;
|
|
|
|
PFAT_IRP_CONTEXT IrpContext;
|
|
|
|
|
|
|
|
CanWait = TRUE;
|
|
|
|
TopLevel = FALSE;
|
|
|
|
Status = STATUS_INVALID_DEVICE_REQUEST;
|
|
|
|
/* Get CanWait flag */
|
|
|
|
if (IoGetCurrentIrpStackLocation(Irp)->FileObject != NULL)
|
|
|
|
CanWait = IoIsOperationSynchronous(Irp);
|
|
|
|
|
|
|
|
/* Enter FsRtl critical region */
|
|
|
|
FsRtlEnterFileSystem();
|
|
|
|
|
|
|
|
if (DeviceObject != FatGlobalData.DiskDeviceObject)
|
|
|
|
{
|
|
|
|
/* Set Top Level IRP if not set */
|
2010-08-09 21:33:17 +00:00
|
|
|
TopLevel = FatIsTopLevelIrp(Irp);
|
2009-01-23 09:41:30 +00:00
|
|
|
|
|
|
|
/* Build an irp context */
|
|
|
|
IrpContext = FatBuildIrpContext(Irp, CanWait);
|
|
|
|
|
|
|
|
/* Perform the actual read */
|
|
|
|
Status = FatiRead(IrpContext);
|
|
|
|
|
|
|
|
/* Restore top level Irp */
|
|
|
|
if (TopLevel)
|
|
|
|
IoSetTopLevelIrp(NULL);
|
|
|
|
}
|
|
|
|
/* Leave FsRtl critical region */
|
|
|
|
FsRtlExitFileSystem();
|
|
|
|
|
|
|
|
return Status;
|
2009-01-11 11:12:55 +00:00
|
|
|
}
|
|
|
|
|
2009-01-11 14:10:54 +00:00
|
|
|
NTSTATUS
|
2009-01-12 17:04:13 +00:00
|
|
|
NTAPI
|
|
|
|
FatWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
2009-01-11 11:12:55 +00:00
|
|
|
{
|
2009-01-14 10:42:56 +00:00
|
|
|
DPRINT1("FatWrite()\n");
|
2009-01-11 14:10:54 +00:00
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
2009-01-11 11:12:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|