ReactOS  0.4.15-dev-1018-g0695ecb
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 
24 BOOLEAN
25 NTAPI
27  IN PVOID Buffer,
30  IN PIRP Irp,
32 {
34  PNP_DATA_QUEUE ReadQueue;
35  PNP_EVENT_BUFFER EventBuffer;
37  ULONG NamedPipeEnd;
38  PNP_CCB Ccb;
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 
52  if (NodeType != NPFS_NTC_CCB)
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,
95  BufferSize,
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  {
112  IoStatus->Status = STATUS_PIPE_BROKEN;
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,
135  ReadEntries,
136  Buffered,
137  BufferSize,
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 
152 Quickie:
153  ExReleaseResourceLite(&Ccb->NonPagedCcb->Lock);
154  return ReadOk;
155 }
156 
157 NTSTATUS
158 NTAPI
160  IN PIRP Irp)
161 {
162  PIO_STACK_LOCATION IoStack;
164  LIST_ENTRY DeferredList;
165  PAGED_CODE();
166  NpSlowReadCalls++;
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)
198 BOOLEAN
199 NTAPI
200 NpFastRead(
203  _In_ ULONG Length,
204  _In_ BOOLEAN Wait,
209 {
210  LIST_ENTRY DeferredList;
211  BOOLEAN Result;
212  PAGED_CODE();
213 
214  InitializeListHead(&DeferredList);
215 
218 
220  Buffer,
221  Length,
222  IoStatus,
223  NULL,
224  &DeferredList);
225  if (Result)
226  ++NpFastReadTrue;
227  else
228  ++NpFastReadFalse;
229 
230  NpReleaseVcb();
231  NpCompleteDeferredIrps(&DeferredList);
233 
234  return Result;
235 }
236 
237 /* EOF */
#define _IRQL_requires_same_
Definition: no_sal2.h:652
#define IN
Definition: typedefs.h:39
FORCEINLINE VOID NpAcquireSharedVcb(VOID)
Definition: npfs.h:328
#define FsRtlEnterFileSystem
#define STATUS_PIPE_DISCONNECTED
Definition: ntstatus.h:412
PNP_EVENT_BUFFER EventBuffer[2]
Definition: npfs.h:253
#define FsRtlExitFileSystem
#define FILE_PIPE_CLOSING_STATE
Definition: winternl.h:793
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2659
_In_ PIRP Irp
Definition: csq.h:116
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_PIPE_EMPTY
Definition: ntstatus.h:453
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_PIPE_CLIENT_END
Definition: iotypes.h:84
#define NPFS_NTC_CCB
Definition: npfs.h:115
Definition: npfs.h:131
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define FILE_PIPE_CONNECTED_STATE
Definition: winternl.h:792
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
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
Definition: npfs.h:258
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
long LONG
Definition: pedump.c:60
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_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:426
#define _Out_
Definition: no_sal2.h:323
#define IoCompleteRequest
Definition: irp.c:1240
Definition: bufpool.h:45
NodeType
Definition: Node.h:5
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:588
LONG NpSlowReadCalls
Definition: read.c:18
ULONG QueueState
Definition: npfs.h:139
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG LockKey
Definition: fatprocs.h:2659
LIST_ENTRY List
Definition: psmgr.c:57
ULONG NpFastReadTrue
Definition: read.c:19
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
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
#define STATUS_PIPE_LISTENING
Definition: ntstatus.h:415
#define BufferSize
Definition: classpnp.h:436
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1962
#define FILE_PIPE_SERVER_END
Definition: iotypes.h:85
#define IO_NAMED_PIPE_INCREMENT
Definition: iotypes.h:576
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define STATUS_PIPE_BROKEN
Definition: ntstatus.h:567
NTSTATUS NTAPI NpFsdRead(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: read.c:159
Status
Definition: gdiplustypes.h:24
#define FILE_PIPE_COMPLETE_OPERATION
Definition: iotypes.h:80
struct _FCB::@715::@718 Fcb
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:588
Definition: typedefs.h:119
ULONG NpFastReadFalse
Definition: read.c:20
_Function_class_(IO_COMPLETION_ROUTINE)
Definition: read.c:67
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1569
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2789
PFILE_OBJECT FileObject
Definition: iotypes.h:2820
PKEVENT Event
Definition: npfs.h:179
FORCEINLINE VOID NpReleaseVcb(VOID)
Definition: npfs.h:344
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:159
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define FILE_PIPE_OUTBOUND
Definition: iotypes.h:82
#define FILE_PIPE_DISCONNECTED_STATE
Definition: winternl.h:790
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 OUT
Definition: typedefs.h:40
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:570
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
#define FILE_PIPE_INBOUND
Definition: iotypes.h:81
ERESOURCE Lock
Definition: npfs.h:254
USHORT NODE_TYPE_CODE
Definition: nodetype.h:22
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2779
FORCEINLINE VOID NpCompleteDeferredIrps(IN PLIST_ENTRY DeferredList)
Definition: npfs.h:356
#define FILE_PIPE_LISTENING_STATE
Definition: winternl.h:791
#define PAGED_CODE()
IN BOOLEAN Wait
Definition: fatprocs.h:1538