예제 #1
0
/*
 * @halfplemented
 */
VOID
NTAPI
IopDecrementDeviceObjectRef(IN PDEVICE_OBJECT DeviceObject,
                            IN BOOLEAN UnloadIfUnused)
{
    KIRQL OldIrql;

    /* Acquire lock */
    OldIrql = KeAcquireQueuedSpinLock(LockQueueIoDatabaseLock);
    ASSERT(DeviceObject->ReferenceCount > 0);

    if (--DeviceObject->ReferenceCount > 0)
    {
        KeReleaseQueuedSpinLock(LockQueueIoDatabaseLock, OldIrql);
        return;
    }

    /* Here, DO is not referenced any longer, check if we have to unload it */
    if (UnloadIfUnused || IoGetDevObjExtension(DeviceObject)->ExtensionFlags &
                          (DOE_UNLOAD_PENDING | DOE_DELETE_PENDING | DOE_REMOVE_PENDING))
    {
        /* Unload the driver */
        IopUnloadDevice(DeviceObject);
    }

    /* Release lock */
    KeReleaseQueuedSpinLock(LockQueueIoDatabaseLock, OldIrql);
}
예제 #2
0
PVPB
NTAPI
IopMountInitializeVpb(IN PDEVICE_OBJECT DeviceObject,
                      IN PDEVICE_OBJECT AttachedDeviceObject,
                      IN BOOLEAN Raw)
{
    KIRQL OldIrql;
    PVPB Vpb;

    /* Lock the VPBs */
    IoAcquireVpbSpinLock(&OldIrql);
    Vpb = DeviceObject->Vpb;

    /* Set the VPB as mounted and possibly raw */
    Vpb->Flags |= VPB_MOUNTED | (Raw ? VPB_RAW_MOUNT : 0);

    /* Set the stack size */
    Vpb->DeviceObject->StackSize = AttachedDeviceObject->StackSize;

    /* Add one for the FS Driver */
    Vpb->DeviceObject->StackSize++;

    /* Set the VPB in the device extension */
    IoGetDevObjExtension(Vpb->DeviceObject)->Vpb = Vpb;

    /* Reference it */
    Vpb->ReferenceCount++;

    /* Release the VPB lock and return it */
    IoReleaseVpbSpinLock(OldIrql);
    return Vpb;
}
예제 #3
0
        ObDereferenceObject(DeviceObject->DriverObject);
}


PDEVICE_OBJECT
NTAPI
IopAttachDeviceToDeviceStackSafe(IN PDEVICE_OBJECT SourceDevice,
                                 IN PDEVICE_OBJECT TargetDevice,
                                 OUT PDEVICE_OBJECT *AttachedToDeviceObject OPTIONAL)
{
    PDEVICE_OBJECT AttachedDevice;
    PEXTENDED_DEVOBJ_EXTENSION SourceDeviceExtension;

    /* Get the Attached Device and source extension */
    AttachedDevice = IoGetAttachedDevice(TargetDevice);
    SourceDeviceExtension = IoGetDevObjExtension(SourceDevice);
    ASSERT(SourceDeviceExtension->AttachedTo == NULL);

    /* Make sure that it's in a correct state */
    if ((AttachedDevice->Flags & DO_DEVICE_INITIALIZING) ||
        (IoGetDevObjExtension(AttachedDevice)->ExtensionFlags &
         (DOE_UNLOAD_PENDING |
          DOE_DELETE_PENDING |
          DOE_REMOVE_PENDING |
          DOE_REMOVE_PROCESSED)))
    {
        /* Device was unloading or being removed */
        AttachedDevice = NULL;
    }
    else
    {