ReactOS 0.4.16-dev-252-g9ccafe8
read.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Named Pipe FileSystem
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: drivers/filesystems/npfs/read.c
5 * PURPOSE: Pipes Reading
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9/* INCLUDES *******************************************************************/
10
11#include "npfs.h"
12
13// File ID number for NPFS bugchecking support
14#define NPFS_BUGCHECK_FILE_ID (NPFS_BUGCHECK_READ)
15
16/* GLOBALS ********************************************************************/
17
21
22/* FUNCTIONS ******************************************************************/
23
30 IN PIRP Irp,
32{
34 PNP_DATA_QUEUE ReadQueue;
35 PNP_EVENT_BUFFER EventBuffer;
37 ULONG NamedPipeEnd;
39 PNP_NONPAGED_CCB NonPagedCcb;
40 BOOLEAN ReadOk;
41 PAGED_CODE();
42
43 IoStatus->Information = 0;
44 NodeType = NpDecodeFileObject(FileObject, NULL, &Ccb, &NamedPipeEnd);
45
46 if (!NodeType)
47 {
49 return TRUE;
50 }
51
53 {
55 return TRUE;
56 }
57
58 NonPagedCcb = Ccb->NonPagedCcb;
60
61 if (Ccb->NamedPipeState == FILE_PIPE_DISCONNECTED_STATE || Ccb->NamedPipeState == FILE_PIPE_LISTENING_STATE)
62 {
64 ReadOk = TRUE;
65 goto Quickie;
66 }
67
68 ASSERT((Ccb->NamedPipeState == FILE_PIPE_CONNECTED_STATE) || (Ccb->NamedPipeState == FILE_PIPE_CLOSING_STATE));
69
70 if ((NamedPipeEnd == FILE_PIPE_SERVER_END && Ccb->Fcb->NamedPipeConfiguration == FILE_PIPE_OUTBOUND) ||
71 (NamedPipeEnd == FILE_PIPE_CLIENT_END && Ccb->Fcb->NamedPipeConfiguration == FILE_PIPE_INBOUND))
72 {
74 ReadOk = TRUE;
75 goto Quickie;
76 }
77
78 if (NamedPipeEnd == FILE_PIPE_SERVER_END)
79 {
80 ReadQueue = &Ccb->DataQueue[FILE_PIPE_INBOUND];
81 }
82 else
83 {
84 ReadQueue = &Ccb->DataQueue[FILE_PIPE_OUTBOUND];
85 }
86
87 EventBuffer = NonPagedCcb->EventBuffer[NamedPipeEnd];
88
89 if (ReadQueue->QueueState == WriteEntries)
90 {
91 *IoStatus = NpReadDataQueue(ReadQueue,
92 FALSE,
93 FALSE,
94 Buffer,
96 Ccb->ReadMode[NamedPipeEnd],
97 Ccb,
98 List);
99 if (!NT_SUCCESS(IoStatus->Status))
100 {
101 ReadOk = TRUE;
102 goto Quickie;
103 }
104
105 ReadOk = TRUE;
106 if (EventBuffer) KeSetEvent(EventBuffer->Event, IO_NO_INCREMENT, FALSE);
107 goto Quickie;
108 }
109
110 if (Ccb->NamedPipeState == FILE_PIPE_CLOSING_STATE)
111 {
113 ReadOk = TRUE;
114 if (EventBuffer) KeSetEvent(EventBuffer->Event, IO_NO_INCREMENT, FALSE);
115 goto Quickie;
116 }
117
118 if (Ccb->CompletionMode[NamedPipeEnd] == FILE_PIPE_COMPLETE_OPERATION)
119 {
120 IoStatus->Status = STATUS_PIPE_EMPTY;
121 ReadOk = TRUE;
122 if (EventBuffer) KeSetEvent(EventBuffer->Event, IO_NO_INCREMENT, FALSE);
123 goto Quickie;
124 }
125
126 if (!Irp)
127 {
128 ReadOk = FALSE;
129 goto Quickie;
130 }
131
132 Status = NpAddDataQueueEntry(NamedPipeEnd,
133 Ccb,
134 ReadQueue,
136 Buffered,
138 Irp,
139 NULL,
140 0);
141 IoStatus->Status = Status;
142 if (!NT_SUCCESS(Status))
143 {
144 ReadOk = FALSE;
145 }
146 else
147 {
148 ReadOk = TRUE;
149 if (EventBuffer) KeSetEvent(EventBuffer->Event, IO_NO_INCREMENT, FALSE);
150 }
151
152Quickie:
153 ExReleaseResourceLite(&Ccb->NonPagedCcb->Lock);
154 return ReadOk;
155}
156
158NTAPI
160 IN PIRP Irp)
161{
162 PIO_STACK_LOCATION IoStack;
164 LIST_ENTRY DeferredList;
165 PAGED_CODE();
167
168 InitializeListHead(&DeferredList);
170
173
174 NpCommonRead(IoStack->FileObject,
175 Irp->UserBuffer,
176 IoStack->Parameters.Read.Length,
177 &IoStatus,
178 Irp,
179 &DeferredList);
180
181 NpReleaseVcb();
182 NpCompleteDeferredIrps(&DeferredList);
184
185 if (IoStatus.Status != STATUS_PENDING)
186 {
187 Irp->IoStatus.Information = IoStatus.Information;
188 Irp->IoStatus.Status = IoStatus.Status;
190 }
191
192 return IoStatus.Status;
193}
194
195
196_Function_class_(FAST_IO_READ)
199NTAPI
200NpFastRead(
209{
210 LIST_ENTRY DeferredList;
212 PAGED_CODE();
213
214 InitializeListHead(&DeferredList);
215
218
220 Buffer,
221 Length,
222 IoStatus,
223 NULL,
224 &DeferredList);
225 if (Result)
227 else
229
230 NpReleaseVcb();
231 NpCompleteDeferredIrps(&DeferredList);
233
234 return Result;
235}
236
237/* EOF */
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define PAGED_CODE()
NodeType
Definition: Node.h:6
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:160
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:592
Definition: bufpool.h:45
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_PENDING
Definition: d3dkmdt.h:43
NTSTATUS NTAPI NpAddDataQueueEntry(IN ULONG NamedPipeEnd, IN PNP_CCB Ccb, IN PNP_DATA_QUEUE DataQueue, IN ULONG Who, IN ULONG Type, IN ULONG DataSize, IN PIRP Irp, IN PVOID Buffer, IN ULONG ByteOffset)
Definition: datasup.c:295
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
USHORT NODE_TYPE_CODE
Definition: nodetype.h:22
#define NodeType(P)
Definition: nodetype.h:51
FORCEINLINE VOID NpReleaseVcb(VOID)
Definition: npfs.h:344
IO_STATUS_BLOCK NTAPI NpReadDataQueue(IN PNP_DATA_QUEUE DataQueue, IN BOOLEAN Peek, IN BOOLEAN ReadOverflowOperation, IN PVOID Buffer, IN ULONG BufferSize, IN ULONG Mode, IN PNP_CCB Ccb, IN PLIST_ENTRY List)
Definition: readsup.c:20
@ Buffered
Definition: npfs.h:131
FORCEINLINE VOID NpAcquireSharedVcb(VOID)
Definition: npfs.h:328
@ ReadEntries
Definition: npfs.h:123
@ WriteEntries
Definition: npfs.h:124
FORCEINLINE VOID NpCompleteDeferredIrps(IN PLIST_ENTRY DeferredList)
Definition: npfs.h:356
#define NPFS_NTC_CCB
Definition: npfs.h:115
#define _IRQL_requires_same_
Definition: driverspecs.h:232
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define ExAcquireResourceExclusiveLite(res, wait)
Definition: env_spec_w32.h:615
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG LockKey
Definition: fatprocs.h:2666
NODE_TYPE_CODE NTAPI NpDecodeFileObject(IN PFILE_OBJECT FileObject, OUT PVOID *PrimaryContext OPTIONAL, OUT PNP_CCB *Ccb, OUT PULONG NamedPipeEnd OPTIONAL)
Definition: fileobsup.c:20
ULONG NpFastReadFalse
Definition: read.c:20
LONG NpSlowReadCalls
Definition: read.c:18
BOOLEAN NTAPI NpCommonRead(IN PFILE_OBJECT FileObject, IN PVOID Buffer, IN ULONG BufferSize, OUT PIO_STATUS_BLOCK IoStatus, IN PIRP Irp, IN PLIST_ENTRY List)
Definition: read.c:26
NTSTATUS NTAPI NpFsdRead(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: read.c:159
ULONG NpFastReadTrue
Definition: read.c:19
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
Status
Definition: gdiplustypes.h:25
#define FILE_PIPE_DISCONNECTED_STATE
Definition: winternl.h:790
#define FILE_PIPE_LISTENING_STATE
Definition: winternl.h:791
#define FILE_PIPE_CONNECTED_STATE
Definition: winternl.h:792
#define FILE_PIPE_CLOSING_STATE
Definition: winternl.h:793
#define ASSERT(a)
Definition: mode.c:44
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
#define FILE_PIPE_OUTBOUND
Definition: iotypes.h:82
#define FILE_PIPE_INBOUND
Definition: iotypes.h:81
#define FILE_PIPE_CLIENT_END
Definition: iotypes.h:84
#define FILE_PIPE_COMPLETE_OPERATION
Definition: iotypes.h:80
#define FILE_PIPE_SERVER_END
Definition: iotypes.h:85
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define _Function_class_(n)
Definition: no_sal2.h:398
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1822
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_PIPE_DISCONNECTED
Definition: ntstatus.h:412
#define STATUS_PIPE_LISTENING
Definition: ntstatus.h:415
#define STATUS_PIPE_EMPTY
Definition: ntstatus.h:453
#define STATUS_PIPE_BROKEN
Definition: ntstatus.h:567
long LONG
Definition: pedump.c:60
struct _FCB::@729::@732 Fcb
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
union _IO_STACK_LOCATION::@1579 Parameters
struct _IO_STACK_LOCATION::@3978::@3982 Read
Definition: typedefs.h:120
Definition: npfs.h:259
ULONG QueueState
Definition: npfs.h:139
PKEVENT Event
Definition: npfs.h:179
ERESOURCE Lock
Definition: npfs.h:254
PNP_EVENT_BUFFER EventBuffer[2]
Definition: npfs.h:253
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
_In_ WDFDPC _In_ BOOLEAN Wait
Definition: wdfdpc.h:170
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IO_NAMED_PIPE_INCREMENT
Definition: iotypes.h:604
* PFILE_OBJECT
Definition: iotypes.h:1998