ReactOS  0.4.14-dev-342-gdc047f9
readsup.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/readsup.c
5  * PURPOSE: Pipes Reading Support
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_READSUP)
15 
16 /* FUNCTIONS ******************************************************************/
17 
19 NTAPI
21  IN BOOLEAN Peek,
22  IN BOOLEAN ReadOverflowOperation,
23  IN PVOID Buffer,
25  IN ULONG Mode,
26  IN PNP_CCB Ccb,
28 {
29  PNP_DATA_QUEUE_ENTRY DataEntry, TempDataEntry;
30  PVOID DataBuffer;
31  ULONG DataSize, DataLength, TotalBytesCopied, RemainingSize, Offset;
32  PIRP Irp;
34  BOOLEAN CompleteWrites = FALSE;
35  PAGED_CODE();
36 
37  if (ReadOverflowOperation) Peek = TRUE;
38 
39  RemainingSize = BufferSize;
40  IoStatus.Status = STATUS_SUCCESS;
41  TotalBytesCopied = 0;
42 
43  if (Peek)
44  {
45  DataEntry = CONTAINING_RECORD(DataQueue->Queue.Flink,
47  QueueEntry);
48  }
49  else
50  {
51  DataEntry = CONTAINING_RECORD(NpGetNextRealDataQueueEntry(DataQueue, List),
53  QueueEntry);
54  }
55 
56  while ((&DataEntry->QueueEntry != &DataQueue->Queue) && (RemainingSize))
57  {
58  if (!Peek ||
59  DataEntry->DataEntryType == Buffered ||
60  DataEntry->DataEntryType == Unbuffered)
61  {
62  if (DataEntry->DataEntryType == Unbuffered)
63  {
64  DataBuffer = DataEntry->Irp->AssociatedIrp.SystemBuffer;
65  }
66  else
67  {
68  DataBuffer = &DataEntry[1];
69  }
70 
71  DataSize = DataEntry->DataSize;
72  Offset = DataSize;
73 
74  if (&DataEntry->QueueEntry == DataQueue->Queue.Flink)
75  {
76  Offset -= DataQueue->ByteOffset;
77  }
78 
80  if (DataLength >= RemainingSize) DataLength = RemainingSize;
81 
82  _SEH2_TRY
83  {
84  RtlCopyMemory((PVOID)((ULONG_PTR)Buffer + BufferSize - RemainingSize),
85  (PVOID)((ULONG_PTR)DataBuffer + DataSize - Offset),
86  DataLength);
87  }
89  {
90  ASSERT(FALSE);
91  }
92  _SEH2_END;
93 
94 
95  RemainingSize -= DataLength;
96  Offset -= DataLength;
97  TotalBytesCopied += DataLength;
98 
99  if (!Peek)
100  {
101  DataEntry->QuotaInEntry -= DataLength;
102  DataQueue->QuotaUsed -= DataLength;
103  DataQueue->ByteOffset += DataLength;
104  CompleteWrites = TRUE;
105  }
106 
107  NpCopyClientContext(Ccb, DataEntry);
108 
109  if ((Offset) || (ReadOverflowOperation && !TotalBytesCopied))
110  {
112  {
114  break;
115  }
116  }
117  else
118  {
119  if (!Peek || ReadOverflowOperation)
120  {
121  if (ReadOverflowOperation)
122  {
123  TempDataEntry = CONTAINING_RECORD(NpGetNextRealDataQueueEntry(DataQueue, List),
125  QueueEntry);
126  ASSERT(TempDataEntry == DataEntry);
127  }
128 
129  Irp = NpRemoveDataQueueEntry(DataQueue, TRUE, List);
130  if (Irp)
131  {
132  Irp->IoStatus.Information = DataSize;
133  Irp->IoStatus.Status = STATUS_SUCCESS;
134  InsertTailList(List, &Irp->Tail.Overlay.ListEntry);
135  }
136  }
137 
139  {
140  IoStatus.Status = STATUS_SUCCESS;
141  break;
142  }
143 
144  ASSERT(!ReadOverflowOperation);
145  }
146  }
147 
148  if (Peek)
149  {
150  DataEntry = CONTAINING_RECORD(DataEntry->QueueEntry.Flink,
152  QueueEntry);
153  }
154  else
155  {
156  DataEntry = CONTAINING_RECORD(NpGetNextRealDataQueueEntry(DataQueue, List),
158  QueueEntry);
159  }
160  }
161 
162  IoStatus.Information = TotalBytesCopied;
163  if (CompleteWrites) NpCompleteStalledWrites(DataQueue, List);
164  return IoStatus;
165 }
166 
167 /* EOF */
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
PLIST_ENTRY NTAPI NpGetNextRealDataQueueEntry(IN PNP_DATA_QUEUE DataQueue, IN PLIST_ENTRY List)
Definition: datasup.c:174
_In_ ULONG Mode
Definition: hubbusif.h:303
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
_In_ PIRP Irp
Definition: csq.h:116
LIST_ENTRY QueueEntry
Definition: npfs.h:150
Definition: npfs.h:131
#define InsertTailList(ListHead, Entry)
#define PAGED_CODE()
Definition: video.h:57
VOID NTAPI NpCopyClientContext(IN PNP_CCB Ccb, IN PNP_DATA_QUEUE_ENTRY DataQueueEntry)
Definition: secursup.c:58
_SEH2_TRY
Definition: create.c:4250
uint32_t ULONG_PTR
Definition: typedefs.h:63
Definition: npfs.h:258
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
unsigned char BOOLEAN
Definition: bufpool.h:45
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
PIRP NTAPI NpRemoveDataQueueEntry(IN PNP_DATA_QUEUE DataQueue, IN BOOLEAN Flag, IN PLIST_ENTRY List)
Definition: datasup.c:105
ULONG DataSize
Definition: npfs.h:155
LIST_ENTRY List
Definition: psmgr.c:57
#define BufferSize
Definition: classpnp.h:419
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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID NTAPI NpCompleteStalledWrites(IN PNP_DATA_QUEUE DataQueue, IN PLIST_ENTRY List)
Definition: datasup.c:49
Definition: npfs.h:148
static VOID Peek(PUCHAR ReadDataPort, PVOID Buffer, ULONG Length)
Definition: hardware.c:228
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
Definition: typedefs.h:117
_SEH2_END
Definition: create.c:4424
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
#define FILE_PIPE_MESSAGE_MODE
Definition: iotypes.h:78
ULONG DataEntryType
Definition: npfs.h:151
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
_Must_inspect_result_ _Out_writes_to_ DataLength PHIDP_DATA _Inout_ PULONG DataLength
Definition: hidpi.h:333
return STATUS_SUCCESS
Definition: btrfs.c:2938
ULONG QuotaInEntry
Definition: npfs.h:153
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751
PIRP Irp
Definition: npfs.h:152