[fastfat_new]
[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 /* Set offset */
58 FF_Seek(Fcb->FatHandle, ByteOffset.LowPart, FF_SEEK_SET);
59
60 /* Read */
61 BytesRead = FF_Read(Fcb->FatHandle, NumberOfBytes, 1, Buffer);
62 DPRINT1("Read %d bytes\n", BytesRead);
63
64 /* Indicate we read requested amount of bytes */
65 IrpContext->Irp->IoStatus.Information = BytesRead;
66 IrpContext->Irp->IoStatus.Status = STATUS_SUCCESS;
67 }
68
69 /* Complete the request */
70 FatCompleteRequest(IrpContext, IrpContext->Irp, STATUS_SUCCESS);
71 return STATUS_SUCCESS;
72 }
73
74 NTSTATUS
75 NTAPI
76 FatRead(PDEVICE_OBJECT DeviceObject, PIRP Irp)
77 {
78 NTSTATUS Status;
79 BOOLEAN TopLevel, CanWait;
80 PFAT_IRP_CONTEXT IrpContext;
81
82 CanWait = TRUE;
83 TopLevel = FALSE;
84 Status = STATUS_INVALID_DEVICE_REQUEST;
85 /* Get CanWait flag */
86 if (IoGetCurrentIrpStackLocation(Irp)->FileObject != NULL)
87 CanWait = IoIsOperationSynchronous(Irp);
88
89 /* Enter FsRtl critical region */
90 FsRtlEnterFileSystem();
91
92 if (DeviceObject != FatGlobalData.DiskDeviceObject)
93 {
94 /* Set Top Level IRP if not set */
95 if (IoGetTopLevelIrp() == NULL)
96 {
97 IoSetTopLevelIrp(Irp);
98 TopLevel = TRUE;
99 }
100
101 /* Build an irp context */
102 IrpContext = FatBuildIrpContext(Irp, CanWait);
103
104 /* Perform the actual read */
105 Status = FatiRead(IrpContext);
106
107 /* Restore top level Irp */
108 if (TopLevel)
109 IoSetTopLevelIrp(NULL);
110 }
111 /* Leave FsRtl critical region */
112 FsRtlExitFileSystem();
113
114 DPRINT1("FatRead()\n");
115 return Status;
116 }
117
118 NTSTATUS
119 NTAPI
120 FatWrite(PDEVICE_OBJECT DeviceObject, PIRP Irp)
121 {
122 DPRINT1("FatWrite()\n");
123 return STATUS_NOT_IMPLEMENTED;
124 }
125
126