00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
#include "FsRtlP.h"
00045
00046 #define MySearchList(pHdr, Ptr) \
00047
for ( Ptr = (pHdr)->Flink; Ptr != (pHdr); Ptr = Ptr->Flink )
00048
00049
00050
00051
00052
00053 #define Dbg (0x80000000)
00054
00055
00056
NTKERNELAPI
00057
NTSTATUS
00058 FsRtlInsertFilterContext (
00059 IN
PFILE_OBJECT FileObject,
00060 IN
PFSRTL_FILTER_CONTEXT Ptr
00061 )
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 {
00086
PFSRTL_COMMON_FCB_HEADER Header;
00087
00088
ASSERT(FileObject);
00089
ASSERT(FileObject->FsContext);
00090
00091
Header = FileObject->FsContext;
00092
00093
if (! (
Header->Flags2 &
FSRTL_FLAG2_SUPPORTS_FILTER_CONTEXTS) ) {
00094
return STATUS_INVALID_DEVICE_REQUEST;
00095 }
00096
00097 ExAcquireFastMutex (
Header->FastMutex);
00098
00099 InsertHeadList (&
Header->FilterContexts, &
Ptr->Links);
00100
00101 ExReleaseFastMutex(
Header->FastMutex);
00102
return STATUS_SUCCESS;
00103 }
00104
00105
00106
NTKERNELAPI
00107
PFSRTL_FILTER_CONTEXT
00108 FsRtlLookupFilterContextInternal (
00109 IN
PFILE_OBJECT FileObject,
00110 IN PVOID OwnerId OPTIONAL,
00111 IN PVOID InstanceId OPTIONAL
00112 )
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 {
00144
PFSRTL_COMMON_FCB_HEADER Header;
00145
PFSRTL_FILTER_CONTEXT Ctx, RtnCtx;
00146 PLIST_ENTRY
List;
00147
00148
ASSERT(FileObject);
00149
ASSERT(FileObject->FsContext);
00150
00151
Header = FileObject->FsContext;
00152
00153
ASSERT (
Header->Flags2 &
FSRTL_FLAG2_SUPPORTS_FILTER_CONTEXTS);
00154
00155 ExAcquireFastMutex (
Header->FastMutex);
00156 RtnCtx =
NULL;
00157
00158
00159
if ( ARGUMENT_PRESENT(InstanceId) ) {
00160
00161
MySearchList (&
Header->FilterContexts,
List) {
00162 Ctx = CONTAINING_RECORD (
List,
FSRTL_FILTER_CONTEXT, Links);
00163
if (Ctx->
OwnerId == OwnerId && Ctx->
InstanceId == InstanceId) {
00164 RtnCtx = Ctx;
00165
break;
00166 }
00167 }
00168 }
else if ( ARGUMENT_PRESENT(OwnerId) ) {
00169
00170
MySearchList (&
Header->FilterContexts,
List) {
00171 Ctx = CONTAINING_RECORD (
List,
FSRTL_FILTER_CONTEXT, Links);
00172
if (Ctx->
OwnerId == OwnerId) {
00173 RtnCtx = Ctx;
00174
break;
00175 }
00176 }
00177 }
else if (!IsListEmpty(&
Header->FilterContexts)) {
00178
00179 RtnCtx = (
PFSRTL_FILTER_CONTEXT)
Header->FilterContexts.Flink;
00180 }
00181
00182 ExReleaseFastMutex(
Header->FastMutex);
00183
return RtnCtx;
00184 }
00185
00186
00187
NTKERNELAPI
00188
PFSRTL_FILTER_CONTEXT
00189 FsRtlRemoveFilterContext (
00190 IN
PFILE_OBJECT FileObject,
00191 IN PVOID OwnerId OPTIONAL,
00192 IN PVOID InstanceId OPTIONAL
00193 )
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226 {
00227
PFSRTL_COMMON_FCB_HEADER Header;
00228
PFSRTL_FILTER_CONTEXT Ctx, RtnCtx;
00229 PLIST_ENTRY
List;
00230
00231
ASSERT(FileObject);
00232
00233
Header = FileObject->FsContext;
00234
00235
if ( !
Header || !(
Header->Flags2 &
FSRTL_FLAG2_SUPPORTS_FILTER_CONTEXTS) ) {
00236
return NULL;
00237 }
00238
00239 ExAcquireFastMutex (
Header->FastMutex);
00240 RtnCtx =
NULL;
00241
00242
00243
if ( ARGUMENT_PRESENT(InstanceId) ) {
00244
00245
MySearchList (&
Header->FilterContexts,
List) {
00246 Ctx = CONTAINING_RECORD (
List,
FSRTL_FILTER_CONTEXT, Links);
00247
if (Ctx->
OwnerId == OwnerId && Ctx->
InstanceId == InstanceId) {
00248 RtnCtx = Ctx;
00249
break;
00250 }
00251 }
00252 }
else if ( ARGUMENT_PRESENT(OwnerId) ) {
00253
00254
MySearchList (&
Header->FilterContexts,
List) {
00255 Ctx = CONTAINING_RECORD (
List,
FSRTL_FILTER_CONTEXT, Links);
00256
if (Ctx->
OwnerId == OwnerId) {
00257 RtnCtx = Ctx;
00258
break;
00259 }
00260 }
00261 }
else if (!IsListEmpty(&
Header->FilterContexts)) {
00262
00263 RtnCtx = (
PFSRTL_FILTER_CONTEXT)
Header->FilterContexts.Flink;
00264 }
00265
00266
if (RtnCtx) {
00267 RemoveEntryList(&RtnCtx->
Links);
00268 }
00269 ExReleaseFastMutex(
Header->FastMutex);
00270
return RtnCtx;
00271 }
00272
00273
00274
NTKERNELAPI
00275
VOID
00276 FsRtlTeardownFilterContexts (
00277 IN PLIST_ENTRY FilterContexts
00278 )
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301 {
00302
PFSRTL_FILTER_CONTEXT ctx;
00303 PLIST_ENTRY ptr;
00304
00305 ptr = FilterContexts->Flink;
00306
00307
while ( ptr != FilterContexts ) {
00308 ctx = CONTAINING_RECORD (ptr,
FSRTL_FILTER_CONTEXT, Links);
00309 ptr = ptr->Flink;
00310 (*ctx->
FreeCallback)(ctx);
00311 }
00312
00313 InitializeListHead( FilterContexts );
00314
return;
00315 }
00316