3d54129eda8eac5d4cd7af784e9858c16f3d04f4
[reactos.git] / reactos / drivers / filesystems / fastfat_new / rw.c
1 /*
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)
7 * Alexey Vlasov
8 */
9
10 /* INCLUDES *****************************************************************/
11
12 #define NDEBUG
13 #include "fastfat.h"
14
15 /* FUNCTIONS *****************************************************************/
16
17 NTSTATUS
18 NTAPI
19 FatiRead(PFAT_IRP_CONTEXT IrpContext)
20 {
21 ULONG NumberOfBytes;
22 LARGE_INTEGER ByteOffset;
23 PFILE_OBJECT FileObject;
24 TYPE_OF_OPEN OpenType;
25 PIO_STACK_LOCATION IrpSp = IrpContext->Stack;
26 PFCB Fcb;
27 PVCB Vcb;
28 PCCB Ccb;
29 PVOID Buffer;
30 LONG BytesRead;
31
32 FileObject = IrpSp->FileObject;
33 NumberOfBytes = IrpSp->Parameters.Read.Length;
34 ByteOffset = IrpSp->Parameters.Read.ByteOffset;
35 if (NumberOfBytes == 0)
36 {
37 FatCompleteRequest(IrpContext, IrpContext->Irp, STATUS_SUCCESS);
38 return STATUS_SUCCESS;
39 }
40
41 OpenType = FatDecodeFileObject(FileObject, &Vcb, &Fcb, &Ccb);
42
43 DPRINT1("FatiRead() Fcb %p, Name %wZ, Offset %d, Length %d, Handle %p\n",
44 Fcb, &FileObject->FileName, ByteOffset.LowPart, NumberOfBytes, Fcb->FatHandle);
45
46 /* Perform actual read */
47
48 if (IrpContext->MinorFunction & IRP_MN_MDL)
49 {
50 DPRINT1("MDL read\n");
51 }
52 else
53 {
54 Buffer = FatMapUserBuffer(IrpContext->Irp);
55 DPRINT1("Normal cached read, buffer %p\n");
56
57 BytesRead = FF_Read(Fcb->FatHandle, NumberOfBytes, 1, Buffer);
58 DPRINT1("Read %d bytes\n", BytesRead);
59
60 /* Indicate we read requested amount of bytes */
61 IrpContext->Irp->IoStatus.Information = BytesRead;
62 IrpContext->Irp->IoStatus.Status = STATUS_SUCCESS;
63 }
64
65 /* Complete the request */
66 FatCompleteRequest(IrpContext, IrpContext->Irp, STATUS_SUCCESS);
67 return STATUS_SUCCESS;
68 }
69
70 NTSTATUS
71 NTAPI
72 FatRead(PDEVICE_OBJECT DeviceObject, PIRP Irp)
73 {
74 NTSTATUS Status;
75 BOOLEAN TopLevel, CanWait;
76 PFAT_IRP_CONTEXT IrpContext;
77
78 CanWait = TRUE;
79 TopLevel = FALSE;
80 Status = STATUS_INVALID_DEVICE_REQUEST;
81 /* Get CanWait flag */
82 if (IoGetCurrentIrpStackLocation(Irp)->FileObject != NULL)
83 CanWait = IoIsOperationSynchronous(Irp);
84
85 /* Enter FsRtl critical region */
86 FsRtlEnterFileSystem();
87
88 if (DeviceObject != FatGlobalData.DiskDeviceObject)
89 {
90 /* Set Top Level IRP if not set */
91 if (IoGetTopLevelIrp() == NULL)
92 {
93 IoSetTopLevelIrp(Irp);
94 TopLevel = TRUE;
95 }
96
97 /* Build an irp context */
98 IrpContext = FatBuildIrpContext(Irp, CanWait);
99
100 /* Perform the actual read */
101 Status = FatiRead(IrpContext);
102
103 /* Restore top level Irp */
104 if (TopLevel)
105 IoSetTopLevelIrp(NULL);
106 }
107 /* Leave FsRtl critical region */
108 FsRtlExitFileSystem();
109
110 DPRINT1("FatRead()\n");
111 return Status;
112 }
113
114 NTSTATUS
115 NTAPI
116 FatWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp)
117 {
118 DPRINT1("FatWrite()\n");
119 return STATUS_NOT_IMPLEMENTED;
120 }
121
122