2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/io/device.c
5 * PURPOSE: Device Object Management, including Notifications and Queues.
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 * Filip Navara (navaraf@reactos.org)
8 * Hervé Poussineau (hpoussin@reactos.org)
11 /* INCLUDES *******************************************************************/
17 /* GLOBALS ********************************************************************/
19 ULONG IopDeviceObjectNumber
= 0;
20 LIST_ENTRY ShutdownListHead
, LastChanceShutdownListHead
;
21 KSPIN_LOCK ShutdownListLock
;
22 extern LIST_ENTRY IopDiskFileSystemQueueHead
;
23 extern LIST_ENTRY IopCdRomFileSystemQueueHead
;
24 extern LIST_ENTRY IopTapeFileSystemQueueHead
;
25 extern ERESOURCE IopDatabaseResource
;
27 /* PRIVATE FUNCTIONS **********************************************************/
31 IopReadyDeviceObjects(IN PDRIVER_OBJECT Driver
)
33 PDEVICE_OBJECT DeviceObject
;
36 /* Set the driver as initialized */
37 Driver
->Flags
|= DRVO_INITIALIZED
;
38 DeviceObject
= Driver
->DeviceObject
;
41 /* Set every device as initialized too */
42 DeviceObject
->Flags
&= ~DO_DEVICE_INITIALIZING
;
43 DeviceObject
= DeviceObject
->NextDevice
;
49 IopDeleteDevice(IN PVOID ObjectBody
)
51 PDEVICE_OBJECT DeviceObject
= ObjectBody
;
52 PDEVICE_NODE DeviceNode
= IopGetDeviceNode(DeviceObject
);
55 /* Cleanup and free the device node */
57 IopFreeDeviceNode(DeviceNode
);
59 /* Dereference the driver object, referenced in IoCreateDevice */
60 if (DeviceObject
->DriverObject
)
61 ObDereferenceObject(DeviceObject
->DriverObject
);
67 IopAttachDeviceToDeviceStackSafe(IN PDEVICE_OBJECT SourceDevice
,
68 IN PDEVICE_OBJECT TargetDevice
,
69 OUT PDEVICE_OBJECT
*AttachedToDeviceObject OPTIONAL
)
71 PDEVICE_OBJECT AttachedDevice
;
72 PEXTENDED_DEVOBJ_EXTENSION SourceDeviceExtension
;
74 /* Get the Attached Device and source extension */
75 AttachedDevice
= IoGetAttachedDevice(TargetDevice
);
76 SourceDeviceExtension
= IoGetDevObjExtension(SourceDevice
);
77 ASSERT(SourceDeviceExtension
->AttachedTo
== NULL
);
79 /* Make sure that it's in a correct state */
80 if ((AttachedDevice
->Flags
& DO_DEVICE_INITIALIZING
) ||
81 (IoGetDevObjExtension(AttachedDevice
)->ExtensionFlags
&
85 DOE_REMOVE_PROCESSED
)))
87 /* Device was unloading or being removed */
88 AttachedDevice
= NULL
;
92 /* Update atached device fields */
93 AttachedDevice
->AttachedDevice
= SourceDevice
;
94 AttachedDevice
->Spare1
++;
96 /* Update the source with the attached data */
97 SourceDevice
->StackSize
= AttachedDevice
->StackSize
+ 1;
98 SourceDevice
->AlignmentRequirement
= AttachedDevice
->
100 SourceDevice
->SectorSize
= AttachedDevice
->SectorSize
;
102 /* Check for pending start flag */
103 if (IoGetDevObjExtension(AttachedDevice
)->ExtensionFlags
&
107 IoGetDevObjExtension(SourceDevice
)->ExtensionFlags
|=
111 /* Set the attachment in the device extension */
112 SourceDeviceExtension
->AttachedTo
= AttachedDevice
;
115 /* Return the attached device */
116 if (AttachedToDeviceObject
) *AttachedToDeviceObject
= AttachedDevice
;
117 return AttachedDevice
;
122 IoShutdownPnpDevices(VOID
)
124 /* This routine is only used by Driver Verifier to validate shutdown */
130 IoShutdownSystem(IN ULONG Phase
)
132 PLIST_ENTRY ListEntry
;
133 PDEVICE_OBJECT DeviceObject
;
134 PSHUTDOWN_ENTRY ShutdownEntry
;
135 IO_STATUS_BLOCK StatusBlock
;
140 /* Initialize an event to wait on */
141 KeInitializeEvent(&Event
, NotificationEvent
, FALSE
);
147 IoShutdownPnpDevices();
149 /* Loop first-chance shutdown notifications */
150 ListEntry
= ExInterlockedRemoveHeadList(&ShutdownListHead
,
154 /* Get the shutdown entry */
155 ShutdownEntry
= CONTAINING_RECORD(ListEntry
,
159 /* Get the attached device */
160 DeviceObject
= IoGetAttachedDevice(ShutdownEntry
->DeviceObject
);
162 /* Build the shutdown IRP and call the driver */
163 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_SHUTDOWN
,
172 Status
= IoCallDriver(DeviceObject
, Irp
);
173 if (Status
== STATUS_PENDING
)
175 /* Wait on the driver */
176 KeWaitForSingleObject(&Event
, Executive
, KernelMode
, FALSE
, NULL
);
180 /* Remove the flag */
181 ShutdownEntry
->DeviceObject
->Flags
&= ~DO_SHUTDOWN_REGISTERED
;
183 /* Get rid of our reference to it */
184 ObDereferenceObject(ShutdownEntry
->DeviceObject
);
186 /* Free the shutdown entry and reset the event */
187 ExFreePoolWithTag(ShutdownEntry
, TAG_SHUTDOWN_ENTRY
);
188 KeClearEvent(&Event
);
190 /* Go to the next entry */
191 ListEntry
= ExInterlockedRemoveHeadList(&ShutdownListHead
,
197 /* Acquire resource forever */
198 ExAcquireResourceExclusiveLite(&IopDatabaseResource
, TRUE
);
200 /* Shutdown disk file systems */
201 IopShutdownBaseFileSystems(&IopDiskFileSystemQueueHead
);
203 /* Shutdown cdrom file systems */
204 IopShutdownBaseFileSystems(&IopCdRomFileSystemQueueHead
);
206 /* Shutdown tape filesystems */
207 IopShutdownBaseFileSystems(&IopTapeFileSystemQueueHead
);
209 /* Loop last-chance shutdown notifications */
210 ListEntry
= ExInterlockedRemoveHeadList(&LastChanceShutdownListHead
,
214 /* Get the shutdown entry */
215 ShutdownEntry
= CONTAINING_RECORD(ListEntry
,
219 /* Get the attached device */
220 DeviceObject
= IoGetAttachedDevice(ShutdownEntry
->DeviceObject
);
222 /* Build the shutdown IRP and call the driver */
223 Irp
= IoBuildSynchronousFsdRequest(IRP_MJ_SHUTDOWN
,
232 Status
= IoCallDriver(DeviceObject
, Irp
);
233 if (Status
== STATUS_PENDING
)
235 /* Wait on the driver */
236 KeWaitForSingleObject(&Event
, Executive
, KernelMode
, FALSE
, NULL
);
240 /* Remove the flag */
241 ShutdownEntry
->DeviceObject
->Flags
&= ~DO_SHUTDOWN_REGISTERED
;
243 /* Get rid of our reference to it */
244 ObDereferenceObject(ShutdownEntry
->DeviceObject
);
246 /* Free the shutdown entry and reset the event */
247 ExFreePoolWithTag(ShutdownEntry
, TAG_SHUTDOWN_ENTRY
);
248 KeClearEvent(&Event
);
250 /* Go to the next entry */
251 ListEntry
= ExInterlockedRemoveHeadList(&LastChanceShutdownListHead
,
260 IopGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName
,
261 IN ACCESS_MASK DesiredAccess
,
262 OUT PFILE_OBJECT
*FileObject
,
263 OUT PDEVICE_OBJECT
*DeviceObject
,
266 OBJECT_ATTRIBUTES ObjectAttributes
;
267 IO_STATUS_BLOCK StatusBlock
;
268 PFILE_OBJECT LocalFileObject
;
272 /* Open the Device */
273 InitializeObjectAttributes(&ObjectAttributes
,
278 Status
= ZwOpenFile(&FileHandle
,
283 FILE_NON_DIRECTORY_FILE
| AttachFlag
);
284 if (!NT_SUCCESS(Status
)) return Status
;
286 /* Get File Object */
287 Status
= ObReferenceObjectByHandle(FileHandle
,
291 (PVOID
*)&LocalFileObject
,
293 if (NT_SUCCESS(Status
))
295 /* Return the requested data */
296 *DeviceObject
= IoGetRelatedDeviceObject(LocalFileObject
);
297 *FileObject
= LocalFileObject
;
300 /* Close the handle */
308 IopGetLowestDevice(IN PDEVICE_OBJECT DeviceObject
)
310 PDEVICE_OBJECT LowestDevice
;
311 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension
;
313 /* Get the current device and its extension */
314 LowestDevice
= DeviceObject
;
315 DeviceExtension
= IoGetDevObjExtension(LowestDevice
);
317 /* Keep looping as long as we're attached */
318 while (DeviceExtension
->AttachedTo
)
320 /* Get the lowest device and its extension */
321 LowestDevice
= DeviceExtension
->AttachedTo
;
322 DeviceExtension
= IoGetDevObjExtension(LowestDevice
);
325 /* Return the lowest device */
331 IopEditDeviceList(IN PDRIVER_OBJECT DriverObject
,
332 IN PDEVICE_OBJECT DeviceObject
,
333 IN IOP_DEVICE_LIST_OPERATION Type
)
335 PDEVICE_OBJECT Previous
;
337 /* Check the type of operation */
338 if (Type
== IopRemove
)
340 /* Get the current device and check if it's the current one */
341 Previous
= DeviceObject
->DriverObject
->DeviceObject
;
342 if (Previous
== DeviceObject
)
344 /* It is, simply unlink this one directly */
345 DeviceObject
->DriverObject
->DeviceObject
=
346 DeviceObject
->NextDevice
;
350 /* It's not, so loop until we find the device */
351 while (Previous
->NextDevice
!= DeviceObject
)
353 /* Not this one, keep moving */
354 Previous
= Previous
->NextDevice
;
357 /* We found it, now unlink us */
358 Previous
->NextDevice
= DeviceObject
->NextDevice
;
363 /* Link the device object and the driver object */
364 DeviceObject
->NextDevice
= DriverObject
->DeviceObject
;
365 DriverObject
->DeviceObject
= DeviceObject
;
371 IopUnloadDevice(IN PDEVICE_OBJECT DeviceObject
)
373 PDRIVER_OBJECT DriverObject
= DeviceObject
->DriverObject
;
374 PEXTENDED_DEVOBJ_EXTENSION ThisExtension
= IoGetDevObjExtension(DeviceObject
);
376 /* Check if deletion is pending */
377 if (ThisExtension
->ExtensionFlags
& DOE_DELETE_PENDING
)
379 if (DeviceObject
->AttachedDevice
)
381 DPRINT("Device object is in the middle of a device stack\n");
385 if (DeviceObject
->ReferenceCount
)
387 DPRINT("Device object still has %d references\n", DeviceObject
->ReferenceCount
);
391 /* Check if we have a Security Descriptor */
392 if (DeviceObject
->SecurityDescriptor
)
395 ExFreePoolWithTag(DeviceObject
->SecurityDescriptor
, TAG_SD
);
398 /* Remove the device from the list */
399 IopEditDeviceList(DeviceObject
->DriverObject
, DeviceObject
, IopRemove
);
401 /* Dereference the keep-alive */
402 ObDereferenceObject(DeviceObject
);
405 /* We can't unload a non-PnP driver here */
406 if (DriverObject
->Flags
& DRVO_LEGACY_DRIVER
)
408 DPRINT("Not a PnP driver! '%wZ' will not be unloaded!\n", &DriverObject
->DriverName
);
412 /* Return if we've already called unload (maybe we're in it?) */
413 if (DriverObject
->Flags
& DRVO_UNLOAD_INVOKED
) return;
415 /* We can't unload unless there's an unload handler */
416 if (!DriverObject
->DriverUnload
)
418 DPRINT1("No DriverUnload function on PnP driver! '%wZ' will not be unloaded!\n", &DriverObject
->DriverName
);
422 /* Bail if there are still devices present */
423 if (DriverObject
->DeviceObject
)
425 DPRINT("Devices still present! '%wZ' will not be unloaded!\n", &DriverObject
->DriverName
);
429 DPRINT1("Unloading driver '%wZ' (automatic)\n", &DriverObject
->DriverName
);
431 /* Set the unload invoked flag */
432 DriverObject
->Flags
|= DRVO_UNLOAD_INVOKED
;
435 DriverObject
->DriverUnload(DriverObject
);
437 /* Make object temporary so it can be deleted */
438 ObMakeTemporaryObject(DriverObject
);
443 IopDereferenceDeviceObject(IN PDEVICE_OBJECT DeviceObject
,
444 IN BOOLEAN ForceUnload
)
447 ASSERT(DeviceObject
->ReferenceCount
);
449 /* Dereference the device */
450 InterlockedDecrement(&DeviceObject
->ReferenceCount
);
453 * Check if we can unload it and it's safe to unload (or if we're forcing
454 * an unload, which is OK too).
456 ASSERT(!ForceUnload
);
457 if (!(DeviceObject
->ReferenceCount
) &&
458 (IoGetDevObjExtension(DeviceObject
)->ExtensionFlags
& DOE_DELETE_PENDING
))
461 IopUnloadDevice(DeviceObject
);
467 IopStartNextPacketByKey(IN PDEVICE_OBJECT DeviceObject
,
468 IN BOOLEAN Cancelable
,
471 PKDEVICE_QUEUE_ENTRY Entry
;
475 /* Acquire the cancel lock if this is cancelable */
476 if (Cancelable
) IoAcquireCancelSpinLock(&OldIrql
);
478 /* Clear the current IRP */
479 DeviceObject
->CurrentIrp
= NULL
;
481 /* Remove an entry from the queue */
482 Entry
= KeRemoveByKeyDeviceQueue(&DeviceObject
->DeviceQueue
, Key
);
485 /* Get the IRP and set it */
486 Irp
= CONTAINING_RECORD(Entry
, IRP
, Tail
.Overlay
.DeviceQueueEntry
);
487 DeviceObject
->CurrentIrp
= Irp
;
489 /* Check if this is a cancelable packet */
492 /* Check if the caller requested no cancellation */
493 if (IoGetDevObjExtension(DeviceObject
)->StartIoFlags
&
496 /* He did, so remove the cancel routine */
497 Irp
->CancelRoutine
= NULL
;
500 /* Release the cancel lock */
501 IoReleaseCancelSpinLock(OldIrql
);
504 /* Call the Start I/O Routine */
505 DeviceObject
->DriverObject
->DriverStartIo(DeviceObject
, Irp
);
509 /* Otherwise, release the cancel lock if we had acquired it */
510 if (Cancelable
) IoReleaseCancelSpinLock(OldIrql
);
516 IopStartNextPacket(IN PDEVICE_OBJECT DeviceObject
,
517 IN BOOLEAN Cancelable
)
519 PKDEVICE_QUEUE_ENTRY Entry
;
523 /* Acquire the cancel lock if this is cancelable */
524 if (Cancelable
) IoAcquireCancelSpinLock(&OldIrql
);
526 /* Clear the current IRP */
527 DeviceObject
->CurrentIrp
= NULL
;
529 /* Remove an entry from the queue */
530 Entry
= KeRemoveDeviceQueue(&DeviceObject
->DeviceQueue
);
533 /* Get the IRP and set it */
534 Irp
= CONTAINING_RECORD(Entry
, IRP
, Tail
.Overlay
.DeviceQueueEntry
);
535 DeviceObject
->CurrentIrp
= Irp
;
537 /* Check if this is a cancelable packet */
540 /* Check if the caller requested no cancellation */
541 if (IoGetDevObjExtension(DeviceObject
)->StartIoFlags
&
544 /* He did, so remove the cancel routine */
545 Irp
->CancelRoutine
= NULL
;
548 /* Release the cancel lock */
549 IoReleaseCancelSpinLock(OldIrql
);
552 /* Call the Start I/O Routine */
553 DeviceObject
->DriverObject
->DriverStartIo(DeviceObject
, Irp
);
557 /* Otherwise, release the cancel lock if we had acquired it */
558 if (Cancelable
) IoReleaseCancelSpinLock(OldIrql
);
564 IopStartNextPacketByKeyEx(IN PDEVICE_OBJECT DeviceObject
,
568 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension
;
569 ULONG CurrentKey
= Key
;
570 ULONG CurrentFlags
= Flags
;
572 /* Get the device extension and start the packet loop */
573 DeviceExtension
= IoGetDevObjExtension(DeviceObject
);
576 /* Increase the count */
577 if (InterlockedIncrement(&DeviceExtension
->StartIoCount
) > 1)
580 * We've already called the routine once...
581 * All we have to do is save the key and add the new flags
583 DeviceExtension
->StartIoFlags
|= CurrentFlags
;
584 DeviceExtension
->StartIoKey
= CurrentKey
;
588 /* Mask out the current packet flags and key */
589 DeviceExtension
->StartIoFlags
&= ~(DOE_SIO_WITH_KEY
|
592 DeviceExtension
->StartIoKey
= 0;
594 /* Check if this is a packet start with key */
595 if (Flags
& DOE_SIO_WITH_KEY
)
597 /* Start the packet with a key */
598 IopStartNextPacketByKey(DeviceObject
,
599 (Flags
& DOE_SIO_CANCELABLE
) ?
603 else if (Flags
& DOE_SIO_NO_KEY
)
605 /* Start the packet */
606 IopStartNextPacket(DeviceObject
,
607 (Flags
& DOE_SIO_CANCELABLE
) ?
612 /* Decrease the Start I/O count and check if it's 0 now */
613 if (!InterlockedDecrement(&DeviceExtension
->StartIoCount
))
615 /* Get the current active key and flags */
616 CurrentKey
= DeviceExtension
->StartIoKey
;
617 CurrentFlags
= DeviceExtension
->StartIoFlags
& (DOE_SIO_WITH_KEY
|
621 /* Check if we should still loop */
622 if (!(CurrentFlags
& (DOE_SIO_WITH_KEY
| DOE_SIO_NO_KEY
))) break;
626 /* There are still Start I/Os active, so quit this loop */
634 IopGetRelatedTargetDevice(IN PFILE_OBJECT FileObject
,
635 OUT PDEVICE_NODE
*DeviceNode
)
638 IO_STACK_LOCATION Stack
= {0};
639 PDEVICE_RELATIONS DeviceRelations
;
640 PDEVICE_OBJECT DeviceObject
= NULL
;
644 /* Get DeviceObject related to given FileObject */
645 DeviceObject
= IoGetRelatedDeviceObject(FileObject
);
646 if (!DeviceObject
) return STATUS_NO_SUCH_DEVICE
;
648 /* Define input parameters */
649 Stack
.MajorFunction
= IRP_MJ_PNP
;
650 Stack
.MinorFunction
= IRP_MN_QUERY_DEVICE_RELATIONS
;
651 Stack
.Parameters
.QueryDeviceRelations
.Type
= TargetDeviceRelation
;
652 Stack
.FileObject
= FileObject
;
654 /* Call the driver to query all relations (IRP_MJ_PNP) */
655 Status
= IopSynchronousCall(DeviceObject
,
657 (PVOID
)&DeviceRelations
);
658 if (!NT_SUCCESS(Status
)) return Status
;
660 /* Make sure it's not NULL and contains only one object */
661 ASSERT(DeviceRelations
);
662 ASSERT(DeviceRelations
->Count
== 1);
664 /* Finally get the device node */
665 *DeviceNode
= IopGetDeviceNode(DeviceRelations
->Objects
[0]);
666 if (!*DeviceNode
) Status
= STATUS_NO_SUCH_DEVICE
;
668 /* Free the DEVICE_RELATIONS structure, it's not needed anymore */
669 ExFreePool(DeviceRelations
);
674 /* PUBLIC FUNCTIONS ***********************************************************/
679 * Layers a device over the highest device in a device stack.
683 * Device to be attached.
686 * Name of the target device.
689 * Caller storage for the device attached to.
696 IoAttachDevice(PDEVICE_OBJECT SourceDevice
,
697 PUNICODE_STRING TargetDeviceName
,
698 PDEVICE_OBJECT
*AttachedDevice
)
701 PFILE_OBJECT FileObject
= NULL
;
702 PDEVICE_OBJECT TargetDevice
= NULL
;
704 /* Call the helper routine for an attach operation */
705 Status
= IopGetDeviceObjectPointer(TargetDeviceName
,
706 FILE_READ_ATTRIBUTES
,
709 IO_ATTACH_DEVICE_API
);
710 if (!NT_SUCCESS(Status
)) return Status
;
712 /* Attach the device */
713 Status
= IoAttachDeviceToDeviceStackSafe(SourceDevice
,
718 ObDereferenceObject(FileObject
);
723 * IoAttachDeviceByPointer
730 IoAttachDeviceByPointer(IN PDEVICE_OBJECT SourceDevice
,
731 IN PDEVICE_OBJECT TargetDevice
)
733 PDEVICE_OBJECT AttachedDevice
;
734 NTSTATUS Status
= STATUS_SUCCESS
;
737 AttachedDevice
= IoAttachDeviceToDeviceStack(SourceDevice
, TargetDevice
);
738 if (!AttachedDevice
) Status
= STATUS_NO_SUCH_DEVICE
;
740 /* Return the status */
749 IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice
,
750 IN PDEVICE_OBJECT TargetDevice
)
752 /* Attach it safely */
753 return IopAttachDeviceToDeviceStackSafe(SourceDevice
,
763 IoAttachDeviceToDeviceStackSafe(IN PDEVICE_OBJECT SourceDevice
,
764 IN PDEVICE_OBJECT TargetDevice
,
765 IN OUT PDEVICE_OBJECT
*AttachedToDeviceObject
)
767 /* Call the internal function */
768 if (!IopAttachDeviceToDeviceStackSafe(SourceDevice
,
770 AttachedToDeviceObject
))
773 return STATUS_NO_SUCH_DEVICE
;
777 return STATUS_SUCCESS
;
783 * Allocates memory for and intializes a device object for use for
788 * Driver object passed by IO Manager when the driver was loaded.
790 * DeviceExtensionSize
791 * Number of bytes for the device extension.
794 * Unicode name of device.
797 * Device type of the new device.
799 * DeviceCharacteristics
800 * Bit mask of device characteristics.
803 * TRUE if only one thread can access the device at a time.
806 * On successful return this parameter is filled by pointer to
807 * allocated device object.
814 IoCreateDevice(IN PDRIVER_OBJECT DriverObject
,
815 IN ULONG DeviceExtensionSize
,
816 IN PUNICODE_STRING DeviceName
,
817 IN DEVICE_TYPE DeviceType
,
818 IN ULONG DeviceCharacteristics
,
819 IN BOOLEAN Exclusive
,
820 OUT PDEVICE_OBJECT
*DeviceObject
)
822 WCHAR AutoNameBuffer
[20];
823 UNICODE_STRING AutoName
;
824 PDEVICE_OBJECT CreatedDeviceObject
;
825 PDEVOBJ_EXTENSION DeviceObjectExtension
;
826 OBJECT_ATTRIBUTES ObjectAttributes
;
828 ULONG AlignedDeviceExtensionSize
;
833 /* Check if we have to generate a name */
834 if (DeviceCharacteristics
& FILE_AUTOGENERATED_DEVICE_NAME
)
837 swprintf(AutoNameBuffer
,
839 InterlockedIncrementUL(&IopDeviceObjectNumber
));
841 /* Initialize the name */
842 RtlInitUnicodeString(&AutoName
, AutoNameBuffer
);
843 DeviceName
= &AutoName
;
846 /* Initialize the Object Attributes */
847 InitializeObjectAttributes(&ObjectAttributes
,
853 /* Honor exclusive flag */
854 if (Exclusive
) ObjectAttributes
.Attributes
|= OBJ_EXCLUSIVE
;
856 /* Create a permanent object for named devices */
857 if (DeviceName
) ObjectAttributes
.Attributes
|= OBJ_PERMANENT
;
859 /* Align the Extension Size to 8-bytes */
860 AlignedDeviceExtensionSize
= (DeviceExtensionSize
+ 7) &~ 7;
863 TotalSize
= AlignedDeviceExtensionSize
+
864 sizeof(DEVICE_OBJECT
) +
865 sizeof(EXTENDED_DEVOBJ_EXTENSION
);
867 /* Create the Device Object */
868 *DeviceObject
= NULL
;
869 Status
= ObCreateObject(KernelMode
,
877 (PVOID
*)&CreatedDeviceObject
);
878 if (!NT_SUCCESS(Status
)) return Status
;
880 /* Clear the whole Object and extension so we don't null stuff manually */
881 RtlZeroMemory(CreatedDeviceObject
, TotalSize
);
884 * Setup the Type and Size. Note that we don't use the aligned size,
885 * because that's only padding for the DevObjExt and not part of the Object.
887 CreatedDeviceObject
->Type
= IO_TYPE_DEVICE
;
888 CreatedDeviceObject
->Size
= sizeof(DEVICE_OBJECT
) + (USHORT
)DeviceExtensionSize
;
890 /* The kernel extension is after the driver internal extension */
891 DeviceObjectExtension
= (PDEVOBJ_EXTENSION
)
892 ((ULONG_PTR
)(CreatedDeviceObject
+ 1) +
893 AlignedDeviceExtensionSize
);
895 /* Set the Type and Size. Question: why is Size 0 on Windows? */
896 DeviceObjectExtension
->Type
= IO_TYPE_DEVICE_OBJECT_EXTENSION
;
897 DeviceObjectExtension
->Size
= 0;
899 /* Initialize with Power Manager */
900 PoInitializeDeviceObject(DeviceObjectExtension
);
902 /* Link the Object and Extension */
903 DeviceObjectExtension
->DeviceObject
= CreatedDeviceObject
;
904 CreatedDeviceObject
->DeviceObjectExtension
= DeviceObjectExtension
;
906 /* Set Device Object Data */
907 CreatedDeviceObject
->DeviceType
= DeviceType
;
908 CreatedDeviceObject
->Characteristics
= DeviceCharacteristics
;
909 CreatedDeviceObject
->DeviceExtension
= DeviceExtensionSize
?
910 CreatedDeviceObject
+ 1 :
912 CreatedDeviceObject
->StackSize
= 1;
913 CreatedDeviceObject
->AlignmentRequirement
= 0;
916 CreatedDeviceObject
->Flags
= DO_DEVICE_INITIALIZING
;
917 if (Exclusive
) CreatedDeviceObject
->Flags
|= DO_EXCLUSIVE
;
918 if (DeviceName
) CreatedDeviceObject
->Flags
|= DO_DEVICE_HAS_NAME
;
920 /* Attach a Vpb for Disks and Tapes, and create the Device Lock */
921 if ((CreatedDeviceObject
->DeviceType
== FILE_DEVICE_DISK
) ||
922 (CreatedDeviceObject
->DeviceType
== FILE_DEVICE_VIRTUAL_DISK
) ||
923 (CreatedDeviceObject
->DeviceType
== FILE_DEVICE_CD_ROM
) ||
924 (CreatedDeviceObject
->DeviceType
== FILE_DEVICE_TAPE
))
927 Status
= IopCreateVpb(CreatedDeviceObject
);
928 if (!NT_SUCCESS(Status
))
930 /* Dereference the device object and fail */
931 ObDereferenceObject(CreatedDeviceObject
);
935 /* Initialize Lock Event */
936 KeInitializeEvent(&CreatedDeviceObject
->DeviceLock
,
937 SynchronizationEvent
,
941 /* Set the right Sector Size */
944 /* All disk systems */
945 case FILE_DEVICE_DISK_FILE_SYSTEM
:
946 case FILE_DEVICE_DISK
:
947 case FILE_DEVICE_VIRTUAL_DISK
:
949 /* The default is 512 bytes */
950 CreatedDeviceObject
->SectorSize
= 512;
953 /* CD-ROM file systems */
954 case FILE_DEVICE_CD_ROM_FILE_SYSTEM
:
956 /* The default is 2048 bytes */
957 CreatedDeviceObject
->SectorSize
= 2048;
960 /* Create the Device Queue */
961 if ((CreatedDeviceObject
->DeviceType
== FILE_DEVICE_DISK_FILE_SYSTEM
) ||
962 (CreatedDeviceObject
->DeviceType
== FILE_DEVICE_FILE_SYSTEM
) ||
963 (CreatedDeviceObject
->DeviceType
== FILE_DEVICE_CD_ROM_FILE_SYSTEM
) ||
964 (CreatedDeviceObject
->DeviceType
== FILE_DEVICE_NETWORK_FILE_SYSTEM
) ||
965 (CreatedDeviceObject
->DeviceType
== FILE_DEVICE_TAPE_FILE_SYSTEM
))
967 /* Simple FS Devices, they don't need a real Device Queue */
968 InitializeListHead(&CreatedDeviceObject
->Queue
.ListEntry
);
972 /* An actual Device, initialize its DQ */
973 KeInitializeDeviceQueue(&CreatedDeviceObject
->DeviceQueue
);
976 /* Insert the Object */
977 Status
= ObInsertObject(CreatedDeviceObject
,
979 FILE_READ_DATA
| FILE_WRITE_DATA
,
981 (PVOID
*)&CreatedDeviceObject
,
983 if (!NT_SUCCESS(Status
)) return Status
;
985 /* Now do the final linking */
986 ObReferenceObject(DriverObject
);
987 ASSERT((DriverObject
->Flags
& DRVO_UNLOAD_INVOKED
) == 0);
988 CreatedDeviceObject
->DriverObject
= DriverObject
;
989 IopEditDeviceList(DriverObject
, CreatedDeviceObject
, IopAdd
);
991 /* Link with the power manager */
992 if (CreatedDeviceObject
->Vpb
) PoVolumeDevice(CreatedDeviceObject
);
994 /* Close the temporary handle and return to caller */
995 ObCloseHandle(TempHandle
, KernelMode
);
996 *DeviceObject
= CreatedDeviceObject
;
997 return STATUS_SUCCESS
;
1008 IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject
)
1012 /* Check if the device is registered for shutdown notifications */
1013 if (DeviceObject
->Flags
& DO_SHUTDOWN_REGISTERED
)
1015 /* Call the shutdown notifications */
1016 IoUnregisterShutdownNotification(DeviceObject
);
1019 /* Check if it has a timer */
1020 Timer
= DeviceObject
->Timer
;
1023 /* Remove it and free it */
1024 IopRemoveTimerFromTimerList(Timer
);
1025 ExFreePoolWithTag(Timer
, TAG_IO_TIMER
);
1028 /* Check if the device has a name */
1029 if (DeviceObject
->Flags
& DO_DEVICE_HAS_NAME
)
1031 /* It does, make it temporary so we can remove it */
1032 ObMakeTemporaryObject(DeviceObject
);
1035 /* Set the pending delete flag */
1036 IoGetDevObjExtension(DeviceObject
)->ExtensionFlags
|= DOE_DELETE_PENDING
;
1038 /* Unlink with the power manager */
1039 if (DeviceObject
->Vpb
) PoRemoveVolumeDevice(DeviceObject
);
1041 /* Check if the device object can be unloaded */
1042 if (!DeviceObject
->ReferenceCount
) IopUnloadDevice(DeviceObject
);
1053 IoDetachDevice(IN PDEVICE_OBJECT TargetDevice
)
1055 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension
;
1058 DeviceExtension
= IoGetDevObjExtension(TargetDevice
->AttachedDevice
);
1059 ASSERT(DeviceExtension
->AttachedTo
== TargetDevice
);
1061 /* Remove the attachment */
1062 DeviceExtension
->AttachedTo
= NULL
;
1063 TargetDevice
->AttachedDevice
= NULL
;
1065 /* Check if it's ok to delete this device */
1066 if ((IoGetDevObjExtension(TargetDevice
)->ExtensionFlags
& DOE_DELETE_PENDING
) &&
1067 !(TargetDevice
->ReferenceCount
))
1070 IopUnloadDevice(TargetDevice
);
1079 IoEnumerateDeviceObjectList(IN PDRIVER_OBJECT DriverObject
,
1080 IN PDEVICE_OBJECT
*DeviceObjectList
,
1081 IN ULONG DeviceObjectListSize
,
1082 OUT PULONG ActualNumberDeviceObjects
)
1084 ULONG ActualDevices
= 1;
1085 PDEVICE_OBJECT CurrentDevice
= DriverObject
->DeviceObject
;
1087 /* Find out how many devices we'll enumerate */
1088 while ((CurrentDevice
= CurrentDevice
->NextDevice
)) ActualDevices
++;
1090 /* Go back to the first */
1091 CurrentDevice
= DriverObject
->DeviceObject
;
1093 /* Start by at least returning this */
1094 *ActualNumberDeviceObjects
= ActualDevices
;
1096 /* Check if we can support so many */
1097 if ((ActualDevices
* 4) > DeviceObjectListSize
)
1099 /* Fail because the buffer was too small */
1100 return STATUS_BUFFER_TOO_SMALL
;
1103 /* Check if the caller only wanted the size */
1104 if (DeviceObjectList
)
1106 /* Loop through all the devices */
1107 while (ActualDevices
)
1109 /* Reference each Device */
1110 ObReferenceObject(CurrentDevice
);
1112 /* Add it to the list */
1113 *DeviceObjectList
= CurrentDevice
;
1115 /* Go to the next one */
1116 CurrentDevice
= CurrentDevice
->NextDevice
;
1122 /* Return the status */
1123 return STATUS_SUCCESS
;
1127 * IoGetAttachedDevice
1134 IoGetAttachedDevice(PDEVICE_OBJECT DeviceObject
)
1136 /* Get the last attached device */
1137 while (DeviceObject
->AttachedDevice
)
1139 /* Move to the next one */
1140 DeviceObject
= DeviceObject
->AttachedDevice
;
1144 return DeviceObject
;
1148 * IoGetAttachedDeviceReference
1155 IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject
)
1157 /* Reference the Attached Device */
1158 DeviceObject
= IoGetAttachedDevice(DeviceObject
);
1159 ObReferenceObject(DeviceObject
);
1160 return DeviceObject
;
1168 IoGetDeviceAttachmentBaseRef(IN PDEVICE_OBJECT DeviceObject
)
1170 /* Reference the lowest attached device */
1171 DeviceObject
= IopGetLowestDevice(DeviceObject
);
1172 ObReferenceObject(DeviceObject
);
1173 return DeviceObject
;
1177 * IoGetDeviceObjectPointer
1184 IoGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName
,
1185 IN ACCESS_MASK DesiredAccess
,
1186 OUT PFILE_OBJECT
*FileObject
,
1187 OUT PDEVICE_OBJECT
*DeviceObject
)
1189 /* Call the helper routine for a normal operation */
1190 return IopGetDeviceObjectPointer(ObjectName
,
1202 IoGetDiskDeviceObject(IN PDEVICE_OBJECT FileSystemDeviceObject
,
1203 OUT PDEVICE_OBJECT
*DiskDeviceObject
)
1205 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension
;
1210 /* Make sure there's a VPB */
1211 if (!FileSystemDeviceObject
->Vpb
) return STATUS_INVALID_PARAMETER
;
1214 IoAcquireVpbSpinLock(&OldIrql
);
1216 /* Get the Device Extension */
1217 DeviceExtension
= IoGetDevObjExtension(FileSystemDeviceObject
);
1219 /* Make sure this one has a VPB too */
1220 Vpb
= DeviceExtension
->Vpb
;
1223 /* Make sure that it's mounted */
1224 if ((Vpb
->ReferenceCount
) &&
1225 (Vpb
->Flags
& VPB_MOUNTED
))
1227 /* Return the Disk Device Object */
1228 *DiskDeviceObject
= Vpb
->RealDevice
;
1230 /* Reference it and return success */
1231 ObReferenceObject(Vpb
->RealDevice
);
1232 Status
= STATUS_SUCCESS
;
1236 /* It's not, so return failure */
1237 Status
= STATUS_VOLUME_DISMOUNTED
;
1243 Status
= STATUS_INVALID_PARAMETER
;
1246 /* Release the lock */
1247 IoReleaseVpbSpinLock(OldIrql
);
1256 IoGetLowerDeviceObject(IN PDEVICE_OBJECT DeviceObject
)
1258 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension
;
1259 PDEVICE_OBJECT LowerDeviceObject
= NULL
;
1261 /* Make sure it's not getting deleted */
1262 DeviceExtension
= IoGetDevObjExtension(DeviceObject
);
1263 if (!(DeviceExtension
->ExtensionFlags
& (DOE_UNLOAD_PENDING
|
1264 DOE_DELETE_PENDING
|
1265 DOE_REMOVE_PENDING
|
1266 DOE_REMOVE_PROCESSED
)))
1268 /* Get the Lower Device Object */
1269 LowerDeviceObject
= DeviceExtension
->AttachedTo
;
1271 /* Check that we got a valid device object */
1272 if (LowerDeviceObject
)
1274 /* We did so let's reference it */
1275 ObReferenceObject(LowerDeviceObject
);
1280 return LowerDeviceObject
;
1288 IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject
)
1290 PDEVICE_OBJECT DeviceObject
= FileObject
->DeviceObject
;
1292 /* Check if we have a VPB with a device object */
1293 if ((FileObject
->Vpb
) && (FileObject
->Vpb
->DeviceObject
))
1295 /* Then use the DO from the VPB */
1296 ASSERT(!(FileObject
->Flags
& FO_DIRECT_DEVICE_OPEN
));
1297 DeviceObject
= FileObject
->Vpb
->DeviceObject
;
1299 else if (!(FileObject
->Flags
& FO_DIRECT_DEVICE_OPEN
) &&
1300 (FileObject
->DeviceObject
->Vpb
) &&
1301 (FileObject
->DeviceObject
->Vpb
->DeviceObject
))
1303 /* The disk device actually has a VPB, so get the DO from there */
1304 DeviceObject
= FileObject
->DeviceObject
->Vpb
->DeviceObject
;
1308 /* Otherwise, this was a direct open */
1309 DeviceObject
= FileObject
->DeviceObject
;
1313 ASSERT(DeviceObject
!= NULL
);
1315 /* Check if we were attached */
1316 if (DeviceObject
->AttachedDevice
)
1318 /* Check if the file object has an extension present */
1319 if (FileObject
->Flags
& FO_FILE_OBJECT_HAS_EXTENSION
)
1321 /* Sanity check, direct open files can't have this */
1322 ASSERT(!(FileObject
->Flags
& FO_DIRECT_DEVICE_OPEN
));
1324 /* Check if the extension is really present */
1325 if (FileObject
->FileObjectExtension
)
1327 /* FIXME: Unhandled yet */
1328 DPRINT1("FOEs not supported\n");
1333 /* Return the highest attached device */
1334 DeviceObject
= IoGetAttachedDevice(DeviceObject
);
1337 /* Return the DO we found */
1338 return DeviceObject
;
1346 IoGetRelatedTargetDevice(IN PFILE_OBJECT FileObject
,
1347 OUT PDEVICE_OBJECT
*DeviceObject
)
1350 PDEVICE_NODE DeviceNode
= NULL
;
1352 /* Call the internal helper function */
1353 Status
= IopGetRelatedTargetDevice(FileObject
, &DeviceNode
);
1354 if (NT_SUCCESS(Status
) && DeviceNode
)
1356 *DeviceObject
= DeviceNode
->PhysicalDeviceObject
;
1366 IoGetBaseFileSystemDeviceObject(IN PFILE_OBJECT FileObject
)
1368 PDEVICE_OBJECT DeviceObject
;
1371 * If the FILE_OBJECT's VPB is defined,
1372 * get the device from it.
1374 if ((FileObject
->Vpb
) && (FileObject
->Vpb
->DeviceObject
))
1376 /* Use the VPB's Device Object's */
1377 DeviceObject
= FileObject
->Vpb
->DeviceObject
;
1379 else if (!(FileObject
->Flags
& FO_DIRECT_DEVICE_OPEN
) &&
1380 (FileObject
->DeviceObject
->Vpb
) &&
1381 (FileObject
->DeviceObject
->Vpb
->DeviceObject
))
1383 /* Use the VPB's File System Object */
1384 DeviceObject
= FileObject
->DeviceObject
->Vpb
->DeviceObject
;
1388 /* Use the FO's Device Object */
1389 DeviceObject
= FileObject
->DeviceObject
;
1392 /* Return the device object we found */
1393 ASSERT(DeviceObject
!= NULL
);
1394 return DeviceObject
;
1402 IoRegisterLastChanceShutdownNotification(IN PDEVICE_OBJECT DeviceObject
)
1404 PSHUTDOWN_ENTRY Entry
;
1406 /* Allocate the shutdown entry */
1407 Entry
= ExAllocatePoolWithTag(NonPagedPool
,
1408 sizeof(SHUTDOWN_ENTRY
),
1409 TAG_SHUTDOWN_ENTRY
);
1410 if (!Entry
) return STATUS_INSUFFICIENT_RESOURCES
;
1413 Entry
->DeviceObject
= DeviceObject
;
1415 /* Reference it so it doesn't go away */
1416 ObReferenceObject(DeviceObject
);
1418 /* Insert it into the list */
1419 ExInterlockedInsertHeadList(&LastChanceShutdownListHead
,
1420 &Entry
->ShutdownList
,
1423 /* Set the shutdown registered flag */
1424 DeviceObject
->Flags
|= DO_SHUTDOWN_REGISTERED
;
1425 return STATUS_SUCCESS
;
1433 IoRegisterShutdownNotification(PDEVICE_OBJECT DeviceObject
)
1435 PSHUTDOWN_ENTRY Entry
;
1437 /* Allocate the shutdown entry */
1438 Entry
= ExAllocatePoolWithTag(NonPagedPool
,
1439 sizeof(SHUTDOWN_ENTRY
),
1440 TAG_SHUTDOWN_ENTRY
);
1441 if (!Entry
) return STATUS_INSUFFICIENT_RESOURCES
;
1444 Entry
->DeviceObject
= DeviceObject
;
1446 /* Reference it so it doesn't go away */
1447 ObReferenceObject(DeviceObject
);
1449 /* Insert it into the list */
1450 ExInterlockedInsertHeadList(&ShutdownListHead
,
1451 &Entry
->ShutdownList
,
1454 /* Set the shutdown registered flag */
1455 DeviceObject
->Flags
|= DO_SHUTDOWN_REGISTERED
;
1456 return STATUS_SUCCESS
;
1464 IoUnregisterShutdownNotification(PDEVICE_OBJECT DeviceObject
)
1466 PSHUTDOWN_ENTRY ShutdownEntry
;
1467 PLIST_ENTRY NextEntry
;
1470 /* Remove the flag */
1471 DeviceObject
->Flags
&= ~DO_SHUTDOWN_REGISTERED
;
1473 /* Acquire the shutdown lock and loop the shutdown list */
1474 KeAcquireSpinLock(&ShutdownListLock
, &OldIrql
);
1475 NextEntry
= ShutdownListHead
.Flink
;
1476 while (NextEntry
!= &ShutdownListHead
)
1479 ShutdownEntry
= CONTAINING_RECORD(NextEntry
,
1483 /* Get if the DO matches */
1484 if (ShutdownEntry
->DeviceObject
== DeviceObject
)
1486 /* Remove it from the list */
1487 RemoveEntryList(NextEntry
);
1488 NextEntry
= NextEntry
->Blink
;
1490 /* Free the entry */
1491 ExFreePoolWithTag(ShutdownEntry
, TAG_SHUTDOWN_ENTRY
);
1493 /* Get rid of our reference to it */
1494 ObDereferenceObject(DeviceObject
);
1497 /* Go to the next entry */
1498 NextEntry
= NextEntry
->Flink
;
1501 /* Now loop the last chance list */
1502 NextEntry
= LastChanceShutdownListHead
.Flink
;
1503 while (NextEntry
!= &LastChanceShutdownListHead
)
1506 ShutdownEntry
= CONTAINING_RECORD(NextEntry
,
1510 /* Get if the DO matches */
1511 if (ShutdownEntry
->DeviceObject
== DeviceObject
)
1513 /* Remove it from the list */
1514 RemoveEntryList(NextEntry
);
1515 NextEntry
= NextEntry
->Blink
;
1517 /* Free the entry */
1518 ExFreePoolWithTag(ShutdownEntry
, TAG_SHUTDOWN_ENTRY
);
1520 /* Get rid of our reference to it */
1521 ObDereferenceObject(DeviceObject
);
1524 /* Go to the next entry */
1525 NextEntry
= NextEntry
->Flink
;
1528 /* Release the shutdown lock */
1529 KeReleaseSpinLock(&ShutdownListLock
, OldIrql
);
1537 IoSetStartIoAttributes(IN PDEVICE_OBJECT DeviceObject
,
1538 IN BOOLEAN DeferredStartIo
,
1539 IN BOOLEAN NonCancelable
)
1541 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension
;
1543 /* Get the Device Extension */
1544 DeviceExtension
= IoGetDevObjExtension(DeviceObject
);
1546 /* Set the flags the caller requested */
1547 DeviceExtension
->StartIoFlags
|= (DeferredStartIo
) ? DOE_SIO_DEFERRED
: 0;
1548 DeviceExtension
->StartIoFlags
|= (NonCancelable
) ? DOE_SIO_NO_CANCEL
: 0;
1556 IoStartNextPacketByKey(IN PDEVICE_OBJECT DeviceObject
,
1557 IN BOOLEAN Cancelable
,
1560 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension
;
1562 /* Get the Device Extension */
1563 DeviceExtension
= IoGetDevObjExtension(DeviceObject
);
1565 /* Check if deferred start was requested */
1566 if (DeviceExtension
->StartIoFlags
& DOE_SIO_DEFERRED
)
1568 /* Call our internal function to handle the defered case */
1569 IopStartNextPacketByKeyEx(DeviceObject
,
1572 (Cancelable
? DOE_SIO_CANCELABLE
: 0));
1576 /* Call the normal routine */
1577 IopStartNextPacketByKey(DeviceObject
, Cancelable
, Key
);
1586 IoStartNextPacket(IN PDEVICE_OBJECT DeviceObject
,
1587 IN BOOLEAN Cancelable
)
1589 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension
;
1591 /* Get the Device Extension */
1592 DeviceExtension
= IoGetDevObjExtension(DeviceObject
);
1594 /* Check if deferred start was requested */
1595 if (DeviceExtension
->StartIoFlags
& DOE_SIO_DEFERRED
)
1597 /* Call our internal function to handle the defered case */
1598 IopStartNextPacketByKeyEx(DeviceObject
,
1601 (Cancelable
? DOE_SIO_CANCELABLE
: 0));
1605 /* Call the normal routine */
1606 IopStartNextPacket(DeviceObject
, Cancelable
);
1615 IoStartPacket(IN PDEVICE_OBJECT DeviceObject
,
1618 IN PDRIVER_CANCEL CancelFunction
)
1621 KIRQL OldIrql
, CancelIrql
;
1623 /* Raise to dispatch level */
1624 KeRaiseIrql(DISPATCH_LEVEL
, &OldIrql
);
1626 /* Check if we should acquire the cancel lock */
1629 /* Acquire and set it */
1630 IoAcquireCancelSpinLock(&CancelIrql
);
1631 Irp
->CancelRoutine
= CancelFunction
;
1634 /* Check if we have a key */
1638 Stat
= KeInsertByKeyDeviceQueue(&DeviceObject
->DeviceQueue
,
1639 &Irp
->Tail
.Overlay
.DeviceQueueEntry
,
1644 /* Insert without a key */
1645 Stat
= KeInsertDeviceQueue(&DeviceObject
->DeviceQueue
,
1646 &Irp
->Tail
.Overlay
.DeviceQueueEntry
);
1649 /* Check if this was a first insert */
1653 DeviceObject
->CurrentIrp
= Irp
;
1655 /* Check if this is a cancelable packet */
1658 /* Check if the caller requested no cancellation */
1659 if (IoGetDevObjExtension(DeviceObject
)->StartIoFlags
&
1662 /* He did, so remove the cancel routine */
1663 Irp
->CancelRoutine
= NULL
;
1666 /* Release the cancel lock */
1667 IoReleaseCancelSpinLock(CancelIrql
);
1670 /* Call the Start I/O function */
1671 DeviceObject
->DriverObject
->DriverStartIo(DeviceObject
, Irp
);
1675 /* The packet was inserted... check if we have a cancel function */
1678 /* Check if the IRP got cancelled */
1682 * Set the cancel IRQL, clear the currnet cancel routine and
1685 Irp
->CancelIrql
= CancelIrql
;
1686 Irp
->CancelRoutine
= NULL
;
1687 CancelFunction(DeviceObject
, Irp
);
1691 /* Otherwise, release the lock */
1692 IoReleaseCancelSpinLock(CancelIrql
);
1697 /* Return back to previous IRQL */
1698 KeLowerIrql(OldIrql
);
1701 #if defined (_WIN64)
1704 IoWMIDeviceObjectToProviderId(
1705 IN PDEVICE_OBJECT DeviceObject
)