2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS NDIS User I/O driver
5 * PURPOSE: Helper functions
6 * PROGRAMMERS: Cameron Gutman (cameron.gutman@reactos.org)
14 PNDISUIO_ADAPTER_CONTEXT
15 FindAdapterContextByName(PNDIS_STRING DeviceName
)
18 PLIST_ENTRY CurrentEntry
;
19 PNDISUIO_ADAPTER_CONTEXT AdapterContext
;
21 KeAcquireSpinLock(&GlobalAdapterListLock
, &OldIrql
);
22 CurrentEntry
= GlobalAdapterList
.Flink
;
23 while (CurrentEntry
!= &GlobalAdapterList
)
25 AdapterContext
= CONTAINING_RECORD(CurrentEntry
, NDISUIO_ADAPTER_CONTEXT
, ListEntry
);
27 /* Check if the device name matches */
28 if (RtlEqualUnicodeString(&AdapterContext
->DeviceName
, DeviceName
, TRUE
))
30 KeReleaseSpinLock(&GlobalAdapterListLock
, OldIrql
);
31 return AdapterContext
;
34 CurrentEntry
= CurrentEntry
->Flink
;
36 KeReleaseSpinLock(&GlobalAdapterListLock
, OldIrql
);
42 ReferenceAdapterContext(PNDISUIO_ADAPTER_CONTEXT AdapterContext
)
44 /* Increment the open count */
45 AdapterContext
->OpenCount
++;
49 DereferenceAdapterContextWithOpenEntry(PNDISUIO_ADAPTER_CONTEXT AdapterContext
,
50 PNDISUIO_OPEN_ENTRY OpenEntry
)
54 /* Lock the adapter context */
55 KeAcquireSpinLock(&AdapterContext
->Spinlock
, &OldIrql
);
57 /* Decrement the open count */
58 AdapterContext
->OpenCount
--;
60 /* Cleanup the open entry if we were given one */
61 if (OpenEntry
!= NULL
)
63 /* Remove the open entry */
64 RemoveEntryList(&OpenEntry
->ListEntry
);
66 /* Invalidate the FO */
67 OpenEntry
->FileObject
->FsContext
= NULL
;
68 OpenEntry
->FileObject
->FsContext2
= NULL
;
70 /* Free the open entry */
71 ExFreePool(OpenEntry
);
74 /* See if this binding can be destroyed */
75 if (AdapterContext
->OpenCount
== 0)
77 /* Unlock the context */
78 KeReleaseSpinLock(&AdapterContext
->Spinlock
, OldIrql
);
80 /* Destroy the adapter context */
81 UnbindAdapterByContext(AdapterContext
);
85 /* Still more references on it */
86 KeReleaseSpinLock(&AdapterContext
->Spinlock
, OldIrql
);