2 * PROJECT: ReactOS FAT file system driver
3 * LICENSE: GNU GPLv3 as published by the Free Software Foundation
4 * FILE: drivers/filesystems/fastfat/rw.c
5 * PURPOSE: Read/write support
6 * PROGRAMMERS: Aleksey Bragin (aleksey@reactos.org)
9 /* INCLUDES *****************************************************************/
14 /* FUNCTIONS *****************************************************************/
18 FatiRead(PFAT_IRP_CONTEXT IrpContext
)
21 LARGE_INTEGER ByteOffset
;
22 PFILE_OBJECT FileObject
;
23 TYPE_OF_OPEN OpenType
;
24 PIO_STACK_LOCATION IrpSp
= IrpContext
->Stack
;
31 FileObject
= IrpSp
->FileObject
;
32 NumberOfBytes
= IrpSp
->Parameters
.Read
.Length
;
33 ByteOffset
= IrpSp
->Parameters
.Read
.ByteOffset
;
34 if (NumberOfBytes
== 0)
36 FatCompleteRequest(IrpContext
, IrpContext
->Irp
, STATUS_SUCCESS
);
37 return STATUS_SUCCESS
;
40 OpenType
= FatDecodeFileObject(FileObject
, &Vcb
, &Fcb
, &Ccb
);
42 DPRINT("FatiRead() Fcb %p, Name %wZ, Offset %d, Length %d, Handle %p\n",
43 Fcb
, &FileObject
->FileName
, ByteOffset
.LowPart
, NumberOfBytes
, Fcb
->FatHandle
);
45 /* Perform actual read */
47 if (IrpContext
->MinorFunction
& IRP_MN_MDL
)
49 DPRINT1("MDL read\n");
53 Buffer
= FatMapUserBuffer(IrpContext
->Irp
);
54 DPRINT("Normal cached read, buffer %p\n");
57 FF_Seek(Fcb
->FatHandle
, ByteOffset
.LowPart
, FF_SEEK_SET
);
60 BytesRead
= FF_Read(Fcb
->FatHandle
, NumberOfBytes
, 1, Buffer
);
61 DPRINT("Read %d bytes\n", BytesRead
);
63 /* Indicate we read requested amount of bytes */
64 IrpContext
->Irp
->IoStatus
.Information
= BytesRead
;
65 IrpContext
->Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
68 /* Complete the request */
69 FatCompleteRequest(IrpContext
, IrpContext
->Irp
, STATUS_SUCCESS
);
70 return STATUS_SUCCESS
;
75 FatRead(PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
78 BOOLEAN TopLevel
, CanWait
;
79 PFAT_IRP_CONTEXT IrpContext
;
83 Status
= STATUS_INVALID_DEVICE_REQUEST
;
84 /* Get CanWait flag */
85 if (IoGetCurrentIrpStackLocation(Irp
)->FileObject
!= NULL
)
86 CanWait
= IoIsOperationSynchronous(Irp
);
88 /* Enter FsRtl critical region */
89 FsRtlEnterFileSystem();
91 if (DeviceObject
!= FatGlobalData
.DiskDeviceObject
)
93 /* Set Top Level IRP if not set */
94 if (IoGetTopLevelIrp() == NULL
)
96 IoSetTopLevelIrp(Irp
);
100 /* Build an irp context */
101 IrpContext
= FatBuildIrpContext(Irp
, CanWait
);
103 /* Perform the actual read */
104 Status
= FatiRead(IrpContext
);
106 /* Restore top level Irp */
108 IoSetTopLevelIrp(NULL
);
110 /* Leave FsRtl critical region */
111 FsRtlExitFileSystem();
118 FatWrite(PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
120 DPRINT1("FatWrite()\n");
121 return STATUS_NOT_IMPLEMENTED
;