IN KSDEVICE_HEADER DevHeader,
IN BOOLEAN Exclusive)
{
- NTSTATUS Status;
PKSIDEVICE_HEADER Header = (PKSIDEVICE_HEADER)DevHeader;
KeEnterCriticalRegion();
if (Exclusive)
{
- Status = ExAcquireResourceExclusiveLite(&Header->SecurityLock, TRUE);
+ ExAcquireResourceExclusiveLite(&Header->SecurityLock, TRUE);
}
else
{
- Status = ExAcquireResourceSharedLite(&Header->SecurityLock, TRUE);
+ ExAcquireResourceSharedLite(&Header->SecurityLock, TRUE);
}
}
PDEVICE_EXTENSION DeviceExtension;
PKSIDEVICE_HEADER DeviceHeader;
PKSIOBJECT_HEADER ObjectHeader;
- PIO_STACK_LOCATION IoStack;
+ //PIO_STACK_LOCATION IoStack;
PLIST_ENTRY ListEntry;
NTSTATUS Status;
/* get current irp stack */
- IoStack = IoGetCurrentIrpStackLocation(Irp);
+ //IoStack = IoGetCurrentIrpStackLocation(Irp);
/* caller wants to add the target device */
DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
{
PDEVICE_EXTENSION DeviceExtension;
PKSIDEVICE_HEADER DeviceHeader;
- PIO_STACK_LOCATION IoStack;
+ //PIO_STACK_LOCATION IoStack;
NTSTATUS Status;
/* get current irp stack */
- IoStack = IoGetCurrentIrpStackLocation(Irp);
+ //IoStack = IoGetCurrentIrpStackLocation(Irp);
/* caller wants to add the target device */
DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
IN KSDISPATCH_TABLE* Table)
{
PIO_STACK_LOCATION IoStack;
- PDEVICE_EXTENSION DeviceExtension;
- PKSIDEVICE_HEADER DeviceHeader;
+ //PDEVICE_EXTENSION DeviceExtension;
+ //PKSIDEVICE_HEADER DeviceHeader;
PKSIOBJECT_HEADER ObjectHeader;
- PKSOBJECT_CREATE_ITEM CreateItem;
+ //PKSOBJECT_CREATE_ITEM CreateItem;
NTSTATUS Status;
if (!Header)
/* get current stack location */
IoStack = IoGetCurrentIrpStackLocation(Irp);
/* get device extension */
- DeviceExtension = (PDEVICE_EXTENSION)IoStack->DeviceObject->DeviceExtension;
+ //DeviceExtension = (PDEVICE_EXTENSION)IoStack->DeviceObject->DeviceExtension;
/* get device header */
- DeviceHeader = DeviceExtension->DeviceHeader;
+ //DeviceHeader = DeviceExtension->DeviceHeader;
/* sanity check */
ASSERT(IoStack->FileObject);
InitializeListHead(&ObjectHeader->ItemList);
/* get create item */
- CreateItem = KSCREATE_ITEM_IRP_STORAGE(Irp);
+ //CreateItem = KSCREATE_ITEM_IRP_STORAGE(Irp);
/* do we have a name */
if (IoStack->FileObject->FileName.Buffer)
/* set counter */
Count = AutomationTableA->MethodSetsCount;
- /* now copy entries which arent available in the dominant table */
+ /* now copy entries which aren't available in the dominant table */
for(Index = 0; Index < AutomationTableB->MethodSetsCount; Index++)
{
/* set found to false */
return STATUS_SUCCESS;
}
+VOID
+KspAddPropertyItem(
+ OUT PKSPROPERTY_SET OutPropertySet,
+ IN PKSPROPERTY_ITEM PropertyItem,
+ IN ULONG PropertyItemSize)
+{
+ PKSPROPERTY_ITEM CurrentPropertyItem;
+ ULONG Index;
+
+ // check if the property item is already present
+ CurrentPropertyItem = (PKSPROPERTY_ITEM)OutPropertySet->PropertyItem;
+ for(Index = 0; Index < OutPropertySet->PropertiesCount; Index++)
+ {
+ if (CurrentPropertyItem->PropertyId == PropertyItem->PropertyId)
+ {
+ // item already present
+ return;
+ }
+
+ // next item
+ CurrentPropertyItem = (PKSPROPERTY_ITEM)((ULONG_PTR)CurrentPropertyItem + PropertyItemSize);
+ }
+ // add item
+ RtlCopyMemory(CurrentPropertyItem, PropertyItem, PropertyItemSize);
+ OutPropertySet->PropertiesCount++;
+}
+
+NTSTATUS
+KspMergePropertySet(
+ OUT PKSAUTOMATION_TABLE Table,
+ OUT PKSPROPERTY_SET OutPropertySet,
+ IN PKSPROPERTY_SET PropertySetA,
+ IN PKSPROPERTY_SET PropertySetB,
+ IN KSOBJECT_BAG Bag OPTIONAL)
+{
+ ULONG PropertyCount, Index;
+ PKSPROPERTY_ITEM PropertyItem, CurrentPropertyItem;
+ NTSTATUS Status;
+
+ // max properties
+ PropertyCount = PropertySetA->PropertiesCount + PropertySetB->PropertiesCount;
+
+ // allocate items
+ PropertyItem = AllocateItem(NonPagedPool, Table->PropertyItemSize * PropertyCount);
+ if (!PropertyItem)
+ return STATUS_INSUFFICIENT_RESOURCES;
+
+ if (Bag)
+ {
+ /* add table to object bag */
+ Status = KsAddItemToObjectBag(Bag, PropertyItem, NULL);
+ /* check for success */
+ if (!NT_SUCCESS(Status))
+ {
+ /* free table */
+ FreeItem(Table);
+ return Status;
+ }
+ }
+
+ // copy entries from dominant table
+ RtlCopyMemory(PropertyItem, PropertySetA->PropertyItem, Table->PropertyItemSize * PropertySetA->PropertiesCount);
+
+ // init property set
+ OutPropertySet->PropertiesCount = PropertySetA->PropertiesCount;
+ OutPropertySet->PropertyItem = PropertyItem;
+
+ // copy other entries
+ CurrentPropertyItem = (PKSPROPERTY_ITEM)PropertySetB->PropertyItem;
+ for(Index = 0; Index < PropertySetB->PropertiesCount; Index++)
+ {
+
+ // add entries
+ KspAddPropertyItem(OutPropertySet, CurrentPropertyItem, Table->PropertyItemSize);
+
+ // next entry
+ CurrentPropertyItem = (PKSPROPERTY_ITEM)((ULONG_PTR)CurrentPropertyItem + Table->PropertyItemSize);
+ }
+
+ // done
+ return STATUS_SUCCESS;
+}
+
NTSTATUS
KspCopyPropertySets(
OUT PKSAUTOMATION_TABLE Table,
IN PKSAUTOMATION_TABLE AutomationTableA OPTIONAL,
- IN PKSAUTOMATION_TABLE AutomationTableB OPTIONAL)
+ IN PKSAUTOMATION_TABLE AutomationTableB OPTIONAL,
+ IN KSOBJECT_BAG Bag OPTIONAL)
{
ULONG Index, SubIndex, Count;
BOOL bFound;
+ NTSTATUS Status;
if (!AutomationTableA)
{
/* set counter */
Count = AutomationTableA->PropertySetsCount;
- /* now copy entries which arent available in the dominant table */
+ /* now copy entries which aren't available in the dominant table */
for(Index = 0; Index < AutomationTableB->PropertySetsCount; Index++)
{
/* set found to false */
RtlMoveMemory((PVOID)&Table->PropertySets[Count], &AutomationTableB->PropertySets[Index], sizeof(KSPROPERTY_SET));
Count++;
}
+ else
+ {
+ // merge property sets
+ Status = KspMergePropertySet(Table, (PKSPROPERTY_SET)&Table->PropertySets[SubIndex], (PKSPROPERTY_SET)&AutomationTableA->PropertySets[SubIndex], (PKSPROPERTY_SET)&AutomationTableB->PropertySets[Index], Bag);
+ if (!NT_SUCCESS(Status))
+ {
+ // failed to merge
+ DPRINT1("[KS] Failed to merge %x\n", Status);
+ return Status;
+ }
+ }
}
return STATUS_SUCCESS;
/* set counter */
Count = AutomationTableA->EventSetsCount;
- /* now copy entries which arent available in the dominant table */
+ /* now copy entries which aren't available in the dominant table */
for(Index = 0; Index < AutomationTableB->EventSetsCount; Index++)
{
/* set found to false */
Table->PropertyItemSize = AutomationTableB->PropertyItemSize;
}
+ if (AutomationTableA && AutomationTableB)
+ {
+ // FIXME handle different propery item sizes
+ ASSERT(AutomationTableA->PropertyItemSize == AutomationTableB->PropertyItemSize);
+ }
+
/* now allocate the property sets */
Table->PropertySets = AllocateItem(NonPagedPool, sizeof(KSPROPERTY_SET) * Table->PropertySetsCount);
}
}
/* now copy the property sets */
- Status = KspCopyPropertySets(Table, AutomationTableA, AutomationTableB);
+ Status = KspCopyPropertySets(Table, AutomationTableA, AutomationTableB, Bag);
if(!NT_SUCCESS(Status))
goto cleanup;