ReactOS 0.4.16-dev-197-g92996da
strucsup.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/strucsup.c
5 * PURPOSE:
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_STRUCSUP)
15
16/* GLOBALS ********************************************************************/
17
20
21/* FUNCTIONS ******************************************************************/
22
28{
30 return GenericEqual;
31}
32
37{
39 return NULL;
40}
41
42VOID
46{
48}
49
54{
55 if (!Buffer) return FALSE;
56
59}
60
61VOID
64 IN PLIST_ENTRY ListEntry)
65{
67 PAGED_CODE();
68
69 Dcb = Fcb->ParentDcb;
70 if (Fcb->CurrentInstances) NpBugCheck(0, 0, 0);
71
73 &Fcb->FullName,
75 ListEntry);
76
77 RemoveEntryList(&Fcb->DcbEntry);
78
79 if (Fcb->SecurityDescriptor)
80 {
81 ObDereferenceSecurityDescriptor(Fcb->SecurityDescriptor, 1);
82 }
83
84 RtlRemoveUnicodePrefix(&NpVcb->PrefixTable, &Fcb->PrefixTableEntry);
85 ExFreePool(Fcb->FullName.Buffer);
87 NpCheckForNotify(Dcb, TRUE, ListEntry);
88}
89
90VOID
93 IN PLIST_ENTRY ListEntry)
94{
95 PNP_ROOT_DCB_FCB RootDcbCcb;
96 PAGED_CODE();
97
98 RootDcbCcb = (PNP_ROOT_DCB_FCB)Ccb;
99 if (Ccb->NodeType == NPFS_NTC_CCB)
100 {
101 RemoveEntryList(&Ccb->CcbEntry);
102 --Ccb->Fcb->CurrentInstances;
103
105 Ccb->NonPagedCcb->EventBuffer[FILE_PIPE_CLIENT_END]);
107 Ccb->NonPagedCcb->EventBuffer[FILE_PIPE_SERVER_END]);
110 NpCheckForNotify(Ccb->Fcb->ParentDcb, FALSE, ListEntry);
111 ExDeleteResourceLite(&Ccb->NonPagedCcb->Lock);
113 if (Ccb->ClientSession)
114 {
115 ExFreePool(Ccb->ClientSession);
116 Ccb->ClientSession = NULL;
117 }
118 ExFreePool(Ccb->NonPagedCcb);
119 }
120 else if (RootDcbCcb->NodeType == NPFS_NTC_ROOT_DCB_CCB && RootDcbCcb->Unknown)
121 {
122 ExFreePool(RootDcbCcb->Unknown);
123 }
124
126}
127
128VOID
129NTAPI
131{
132 PAGED_CODE();
133
134 RtlZeroMemory(NpVcb, sizeof(*NpVcb));
135
143 0);
145}
146
148NTAPI
150{
151 PNP_ROOT_DCB_FCB RootCcb;
152 PAGED_CODE();
153
154 RootCcb = ExAllocatePoolWithTag(PagedPool, sizeof(*RootCcb), NPFS_ROOT_DCB_CCB_TAG);
155 if (!RootCcb) return STATUS_INSUFFICIENT_RESOURCES;
156
157 RtlZeroMemory(RootCcb, sizeof(*RootCcb));
159 *NewRootCcb = RootCcb;
160 return STATUS_SUCCESS;
161}
162
164NTAPI
166{
167 PNP_DCB Dcb;
168 PAGED_CODE();
169
170 if (NpVcb->RootDcb)
171 {
172 NpBugCheck(0, 0, 0);
173 }
174
176 if (!NpVcb->RootDcb)
177 {
179 }
180
181 Dcb = NpVcb->RootDcb;
182 RtlZeroMemory(Dcb, sizeof(*Dcb));
183 Dcb->NodeType = NPFS_NTC_ROOT_DCB;
184
185 InitializeListHead(&Dcb->DcbEntry);
186 InitializeListHead(&Dcb->NotifyList);
187 InitializeListHead(&Dcb->NotifyList2);
188 InitializeListHead(&Dcb->FcbList);
189
190 Dcb->FullName.Buffer = NpRootDCBName;
191 Dcb->FullName.Length = sizeof(NpRootDCBName) - sizeof(UNICODE_NULL);
192 Dcb->FullName.MaximumLength = sizeof(NpRootDCBName);
193
194 Dcb->ShortName.Length = Dcb->FullName.Length;
195 Dcb->ShortName.MaximumLength = Dcb->FullName.MaximumLength;
196 Dcb->ShortName.Buffer = Dcb->FullName.Buffer;
197
199 &Dcb->FullName,
200 &Dcb->PrefixTableEntry))
201 {
202 NpBugCheck(0, 0, 0);
203 }
204
205 return STATUS_SUCCESS;
206}
207
209NTAPI
211 IN PUNICODE_STRING PipeName,
212 IN ULONG MaximumInstances,
214 IN USHORT NamedPipeConfiguration,
215 IN USHORT NamedPipeType,
216 OUT PNP_FCB *NewFcb)
217{
218 PNP_FCB Fcb;
219 BOOLEAN RootPipe;
220 PWCHAR NameBuffer;
222 PAGED_CODE();
223
224 Length = PipeName->Length;
226
227 if ((Length < sizeof(WCHAR)) || (MaximumLength < Length))
228 {
230 }
231
232 RootPipe = FALSE;
233 if (PipeName->Buffer[0] != OBJ_NAME_PATH_SEPARATOR)
234 {
237 RootPipe = TRUE;
238 if (MaximumLength < sizeof(WCHAR))
239 {
241 }
242 }
243
246
247 RtlZeroMemory(Fcb, sizeof(*Fcb));
248 Fcb->MaximumInstances = MaximumInstances;
249 Fcb->Timeout = Timeout;
250 Fcb->NodeType = NPFS_NTC_FCB;
251 Fcb->ParentDcb = Dcb;
252 InitializeListHead(&Fcb->CcbList);
253
254 NameBuffer = ExAllocatePoolWithTag(PagedPool,
257 if (!NameBuffer)
258 {
261 }
262
263 InsertTailList(&Dcb->FcbList, &Fcb->DcbEntry);
264
265 if (RootPipe)
266 {
267 NameBuffer[0] = OBJ_NAME_PATH_SEPARATOR;
268 RtlCopyMemory(NameBuffer + 1,
269 PipeName->Buffer,
270 PipeName->Length);
271 }
272 else
273 {
274 RtlCopyMemory(NameBuffer,
275 PipeName->Buffer,
276 PipeName->Length);
277 }
278
279 NameBuffer[Length / sizeof(WCHAR)] = UNICODE_NULL;
280
281 Fcb->FullName.Length = Length;
282 Fcb->FullName.MaximumLength = MaximumLength;
283 Fcb->FullName.Buffer = NameBuffer;
284
285 Fcb->ShortName.MaximumLength = Length;
286 Fcb->ShortName.Length = Length - sizeof(OBJ_NAME_PATH_SEPARATOR);
287 Fcb->ShortName.Buffer = NameBuffer + 1;
288
290 &Fcb->FullName,
291 &Fcb->PrefixTableEntry))
292 {
293 NpBugCheck(0, 0, 0);
294 }
295
296 Fcb->NamedPipeConfiguration = NamedPipeConfiguration;
297 Fcb->NamedPipeType = NamedPipeType;
298 *NewFcb = Fcb;
299 return STATUS_SUCCESS;
300}
301
303NTAPI
306 IN UCHAR State,
307 IN UCHAR ReadMode,
308 IN UCHAR CompletionMode,
309 IN ULONG InQuota,
310 IN ULONG OutQuota,
311 OUT PNP_CCB *NewCcb)
312{
313 PNP_CCB Ccb;
314 PNP_NONPAGED_CCB CcbNonPaged;
316 PAGED_CODE();
317
320
321 CcbNonPaged = ExAllocatePoolWithTag(NonPagedPool, sizeof(*CcbNonPaged), NPFS_CCB_TAG);
322 if (!CcbNonPaged)
323 {
326 }
327
328 RtlZeroMemory(CcbNonPaged, sizeof(*CcbNonPaged));
329 CcbNonPaged->NodeType = NPFS_NTC_NONPAGED_CCB;
330
331 RtlZeroMemory(Ccb, sizeof(*Ccb));
332 Ccb->NodeType = NPFS_NTC_CCB;
333 Ccb->NonPagedCcb = CcbNonPaged;
335 Ccb->Fcb = Fcb;
336 Ccb->NamedPipeState = State;
337 Ccb->ReadMode[FILE_PIPE_SERVER_END] = ReadMode;
338 Ccb->CompletionMode[FILE_PIPE_SERVER_END] = CompletionMode;
339
340 Status = NpInitializeDataQueue(&Ccb->DataQueue[FILE_PIPE_INBOUND], InQuota);
341 if (!NT_SUCCESS(Status))
342 {
343 ExFreePool(CcbNonPaged);
346 }
347
348 Status = NpInitializeDataQueue(&Ccb->DataQueue[FILE_PIPE_OUTBOUND], OutQuota);
349 if (!NT_SUCCESS(Status))
350 {
352 ExFreePool(CcbNonPaged);
355 }
356
357 InsertTailList(&Fcb->CcbList, &Ccb->CcbEntry);
358
359 Fcb->CurrentInstances++;
360 Fcb->ServerOpenCount++;
361 InitializeListHead(&Ccb->IrpList);
362 ExInitializeResourceLite(&Ccb->NonPagedCcb->Lock);
363 *NewCcb = Ccb;
364 return STATUS_SUCCESS;
365}
366
367/* EOF */
#define PAGED_CODE()
unsigned char BOOLEAN
#define OBJ_NAME_PATH_SEPARATOR
Definition: arcname_tests.c:25
LONG NTSTATUS
Definition: precomp.h:26
#define UNIMPLEMENTED
Definition: debug.h:118
_In_ PFCB Fcb
Definition: cdprocs.h:159
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:592
Definition: bufpool.h:45
NTSTATUS NTAPI NpUninitializeDataQueue(IN PNP_DATA_QUEUE DataQueue)
Definition: datasup.c:20
NTSTATUS NTAPI NpInitializeDataQueue(IN PNP_DATA_QUEUE DataQueue, IN ULONG Quota)
Definition: datasup.c:32
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB * Dcb
Definition: create.c:4140
VOID NTAPI NpCheckForNotify(IN PNP_DCB Dcb, IN BOOLEAN SecondList, IN PLIST_ENTRY List)
Definition: create.c:20
#define NPFS_NTC_VCB
Definition: npfs.h:112
#define NPFS_FCB_TAG
Definition: npfs.h:56
#define NPFS_NTC_ROOT_DCB_CCB
Definition: npfs.h:117
#define NPFS_NTC_ROOT_DCB
Definition: npfs.h:113
#define NPFS_ROOT_DCB_CCB_TAG
Definition: npfs.h:54
#define NPFS_DCB_TAG
Definition: npfs.h:55
#define NpBugCheck(p1, p2, p3)
Definition: npfs.h:106
#define NPFS_CCB_TAG
Definition: npfs.h:53
VOID NTAPI NpInitializeWaitQueue(IN PNP_WAIT_QUEUE WaitQueue)
Definition: waitsup.c:96
NTSTATUS NTAPI NpCancelWaiter(IN PNP_WAIT_QUEUE WaitQueue, IN PUNICODE_STRING PipeName, IN NTSTATUS Status, IN PLIST_ENTRY ListEntry)
Definition: waitsup.c:120
#define NPFS_NAME_BLOCK_TAG
Definition: npfs.h:59
struct _NP_ROOT_DCB_CCB * PNP_ROOT_DCB_FCB
#define NPFS_NTC_FCB
Definition: npfs.h:114
#define NPFS_NTC_NONPAGED_CCB
Definition: npfs.h:116
#define NPFS_NTC_CCB
Definition: npfs.h:115
VOID NTAPI NpUninitializeSecurity(IN PNP_CCB Ccb)
Definition: secursup.c:72
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertTailList(ListHead, Entry)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define ExDeleteResourceLite(res)
Definition: env_spec_w32.h:647
#define NonPagedPool
Definition: env_spec_w32.h:307
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define PagedPool
Definition: env_spec_w32.h:308
Status
Definition: gdiplustypes.h:25
VOID NTAPI RtlInitializeGenericTable(IN PRTL_GENERIC_TABLE Table, IN PRTL_GENERIC_COMPARE_ROUTINE CompareRoutine, IN PRTL_GENERIC_ALLOCATE_ROUTINE AllocateRoutine, IN PRTL_GENERIC_FREE_ROUTINE FreeRoutine, IN PVOID TableContext)
Definition: generictable.c:100
ASMGENDATA Table[]
Definition: genincdata.c:61
#define FILE_PIPE_OUTBOUND
Definition: iotypes.h:82
#define FILE_PIPE_INBOUND
Definition: iotypes.h:81
#define FILE_PIPE_CLIENT_END
Definition: iotypes.h:84
#define FILE_PIPE_SERVER_END
Definition: iotypes.h:85
VOID NTAPI NpInitializeVcb(VOID)
Definition: strucsup.c:130
NTSTATUS NTAPI NpCreateCcb(IN PNP_FCB Fcb, IN PFILE_OBJECT FileObject, IN UCHAR State, IN UCHAR ReadMode, IN UCHAR CompletionMode, IN ULONG InQuota, IN ULONG OutQuota, OUT PNP_CCB *NewCcb)
Definition: strucsup.c:304
RTL_GENERIC_COMPARE_RESULTS NTAPI NpEventTableCompareRoutine(IN PRTL_GENERIC_TABLE Table, IN PVOID FirstStruct, IN PVOID SecondStruct)
Definition: strucsup.c:25
PNP_VCB NpVcb
Definition: strucsup.c:19
NTSTATUS NTAPI NpCreateFcb(IN PNP_DCB Dcb, IN PUNICODE_STRING PipeName, IN ULONG MaximumInstances, IN LARGE_INTEGER Timeout, IN USHORT NamedPipeConfiguration, IN USHORT NamedPipeType, OUT PNP_FCB *NewFcb)
Definition: strucsup.c:210
NTSTATUS NTAPI NpCreateRootDcb(VOID)
Definition: strucsup.c:165
VOID NTAPI NpDeleteFcb(IN PNP_FCB Fcb, IN PLIST_ENTRY ListEntry)
Definition: strucsup.c:63
PVOID NTAPI NpEventTableAllocate(IN PRTL_GENERIC_TABLE Table, IN CLONG ByteSize)
Definition: strucsup.c:35
NTSTATUS NTAPI NpCreateRootDcbCcb(IN PNP_ROOT_DCB_FCB *NewRootCcb)
Definition: strucsup.c:149
VOID NTAPI NpDeleteCcb(IN PNP_CCB Ccb, IN PLIST_ENTRY ListEntry)
Definition: strucsup.c:92
WCHAR NpRootDCBName[]
Definition: strucsup.c:18
VOID NTAPI NpEventTableDeallocate(IN PRTL_GENERIC_TABLE Table, IN PVOID Buffer)
Definition: strucsup.c:44
BOOLEAN NTAPI NpDeleteEventTableEntry(IN PRTL_GENERIC_TABLE Table, IN PVOID Buffer)
Definition: strucsup.c:52
#define UNICODE_NULL
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define L(x)
Definition: ntvdm.h:50
VOID NTAPI ObDereferenceSecurityDescriptor(IN PSECURITY_DESCRIPTOR SecurityDescriptor, IN ULONG Count)
Definition: obsdcach.c:287
unsigned short USHORT
Definition: pedump.c:61
static ULONG Timeout
Definition: ping.c:61
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _FCB * ParentDcb
Definition: fatstruc.h:836
struct _FCB::@729::@732 Fcb
FILE_NAME_NODE ShortName
Definition: fatstruc.h:1115
PFILE_OBJECT FileObject
Definition: ntfs.h:520
Definition: typedefs.h:120
Definition: npfs.h:259
Definition: npfs.h:211
Definition: npfs.h:229
NODE_TYPE_CODE NodeType
Definition: npfs.h:252
NODE_TYPE_CODE NodeType
Definition: npfs.h:185
PVOID Unknown
Definition: npfs.h:186
Definition: npfs.h:278
PNP_DCB RootDcb
Definition: npfs.h:281
ERESOURCE Lock
Definition: npfs.h:283
UNICODE_PREFIX_TABLE PrefixTable
Definition: npfs.h:282
NODE_TYPE_CODE NodeType
Definition: npfs.h:279
NP_WAIT_QUEUE WaitQueue
Definition: npfs.h:285
RTL_GENERIC_TABLE EventTable
Definition: npfs.h:284
#define NTAPI
Definition: typedefs.h:36
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IN
Definition: typedefs.h:39
uint16_t * PWCHAR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
ULONG CLONG
Definition: umtypes.h:126
VOID NTAPI RtlRemoveUnicodePrefix(PUNICODE_PREFIX_TABLE PrefixTable, PUNICODE_PREFIX_TABLE_ENTRY PrefixTableEntry)
BOOLEAN NTAPI RtlInsertUnicodePrefix(PUNICODE_PREFIX_TABLE PrefixTable, PUNICODE_STRING Prefix, PUNICODE_PREFIX_TABLE_ENTRY PrefixTableEntry)
VOID NTAPI RtlInitializeUnicodePrefix(PUNICODE_PREFIX_TABLE PrefixTable)
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
_In_ WDFDMATRANSACTION _In_ size_t MaximumLength
* PFILE_OBJECT
Definition: iotypes.h:1998
#define ObDereferenceObject
Definition: obfuncs.h:203
NTSYSAPI BOOLEAN NTAPI RtlDeleteElementGenericTable(_In_ PRTL_GENERIC_TABLE Table, _In_ PVOID Buffer)
_IRQL_requires_same_ _In_ PVOID _In_ PVOID SecondStruct
Definition: rtltypes.h:403
_IRQL_requires_same_ _In_ CLONG ByteSize
Definition: rtltypes.h:412
_IRQL_requires_same_ _In_ PVOID FirstStruct
Definition: rtltypes.h:402
@ GenericEqual
Definition: rtltypes.h:391
enum _RTL_GENERIC_COMPARE_RESULTS RTL_GENERIC_COMPARE_RESULTS
unsigned char UCHAR
Definition: xmlstorage.h:181
__wchar_t WCHAR
Definition: xmlstorage.h:180