ReactOS  0.4.15-dev-3165-gdf6fff7
read.c File Reference
#include "npfs.h"
Include dependency graph for read.c:

Go to the source code of this file.

Macros

#define NPFS_BUGCHECK_FILE_ID   (NPFS_BUGCHECK_READ)
 

Functions

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)
 
NTSTATUS NTAPI NpFsdRead (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
 _Function_class_ (FAST_IO_READ)
 

Variables

LONG NpSlowReadCalls
 
ULONG NpFastReadTrue
 
ULONG NpFastReadFalse
 

Macro Definition Documentation

◆ NPFS_BUGCHECK_FILE_ID

#define NPFS_BUGCHECK_FILE_ID   (NPFS_BUGCHECK_READ)

Definition at line 14 of file read.c.

Function Documentation

◆ _Function_class_()

_Function_class_ ( FAST_IO_READ  )

Definition at line 196 of file read.c.

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 }
FORCEINLINE VOID NpAcquireSharedVcb(VOID)
Definition: npfs.h:328
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
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
unsigned char BOOLEAN
_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
Definition: bufpool.h:45
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
ULONG NpFastReadTrue
Definition: read.c:19
Definition: typedefs.h:119
ULONG NpFastReadFalse
Definition: read.c:20
FORCEINLINE VOID NpReleaseVcb(VOID)
Definition: npfs.h:344
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define NULL
Definition: types.h:112
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:155
FORCEINLINE VOID NpCompleteDeferredIrps(IN PLIST_ENTRY DeferredList)
Definition: npfs.h:356
#define PAGED_CODE()

◆ NpCommonRead()

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 at line 26 of file read.c.

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 }
#define STATUS_PIPE_DISCONNECTED
Definition: ntstatus.h:412
PNP_EVENT_BUFFER EventBuffer[2]
Definition: npfs.h:253
#define FILE_PIPE_CLOSING_STATE
Definition: winternl.h:793
#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 ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
struct _FCB::@703::@706 Fcb
Definition: npfs.h:258
#define FALSE
Definition: types.h:117
_In_ PIRP Irp
Definition: csq.h:116
unsigned char BOOLEAN
Definition: bufpool.h:45
NodeType
Definition: Node.h:5
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
ULONG QueueState
Definition: npfs.h:139
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
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
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
#define FILE_PIPE_SERVER_END
Definition: iotypes.h:85
#define STATUS_PIPE_BROKEN
Definition: ntstatus.h:567
#define FILE_PIPE_COMPLETE_OPERATION
Definition: iotypes.h:80
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:588
PKEVENT Event
Definition: npfs.h:179
#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 NULL
Definition: types.h:112
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:155
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:598
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
#define FILE_PIPE_LISTENING_STATE
Definition: winternl.h:791
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:251
#define PAGED_CODE()

Referenced by _Function_class_(), and NpFsdRead().

◆ NpFsdRead()

NTSTATUS NTAPI NpFsdRead ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 159 of file read.c.

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 }
FORCEINLINE VOID NpAcquireSharedVcb(VOID)
Definition: npfs.h:328
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
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
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
LONG NpSlowReadCalls
Definition: read.c:18
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IO_NAMED_PIPE_INCREMENT
Definition: iotypes.h:604
Definition: typedefs.h:119
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2793
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
FORCEINLINE VOID NpReleaseVcb(VOID)
Definition: npfs.h:344
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:155
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:3128
FORCEINLINE VOID NpCompleteDeferredIrps(IN PLIST_ENTRY DeferredList)
Definition: npfs.h:356
#define PAGED_CODE()

Referenced by DriverEntry().

Variable Documentation

◆ NpFastReadFalse

ULONG NpFastReadFalse

Definition at line 20 of file read.c.

Referenced by _Function_class_().

◆ NpFastReadTrue

ULONG NpFastReadTrue

Definition at line 19 of file read.c.

Referenced by _Function_class_().

◆ NpSlowReadCalls

LONG NpSlowReadCalls

Definition at line 18 of file read.c.

Referenced by NpFsdRead().