ReactOS 0.4.16-dev-112-g52265ae
writesup.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/writesup.c
5 * PURPOSE: Pipes Writing 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_WRITESUP)
15
16/* FUNCTIONS ******************************************************************/
17
24 IN ULONG PipeType,
25 OUT PULONG BytesNotWritten,
27 IN ULONG NamedPipeEnd,
30{
31 BOOLEAN HaveContext = FALSE, MoreProcessing, AllocatedBuffer;
32 PNP_DATA_QUEUE_ENTRY DataEntry;
34 PIRP WriteIrp;
35 PIO_STACK_LOCATION IoStack;
39 PAGED_CODE();
40
41 *BytesNotWritten = OutBufferSize;
42
43 MoreProcessing = TRUE;
44 if ((PipeType != FILE_PIPE_MESSAGE_MODE) || (OutBufferSize))
45 {
46 MoreProcessing = FALSE;
47 }
48
49 for (DataEntry = CONTAINING_RECORD(NpGetNextRealDataQueueEntry(WriteQueue, List),
51 QueueEntry);
52 ((WriteQueue->QueueState == ReadEntries) &&
53 ((*BytesNotWritten > 0) || (MoreProcessing)));
54 DataEntry = CONTAINING_RECORD(NpGetNextRealDataQueueEntry(WriteQueue, List),
56 QueueEntry))
57 {
58 DataSize = DataEntry->DataSize;
59
60 IoStack = IoGetCurrentIrpStackLocation(DataEntry->Irp);
61
64 (DataSize < OutBufferSize || MoreProcessing))
65 {
66 WriteIrp = NpRemoveDataQueueEntry(WriteQueue, TRUE, List);
67 if (WriteIrp)
68 {
70 InsertTailList(List, &WriteIrp->Tail.Overlay.ListEntry);
71 }
72 continue;
73 }
74
75 if (DataEntry->DataEntryType == Unbuffered)
76 {
77 DataEntry->Irp->Overlay.AllocationSize.QuadPart = 0;
78 }
79
80 BufferSize = *BytesNotWritten;
82
83 if (DataEntry->DataEntryType != Unbuffered && BufferSize)
84 {
87 AllocatedBuffer = TRUE;
88 }
89 else
90 {
92 AllocatedBuffer = FALSE;
93 }
94
96 {
98 (PVOID)((ULONG_PTR)OutBuffer + OutBufferSize - *BytesNotWritten),
100 }
102 {
103 if (AllocatedBuffer) ExFreePool(Buffer);
105 }
106 _SEH2_END;
107
108 if (!HaveContext)
109 {
110 HaveContext = TRUE;
112 if (!NT_SUCCESS(Status))
113 {
114 if (AllocatedBuffer) ExFreePool(Buffer);
115 return Status;
116 }
117
118 if (ClientContext)
119 {
120 NpFreeClientSecurityContext(Ccb->ClientContext);
121 Ccb->ClientContext = ClientContext;
122 }
123 }
124
125 WriteIrp = NpRemoveDataQueueEntry(WriteQueue, TRUE, List);
126 if (WriteIrp)
127 {
128 *BytesNotWritten -= BufferSize;
129 WriteIrp->IoStatus.Information = BufferSize;
130
131 if (AllocatedBuffer)
132 {
135 }
136
137 if (!*BytesNotWritten)
138 {
139 MoreProcessing = FALSE;
140 WriteIrp->IoStatus.Status = STATUS_SUCCESS;
141 InsertTailList(List, &WriteIrp->Tail.Overlay.ListEntry);
142 continue;
143 }
144
146 {
148 }
149 else
150 {
151 WriteIrp->IoStatus.Status = STATUS_SUCCESS;
152 }
153
154 InsertTailList(List, &WriteIrp->Tail.Overlay.ListEntry);
155 }
156 else if (AllocatedBuffer)
157 {
159 }
160 }
161
162 if (*BytesNotWritten > 0 || MoreProcessing)
163 {
164 ASSERT(WriteQueue->QueueState != ReadEntries);
166 }
167 else
168 {
170 }
171
172 return Status;
173}
174
175/* EOF */
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define PAGED_CODE()
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:592
Definition: bufpool.h:45
PIRP NTAPI NpRemoveDataQueueEntry(IN PNP_DATA_QUEUE DataQueue, IN BOOLEAN Flag, IN PLIST_ENTRY List)
Definition: datasup.c:105
PLIST_ENTRY NTAPI NpGetNextRealDataQueueEntry(IN PNP_DATA_QUEUE DataQueue, IN PLIST_ENTRY List)
Definition: datasup.c:174
#define BufferSize
Definition: mmc.h:75
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
@ Unbuffered
Definition: npfs.h:132
@ ReadEntries
Definition: npfs.h:123
NTSTATUS NTAPI NpGetClientSecurityContext(IN ULONG NamedPipeEnd, IN PNP_CCB Ccb, IN PETHREAD Thread, IN PSECURITY_CLIENT_CONTEXT *Context)
Definition: secursup.c:129
#define NPFS_DATA_ENTRY_TAG
Definition: npfs.h:61
VOID NTAPI NpFreeClientSecurityContext(IN PSECURITY_CLIENT_CONTEXT ClientContext)
Definition: secursup.c:40
#define InsertTailList(ListHead, Entry)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define NonPagedPool
Definition: env_spec_w32.h:307
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
Status
Definition: gdiplustypes.h:25
_In_ ULONG Mode
Definition: hubbusif.h:303
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define ASSERT(a)
Definition: mode.c:44
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4755
#define FILE_PIPE_MESSAGE_MODE
Definition: iotypes.h:78
_In_ PVOID ClientContext
Definition: netioddk.h:55
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define _SEH2_YIELD(__stmt)
Definition: pseh2_64.h:168
#define FSCTL_PIPE_INTERNAL_READ_OVFLOW
Definition: winioctl.h:206
_In_ UCHAR _In_ ULONG _Out_ PUCHAR _Outptr_result_bytebuffer_ OutBufferLength PVOID * OutBuffer
Definition: scsi.h:4071
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
struct _IO_STACK_LOCATION::@3974::@3989 FileSystemControl
union _IO_STACK_LOCATION::@1575 Parameters
union _IRP::@1577 AssociatedIrp
PVOID SystemBuffer
IO_STATUS_BLOCK IoStatus
Definition: typedefs.h:120
Definition: npfs.h:259
Definition: npfs.h:149
ULONG DataSize
Definition: npfs.h:155
ULONG DataEntryType
Definition: npfs.h:151
PIRP Irp
Definition: npfs.h:152
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
_In_ ULONG OutBufferSize
Definition: wdfwmi.h:87
NTSTATUS NTAPI NpWriteDataQueue(IN PNP_DATA_QUEUE WriteQueue, IN ULONG Mode, IN PVOID OutBuffer, IN ULONG OutBufferSize, IN ULONG PipeType, OUT PULONG BytesNotWritten, IN PNP_CCB Ccb, IN ULONG NamedPipeEnd, IN PETHREAD Thread, IN PLIST_ENTRY List)
Definition: writesup.c:20
#define IRP_DEALLOCATE_BUFFER
#define IRP_INPUT_OPERATION
#define IRP_MJ_FILE_SYSTEM_CONTROL
#define IRP_BUFFERED_IO