ReactOS 0.4.15-dev-5664-g3bf4ef6
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)
 
PDEVICE_OBJECT NTAPI IopAttachDeviceToDeviceStackSafe (IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice, OUT PDEVICE_OBJECT *AttachedToDeviceObject OPTIONAL)
 
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 913 of file device.c.

916{
920
921 /* Call the helper routine for an attach operation */
922 Status = IopGetDeviceObjectPointer(TargetDeviceName,
924 &FileObject,
927 if (!NT_SUCCESS(Status)) return Status;
928
929 /* Attach the device */
932 AttachedDevice);
933
934 /* Dereference it */
936 return Status;
937}
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:25
#define IO_ATTACH_DEVICE_API
Definition: iotypes.h:218
#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:980
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:263
_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 947 of file device.c.

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

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

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

1038{
1039 WCHAR AutoNameBuffer[20];
1040 UNICODE_STRING AutoName;
1041 PDEVICE_OBJECT CreatedDeviceObject;
1042 PDEVOBJ_EXTENSION DeviceObjectExtension;
1045 ULONG AlignedDeviceExtensionSize;
1046 ULONG TotalSize;
1047 HANDLE TempHandle;
1048 PACL Dacl;
1050 PAGED_CODE();
1051
1052 /* Check if we have to generate a name */
1054 {
1055 /* Generate it */
1056 swprintf(AutoNameBuffer,
1057 L"\\Device\\%08lx",
1059
1060 /* Initialize the name */
1061 RtlInitUnicodeString(&AutoName, AutoNameBuffer);
1062 DeviceName = &AutoName;
1063 }
1064
1065 /* Get the security descriptor */
1068 DeviceName != NULL,
1070 &Dacl,
1071 NULL);
1072
1073 /* Initialize the Object Attributes */
1075 DeviceName,
1077 NULL,
1078 ReturnedSD);
1079
1080 /* Honor exclusive flag */
1081 if (Exclusive) ObjectAttributes.Attributes |= OBJ_EXCLUSIVE;
1082
1083 /* Create a permanent object for named devices */
1084 if (DeviceName) ObjectAttributes.Attributes |= OBJ_PERMANENT;
1085
1086 /* Align the Extension Size to 8-bytes */
1087 AlignedDeviceExtensionSize = ALIGN_UP_BY(DeviceExtensionSize,
1089
1090 /* Total Size */
1091 TotalSize = AlignedDeviceExtensionSize +
1092 sizeof(DEVICE_OBJECT) +
1094
1095 /* Create the Device Object */
1096 *DeviceObject = NULL;
1100 KernelMode,
1101 NULL,
1102 TotalSize,
1103 0,
1104 0,
1105 (PVOID*)&CreatedDeviceObject);
1106 if (!NT_SUCCESS(Status))
1107 {
1108 if (Dacl != NULL) ExFreePoolWithTag(Dacl, 'eSoI');
1109
1110 return Status;
1111 }
1112
1113 /* Clear the whole Object and extension so we don't null stuff manually */
1114 RtlZeroMemory(CreatedDeviceObject, TotalSize);
1115
1116 /*
1117 * Setup the Type and Size. Note that we don't use the aligned size,
1118 * because that's only padding for the DevObjExt and not part of the Object.
1119 */
1120 CreatedDeviceObject->Type = IO_TYPE_DEVICE;
1121 CreatedDeviceObject->Size = sizeof(DEVICE_OBJECT) + (USHORT)DeviceExtensionSize;
1122
1123 /* The kernel extension is after the driver internal extension */
1124 DeviceObjectExtension = (PDEVOBJ_EXTENSION)
1125 ((ULONG_PTR)(CreatedDeviceObject + 1) +
1126 AlignedDeviceExtensionSize);
1127
1128 /* Set the Type and Size. Question: why is Size 0 on Windows? */
1129 DeviceObjectExtension->Type = IO_TYPE_DEVICE_OBJECT_EXTENSION;
1130 DeviceObjectExtension->Size = 0;
1131
1132 /* Initialize with Power Manager */
1133 PoInitializeDeviceObject(DeviceObjectExtension);
1134
1135 /* Link the Object and Extension */
1136 DeviceObjectExtension->DeviceObject = CreatedDeviceObject;
1137 CreatedDeviceObject->DeviceObjectExtension = DeviceObjectExtension;
1138
1139 /* Set Device Object Data */
1140 CreatedDeviceObject->DeviceType = DeviceType;
1141 CreatedDeviceObject->Characteristics = DeviceCharacteristics;
1142 CreatedDeviceObject->DeviceExtension = DeviceExtensionSize ?
1143 CreatedDeviceObject + 1 :
1144 NULL;
1145 CreatedDeviceObject->StackSize = 1;
1146 CreatedDeviceObject->AlignmentRequirement = 0;
1147
1148 /* Set the Flags */
1149 CreatedDeviceObject->Flags = DO_DEVICE_INITIALIZING;
1150 if (Exclusive) CreatedDeviceObject->Flags |= DO_EXCLUSIVE;
1151 if (DeviceName) CreatedDeviceObject->Flags |= DO_DEVICE_HAS_NAME;
1152
1153 /* Attach a Vpb for Disks and Tapes, and create the Device Lock */
1154 if ((CreatedDeviceObject->DeviceType == FILE_DEVICE_DISK) ||
1155 (CreatedDeviceObject->DeviceType == FILE_DEVICE_VIRTUAL_DISK) ||
1156 (CreatedDeviceObject->DeviceType == FILE_DEVICE_CD_ROM) ||
1157 (CreatedDeviceObject->DeviceType == FILE_DEVICE_TAPE))
1158 {
1159 /* Create Vpb */
1160 Status = IopCreateVpb(CreatedDeviceObject);
1161 if (!NT_SUCCESS(Status))
1162 {
1163 if (Dacl != NULL) ExFreePoolWithTag(Dacl, 'eSoI');
1164
1165 /* Dereference the device object and fail */
1166 ObDereferenceObject(CreatedDeviceObject);
1167 return Status;
1168 }
1169
1170 /* Initialize Lock Event */
1171 KeInitializeEvent(&CreatedDeviceObject->DeviceLock,
1173 TRUE);
1174 }
1175
1176 /* Set the right Sector Size */
1177 switch (DeviceType)
1178 {
1179 /* All disk systems */
1181 case FILE_DEVICE_DISK:
1183
1184 /* The default is 512 bytes */
1185 CreatedDeviceObject->SectorSize = 512;
1186 break;
1187
1188 /* CD-ROM file systems */
1190
1191 /* The default is 2048 bytes */
1192 CreatedDeviceObject->SectorSize = 2048;
1193 }
1194
1195 /* Create the Device Queue */
1196 if ((CreatedDeviceObject->DeviceType == FILE_DEVICE_DISK_FILE_SYSTEM) ||
1197 (CreatedDeviceObject->DeviceType == FILE_DEVICE_FILE_SYSTEM) ||
1198 (CreatedDeviceObject->DeviceType == FILE_DEVICE_CD_ROM_FILE_SYSTEM) ||
1199 (CreatedDeviceObject->DeviceType == FILE_DEVICE_NETWORK_FILE_SYSTEM) ||
1200 (CreatedDeviceObject->DeviceType == FILE_DEVICE_TAPE_FILE_SYSTEM))
1201 {
1202 /* Simple FS Devices, they don't need a real Device Queue */
1203 InitializeListHead(&CreatedDeviceObject->Queue.ListEntry);
1204 }
1205 else
1206 {
1207 /* An actual Device, initialize its DQ */
1208 KeInitializeDeviceQueue(&CreatedDeviceObject->DeviceQueue);
1209 }
1210
1211 /* Insert the Object */
1212 Status = ObInsertObject(CreatedDeviceObject,
1213 NULL,
1215 1,
1216 (PVOID*)&CreatedDeviceObject,
1217 &TempHandle);
1218 if (!NT_SUCCESS(Status))
1219 {
1220 if (Dacl != NULL) ExFreePoolWithTag(Dacl, 'eSoI');
1221
1222 return Status;
1223 }
1224
1225 /* Now do the final linking */
1227 ASSERT((DriverObject->Flags & DRVO_UNLOAD_INVOKED) == 0);
1228 CreatedDeviceObject->DriverObject = DriverObject;
1229 IopEditDeviceList(DriverObject, CreatedDeviceObject, IopAdd);
1230
1231 /* Link with the power manager */
1232 if (CreatedDeviceObject->Vpb) PoVolumeDevice(CreatedDeviceObject);
1233
1234 /* Close the temporary handle and return to caller */
1235 ObCloseHandle(TempHandle, KernelMode);
1236 *DeviceObject = CreatedDeviceObject;
1237
1238 if (Dacl != NULL) ExFreePoolWithTag(Dacl, 'eSoI');
1239
1240 return STATUS_SUCCESS;
1241}
#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
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:1526
__in PWDFDEVICE_INIT __in BOOLEAN Exclusive
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_EXCLUSIVE
Definition: winternl.h:227
#define OBJ_PERMANENT
Definition: winternl.h:226
POBJECT_TYPE IoDeviceObjectType
Definition: iomgr.c:35
unsigned int ULONG
Definition: retypes.h:1
DeviceType
Definition: mmdrv.h:42
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define KernelMode
Definition: asm.h:34
#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:1593
#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:253
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:778
VOID NTAPI IopEditDeviceList(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT DeviceObject, IN IOP_DEVICE_LIST_OPERATION Type)
Definition: device.c:334
ULONG IopDeviceObjectNumber
Definition: device.c:20
#define L(x)
Definition: ntvdm.h:50
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:951
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:115
#define FILE_DEVICE_DISK_FILE_SYSTEM
Definition: winioctl.h:114
#define FILE_DEVICE_TAPE
Definition: winioctl.h:137
#define FILE_DEVICE_TAPE_FILE_SYSTEM
Definition: winioctl.h:138
#define FILE_DEVICE_CD_ROM
Definition: winioctl.h:108
#define FILE_DEVICE_CD_ROM_FILE_SYSTEM
Definition: winioctl.h:109
#define FILE_DEVICE_NETWORK_FILE_SYSTEM
Definition: winioctl.h:126
#define FILE_DEVICE_DISK
Definition: winioctl.h:113
#define FILE_DEVICE_VIRTUAL_DISK
Definition: winioctl.h:142
ULONG AlignmentRequirement
Definition: env_spec_w32.h:420
PVOID DeviceExtension
Definition: env_spec_w32.h:418
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2169
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
_In_ WDFDEVICE _In_ ULONG DeviceCharacteristics
Definition: wdfdevice.h:2775
_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:2225
#define ObReferenceObject
Definition: obfuncs.h:204
__wchar_t WCHAR
Definition: xmlstorage.h:180

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(), HDA_AddDevice(), HDA_InitCodec(), HidClassAddDevice(), HidClassPDO_CreatePDO(), InitDevice(), InitializeSoundBlaster(), InPortAddDevice(), IntVideoPortCreateAdapterDeviceObject(), IntVideoPortEnumerateChildren(), IopInitializeDevice(), IopInitializePlugPlayServices(), IsaPnpCreateReadPortDO(), KbdHid_AddDevice(), KeyboardAddDevice(), KMix_AddDevice(), KopAddDevice(), KsCreateDevice(), KspCreatePDO(), MouHid_AddDevice(), mount_vol(), Mx::MxCreateDevice(), Mx::MxCreateDeviceSecure(), NdisIAddDevice(), NdisMRegisterDevice(), NtfsMountVolume(), PartitionCreateDevice(), PartMgrAddDevice(), PcAddAdapterDevice(), PciAddDevice(), PciIdeXAddDevice(), PciIdeXFdoQueryBusRelations(), PciPdoCreate(), PcmciaAddDevice(), PdoCreateLunDevice(), PnpRootAddDevice(), PnpRootCreateDevice(), PnpRootDriverEntry(), PnpRootQueryDeviceRelations(), 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 1251 of file device.c.

1252{
1254
1255 /* Check if the device is registered for shutdown notifications */
1257 {
1258 /* Call the shutdown notifications */
1260 }
1261
1262 /* Check if it has a timer */
1264 if (Timer)
1265 {
1266 /* Remove it and free it */
1269 }
1270
1271 /* Check if the device has a name */
1272 if (DeviceObject->Flags & DO_DEVICE_HAS_NAME)
1273 {
1274 /* It does, make it temporary so we can remove it */
1276 }
1277
1278 /* Set the pending delete flag */
1280
1281 /* Unlink with the power manager */
1283
1284 /* Check if the device object can be unloaded */
1285 if (!DeviceObject->ReferenceCount) IopUnloadDevice(DeviceObject);
1286}
#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:129
VOID NTAPI IopUnloadDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:390
VOID NTAPI IoUnregisterShutdownNotification(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1725
VOID NTAPI ObMakeTemporaryObject(IN PVOID ObjectBody)
Definition: oblife.c:1361
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(), 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(), HDA_FDORemoveDevice(), HDA_PDORemoveDevice(), HidClassAddDevice(), HidClassFDO_RemoveDevice(), HidClassPDO_CreatePDO(), HidClassPDO_PnP(), i8042RemoveDevice(), InitDevice(), InitializeSoundBlaster(), InPortAddDevice(), InPortRemoveDevice(), IntVideoPortCreateAdapterDeviceObject(), IntVideoPortDispatchPdoPnp(), IntVideoPortEnumerateChildren(), IntVideoPortFindAdapter(), IopInitializeDevice(), IsaFdoRemoveDevice(), IsaPnpRemoveLogicalDeviceDO(), IsaPnpRemoveReadPortDO(), KbdHid_AddDevice(), KbdHid_Pnp(), KMix_AddDevice(), KopAddDevice(), KsCreateDevice(), KsDefaultDispatchPnp(), KspCreatePDO(), KsServiceBusEnumPnpRequest(), MouHid_AddDevice(), MouHid_Pnp(), mount_vol(), MountMgrUnload(), MupUnload(), Mx::MxDeleteDevice(), NdisIAddDevice(), NdisMDeregisterDevice(), NdisMRegisterDevice(), NullUnload(), PartitionHandleRemove(), PartMgrAddDevice(), PcAddAdapterDevice(), PciAddDevice(), PDO_HandlePnp(), 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 1296 of file device.c.

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

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(), HDA_FDORemoveDevice(), HidClassAddDevice(), HidClassFDO_RemoveDevice(), i8042RemoveDevice(), InPortAddDevice(), InPortRemoveDevice(), IntVideoPortCreateAdapterDeviceObject(), IntVideoPortFindAdapter(), IsaFdoRemoveDevice(), KbdHid_Pnp(), KsCreateBusEnumObject(), KsCreateDevice(), KsDefaultDispatchPnp(), MouHid_Pnp(), Mx::MxDetachDevice(), PciAddDevice(), PciIdeXAddDevice(), 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 1322 of file device.c.

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

Referenced by FltpEnumerateFileSystemVolumes().

◆ IoGetAttachedDevice()

PDEVICE_OBJECT NTAPI IoGetAttachedDevice ( PDEVICE_OBJECT  DeviceObject)

Definition at line 1385 of file device.c.

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

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)

◆ IoGetBaseFileSystemDeviceObject()

PDEVICE_OBJECT NTAPI IoGetBaseFileSystemDeviceObject ( IN PFILE_OBJECT  FileObject)

Definition at line 1627 of file device.c.

1628{
1630
1631 /*
1632 * If the FILE_OBJECT's VPB is defined,
1633 * get the device from it.
1634 */
1635 if ((FileObject->Vpb) && (FileObject->Vpb->DeviceObject))
1636 {
1637 /* Use the VPB's Device Object's */
1638 DeviceObject = FileObject->Vpb->DeviceObject;
1639 }
1640 else if (!(FileObject->Flags & FO_DIRECT_DEVICE_OPEN) &&
1641 (FileObject->DeviceObject->Vpb) &&
1642 (FileObject->DeviceObject->Vpb->DeviceObject))
1643 {
1644 /* Use the VPB's File System Object */
1645 DeviceObject = FileObject->DeviceObject->Vpb->DeviceObject;
1646 }
1647 else
1648 {
1649 /* Use the FO's Device Object */
1650 DeviceObject = FileObject->DeviceObject;
1651 }
1652
1653 /* Return the device object we found */
1655 return DeviceObject;
1656}
#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 1419 of file device.c.

1420{
1421 /* Reference the lowest attached device */
1424 return DeviceObject;
1425}
PDEVICE_OBJECT NTAPI IopGetLowestDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:311

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

1439{
1440 /* Call the helper routine for a normal operation */
1443 FileObject,
1445 0);
1446}
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2658
_In_ PVOID _Out_opt_ PULONG_PTR _Outptr_opt_ PCUNICODE_STRING * ObjectName
Definition: cmfuncs.h:64

Referenced by _Function_class_(), add_device(), add_volume_device(), 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(), mountmgr_notification(), MountMgrNotifyNameChange(), PatchKeyboardDriver(), probe_volume(), QueryDeviceInformation(), QuerySuggestedLinkName(), read_registry(), ReconcileThisDatabaseWithMasterWorker(), RegisterForTargetDeviceNotification(), remove_volume_child(), ReportToMountMgr(), SearchForLegacyDrivers(), SendLinkCreated(), SendLinkDeleted(), SendOnlineNotification(), TestIoVolumeDeviceToDosName(), UDFCheckOtherFSByName(), and volume_arrival().

◆ IoGetDiskDeviceObject()

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

Definition at line 1453 of file device.c.

1455{
1456 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
1457 PVPB Vpb;
1458 KIRQL OldIrql;
1460
1461 /* Make sure there's a VPB */
1462 if (!FileSystemDeviceObject->Vpb) return STATUS_INVALID_PARAMETER;
1463
1464 /* Acquire it */
1466
1467 /* Get the Device Extension */
1468 DeviceExtension = IoGetDevObjExtension(FileSystemDeviceObject);
1469
1470 /* Make sure this one has a VPB too */
1471 Vpb = DeviceExtension->Vpb;
1472 if (Vpb)
1473 {
1474 /* Make sure that it's mounted */
1475 if ((Vpb->ReferenceCount) &&
1476 (Vpb->Flags & VPB_MOUNTED))
1477 {
1478 /* Return the Disk Device Object */
1479 *DiskDeviceObject = Vpb->RealDevice;
1480
1481 /* Reference it and return success */
1482 ObReferenceObject(Vpb->RealDevice);
1484 }
1485 else
1486 {
1487 /* It's not, so return failure */
1489 }
1490 }
1491 else
1492 {
1493 /* Fail */
1495 }
1496
1497 /* Release the lock */
1499 return Status;
1500}
IN OUT PVCB IN PDEVICE_OBJECT IN PVPB Vpb
Definition: fatprocs.h:1675
_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:747
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 1507 of file device.c.

1508{
1509 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
1511
1512 /* Make sure it's not getting deleted */
1513 DeviceExtension = IoGetDevObjExtension(DeviceObject);
1514 if (!(DeviceExtension->ExtensionFlags & (DOE_UNLOAD_PENDING |
1518 {
1519 /* Get the Lower Device Object */
1520 LowerDeviceObject = DeviceExtension->AttachedTo;
1521
1522 /* Check that we got a valid device object */
1524 {
1525 /* We did so let's reference it */
1527 }
1528 }
1529
1530 /* Return it */
1531 return LowerDeviceObject;
1532}
_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 1539 of file device.c.

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

1609{
1612
1613 /* Call the internal helper function */
1616 {
1617 *DeviceObject = DeviceNode->PhysicalDeviceObject;
1618 }
1619 return Status;
1620}
@ DeviceNode
Definition: Node.h:9
NTSTATUS NTAPI IopGetRelatedTargetDevice(IN PFILE_OBJECT FileObject, OUT PDEVICE_NODE *DeviceNode)
Definition: device.c:653

Referenced by FsRtlNotifyVolumeEvent(), and NtSetVolumeInformationFile().

◆ IopAttachDeviceToDeviceStackSafe()

PDEVICE_OBJECT NTAPI IopAttachDeviceToDeviceStackSafe ( IN PDEVICE_OBJECT  SourceDevice,
IN PDEVICE_OBJECT  TargetDevice,
OUT PDEVICE_OBJECT *AttachedToDeviceObject  OPTIONAL 
)

Definition at line 70 of file device.c.

73{
74 PDEVICE_OBJECT AttachedDevice;
75 PEXTENDED_DEVOBJ_EXTENSION SourceDeviceExtension;
76
77 /* Get the Attached Device and source extension */
78 AttachedDevice = IoGetAttachedDevice(TargetDevice);
79 SourceDeviceExtension = IoGetDevObjExtension(SourceDevice);
80 ASSERT(SourceDeviceExtension->AttachedTo == NULL);
81
82 /* Make sure that it's in a correct state */
83 if ((AttachedDevice->Flags & DO_DEVICE_INITIALIZING) ||
84 (IoGetDevObjExtension(AttachedDevice)->ExtensionFlags &
89 {
90 /* Device was unloading or being removed */
91 AttachedDevice = NULL;
92 }
93 else
94 {
95 /* Update atached device fields */
96 AttachedDevice->AttachedDevice = SourceDevice;
97 AttachedDevice->Spare1++;
98
99 /* Update the source with the attached data */
100 SourceDevice->StackSize = AttachedDevice->StackSize + 1;
101 SourceDevice->AlignmentRequirement = AttachedDevice->
103 SourceDevice->SectorSize = AttachedDevice->SectorSize;
104
105 /* Check for pending start flag */
106 if (IoGetDevObjExtension(AttachedDevice)->ExtensionFlags &
108 {
109 /* Propagate */
110 IoGetDevObjExtension(SourceDevice)->ExtensionFlags |=
112 }
113
114 /* Set the attachment in the device extension */
115 SourceDeviceExtension->AttachedTo = AttachedDevice;
116 }
117
118 /* Return the attached device */
119 if (AttachedToDeviceObject) *AttachedToDeviceObject = AttachedDevice;
120 return AttachedDevice;
121}
#define DOE_START_PENDING
Definition: boot.c:37
_In_ WDFDEVICE _In_ ULONG AlignmentRequirement
Definition: wdfdevice.h:2854

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

784{
785 PACL Dacl;
786 ULONG AceId;
789 BOOLEAN AdminsSet, WorldSet;
790
791 PAGED_CODE();
792
793 /* Zero our output vars */
794 if (OutputFlags) *OutputFlags = 0;
795
796 *OutputDacl = NULL;
797
798 /* For FSD, easy use SePublicDefaultUnrestrictedDacl */
803 {
806 OutputFlags);
807 goto Quit;
808 }
809 /* For storage devices with a name and floppy attribute,
810 * use SePublicOpenUnrestrictedDacl
811 */
820 {
823 OutputFlags);
824 goto Quit;
825 }
826
827 /* The rest...
828 * We will rely on SePublicDefaultUnrestrictedDacl as well
829 */
831 if (Dacl == NULL)
832 {
833 return NULL;
834 }
835
836 /* Copy our DACL */
838
839 /* Now, browse the DACL to make sure we have everything we want in them,
840 * including permissions
841 */
842 AceId = 0;
843 AdminsSet = FALSE;
844 WorldSet = FALSE;
845 while (NT_SUCCESS(RtlGetAce(Dacl, AceId, (PVOID *)&Ace)))
846 {
847 /* Admins must acess and in RWX, set it */
848 if (RtlEqualSid(SeAliasAdminsSid, &Ace->SidStart))
849 {
851 AdminsSet = TRUE;
852 }
853
854 /* World can read a CD_ROM device */
856 {
857 SetFlag(Ace->Mask, GENERIC_READ);
858 WorldSet = TRUE;
859 }
860
861 ++AceId;
862 }
863
864 /* AdminSid was present and set (otherwise, we have big trouble) */
865 ASSERT(AdminsSet);
866
867 /* If CD_ROM device, we've set world permissions */
868 if (DeviceType == FILE_DEVICE_CD_ROM) ASSERT(WorldSet);
869
870 /* Now our DACL is correct, setup the security descriptor */
873
874 /* We've set DACL */
875 if (OutputFlags) *OutputFlags |= DACL_SET;
876
877 /* Return DACL to allow later freeing */
878 *OutputDacl = Dacl;
880
881Quit:
882 /* Only return SD if we succeed */
883 if (!NT_SUCCESS(Status))
884 {
885 return NULL;
886 }
887
888 return SecurityDescriptor;
889}
unsigned char BOOLEAN
@ 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
NTSYSAPI NTSTATUS WINAPI RtlSetDaclSecurityDescriptor(PSECURITY_DESCRIPTOR, BOOLEAN, PACL, BOOLEAN)
#define FILE_DEVICE_MASS_STORAGE
Definition: imports.h:62
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:517
@ UnrestrictedPublic
Definition: io.h:515
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:729
#define DACL_SET
Definition: device.c:28
#define FILE_DEVICE_DFS_FILE_SYSTEM
Definition: winioctl.h:159
#define FILE_DEVICE_NETWORK
Definition: winioctl.h:124
USHORT AclSize
Definition: ms-dtyp.idl:296
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#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 729 of file device.c.

732{
733 PACL Dacl;
735
736 /* Select the DACL the caller wants */
737 switch (Type)
738 {
739 case RestrictedPublic:
741 break;
742
745 break;
746
749 break;
750
753 break;
754
755 case SystemDefault:
757 break;
758
759 default:
760 ASSERT(FALSE);
762 }
763
764 /* Create the SD and set the DACL caller wanted */
768
769 /* We've set DACL */
770 if (OutputFlags) *OutputFlags |= DACL_SET;
771
772 /* Done */
773 return Status;
774}
Type
Definition: Type.h:7
@ RestrictedPublicOpen
Definition: io.h:516
@ RestrictedPublic
Definition: io.h:514
@ SystemDefault
Definition: io.h:518
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 462 of file device.c.

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

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

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

268{
270 IO_STATUS_BLOCK StatusBlock;
271 PFILE_OBJECT LocalFileObject;
274
275 /* Open the Device */
279 NULL,
280 NULL);
284 &StatusBlock,
285 0,
286 FILE_NON_DIRECTORY_FILE | AttachFlag);
287 if (!NT_SUCCESS(Status)) return Status;
288
289 /* Get File Object */
291 0,
294 (PVOID*)&LocalFileObject,
295 NULL);
296 if (NT_SUCCESS(Status))
297 {
298 /* Return the requested data */
299 *DeviceObject = IoGetRelatedDeviceObject(LocalFileObject);
300 *FileObject = LocalFileObject;
301 }
302
303 /* Close the handle */
305
306 return Status;
307}
#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:1539
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 311 of file device.c.

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

Referenced by IoGetDeviceAttachmentBaseRef().

◆ IopGetRelatedTargetDevice()

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

Definition at line 653 of file device.c.

655{
658 PDEVICE_RELATIONS DeviceRelations;
660
662
663 /* Get DeviceObject related to given FileObject */
666
667 /* Define input parameters */
668 Stack.MajorFunction = IRP_MJ_PNP;
669 Stack.MinorFunction = IRP_MN_QUERY_DEVICE_RELATIONS;
670 Stack.Parameters.QueryDeviceRelations.Type = TargetDeviceRelation;
671 Stack.FileObject = FileObject;
672
673 /* Call the driver to query all relations (IRP_MJ_PNP) */
675 &Stack,
676 (PVOID)&DeviceRelations);
677 if (!NT_SUCCESS(Status)) return Status;
678
679 /* Make sure it's not NULL and contains only one object */
680 ASSERT(DeviceRelations);
681 ASSERT(DeviceRelations->Count == 1);
682
683 /* Finally get the device node */
684 *DeviceNode = IopGetDeviceNode(DeviceRelations->Objects[0]);
686
687 /* Free the DEVICE_RELATIONS structure, it's not needed anymore */
688 ExFreePool(DeviceRelations);
689
690 return Status;
691}
#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:2163
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639
@ TargetDeviceRelation
Definition: iotypes.h:2156
#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:4470

Referenced by IopInitializeDriverModule().

◆ IopStartNextPacket()

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

Definition at line 535 of file device.c.

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

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

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

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

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

◆ IopVerifyDeviceObjectOnStack()

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

Definition at line 695 of file device.c.

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

Referenced by IoGetRelatedDeviceObject(), and IopCheckTopDeviceHint().

◆ IoRegisterLastChanceShutdownNotification()

NTSTATUS NTAPI IoRegisterLastChanceShutdownNotification ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 1663 of file device.c.

1664{
1666
1667 /* Allocate the shutdown entry */
1669 sizeof(SHUTDOWN_ENTRY),
1672
1673 /* Set the DO */
1674 Entry->DeviceObject = DeviceObject;
1675
1676 /* Reference it so it doesn't go away */
1678
1679 /* Insert it into the list */
1681 &Entry->ShutdownList,
1683
1684 /* Set the shutdown registered flag */
1686 return STATUS_SUCCESS;
1687}
#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:428
#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 1694 of file device.c.

1695{
1697
1698 /* Allocate the shutdown entry */
1700 sizeof(SHUTDOWN_ENTRY),
1703
1704 /* Set the DO */
1705 Entry->DeviceObject = DeviceObject;
1706
1707 /* Reference it so it doesn't go away */
1709
1710 /* Insert it into the list */
1712 &Entry->ShutdownList,
1714
1715 /* Set the shutdown registered flag */
1717 return STATUS_SUCCESS;
1718}
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 1798 of file device.c.

1801{
1802 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
1803
1804 /* Get the Device Extension */
1805 DeviceExtension = IoGetDevObjExtension(DeviceObject);
1806
1807 /* Set the flags the caller requested */
1808 DeviceExtension->StartIoFlags |= (DeferredStartIo) ? DOE_SIO_DEFERRED : 0;
1809 DeviceExtension->StartIoFlags |= (NonCancelable) ? DOE_SIO_NO_CANCEL : 0;
1810}
#define DOE_SIO_DEFERRED
Definition: iotypes.h:161

Referenced by ClassAddDevice().

◆ IoShutdownPnpDevices()

VOID NTAPI IoShutdownPnpDevices ( VOID  )

Definition at line 125 of file device.c.

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

Referenced by IoShutdownSystem().

◆ IoShutdownSystem()

VOID NTAPI IoShutdownSystem ( IN ULONG  Phase)

Definition at line 133 of file device.c.

134{
135 PLIST_ENTRY ListEntry;
137 PSHUTDOWN_ENTRY ShutdownEntry;
138 IO_STATUS_BLOCK StatusBlock;
139 PIRP Irp;
142
143 /* Initialize an event to wait on */
145
146 /* What phase? */
147 if (Phase == 0)
148 {
149 /* Shutdown PnP */
151
152 /* Loop first-chance shutdown notifications */
155 while (ListEntry)
156 {
157 /* Get the shutdown entry */
158 ShutdownEntry = CONTAINING_RECORD(ListEntry,
160 ShutdownList);
161
162 /* Get the attached device */
164
165 /* Build the shutdown IRP and call the driver */
168 NULL,
169 0,
170 NULL,
171 &Event,
172 &StatusBlock);
173 if (Irp)
174 {
176 if (Status == STATUS_PENDING)
177 {
178 /* Wait on the driver */
180 }
181 }
182
183 /* Remove the flag */
184 ShutdownEntry->DeviceObject->Flags &= ~DO_SHUTDOWN_REGISTERED;
185
186 /* Get rid of our reference to it */
187 ObDereferenceObject(ShutdownEntry->DeviceObject);
188
189 /* Free the shutdown entry and reset the event */
192
193 /* Go to the next entry */
196 }
197 }
198 else if (Phase == 1)
199 {
200 /* Acquire resource forever */
202
203 /* Shutdown disk file systems */
205
206 /* Shutdown cdrom file systems */
208
209 /* Shutdown tape filesystems */
211
212 /* Loop last-chance shutdown notifications */
215 while (ListEntry)
216 {
217 /* Get the shutdown entry */
218 ShutdownEntry = CONTAINING_RECORD(ListEntry,
220 ShutdownList);
221
222 /* Get the attached device */
224
225 /* Build the shutdown IRP and call the driver */
228 NULL,
229 0,
230 NULL,
231 &Event,
232 &StatusBlock);
233 if (Irp)
234 {
236 if (Status == STATUS_PENDING)
237 {
238 /* Wait on the driver */
240 }
241 }
242
243 /* Remove the flag */
244 ShutdownEntry->DeviceObject->Flags &= ~DO_SHUTDOWN_REGISTERED;
245
246 /* Get rid of our reference to it */
247 ObDereferenceObject(ShutdownEntry->DeviceObject);
248
249 /* Free the shutdown entry and reset the event */
252
253 /* Go to the next entry */
256 }
257
258 }
259}
#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:125
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
#define STATUS_PENDING
Definition: ntstatus.h:82
Definition: typedefs.h:120
PDEVICE_OBJECT DeviceObject
Definition: io.h:430
#define IRP_MJ_SHUTDOWN
@ Executive
Definition: ketypes.h:403

Referenced by PopGracefulShutdown().

◆ IoStartNextPacket()

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

Definition at line 1847 of file device.c.

1849{
1850 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
1851
1852 /* Get the Device Extension */
1853 DeviceExtension = IoGetDevObjExtension(DeviceObject);
1854
1855 /* Check if deferred start was requested */
1856 if (DeviceExtension->StartIoFlags & DOE_SIO_DEFERRED)
1857 {
1858 /* Call our internal function to handle the defered case */
1860 0,
1863 }
1864 else
1865 {
1866 /* Call the normal routine */
1868 }
1869}
VOID NTAPI IopStartNextPacketByKeyEx(IN PDEVICE_OBJECT DeviceObject, IN ULONG Key, IN ULONG Flags)
Definition: device.c:583

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

1820{
1821 PEXTENDED_DEVOBJ_EXTENSION DeviceExtension;
1822
1823 /* Get the Device Extension */
1824 DeviceExtension = IoGetDevObjExtension(DeviceObject);
1825
1826 /* Check if deferred start was requested */
1827 if (DeviceExtension->StartIoFlags & DOE_SIO_DEFERRED)
1828 {
1829 /* Call our internal function to handle the defered case */
1831 Key,
1834 }
1835 else
1836 {
1837 /* Call the normal routine */
1839 }
1840}

◆ IoStartPacket()

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

Definition at line 1876 of file device.c.

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

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