ReactOS  0.4.14-dev-854-gb9426a3
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 
24 NTAPI
28 {
30  return GenericEqual;
31 }
32 
33 PVOID
34 NTAPI
37 {
39  return NULL;
40 }
41 
42 VOID
43 NTAPI
45  IN PVOID Buffer)
46 {
48 }
49 
50 BOOLEAN
51 NTAPI
53  IN PVOID Buffer)
54 {
55  if (!Buffer) return FALSE;
56 
59 }
60 
61 VOID
62 NTAPI
64  IN PLIST_ENTRY ListEntry)
65 {
66  PNP_DCB Dcb;
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);
86  ExFreePool(Fcb);
87  NpCheckForNotify(Dcb, TRUE, ListEntry);
88 }
89 
90 VOID
91 NTAPI
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 
125  ExFreePool(Ccb);
126 }
127 
128 VOID
129 NTAPI
131 {
132  PAGED_CODE();
133 
134  RtlZeroMemory(NpVcb, sizeof(*NpVcb));
135 
143  0);
145 }
146 
147 NTSTATUS
148 NTAPI
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));
158  RootCcb->NodeType = NPFS_NTC_ROOT_DCB_CCB;
159  *NewRootCcb = RootCcb;
160  return STATUS_SUCCESS;
161 }
162 
163 NTSTATUS
164 NTAPI
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 
208 NTSTATUS
209 NTAPI
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;
225  MaximumLength = Length + sizeof(UNICODE_NULL);
226 
227  if ((Length < sizeof(WCHAR)) || (MaximumLength < Length))
228  {
230  }
231 
232  RootPipe = FALSE;
233  if (PipeName->Buffer[0] != OBJ_NAME_PATH_SEPARATOR)
234  {
235  Length += sizeof(OBJ_NAME_PATH_SEPARATOR);
237  RootPipe = TRUE;
238  if (MaximumLength < sizeof(WCHAR))
239  {
241  }
242  }
243 
245  if (!Fcb) return STATUS_INSUFFICIENT_RESOURCES;
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  {
259  ExFreePool(Fcb);
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 
302 NTSTATUS
303 NTAPI
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 
319  if (!Ccb) return STATUS_INSUFFICIENT_RESOURCES;
320 
321  CcbNonPaged = ExAllocatePoolWithTag(NonPagedPool, sizeof(*CcbNonPaged), NPFS_CCB_TAG);
322  if (!CcbNonPaged)
323  {
324  ExFreePool(Ccb);
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);
344  ExFreePool(Ccb);
346  }
347 
348  Status = NpInitializeDataQueue(&Ccb->DataQueue[FILE_PIPE_OUTBOUND], OutQuota);
349  if (!NT_SUCCESS(Status))
350  {
352  ExFreePool(CcbNonPaged);
353  ExFreePool(Ccb);
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 NPFS_CCB_TAG
Definition: npfs.h:53
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
#define IN
Definition: typedefs.h:38
ASMGENDATA Table[]
Definition: genincdata.c:61
#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
VOID NTAPI ObDereferenceSecurityDescriptor(IN PSECURITY_DESCRIPTOR SecurityDescriptor, IN ULONG Count)
Definition: obsdcach.c:287
NP_WAIT_QUEUE WaitQueue
Definition: npfs.h:285
struct _FCB::@710::@713 Fcb
PFILE_OBJECT FileObject
Definition: ntfs.h:516
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
VOID NTAPI RtlRemoveUnicodePrefix(PUNICODE_PREFIX_TABLE PrefixTable, PUNICODE_PREFIX_TABLE_ENTRY PrefixTableEntry)
#define NPFS_DCB_TAG
Definition: npfs.h:55
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NpInitializeDataQueue(IN PNP_DATA_QUEUE DataQueue, IN ULONG Quota)
Definition: datasup.c:32
#define NPFS_NAME_BLOCK_TAG
Definition: npfs.h:59
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
NTSTATUS NTAPI ExDeleteResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1456
#define FILE_PIPE_CLIENT_END
Definition: iotypes.h:84
Definition: npfs.h:277
#define NPFS_NTC_CCB
Definition: npfs.h:115
VOID NTAPI RtlInitializeUnicodePrefix(PUNICODE_PREFIX_TABLE PrefixTable)
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
uint16_t * PWCHAR
Definition: typedefs.h:54
VOID NTAPI NpCheckForNotify(IN PNP_DCB Dcb, IN BOOLEAN SecondList, IN PLIST_ENTRY List)
Definition: create.c:20
#define InsertTailList(ListHead, Entry)
struct _FCB * ParentDcb
Definition: fatstruc.h:835
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
#define PAGED_CODE()
Definition: video.h:57
PVOID Unknown
Definition: npfs.h:186
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
VOID NTAPI NpDeleteFcb(IN PNP_FCB Fcb, IN PLIST_ENTRY ListEntry)
Definition: strucsup.c:63
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
ULONG CLONG
Definition: umtypes.h:126
Definition: npfs.h:210
Definition: npfs.h:228
Definition: npfs.h:258
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define UNICODE_NULL
NODE_TYPE_CODE NodeType
Definition: npfs.h:279
NTSTATUS NTAPI NpCreateRootDcbCcb(IN PNP_ROOT_DCB_FCB *NewRootCcb)
Definition: strucsup.c:149
#define OBJ_NAME_PATH_SEPARATOR
Definition: arcname_tests.c:25
PVOID NTAPI NpEventTableAllocate(IN PRTL_GENERIC_TABLE Table, IN CLONG ByteSize)
Definition: strucsup.c:35
PNP_VCB NpVcb
Definition: strucsup.c:19
unsigned char BOOLEAN
#define NPFS_ROOT_DCB_CCB_TAG
Definition: npfs.h:54
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define NpBugCheck(p1, p2, p3)
Definition: npfs.h:106
VOID NTAPI NpInitializeWaitQueue(IN PNP_WAIT_QUEUE WaitQueue)
Definition: waitsup.c:96
_IRQL_requires_same_ _In_ PVOID _In_ PVOID SecondStruct
Definition: rtltypes.h:379
#define NPFS_NTC_ROOT_DCB_CCB
Definition: npfs.h:117
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _NP_ROOT_DCB_CCB * PNP_ROOT_DCB_FCB
NTSTATUS NTAPI NpCreateRootDcb(VOID)
Definition: strucsup.c:165
VOID NTAPI NpInitializeVcb(VOID)
Definition: strucsup.c:130
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
* PFILE_OBJECT
Definition: iotypes.h:1955
#define FILE_PIPE_SERVER_END
Definition: iotypes.h:85
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
unsigned char UCHAR
Definition: xmlstorage.h:181
static const WCHAR L[]
Definition: oid.c:1250
#define NPFS_FCB_TAG
Definition: npfs.h:56
RTL_GENERIC_TABLE EventTable
Definition: npfs.h:284
_IRQL_requires_same_ _In_ PVOID FirstStruct
Definition: rtltypes.h:379
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:593
BOOLEAN NTAPI RtlInsertUnicodePrefix(PUNICODE_PREFIX_TABLE PrefixTable, PUNICODE_STRING Prefix, PUNICODE_PREFIX_TABLE_ENTRY PrefixTableEntry)
Definition: typedefs.h:117
#define NPFS_NTC_ROOT_DCB
Definition: npfs.h:113
VOID NTAPI NpUninitializeSecurity(IN PNP_CCB Ccb)
Definition: secursup.c:72
ERESOURCE Lock
Definition: npfs.h:283
NTSTATUS NTAPI NpUninitializeDataQueue(IN PNP_DATA_QUEUE DataQueue)
Definition: datasup.c:20
Status
Definition: gdiplustypes.h:24
UnicodeString MaximumLength
Definition: rtlfuncs.h:2982
NTSYSAPI BOOLEAN NTAPI RtlDeleteElementGenericTable(_In_ PRTL_GENERIC_TABLE Table, _In_ PVOID Buffer)
UNICODE_PREFIX_TABLE PrefixTable
Definition: npfs.h:282
enum State_ State
Definition: pofuncs.h:54
static ULONG Timeout
Definition: ping.c:61
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
unsigned short USHORT
Definition: pedump.c:61
NODE_TYPE_CODE NodeType
Definition: npfs.h:252
VOID NTAPI NpDeleteCcb(IN PNP_CCB Ccb, IN PLIST_ENTRY ListEntry)
Definition: strucsup.c:92
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define FILE_PIPE_OUTBOUND
Definition: iotypes.h:82
enum _RTL_GENERIC_COMPARE_RESULTS RTL_GENERIC_COMPARE_RESULTS
PNP_DCB RootDcb
Definition: npfs.h:281
RTL_GENERIC_COMPARE_RESULTS NTAPI NpEventTableCompareRoutine(IN PRTL_GENERIC_TABLE Table, IN PVOID FirstStruct, IN PVOID SecondStruct)
Definition: strucsup.c:25
#define OUT
Definition: typedefs.h:39
#define NPFS_NTC_FCB
Definition: npfs.h:114
VOID NTAPI NpEventTableDeallocate(IN PRTL_GENERIC_TABLE Table, IN PVOID Buffer)
Definition: strucsup.c:44
unsigned int ULONG
Definition: retypes.h:1
WCHAR NpRootDCBName[]
Definition: strucsup.c:18
NTSTATUS NTAPI NpCancelWaiter(IN PNP_WAIT_QUEUE WaitQueue, IN PUNICODE_STRING PipeName, IN NTSTATUS Status, IN PLIST_ENTRY ListEntry)
Definition: waitsup.c:120
#define UNIMPLEMENTED
Definition: debug.h:114
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define FILE_PIPE_INBOUND
Definition: iotypes.h:81
NODE_TYPE_CODE NodeType
Definition: npfs.h:185
_In_ PFCB Fcb
Definition: cdprocs.h:151
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define NPFS_NTC_NONPAGED_CCB
Definition: npfs.h:116
_IRQL_requires_same_ _In_ CLONG ByteSize
Definition: rtltypes.h:389
FILE_NAME_NODE ShortName
Definition: fatstruc.h:1114
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB _Outptr_result_maybenull_ PDCB * Dcb
Definition: create.c:4157
#define NPFS_NTC_VCB
Definition: npfs.h:112
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
BOOLEAN NTAPI NpDeleteEventTableEntry(IN PRTL_GENERIC_TABLE Table, IN PVOID Buffer)
Definition: strucsup.c:52