ReactOS 0.4.16-dev-2621-gb0c8475
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 914 of file device.c.

917{
921
922 /* Call the helper routine for an attach operation */
923 Status = IopGetDeviceObjectPointer(TargetDeviceName,
925 &FileObject,
928 if (!NT_SUCCESS(Status)) return Status;
929
930 /* Attach the device */
933 AttachedDevice);
934
935 /* Dereference it */
937 return Status;
938}
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
Status
Definition: gdiplustypes.h:25
#define IO_ATTACH_DEVICE_API
Definition: iotypes.h:219
#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:981
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 948 of file device.c.

950{
951 PDEVICE_OBJECT AttachedDevice;
953
954 /* Do the Attach */
956 if (!AttachedDevice) Status = STATUS_NO_SUCH_DEVICE;
957
958 /* Return the status */
959 return Status;
960}
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:967
#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 981 of file device.c.

984{
985 /* Call the internal function */
988 AttachedToDeviceObject))
989 {
990 /* Nothing found */
992 }
993
994 /* Success! */
995 return STATUS_SUCCESS;
996}

Referenced by _Dispatch_type_(), AddDeviceInternal(), ClassAddDevice(), FdcAddDevice(), FltpAttachDeviceObject(), IoAttachDevice(), PciIdeXAddDevice(), 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 1032 of file device.c.

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

1253{
1255
1256 /* Check if the device is registered for shutdown notifications */
1258 {
1259 /* Call the shutdown notifications */
1261 }
1262
1263 /* Check if it has a timer */
1265 if (Timer)
1266 {
1267 /* Remove it and free it */
1270 }
1271
1272 /* Check if the device has a name */
1273 if (DeviceObject->Flags & DO_DEVICE_HAS_NAME)
1274 {
1275 /* It does, make it temporary so we can remove it */
1277 }
1278
1279 /* Set the pending delete flag */
1281
1282 /* Unlink with the power manager */
1284
1285 /* Check if the device object can be unloaded */
1286 if (!DeviceObject->ReferenceCount) IopUnloadDevice(DeviceObject);
1287}
#define DO_SHUTDOWN_REGISTERED
Definition: env_spec_w32.h:403
#define DOE_DELETE_PENDING
Definition: iotypes.h:150
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:391
VOID NTAPI IoUnregisterShutdownNotification(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1735
VOID NTAPI ObMakeTemporaryObject(IN PVOID ObjectBody)
Definition: oblife.c:1449
VOID NTAPI PoRemoveVolumeDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: povolume.c:103
#define TAG_IO_TIMER
Definition: tag.h:93

Referenced by _Dispatch_type_(), _Function_class_(), _Requires_lock_held_(), AddDeviceInternal(), BeepUnload(), Bus_AddDevice(), Bus_DestroyPdo(), Bus_PlugInDevice(), CdDeleteVcb(), 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(), PciIdeXAddDevice(), PciIdeXFdoRemoveDevice(), 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 1297 of file device.c.

1298{
1299 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
1300
1301 /* Sanity check */
1302 DeviceExtension = IoGetDevObjExtension(TargetDevice->AttachedDevice);
1303 ASSERT(DeviceExtension->AttachedTo == TargetDevice);
1304
1305 /* Remove the attachment */
1306 DeviceExtension->AttachedTo = NULL;
1307 TargetDevice->AttachedDevice = NULL;
1308
1309 /* Check if it's ok to delete this device */
1310 if ((IoGetDevObjExtension(TargetDevice)->ExtensionFlags & DOE_DELETE_PENDING) &&
1311 !(TargetDevice->ReferenceCount))
1312 {
1313 /* It is, do it */
1315 }
1316}
PDEVICE_OBJECT AttachedTo
Definition: iotypes.h:1092

Referenced by _Dispatch_type_(), 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(), PciIdeXAddDevice(), PciIdeXFdoRemoveDevice(), 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 1323 of file device.c.

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

Referenced by FltpEnumerateFileSystemVolumes().

◆ IoGetAttachedDevice()

PDEVICE_OBJECT NTAPI IoGetAttachedDevice ( PDEVICE_OBJECT  DeviceObject)

Definition at line 1386 of file device.c.

1387{
1388 /* Get the last attached device */
1389 while (DeviceObject->AttachedDevice)
1390 {
1391 /* Move to the next one */
1392 DeviceObject = DeviceObject->AttachedDevice;
1393 }
1394
1395 /* Return it */
1396 return DeviceObject;
1397}

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

1408{
1409 KIRQL OldIrql;
1410
1411 /* Retrieve and reference the attached device under the device list lock */
1416
1417 return DeviceObject;
1418}
PDEVICE_OBJECT NTAPI IoGetAttachedDevice(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1386

Referenced by 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(), PciIdeXPdoRepeatRequest(), 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 1637 of file device.c.

1638{
1640
1641 /*
1642 * If the FILE_OBJECT's VPB is defined,
1643 * get the device from it.
1644 */
1645 if ((FileObject->Vpb) && (FileObject->Vpb->DeviceObject))
1646 {
1647 /* Use the VPB's Device Object's */
1648 DeviceObject = FileObject->Vpb->DeviceObject;
1649 }
1650 else if (!(FileObject->Flags & FO_DIRECT_DEVICE_OPEN) &&
1651 (FileObject->DeviceObject->Vpb) &&
1652 (FileObject->DeviceObject->Vpb->DeviceObject))
1653 {
1654 /* Use the VPB's File System Object */
1655 DeviceObject = FileObject->DeviceObject->Vpb->DeviceObject;
1656 }
1657 else
1658 {
1659 /* Use the FO's Device Object */
1660 DeviceObject = FileObject->DeviceObject;
1661 }
1662
1663 /* Return the device object we found */
1665 return DeviceObject;
1666}
#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 1425 of file device.c.

1426{
1427 KIRQL OldIrql;
1428
1429 /* Retrieve and reference the lowest attached device under the device list lock */
1434
1435 return DeviceObject;
1436}
PDEVICE_OBJECT NTAPI IopGetLowestDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:312

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

1450{
1451 /* Call the helper routine for a normal operation */
1454 FileObject,
1456 0);
1457}
_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 1464 of file device.c.

1466{
1467 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
1468 PVPB Vpb;
1469 KIRQL OldIrql;
1471
1472 /* Make sure there's a VPB */
1473 if (!FileSystemDeviceObject->Vpb) return STATUS_INVALID_PARAMETER;
1474
1475 /* Acquire it */
1477
1478 /* Get the Device Extension */
1479 DeviceExtension = IoGetDevObjExtension(FileSystemDeviceObject);
1480
1481 /* Make sure this one has a VPB too */
1482 Vpb = DeviceExtension->Vpb;
1483 if (Vpb)
1484 {
1485 /* Make sure that it's mounted */
1486 if ((Vpb->ReferenceCount) &&
1487 (Vpb->Flags & VPB_MOUNTED))
1488 {
1489 /* Return the Disk Device Object */
1490 *DiskDeviceObject = Vpb->RealDevice;
1491
1492 /* Reference it and return success */
1493 ObReferenceObject(Vpb->RealDevice);
1495 }
1496 else
1497 {
1498 /* It's not, so return failure */
1500 }
1501 }
1502 else
1503 {
1504 /* Fail */
1506 }
1507
1508 /* Release the lock */
1510 return Status;
1511}
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 1518 of file device.c.

1519{
1520 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
1522
1523 /* Make sure it's not getting deleted */
1524 DeviceExtension = IoGetDevObjExtension(DeviceObject);
1525 if (!(DeviceExtension->ExtensionFlags &
1528 {
1529 /* Get the Lower Device Object */
1530 LowerDeviceObject = DeviceExtension->AttachedTo;
1531
1532 /* Check that we got a valid device object */
1534 {
1535 /* We did so let's reference it */
1537 }
1538 }
1539
1540 /* Return it */
1541 return LowerDeviceObject;
1542}
_In_z_ PCCHAR _In_ PDEVICE_OBJECT LowerDeviceObject
Definition: classpnp.h:983
#define DOE_REMOVE_PROCESSED
Definition: iotypes.h:152
#define DOE_UNLOAD_PENDING
Definition: iotypes.h:149
#define DOE_REMOVE_PENDING
Definition: iotypes.h:151

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

◆ IoGetRelatedDeviceObject()

PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject ( IN PFILE_OBJECT  FileObject)

Definition at line 1549 of file device.c.

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

1619{
1622
1623 /* Call the internal helper function */
1626 {
1627 *DeviceObject = DeviceNode->PhysicalDeviceObject;
1628 }
1629 return Status;
1630}
@ DeviceNode
Definition: Node.h:9
NTSTATUS NTAPI IopGetRelatedTargetDevice(IN PFILE_OBJECT FileObject, OUT PDEVICE_NODE *DeviceNode)
Definition: device.c:654

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

785{
786 PACL Dacl;
787 ULONG AceId;
790 BOOLEAN AdminsSet, WorldSet;
791
792 PAGED_CODE();
793
794 /* Zero our output vars */
795 if (OutputFlags) *OutputFlags = 0;
796
797 *OutputDacl = NULL;
798
799 /* For FSD, easy use SePublicDefaultUnrestrictedDacl */
804 {
807 OutputFlags);
808 goto Quit;
809 }
810 /* For storage devices with a name and floppy attribute,
811 * use SePublicOpenUnrestrictedDacl
812 */
821 {
824 OutputFlags);
825 goto Quit;
826 }
827
828 /* The rest...
829 * We will rely on SePublicDefaultUnrestrictedDacl as well
830 */
832 if (Dacl == NULL)
833 {
834 return NULL;
835 }
836
837 /* Copy our DACL */
839
840 /* Now, browse the DACL to make sure we have everything we want in them,
841 * including permissions
842 */
843 AceId = 0;
844 AdminsSet = FALSE;
845 WorldSet = FALSE;
846 while (NT_SUCCESS(RtlGetAce(Dacl, AceId, (PVOID *)&Ace)))
847 {
848 /* Admins must acess and in RWX, set it */
849 if (RtlEqualSid(SeAliasAdminsSid, &Ace->SidStart))
850 {
852 AdminsSet = TRUE;
853 }
854
855 /* World can read a CD_ROM device */
857 {
858 SetFlag(Ace->Mask, GENERIC_READ);
859 WorldSet = TRUE;
860 }
861
862 ++AceId;
863 }
864
865 /* AdminSid was present and set (otherwise, we have big trouble) */
866 ASSERT(AdminsSet);
867
868 /* If CD_ROM device, we've set world permissions */
869 if (DeviceType == FILE_DEVICE_CD_ROM) ASSERT(WorldSet);
870
871 /* Now our DACL is correct, setup the security descriptor */
874
875 /* We've set DACL */
876 if (OutputFlags) *OutputFlags |= DACL_SET;
877
878 /* Return DACL to allow later freeing */
879 *OutputDacl = Dacl;
881
882Quit:
883 /* Only return SD if we succeed */
884 if (!NT_SUCCESS(Status))
885 {
886 return NULL;
887 }
888
889 return SecurityDescriptor;
890}
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:730
#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 730 of file device.c.

733{
734 PACL Dacl;
736
737 /* Select the DACL the caller wants */
738 switch (Type)
739 {
740 case RestrictedPublic:
742 break;
743
746 break;
747
750 break;
751
754 break;
755
756 case SystemDefault:
758 break;
759
760 default:
761 ASSERT(FALSE);
763 }
764
765 /* Create the SD and set the DACL caller wanted */
769
770 /* We've set DACL */
771 if (OutputFlags) *OutputFlags |= DACL_SET;
772
773 /* Done */
774 return Status;
775}
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 463 of file device.c.

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

338{
339 PDEVICE_OBJECT Previous;
341
342 /* Lock the device list while we edit it */
344
345 /* Check the type of operation */
346 if (Type == IopRemove)
347 {
348 /* Get the current device and check if it's the current one */
349 Previous = DeviceObject->DriverObject->DeviceObject;
350 if (Previous == DeviceObject)
351 {
352 /* It is, simply unlink this one directly */
353 DeviceObject->DriverObject->DeviceObject =
354 DeviceObject->NextDevice;
355 }
356 else
357 {
358 /* It's not, so loop until we find the device */
359 while (Previous->NextDevice != DeviceObject)
360 {
361 /* Not this one, keep moving */
362 if (!Previous->NextDevice)
363 {
364 DPRINT1("Failed to remove PDO %p (not found)\n",
366
367 ASSERT(FALSE);
369 return;
370 }
371 Previous = Previous->NextDevice;
372 }
373
374 /* We found it, now unlink us */
375 Previous->NextDevice = DeviceObject->NextDevice;
376 }
377 }
378 else
379 {
380 /* Link the device object and the driver object */
381 DeviceObject->NextDevice = DriverObject->DeviceObject;
382 DriverObject->DeviceObject = DeviceObject;
383 }
384
385 /* Release the device list lock */
387}
#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);
285 &StatusBlock,
286 0,
287 FILE_NON_DIRECTORY_FILE | AttachFlag);
288 if (!NT_SUCCESS(Status)) return Status;
289
290 /* Get File Object */
292 0,
295 (PVOID*)&LocalFileObject,
296 NULL);
297 if (NT_SUCCESS(Status))
298 {
299 /* Return the requested data */
300 *DeviceObject = IoGetRelatedDeviceObject(LocalFileObject);
301 *FileObject = LocalFileObject;
302 }
303
304 /* Close the handle */
306
307 return Status;
308}
#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:1549
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:494

Referenced by IoAttachDevice(), and IoGetDeviceObjectPointer().

◆ IopGetLowestDevice()

PDEVICE_OBJECT NTAPI IopGetLowestDevice ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 312 of file device.c.

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

Referenced by IoGetDeviceAttachmentBaseRef().

◆ IopGetRelatedTargetDevice()

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

Definition at line 654 of file device.c.

656{
659 PDEVICE_RELATIONS DeviceRelations;
661
663
664 /* Get DeviceObject related to given FileObject */
667
668 /* Define input parameters */
669 Stack.MajorFunction = IRP_MJ_PNP;
670 Stack.MinorFunction = IRP_MN_QUERY_DEVICE_RELATIONS;
671 Stack.Parameters.QueryDeviceRelations.Type = TargetDeviceRelation;
672 Stack.FileObject = FileObject;
673
674 /* Call the driver to query all relations (IRP_MJ_PNP) */
676 &Stack,
677 (PVOID)&DeviceRelations);
678 if (!NT_SUCCESS(Status)) return Status;
679
680 /* Make sure it's not NULL and contains only one object */
681 ASSERT(DeviceRelations);
682 ASSERT(DeviceRelations->Count == 1);
683
684 /* Finally get the device node */
685 *DeviceNode = IopGetDeviceNode(DeviceRelations->Objects[0]);
687
688 /* Free the DEVICE_RELATIONS structure, it's not needed anymore */
689 ExFreePool(DeviceRelations);
690
691 return Status;
692}
#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 536 of file device.c.

538{
540 PIRP Irp;
542
543 /* Acquire the cancel lock if this is cancelable */
545
546 /* Clear the current IRP */
547 DeviceObject->CurrentIrp = NULL;
548
549 /* Remove an entry from the queue */
550 Entry = KeRemoveDeviceQueue(&DeviceObject->DeviceQueue);
551 if (Entry)
552 {
553 /* Get the IRP and set it */
554 Irp = CONTAINING_RECORD(Entry, IRP, Tail.Overlay.DeviceQueueEntry);
555 DeviceObject->CurrentIrp = Irp;
556
557 /* Check if this is a cancelable packet */
558 if (Cancelable)
559 {
560 /* Check if the caller requested no cancellation */
561 if (IoGetDevObjExtension(DeviceObject)->StartIoFlags &
563 {
564 /* He did, so remove the cancel routine */
565 Irp->CancelRoutine = NULL;
566 }
567
568 /* Release the cancel lock */
570 }
571
572 /* Call the Start I/O Routine */
573 DeviceObject->DriverObject->DriverStartIo(DeviceObject, Irp);
574 }
575 else
576 {
577 /* Otherwise, release the cancel lock if we had acquired it */
579 }
580}
_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:163
VOID NTAPI IoReleaseCancelSpinLock(IN KIRQL Irql)
Definition: util.c:150
VOID NTAPI IoAcquireCancelSpinLock(OUT PKIRQL Irql)
Definition: util.c:56
Entry
Definition: section.c:5210
Definition: ketypes.h:630
#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 487 of file device.c.

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

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

Referenced by IoStartNextPacket(), and IoStartNextPacketByKey().

◆ IopUnloadDevice()

VOID NTAPI IopUnloadDevice ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 391 of file device.c.

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

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

1674{
1676
1677 /* Allocate the shutdown entry */
1679 sizeof(SHUTDOWN_ENTRY),
1682
1683 /* Set the DO */
1684 Entry->DeviceObject = DeviceObject;
1685
1686 /* Reference it so it doesn't go away */
1688
1689 /* Insert it into the list */
1691 &Entry->ShutdownList,
1693
1694 /* Set the shutdown registered flag */
1696 return STATUS_SUCCESS;
1697}
#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 1704 of file device.c.

1705{
1707
1708 /* Allocate the shutdown entry */
1710 sizeof(SHUTDOWN_ENTRY),
1713
1714 /* Set the DO */
1715 Entry->DeviceObject = DeviceObject;
1716
1717 /* Reference it so it doesn't go away */
1719
1720 /* Insert it into the list */
1722 &Entry->ShutdownList,
1724
1725 /* Set the shutdown registered flag */
1727 return STATUS_SUCCESS;
1728}
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 1808 of file device.c.

1811{
1812 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
1813
1814 /* Get the Device Extension */
1815 DeviceExtension = IoGetDevObjExtension(DeviceObject);
1816
1817 /* Set the flags the caller requested */
1818 DeviceExtension->StartIoFlags |= (DeferredStartIo) ? DOE_SIO_DEFERRED : 0;
1819 DeviceExtension->StartIoFlags |= (NonCancelable) ? DOE_SIO_NO_CANCEL : 0;
1820}
#define DOE_SIO_DEFERRED
Definition: iotypes.h:162

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:1069
#define IoCallDriver
Definition: irp.c:1225
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 1857 of file device.c.

1859{
1860 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
1861
1862 /* Get the Device Extension */
1863 DeviceExtension = IoGetDevObjExtension(DeviceObject);
1864
1865 /* Check if deferred start was requested */
1866 if (DeviceExtension->StartIoFlags & DOE_SIO_DEFERRED)
1867 {
1868 /* Call our internal function to handle the defered case */
1870 0,
1873 }
1874 else
1875 {
1876 /* Call the normal routine */
1878 }
1879}
VOID NTAPI IopStartNextPacketByKeyEx(IN PDEVICE_OBJECT DeviceObject, IN ULONG Key, IN ULONG Flags)
Definition: device.c:584

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

1830{
1831 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
1832
1833 /* Get the Device Extension */
1834 DeviceExtension = IoGetDevObjExtension(DeviceObject);
1835
1836 /* Check if deferred start was requested */
1837 if (DeviceExtension->StartIoFlags & DOE_SIO_DEFERRED)
1838 {
1839 /* Call our internal function to handle the defered case */
1841 Key,
1844 }
1845 else
1846 {
1847 /* Call the normal routine */
1849 }
1850}

◆ IoStartPacket()

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

Definition at line 1886 of file device.c.

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

1736{
1737 PSHUTDOWN_ENTRY ShutdownEntry;
1738 PLIST_ENTRY NextEntry;
1739 KIRQL OldIrql;
1740
1741 /* Remove the flag */
1742 DeviceObject->Flags &= ~DO_SHUTDOWN_REGISTERED;
1743
1744 /* Acquire the shutdown lock and loop the shutdown list */
1746 NextEntry = ShutdownListHead.Flink;
1747 while (NextEntry != &ShutdownListHead)
1748 {
1749 /* Get the entry */
1750 ShutdownEntry = CONTAINING_RECORD(NextEntry,
1752 ShutdownList);
1753
1754 /* Get if the DO matches */
1755 if (ShutdownEntry->DeviceObject == DeviceObject)
1756 {
1757 /* Remove it from the list */
1758 RemoveEntryList(NextEntry);
1759 NextEntry = NextEntry->Blink;
1760
1761 /* Free the entry */
1762 ExFreePoolWithTag(ShutdownEntry, TAG_SHUTDOWN_ENTRY);
1763
1764 /* Get rid of our reference to it */
1766 }
1767
1768 /* Go to the next entry */
1769 NextEntry = NextEntry->Flink;
1770 }
1771
1772 /* Now loop the last chance list */
1774 while (NextEntry != &LastChanceShutdownListHead)
1775 {
1776 /* Get the entry */
1777 ShutdownEntry = CONTAINING_RECORD(NextEntry,
1779 ShutdownList);
1780
1781 /* Get if the DO matches */
1782 if (ShutdownEntry->DeviceObject == DeviceObject)
1783 {
1784 /* Remove it from the list */
1785 RemoveEntryList(NextEntry);
1786 NextEntry = NextEntry->Blink;
1787
1788 /* Free the entry */
1789 ExFreePoolWithTag(ShutdownEntry, TAG_SHUTDOWN_ENTRY);
1790
1791 /* Get rid of our reference to it */
1793 }
1794
1795 /* Go to the next entry */
1796 NextEntry = NextEntry->Flink;
1797 }
1798
1799 /* Release the shutdown lock */
1801}
#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