2 * PROJECT: Filesystem Filter Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/filters/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 ******************************************************************/
15 #include "fltmgrint.h"
21 /* DATA *********************************************************************/
25 /* EXPORTED FUNCTIONS ******************************************************/
30 FltObjectReference(_Inout_ PVOID Object
)
32 if (!FltpExAcquireRundownProtection(&((PFLT_OBJECT
)Object
)->RundownRef
))
34 return STATUS_FLT_DELETING_OBJECT
;
37 return STATUS_SUCCESS
;
42 FltObjectDereference(_Inout_ PVOID Object
)
44 FltpExReleaseRundownProtection(&((PFLT_OBJECT
)Object
)->RundownRef
);
49 /* INTERNAL FUNCTIONS ******************************************************/
52 FltpExInitializeRundownProtection(_Out_ PEX_RUNDOWN_REF RundownRef
)
54 ExInitializeRundownProtection(RundownRef
);
58 FltpExAcquireRundownProtection(_Inout_ PEX_RUNDOWN_REF RundownRef
)
60 return ExAcquireRundownProtection(RundownRef
);
64 FltpExReleaseRundownProtection(_Inout_ PEX_RUNDOWN_REF RundownRef
)
66 ExReleaseRundownProtection(RundownRef
);
71 FltpExRundownCompleted(_Inout_ PEX_RUNDOWN_REF RundownRef
)
73 return _InterlockedExchange((PLONG
)RundownRef
, 1);
78 FltpObjectRundownWait(_Inout_ PEX_RUNDOWN_REF RundownRef
)
80 //return FltpExWaitForRundownProtectionRelease(RundownRef);
85 FltpGetBaseDeviceObjectName(_In_ PDEVICE_OBJECT DeviceObject
,
86 _Inout_ PUNICODE_STRING ObjectName
)
88 PDEVICE_OBJECT BaseDeviceObject
;
92 * Get the lowest device object on the stack, which may be the
93 * object we were passed, and lookup the name for that object
95 BaseDeviceObject
= IoGetDeviceAttachmentBaseRef(DeviceObject
);
96 Status
= FltpGetObjectName(BaseDeviceObject
, ObjectName
);
97 ObDereferenceObject(BaseDeviceObject
);
103 FltpGetObjectName(_In_ PVOID Object
,
104 _Inout_ PUNICODE_STRING ObjectName
)
106 POBJECT_NAME_INFORMATION ObjectNameInfo
= NULL
;
107 OBJECT_NAME_INFORMATION LocalNameInfo
;
111 if (ObjectName
== NULL
)
112 return STATUS_INVALID_PARAMETER
;
114 /* Get the size of the buffer required to hold the nameinfo */
115 Status
= ObQueryNameString(Object
,
117 sizeof(LocalNameInfo
),
119 if (Status
== STATUS_INFO_LENGTH_MISMATCH
)
121 ObjectNameInfo
= ExAllocatePoolWithTag(PagedPool
,
123 FM_TAG_UNICODE_STRING
);
124 if (ObjectNameInfo
== NULL
) return STATUS_INSUFFICIENT_RESOURCES
;
126 /* Get the actual name info now we have the buffer to hold it */
127 Status
= ObQueryNameString(Object
,
134 if (NT_SUCCESS(Status
))
136 /* Make sure the buffer we were passed is large enough to hold the string */
137 if (ObjectName
->MaximumLength
< ObjectNameInfo
->Name
.Length
)
139 /* It wasn't, let's enlarge the buffer */
140 Status
= FltpReallocateUnicodeString(ObjectName
,
141 ObjectNameInfo
->Name
.Length
,
146 if (NT_SUCCESS(Status
))
148 /* Copy the object name into the callers buffer */
149 RtlCopyUnicodeString(ObjectName
, &ObjectNameInfo
->Name
);
155 ExFreePoolWithTag(ObjectNameInfo
, FM_TAG_UNICODE_STRING
);