[fastfat_new]
[reactos.git] / reactos / drivers / filesystems / fastfat_new / rw.c
index a2223fb..10aa8f9 100644 (file)
@@ -18,20 +18,57 @@ NTSTATUS
 NTAPI
 FatiRead(PFAT_IRP_CONTEXT IrpContext)
 {
-    CSHORT FcbType;
     ULONG NumberOfBytes;
-
-    FcbType = *((PCSHORT) IrpContext->FileObject->FsContext);
-    NumberOfBytes = IrpContext->Stack->Parameters.Read.Length;
+    LARGE_INTEGER ByteOffset;
+    PFILE_OBJECT FileObject;
+    TYPE_OF_OPEN OpenType;
+    PIO_STACK_LOCATION IrpSp = IrpContext->Stack;
+    PFCB Fcb;
+    PVCB Vcb;
+    PCCB Ccb;
+    PVOID Buffer;
+    LONG BytesRead;
+
+    FileObject = IrpSp->FileObject;
+    NumberOfBytes = IrpSp->Parameters.Read.Length;
+    ByteOffset = IrpSp->Parameters.Read.ByteOffset;
     if (NumberOfBytes == 0)
     {
         FatCompleteRequest(IrpContext, IrpContext->Irp, STATUS_SUCCESS);
         return STATUS_SUCCESS;
     }
-    //if (FcbType == FAT_NTC_VCB)
+    
+    OpenType = FatDecodeFileObject(FileObject, &Vcb, &Fcb, &Ccb);
 
-    DPRINT1("FatiRead()\n");
-    return STATUS_NOT_IMPLEMENTED;
+    DPRINT1("FatiRead() Fcb %p, Name %wZ, Offset %d, Length %d, Handle %p\n",
+        Fcb, &FileObject->FileName, ByteOffset.LowPart, NumberOfBytes, Fcb->FatHandle);
+
+    /* Perform actual read */
+
+    if (IrpContext->MinorFunction & IRP_MN_MDL)
+    {
+        DPRINT1("MDL read\n");
+    }
+    else
+    {
+        Buffer = FatMapUserBuffer(IrpContext->Irp);
+        DPRINT1("Normal cached read, buffer %p\n");
+
+        /* Set offset */
+        FF_Seek(Fcb->FatHandle, ByteOffset.LowPart, FF_SEEK_SET);
+
+        /* Read */
+        BytesRead = FF_Read(Fcb->FatHandle, NumberOfBytes, 1, Buffer);
+        DPRINT1("Read %d bytes\n", BytesRead);
+
+        /* 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;
 }
 
 NTSTATUS