ReactOS 0.4.16-dev-319-g6cf4263
write.c File Reference
#include "npfs.h"
Include dependency graph for write.c:

Go to the source code of this file.

Macros

#define NPFS_BUGCHECK_FILE_ID   (NPFS_BUGCHECK_WRITE)
 

Functions

BOOLEAN NTAPI NpCommonWrite (IN PFILE_OBJECT FileObject, IN PVOID Buffer, IN ULONG DataSize, IN PETHREAD Thread, IN PIO_STATUS_BLOCK IoStatus, IN PIRP Irp, IN PLIST_ENTRY List)
 
NTSTATUS NTAPI NpFsdWrite (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
 _Function_class_ (FAST_IO_WRITE)
 

Variables

LONG NpSlowWriteCalls
 
ULONG NpFastWriteTrue
 
ULONG NpFastWriteFalse
 

Macro Definition Documentation

◆ NPFS_BUGCHECK_FILE_ID

#define NPFS_BUGCHECK_FILE_ID   (NPFS_BUGCHECK_WRITE)

Definition at line 14 of file write.c.

Function Documentation

◆ _Function_class_()

_Function_class_ ( FAST_IO_WRITE  )

Definition at line 213 of file write.c.

226{
227 LIST_ENTRY DeferredList;
229 PAGED_CODE();
230
231 InitializeListHead(&DeferredList);
232
235
237 Buffer,
238 Length,
240 IoStatus,
241 NULL,
242 &DeferredList);
243 if (Result)
245 else
247
248 NpReleaseVcb();
249 NpCompleteDeferredIrps(&DeferredList);
251
252 return Result;
253}
#define PAGED_CODE()
unsigned char BOOLEAN
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
FORCEINLINE VOID NpReleaseVcb(VOID)
Definition: npfs.h:344
FORCEINLINE VOID NpAcquireSharedVcb(VOID)
Definition: npfs.h:328
FORCEINLINE VOID NpCompleteDeferredIrps(IN PLIST_ENTRY DeferredList)
Definition: npfs.h:356
ULONG NpFastWriteTrue
Definition: write.c:19
ULONG NpFastWriteFalse
Definition: write.c:20
BOOLEAN NTAPI NpCommonWrite(IN PFILE_OBJECT FileObject, IN PVOID Buffer, IN ULONG DataSize, IN PETHREAD Thread, IN PIO_STATUS_BLOCK IoStatus, IN PIRP Irp, IN PLIST_ENTRY List)
Definition: write.c:26
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
Definition: typedefs.h:120
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409

◆ NpCommonWrite()

BOOLEAN NTAPI NpCommonWrite ( IN PFILE_OBJECT  FileObject,
IN PVOID  Buffer,
IN ULONG  DataSize,
IN PETHREAD  Thread,
IN PIO_STATUS_BLOCK  IoStatus,
IN PIRP  Irp,
IN PLIST_ENTRY  List 
)

Definition at line 26 of file write.c.

33{
35 BOOLEAN WriteOk;
37 PNP_NONPAGED_CCB NonPagedCcb;
38 PNP_DATA_QUEUE WriteQueue;
40 PNP_EVENT_BUFFER EventBuffer;
41 ULONG BytesWritten, NamedPipeEnd, ReadMode;
42 PAGED_CODE();
43
44 IoStatus->Information = 0;
45 NodeType = NpDecodeFileObject(FileObject, NULL, &Ccb, &NamedPipeEnd);
46
47 if (!NodeType)
48 {
50 return TRUE;
51 }
52
54 {
56 return TRUE;
57 }
58
59 NonPagedCcb = Ccb->NonPagedCcb;
61
62 if (Ccb->NamedPipeState != FILE_PIPE_CONNECTED_STATE)
63 {
64 if (Ccb->NamedPipeState == FILE_PIPE_DISCONNECTED_STATE)
65 {
67 }
68 else if (Ccb->NamedPipeState == FILE_PIPE_LISTENING_STATE)
69 {
71 }
72 else
73 {
74 ASSERT(Ccb->NamedPipeState == FILE_PIPE_CLOSING_STATE);
76 }
77
78 WriteOk = TRUE;
79 goto Quickie;
80 }
81
82 if ((NamedPipeEnd == FILE_PIPE_SERVER_END && Ccb->Fcb->NamedPipeConfiguration == FILE_PIPE_INBOUND) ||
83 (NamedPipeEnd == FILE_PIPE_CLIENT_END && Ccb->Fcb->NamedPipeConfiguration == FILE_PIPE_OUTBOUND))
84 {
86 WriteOk = TRUE;
87 goto Quickie;
88 }
89
90 IoStatus->Status = STATUS_SUCCESS;
91 IoStatus->Information = DataSize;
92
93 if (NamedPipeEnd == FILE_PIPE_SERVER_END)
94 {
95 WriteQueue = &Ccb->DataQueue[FILE_PIPE_OUTBOUND];
96 ReadMode = Ccb->ReadMode[FILE_PIPE_CLIENT_END];
97 }
98 else
99 {
100 WriteQueue = &Ccb->DataQueue[FILE_PIPE_INBOUND];
101 ReadMode = Ccb->ReadMode[FILE_PIPE_SERVER_END];
102 }
103
104 EventBuffer = NonPagedCcb->EventBuffer[NamedPipeEnd];
105
106 if ((WriteQueue->QueueState == ReadEntries &&
107 WriteQueue->BytesInQueue < DataSize &&
108 WriteQueue->Quota < DataSize - WriteQueue->BytesInQueue) ||
109 (WriteQueue->QueueState != ReadEntries &&
110 WriteQueue->Quota - WriteQueue->QuotaUsed < DataSize))
111 {
112 if (Ccb->Fcb->NamedPipeType == FILE_PIPE_MESSAGE_TYPE &&
113 Ccb->CompletionMode[NamedPipeEnd] == FILE_PIPE_COMPLETE_OPERATION)
114 {
115 IoStatus->Information = 0;
116 IoStatus->Status = STATUS_SUCCESS;
117 WriteOk = TRUE;
118 goto Quickie;
119 }
120
121 if (!Irp)
122 {
123 WriteOk = FALSE;
124 goto Quickie;
125 }
126 }
127
128 Status = NpWriteDataQueue(WriteQueue,
129 ReadMode,
130 Buffer,
131 DataSize,
132 Ccb->Fcb->NamedPipeType,
134 Ccb,
135 NamedPipeEnd,
136 Thread,
137 List);
138 IoStatus->Status = Status;
139
141 {
142 ASSERT(WriteQueue->QueueState != ReadEntries);
143 if ((Ccb->CompletionMode[NamedPipeEnd] == FILE_PIPE_COMPLETE_OPERATION || !Irp) &&
144 ((WriteQueue->Quota - WriteQueue->QuotaUsed) < BytesWritten))
145 {
146 IoStatus->Information = DataSize - BytesWritten;
147 IoStatus->Status = STATUS_SUCCESS;
148 }
149 else
150 {
151 ASSERT(WriteQueue->QueueState != ReadEntries);
152
153 IoStatus->Status = NpAddDataQueueEntry(NamedPipeEnd,
154 Ccb,
155 WriteQueue,
157 Buffered,
158 DataSize,
159 Irp,
160 Buffer,
162 }
163 }
164
165 if (EventBuffer) KeSetEvent(EventBuffer->Event, IO_NO_INCREMENT, FALSE);
166 WriteOk = TRUE;
167
168Quickie:
169 ExReleaseResourceLite(&Ccb->NonPagedCcb->Lock);
170 return WriteOk;
171}
NodeType
Definition: Node.h:6
LONG NTSTATUS
Definition: precomp.h:26
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:592
_In_ PIRP Irp
Definition: csq.h:116
NTSTATUS NTAPI NpAddDataQueueEntry(IN ULONG NamedPipeEnd, IN PNP_CCB Ccb, IN PNP_DATA_QUEUE DataQueue, IN ULONG Who, IN ULONG Type, IN ULONG DataSize, IN PIRP Irp, IN PVOID Buffer, IN ULONG ByteOffset)
Definition: datasup.c:295
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
USHORT NODE_TYPE_CODE
Definition: nodetype.h:22
#define NodeType(P)
Definition: nodetype.h:51
@ Buffered
Definition: npfs.h:131
@ ReadEntries
Definition: npfs.h:123
@ WriteEntries
Definition: npfs.h:124
NTSTATUS NTAPI NpWriteDataQueue(IN PNP_DATA_QUEUE WriteQueue, IN ULONG Mode, IN PVOID OutBuffer, IN ULONG OutBufferSize, IN ULONG PipeType, OUT PULONG BytesWritten, IN PNP_CCB Ccb, IN ULONG NamedPipeEnd, IN PETHREAD Thread, IN PLIST_ENTRY List)
Definition: writesup.c:20
#define NPFS_NTC_CCB
Definition: npfs.h:115
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
#define ExAcquireResourceExclusiveLite(res, wait)
Definition: env_spec_w32.h:615
NODE_TYPE_CODE NTAPI NpDecodeFileObject(IN PFILE_OBJECT FileObject, OUT PVOID *PrimaryContext OPTIONAL, OUT PNP_CCB *Ccb, OUT PULONG NamedPipeEnd OPTIONAL)
Definition: fileobsup.c:20
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
Status
Definition: gdiplustypes.h:25
#define FILE_PIPE_DISCONNECTED_STATE
Definition: winternl.h:790
#define FILE_PIPE_LISTENING_STATE
Definition: winternl.h:791
#define FILE_PIPE_CONNECTED_STATE
Definition: winternl.h:792
#define FILE_PIPE_CLOSING_STATE
Definition: winternl.h:793
#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_OUTBOUND
Definition: iotypes.h:82
#define FILE_PIPE_MESSAGE_TYPE
Definition: iotypes.h:76
#define FILE_PIPE_INBOUND
Definition: iotypes.h:81
#define FILE_PIPE_CLIENT_END
Definition: iotypes.h:84
#define FILE_PIPE_COMPLETE_OPERATION
Definition: iotypes.h:80
#define FILE_PIPE_SERVER_END
Definition: iotypes.h:85
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1822
#define STATUS_PIPE_DISCONNECTED
Definition: ntstatus.h:412
#define STATUS_PIPE_LISTENING
Definition: ntstatus.h:415
#define STATUS_PIPE_CLOSING
Definition: ntstatus.h:413
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _FCB::@730::@733 Fcb
Definition: npfs.h:259
ULONG Quota
Definition: npfs.h:144
ULONG QueueState
Definition: npfs.h:139
ULONG QuotaUsed
Definition: npfs.h:142
ULONG BytesInQueue
Definition: npfs.h:140
PKEVENT Event
Definition: npfs.h:179
ERESOURCE Lock
Definition: npfs.h:254
PNP_EVENT_BUFFER EventBuffer[2]
Definition: npfs.h:253
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesWritten
Definition: wdfiotarget.h:960
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
#define IO_NO_INCREMENT
Definition: iotypes.h:598

Referenced by _Function_class_(), and NpFsdWrite().

◆ NpFsdWrite()

NTSTATUS NTAPI NpFsdWrite ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 175 of file write.c.

177{
178 PIO_STACK_LOCATION IoStack;
180 LIST_ENTRY DeferredList;
181 PAGED_CODE();
183
184 InitializeListHead(&DeferredList);
186
189
190 NpCommonWrite(IoStack->FileObject,
191 Irp->UserBuffer,
192 IoStack->Parameters.Write.Length,
193 Irp->Tail.Overlay.Thread,
194 &IoStatus,
195 Irp,
196 &DeferredList);
197
198 NpReleaseVcb();
199 NpCompleteDeferredIrps(&DeferredList);
201
202 if (IoStatus.Status != STATUS_PENDING)
203 {
204 Irp->IoStatus.Information = IoStatus.Information;
205 Irp->IoStatus.Status = IoStatus.Status;
207 }
208
209 return IoStatus.Status;
210}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define STATUS_PENDING
Definition: d3dkmdt.h:43
LONG NpSlowWriteCalls
Definition: write.c:18
#define IoCompleteRequest
Definition: irp.c:1240
struct _IO_STACK_LOCATION::@3979::@3984 Write
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
union _IO_STACK_LOCATION::@1580 Parameters
#define IO_NAMED_PIPE_INCREMENT
Definition: iotypes.h:604

Referenced by DriverEntry().

Variable Documentation

◆ NpFastWriteFalse

ULONG NpFastWriteFalse

Definition at line 20 of file write.c.

Referenced by _Function_class_().

◆ NpFastWriteTrue

ULONG NpFastWriteTrue

Definition at line 19 of file write.c.

Referenced by _Function_class_().

◆ NpSlowWriteCalls

LONG NpSlowWriteCalls

Definition at line 18 of file write.c.

Referenced by NpFsdWrite().