2 * PROJECT: ReactOS FAT file system driver
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/filesystems/fastfat/rw.c
5 * PURPOSE: Read/write support
6 * PROGRAMMERS: Aleksey Bragin (aleksey@reactos.org)
10 /* INCLUDES *****************************************************************/
15 /* FUNCTIONS *****************************************************************/
19 FatiRead(PFAT_IRP_CONTEXT IrpContext
)
22 LARGE_INTEGER ByteOffset
;
23 PFILE_OBJECT FileObject
;
24 TYPE_OF_OPEN OpenType
;
25 PIO_STACK_LOCATION IrpSp
= IrpContext
->Stack
;
32 FileObject
= IrpSp
->FileObject
;
33 NumberOfBytes
= IrpSp
->Parameters
.Read
.Length
;
34 ByteOffset
= IrpSp
->Parameters
.Read
.ByteOffset
;
35 if (NumberOfBytes
== 0)
37 FatCompleteRequest(IrpContext
, IrpContext
->Irp
, STATUS_SUCCESS
);
38 return STATUS_SUCCESS
;
41 OpenType
= FatDecodeFileObject(FileObject
, &Vcb
, &Fcb
, &Ccb
);
43 DPRINT1("FatiRead() Fcb %p, Name %wZ, Offset %d, Length %d, Handle %p\n",
44 Fcb
, &FileObject
->FileName
, ByteOffset
.LowPart
, NumberOfBytes
, Fcb
->FatHandle
);
46 /* Perform actual read */
48 if (IrpContext
->MinorFunction
& IRP_MN_MDL
)
50 DPRINT1("MDL read\n");
54 Buffer
= FatMapUserBuffer(IrpContext
->Irp
);
55 DPRINT1("Normal cached read, buffer %p\n");
58 FF_Seek(Fcb
->FatHandle
, ByteOffset
.LowPart
, FF_SEEK_SET
);
61 BytesRead
= FF_Read(Fcb
->FatHandle
, NumberOfBytes
, 1, Buffer
);
62 DPRINT1("Read %d bytes\n", BytesRead
);
64 /* Indicate we read requested amount of bytes */
65 IrpContext
->Irp
->IoStatus
.Information
= BytesRead
;
66 IrpContext
->Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
69 /* Complete the request */
70 FatCompleteRequest(IrpContext
, IrpContext
->Irp
, STATUS_SUCCESS
);
71 return STATUS_SUCCESS
;
76 FatRead(PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
79 BOOLEAN TopLevel
, CanWait
;
80 PFAT_IRP_CONTEXT IrpContext
;
84 Status
= STATUS_INVALID_DEVICE_REQUEST
;
85 /* Get CanWait flag */
86 if (IoGetCurrentIrpStackLocation(Irp
)->FileObject
!= NULL
)
87 CanWait
= IoIsOperationSynchronous(Irp
);
89 /* Enter FsRtl critical region */
90 FsRtlEnterFileSystem();
92 if (DeviceObject
!= FatGlobalData
.DiskDeviceObject
)
94 /* Set Top Level IRP if not set */
95 if (IoGetTopLevelIrp() == NULL
)
97 IoSetTopLevelIrp(Irp
);
101 /* Build an irp context */
102 IrpContext
= FatBuildIrpContext(Irp
, CanWait
);
104 /* Perform the actual read */
105 Status
= FatiRead(IrpContext
);
107 /* Restore top level Irp */
109 IoSetTopLevelIrp(NULL
);
111 /* Leave FsRtl critical region */
112 FsRtlExitFileSystem();
114 DPRINT1("FatRead()\n");
120 FatWrite(PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
122 DPRINT1("FatWrite()\n");
123 return STATUS_NOT_IMPLEMENTED
;