2 * PROJECT: Filesystem Filter Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/filters/fltmgr/Context.c
5 * PURPOSE: Contains context routines
6 * PROGRAMMERS: Ged Murphy (gedmurphy@reactos.org)
9 /* INCLUDES ******************************************************************/
12 #include "fltmgrint.h"
18 /* DATA *********************************************************************/
23 _In_ FLT_CONTEXT_TYPE ContextType
29 _In_ PFLT_FILTER Filter
,
30 _In_ PCFLT_CONTEXT_REGISTRATION ContextPtr
,
31 _Out_ PALLOCATE_CONTEXT_HEADER ContextHeader
34 /* EXPORTED FUNCTIONS ******************************************************/
39 /* INTERNAL FUNCTIONS ******************************************************/
43 FltpRegisterContexts(_In_ PFLT_FILTER Filter
,
44 _In_
const FLT_CONTEXT_REGISTRATION
*Context
)
46 PCFLT_CONTEXT_REGISTRATION ContextPtr
;
47 PALLOCATE_CONTEXT_HEADER ContextHeader
, Prev
;
53 /* Loop through all entries in the context registration array */
57 /* Bail if we found the terminator */
58 if (ContextPtr
->ContextType
== FLT_CONTEXT_END
)
61 /* Make sure we have a valid context */
62 if (IsContextTypeValid(ContextPtr
->ContextType
))
64 /* Each context is backed by a crtl struct. Reserve space for it */
65 BufferSize
+= sizeof(STREAM_LIST_CTRL
);
68 /* Move to the next entry */
72 /* Bail if we found no valid registration requests */
75 return STATUS_SUCCESS
;
78 /* Allocate the pool that'll hold the context crtl structs */
79 Buffer
= ExAllocatePoolWithTag(NonPagedPool
, BufferSize
, FM_TAG_CONTEXT_REGISTA
);
80 if (!Buffer
) return STATUS_INSUFFICIENT_RESOURCES
;
82 RtlZeroMemory(Buffer
, BufferSize
);
84 /* Setup our loop data */
85 ContextHeader
= Buffer
;
87 Status
= STATUS_SUCCESS
;
89 for (i
= 0; i
< MAX_CONTEXT_TYPES
; i
++)
91 ContextPtr
= (PFLT_CONTEXT_REGISTRATION
)Context
;
94 /* We don't support variable sized contents yet */
95 FLT_ASSERT(ContextPtr
->Size
!= FLT_VARIABLE_SIZED_CONTEXTS
);
97 /* Bail if we found the terminator */
98 if (ContextPtr
->ContextType
== FLT_CONTEXT_END
)
101 /* Size and pooltag are only checked when ContextAllocateCallback is null */
102 if (ContextPtr
->ContextAllocateCallback
== FALSE
&& ContextPtr
->PoolTag
== FALSE
)
104 Status
= STATUS_FLT_INVALID_CONTEXT_REGISTRATION
;
108 /* Make sure we have a valid context */
109 if (IsContextTypeValid(ContextPtr
->ContextType
))
111 Status
= SetupContextHeader(Filter
, ContextPtr
, ContextHeader
);
112 if (NT_SUCCESS(Status
))
116 Prev
->Next
= ContextHeader
;
119 Filter
->SupportedContexts
[i
] = ContextHeader
;
123 Prev
= ContextHeader
;
125 /* Move to the next entry */
131 if (NT_SUCCESS(Status
))
133 Filter
->SupportedContextsListHead
= Buffer
;
137 ExFreePoolWithTag(Buffer
, FM_TAG_CONTEXT_REGISTA
);
138 //FIXME: Cleanup anything that SetupContextHeader may have allocated
145 /* PRIVATE FUNCTIONS ******************************************************/
149 IsContextTypeValid(_In_ FLT_CONTEXT_TYPE ContextType
)
153 case FLT_VOLUME_CONTEXT
:
154 case FLT_INSTANCE_CONTEXT
:
155 case FLT_FILE_CONTEXT
:
156 case FLT_STREAM_CONTEXT
:
157 case FLT_STREAMHANDLE_CONTEXT
:
158 case FLT_TRANSACTION_CONTEXT
:
167 SetupContextHeader(_In_ PFLT_FILTER Filter
,
168 _In_ PCFLT_CONTEXT_REGISTRATION ContextPtr
,
169 _Out_ PALLOCATE_CONTEXT_HEADER ContextHeader
)