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