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 // File ID number for NPFS bugchecking support
14 #define NPFS_BUGCHECK_FILE_ID (NPFS_BUGCHECK_READSUP)
16 /* FUNCTIONS ******************************************************************/
20 NpReadDataQueue(IN PNP_DATA_QUEUE DataQueue
,
22 IN BOOLEAN ReadOverflowOperation
,
29 PNP_DATA_QUEUE_ENTRY DataEntry
, TempDataEntry
;
31 ULONG DataSize
, DataLength
, TotalBytesCopied
, RemainingSize
, Offset
;
33 IO_STATUS_BLOCK IoStatus
;
34 BOOLEAN CompleteWrites
= FALSE
;
37 if (ReadOverflowOperation
) Peek
= TRUE
;
39 RemainingSize
= BufferSize
;
40 IoStatus
.Status
= STATUS_SUCCESS
;
45 DataEntry
= CONTAINING_RECORD(DataQueue
->Queue
.Flink
,
51 DataEntry
= CONTAINING_RECORD(NpGetNextRealDataQueueEntry(DataQueue
, List
),
56 while ((&DataEntry
->QueueEntry
!= &DataQueue
->Queue
) && (RemainingSize
))
59 DataEntry
->DataEntryType
== Buffered
||
60 DataEntry
->DataEntryType
== Unbuffered
)
62 if (DataEntry
->DataEntryType
== Unbuffered
)
64 DataBuffer
= DataEntry
->Irp
->AssociatedIrp
.SystemBuffer
;
68 DataBuffer
= &DataEntry
[1];
71 DataSize
= DataEntry
->DataSize
;
74 if (&DataEntry
->QueueEntry
== DataQueue
->Queue
.Flink
)
76 Offset
-= DataQueue
->ByteOffset
;
80 if (DataLength
>= RemainingSize
) DataLength
= RemainingSize
;
84 RtlCopyMemory((PVOID
)((ULONG_PTR
)Buffer
+ BufferSize
- RemainingSize
),
85 (PVOID
)((ULONG_PTR
)DataBuffer
+ DataSize
- Offset
),
88 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
95 RemainingSize
-= DataLength
;
97 TotalBytesCopied
+= DataLength
;
101 DataEntry
->QuotaInEntry
-= DataLength
;
102 DataQueue
->QuotaUsed
-= DataLength
;
103 DataQueue
->ByteOffset
+= DataLength
;
104 CompleteWrites
= TRUE
;
107 NpCopyClientContext(Ccb
, DataEntry
);
109 if ((Offset
) || (ReadOverflowOperation
&& !TotalBytesCopied
))
111 if (Mode
== FILE_PIPE_MESSAGE_MODE
)
113 IoStatus
.Status
= STATUS_BUFFER_OVERFLOW
;
119 if (!Peek
|| ReadOverflowOperation
)
121 if (ReadOverflowOperation
)
123 TempDataEntry
= CONTAINING_RECORD(NpGetNextRealDataQueueEntry(DataQueue
, List
),
126 ASSERT(TempDataEntry
== DataEntry
);
129 Irp
= NpRemoveDataQueueEntry(DataQueue
, TRUE
, List
);
132 Irp
->IoStatus
.Information
= DataSize
;
133 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
134 InsertTailList(List
, &Irp
->Tail
.Overlay
.ListEntry
);
138 if (Mode
== FILE_PIPE_MESSAGE_MODE
)
140 IoStatus
.Status
= STATUS_SUCCESS
;
144 ASSERT(!ReadOverflowOperation
);
150 DataEntry
= CONTAINING_RECORD(DataEntry
->QueueEntry
.Flink
,
156 DataEntry
= CONTAINING_RECORD(NpGetNextRealDataQueueEntry(DataQueue
, List
),
162 IoStatus
.Information
= TotalBytesCopied
;
163 if (CompleteWrites
) NpCompleteStalledWrites(DataQueue
, List
);