mirror of
https://github.com/reactos/reactos.git
synced 2024-07-29 23:58:44 +00:00
89 lines
2.3 KiB
C
89 lines
2.3 KiB
C
/*
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
* PROJECT: ReactOS NDIS User I/O driver
|
|
* FILE: misc.c
|
|
* PURPOSE: Helper functions
|
|
* PROGRAMMERS: Cameron Gutman (cameron.gutman@reactos.org)
|
|
*/
|
|
|
|
#include "ndisuio.h"
|
|
|
|
#define NDEBUG
|
|
#include <debug.h>
|
|
|
|
PNDISUIO_ADAPTER_CONTEXT
|
|
FindAdapterContextByName(PNDIS_STRING DeviceName)
|
|
{
|
|
KIRQL OldIrql;
|
|
PLIST_ENTRY CurrentEntry;
|
|
PNDISUIO_ADAPTER_CONTEXT AdapterContext;
|
|
|
|
KeAcquireSpinLock(&GlobalAdapterListLock, &OldIrql);
|
|
CurrentEntry = GlobalAdapterList.Flink;
|
|
while (CurrentEntry != &GlobalAdapterList)
|
|
{
|
|
AdapterContext = CONTAINING_RECORD(CurrentEntry, NDISUIO_ADAPTER_CONTEXT, ListEntry);
|
|
|
|
/* Check if the device name matches */
|
|
if (RtlEqualUnicodeString(&AdapterContext->DeviceName, DeviceName, TRUE))
|
|
{
|
|
KeReleaseSpinLock(&GlobalAdapterListLock, OldIrql);
|
|
return AdapterContext;
|
|
}
|
|
|
|
CurrentEntry = CurrentEntry->Flink;
|
|
}
|
|
KeReleaseSpinLock(&GlobalAdapterListLock, OldIrql);
|
|
|
|
return NULL;
|
|
}
|
|
|
|
VOID
|
|
ReferenceAdapterContext(PNDISUIO_ADAPTER_CONTEXT AdapterContext)
|
|
{
|
|
/* Increment the open count */
|
|
AdapterContext->OpenCount++;
|
|
}
|
|
|
|
VOID
|
|
DereferenceAdapterContextWithOpenEntry(PNDISUIO_ADAPTER_CONTEXT AdapterContext,
|
|
PNDISUIO_OPEN_ENTRY OpenEntry)
|
|
{
|
|
KIRQL OldIrql;
|
|
|
|
/* Lock the adapter context */
|
|
KeAcquireSpinLock(&AdapterContext->Spinlock, &OldIrql);
|
|
|
|
/* Decrement the open count */
|
|
AdapterContext->OpenCount--;
|
|
|
|
/* Cleanup the open entry if we were given one */
|
|
if (OpenEntry != NULL)
|
|
{
|
|
/* Remove the open entry */
|
|
RemoveEntryList(&OpenEntry->ListEntry);
|
|
|
|
/* Invalidate the FO */
|
|
OpenEntry->FileObject->FsContext = NULL;
|
|
OpenEntry->FileObject->FsContext2 = NULL;
|
|
|
|
/* Free the open entry */
|
|
ExFreePool(OpenEntry);
|
|
}
|
|
|
|
/* See if this binding can be destroyed */
|
|
if (AdapterContext->OpenCount == 0)
|
|
{
|
|
/* Unlock the context */
|
|
KeReleaseSpinLock(&AdapterContext->Spinlock, OldIrql);
|
|
|
|
/* Destroy the adapter context */
|
|
UnbindAdapterByContext(AdapterContext);
|
|
}
|
|
else
|
|
{
|
|
/* Still more references on it */
|
|
KeReleaseSpinLock(&AdapterContext->Spinlock, OldIrql);
|
|
}
|
|
}
|