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
9 /* INCLUDES *******************************************************************/
13 /* FUNCTIONS ******************************************************************/
17 NpReadDataQueue(IN PNP_DATA_QUEUE DataQueue
,
19 IN BOOLEAN ReadOverflowOperation
,
26 PNP_DATA_QUEUE_ENTRY DataEntry
, TempDataEntry
;
28 ULONG DataSize
, DataLength
, TotalBytesCopied
, RemainingSize
, Offset
;
30 IO_STATUS_BLOCK Status
;
31 BOOLEAN CompleteWrites
= FALSE
;
34 if (ReadOverflowOperation
) Peek
= TRUE
;
36 RemainingSize
= BufferSize
;
37 Status
.Status
= STATUS_SUCCESS
;
42 DataEntry
= CONTAINING_RECORD(DataQueue
->Queue
.Flink
,
48 DataEntry
= NpGetNextRealDataQueueEntry(DataQueue
, List
);
51 while ((&DataEntry
->QueueEntry
!= &DataQueue
->Queue
) && (RemainingSize
))
54 DataEntry
->DataEntryType
== Buffered
||
55 DataEntry
->DataEntryType
== Unbuffered
)
57 if (DataEntry
->DataEntryType
== Unbuffered
)
59 DataBuffer
= DataEntry
->Irp
->AssociatedIrp
.SystemBuffer
;
63 DataBuffer
= &DataEntry
[1];
66 DataSize
= DataEntry
->DataSize
;
69 if (&DataEntry
->QueueEntry
== DataQueue
->Queue
.Flink
)
71 Offset
-= DataQueue
->ByteOffset
;
75 if (Offset
>= RemainingSize
) DataLength
= RemainingSize
;
79 RtlCopyMemory((PVOID
)((ULONG_PTR
)Buffer
+ BufferSize
- RemainingSize
),
80 (PVOID
)((ULONG_PTR
)DataBuffer
+ DataSize
- Offset
),
83 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
90 RemainingSize
-= DataLength
;
92 TotalBytesCopied
+= DataLength
;
96 DataEntry
->QuotaInEntry
-= DataLength
;
97 DataQueue
->QuotaUsed
-= DataLength
;
98 DataQueue
->ByteOffset
+= DataLength
;
99 CompleteWrites
= TRUE
;
102 NpCopyClientContext(Ccb
, DataEntry
);
104 if ((Offset
) || (ReadOverflowOperation
&& !TotalBytesCopied
))
106 if (Mode
== FILE_PIPE_MESSAGE_MODE
)
108 Status
.Status
= STATUS_BUFFER_OVERFLOW
;
114 if (!Peek
|| ReadOverflowOperation
)
116 if (ReadOverflowOperation
)
118 TempDataEntry
= NpGetNextRealDataQueueEntry(DataQueue
, List
);
119 ASSERT(TempDataEntry
== DataEntry
);
122 Irp
= NpRemoveDataQueueEntry(DataQueue
, TRUE
, List
);
125 Irp
->IoStatus
.Information
= DataSize
;
126 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
127 InsertTailList(List
, &Irp
->Tail
.Overlay
.ListEntry
);
130 if (Mode
== FILE_PIPE_MESSAGE_MODE
)
132 Status
.Status
= STATUS_SUCCESS
;
135 ASSERT(!ReadOverflowOperation
);
140 DataEntry
= CONTAINING_RECORD(DataEntry
->QueueEntry
.Flink
,
146 DataEntry
= NpGetNextRealDataQueueEntry(DataQueue
, List
);
150 Status
.Information
= TotalBytesCopied
;
151 if (CompleteWrites
) NpCompleteStalledWrites(DataQueue
, List
);