Sync with trunk (r48545)
[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 TopLevel = FatIsTopLevelIrp(Irp);
95
96 /* Build an irp context */
97 IrpContext = FatBuildIrpContext(Irp, CanWait);
98
99 /* Perform the actual read */
100 Status = FatiRead(IrpContext);
101
102 /* Restore top level Irp */
103 if (TopLevel)
104 IoSetTopLevelIrp(NULL);
105 }
106 /* Leave FsRtl critical region */
107 FsRtlExitFileSystem();
108
109 return Status;
110 }
111
112 NTSTATUS
113 NTAPI
114 FatWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp)
115 {
116 DPRINT1("FatWrite()\n");
117 return STATUS_NOT_IMPLEMENTED;
118 }
119
120