ReactOS  0.4.14-dev-376-gaedba84
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 
19 NTAPI
21  IN ULONG Mode,
22  IN PVOID OutBuffer,
24  IN ULONG PipeType,
25  OUT PULONG BytesNotWritten,
26  IN PNP_CCB Ccb,
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;
36  PVOID Buffer;
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 
62  if (IoStack->MajorFunction == IRP_MJ_FILE_SYSTEM_CONTROL &&
63  IoStack->Parameters.FileSystemControl.FsControlCode == FSCTL_PIPE_INTERNAL_READ_OVFLOW &&
64  (DataSize < OutBufferSize || MoreProcessing))
65  {
66  WriteIrp = NpRemoveDataQueueEntry(WriteQueue, TRUE, List);
67  if (WriteIrp)
68  {
69  WriteIrp->IoStatus.Status = STATUS_BUFFER_OVERFLOW;
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  {
91  Buffer = DataEntry->Irp->AssociatedIrp.SystemBuffer;
92  AllocatedBuffer = FALSE;
93  }
94 
95  _SEH2_TRY
96  {
98  (PVOID)((ULONG_PTR)OutBuffer + OutBufferSize - *BytesNotWritten),
99  BufferSize);
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  {
133  WriteIrp->AssociatedIrp.SystemBuffer = Buffer;
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  {
147  WriteIrp->IoStatus.Status = STATUS_BUFFER_OVERFLOW;
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 */
#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)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
NTSTATUS NTAPI NpGetClientSecurityContext(IN ULONG NamedPipeEnd, IN PNP_CCB Ccb, IN PETHREAD Thread, IN PSECURITY_CLIENT_CONTEXT *Context)
Definition: secursup.c:129
PLIST_ENTRY NTAPI NpGetNextRealDataQueueEntry(IN PNP_DATA_QUEUE DataQueue, IN PLIST_ENTRY List)
Definition: datasup.c:174
#define NPFS_DATA_ENTRY_TAG
Definition: npfs.h:61
_In_ ULONG Mode
Definition: hubbusif.h:303
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
LONG NTSTATUS
Definition: precomp.h:26
_In_ PIRP _In_ ULONG _In_ ULONG _In_ ULONG _In_ ULONG OutBufferSize
Definition: classpnp.h:429
#define InsertTailList(ListHead, Entry)
#define PAGED_CODE()
Definition: video.h:57
_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
VOID NTAPI NpFreeClientSecurityContext(IN PSECURITY_CLIENT_CONTEXT ClientContext)
Definition: secursup.c:40
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define FSCTL_PIPE_INTERNAL_READ_OVFLOW
Definition: winioctl.h:206
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
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
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
LIST_ENTRY List
Definition: psmgr.c:57
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ PVOID ClientContext
Definition: netioddk.h:55
#define IRP_MJ_FILE_SYSTEM_CONTROL
#define BufferSize
Definition: classpnp.h:419
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
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
Definition: npfs.h:148
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
Definition: typedefs.h:117
Status
Definition: gdiplustypes.h:24
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
_SEH2_END
Definition: create.c:4424
#define IRP_INPUT_OPERATION
#define IRP_BUFFERED_IO
#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 * PULONG
Definition: retypes.h:1
#define IRP_DEALLOCATE_BUFFER
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2938
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
PIRP Irp
Definition: npfs.h:152