- PVFATFCB Fcb;
- PVFATCCB Ccb;
- NTSTATUS Status = STATUS_SUCCESS;
- ULONG ReadLength;
- ULONG ReturnedReadLength = 0;
- LARGE_INTEGER ReadOffset;
- PVOID Buffer;
-
- DPRINT ("VfatRead(IrpContext %x)\n", IrpContext);
- assert (IrpContext);
- Ccb = (PVFATCCB) IrpContext->FileObject->FsContext2;
- assert (Ccb);
- Fcb = Ccb->pFcb;
- assert (Fcb);
-
- if (IrpContext->Irp->Flags & IRP_PAGING_IO)
- {
- if (!ExAcquireResourceSharedLite(&Fcb->PagingIoResource,
- IrpContext->Flags & IRPCONTEXT_CANWAIT))
+ NTSTATUS Status;
+ PVFATFCB Fcb;
+ PVFATCCB Ccb;
+ ULONG Length;
+ ULONG ReturnedLength = 0;
+ PERESOURCE Resource = NULL;
+ LARGE_INTEGER ByteOffset;
+ PVOID Buffer;
+ PDEVICE_OBJECT DeviceToVerify;
+
+ assert(IrpContext);
+
+ DPRINT("VfatRead(IrpContext %x)\n", IrpContext);
+
+ assert(IrpContext->DeviceObject);
+
+ // This request is not allowed on the main device object
+ if (IrpContext->DeviceObject == VfatGlobalData->DeviceObject)
+ {
+ DPRINT("VfatRead is called with the main device object.\n");
+ Status = STATUS_INVALID_DEVICE_REQUEST;
+ goto ByeBye;
+ }
+
+ assert(IrpContext->DeviceExt);
+ assert(IrpContext->FileObject);
+ Ccb = (PVFATCCB) IrpContext->FileObject->FsContext2;
+ assert(Ccb);
+ Fcb = Ccb->pFcb;
+ assert(Fcb);
+
+ DPRINT("<%S>\n", Fcb->PathName);
+
+ ByteOffset = IrpContext->Stack->Parameters.Read.ByteOffset;
+ Length = IrpContext->Stack->Parameters.Read.Length;
+
+ /* fail if file is a directory and no paged read */
+ if (Fcb->entry.Attrib & FILE_ATTRIBUTE_DIRECTORY && !(IrpContext->Irp->Flags & IRP_PAGING_IO))
+ {
+ Status = STATUS_INVALID_PARAMETER;
+ goto ByeBye;
+ }
+
+
+ DPRINT("'%S', Offset: %d, Length %d\n", Fcb->PathName, ByteOffset.u.LowPart, Length);
+
+ if (ByteOffset.u.HighPart && !(Fcb->Flags & FCB_IS_VOLUME))
+ {
+ Status = STATUS_INVALID_PARAMETER;
+ goto ByeBye;
+ }
+ if (ByteOffset.QuadPart >= Fcb->RFCB.FileSize.QuadPart)
+ {
+ IrpContext->Irp->IoStatus.Information = 0;
+ Status = STATUS_END_OF_FILE;
+ goto ByeBye;
+ }
+ if (IrpContext->Irp->Flags & (IRP_PAGING_IO | IRP_NOCACHE) || (Fcb->Flags & FCB_IS_VOLUME))
+ {
+ if (ByteOffset.u.LowPart % BLOCKSIZE != 0 || Length % BLOCKSIZE != 0)