ReactOS 0.4.17-dev-1196-gb6224c3
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 920 of file device.c.

923{
927
928 /* Call the helper routine for an attach operation */
929 Status = IopGetDeviceObjectPointer(TargetDeviceName,
931 &FileObject,
934 if (!NT_SUCCESS(Status)) return Status;
935
936 /* Attach the device */
939 AttachedDevice);
940
941 /* Dereference it */
943 return Status;
944}
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:987
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:266
_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 954 of file device.c.

956{
957 PDEVICE_OBJECT AttachedDevice;
959
960 /* Do the Attach */
962 if (!AttachedDevice) Status = STATUS_NO_SUCH_DEVICE;
963
964 /* Return the status */
965 return Status;
966}
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:973
#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 987 of file device.c.

990{
991 /* Call the internal function */
994 AttachedToDeviceObject))
995 {
996 /* Nothing found */
998 }
999
1000 /* Success! */
1001 return STATUS_SUCCESS;
1002}

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 1038 of file device.c.

1045{
1046 WCHAR AutoNameBuffer[20];
1047 UNICODE_STRING AutoName;
1048 PDEVICE_OBJECT CreatedDeviceObject;
1049 PDEVOBJ_EXTENSION DeviceObjectExtension;
1052 ULONG AlignedDeviceExtensionSize;
1053 ULONG TotalSize;
1054 HANDLE TempHandle;
1055 PACL Dacl;
1057 PAGED_CODE();
1058
1059 /* Check if we have to generate a name */
1061 {
1062 /* Generate it */
1063 _swprintf(AutoNameBuffer,
1064 L"\\Device\\%08lx",
1066
1067 /* Initialize the name */
1068 RtlInitUnicodeString(&AutoName, AutoNameBuffer);
1069 DeviceName = &AutoName;
1070 }
1071
1072 /* Get the security descriptor */
1075 DeviceName != NULL,
1077 &Dacl,
1078 NULL);
1079
1080 /* Initialize the Object Attributes */
1082 DeviceName,
1084 NULL,
1085 ReturnedSD);
1086
1087 /* Honor the internal I/O System case (in)sensitivity */
1089
1090 /* Honor the exclusive flag */
1091 if (Exclusive) ObjectAttributes.Attributes |= OBJ_EXCLUSIVE;
1092
1093 /* Create a permanent object for named devices */
1094 if (DeviceName) ObjectAttributes.Attributes |= OBJ_PERMANENT;
1095
1096 /* Align the Extension Size to 8-bytes */
1097 AlignedDeviceExtensionSize = ALIGN_UP_BY(DeviceExtensionSize,
1099
1100 /* Total Size */
1101 TotalSize = AlignedDeviceExtensionSize +
1102 sizeof(DEVICE_OBJECT) +
1104
1105 /* Create the Device Object */
1106 *DeviceObject = NULL;
1110 KernelMode,
1111 NULL,
1112 TotalSize,
1113 0,
1114 0,
1115 (PVOID*)&CreatedDeviceObject);
1116 if (!NT_SUCCESS(Status))
1117 {
1118 if (Dacl != NULL) ExFreePoolWithTag(Dacl, 'eSoI');
1119
1120 return Status;
1121 }
1122
1123 /* Clear the whole Object and extension so we don't null stuff manually */
1124 RtlZeroMemory(CreatedDeviceObject, TotalSize);
1125
1126 /*
1127 * Setup the Type and Size. Note that we don't use the aligned size,
1128 * because that's only padding for the DevObjExt and not part of the Object.
1129 */
1130 CreatedDeviceObject->Type = IO_TYPE_DEVICE;
1131 CreatedDeviceObject->Size = sizeof(DEVICE_OBJECT) + (USHORT)DeviceExtensionSize;
1132
1133 /* The kernel extension is after the driver internal extension */
1134 DeviceObjectExtension = (PDEVOBJ_EXTENSION)
1135 ((ULONG_PTR)(CreatedDeviceObject + 1) +
1136 AlignedDeviceExtensionSize);
1137
1138 /* Set the Type and Size. Question: why is Size 0 on Windows? */
1139 DeviceObjectExtension->Type = IO_TYPE_DEVICE_OBJECT_EXTENSION;
1140 DeviceObjectExtension->Size = 0;
1141
1142 /* Initialize with Power Manager */
1143 PoInitializeDeviceObject(DeviceObjectExtension);
1144
1145 /* Link the Object and Extension */
1146 DeviceObjectExtension->DeviceObject = CreatedDeviceObject;
1147 CreatedDeviceObject->DeviceObjectExtension = DeviceObjectExtension;
1148
1149 /* Set Device Object Data */
1150 CreatedDeviceObject->DeviceType = DeviceType;
1151 CreatedDeviceObject->Characteristics = DeviceCharacteristics;
1152 CreatedDeviceObject->DeviceExtension = DeviceExtensionSize ?
1153 CreatedDeviceObject + 1 :
1154 NULL;
1155 CreatedDeviceObject->StackSize = 1;
1156 CreatedDeviceObject->AlignmentRequirement = 0;
1157
1158 /* Set the Flags */
1159 CreatedDeviceObject->Flags = DO_DEVICE_INITIALIZING;
1160 if (Exclusive) CreatedDeviceObject->Flags |= DO_EXCLUSIVE;
1161 if (DeviceName) CreatedDeviceObject->Flags |= DO_DEVICE_HAS_NAME;
1162
1163 /* Attach a Vpb for Disks and Tapes, and create the Device Lock */
1164 if ((CreatedDeviceObject->DeviceType == FILE_DEVICE_DISK) ||
1165 (CreatedDeviceObject->DeviceType == FILE_DEVICE_VIRTUAL_DISK) ||
1166 (CreatedDeviceObject->DeviceType == FILE_DEVICE_CD_ROM) ||
1167 (CreatedDeviceObject->DeviceType == FILE_DEVICE_TAPE))
1168 {
1169 /* Create Vpb */
1170 Status = IopCreateVpb(CreatedDeviceObject);
1171 if (!NT_SUCCESS(Status))
1172 {
1173 if (Dacl != NULL) ExFreePoolWithTag(Dacl, 'eSoI');
1174
1175 /* Dereference the device object and fail */
1176 ObDereferenceObject(CreatedDeviceObject);
1177 return Status;
1178 }
1179
1180 /* Initialize Lock Event */
1181 KeInitializeEvent(&CreatedDeviceObject->DeviceLock,
1183 TRUE);
1184 }
1185
1186 /* Set the right Sector Size */
1187 switch (DeviceType)
1188 {
1189 /* All disk systems */
1191 case FILE_DEVICE_DISK:
1193
1194 /* The default is 512 bytes */
1195 CreatedDeviceObject->SectorSize = 512;
1196 break;
1197
1198 /* CD-ROM file systems */
1200
1201 /* The default is 2048 bytes */
1202 CreatedDeviceObject->SectorSize = 2048;
1203 }
1204
1205 /* Create the Device Queue */
1206 if ((CreatedDeviceObject->DeviceType == FILE_DEVICE_DISK_FILE_SYSTEM) ||
1207 (CreatedDeviceObject->DeviceType == FILE_DEVICE_FILE_SYSTEM) ||
1208 (CreatedDeviceObject->DeviceType == FILE_DEVICE_CD_ROM_FILE_SYSTEM) ||
1209 (CreatedDeviceObject->DeviceType == FILE_DEVICE_NETWORK_FILE_SYSTEM) ||
1210 (CreatedDeviceObject->DeviceType == FILE_DEVICE_TAPE_FILE_SYSTEM))
1211 {
1212 /* Simple FS Devices, they don't need a real Device Queue */
1213 InitializeListHead(&CreatedDeviceObject->Queue.ListEntry);
1214 }
1215 else
1216 {
1217 /* An actual Device, initialize its DQ */
1218 KeInitializeDeviceQueue(&CreatedDeviceObject->DeviceQueue);
1219 }
1220
1221 /* Insert the Object */
1222 Status = ObInsertObject(CreatedDeviceObject,
1223 NULL,
1225 1,
1226 (PVOID*)&CreatedDeviceObject,
1227 &TempHandle);
1228 if (!NT_SUCCESS(Status))
1229 {
1230 if (Dacl != NULL) ExFreePoolWithTag(Dacl, 'eSoI');
1231
1232 return Status;
1233 }
1234
1235 /* Now do the final linking */
1237 ASSERT((DriverObject->Flags & DRVO_UNLOAD_INVOKED) == 0);
1238 CreatedDeviceObject->DriverObject = DriverObject;
1239 IopEditDeviceList(DriverObject, CreatedDeviceObject, IopAdd);
1240
1241 /* Link with the power manager */
1242 if (CreatedDeviceObject->Vpb) PoVolumeDevice(CreatedDeviceObject);
1243
1244 /* Close the temporary handle and return to caller */
1245 ObCloseHandle(TempHandle, KernelMode);
1246 *DeviceObject = CreatedDeviceObject;
1247
1248 if (Dacl != NULL) ExFreePoolWithTag(Dacl, 'eSoI');
1249
1250 return STATUS_SUCCESS;
1251}
#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:785
VOID NTAPI IopEditDeviceList(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT DeviceObject, IN IOP_DEVICE_LIST_OPERATION Type)
Definition: device.c:341
ULONG IopDeviceObjectNumber
Definition: device.c:20
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3411
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:2962
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:1049
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:2240
#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 1261 of file device.c.

1262{
1264
1265 /* Check if the device is registered for shutdown notifications */
1267 {
1268 /* Call the shutdown notifications */
1270 }
1271
1272 /* Check if it has a timer */
1274 if (Timer)
1275 {
1276 /* Remove it and free it */
1279 }
1280
1281 /* Check if the device has a name */
1282 if (DeviceObject->Flags & DO_DEVICE_HAS_NAME)
1283 {
1284 /* It does, make it temporary so we can remove it */
1286 }
1287
1288 /* Set the pending delete flag */
1290
1291 /* Unlink with the power manager */
1293
1294 /* Check if the device object can be unloaded */
1295 if (!DeviceObject->ReferenceCount) IopUnloadDevice(DeviceObject);
1296}
#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:397
VOID NTAPI IoUnregisterShutdownNotification(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1744
VOID NTAPI ObMakeTemporaryObject(IN PVOID ObjectBody)
Definition: oblife.c:1459
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(), FdcFdoPnp(), FdcFdoQueryBusRelations(), FdcPdoDeleteDevice(), 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(), PciDeleteBusChildren(), PciFdoIrpRemoveDevice(), 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 1306 of file device.c.

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

Referenced by _Dispatch_type_(), AtaAddChannel(), AtaFdoRemoveDevice(), Bus_AddDevice(), CmBattAddBattery(), CmBattCreateFdo(), CmBattRemoveDevice(), CompBattAddDevice(), CreateGreenFdo(), CreateTestDevices(), DestroyPortDriver(), do_shutdown(), FdcFdoPnp(), 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(), PciFdoIrpRemoveDevice(), 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 1332 of file device.c.

1336{
1337 ULONG ActualDevices = 1;
1338 PDEVICE_OBJECT CurrentDevice = DriverObject->DeviceObject;
1339 KIRQL OldIrql;
1340
1341 /* Lock the device list while we enumerate it */
1343
1344 /* Find out how many devices we'll enumerate */
1345 while ((CurrentDevice = CurrentDevice->NextDevice)) ActualDevices++;
1346
1347 /* Go back to the first */
1348 CurrentDevice = DriverObject->DeviceObject;
1349
1350 /* Start by at least returning this */
1351 *ActualNumberDeviceObjects = ActualDevices;
1352
1353 /* Check if we can support so many */
1354 if ((ActualDevices * sizeof(PDEVICE_OBJECT)) > DeviceObjectListSize)
1355 {
1356 /* Fail because the buffer was too small */
1359 }
1360
1361 /* Check if the caller wanted the device list */
1362 if (DeviceObjectList)
1363 {
1364 /* Loop through all the devices */
1365 while (ActualDevices)
1366 {
1367 /* Reference each Device */
1368 ObReferenceObject(CurrentDevice);
1369
1370 /* Add it to the list */
1371 *DeviceObjectList = CurrentDevice;
1372
1373 /* Go to the next one */
1374 CurrentDevice = CurrentDevice->NextDevice;
1375 ActualDevices--;
1376 DeviceObjectList++;
1377 }
1378 }
1379
1380 /* Release the device list lock */
1382
1383 /* Return the status */
1384 return STATUS_SUCCESS;
1385}
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 1395 of file device.c.

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

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 1416 of file device.c.

1417{
1418 KIRQL OldIrql;
1419
1420 /* Retrieve and reference the attached device under the device list lock */
1425
1426 return DeviceObject;
1427}
PDEVICE_OBJECT NTAPI IoGetAttachedDevice(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1395

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(), PciSendDeviceUsageToParent(), 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 1646 of file device.c.

1647{
1649
1650 /*
1651 * If the FILE_OBJECT's VPB is defined,
1652 * get the device from it.
1653 */
1654 if ((FileObject->Vpb) && (FileObject->Vpb->DeviceObject))
1655 {
1656 /* Use the VPB's Device Object's */
1657 DeviceObject = FileObject->Vpb->DeviceObject;
1658 }
1659 else if (!(FileObject->Flags & FO_DIRECT_DEVICE_OPEN) &&
1660 (FileObject->DeviceObject->Vpb) &&
1661 (FileObject->DeviceObject->Vpb->DeviceObject))
1662 {
1663 /* Use the VPB's File System Object */
1664 DeviceObject = FileObject->DeviceObject->Vpb->DeviceObject;
1665 }
1666 else
1667 {
1668 /* Use the FO's Device Object */
1669 DeviceObject = FileObject->DeviceObject;
1670 }
1671
1672 /* Return the device object we found */
1674 return DeviceObject;
1675}
#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 1434 of file device.c.

1435{
1436 KIRQL OldIrql;
1437
1438 /* Retrieve and reference the lowest attached device under the device list lock */
1443
1444 return DeviceObject;
1445}
PDEVICE_OBJECT NTAPI IopGetLowestDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:318

Referenced by FltpEnumerateFileSystemVolumes(), FltpGetBaseDeviceObjectName(), ReferenceInterfacePdo(), 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 1455 of file device.c.

1459{
1460 /* Call the helper routine for a normal operation */
1463 FileObject,
1465 0);
1466}
_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(), ReferenceInterfacePdo(), 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 1473 of file device.c.

1475{
1476 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
1477 PVPB Vpb;
1478 KIRQL OldIrql;
1480
1481 /* Make sure there's a VPB */
1482 if (!FileSystemDeviceObject->Vpb) return STATUS_INVALID_PARAMETER;
1483
1484 /* Acquire it */
1486
1487 /* Get the Device Extension */
1488 DeviceExtension = IoGetDevObjExtension(FileSystemDeviceObject);
1489
1490 /* Make sure this one has a VPB too */
1491 Vpb = DeviceExtension->Vpb;
1492 if (Vpb)
1493 {
1494 /* Make sure that it's mounted */
1495 if ((Vpb->ReferenceCount) &&
1496 (Vpb->Flags & VPB_MOUNTED))
1497 {
1498 /* Return the Disk Device Object */
1499 *DiskDeviceObject = Vpb->RealDevice;
1500
1501 /* Reference it and return success */
1502 ObReferenceObject(Vpb->RealDevice);
1504 }
1505 else
1506 {
1507 /* It's not, so return failure */
1509 }
1510 }
1511 else
1512 {
1513 /* Fail */
1515 }
1516
1517 /* Release the lock */
1519 return Status;
1520}
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 1527 of file device.c.

1528{
1529 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
1531
1532 /* Make sure it's not getting deleted */
1533 DeviceExtension = IoGetDevObjExtension(DeviceObject);
1534 if (!(DeviceExtension->ExtensionFlags &
1537 {
1538 /* Get the Lower Device Object */
1539 LowerDeviceObject = DeviceExtension->AttachedTo;
1540
1541 /* Check that we got a valid device object */
1543 {
1544 /* We did so let's reference it */
1546 }
1547 }
1548
1549 /* Return it */
1550 return LowerDeviceObject;
1551}
_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 1558 of file device.c.

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

1628{
1631
1632 /* Call the internal helper function */
1635 {
1636 *DeviceObject = DeviceNode->PhysicalDeviceObject;
1637 }
1638 return Status;
1639}
@ DeviceNode
Definition: Node.h:9
NTSTATUS NTAPI IopGetRelatedTargetDevice(IN PFILE_OBJECT FileObject, OUT PDEVICE_NODE *DeviceNode)
Definition: device.c:660

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 71 of file device.c.

75{
76 PDEVICE_OBJECT AttachedDevice;
77 PEXTENDED_DEVOBJ_EXTENSION SourceDeviceExtension;
79
80 /* Lock the device list while attaching the device */
82
83 /* Get the attached device and source extension */
84 AttachedDevice = IoGetAttachedDevice(TargetDevice);
85 SourceDeviceExtension = IoGetDevObjExtension(SourceDevice);
86 ASSERT(SourceDeviceExtension->AttachedTo == NULL);
87
88 /* Make sure that it's in a correct state */
89 if ((AttachedDevice->Flags & DO_DEVICE_INITIALIZING) ||
90 (IoGetDevObjExtension(AttachedDevice)->ExtensionFlags &
93 {
94 /* The device is unloading or being removed */
95 AttachedDevice = NULL;
96 }
97 else
98 {
99 /* Update the attached device fields */
100 AttachedDevice->AttachedDevice = SourceDevice;
101 AttachedDevice->Spare1++;
102
103 /* Update the source with the attached data */
104 SourceDevice->StackSize = AttachedDevice->StackSize + 1;
106 SourceDevice->SectorSize = AttachedDevice->SectorSize;
107
108 /* Check for pending start flag and propagate it */
109 if (IoGetDevObjExtension(AttachedDevice)->ExtensionFlags & DOE_START_PENDING)
111
112 /* Set the attachment in the device extension */
113 SourceDeviceExtension->AttachedTo = AttachedDevice;
114 }
115
116 /* Return the attached device (under the lock) */
117 if (AttachedToDeviceObject)
118 *AttachedToDeviceObject = AttachedDevice;
119
120 /* Release the device list lock */
122
123 return AttachedDevice;
124}
#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 785 of file device.c.

791{
792 PACL Dacl;
793 ULONG AceId;
796 BOOLEAN AdminsSet, WorldSet;
797
798 PAGED_CODE();
799
800 /* Zero our output vars */
801 if (OutputFlags) *OutputFlags = 0;
802
803 *OutputDacl = NULL;
804
805 /* For FSD, easy use SePublicDefaultUnrestrictedDacl */
810 {
813 OutputFlags);
814 goto Quit;
815 }
816 /* For storage devices with a name and floppy attribute,
817 * use SePublicOpenUnrestrictedDacl
818 */
827 {
830 OutputFlags);
831 goto Quit;
832 }
833
834 /* The rest...
835 * We will rely on SePublicDefaultUnrestrictedDacl as well
836 */
838 if (Dacl == NULL)
839 {
840 return NULL;
841 }
842
843 /* Copy our DACL */
845
846 /* Now, browse the DACL to make sure we have everything we want in them,
847 * including permissions
848 */
849 AceId = 0;
850 AdminsSet = FALSE;
851 WorldSet = FALSE;
852 while (NT_SUCCESS(RtlGetAce(Dacl, AceId, (PVOID *)&Ace)))
853 {
854 /* Admins must acess and in RWX, set it */
855 if (RtlEqualSid(SeAliasAdminsSid, &Ace->SidStart))
856 {
858 AdminsSet = TRUE;
859 }
860
861 /* World can read a CD_ROM device */
863 {
864 SetFlag(Ace->Mask, GENERIC_READ);
865 WorldSet = TRUE;
866 }
867
868 ++AceId;
869 }
870
871 /* AdminSid was present and set (otherwise, we have big trouble) */
872 ASSERT(AdminsSet);
873
874 /* If CD_ROM device, we've set world permissions */
875 if (DeviceType == FILE_DEVICE_CD_ROM) ASSERT(WorldSet);
876
877 /* Now our DACL is correct, setup the security descriptor */
880
881 /* We've set DACL */
882 if (OutputFlags) *OutputFlags |= DACL_SET;
883
884 /* Return DACL to allow later freeing */
885 *OutputDacl = Dacl;
887
888Quit:
889 /* Only return SD if we succeed */
890 if (!NT_SUCCESS(Status))
891 {
892 return NULL;
893 }
894
895 return SecurityDescriptor;
896}
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:736
#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 736 of file device.c.

739{
740 PACL Dacl;
742
743 /* Select the DACL the caller wants */
744 switch (Type)
745 {
746 case RestrictedPublic:
748 break;
749
752 break;
753
756 break;
757
760 break;
761
762 case SystemDefault:
764 break;
765
766 default:
767 ASSERT(FALSE);
769 }
770
771 /* Create the SD and set the DACL caller wanted */
775
776 /* We've set DACL */
777 if (OutputFlags) *OutputFlags |= DACL_SET;
778
779 /* Done */
780 return Status;
781}
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
63
64 /* Dereference the driver object, referenced in IoCreateDevice */
65 if (DeviceObject->DriverObject)
66 ObDereferenceObject(DeviceObject->DriverObject);
67}
PDEVICE_NODE FASTCALL IopGetDeviceNode(IN PDEVICE_OBJECT DeviceObject)
NTSTATUS IopFreeDeviceNode(IN PDEVICE_NODE DeviceNode)
VOID PiPropReleaseDevice(_In_ PDEVICE_OBJECT DeviceObject)
Definition: pnpprop.c:1731

Referenced by IopCreateObjectTypes().

◆ IopDereferenceDeviceObject()

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

Definition at line 469 of file device.c.

471{
472 /* Sanity check */
473 ASSERT(DeviceObject->ReferenceCount);
474
475 /* Dereference the device */
476 InterlockedDecrement(&DeviceObject->ReferenceCount);
477
478 /*
479 * Check if we can unload it and it's safe to unload (or if we're forcing
480 * an unload, which is OK too).
481 */
482 ASSERT(!ForceUnload);
483 if (!(DeviceObject->ReferenceCount) &&
485 {
486 /* Unload it */
488 }
489}
#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 341 of file device.c.

344{
345 PDEVICE_OBJECT Previous;
347
348 /* Lock the device list while we edit it */
350
351 /* Check the type of operation */
352 if (Type == IopRemove)
353 {
354 /* Get the current device and check if it's the current one */
355 Previous = DeviceObject->DriverObject->DeviceObject;
356 if (Previous == DeviceObject)
357 {
358 /* It is, simply unlink this one directly */
359 DeviceObject->DriverObject->DeviceObject =
360 DeviceObject->NextDevice;
361 }
362 else
363 {
364 /* It's not, so loop until we find the device */
365 while (Previous->NextDevice != DeviceObject)
366 {
367 /* Not this one, keep moving */
368 if (!Previous->NextDevice)
369 {
370 DPRINT1("Failed to remove PDO %p (not found)\n",
372
373 ASSERT(FALSE);
375 return;
376 }
377 Previous = Previous->NextDevice;
378 }
379
380 /* We found it, now unlink us */
381 Previous->NextDevice = DeviceObject->NextDevice;
382 }
383 }
384 else
385 {
386 /* Link the device object and the driver object */
387 DeviceObject->NextDevice = DriverObject->DeviceObject;
388 DriverObject->DeviceObject = DeviceObject;
389 }
390
391 /* Release the device list lock */
393}
#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 266 of file device.c.

271{
273 IO_STATUS_BLOCK StatusBlock;
274 PFILE_OBJECT LocalFileObject;
277
278 /* Open the Device */
282 NULL,
283 NULL);
284
285 /* Honor the internal I/O System case (in)sensitivity */
287
291 &StatusBlock,
292 0,
293 FILE_NON_DIRECTORY_FILE | AttachFlag);
294 if (!NT_SUCCESS(Status)) return Status;
295
296 /* Get File Object */
298 0,
301 (PVOID*)&LocalFileObject,
302 NULL);
303 if (NT_SUCCESS(Status))
304 {
305 /* Return the requested data */
306 *DeviceObject = IoGetRelatedDeviceObject(LocalFileObject);
307 *FileObject = LocalFileObject;
308 }
309
310 /* Close the handle */
312
313 return Status;
314}
#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:1558
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 318 of file device.c.

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

Referenced by IoGetDeviceAttachmentBaseRef().

◆ IopGetRelatedTargetDevice()

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

Definition at line 660 of file device.c.

662{
665 PDEVICE_RELATIONS DeviceRelations;
667
669
670 /* Get DeviceObject related to given FileObject */
673
674 /* Define input parameters */
675 Stack.MajorFunction = IRP_MJ_PNP;
676 Stack.MinorFunction = IRP_MN_QUERY_DEVICE_RELATIONS;
677 Stack.Parameters.QueryDeviceRelations.Type = TargetDeviceRelation;
678 Stack.FileObject = FileObject;
679
680 /* Call the driver to query all relations (IRP_MJ_PNP) */
682 &Stack,
683 (PVOID)&DeviceRelations);
684 if (!NT_SUCCESS(Status)) return Status;
685
686 /* Make sure it's not NULL and contains only one object */
687 ASSERT(DeviceRelations);
688 ASSERT(DeviceRelations->Count == 1);
689
690 /* Finally get the device node */
691 *DeviceNode = IopGetDeviceNode(DeviceRelations->Objects[0]);
693
694 /* Free the DEVICE_RELATIONS structure, it's not needed anymore */
695 ExFreePool(DeviceRelations);
696
697 return Status;
698}
#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:4486

Referenced by IopInitializeDriverModule().

◆ IopStartNextPacket()

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

Definition at line 542 of file device.c.

544{
546 PIRP Irp;
548
549 /* Acquire the cancel lock if this is cancelable */
551
552 /* Clear the current IRP */
553 DeviceObject->CurrentIrp = NULL;
554
555 /* Remove an entry from the queue */
556 Entry = KeRemoveDeviceQueue(&DeviceObject->DeviceQueue);
557 if (Entry)
558 {
559 /* Get the IRP and set it */
560 Irp = CONTAINING_RECORD(Entry, IRP, Tail.Overlay.DeviceQueueEntry);
561 DeviceObject->CurrentIrp = Irp;
562
563 /* Check if this is a cancelable packet */
564 if (Cancelable)
565 {
566 /* Check if the caller requested no cancellation */
567 if (IoGetDevObjExtension(DeviceObject)->StartIoFlags &
569 {
570 /* He did, so remove the cancel routine */
571 Irp->CancelRoutine = NULL;
572 }
573
574 /* Release the cancel lock */
576 }
577
578 /* Call the Start I/O Routine */
579 DeviceObject->DriverObject->DriverStartIo(DeviceObject, Irp);
580 }
581 else
582 {
583 /* Otherwise, release the cancel lock if we had acquired it */
585 }
586}
PKDEVICE_QUEUE_ENTRY NTAPI KeRemoveDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue)
Definition: devqueue.c:153
_In_ PIRP Irp
Definition: kse.h:79
#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 493 of file device.c.

496{
498 PIRP Irp;
500
501 /* Acquire the cancel lock if this is cancelable */
503
504 /* Clear the current IRP */
505 DeviceObject->CurrentIrp = NULL;
506
507 /* Remove an entry from the queue */
509 if (Entry)
510 {
511 /* Get the IRP and set it */
512 Irp = CONTAINING_RECORD(Entry, IRP, Tail.Overlay.DeviceQueueEntry);
513 DeviceObject->CurrentIrp = Irp;
514
515 /* Check if this is a cancelable packet */
516 if (Cancelable)
517 {
518 /* Check if the caller requested no cancellation */
519 if (IoGetDevObjExtension(DeviceObject)->StartIoFlags &
521 {
522 /* He did, so remove the cancel routine */
523 Irp->CancelRoutine = NULL;
524 }
525
526 /* Release the cancel lock */
528 }
529
530 /* Call the Start I/O Routine */
531 DeviceObject->DriverObject->DriverStartIo(DeviceObject, Irp);
532 }
533 else
534 {
535 /* Otherwise, release the cancel lock if we had acquired it */
537 }
538}
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 590 of file device.c.

593{
594 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
595 ULONG CurrentKey = Key;
596 ULONG CurrentFlags = Flags;
597
598 /* Get the device extension and start the packet loop */
599 DeviceExtension = IoGetDevObjExtension(DeviceObject);
600 while (TRUE)
601 {
602 /* Increase the count */
603 if (InterlockedIncrement(&DeviceExtension->StartIoCount) > 1)
604 {
605 /*
606 * We've already called the routine once...
607 * All we have to do is save the key and add the new flags
608 */
609 DeviceExtension->StartIoFlags |= CurrentFlags;
610 DeviceExtension->StartIoKey = CurrentKey;
611 }
612 else
613 {
614 /* Mask out the current packet flags and key */
615 DeviceExtension->StartIoFlags &= ~(DOE_SIO_WITH_KEY |
618 DeviceExtension->StartIoKey = 0;
619
620 /* Check if this is a packet start with key */
622 {
623 /* Start the packet with a key */
626 TRUE : FALSE,
627 CurrentKey);
628 }
629 else if (Flags & DOE_SIO_NO_KEY)
630 {
631 /* Start the packet */
634 TRUE : FALSE);
635 }
636 }
637
638 /* Decrease the Start I/O count and check if it's 0 now */
639 if (!InterlockedDecrement(&DeviceExtension->StartIoCount))
640 {
641 /* Get the current active key and flags */
642 CurrentKey = DeviceExtension->StartIoKey;
643 CurrentFlags = DeviceExtension->StartIoFlags & (DOE_SIO_WITH_KEY |
646
647 /* Check if we should still loop */
648 if (!(CurrentFlags & (DOE_SIO_WITH_KEY | DOE_SIO_NO_KEY))) break;
649 }
650 else
651 {
652 /* There are still Start I/Os active, so quit this loop */
653 break;
654 }
655 }
656}
#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:493
VOID NTAPI IopStartNextPacket(IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN Cancelable)
Definition: device.c:542

Referenced by IoStartNextPacket(), and IoStartNextPacketByKey().

◆ IopUnloadDevice()

VOID NTAPI IopUnloadDevice ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 397 of file device.c.

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

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

◆ IopVerifyDeviceObjectOnStack()

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

Definition at line 702 of file device.c.

704{
707 PDEVICE_OBJECT LoopObject;
708
709 ASSERT(BaseDeviceObject != NULL);
710
711 Result = FALSE;
712 /* Simply loop on the device stack and try to find our hint */
714 for (LoopObject = BaseDeviceObject; ; LoopObject = LoopObject->AttachedDevice)
715 {
716 /* It was found, it's a success */
717 if (LoopObject == TopDeviceObjectHint)
718 {
719 Result = TRUE;
720 break;
721 }
722
723 /* End of the stack, that's a failure - default */
724 if (LoopObject == NULL)
725 {
726 break;
727 }
728 }
730
731 return Result;
732}
_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 1682 of file device.c.

1683{
1685
1686 /* Allocate the shutdown entry */
1688 sizeof(SHUTDOWN_ENTRY),
1691
1692 /* Set the DO */
1693 Entry->DeviceObject = DeviceObject;
1694
1695 /* Reference it so it doesn't go away */
1697
1698 /* Insert it into the list */
1700 &Entry->ShutdownList,
1702
1703 /* Set the shutdown registered flag */
1705 return STATUS_SUCCESS;
1706}
#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 1713 of file device.c.

1714{
1716
1717 /* Allocate the shutdown entry */
1719 sizeof(SHUTDOWN_ENTRY),
1722
1723 /* Set the DO */
1724 Entry->DeviceObject = DeviceObject;
1725
1726 /* Reference it so it doesn't go away */
1728
1729 /* Insert it into the list */
1731 &Entry->ShutdownList,
1733
1734 /* Set the shutdown registered flag */
1736 return STATUS_SUCCESS;
1737}
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 1817 of file device.c.

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

Referenced by ClassAddDevice().

◆ IoShutdownPnpDevices()

VOID NTAPI IoShutdownPnpDevices ( VOID  )

Definition at line 128 of file device.c.

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

Referenced by IoShutdownSystem().

◆ IoShutdownSystem()

VOID NTAPI IoShutdownSystem ( IN ULONG  Phase)

Definition at line 136 of file device.c.

137{
138 PLIST_ENTRY ListEntry;
140 PSHUTDOWN_ENTRY ShutdownEntry;
141 IO_STATUS_BLOCK StatusBlock;
142 PIRP Irp;
145
146 /* Initialize an event to wait on */
148
149 /* What phase? */
150 if (Phase == 0)
151 {
152 /* Shutdown PnP */
154
155 /* Loop first-chance shutdown notifications */
158 while (ListEntry)
159 {
160 /* Get the shutdown entry */
161 ShutdownEntry = CONTAINING_RECORD(ListEntry,
163 ShutdownList);
164
165 /* Get the attached device */
167
168 /* Build the shutdown IRP and call the driver */
171 NULL,
172 0,
173 NULL,
174 &Event,
175 &StatusBlock);
176 if (Irp)
177 {
179 if (Status == STATUS_PENDING)
180 {
181 /* Wait on the driver */
183 }
184 }
185
186 /* Remove the flag */
187 ShutdownEntry->DeviceObject->Flags &= ~DO_SHUTDOWN_REGISTERED;
188
189 /* Get rid of our reference to it */
190 ObDereferenceObject(ShutdownEntry->DeviceObject);
191
192 /* Free the shutdown entry and reset the event */
195
196 /* Go to the next entry */
199 }
200 }
201 else if (Phase == 1)
202 {
203 /* Acquire resource forever */
205
206 /* Shutdown disk file systems */
208
209 /* Shutdown cdrom file systems */
211
212 /* Shutdown tape filesystems */
214
215 /* Loop last-chance shutdown notifications */
218 while (ListEntry)
219 {
220 /* Get the shutdown entry */
221 ShutdownEntry = CONTAINING_RECORD(ListEntry,
223 ShutdownList);
224
225 /* Get the attached device */
227
228 /* Build the shutdown IRP and call the driver */
231 NULL,
232 0,
233 NULL,
234 &Event,
235 &StatusBlock);
236 if (Irp)
237 {
239 if (Status == STATUS_PENDING)
240 {
241 /* Wait on the driver */
243 }
244 }
245
246 /* Remove the flag */
247 ShutdownEntry->DeviceObject->Flags &= ~DO_SHUTDOWN_REGISTERED;
248
249 /* Get rid of our reference to it */
250 ObDereferenceObject(ShutdownEntry->DeviceObject);
251
252 /* Free the shutdown entry and reset the event */
255
256 /* Go to the next entry */
259 }
260
261 }
262}
_Check_return_ _In_ DXGK_EVENT_TYPE _In_ ULONG Event
Definition: dispmprt.h:1287
#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:128
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 1866 of file device.c.

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

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 1836 of file device.c.

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

◆ IoStartPacket()

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

Definition at line 1895 of file device.c.

1899{
1900 BOOLEAN Stat;
1901 KIRQL OldIrql, CancelIrql;
1902
1903 /* Raise to dispatch level */
1905
1906 /* Check if we should acquire the cancel lock */
1907 if (CancelFunction)
1908 {
1909 /* Acquire and set it */
1910 IoAcquireCancelSpinLock(&CancelIrql);
1911 Irp->CancelRoutine = CancelFunction;
1912 }
1913
1914 /* Check if we have a key */
1915 if (Key)
1916 {
1917 /* Insert by key */
1919 &Irp->Tail.Overlay.DeviceQueueEntry,
1920 *Key);
1921 }
1922 else
1923 {
1924 /* Insert without a key */
1925 Stat = KeInsertDeviceQueue(&DeviceObject->DeviceQueue,
1926 &Irp->Tail.Overlay.DeviceQueueEntry);
1927 }
1928
1929 /* Check if this was a first insert */
1930 if (!Stat)
1931 {
1932 /* Set the IRP */
1933 DeviceObject->CurrentIrp = Irp;
1934
1935 /* Check if this is a cancelable packet */
1936 if (CancelFunction)
1937 {
1938 /* Check if the caller requested no cancellation */
1939 if (IoGetDevObjExtension(DeviceObject)->StartIoFlags &
1941 {
1942 /* He did, so remove the cancel routine */
1943 Irp->CancelRoutine = NULL;
1944 }
1945
1946 /* Release the cancel lock */
1947 IoReleaseCancelSpinLock(CancelIrql);
1948 }
1949
1950 /* Call the Start I/O function */
1951 DeviceObject->DriverObject->DriverStartIo(DeviceObject, Irp);
1952 }
1953 else
1954 {
1955 /* The packet was inserted... check if we have a cancel function */
1956 if (CancelFunction)
1957 {
1958 /* Check if the IRP got cancelled */
1959 if (Irp->Cancel)
1960 {
1961 /*
1962 * Set the cancel IRQL, clear the currnet cancel routine and
1963 * call ours
1964 */
1965 Irp->CancelIrql = CancelIrql;
1966 Irp->CancelRoutine = NULL;
1968 }
1969 else
1970 {
1971 /* Otherwise, release the lock */
1972 IoReleaseCancelSpinLock(CancelIrql);
1973 }
1974 }
1975 }
1976
1977 /* Return back to previous IRQL */
1979}
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 1744 of file device.c.

1745{
1746 PSHUTDOWN_ENTRY ShutdownEntry;
1747 PLIST_ENTRY NextEntry;
1748 KIRQL OldIrql;
1749
1750 /* Remove the flag */
1751 DeviceObject->Flags &= ~DO_SHUTDOWN_REGISTERED;
1752
1753 /* Acquire the shutdown lock and loop the shutdown list */
1755 NextEntry = ShutdownListHead.Flink;
1756 while (NextEntry != &ShutdownListHead)
1757 {
1758 /* Get the entry */
1759 ShutdownEntry = CONTAINING_RECORD(NextEntry,
1761 ShutdownList);
1762
1763 /* Get if the DO matches */
1764 if (ShutdownEntry->DeviceObject == DeviceObject)
1765 {
1766 /* Remove it from the list */
1767 RemoveEntryList(NextEntry);
1768 NextEntry = NextEntry->Blink;
1769
1770 /* Free the entry */
1771 ExFreePoolWithTag(ShutdownEntry, TAG_SHUTDOWN_ENTRY);
1772
1773 /* Get rid of our reference to it */
1775 }
1776
1777 /* Go to the next entry */
1778 NextEntry = NextEntry->Flink;
1779 }
1780
1781 /* Now loop the last chance list */
1783 while (NextEntry != &LastChanceShutdownListHead)
1784 {
1785 /* Get the entry */
1786 ShutdownEntry = CONTAINING_RECORD(NextEntry,
1788 ShutdownList);
1789
1790 /* Get if the DO matches */
1791 if (ShutdownEntry->DeviceObject == DeviceObject)
1792 {
1793 /* Remove it from the list */
1794 RemoveEntryList(NextEntry);
1795 NextEntry = NextEntry->Blink;
1796
1797 /* Free the entry */
1798 ExFreePoolWithTag(ShutdownEntry, TAG_SHUTDOWN_ENTRY);
1799
1800 /* Get rid of our reference to it */
1802 }
1803
1804 /* Go to the next entry */
1805 NextEntry = NextEntry->Flink;
1806 }
1807
1808 /* Release the shutdown lock */
1810}
#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