Synchronize with trunk revision 59636 (just before Alex's CreateProcess revamp).
[reactos.git] / drivers / ksfilter / ks / deviceinterface.c
1 #include "priv.h"
2
3 NTSTATUS
4 KspSetDeviceInterfacesState(
5 IN PLIST_ENTRY ListHead,
6 IN BOOL Enable)
7 {
8 NTSTATUS Status = STATUS_SUCCESS;
9 PLIST_ENTRY Entry;
10 PSYMBOLIC_LINK_ENTRY SymEntry;
11
12
13 Entry = ListHead->Flink;
14 while(Entry != ListHead)
15 {
16 /* fetch symbolic link entry */
17 SymEntry = (PSYMBOLIC_LINK_ENTRY)CONTAINING_RECORD(Entry, SYMBOLIC_LINK_ENTRY, Entry);
18 /* set device interface state */
19 Status = IoSetDeviceInterfaceState(&SymEntry->SymbolicLink, Enable);
20
21 DPRINT("KspSetDeviceInterfacesState SymbolicLink '%S' Status %lx\n", SymEntry->SymbolicLink.Buffer, Status, Enable);
22
23 /* check for success */
24 if (!NT_SUCCESS(Status))
25 return Status;
26 /* get next entry */
27 Entry = Entry->Flink;
28 }
29 /* return result */
30 return Status;
31 }
32
33 NTSTATUS
34 KspFreeDeviceInterfaces(
35 IN PLIST_ENTRY ListHead)
36 {
37 PLIST_ENTRY Entry;
38 PSYMBOLIC_LINK_ENTRY SymEntry;
39
40 while(!IsListEmpty(ListHead))
41 {
42 /* remove first entry */
43 Entry = RemoveHeadList(ListHead);
44
45 /* fetch symbolic link entry */
46 SymEntry = (PSYMBOLIC_LINK_ENTRY)CONTAINING_RECORD(Entry, SYMBOLIC_LINK_ENTRY, Entry);
47
48 /* free device interface string */
49 RtlFreeUnicodeString(&SymEntry->SymbolicLink);
50 /* free entry item */
51 FreeItem(Entry);
52 }
53
54 return STATUS_SUCCESS;
55 }
56
57 NTSTATUS
58 KspRegisterDeviceInterfaces(
59 IN PDEVICE_OBJECT PhysicalDeviceObject,
60 IN ULONG CategoriesCount,
61 IN GUID const*Categories,
62 IN PUNICODE_STRING ReferenceString,
63 OUT PLIST_ENTRY SymbolicLinkList)
64 {
65 ULONG Index;
66 NTSTATUS Status = STATUS_SUCCESS;
67 PSYMBOLIC_LINK_ENTRY SymEntry;
68
69 for(Index = 0; Index < CategoriesCount; Index++)
70 {
71 /* allocate a symbolic link entry */
72 SymEntry = AllocateItem(NonPagedPool, sizeof(SYMBOLIC_LINK_ENTRY));
73 /* check for success */
74 if (!SymEntry)
75 return STATUS_INSUFFICIENT_RESOURCES;
76
77 /* now register device interface */
78 Status = IoRegisterDeviceInterface(PhysicalDeviceObject,
79 &Categories[Index],
80 ReferenceString,
81 &SymEntry->SymbolicLink);
82
83 if (!NT_SUCCESS(Status))
84 {
85 DPRINT1("Failed to register device interface %x\n", Status);
86
87 /* free entry */
88 FreeItem(SymEntry);
89
90 /* return result */
91 return Status;
92 }
93
94 /* copy device class */
95 RtlMoveMemory(&SymEntry->DeviceInterfaceClass, &Categories[Index], sizeof(CLSID));
96
97 /* insert symbolic link entry */
98 InsertTailList(SymbolicLinkList, &SymEntry->Entry);
99 }
100
101 /* return result */
102 return Status;
103 }
104
105 NTSTATUS
106 KspSetFilterFactoriesState(
107 IN PKSIDEVICE_HEADER DeviceHeader,
108 IN BOOLEAN NewState)
109 {
110 PCREATE_ITEM_ENTRY CreateEntry;
111 PLIST_ENTRY Entry;
112 NTSTATUS Status = STATUS_SUCCESS;
113
114 /* grab first device interface */
115 Entry = DeviceHeader->ItemList.Flink;
116 while(Entry != &DeviceHeader->ItemList && Status == STATUS_SUCCESS)
117 {
118 /* grab create entry */
119 CreateEntry = CONTAINING_RECORD(Entry, CREATE_ITEM_ENTRY, Entry);
120
121 /* sanity check */
122 ASSERT(CreateEntry->CreateItem);
123
124 if (CreateEntry->CreateItem->Create == IKsFilterFactory_Create)
125 {
126 /* found our own filterfactory */
127 Status = KsFilterFactorySetDeviceClassesState((PKSFILTERFACTORY)CreateEntry->CreateItem->Context, NewState);
128 }
129
130 Entry = Entry->Flink;
131 }
132
133 /* store result */
134 return Status;
135 }