2 * PROJECT: Filesystem Filter Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/fs_minifilter/fltmgr/Object.c
5 * PURPOSE: Miscellaneous library functions
6 * PROGRAMMERS: Ged Murphy (gedmurphy@reactos.org)
9 // NOTE: Split this file into filter object and device object functions
10 // when the code base grows sufficiently
12 /* INCLUDES ******************************************************************/
20 /* DATA *********************************************************************/
24 /* EXPORTED FUNCTIONS ******************************************************/
29 FltObjectReference(_Inout_ PFLT_OBJECT Object
)
31 if (!FltpExAcquireRundownProtection(&Object
->RundownRef
))
33 return STATUS_FLT_DELETING_OBJECT
;
36 return STATUS_SUCCESS
;
41 FltObjectDereference(_Inout_ PFLT_OBJECT Object
)
43 return FltpExReleaseRundownProtection(&Object
->RundownRef
);
48 /* INTERNAL FUNCTIONS ******************************************************/
51 FltpExInitializeRundownProtection(_Out_ PEX_RUNDOWN_REF RundownRef
)
53 ExInitializeRundownProtection(RundownRef
);
57 FltpExAcquireRundownProtection(_Inout_ PEX_RUNDOWN_REF RundownRef
)
59 return ExAcquireRundownProtection(RundownRef
);
63 FltpExReleaseRundownProtection(_Inout_ PEX_RUNDOWN_REF RundownRef
)
65 ExReleaseRundownProtection(RundownRef
);
70 FltpExRundownCompleted(_Inout_ PEX_RUNDOWN_REF RundownRef
)
72 return _InterlockedExchange((PLONG
)RundownRef
, 1);
77 FltpObjectRundownWait(_Inout_ PEX_RUNDOWN_REF RundownRef
)
79 //return FltpExWaitForRundownProtectionRelease(RundownRef);
84 FltpGetBaseDeviceObjectName(_In_ PDEVICE_OBJECT DeviceObject
,
85 _Inout_ PUNICODE_STRING ObjectName
)
87 PDEVICE_OBJECT BaseDeviceObject
;
91 * Get the lowest device object on the stack, which may be the
92 * object we were passed, and lookup the name for that object
94 BaseDeviceObject
= IoGetDeviceAttachmentBaseRef(DeviceObject
);
95 Status
= FltpGetObjectName(BaseDeviceObject
, ObjectName
);
96 ObDereferenceObject(BaseDeviceObject
);
102 FltpGetObjectName(_In_ PVOID Object
,
103 _Inout_ PUNICODE_STRING ObjectName
)
105 POBJECT_NAME_INFORMATION ObjectNameInfo
= NULL
;
106 OBJECT_NAME_INFORMATION LocalNameInfo
;
110 if (ObjectName
== NULL
)
111 return STATUS_INVALID_PARAMETER
;
113 /* Get the size of the buffer required to hold the nameinfo */
114 Status
= ObQueryNameString(Object
,
116 sizeof(LocalNameInfo
),
118 if (Status
== STATUS_INFO_LENGTH_MISMATCH
)
120 ObjectNameInfo
= ExAllocatePoolWithTag(PagedPool
,
122 FM_TAG_UNICODE_STRING
);
123 if (ObjectNameInfo
== NULL
) return STATUS_INSUFFICIENT_RESOURCES
;
125 /* Get the actual name info now we have the buffer to hold it */
126 Status
= ObQueryNameString(Object
,
133 if (NT_SUCCESS(Status
))
135 /* Make sure the buffer we were passed is large enough to hold the string */
136 if (ObjectName
->MaximumLength
< ObjectNameInfo
->Name
.Length
)
138 /* It wasn't, let's enlarge the buffer */
139 Status
= FltpReallocateUnicodeString(ObjectName
,
140 ObjectNameInfo
->Name
.Length
,
145 if (NT_SUCCESS(Status
))
147 /* Copy the object name into the callers buffer */
148 RtlCopyUnicodeString(ObjectName
, &ObjectNameInfo
->Name
);
154 ExFreePoolWithTag(ObjectNameInfo
, FM_TAG_UNICODE_STRING
);