ReactOS 0.4.17-dev-806-gffa4164
device.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for device.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define DACL_SET   4
 

Functions

VOID NTAPI IopReadyDeviceObjects (IN PDRIVER_OBJECT Driver)
 
VOID NTAPI IopDeleteDevice (IN PVOID ObjectBody)
 
static PDEVICE_OBJECT NTAPI IopAttachDeviceToDeviceStackSafe (_In_ PDEVICE_OBJECT SourceDevice, _In_ PDEVICE_OBJECT TargetDevice, _Out_opt_ PDEVICE_OBJECT *AttachedToDeviceObject)
 
VOID NTAPI IoShutdownPnpDevices (VOID)
 
VOID NTAPI IoShutdownSystem (IN ULONG Phase)
 
NTSTATUS NTAPI IopGetDeviceObjectPointer (IN PUNICODE_STRING ObjectName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject, IN ULONG AttachFlag)
 
PDEVICE_OBJECT NTAPI IopGetLowestDevice (IN PDEVICE_OBJECT DeviceObject)
 
VOID NTAPI IopEditDeviceList (IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT DeviceObject, IN IOP_DEVICE_LIST_OPERATION Type)
 
VOID NTAPI IopUnloadDevice (IN PDEVICE_OBJECT DeviceObject)
 
VOID NTAPI IopDereferenceDeviceObject (IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN ForceUnload)
 
VOID NTAPI IopStartNextPacketByKey (IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN Cancelable, IN ULONG Key)
 
VOID NTAPI IopStartNextPacket (IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN Cancelable)
 
VOID NTAPI IopStartNextPacketByKeyEx (IN PDEVICE_OBJECT DeviceObject, IN ULONG Key, IN ULONG Flags)
 
NTSTATUS NTAPI IopGetRelatedTargetDevice (IN PFILE_OBJECT FileObject, OUT PDEVICE_NODE *DeviceNode)
 
BOOLEAN NTAPI IopVerifyDeviceObjectOnStack (IN PDEVICE_OBJECT BaseDeviceObject, IN PDEVICE_OBJECT TopDeviceObjectHint)
 
NTSTATUS NTAPI IopCreateSecurityDescriptorPerType (IN PSECURITY_DESCRIPTOR SecurityDescriptor, IN SECURITY_DESCRIPTOR_TYPE Type, OUT PULONG OutputFlags)
 
PSECURITY_DESCRIPTOR NTAPI IopCreateDefaultDeviceSecurityDescriptor (IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN HasDeviceName, IN PSECURITY_DESCRIPTOR SecurityDescriptor, OUT PACL *OutputDacl, OUT PULONG OutputFlags)
 
NTSTATUS NTAPI IoAttachDevice (PDEVICE_OBJECT SourceDevice, PUNICODE_STRING TargetDeviceName, PDEVICE_OBJECT *AttachedDevice)
 
NTSTATUS NTAPI IoAttachDeviceByPointer (IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
 
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack (IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
 
NTSTATUS NTAPI IoAttachDeviceToDeviceStackSafe (IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice, IN OUT PDEVICE_OBJECT *AttachedToDeviceObject)
 
NTSTATUS NTAPI IoCreateDevice (IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
 
VOID NTAPI IoDeleteDevice (IN PDEVICE_OBJECT DeviceObject)
 
VOID NTAPI IoDetachDevice (IN PDEVICE_OBJECT TargetDevice)
 
NTSTATUS NTAPI IoEnumerateDeviceObjectList (IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT *DeviceObjectList, IN ULONG DeviceObjectListSize, OUT PULONG ActualNumberDeviceObjects)
 
PDEVICE_OBJECT NTAPI IoGetAttachedDevice (PDEVICE_OBJECT DeviceObject)
 
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference (PDEVICE_OBJECT DeviceObject)
 
PDEVICE_OBJECT NTAPI IoGetDeviceAttachmentBaseRef (IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS NTAPI IoGetDeviceObjectPointer (IN PUNICODE_STRING ObjectName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject)
 
NTSTATUS NTAPI IoGetDiskDeviceObject (IN PDEVICE_OBJECT FileSystemDeviceObject, OUT PDEVICE_OBJECT *DiskDeviceObject)
 
PDEVICE_OBJECT NTAPI IoGetLowerDeviceObject (IN PDEVICE_OBJECT DeviceObject)
 
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject (IN PFILE_OBJECT FileObject)
 
NTSTATUS NTAPI IoGetRelatedTargetDevice (IN PFILE_OBJECT FileObject, OUT PDEVICE_OBJECT *DeviceObject)
 
PDEVICE_OBJECT NTAPI IoGetBaseFileSystemDeviceObject (IN PFILE_OBJECT FileObject)
 
NTSTATUS NTAPI IoRegisterLastChanceShutdownNotification (IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS NTAPI IoRegisterShutdownNotification (PDEVICE_OBJECT DeviceObject)
 
VOID NTAPI IoUnregisterShutdownNotification (PDEVICE_OBJECT DeviceObject)
 
VOID NTAPI IoSetStartIoAttributes (IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN DeferredStartIo, IN BOOLEAN NonCancelable)
 
VOID NTAPI IoStartNextPacketByKey (IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN Cancelable, IN ULONG Key)
 
VOID NTAPI IoStartNextPacket (IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN Cancelable)
 
VOID NTAPI IoStartPacket (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PULONG Key, IN PDRIVER_CANCEL CancelFunction)
 

Variables

ULONG IopDeviceObjectNumber = 0
 
LIST_ENTRY ShutdownListHead
 
LIST_ENTRY LastChanceShutdownListHead
 
KSPIN_LOCK ShutdownListLock
 
LIST_ENTRY IopDiskFileSystemQueueHead
 
LIST_ENTRY IopCdRomFileSystemQueueHead
 
LIST_ENTRY IopTapeFileSystemQueueHead
 
ERESOURCE IopDatabaseResource
 

Macro Definition Documentation

◆ DACL_SET

#define DACL_SET   4

Definition at line 28 of file device.c.

◆ NDEBUG

#define NDEBUG

Definition at line 15 of file device.c.

Function Documentation

◆ IoAttachDevice()

NTSTATUS NTAPI IoAttachDevice ( PDEVICE_OBJECT  SourceDevice,
PUNICODE_STRING  TargetDeviceName,
PDEVICE_OBJECT AttachedDevice 
)

Definition at line 918 of file device.c.

921{
925
926 /* Call the helper routine for an attach operation */
927 Status = IopGetDeviceObjectPointer(TargetDeviceName,
929 &FileObject,
932 if (!NT_SUCCESS(Status)) return Status;
933
934 /* Attach the device */
937 AttachedDevice);
938
939 /* Dereference it */
941 return Status;
942}
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
Status
Definition: gdiplustypes.h:24
#define IO_ATTACH_DEVICE_API
Definition: iotypes.h:223
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
NTSTATUS NTAPI IoAttachDeviceToDeviceStackSafe(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice, IN OUT PDEVICE_OBJECT *AttachedToDeviceObject)
Definition: device.c:985
NTSTATUS NTAPI IopGetDeviceObjectPointer(IN PUNICODE_STRING ObjectName, IN ACCESS_MASK DesiredAccess, OUT PFILE_OBJECT *FileObject, OUT PDEVICE_OBJECT *DeviceObject, IN ULONG AttachFlag)
Definition: device.c:264
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
_Must_inspect_result_ __drv_aliasesMem PDEVICE_OBJECT SourceDevice
Definition: iofuncs.h:690
_Must_inspect_result_ __drv_aliasesMem PDEVICE_OBJECT _In_ PDEVICE_OBJECT TargetDevice
Definition: iofuncs.h:691
* PFILE_OBJECT
Definition: iotypes.h:1998
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by ScreenAddDevice(), and TestAttachDevice().

◆ IoAttachDeviceByPointer()

NTSTATUS NTAPI IoAttachDeviceByPointer ( IN PDEVICE_OBJECT  SourceDevice,
IN PDEVICE_OBJECT  TargetDevice 
)

Definition at line 952 of file device.c.

954{
955 PDEVICE_OBJECT AttachedDevice;
957
958 /* Do the Attach */
960 if (!AttachedDevice) Status = STATUS_NO_SUCH_DEVICE;
961
962 /* Return the status */
963 return Status;
964}
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:971
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136

Referenced by UDFCheckOtherFS().

◆ IoAttachDeviceToDeviceStack()

◆ IoAttachDeviceToDeviceStackSafe()

NTSTATUS NTAPI IoAttachDeviceToDeviceStackSafe ( IN PDEVICE_OBJECT  SourceDevice,
IN PDEVICE_OBJECT  TargetDevice,
IN OUT PDEVICE_OBJECT AttachedToDeviceObject 
)

Definition at line 985 of file device.c.

988{
989 /* Call the internal function */
992 AttachedToDeviceObject))
993 {
994 /* Nothing found */
996 }
997
998 /* Success! */
999 return STATUS_SUCCESS;
1000}

Referenced by _Dispatch_type_(), AddDeviceInternal(), ClassAddDevice(), FdcAddDevice(), FltpAttachDeviceObject(), IoAttachDevice(), PciIdeXAddDeviceEx(), PortAddDevice(), ProcessorAddDevice(), SerenumAddDevice(), SerialAddDeviceInternal(), and SermouseAddDevice().

◆ IoCreateDevice()

NTSTATUS NTAPI IoCreateDevice ( IN PDRIVER_OBJECT  DriverObject,
IN ULONG  DeviceExtensionSize,
IN PUNICODE_STRING  DeviceName,
IN DEVICE_TYPE  DeviceType,
IN ULONG  DeviceCharacteristics,
IN BOOLEAN  Exclusive,
OUT PDEVICE_OBJECT DeviceObject 
)

Definition at line 1036 of file device.c.

1043{
1044 WCHAR AutoNameBuffer[20];
1045 UNICODE_STRING AutoName;
1046 PDEVICE_OBJECT CreatedDeviceObject;
1047 PDEVOBJ_EXTENSION DeviceObjectExtension;
1050 ULONG AlignedDeviceExtensionSize;
1051 ULONG TotalSize;
1052 HANDLE TempHandle;
1053 PACL Dacl;
1055 PAGED_CODE();
1056
1057 /* Check if we have to generate a name */
1059 {
1060 /* Generate it */
1061 _swprintf(AutoNameBuffer,
1062 L"\\Device\\%08lx",
1064
1065 /* Initialize the name */
1066 RtlInitUnicodeString(&AutoName, AutoNameBuffer);
1067 DeviceName = &AutoName;
1068 }
1069
1070 /* Get the security descriptor */
1073 DeviceName != NULL,
1075 &Dacl,
1076 NULL);
1077
1078 /* Initialize the Object Attributes */
1080 DeviceName,
1082 NULL,
1083 ReturnedSD);
1084
1085 /* Honor the internal I/O System case (in)sensitivity */
1087
1088 /* Honor the exclusive flag */
1089 if (Exclusive) ObjectAttributes.Attributes |= OBJ_EXCLUSIVE;
1090
1091 /* Create a permanent object for named devices */
1092 if (DeviceName) ObjectAttributes.Attributes |= OBJ_PERMANENT;
1093
1094 /* Align the Extension Size to 8-bytes */
1095 AlignedDeviceExtensionSize = ALIGN_UP_BY(DeviceExtensionSize,
1097
1098 /* Total Size */
1099 TotalSize = AlignedDeviceExtensionSize +
1100 sizeof(DEVICE_OBJECT) +
1102
1103 /* Create the Device Object */
1104 *DeviceObject = NULL;
1108 KernelMode,
1109 NULL,
1110 TotalSize,
1111 0,
1112 0,
1113 (PVOID*)&CreatedDeviceObject);
1114 if (!NT_SUCCESS(Status))
1115 {
1116 if (Dacl != NULL) ExFreePoolWithTag(Dacl, 'eSoI');
1117
1118 return Status;
1119 }
1120
1121 /* Clear the whole Object and extension so we don't null stuff manually */
1122 RtlZeroMemory(CreatedDeviceObject, TotalSize);
1123
1124 /*
1125 * Setup the Type and Size. Note that we don't use the aligned size,
1126 * because that's only padding for the DevObjExt and not part of the Object.
1127 */
1128 CreatedDeviceObject->Type = IO_TYPE_DEVICE;
1129 CreatedDeviceObject->Size = sizeof(DEVICE_OBJECT) + (USHORT)DeviceExtensionSize;
1130
1131 /* The kernel extension is after the driver internal extension */
1132 DeviceObjectExtension = (PDEVOBJ_EXTENSION)
1133 ((ULONG_PTR)(CreatedDeviceObject + 1) +
1134 AlignedDeviceExtensionSize);
1135
1136 /* Set the Type and Size. Question: why is Size 0 on Windows? */
1137 DeviceObjectExtension->Type = IO_TYPE_DEVICE_OBJECT_EXTENSION;
1138 DeviceObjectExtension->Size = 0;
1139
1140 /* Initialize with Power Manager */
1141 PoInitializeDeviceObject(DeviceObjectExtension);
1142
1143 /* Link the Object and Extension */
1144 DeviceObjectExtension->DeviceObject = CreatedDeviceObject;
1145 CreatedDeviceObject->DeviceObjectExtension = DeviceObjectExtension;
1146
1147 /* Set Device Object Data */
1148 CreatedDeviceObject->DeviceType = DeviceType;
1149 CreatedDeviceObject->Characteristics = DeviceCharacteristics;
1150 CreatedDeviceObject->DeviceExtension = DeviceExtensionSize ?
1151 CreatedDeviceObject + 1 :
1152 NULL;
1153 CreatedDeviceObject->StackSize = 1;
1154 CreatedDeviceObject->AlignmentRequirement = 0;
1155
1156 /* Set the Flags */
1157 CreatedDeviceObject->Flags = DO_DEVICE_INITIALIZING;
1158 if (Exclusive) CreatedDeviceObject->Flags |= DO_EXCLUSIVE;
1159 if (DeviceName) CreatedDeviceObject->Flags |= DO_DEVICE_HAS_NAME;
1160
1161 /* Attach a Vpb for Disks and Tapes, and create the Device Lock */
1162 if ((CreatedDeviceObject->DeviceType == FILE_DEVICE_DISK) ||
1163 (CreatedDeviceObject->DeviceType == FILE_DEVICE_VIRTUAL_DISK) ||
1164 (CreatedDeviceObject->DeviceType == FILE_DEVICE_CD_ROM) ||
1165 (CreatedDeviceObject->DeviceType == FILE_DEVICE_TAPE))
1166 {
1167 /* Create Vpb */
1168 Status = IopCreateVpb(CreatedDeviceObject);
1169 if (!NT_SUCCESS(Status))
1170 {
1171 if (Dacl != NULL) ExFreePoolWithTag(Dacl, 'eSoI');
1172
1173 /* Dereference the device object and fail */
1174 ObDereferenceObject(CreatedDeviceObject);
1175 return Status;
1176 }
1177
1178 /* Initialize Lock Event */
1179 KeInitializeEvent(&CreatedDeviceObject->DeviceLock,
1181 TRUE);
1182 }
1183
1184 /* Set the right Sector Size */
1185 switch (DeviceType)
1186 {
1187 /* All disk systems */
1189 case FILE_DEVICE_DISK:
1191
1192 /* The default is 512 bytes */
1193 CreatedDeviceObject->SectorSize = 512;
1194 break;
1195
1196 /* CD-ROM file systems */
1198
1199 /* The default is 2048 bytes */
1200 CreatedDeviceObject->SectorSize = 2048;
1201 }
1202
1203 /* Create the Device Queue */
1204 if ((CreatedDeviceObject->DeviceType == FILE_DEVICE_DISK_FILE_SYSTEM) ||
1205 (CreatedDeviceObject->DeviceType == FILE_DEVICE_FILE_SYSTEM) ||
1206 (CreatedDeviceObject->DeviceType == FILE_DEVICE_CD_ROM_FILE_SYSTEM) ||
1207 (CreatedDeviceObject->DeviceType == FILE_DEVICE_NETWORK_FILE_SYSTEM) ||
1208 (CreatedDeviceObject->DeviceType == FILE_DEVICE_TAPE_FILE_SYSTEM))
1209 {
1210 /* Simple FS Devices, they don't need a real Device Queue */
1211 InitializeListHead(&CreatedDeviceObject->Queue.ListEntry);
1212 }
1213 else
1214 {
1215 /* An actual Device, initialize its DQ */
1216 KeInitializeDeviceQueue(&CreatedDeviceObject->DeviceQueue);
1217 }
1218
1219 /* Insert the Object */
1220 Status = ObInsertObject(CreatedDeviceObject,
1221 NULL,
1223 1,
1224 (PVOID*)&CreatedDeviceObject,
1225 &TempHandle);
1226 if (!NT_SUCCESS(Status))
1227 {
1228 if (Dacl != NULL) ExFreePoolWithTag(Dacl, 'eSoI');
1229
1230 return Status;
1231 }
1232
1233 /* Now do the final linking */
1235 ASSERT((DriverObject->Flags & DRVO_UNLOAD_INVOKED) == 0);
1236 CreatedDeviceObject->DriverObject = DriverObject;
1237 IopEditDeviceList(DriverObject, CreatedDeviceObject, IopAdd);
1238
1239 /* Link with the power manager */
1240 if (CreatedDeviceObject->Vpb) PoVolumeDevice(CreatedDeviceObject);
1241
1242 /* Close the temporary handle and return to caller */
1243 ObCloseHandle(TempHandle, KernelMode);
1244 *DeviceObject = CreatedDeviceObject;
1245
1246 if (Dacl != NULL) ExFreePoolWithTag(Dacl, 'eSoI');
1247
1248 return STATUS_SUCCESS;
1249}
#define PAGED_CODE()
#define ALIGN_UP_BY(size, align)
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
VOID NTAPI KeInitializeDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue)
Definition: devqueue.c:22
#define TRUE
Definition: types.h:120
#define L(x)
Definition: resources.c:13
struct _DEVICE_OBJECT DEVICE_OBJECT
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define DO_EXCLUSIVE
Definition: env_spec_w32.h:395
#define DO_DEVICE_INITIALIZING
Definition: env_spec_w32.h:399
#define DO_DEVICE_HAS_NAME
Definition: env_spec_w32.h:398
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define InterlockedIncrementUL(Addend)
Definition: ex.h:1544
__in PWDFDEVICE_INIT __in BOOLEAN Exclusive
POBJECT_TYPE IoDeviceObjectType
Definition: iomgr.c:35
DeviceType
Definition: mmdrv.h:42
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define _swprintf(buf, format,...)
Definition: sprintf.c:56
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:115
#define KernelMode
Definition: asm.h:38
#define FILE_AUTOGENERATED_DEVICE_NAME
Definition: iotypes.h:142
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL Dacl
Definition: rtlfuncs.h:1625
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define FILE_READ_DATA
Definition: nt_native.h:628
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define MEMORY_ALLOCATION_ALIGNMENT
Definition: ntbasedef.h:90
@ SynchronizationEvent
ULONG IopCaseInsensitive
Definition: iomgr.c:38
NTSTATUS NTAPI IopCreateVpb(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:158
@ IopAdd
Definition: io.h:252
PSECURITY_DESCRIPTOR NTAPI IopCreateDefaultDeviceSecurityDescriptor(IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN HasDeviceName, IN PSECURITY_DESCRIPTOR SecurityDescriptor, OUT PACL *OutputDacl, OUT PULONG OutputFlags)
Definition: device.c:783
VOID NTAPI IopEditDeviceList(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT DeviceObject, IN IOP_DEVICE_LIST_OPERATION Type)
Definition: device.c:339
ULONG IopDeviceObjectNumber
Definition: device.c:20
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3406
NTSTATUS NTAPI ObInsertObject(IN PVOID Object, IN PACCESS_STATE AccessState OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG ObjectPointerBias, OUT PVOID *NewObject OPTIONAL, OUT PHANDLE Handle)
Definition: obhandle.c:2957
NTSTATUS NTAPI ObCreateObject(IN KPROCESSOR_MODE ProbeMode OPTIONAL, IN POBJECT_TYPE Type, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN KPROCESSOR_MODE AccessMode, IN OUT PVOID ParseContext OPTIONAL, IN ULONG ObjectSize, IN ULONG PagedPoolCharge OPTIONAL, IN ULONG NonPagedPoolCharge OPTIONAL, OUT PVOID *Object)
Definition: oblife.c:1040
short WCHAR
Definition: pedump.c:58
unsigned short USHORT
Definition: pedump.c:61
VOID NTAPI PoInitializeDeviceObject(IN OUT PDEVOBJ_EXTENSION DeviceObjectExtension)
Definition: povolume.c:361
VOID NTAPI PoVolumeDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: povolume.c:81
#define FILE_DEVICE_FILE_SYSTEM
Definition: winioctl.h:54
#define FILE_DEVICE_DISK_FILE_SYSTEM
Definition: winioctl.h:53
#define FILE_DEVICE_TAPE
Definition: winioctl.h:76
#define FILE_DEVICE_TAPE_FILE_SYSTEM
Definition: winioctl.h:77
#define FILE_DEVICE_CD_ROM
Definition: winioctl.h:47
#define FILE_DEVICE_CD_ROM_FILE_SYSTEM
Definition: winioctl.h:48
#define FILE_DEVICE_NETWORK_FILE_SYSTEM
Definition: winioctl.h:65
#define FILE_DEVICE_DISK
Definition: winioctl.h:52
#define FILE_DEVICE_VIRTUAL_DISK
Definition: winioctl.h:81
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define OBJ_EXCLUSIVE
Definition: winternl.h:227
#define OBJ_PERMANENT
Definition: winternl.h:226
ULONG AlignmentRequirement
Definition: env_spec_w32.h:420
PVOID DeviceExtension
Definition: env_spec_w32.h:418
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2171
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2061
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3281
_In_ WDFDEVICE _In_ ULONG DeviceCharacteristics
Definition: wdfdevice.h:2781
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID _In_opt_ const WSK_CLIENT_CONNECTION_DISPATCH _In_opt_ PEPROCESS _In_opt_ PETHREAD _In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor
Definition: wsk.h:191
#define IO_TYPE_DEVICE
struct _DEVOBJ_EXTENSION * PDEVOBJ_EXTENSION
#define IO_TYPE_DEVICE_OBJECT_EXTENSION
#define DRVO_UNLOAD_INVOKED
Definition: iotypes.h:2227
#define ObReferenceObject
Definition: obfuncs.h:204

Referenced by _Dispatch_type_(), _Function_class_(), add_volume_device(), AddControllers(), AddDeviceInternal(), AtaAddChannel(), AtaPdoCreateDevice(), Bus_AddDevice(), Bus_PlugInDevice(), ClassAddDevice(), CmBattCreateFdo(), CODE_SEG(), CompBattAddDevice(), ConDrvCreateController(), CreateClassDeviceObject(), CreateGreenFdo(), CreateSoundDevice(), CreateTestDevices(), DriverEntry(), Ext2MountVolume(), FdcAddDevice(), FdcFdoQueryBusRelations(), FDO_CreateChildPdo(), FdoCreateRawParallelPdo(), FdoQueryBusRelations(), FltpAttachToFileSystemDevice(), FltpEnumerateFileSystemVolumes(), FltpSetupCommunicationObjects(), FreeBT_AddDevice(), FsdMount(), FsRecRegisterFs(), FxLibraryCreateDevice(), GreenQueryBusRelations(), HalpAddDevice(), HidClassAddDevice(), HidClassPDO_CreatePDO(), InitDevice(), InitializeSoundBlaster(), InPortAddDevice(), IntVideoPortCreateAdapterDeviceObject(), IntVideoPortEnumerateChildren(), IopInitializePlugPlayServices(), IsaPnpCreateReadPortDO(), IsaPnpFillDeviceRelations(), KbdHid_AddDevice(), KeyboardAddDevice(), KMix_AddDevice(), KopAddDevice(), KsCreateDevice(), KspCreatePDO(), MouHid_AddDevice(), mount_vol(), Mx::MxCreateDevice(), Mx::MxCreateDeviceSecure(), NdisIAddDevice(), NdisMRegisterDevice(), NtfsMountVolume(), PartitionCreateDevice(), PartMgrAddDevice(), PcAddAdapterDevice(), PciAddDevice(), PciIdeXAddDeviceEx(), PciIdeXPdoCreateDevice(), PciPdoCreate(), PcmciaAddDevice(), PdoCreateLunDevice(), PnpRootCreateDeviceObject(), PnpRootDriverEntry(), PortAddDevice(), PortCreatePdo(), ProcessorAddDevice(), RamdiskAddDevice(), RamdiskCreateDiskDevice(), RawFsDriverEntry(), RawMountVolume(), ReportDetectedDevice(), RxRegisterMinirdr(), ScreenAddDevice(), ScsiPortInitialize(), SerenumAddDevice(), SerialAddDeviceInternal(), SermouseAddDevice(), StreamClassAddDevice(), SwAddDevice(), SysAudio_AddDevice(), TestDeviceCreateDelete(), UDFCheckOtherFS(), UDFCreateFsDeviceObject(), UDFMountVolume(), UniataClaimLegacyPCIIDE(), UniataConnectIntr2(), USBCCGP_AddDevice(), USBH_AddDevice(), USBH_CreateDevice(), USBPORT_AddDevice(), USBPORT_CreatePdo(), USBSTOR_AddDevice(), USBSTOR_CreatePDO(), VfatMount(), VfdCreateDevice(), ViCreateDriveLetter(), and WdmaudAddDevice().

◆ IoDeleteDevice()

VOID NTAPI IoDeleteDevice ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 1259 of file device.c.

1260{
1262
1263 /* Check if the device is registered for shutdown notifications */
1265 {
1266 /* Call the shutdown notifications */
1268 }
1269
1270 /* Check if it has a timer */
1272 if (Timer)
1273 {
1274 /* Remove it and free it */
1277 }
1278
1279 /* Check if the device has a name */
1280 if (DeviceObject->Flags & DO_DEVICE_HAS_NAME)
1281 {
1282 /* It does, make it temporary so we can remove it */
1284 }
1285
1286 /* Set the pending delete flag */
1288
1289 /* Unlink with the power manager */
1291
1292 /* Check if the device object can be unloaded */
1293 if (!DeviceObject->ReferenceCount) IopUnloadDevice(DeviceObject);
1294}
#define DO_SHUTDOWN_REGISTERED
Definition: env_spec_w32.h:403
#define DOE_DELETE_PENDING
Definition: iotypes.h:154
VOID NTAPI IopRemoveTimerFromTimerList(IN PIO_TIMER Timer)
Definition: iotimer.c:70
#define IoGetDevObjExtension(DeviceObject)
Definition: io.h:128
VOID NTAPI IopUnloadDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:395
VOID NTAPI IoUnregisterShutdownNotification(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1742
VOID NTAPI ObMakeTemporaryObject(IN PVOID ObjectBody)
Definition: oblife.c:1450
VOID NTAPI PoRemoveVolumeDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: povolume.c:103
#define TAG_IO_TIMER
Definition: tag.h:94

Referenced by _Dispatch_type_(), _Function_class_(), _Requires_lock_held_(), AddDeviceInternal(), AtaAddChannel(), AtaFdoRemoveDevice(), AtaPdoFreeDevice(), BeepUnload(), Bus_AddDevice(), Bus_DestroyPdo(), Bus_PlugInDevice(), CdDeleteVcb(), Cleanup(), CmBattDestroyFdo(), CmBattRemoveDevice(), CODE_SEG(), CompBattAddDevice(), ConDrvCreateController(), ConDrvDeleteController(), CreateFlopDeviceObject(), CreateGreenFdo(), CreateSoundDevice(), CreateTestDevices(), DestroyPortDriver(), DestroySoundDevice(), DiskCreateFdo(), do_shutdown(), DriverEntry(), DriverUnload(), Ext2DestroyVcb(), Ext2MountVolume(), FdcAddDevice(), FDO_HandlePnp(), FdoCreateRawParallelPdo(), FdoHandleRemoveDevice(), FdoPnpControl(), FdoRemoveAdapter(), FdoScanAdapter(), FltpAttachToFileSystemDevice(), FltpDetachFromFileSystemDevice(), FltpEnumerateFileSystemVolumes(), FltpFastIoDetachDevice(), FltpFastIoDetachDeviceWorker(), FltpSetupCommunicationObjects(), free_vol(), FreeBT_AddDevice(), FsRecUnload(), FxLibraryCleanup(), GreenQueryBusRelations(), HalpAddDevice(), HalpDriverEntry(), HandleRemoveDevice(), HidClassAddDevice(), HidClassFDO_RemoveDevice(), HidClassPDO_CreatePDO(), HidClassPDO_PnP(), i8042RemoveDevice(), InitDevice(), InitializeSoundBlaster(), InPortAddDevice(), InPortRemoveDevice(), IntVideoPortCreateAdapterDeviceObject(), IntVideoPortDispatchPdoPnp(), IntVideoPortEnumerateChildren(), IntVideoPortFindAdapter(), IsaFdoRemoveDevice(), IsaPnpFillDeviceRelations(), IsaPnpRemoveLogicalDeviceDO(), IsaPnpRemoveReadPortDO(), KbdHid_AddDevice(), KbdHid_Pnp(), KMix_AddDevice(), KopAddDevice(), KsCreateDevice(), KsDefaultDispatchPnp(), KspCreatePDO(), KsServiceBusEnumPnpRequest(), MouHid_AddDevice(), MouHid_Pnp(), mount_vol(), MountMgrUnload(), MupUnload(), Mx::MxDeleteDevice(), NdisIAddDevice(), NdisIPnPRemoveDevice(), NdisMDeregisterDevice(), NdisMRegisterDevice(), NullUnload(), PartitionHandleRemove(), PartMgrAddDevice(), PcAddAdapterDevice(), PciAddDevice(), PciIdeXAddDeviceEx(), PciIdeXFdoDispatchPnp(), PciIdeXPdoRemoveDevice(), PDO_HandlePnp(), PiControlInitializeDevice(), PnpRootCreateDevice(), PnpRootPdoPnpControl(), PnpRootQueryDeviceRelations(), PortAddDevice(), PortDeletePdo(), ProcessorAddDevice(), RamdiskAddDevice(), RamdiskRemoveBusDevice(), RawCheckForDismount(), RawFsDriverEntry(), RawMountVolume(), RawShutdown(), remove_volume_child(), ReportDetectedDevice(), ReportGreenPdo(), ScreenAddDevice(), SerenumAddDevice(), SerialAddDeviceInternal(), SermouseAddDevice(), StreamClassAddDevice(), SwAddDevice(), SwDispatchPnp(), SysAudio_AddDevice(), TestDeviceCreateDelete(), TestMessageHandler(), TestUnload(), TiUnload(), UDFCheckOtherFS(), UDFCommonDeviceControl(), UDFMountVolume(), UDFReleaseVCB(), UniataClaimLegacyPCIIDE(), UniataConnectIntr2(), UniataDisconnectIntr2(), uninit(), Unload(), UnloadHandler(), USBCCGP_AddDevice(), USBH_AddDevice(), USBH_FdoQueryBusRelations(), USBH_FdoRemoveDevice(), USBH_PdoRemoveDevice(), USBPORT_FdoPnP(), USBSTOR_AddDevice(), USBSTOR_FdoHandleRemoveDevice(), USBSTOR_PdoHandlePnp(), VfatCheckForDismount(), VfatMount(), VfdCreateDevice(), VfdDeleteDevice(), ViCreateDriveLetter(), ViDeleteDevice(), and WdmaudAddDevice().

◆ IoDetachDevice()

VOID NTAPI IoDetachDevice ( IN PDEVICE_OBJECT  TargetDevice)

Definition at line 1304 of file device.c.

1305{
1306 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
1307
1308 /* Sanity check */
1309 DeviceExtension = IoGetDevObjExtension(TargetDevice->AttachedDevice);
1310 ASSERT(DeviceExtension->AttachedTo == TargetDevice);
1311
1312 /* Remove the attachment */
1313 DeviceExtension->AttachedTo = NULL;
1314 TargetDevice->AttachedDevice = NULL;
1315
1316 /* Check if it's ok to delete this device */
1317 if ((IoGetDevObjExtension(TargetDevice)->ExtensionFlags & DOE_DELETE_PENDING) &&
1318 !(TargetDevice->ReferenceCount))
1319 {
1320 /* It is, do it */
1322 }
1323}
PDEVICE_OBJECT AttachedTo
Definition: iotypes.h:1096

Referenced by _Dispatch_type_(), AtaAddChannel(), AtaFdoRemoveDevice(), Bus_AddDevice(), CmBattAddBattery(), CmBattCreateFdo(), CmBattRemoveDevice(), CompBattAddDevice(), CreateGreenFdo(), CreateTestDevices(), DestroyPortDriver(), do_shutdown(), FDO_HandlePnp(), FdoHandleRemoveDevice(), FdoPnpControl(), FltpAttachToFileSystemDevice(), FltpDetachFromFileSystemDevice(), FltpFastIoDetachDevice(), FltpFastIoDetachDeviceWorker(), free_vol(), FreeBT_AddDevice(), HandleRemoveDevice(), HidClassAddDevice(), HidClassFDO_RemoveDevice(), i8042RemoveDevice(), InPortAddDevice(), InPortRemoveDevice(), IntVideoPortCreateAdapterDeviceObject(), IntVideoPortFindAdapter(), IsaFdoRemoveDevice(), KbdHid_Pnp(), KsCreateBusEnumObject(), KsCreateDevice(), KsDefaultDispatchPnp(), MouHid_Pnp(), Mx::MxDetachDevice(), NdisIPnPRemoveDevice(), PciAddDevice(), PciIdeXAddDeviceEx(), PciIdeXFdoDispatchPnp(), RamdiskRemoveBusDevice(), remove_volume_child(), ScreenAddDevice(), SermouseAddDevice(), StreamClassAddDevice(), TestDetachDevice(), TestMessageHandler(), uninit(), USBH_FdoRemoveDevice(), USBPORT_FdoPnP(), and USBSTOR_FdoHandleRemoveDevice().

◆ IoEnumerateDeviceObjectList()

NTSTATUS NTAPI IoEnumerateDeviceObjectList ( IN PDRIVER_OBJECT  DriverObject,
IN PDEVICE_OBJECT DeviceObjectList,
IN ULONG  DeviceObjectListSize,
OUT PULONG  ActualNumberDeviceObjects 
)

Definition at line 1330 of file device.c.

1334{
1335 ULONG ActualDevices = 1;
1336 PDEVICE_OBJECT CurrentDevice = DriverObject->DeviceObject;
1337 KIRQL OldIrql;
1338
1339 /* Lock the device list while we enumerate it */
1341
1342 /* Find out how many devices we'll enumerate */
1343 while ((CurrentDevice = CurrentDevice->NextDevice)) ActualDevices++;
1344
1345 /* Go back to the first */
1346 CurrentDevice = DriverObject->DeviceObject;
1347
1348 /* Start by at least returning this */
1349 *ActualNumberDeviceObjects = ActualDevices;
1350
1351 /* Check if we can support so many */
1352 if ((ActualDevices * sizeof(PDEVICE_OBJECT)) > DeviceObjectListSize)
1353 {
1354 /* Fail because the buffer was too small */
1357 }
1358
1359 /* Check if the caller wanted the device list */
1360 if (DeviceObjectList)
1361 {
1362 /* Loop through all the devices */
1363 while (ActualDevices)
1364 {
1365 /* Reference each Device */
1366 ObReferenceObject(CurrentDevice);
1367
1368 /* Add it to the list */
1369 *DeviceObjectList = CurrentDevice;
1370
1371 /* Go to the next one */
1372 CurrentDevice = CurrentDevice->NextDevice;
1373 ActualDevices--;
1374 DeviceObjectList++;
1375 }
1376 }
1377
1378 /* Release the device list lock */
1380
1381 /* Return the status */
1382 return STATUS_SUCCESS;
1383}
UCHAR KIRQL
Definition: env_spec_w32.h:591
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778
@ LockQueueIoDatabaseLock
Definition: ketypes.h:736

Referenced by FltpEnumerateFileSystemVolumes().

◆ IoGetAttachedDevice()

PDEVICE_OBJECT NTAPI IoGetAttachedDevice ( PDEVICE_OBJECT  DeviceObject)

Definition at line 1393 of file device.c.

1394{
1395 /* Get the last attached device */
1396 while (DeviceObject->AttachedDevice)
1397 {
1398 /* Move to the next one */
1399 DeviceObject = DeviceObject->AttachedDevice;
1400 }
1401
1402 /* Return it */
1403 return DeviceObject;
1404}

Referenced by IoGetAttachedDeviceReference(), IoGetRelatedDeviceObject(), IopAttachDeviceToDeviceStackSafe(), IopCloseFile(), IopDeleteFile(), IopDeviceFsIoControl(), IopGetSetSecurityObject(), IopParseDevice(), IopShutdownBaseFileSystems(), IoShutdownSystem(), NtQueryInformationFile(), NtSetInformationFile(), NtUnlockFile(), PiCallDriverAddDevice(), and UDFCheckOtherFS().

◆ IoGetAttachedDeviceReference()

PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference ( PDEVICE_OBJECT  DeviceObject)

Definition at line 1414 of file device.c.

1415{
1416 KIRQL OldIrql;
1417
1418 /* Retrieve and reference the attached device under the device list lock */
1423
1424 return DeviceObject;
1425}
PDEVICE_OBJECT NTAPI IoGetAttachedDevice(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1393

Referenced by _IRQL_requires_max_(), AtaPnpRepeatRequest(), AtaStorageNotificationWorker(), Bus_GetDeviceCapabilities(), ClasspFailurePredict(), ClasspUpdateDiskProperties(), DiskCreateFdo(), DiskIoctlPredictFailure(), DiskSendFailurePredictIoctl(), FltpDetachFromFileSystemDevice(), FltpIsAttachedToDevice(), MxDeviceObject::GetAttachedDeviceReference(), GetDeviceId(), FxIoTargetRemote::GetTargetDeviceRelations(), HalpIsOldStyleFloppy(), HalpQueryDriveLayout(), HalpQueryPartitionType(), i8042SendHookWorkItem(), IopComputeHarddiskDerangements(), IopInitiatePnpIrp(), IopSynchronousCall(), IsFtVolume(), IssueUniqueIdChangeNotify(), IssueUniqueIdChangeNotifyWorker(), MountMgrNotifyNameChange(), Mx::MxGetAttachedDeviceReference(), PciGetDeviceCapabilities(), PciIdeXPnpRepeatRequest(), PciQueryForPciBusInterface(), PciSendIoctl(), PiCallDriverAddDevice(), PopQuerySystemPowerStateTraverse(), PopSetSystemPowerState(), PopSetSystemPowerStateTraverse(), PoRequestPowerIrp(), QueryDeviceInformation(), FxPkgPnp::QueryForD3ColdInterface(), QuerySuggestedLinkName(), SendLinkCreated(), SendLinkDeleted(), SendOnlineNotification(), USBPORT_IsCompanionController(), and USBPORT_QueryPciBusInterface().

◆ IoGetBaseFileSystemDeviceObject()

PDEVICE_OBJECT NTAPI IoGetBaseFileSystemDeviceObject ( IN PFILE_OBJECT  FileObject)

Definition at line 1644 of file device.c.

1645{
1647
1648 /*
1649 * If the FILE_OBJECT's VPB is defined,
1650 * get the device from it.
1651 */
1652 if ((FileObject->Vpb) && (FileObject->Vpb->DeviceObject))
1653 {
1654 /* Use the VPB's Device Object's */
1655 DeviceObject = FileObject->Vpb->DeviceObject;
1656 }
1657 else if (!(FileObject->Flags & FO_DIRECT_DEVICE_OPEN) &&
1658 (FileObject->DeviceObject->Vpb) &&
1659 (FileObject->DeviceObject->Vpb->DeviceObject))
1660 {
1661 /* Use the VPB's File System Object */
1662 DeviceObject = FileObject->DeviceObject->Vpb->DeviceObject;
1663 }
1664 else
1665 {
1666 /* Use the FO's Device Object */
1667 DeviceObject = FileObject->DeviceObject;
1668 }
1669
1670 /* Return the device object we found */
1672 return DeviceObject;
1673}
#define FO_DIRECT_DEVICE_OPEN
Definition: iotypes.h:1787

Referenced by FsRtlAcquireFileForCcFlushEx(), FsRtlAcquireFileForModWriteEx(), FsRtlMdlRead(), FsRtlMdlReadComplete(), FsRtlMdlWriteComplete(), FsRtlPrepareMdlWrite(), FsRtlReleaseFileForCcFlush(), and FsRtlReleaseFileForModWrite().

◆ IoGetDeviceAttachmentBaseRef()

PDEVICE_OBJECT NTAPI IoGetDeviceAttachmentBaseRef ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 1432 of file device.c.

1433{
1434 KIRQL OldIrql;
1435
1436 /* Retrieve and reference the lowest attached device under the device list lock */
1441
1442 return DeviceObject;
1443}
PDEVICE_OBJECT NTAPI IopGetLowestDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:316

Referenced by FltpEnumerateFileSystemVolumes(), FltpGetBaseDeviceObjectName(), and TestLowerDeviceKernelAPI().

◆ IoGetDeviceObjectPointer()

NTSTATUS NTAPI IoGetDeviceObjectPointer ( IN PUNICODE_STRING  ObjectName,
IN ACCESS_MASK  DesiredAccess,
OUT PFILE_OBJECT FileObject,
OUT PDEVICE_OBJECT DeviceObject 
)

Definition at line 1453 of file device.c.

1457{
1458 /* Call the helper routine for a normal operation */
1461 FileObject,
1463 0);
1464}
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2664
_In_ PVOID _Out_opt_ PULONG_PTR _Outptr_opt_ PCUNICODE_STRING * ObjectName
Definition: cmfuncs.h:64

Referenced by _Function_class_(), add_device(), add_volume_device(), ClassOpen(), CODE_SEG(), disk_arrival(), do_shutdown(), DriverEntry(), EngpRegisterGraphicsDevice(), finish_removing_device(), get_device_pnp_name_guid(), HalpDeleteMountLetter(), HalpEnableAutomaticDriveLetterAssignment(), HalpIsOldStyleFloppy(), HalpNextMountLetter(), HalpQueryDriveLayout(), HalpQueryPartitionType(), HalpSetMountLetter(), IoGetBootDiskInformation(), IopComputeHarddiskDerangements(), IopCreateArcNamesCd(), IopCreateArcNamesDisk(), IoVolumeDeviceToDosName(), IsFtVolume(), IssueUniqueIdChangeNotify(), IssueUniqueIdChangeNotifyWorker(), LibraryOpen(), mountmgr_notification(), MountMgrNotifyNameChange(), probe_volume(), QueryDeviceInformation(), QuerySuggestedLinkName(), read_registry(), ReconcileThisDatabaseWithMasterWorker(), RegisterForTargetDeviceNotification(), remove_volume_child(), ReportToMountMgr(), SearchForLegacyDrivers(), SendLinkCreated(), SendLinkDeleted(), SendOnlineNotification(), TestIoVolumeDeviceToDosName(), UDFCheckOtherFSByName(), volume_arrival(), and VolumeDeleteMountPoints().

◆ IoGetDiskDeviceObject()

NTSTATUS NTAPI IoGetDiskDeviceObject ( IN PDEVICE_OBJECT  FileSystemDeviceObject,
OUT PDEVICE_OBJECT DiskDeviceObject 
)

Definition at line 1471 of file device.c.

1473{
1474 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
1475 PVPB Vpb;
1476 KIRQL OldIrql;
1478
1479 /* Make sure there's a VPB */
1480 if (!FileSystemDeviceObject->Vpb) return STATUS_INVALID_PARAMETER;
1481
1482 /* Acquire it */
1484
1485 /* Get the Device Extension */
1486 DeviceExtension = IoGetDevObjExtension(FileSystemDeviceObject);
1487
1488 /* Make sure this one has a VPB too */
1489 Vpb = DeviceExtension->Vpb;
1490 if (Vpb)
1491 {
1492 /* Make sure that it's mounted */
1493 if ((Vpb->ReferenceCount) &&
1494 (Vpb->Flags & VPB_MOUNTED))
1495 {
1496 /* Return the Disk Device Object */
1497 *DiskDeviceObject = Vpb->RealDevice;
1498
1499 /* Reference it and return success */
1500 ObReferenceObject(Vpb->RealDevice);
1502 }
1503 else
1504 {
1505 /* It's not, so return failure */
1507 }
1508 }
1509 else
1510 {
1511 /* Fail */
1513 }
1514
1515 /* Release the lock */
1517 return Status;
1518}
IN OUT PVCB IN PDEVICE_OBJECT IN PVPB Vpb
Definition: fatprocs.h:1676
_Outptr_ PDEVICE_OBJECT * DiskDeviceObject
Definition: fltkernel.h:1672
VOID NTAPI IoReleaseVpbSpinLock(IN KIRQL Irql)
Definition: volume.c:1215
VOID NTAPI IoAcquireVpbSpinLock(OUT PKIRQL Irql)
Definition: volume.c:1204
#define STATUS_VOLUME_DISMOUNTED
Definition: ntstatus.h:869
Definition: iotypes.h:189
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define VPB_MOUNTED
Definition: iotypes.h:1807

Referenced by FltpEnumerateFileSystemVolumes().

◆ IoGetLowerDeviceObject()

PDEVICE_OBJECT NTAPI IoGetLowerDeviceObject ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 1525 of file device.c.

1526{
1527 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
1529
1530 /* Make sure it's not getting deleted */
1531 DeviceExtension = IoGetDevObjExtension(DeviceObject);
1532 if (!(DeviceExtension->ExtensionFlags &
1535 {
1536 /* Get the Lower Device Object */
1537 LowerDeviceObject = DeviceExtension->AttachedTo;
1538
1539 /* Check that we got a valid device object */
1541 {
1542 /* We did so let's reference it */
1544 }
1545 }
1546
1547 /* Return it */
1548 return LowerDeviceObject;
1549}
_In_z_ PCCHAR _In_ PDEVICE_OBJECT LowerDeviceObject
Definition: classpnp.h:983
#define DOE_REMOVE_PROCESSED
Definition: iotypes.h:156
#define DOE_UNLOAD_PENDING
Definition: iotypes.h:153
#define DOE_REMOVE_PENDING
Definition: iotypes.h:155

Referenced by FltpDetachFromFileSystemDevice(), FltpIsAttachedToDevice(), mount_vol(), still_has_superblock(), and TestLowerDeviceKernelAPI().

◆ IoGetRelatedDeviceObject()

PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject ( IN PFILE_OBJECT  FileObject)

Definition at line 1556 of file device.c.

1557{
1558 PDEVICE_OBJECT DeviceObject = FileObject->DeviceObject;
1559
1560 /* Check if we have a VPB with a device object */
1561 if ((FileObject->Vpb) && (FileObject->Vpb->DeviceObject))
1562 {
1563 /* Then use the DO from the VPB */
1565 DeviceObject = FileObject->Vpb->DeviceObject;
1566 }
1567 else if (!(FileObject->Flags & FO_DIRECT_DEVICE_OPEN) &&
1568 (FileObject->DeviceObject->Vpb) &&
1569 (FileObject->DeviceObject->Vpb->DeviceObject))
1570 {
1571 /* The disk device actually has a VPB, so get the DO from there */
1572 DeviceObject = FileObject->DeviceObject->Vpb->DeviceObject;
1573 }
1574 else
1575 {
1576 /* Otherwise, this was a direct open */
1577 DeviceObject = FileObject->DeviceObject;
1578 }
1579
1580 /* Sanity check */
1582
1583 /* Check if we were attached */
1584 if (DeviceObject->AttachedDevice)
1585 {
1586 /* Check if the file object has an extension present */
1588 {
1589 /* Sanity check, direct open files can't have this */
1591
1592 /* Check if the extension is really present */
1593 if (FileObject->FileObjectExtension)
1594 {
1595 PFILE_OBJECT_EXTENSION FileObjectExtension;
1596
1597 /* Cast the buffer to something we understand */
1598 FileObjectExtension = FileObject->FileObjectExtension;
1599
1600 /* Check if have a valid replacement top level device */
1601 if (FileObjectExtension->TopDeviceObjectHint &&
1603 FileObjectExtension->TopDeviceObjectHint))
1604 {
1605 /* Use this instead of returning the top level device */
1606 return FileObjectExtension->TopDeviceObjectHint;
1607 }
1608 }
1609 }
1610
1611 /* Return the highest attached device */
1613 }
1614
1615 /* Return the DO we found */
1616 return DeviceObject;
1617}
#define FO_FILE_OBJECT_HAS_EXTENSION
Definition: iotypes.h:148
BOOLEAN NTAPI IopVerifyDeviceObjectOnStack(IN PDEVICE_OBJECT BaseDeviceObject, IN PDEVICE_OBJECT TopDeviceObjectHint)
Definition: device.c:700
PDEVICE_OBJECT TopDeviceObjectHint
Definition: io.h:102

Referenced by _In_reads_(), BroadcastOpen(), BuildAndSubmitIrp(), CcMdlReadComplete(), CcMdlWriteComplete(), CompBattGetDeviceObjectPointer(), EngpFileIoRequest(), FsRtlAcquireFileExclusiveCommon(), FsRtlAcquireFileForCcFlushEx(), FsRtlAcquireFileForModWriteEx(), FsRtlCopyRead(), FsRtlCopyRead2(), FsRtlCopyWrite(), FsRtlCopyWrite2(), FsRtlGetFileSize(), FsRtlMdlRead(), FsRtlMdlReadComplete(), FsRtlMdlReadDev(), FsRtlMdlWriteComplete(), FsRtlPrepareMdlWrite(), FsRtlPrepareMdlWriteDev(), FsRtlReleaseFile(), FsRtlReleaseFileForCcFlush(), FsRtlReleaseFileForModWrite(), FsRtlTest_StartTest(), IoPageRead(), IopCloseFile(), IopDeleteFile(), IopDeviceFsIoControl(), IopGetBasicInformationFile(), IopGetDeviceObjectPointer(), IopGetFileInformation(), IopGetRelatedTargetDevice(), IopGetSetSecurityObject(), IopOpenLinkOrRenameTarget(), IopParseDevice(), IopParseFile(), IopQueryDeviceInformation(), IoSetInformation(), IoSynchronousPageWrite(), KsAllocateObjectHeader(), KsQueryInformationFile(), KsReadFile(), KsSetInformationFile(), KsStreamIo(), KsSynchronousIoControlDevice(), KsWriteFile(), MmGetDeviceObjectForFile(), MupBuildIoControlRequest(), NtCreatePagingFile(), NtFlushBuffersFile(), NtLockFile(), NtNotifyChangeDirectoryFile(), NtQueryDirectoryFile(), NtQueryInformationFile(), NtQueryVolumeInformationFile(), NtReadFile(), NtSetInformationFile(), NtSetVolumeInformationFile(), NtUnlockFile(), NtWriteFile(), FxIoTargetRemote::OpenTargetHandle(), Pin_fnWrite(), PopAddRemoveSysCapsCallback(), RawSetInformation(), RegisterUncProvider(), TdiAccept(), TdiAssociateAddressFile(), TdiConnect(), TdiDisassociateAddressFile(), TdiDisconnect(), TdiListen(), TdiQueryDeviceControl(), TdiQueryInformation(), TdiReceive(), TdiReceiveDatagram(), TdiSend(), TdiSendDatagram(), TdiSetEventHandler(), TestProviderInfo(), TestTcpConnect(), VfatSetRenameInformation(), ViReadFile(), and WdmAudReadWrite().

◆ IoGetRelatedTargetDevice()

NTSTATUS NTAPI IoGetRelatedTargetDevice ( IN PFILE_OBJECT  FileObject,
OUT PDEVICE_OBJECT DeviceObject 
)

Definition at line 1624 of file device.c.

1626{
1629
1630 /* Call the internal helper function */
1633 {
1634 *DeviceObject = DeviceNode->PhysicalDeviceObject;
1635 }
1636 return Status;
1637}
@ DeviceNode
Definition: Node.h:9
NTSTATUS NTAPI IopGetRelatedTargetDevice(IN PFILE_OBJECT FileObject, OUT PDEVICE_NODE *DeviceNode)
Definition: device.c:658

Referenced by FsRtlNotifyVolumeEvent(), and NtSetVolumeInformationFile().

◆ IopAttachDeviceToDeviceStackSafe()

static PDEVICE_OBJECT NTAPI IopAttachDeviceToDeviceStackSafe ( _In_ PDEVICE_OBJECT  SourceDevice,
_In_ PDEVICE_OBJECT  TargetDevice,
_Out_opt_ PDEVICE_OBJECT AttachedToDeviceObject 
)
static

Definition at line 69 of file device.c.

73{
74 PDEVICE_OBJECT AttachedDevice;
75 PEXTENDED_DEVOBJ_EXTENSION SourceDeviceExtension;
77
78 /* Lock the device list while attaching the device */
80
81 /* Get the attached device and source extension */
82 AttachedDevice = IoGetAttachedDevice(TargetDevice);
83 SourceDeviceExtension = IoGetDevObjExtension(SourceDevice);
84 ASSERT(SourceDeviceExtension->AttachedTo == NULL);
85
86 /* Make sure that it's in a correct state */
87 if ((AttachedDevice->Flags & DO_DEVICE_INITIALIZING) ||
88 (IoGetDevObjExtension(AttachedDevice)->ExtensionFlags &
91 {
92 /* The device is unloading or being removed */
93 AttachedDevice = NULL;
94 }
95 else
96 {
97 /* Update the attached device fields */
98 AttachedDevice->AttachedDevice = SourceDevice;
99 AttachedDevice->Spare1++;
100
101 /* Update the source with the attached data */
102 SourceDevice->StackSize = AttachedDevice->StackSize + 1;
104 SourceDevice->SectorSize = AttachedDevice->SectorSize;
105
106 /* Check for pending start flag and propagate it */
107 if (IoGetDevObjExtension(AttachedDevice)->ExtensionFlags & DOE_START_PENDING)
109
110 /* Set the attachment in the device extension */
111 SourceDeviceExtension->AttachedTo = AttachedDevice;
112 }
113
114 /* Return the attached device (under the lock) */
115 if (AttachedToDeviceObject)
116 *AttachedToDeviceObject = AttachedDevice;
117
118 /* Release the device list lock */
120
121 return AttachedDevice;
122}
#define DOE_START_PENDING
Definition: boot.c:37

Referenced by IoAttachDeviceToDeviceStack(), and IoAttachDeviceToDeviceStackSafe().

◆ IopCreateDefaultDeviceSecurityDescriptor()

PSECURITY_DESCRIPTOR NTAPI IopCreateDefaultDeviceSecurityDescriptor ( IN DEVICE_TYPE  DeviceType,
IN ULONG  DeviceCharacteristics,
IN BOOLEAN  HasDeviceName,
IN PSECURITY_DESCRIPTOR  SecurityDescriptor,
OUT PACL OutputDacl,
OUT PULONG  OutputFlags 
)

Definition at line 783 of file device.c.

789{
790 PACL Dacl;
791 ULONG AceId;
794 BOOLEAN AdminsSet, WorldSet;
795
796 PAGED_CODE();
797
798 /* Zero our output vars */
799 if (OutputFlags) *OutputFlags = 0;
800
801 *OutputDacl = NULL;
802
803 /* For FSD, easy use SePublicDefaultUnrestrictedDacl */
808 {
811 OutputFlags);
812 goto Quit;
813 }
814 /* For storage devices with a name and floppy attribute,
815 * use SePublicOpenUnrestrictedDacl
816 */
825 {
828 OutputFlags);
829 goto Quit;
830 }
831
832 /* The rest...
833 * We will rely on SePublicDefaultUnrestrictedDacl as well
834 */
836 if (Dacl == NULL)
837 {
838 return NULL;
839 }
840
841 /* Copy our DACL */
843
844 /* Now, browse the DACL to make sure we have everything we want in them,
845 * including permissions
846 */
847 AceId = 0;
848 AdminsSet = FALSE;
849 WorldSet = FALSE;
850 while (NT_SUCCESS(RtlGetAce(Dacl, AceId, (PVOID *)&Ace)))
851 {
852 /* Admins must acess and in RWX, set it */
853 if (RtlEqualSid(SeAliasAdminsSid, &Ace->SidStart))
854 {
856 AdminsSet = TRUE;
857 }
858
859 /* World can read a CD_ROM device */
861 {
862 SetFlag(Ace->Mask, GENERIC_READ);
863 WorldSet = TRUE;
864 }
865
866 ++AceId;
867 }
868
869 /* AdminSid was present and set (otherwise, we have big trouble) */
870 ASSERT(AdminsSet);
871
872 /* If CD_ROM device, we've set world permissions */
873 if (DeviceType == FILE_DEVICE_CD_ROM) ASSERT(WorldSet);
874
875 /* Now our DACL is correct, setup the security descriptor */
878
879 /* We've set DACL */
880 if (OutputFlags) *OutputFlags |= DACL_SET;
881
882 /* Return DACL to allow later freeing */
883 *OutputDacl = Dacl;
885
886Quit:
887 /* Only return SD if we succeed */
888 if (!NT_SUCCESS(Status))
889 {
890 return NULL;
891 }
892
893 return SecurityDescriptor;
894}
unsigned char BOOLEAN
Definition: actypes.h:127
@ Ace
Definition: card.h:12
#define FALSE
Definition: types.h:117
#define GENERIC_READ
Definition: compat.h:135
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
#define SetFlag(_F, _SF)
Definition: ext2fs.h:187
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
#define FILE_DEVICE_MASS_STORAGE
Definition: imports.h:60
NTSYSAPI NTSTATUS NTAPI RtlGetAce(PACL Acl, ULONG AceIndex, PVOID *Ace)
NTSYSAPI NTSTATUS NTAPI RtlCreateSecurityDescriptor(_Out_ PSECURITY_DESCRIPTOR SecurityDescriptor, _In_ ULONG Revision)
NTSYSAPI BOOLEAN NTAPI RtlEqualSid(_In_ PSID Sid1, _In_ PSID Sid2)
#define FILE_FLOPPY_DISKETTE
Definition: nt_native.h:809
#define GENERIC_WRITE
Definition: nt_native.h:90
#define GENERIC_EXECUTE
Definition: nt_native.h:91
@ UnrestrictedPublicOpen
Definition: io.h:516
@ UnrestrictedPublic
Definition: io.h:514
PACL SePublicDefaultUnrestrictedDacl
Definition: acl.c:18
PSID SeAliasAdminsSid
Definition: sid.c:41
PSID SeWorldSid
Definition: sid.c:25
NTSTATUS NTAPI IopCreateSecurityDescriptorPerType(IN PSECURITY_DESCRIPTOR SecurityDescriptor, IN SECURITY_DESCRIPTOR_TYPE Type, OUT PULONG OutputFlags)
Definition: device.c:734
#define DACL_SET
Definition: device.c:28
#define FILE_DEVICE_DFS_FILE_SYSTEM
Definition: winioctl.h:98
#define FILE_DEVICE_NETWORK
Definition: winioctl.h:63
USHORT AclSize
Definition: ms-dtyp.idl:296
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
NTSYSAPI NTSTATUS WINAPI RtlSetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR, BOOLEAN, PACL, BOOLEAN)
#define SECURITY_DESCRIPTOR_REVISION
Definition: setypes.h:58

Referenced by IoCreateDevice().

◆ IopCreateSecurityDescriptorPerType()

NTSTATUS NTAPI IopCreateSecurityDescriptorPerType ( IN PSECURITY_DESCRIPTOR  SecurityDescriptor,
IN SECURITY_DESCRIPTOR_TYPE  Type,
OUT PULONG  OutputFlags 
)

Definition at line 734 of file device.c.

737{
738 PACL Dacl;
740
741 /* Select the DACL the caller wants */
742 switch (Type)
743 {
744 case RestrictedPublic:
746 break;
747
750 break;
751
754 break;
755
758 break;
759
760 case SystemDefault:
762 break;
763
764 default:
765 ASSERT(FALSE);
767 }
768
769 /* Create the SD and set the DACL caller wanted */
773
774 /* We've set DACL */
775 if (OutputFlags) *OutputFlags |= DACL_SET;
776
777 /* Done */
778 return Status;
779}
Type
Definition: Type.h:7
@ RestrictedPublicOpen
Definition: io.h:515
@ RestrictedPublic
Definition: io.h:513
@ SystemDefault
Definition: io.h:517
PACL SePublicOpenDacl
Definition: acl.c:19
PACL SePublicOpenUnrestrictedDacl
Definition: acl.c:20
PACL SePublicDefaultDacl
Definition: acl.c:16
PACL SeSystemDefaultDacl
Definition: acl.c:17

Referenced by IopCreateDefaultDeviceSecurityDescriptor().

◆ IopDeleteDevice()

VOID NTAPI IopDeleteDevice ( IN PVOID  ObjectBody)

Definition at line 52 of file device.c.

53{
54 PDEVICE_OBJECT DeviceObject = ObjectBody;
56 PAGED_CODE();
57
58 /* Cleanup and free the device node */
59 if (DeviceNode)
61
62 /* Dereference the driver object, referenced in IoCreateDevice */
63 if (DeviceObject->DriverObject)
64 ObDereferenceObject(DeviceObject->DriverObject);
65}
PDEVICE_NODE FASTCALL IopGetDeviceNode(IN PDEVICE_OBJECT DeviceObject)
NTSTATUS IopFreeDeviceNode(IN PDEVICE_NODE DeviceNode)

Referenced by IopCreateObjectTypes().

◆ IopDereferenceDeviceObject()

VOID NTAPI IopDereferenceDeviceObject ( IN PDEVICE_OBJECT  DeviceObject,
IN BOOLEAN  ForceUnload 
)

Definition at line 467 of file device.c.

469{
470 /* Sanity check */
471 ASSERT(DeviceObject->ReferenceCount);
472
473 /* Dereference the device */
474 InterlockedDecrement(&DeviceObject->ReferenceCount);
475
476 /*
477 * Check if we can unload it and it's safe to unload (or if we're forcing
478 * an unload, which is OK too).
479 */
480 ASSERT(!ForceUnload);
481 if (!(DeviceObject->ReferenceCount) &&
483 {
484 /* Unload it */
486 }
487}
#define InterlockedDecrement
Definition: armddk.h:52

Referenced by IoCreateStreamFileObjectEx(), IoCreateStreamFileObjectLite(), IopCheckVpbMounted(), IopDeleteFile(), and IopParseDevice().

◆ IopEditDeviceList()

VOID NTAPI IopEditDeviceList ( IN PDRIVER_OBJECT  DriverObject,
IN PDEVICE_OBJECT  DeviceObject,
IN IOP_DEVICE_LIST_OPERATION  Type 
)

Definition at line 339 of file device.c.

342{
343 PDEVICE_OBJECT Previous;
345
346 /* Lock the device list while we edit it */
348
349 /* Check the type of operation */
350 if (Type == IopRemove)
351 {
352 /* Get the current device and check if it's the current one */
353 Previous = DeviceObject->DriverObject->DeviceObject;
354 if (Previous == DeviceObject)
355 {
356 /* It is, simply unlink this one directly */
357 DeviceObject->DriverObject->DeviceObject =
358 DeviceObject->NextDevice;
359 }
360 else
361 {
362 /* It's not, so loop until we find the device */
363 while (Previous->NextDevice != DeviceObject)
364 {
365 /* Not this one, keep moving */
366 if (!Previous->NextDevice)
367 {
368 DPRINT1("Failed to remove PDO %p (not found)\n",
370
371 ASSERT(FALSE);
373 return;
374 }
375 Previous = Previous->NextDevice;
376 }
377
378 /* We found it, now unlink us */
379 Previous->NextDevice = DeviceObject->NextDevice;
380 }
381 }
382 else
383 {
384 /* Link the device object and the driver object */
385 DeviceObject->NextDevice = DriverObject->DeviceObject;
386 DriverObject->DeviceObject = DeviceObject;
387 }
388
389 /* Release the device list lock */
391}
#define DPRINT1
Definition: precomp.h:8
@ IopRemove
Definition: io.h:251

Referenced by IoCreateDevice(), and IopUnloadDevice().

◆ IopGetDeviceObjectPointer()

NTSTATUS NTAPI IopGetDeviceObjectPointer ( IN PUNICODE_STRING  ObjectName,
IN ACCESS_MASK  DesiredAccess,
OUT PFILE_OBJECT FileObject,
OUT PDEVICE_OBJECT DeviceObject,
IN ULONG  AttachFlag 
)

Definition at line 264 of file device.c.

269{
271 IO_STATUS_BLOCK StatusBlock;
272 PFILE_OBJECT LocalFileObject;
275
276 /* Open the Device */
280 NULL,
281 NULL);
282
283 /* Honor the internal I/O System case (in)sensitivity */
285
289 &StatusBlock,
290 0,
291 FILE_NON_DIRECTORY_FILE | AttachFlag);
292 if (!NT_SUCCESS(Status)) return Status;
293
294 /* Get File Object */
296 0,
299 (PVOID*)&LocalFileObject,
300 NULL);
301 if (NT_SUCCESS(Status))
302 {
303 /* Return the requested data */
304 *DeviceObject = IoGetRelatedDeviceObject(LocalFileObject);
305 *FileObject = LocalFileObject;
306 }
307
308 /* Close the handle */
310
311 return Status;
312}
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
NTSYSAPI NTSTATUS NTAPI ZwOpenFile(_Out_ PHANDLE FileHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes, _Out_ PIO_STATUS_BLOCK IoStatusBlock, _In_ ULONG ShareAccess, _In_ ULONG OpenOptions)
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1556
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:493

Referenced by IoAttachDevice(), and IoGetDeviceObjectPointer().

◆ IopGetLowestDevice()

PDEVICE_OBJECT NTAPI IopGetLowestDevice ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 316 of file device.c.

317{
318 PDEVICE_OBJECT LowestDevice;
319 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
320
321 /* Get the current device and its extension */
322 LowestDevice = DeviceObject;
323 DeviceExtension = IoGetDevObjExtension(LowestDevice);
324
325 /* Keep looping as long as we're attached */
326 while (DeviceExtension->AttachedTo)
327 {
328 /* Get the lowest device and its extension */
329 LowestDevice = DeviceExtension->AttachedTo;
330 DeviceExtension = IoGetDevObjExtension(LowestDevice);
331 }
332
333 /* Return the lowest device */
334 return LowestDevice;
335}

Referenced by IoGetDeviceAttachmentBaseRef().

◆ IopGetRelatedTargetDevice()

NTSTATUS NTAPI IopGetRelatedTargetDevice ( IN PFILE_OBJECT  FileObject,
OUT PDEVICE_NODE DeviceNode 
)

Definition at line 658 of file device.c.

660{
663 PDEVICE_RELATIONS DeviceRelations;
665
667
668 /* Get DeviceObject related to given FileObject */
671
672 /* Define input parameters */
673 Stack.MajorFunction = IRP_MJ_PNP;
674 Stack.MinorFunction = IRP_MN_QUERY_DEVICE_RELATIONS;
675 Stack.Parameters.QueryDeviceRelations.Type = TargetDeviceRelation;
676 Stack.FileObject = FileObject;
677
678 /* Call the driver to query all relations (IRP_MJ_PNP) */
680 &Stack,
681 (PVOID)&DeviceRelations);
682 if (!NT_SUCCESS(Status)) return Status;
683
684 /* Make sure it's not NULL and contains only one object */
685 ASSERT(DeviceRelations);
686 ASSERT(DeviceRelations->Count == 1);
687
688 /* Finally get the device node */
689 *DeviceNode = IopGetDeviceNode(DeviceRelations->Objects[0]);
691
692 /* Free the DEVICE_RELATIONS structure, it's not needed anymore */
693 ExFreePool(DeviceRelations);
694
695 return Status;
696}
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
NTSTATUS IopSynchronousCall(IN PDEVICE_OBJECT DeviceObject, IN PIO_STACK_LOCATION IoStackLocation, OUT PVOID *Information)
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2165
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639
@ TargetDeviceRelation
Definition: iotypes.h:2158
#define IRP_MN_QUERY_DEVICE_RELATIONS

Referenced by IoGetRelatedTargetDevice(), and IoRegisterPlugPlayNotification().

◆ IopReadyDeviceObjects()

VOID NTAPI IopReadyDeviceObjects ( IN PDRIVER_OBJECT  Driver)

Definition at line 34 of file device.c.

35{
37 PAGED_CODE();
38
39 /* Set the driver as initialized */
40 Driver->Flags |= DRVO_INITIALIZED;
41 DeviceObject = Driver->DeviceObject;
42 while (DeviceObject)
43 {
44 /* Set every device as initialized too */
45 DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
46 DeviceObject = DeviceObject->NextDevice;
47 }
48}
_Must_inspect_result_ _In_ WDFDRIVER Driver
Definition: wdfcontrol.h:83
#define DRVO_INITIALIZED
Definition: iotypes.h:4473

Referenced by IopInitializeDriverModule().

◆ IopStartNextPacket()

VOID NTAPI IopStartNextPacket ( IN PDEVICE_OBJECT  DeviceObject,
IN BOOLEAN  Cancelable 
)

Definition at line 540 of file device.c.

542{
544 PIRP Irp;
546
547 /* Acquire the cancel lock if this is cancelable */
549
550 /* Clear the current IRP */
551 DeviceObject->CurrentIrp = NULL;
552
553 /* Remove an entry from the queue */
554 Entry = KeRemoveDeviceQueue(&DeviceObject->DeviceQueue);
555 if (Entry)
556 {
557 /* Get the IRP and set it */
558 Irp = CONTAINING_RECORD(Entry, IRP, Tail.Overlay.DeviceQueueEntry);
559 DeviceObject->CurrentIrp = Irp;
560
561 /* Check if this is a cancelable packet */
562 if (Cancelable)
563 {
564 /* Check if the caller requested no cancellation */
565 if (IoGetDevObjExtension(DeviceObject)->StartIoFlags &
567 {
568 /* He did, so remove the cancel routine */
569 Irp->CancelRoutine = NULL;
570 }
571
572 /* Release the cancel lock */
574 }
575
576 /* Call the Start I/O Routine */
577 DeviceObject->DriverObject->DriverStartIo(DeviceObject, Irp);
578 }
579 else
580 {
581 /* Otherwise, release the cancel lock if we had acquired it */
583 }
584}
_In_ PIRP Irp
Definition: csq.h:116
PKDEVICE_QUEUE_ENTRY NTAPI KeRemoveDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue)
Definition: devqueue.c:153
#define DOE_SIO_NO_CANCEL
Definition: iotypes.h:167
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
Entry
Definition: section.c:5216
Definition: ketypes.h:646
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
_In_ BOOLEAN Cancelable
Definition: iofuncs.h:1258

Referenced by IopStartNextPacketByKeyEx(), and IoStartNextPacket().

◆ IopStartNextPacketByKey()

VOID NTAPI IopStartNextPacketByKey ( IN PDEVICE_OBJECT  DeviceObject,
IN BOOLEAN  Cancelable,
IN ULONG  Key 
)

Definition at line 491 of file device.c.

494{
496 PIRP Irp;
498
499 /* Acquire the cancel lock if this is cancelable */
501
502 /* Clear the current IRP */
503 DeviceObject->CurrentIrp = NULL;
504
505 /* Remove an entry from the queue */
507 if (Entry)
508 {
509 /* Get the IRP and set it */
510 Irp = CONTAINING_RECORD(Entry, IRP, Tail.Overlay.DeviceQueueEntry);
511 DeviceObject->CurrentIrp = Irp;
512
513 /* Check if this is a cancelable packet */
514 if (Cancelable)
515 {
516 /* Check if the caller requested no cancellation */
517 if (IoGetDevObjExtension(DeviceObject)->StartIoFlags &
519 {
520 /* He did, so remove the cancel routine */
521 Irp->CancelRoutine = NULL;
522 }
523
524 /* Release the cancel lock */
526 }
527
528 /* Call the Start I/O Routine */
529 DeviceObject->DriverObject->DriverStartIo(DeviceObject, Irp);
530 }
531 else
532 {
533 /* Otherwise, release the cancel lock if we had acquired it */
535 }
536}
PKDEVICE_QUEUE_ENTRY NTAPI KeRemoveByKeyDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue, IN ULONG SortKey)
Definition: devqueue.c:197

Referenced by IopStartNextPacketByKeyEx(), and IoStartNextPacketByKey().

◆ IopStartNextPacketByKeyEx()

VOID NTAPI IopStartNextPacketByKeyEx ( IN PDEVICE_OBJECT  DeviceObject,
IN ULONG  Key,
IN ULONG  Flags 
)

Definition at line 588 of file device.c.

591{
592 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
593 ULONG CurrentKey = Key;
594 ULONG CurrentFlags = Flags;
595
596 /* Get the device extension and start the packet loop */
597 DeviceExtension = IoGetDevObjExtension(DeviceObject);
598 while (TRUE)
599 {
600 /* Increase the count */
601 if (InterlockedIncrement(&DeviceExtension->StartIoCount) > 1)
602 {
603 /*
604 * We've already called the routine once...
605 * All we have to do is save the key and add the new flags
606 */
607 DeviceExtension->StartIoFlags |= CurrentFlags;
608 DeviceExtension->StartIoKey = CurrentKey;
609 }
610 else
611 {
612 /* Mask out the current packet flags and key */
613 DeviceExtension->StartIoFlags &= ~(DOE_SIO_WITH_KEY |
616 DeviceExtension->StartIoKey = 0;
617
618 /* Check if this is a packet start with key */
620 {
621 /* Start the packet with a key */
624 TRUE : FALSE,
625 CurrentKey);
626 }
627 else if (Flags & DOE_SIO_NO_KEY)
628 {
629 /* Start the packet */
632 TRUE : FALSE);
633 }
634 }
635
636 /* Decrease the Start I/O count and check if it's 0 now */
637 if (!InterlockedDecrement(&DeviceExtension->StartIoCount))
638 {
639 /* Get the current active key and flags */
640 CurrentKey = DeviceExtension->StartIoKey;
641 CurrentFlags = DeviceExtension->StartIoFlags & (DOE_SIO_WITH_KEY |
644
645 /* Check if we should still loop */
646 if (!(CurrentFlags & (DOE_SIO_WITH_KEY | DOE_SIO_NO_KEY))) break;
647 }
648 else
649 {
650 /* There are still Start I/Os active, so quit this loop */
651 break;
652 }
653 }
654}
#define InterlockedIncrement
Definition: armddk.h:53
_In_ D3DDDI_VIDEO_PRESENT_TARGET_ID _In_ ULONG _In_ ULONG Flags
Definition: dispmprt.h:245
#define DOE_SIO_WITH_KEY
Definition: iotypes.h:164
#define DOE_SIO_NO_KEY
Definition: iotypes.h:163
#define DOE_SIO_CANCELABLE
Definition: iotypes.h:165
VOID NTAPI IopStartNextPacketByKey(IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN Cancelable, IN ULONG Key)
Definition: device.c:491
VOID NTAPI IopStartNextPacket(IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN Cancelable)
Definition: device.c:540

Referenced by IoStartNextPacket(), and IoStartNextPacketByKey().

◆ IopUnloadDevice()

VOID NTAPI IopUnloadDevice ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 395 of file device.c.

396{
399
400 /* Check if deletion is pending */
401 if (ThisExtension->ExtensionFlags & DOE_DELETE_PENDING)
402 {
403 if (DeviceObject->AttachedDevice)
404 {
405 DPRINT("Device object is in the middle of a device stack\n");
406 return;
407 }
408
409 if (DeviceObject->ReferenceCount)
410 {
411 DPRINT("Device object still has %d references\n", DeviceObject->ReferenceCount);
412 return;
413 }
414
415 /* Check if we have a Security Descriptor */
416 if (DeviceObject->SecurityDescriptor)
417 {
418 /* Dereference it */
419 ObDereferenceSecurityDescriptor(DeviceObject->SecurityDescriptor, 1);
420 }
421
422 /* Remove the device from the list */
424
425 /* Dereference the keep-alive */
427 }
428
429 /* We can't unload a non-PnP driver here */
430 if (DriverObject->Flags & DRVO_LEGACY_DRIVER)
431 {
432 DPRINT("Not a PnP driver! '%wZ' will not be unloaded!\n", &DriverObject->DriverName);
433 return;
434 }
435
436 /* Return if we've already called unload (maybe we're in it?) */
437 if (DriverObject->Flags & DRVO_UNLOAD_INVOKED) return;
438
439 /* We can't unload unless there's an unload handler */
440 if (!DriverObject->DriverUnload)
441 {
442 DPRINT1("No DriverUnload function on PnP driver! '%wZ' will not be unloaded!\n", &DriverObject->DriverName);
443 return;
444 }
445
446 /* Bail if there are still devices present */
447 if (DriverObject->DeviceObject)
448 {
449 DPRINT("Devices still present! '%wZ' will not be unloaded!\n", &DriverObject->DriverName);
450 return;
451 }
452
453 DPRINT1("Unloading driver '%wZ' (automatic)\n", &DriverObject->DriverName);
454
455 /* Set the unload invoked flag */
457
458 /* Unload it */
459 DriverObject->DriverUnload(DriverObject);
460
461 /* Make object temporary so it can be deleted */
463}
VOID NTAPI ObDereferenceSecurityDescriptor(IN PSECURITY_DESCRIPTOR SecurityDescriptor, IN ULONG Count)
Definition: obsdcach.c:287
#define DPRINT
Definition: sndvol32.h:73
#define DRVO_LEGACY_DRIVER
Definition: iotypes.h:2228

Referenced by IoDeleteDevice(), IoDetachDevice(), IopDecrementDeviceObjectRef(), and IopDereferenceDeviceObject().

◆ IopVerifyDeviceObjectOnStack()

BOOLEAN NTAPI IopVerifyDeviceObjectOnStack ( IN PDEVICE_OBJECT  BaseDeviceObject,
IN PDEVICE_OBJECT  TopDeviceObjectHint 
)

Definition at line 700 of file device.c.

702{
705 PDEVICE_OBJECT LoopObject;
706
707 ASSERT(BaseDeviceObject != NULL);
708
709 Result = FALSE;
710 /* Simply loop on the device stack and try to find our hint */
712 for (LoopObject = BaseDeviceObject; ; LoopObject = LoopObject->AttachedDevice)
713 {
714 /* It was found, it's a success */
715 if (LoopObject == TopDeviceObjectHint)
716 {
717 Result = TRUE;
718 break;
719 }
720
721 /* End of the stack, that's a failure - default */
722 if (LoopObject == NULL)
723 {
724 break;
725 }
726 }
728
729 return Result;
730}
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409

Referenced by IoGetRelatedDeviceObject(), and IopCheckTopDeviceHint().

◆ IoRegisterLastChanceShutdownNotification()

NTSTATUS NTAPI IoRegisterLastChanceShutdownNotification ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 1680 of file device.c.

1681{
1683
1684 /* Allocate the shutdown entry */
1686 sizeof(SHUTDOWN_ENTRY),
1689
1690 /* Set the DO */
1691 Entry->DeviceObject = DeviceObject;
1692
1693 /* Reference it so it doesn't go away */
1695
1696 /* Insert it into the list */
1698 &Entry->ShutdownList,
1700
1701 /* Set the shutdown registered flag */
1703 return STATUS_SUCCESS;
1704}
#define NonPagedPool
Definition: env_spec_w32.h:307
PLIST_ENTRY NTAPI ExInterlockedInsertHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:114
KSPIN_LOCK ShutdownListLock
Definition: device.c:22
LIST_ENTRY LastChanceShutdownListHead
Definition: device.c:21
Definition: io.h:427
#define TAG_SHUTDOWN_ENTRY
Definition: tag.h:58
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158

Referenced by FxPkgGeneral::PostCreateDeviceInitialize().

◆ IoRegisterShutdownNotification()

NTSTATUS NTAPI IoRegisterShutdownNotification ( PDEVICE_OBJECT  DeviceObject)

Definition at line 1711 of file device.c.

1712{
1714
1715 /* Allocate the shutdown entry */
1717 sizeof(SHUTDOWN_ENTRY),
1720
1721 /* Set the DO */
1722 Entry->DeviceObject = DeviceObject;
1723
1724 /* Reference it so it doesn't go away */
1726
1727 /* Insert it into the list */
1729 &Entry->ShutdownList,
1731
1732 /* Set the shutdown registered flag */
1734 return STATUS_SUCCESS;
1735}
LIST_ENTRY ShutdownListHead
Definition: device.c:21

Referenced by _Function_class_(), DriverEntry(), NdisMRegisterAdapterShutdownHandler(), PcAddAdapterDevice(), FxPkgGeneral::PostCreateDeviceInitialize(), SysAudio_AddDevice(), and UDFMountVolume().

◆ IoSetStartIoAttributes()

VOID NTAPI IoSetStartIoAttributes ( IN PDEVICE_OBJECT  DeviceObject,
IN BOOLEAN  DeferredStartIo,
IN BOOLEAN  NonCancelable 
)

Definition at line 1815 of file device.c.

1818{
1819 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
1820
1821 /* Get the Device Extension */
1822 DeviceExtension = IoGetDevObjExtension(DeviceObject);
1823
1824 /* Set the flags the caller requested */
1825 DeviceExtension->StartIoFlags |= (DeferredStartIo) ? DOE_SIO_DEFERRED : 0;
1826 DeviceExtension->StartIoFlags |= (NonCancelable) ? DOE_SIO_NO_CANCEL : 0;
1827}
#define DOE_SIO_DEFERRED
Definition: iotypes.h:166

Referenced by ClassAddDevice().

◆ IoShutdownPnpDevices()

VOID NTAPI IoShutdownPnpDevices ( VOID  )

Definition at line 126 of file device.c.

127{
128 /* This routine is only used by Driver Verifier to validate shutdown */
129 return;
130}

Referenced by IoShutdownSystem().

◆ IoShutdownSystem()

VOID NTAPI IoShutdownSystem ( IN ULONG  Phase)

Definition at line 134 of file device.c.

135{
136 PLIST_ENTRY ListEntry;
138 PSHUTDOWN_ENTRY ShutdownEntry;
139 IO_STATUS_BLOCK StatusBlock;
140 PIRP Irp;
143
144 /* Initialize an event to wait on */
146
147 /* What phase? */
148 if (Phase == 0)
149 {
150 /* Shutdown PnP */
152
153 /* Loop first-chance shutdown notifications */
156 while (ListEntry)
157 {
158 /* Get the shutdown entry */
159 ShutdownEntry = CONTAINING_RECORD(ListEntry,
161 ShutdownList);
162
163 /* Get the attached device */
165
166 /* Build the shutdown IRP and call the driver */
169 NULL,
170 0,
171 NULL,
172 &Event,
173 &StatusBlock);
174 if (Irp)
175 {
177 if (Status == STATUS_PENDING)
178 {
179 /* Wait on the driver */
181 }
182 }
183
184 /* Remove the flag */
185 ShutdownEntry->DeviceObject->Flags &= ~DO_SHUTDOWN_REGISTERED;
186
187 /* Get rid of our reference to it */
188 ObDereferenceObject(ShutdownEntry->DeviceObject);
189
190 /* Free the shutdown entry and reset the event */
193
194 /* Go to the next entry */
197 }
198 }
199 else if (Phase == 1)
200 {
201 /* Acquire resource forever */
203
204 /* Shutdown disk file systems */
206
207 /* Shutdown cdrom file systems */
209
210 /* Shutdown tape filesystems */
212
213 /* Loop last-chance shutdown notifications */
216 while (ListEntry)
217 {
218 /* Get the shutdown entry */
219 ShutdownEntry = CONTAINING_RECORD(ListEntry,
221 ShutdownList);
222
223 /* Get the attached device */
225
226 /* Build the shutdown IRP and call the driver */
229 NULL,
230 0,
231 NULL,
232 &Event,
233 &StatusBlock);
234 if (Irp)
235 {
237 if (Status == STATUS_PENDING)
238 {
239 /* Wait on the driver */
241 }
242 }
243
244 /* Remove the flag */
245 ShutdownEntry->DeviceObject->Flags &= ~DO_SHUTDOWN_REGISTERED;
246
247 /* Get rid of our reference to it */
248 ObDereferenceObject(ShutdownEntry->DeviceObject);
249
250 /* Free the shutdown entry and reset the event */
253
254 /* Go to the next entry */
257 }
258
259 }
260}
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define ExAcquireResourceExclusiveLite(res, wait)
Definition: env_spec_w32.h:615
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
PLIST_ENTRY NTAPI ExInterlockedRemoveHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:166
@ NotificationEvent
VOID NTAPI IopShutdownBaseFileSystems(IN PLIST_ENTRY ListHead)
Definition: volume.c:349
LIST_ENTRY IopCdRomFileSystemQueueHead
Definition: volume.c:22
ERESOURCE IopDatabaseResource
Definition: volume.c:20
VOID NTAPI IoShutdownPnpDevices(VOID)
Definition: device.c:126
LIST_ENTRY IopDiskFileSystemQueueHead
Definition: volume.c:21
LIST_ENTRY IopTapeFileSystemQueueHead
Definition: volume.c:22
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1101
#define IoCallDriver
Definition: irp.c:1257
Definition: typedefs.h:120
PDEVICE_OBJECT DeviceObject
Definition: io.h:429
#define STATUS_PENDING
Definition: telnetd.h:14
#define IRP_MJ_SHUTDOWN
@ Executive
Definition: ketypes.h:467

Referenced by PopGracefulShutdown().

◆ IoStartNextPacket()

VOID NTAPI IoStartNextPacket ( IN PDEVICE_OBJECT  DeviceObject,
IN BOOLEAN  Cancelable 
)

Definition at line 1864 of file device.c.

1866{
1867 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
1868
1869 /* Get the Device Extension */
1870 DeviceExtension = IoGetDevObjExtension(DeviceObject);
1871
1872 /* Check if deferred start was requested */
1873 if (DeviceExtension->StartIoFlags & DOE_SIO_DEFERRED)
1874 {
1875 /* Call our internal function to handle the defered case */
1877 0,
1880 }
1881 else
1882 {
1883 /* Call the normal routine */
1885 }
1886}
VOID NTAPI IopStartNextPacketByKeyEx(IN PDEVICE_OBJECT DeviceObject, IN ULONG Key, IN ULONG Flags)
Definition: device.c:588

Referenced by BeepCancel(), BeepStartIo(), ClassIoComplete(), ClassIoCompleteAssociated(), ClasspStartIo(), i8042PacketDpc(), ScsiPortDpcForIsr(), ScsiPortStartIo(), SpiProcessCompletedRequest(), TransferPktComplete(), and USBSTOR_QueueNextRequest().

◆ IoStartNextPacketByKey()

VOID NTAPI IoStartNextPacketByKey ( IN PDEVICE_OBJECT  DeviceObject,
IN BOOLEAN  Cancelable,
IN ULONG  Key 
)

Definition at line 1834 of file device.c.

1837{
1838 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
1839
1840 /* Get the Device Extension */
1841 DeviceExtension = IoGetDevObjExtension(DeviceObject);
1842
1843 /* Check if deferred start was requested */
1844 if (DeviceExtension->StartIoFlags & DOE_SIO_DEFERRED)
1845 {
1846 /* Call our internal function to handle the defered case */
1848 Key,
1851 }
1852 else
1853 {
1854 /* Call the normal routine */
1856 }
1857}

◆ IoStartPacket()

VOID NTAPI IoStartPacket ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp,
IN PULONG  Key,
IN PDRIVER_CANCEL  CancelFunction 
)

Definition at line 1893 of file device.c.

1897{
1898 BOOLEAN Stat;
1899 KIRQL OldIrql, CancelIrql;
1900
1901 /* Raise to dispatch level */
1903
1904 /* Check if we should acquire the cancel lock */
1905 if (CancelFunction)
1906 {
1907 /* Acquire and set it */
1908 IoAcquireCancelSpinLock(&CancelIrql);
1909 Irp->CancelRoutine = CancelFunction;
1910 }
1911
1912 /* Check if we have a key */
1913 if (Key)
1914 {
1915 /* Insert by key */
1917 &Irp->Tail.Overlay.DeviceQueueEntry,
1918 *Key);
1919 }
1920 else
1921 {
1922 /* Insert without a key */
1923 Stat = KeInsertDeviceQueue(&DeviceObject->DeviceQueue,
1924 &Irp->Tail.Overlay.DeviceQueueEntry);
1925 }
1926
1927 /* Check if this was a first insert */
1928 if (!Stat)
1929 {
1930 /* Set the IRP */
1931 DeviceObject->CurrentIrp = Irp;
1932
1933 /* Check if this is a cancelable packet */
1934 if (CancelFunction)
1935 {
1936 /* Check if the caller requested no cancellation */
1937 if (IoGetDevObjExtension(DeviceObject)->StartIoFlags &
1939 {
1940 /* He did, so remove the cancel routine */
1941 Irp->CancelRoutine = NULL;
1942 }
1943
1944 /* Release the cancel lock */
1945 IoReleaseCancelSpinLock(CancelIrql);
1946 }
1947
1948 /* Call the Start I/O function */
1949 DeviceObject->DriverObject->DriverStartIo(DeviceObject, Irp);
1950 }
1951 else
1952 {
1953 /* The packet was inserted... check if we have a cancel function */
1954 if (CancelFunction)
1955 {
1956 /* Check if the IRP got cancelled */
1957 if (Irp->Cancel)
1958 {
1959 /*
1960 * Set the cancel IRQL, clear the currnet cancel routine and
1961 * call ours
1962 */
1963 Irp->CancelIrql = CancelIrql;
1964 Irp->CancelRoutine = NULL;
1966 }
1967 else
1968 {
1969 /* Otherwise, release the lock */
1970 IoReleaseCancelSpinLock(CancelIrql);
1971 }
1972 }
1973 }
1974
1975 /* Return back to previous IRQL */
1977}
BOOLEAN NTAPI KeInsertByKeyDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue, IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry, IN ULONG SortKey)
Definition: devqueue.c:83
BOOLEAN NTAPI KeInsertDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue, IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry)
Definition: devqueue.c:41
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
#define Stat
Definition: syshdrs.h:78
_In_ PIRP _In_opt_ PULONG _In_opt_ PDRIVER_CANCEL CancelFunction
Definition: iofuncs.h:1277

Referenced by BeepDeviceControl(), ClassReadWrite(), i8042KbdInternalDeviceControl(), ScsiPortDispatchScsi(), ScsiPortIoTimer(), SermouseInternalDeviceControl(), SpiGetNextRequestFromLun(), USBSTOR_HandleInternalDeviceControl(), USBSTOR_QueueNextRequest(), and USBSTOR_QueueRelease().

◆ IoUnregisterShutdownNotification()

VOID NTAPI IoUnregisterShutdownNotification ( PDEVICE_OBJECT  DeviceObject)

Definition at line 1742 of file device.c.

1743{
1744 PSHUTDOWN_ENTRY ShutdownEntry;
1745 PLIST_ENTRY NextEntry;
1746 KIRQL OldIrql;
1747
1748 /* Remove the flag */
1749 DeviceObject->Flags &= ~DO_SHUTDOWN_REGISTERED;
1750
1751 /* Acquire the shutdown lock and loop the shutdown list */
1753 NextEntry = ShutdownListHead.Flink;
1754 while (NextEntry != &ShutdownListHead)
1755 {
1756 /* Get the entry */
1757 ShutdownEntry = CONTAINING_RECORD(NextEntry,
1759 ShutdownList);
1760
1761 /* Get if the DO matches */
1762 if (ShutdownEntry->DeviceObject == DeviceObject)
1763 {
1764 /* Remove it from the list */
1765 RemoveEntryList(NextEntry);
1766 NextEntry = NextEntry->Blink;
1767
1768 /* Free the entry */
1769 ExFreePoolWithTag(ShutdownEntry, TAG_SHUTDOWN_ENTRY);
1770
1771 /* Get rid of our reference to it */
1773 }
1774
1775 /* Go to the next entry */
1776 NextEntry = NextEntry->Flink;
1777 }
1778
1779 /* Now loop the last chance list */
1781 while (NextEntry != &LastChanceShutdownListHead)
1782 {
1783 /* Get the entry */
1784 ShutdownEntry = CONTAINING_RECORD(NextEntry,
1786 ShutdownList);
1787
1788 /* Get if the DO matches */
1789 if (ShutdownEntry->DeviceObject == DeviceObject)
1790 {
1791 /* Remove it from the list */
1792 RemoveEntryList(NextEntry);
1793 NextEntry = NextEntry->Blink;
1794
1795 /* Free the entry */
1796 ExFreePoolWithTag(ShutdownEntry, TAG_SHUTDOWN_ENTRY);
1797
1798 /* Get rid of our reference to it */
1800 }
1801
1802 /* Go to the next entry */
1803 NextEntry = NextEntry->Flink;
1804 }
1805
1806 /* Release the shutdown lock */
1808}
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121

Referenced by FreeDeviceData(), IoDeleteDevice(), MountMgrUnload(), NdisMDeregisterAdapterShutdownHandler(), FxPkgGeneral::PostCreateDeviceInitialize(), UDFCleanupVCB(), and UDFDoDismountSequence().

Variable Documentation

◆ IopCdRomFileSystemQueueHead

LIST_ENTRY IopCdRomFileSystemQueueHead
extern

Definition at line 22 of file volume.c.

Referenced by IoShutdownSystem().

◆ IopDatabaseResource

ERESOURCE IopDatabaseResource
extern

Definition at line 20 of file volume.c.

Referenced by IoShutdownSystem().

◆ IopDeviceObjectNumber

ULONG IopDeviceObjectNumber = 0

Definition at line 20 of file device.c.

Referenced by IoCreateDevice().

◆ IopDiskFileSystemQueueHead

LIST_ENTRY IopDiskFileSystemQueueHead
extern

Definition at line 21 of file volume.c.

Referenced by IoShutdownSystem().

◆ IopTapeFileSystemQueueHead

LIST_ENTRY IopTapeFileSystemQueueHead
extern

Definition at line 22 of file volume.c.

Referenced by IoShutdownSystem().

◆ LastChanceShutdownListHead

◆ ShutdownListHead

◆ ShutdownListLock