ReactOS 0.4.15-dev-7958-gcd0bb1a
io.h File Reference
#include "ntdddisk.h"
#include "io_x.h"
Include dependency graph for io.h:

Go to the source code of this file.

Classes

struct  _FILE_OBJECT_EXTENSION
 
struct  _IOP_MINI_COMPLETION_PACKET
 
struct  _IO_UNLOAD_SAFE_COMPLETION_CONTEXT
 
struct  _IO_WORKITEM
 
struct  _IO_INTERRUPT
 
struct  _ERROR_LOG_ENTRY
 
struct  _EXTENDED_IO_REMOVE_LOCK
 
struct  _DUMMY_FILE_OBJECT
 
struct  _OPEN_PACKET
 
struct  _DRIVER_INFORMATION
 
struct  _IO_BUS_TYPE_GUID_LIST
 
struct  _SHUTDOWN_ENTRY
 
struct  _FS_CHANGE_NOTIFY_ENTRY
 
struct  _DRIVER_REINIT_ITEM
 
struct  _DEVICETREE_TRAVERSE_CONTEXT
 
struct  _RESERVE_IRP_ALLOCATOR
 

Macros

#define _IO_DEBUG_   0x00
 
#define IO_IRP_DEBUG   0x01
 
#define IO_FILE_DEBUG   0x02
 
#define IO_API_DEBUG   0x04
 
#define IO_CTL_DEBUG   0x08
 
#define IOTRACE(x, fmt, ...)   DPRINT(fmt, ##__VA_ARGS__)
 
#define ENUM_ROOT   L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum"
 
#define IO_METHOD_FROM_CTL_CODE(c)   (c & 0x00000003)
 
#define RD_NO_XIPROM_DESCRIPTOR   1
 
#define RD_NO_RAMDISK_DRIVER   2
 
#define RD_FSCTL_FAILED   3
 
#define RD_GUID_CONVERT_FAILED   4
 
#define RD_SYMLINK_CREATE_FAILED   5
 
#define RD_SYSROOT_INIT_FAILED   6
 
#define IOP_MAX_REPARSE_TRAVERSAL   0x20
 
#define IOP_USE_TOP_LEVEL_DEVICE_HINT   0x01
 
#define IOP_CREATE_FILE_OBJECT_EXTENSION   0x02
 
#define IopAllocateMdlFromLookaside    ObpAllocateObjectCreateInfoBuffer
 
#define IopFreeMdlFromLookaside    ObpFreeCapturedAttributes
 
#define IsIrpSynchronous(Irp, FileObject)
 
#define IoGetDevObjExtension(DeviceObject)
 
#define IoGetDrvObjExtension(DriverObject)
 
#define IopDeviceNodeSetFlag(DeviceNode, Flag)    ((DeviceNode)->Flags |= (Flag))
 
#define IopDeviceNodeClearFlag(DeviceNode, Flag)    ((DeviceNode)->Flags &= ~(Flag))
 
#define IopDeviceNodeHasFlag(DeviceNode, Flag)    (((DeviceNode)->Flags & (Flag)) > 0)
 
#define IopDeviceNodeSetUserFlag(DeviceNode, UserFlag)    ((DeviceNode)->UserFlags |= (UserFlag))
 
#define IopDeviceNodeClearUserFlag(DeviceNode, UserFlag)    ((DeviceNode)->UserFlags &= ~(UserFlag))
 
#define IopDeviceNodeHasUserFlag(DeviceNode, UserFlag)    (((DeviceNode)->UserFlags & (UserFlag)) > 0)
 
#define IopDeviceNodeSetProblem(DeviceNode, Problem)    ((DeviceNode)->Problem |= (Problem))
 
#define IopDeviceNodeClearProblem(DeviceNode, Problem)    ((DeviceNode)->Problem &= ~(Problem))
 
#define IopDeviceNodeHasProblem(DeviceNode, Problem)    (((DeviceNode)->Problem & (Problem)) > 0)
 
#define IopInitDeviceTreeTraverseContext( _DeviceTreeTraverseContext, _DeviceNode, _Action, _Context)
 
#define IopIsValidPhysicalDeviceObject(PhysicalDeviceObject)
 

Typedefs

typedef struct _FILE_OBJECT_EXTENSION FILE_OBJECT_EXTENSION
 
typedef struct _FILE_OBJECT_EXTENSIONPFILE_OBJECT_EXTENSION
 
typedef enum _IOP_DEVICE_LIST_OPERATION IOP_DEVICE_LIST_OPERATION
 
typedef enum _IOP_DEVICE_LIST_OPERATIONPIOP_DEVICE_LIST_OPERATION
 
typedef enum _IOP_TRANSFER_TYPE IOP_TRANSFER_TYPE
 
typedef enum _IOP_TRANSFER_TYPEPIOP_TRANSFER_TYPE
 
typedef enum _COMPLETION_PACKET_TYPE COMPLETION_PACKET_TYPE
 
typedef enum _COMPLETION_PACKET_TYPEPCOMPLETION_PACKET_TYPE
 
typedef struct _IOP_MINI_COMPLETION_PACKET IOP_MINI_COMPLETION_PACKET
 
typedef struct _IOP_MINI_COMPLETION_PACKETPIOP_MINI_COMPLETION_PACKET
 
typedef struct _IO_UNLOAD_SAFE_COMPLETION_CONTEXT IO_UNLOAD_SAFE_COMPLETION_CONTEXT
 
typedef struct _IO_UNLOAD_SAFE_COMPLETION_CONTEXTPIO_UNLOAD_SAFE_COMPLETION_CONTEXT
 
typedef struct _IO_WORKITEM IO_WORKITEM
 
typedef struct _IO_INTERRUPT IO_INTERRUPT
 
typedef struct _IO_INTERRUPTPIO_INTERRUPT
 
typedef struct _ERROR_LOG_ENTRY ERROR_LOG_ENTRY
 
typedef struct _ERROR_LOG_ENTRYPERROR_LOG_ENTRY
 
typedef struct _EXTENDED_IO_REMOVE_LOCK EXTENDED_IO_REMOVE_LOCK
 
typedef struct _EXTENDED_IO_REMOVE_LOCKPEXTENDED_IO_REMOVE_LOCK
 
typedef struct _DUMMY_FILE_OBJECT DUMMY_FILE_OBJECT
 
typedef struct _DUMMY_FILE_OBJECTPDUMMY_FILE_OBJECT
 
typedef struct _OPEN_PACKET OPEN_PACKET
 
typedef struct _OPEN_PACKETPOPEN_PACKET
 
typedef struct _DRIVER_INFORMATION DRIVER_INFORMATION
 
typedef struct _DRIVER_INFORMATIONPDRIVER_INFORMATION
 
typedef struct _IO_BUS_TYPE_GUID_LIST IO_BUS_TYPE_GUID_LIST
 
typedef struct _IO_BUS_TYPE_GUID_LISTPIO_BUS_TYPE_GUID_LIST
 
typedef struct _SHUTDOWN_ENTRY SHUTDOWN_ENTRY
 
typedef struct _SHUTDOWN_ENTRYPSHUTDOWN_ENTRY
 
typedef struct _FS_CHANGE_NOTIFY_ENTRY FS_CHANGE_NOTIFY_ENTRY
 
typedef struct _FS_CHANGE_NOTIFY_ENTRYPFS_CHANGE_NOTIFY_ENTRY
 
typedef struct _DRIVER_REINIT_ITEM DRIVER_REINIT_ITEM
 
typedef struct _DRIVER_REINIT_ITEMPDRIVER_REINIT_ITEM
 
typedef NTSTATUS(* DEVICETREE_TRAVERSE_ROUTINE) (IN PDEVICE_NODE DeviceNode, IN PVOID Context)
 
typedef struct _DEVICETREE_TRAVERSE_CONTEXT DEVICETREE_TRAVERSE_CONTEXT
 
typedef struct _DEVICETREE_TRAVERSE_CONTEXTPDEVICETREE_TRAVERSE_CONTEXT
 
typedef struct _RESERVE_IRP_ALLOCATOR RESERVE_IRP_ALLOCATOR
 
typedef struct _RESERVE_IRP_ALLOCATORPRESERVE_IRP_ALLOCATOR
 
typedef enum _SECURITY_DESCRIPTOR_TYPE SECURITY_DESCRIPTOR_TYPE
 
typedef enum _SECURITY_DESCRIPTOR_TYPEPSECURITY_DESCRIPTOR_TYPE
 
typedef enum _DEVICE_ACTION DEVICE_ACTION
 

Enumerations

enum  _IOP_DEVICE_LIST_OPERATION { IopRemove , IopAdd }
 
enum  _IOP_TRANSFER_TYPE { IopReadTransfer , IopWriteTransfer , IopOtherTransfer }
 
enum  _COMPLETION_PACKET_TYPE { IopCompletionPacketIrp , IopCompletionPacketMini , IopCompletionPacketQuota }
 
enum  _SECURITY_DESCRIPTOR_TYPE {
  RestrictedPublic = 1 , UnrestrictedPublic , RestrictedPublicOpen , UnrestrictedPublicOpen ,
  SystemDefault
}
 
enum  _DEVICE_ACTION {
  PiActionEnumDeviceTree , PiActionEnumRootDevices , PiActionResetDevice , PiActionAddBootDevices ,
  PiActionStartDevice , PiActionQueryState
}
 

Functions

ULONG NTAPI PnpDetermineResourceListSize (IN PCM_RESOURCE_LIST ResourceList)
 
NTSTATUS NTAPI IopAssignDeviceResources (IN PDEVICE_NODE DeviceNode)
 
NTSTATUS NTAPI IopFixupResourceListWithRequirements (IN PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList, OUT PCM_RESOURCE_LIST *ResourceList)
 
NTSTATUS NTAPI IopDetectResourceConflict (IN PCM_RESOURCE_LIST ResourceList, IN BOOLEAN Silent, OUT OPTIONAL PCM_PARTIAL_RESOURCE_DESCRIPTOR ConflictingDescriptor)
 
NTSTATUS NTAPI PipCallDriverAddDevice (IN PDEVICE_NODE DeviceNode, IN BOOLEAN LoadDriver, IN PDRIVER_OBJECT DriverObject)
 
NTSTATUS NTAPI IopInitializePlugPlayServices (VOID)
 
BOOLEAN NTAPI PpInitSystem (VOID)
 
VOID PnpInit2 (VOID)
 
VOID IopInitDriverImplementation (VOID)
 
NTSTATUS IopGetSystemPowerDeviceObject (IN PDEVICE_OBJECT *DeviceObject)
 
PDEVICE_NODE PipAllocateDeviceNode (IN PDEVICE_OBJECT PhysicalDeviceObject)
 
VOID PiInsertDevNode (_In_ PDEVICE_NODE DeviceNode, _In_ PDEVICE_NODE ParentNode)
 
PNP_DEVNODE_STATE PiSetDevNodeState (_In_ PDEVICE_NODE DeviceNode, _In_ PNP_DEVNODE_STATE NewState)
 
VOID PiSetDevNodeProblem (_In_ PDEVICE_NODE DeviceNode, _In_ UINT32 Problem)
 
VOID PiClearDevNodeProblem (_In_ PDEVICE_NODE DeviceNode)
 
NTSTATUS IopFreeDeviceNode (IN PDEVICE_NODE DeviceNode)
 
NTSTATUS NTAPI IopQueryDeviceCapabilities (PDEVICE_NODE DeviceNode, PDEVICE_CAPABILITIES DeviceCaps)
 
NTSTATUS IopSynchronousCall (IN PDEVICE_OBJECT DeviceObject, IN PIO_STACK_LOCATION IoStackLocation, OUT PVOID *Information)
 
NTSTATUS NTAPI IopInitiatePnpIrp (IN PDEVICE_OBJECT DeviceObject, IN PIO_STATUS_BLOCK IoStatusBlock, IN UCHAR MinorFunction, IN PIO_STACK_LOCATION Stack)
 
PDEVICE_NODE FASTCALL IopGetDeviceNode (IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS IoCreateDriverList (VOID)
 
NTSTATUS IoDestroyDriverList (VOID)
 
NTSTATUS IopInitPlugPlayEvents (VOID)
 
NTSTATUS IopQueueDeviceChangeEvent (_In_ const GUID *EventGuid, _In_ const GUID *InterfaceClassGuid, _In_ PUNICODE_STRING SymbolicLinkName)
 
NTSTATUS IopQueueTargetDeviceEvent (_In_ const GUID *Guid, _In_ PUNICODE_STRING DeviceIds)
 
NTSTATUS IopQueueDeviceInstallEvent (_In_ const GUID *Guid, _In_ PUNICODE_STRING DeviceId)
 
NTSTATUS NTAPI IopOpenRegistryKeyEx (PHANDLE KeyHandle, HANDLE ParentKey, PUNICODE_STRING Name, ACCESS_MASK DesiredAccess)
 
NTSTATUS NTAPI IopGetRegistryValue (IN HANDLE Handle, IN PWSTR ValueName, OUT PKEY_VALUE_FULL_INFORMATION *Information)
 
NTSTATUS NTAPI IopCreateRegistryKeyEx (OUT PHANDLE Handle, IN HANDLE BaseHandle OPTIONAL, IN PUNICODE_STRING KeyName, IN ACCESS_MASK DesiredAccess, IN ULONG CreateOptions, OUT PULONG Disposition OPTIONAL)
 
NTSTATUS IopTraverseDeviceTree (PDEVICETREE_TRAVERSE_CONTEXT Context)
 
NTSTATUS NTAPI IopCreateDeviceKeyPath (IN PCUNICODE_STRING RegistryPath, IN ULONG CreateOptions, OUT PHANDLE Handle)
 
NTSTATUS NTAPI IopUpdateRootKey (VOID)
 
NTSTATUS NTAPI PiInitCacheGroupInformation (VOID)
 
USHORT NTAPI PpInitGetGroupOrderIndex (IN HANDLE ServiceHandle)
 
USHORT NTAPI PipGetDriverTagPriority (IN HANDLE ServiceHandle)
 
NTSTATUS NTAPI PnpRegMultiSzToUnicodeStrings (IN PKEY_VALUE_FULL_INFORMATION KeyValueInformation, OUT PUNICODE_STRING *UnicodeStringList, OUT PULONG UnicodeStringCount)
 
BOOLEAN NTAPI PnpRegSzToString (IN PWCHAR RegSzData, IN ULONG RegSzLength, OUT PUSHORT StringLength OPTIONAL)
 
VOID PiSetDevNodeText (_In_ PDEVICE_NODE DeviceNode, _In_ HANDLE InstanceKey)
 Sets the DeviceNode's DeviceDesc and LocationInformation registry values.
 
NTSTATUS NTAPI IopCreateArcNames (IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 
NTSTATUS NTAPI IopReassignSystemRoot (IN PLOADER_PARAMETER_BLOCK LoaderBlock, OUT PANSI_STRING NtBootPath)
 
BOOLEAN NTAPI IoInitSystem (IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 
BOOLEAN NTAPI IopVerifyDiskSignature (IN PDRIVE_LAYOUT_INFORMATION_EX DriveLayout, IN PARC_DISK_SIGNATURE ArcDiskSignature, OUT PULONG Signature)
 
BOOLEAN NTAPI IoInitializeCrashDump (IN HANDLE PageFileHandle)
 
VOID PiInitializeNotifications (VOID)
 
VOID NTAPI IopReadyDeviceObjects (IN PDRIVER_OBJECT Driver)
 
PVPB NTAPI IopCheckVpbMounted (IN POPEN_PACKET OpenPacket, IN PDEVICE_OBJECT DeviceObject, IN PUNICODE_STRING RemainingName, OUT PNTSTATUS Status)
 
NTSTATUS NTAPI IopMountVolume (IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN AllowRawMount, IN BOOLEAN DeviceIsLocked, IN BOOLEAN Alertable, OUT PVPB *Vpb)
 
PVOID IoOpenSymlink (IN PVOID SymbolicLink)
 
PVOID IoOpenFileOnDevice (IN PVOID SymbolicLink, IN PWCHAR Name)
 
NTSTATUS NTAPI IopCreateVpb (IN PDEVICE_OBJECT DeviceObject)
 
VOID NTAPI IopDereferenceVpbAndFree (IN PVPB Vpb)
 
VOID NTAPI IoInitFileSystemImplementation (VOID)
 
VOID NTAPI IoInitVpbImplementation (VOID)
 
NTSTATUS NTAPI IopReferenceDeviceObject (IN PDEVICE_OBJECT DeviceObject)
 
VOID NTAPI IopDereferenceDeviceObject (IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN ForceUnload)
 
NTSTATUS NTAPI IopGetRelatedTargetDevice (IN PFILE_OBJECT FileObject, OUT PDEVICE_NODE *DeviceNode)
 
NTSTATUS NTAPI IoGetRelatedTargetDevice (IN PFILE_OBJECT FileObject, OUT PDEVICE_OBJECT *DeviceObject)
 
VOID NTAPI IopUnloadDevice (IN PDEVICE_OBJECT DeviceObject)
 
PDEVICE_OBJECT NTAPI IopGetDeviceAttachmentBase (IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS NTAPI IopCleanupFailedIrp (IN PFILE_OBJECT FileObject, IN PKEVENT EventObject, IN PVOID Buffer OPTIONAL)
 
VOID NTAPI IopAbortInterruptedIrp (IN PKEVENT EventObject, IN PIRP Irp)
 
PIRP NTAPI IopAllocateIrpMustSucceed (IN CCHAR StackSize)
 
BOOLEAN NTAPI IopInitializeReserveIrp (IN PRESERVE_IRP_ALLOCATOR ReserveIrpAllocator)
 
PIRP NTAPI IopAllocateReserveIrp (IN CCHAR StackSize)
 
VOID IoInitShutdownNotification (VOID)
 
VOID NTAPI IoShutdownSystem (IN ULONG Phase)
 
VOID NTAPI IopShutdownBaseFileSystems (IN PLIST_ENTRY ListHead)
 
VOID IopInitBootLog (IN BOOLEAN StartBootLog)
 
VOID IopStartBootLog (VOID)
 
VOID IopStopBootLog (VOID)
 
VOID IopBootLog (IN PUNICODE_STRING DriverName, IN BOOLEAN Success)
 
VOID IopSaveBootLogToFile (VOID)
 
VOID NTAPI IoCancelThreadIo (IN PETHREAD Thread)
 
VOID IoInitCancelHandling (VOID)
 
VOID NTAPI IopCompleteRequest (IN PKAPC Apc, IN PKNORMAL_ROUTINE *NormalRoutine, IN PVOID *NormalContext, IN PVOID *SystemArgument1, IN PVOID *SystemArgument2)
 
VOID NTAPI IopInitErrorLog (VOID)
 
VOID NTAPI IopLogWorker (IN PVOID Parameter)
 
BOOLEAN RawFsIsRawFileSystemDeviceObject (IN PDEVICE_OBJECT DeviceObject)
 
NTSTATUS NTAPI RawFsDriverEntry (IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
 
NTSTATUS NTAPI PnpRootDriverEntry (IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
 
NTSTATUS PnpRootCreateDeviceObject (OUT PDEVICE_OBJECT *DeviceObject)
 
NTSTATUS PnpRootCreateDevice (IN PUNICODE_STRING ServiceName, OUT PDEVICE_OBJECT *PhysicalDeviceObject, OUT PUNICODE_STRING FullInstancePath)
 
NTSTATUS PnpRootRegisterDevice (IN PDEVICE_OBJECT DeviceObject)
 
VOID PnpRootInitializeDevExtension (VOID)
 
VOID FASTCALL IopInitializeBootDrivers (VOID)
 
VOID FASTCALL IopInitializeSystemDrivers (VOID)
 
VOID NTAPI IopDeleteDriver (IN PVOID ObjectBody)
 
NTSTATUS IopLoadDriver (_In_ HANDLE ServiceHandle, _Out_ PDRIVER_OBJECT *DriverObject)
 
NTSTATUS IopGetDriverNames (_In_ HANDLE ServiceHandle, _Out_ PUNICODE_STRING DriverName, _Out_opt_ PUNICODE_STRING ServiceName)
 
NTSTATUS IopInitializeDriverModule (_In_ PLDR_DATA_TABLE_ENTRY ModuleObject, _In_ HANDLE ServiceHandle, _Out_ PDRIVER_OBJECT *DriverObject, _Out_ NTSTATUS *DriverEntryStatus)
 Initialize a loaded driver.
 
NTSTATUS FASTCALL IopAttachFilterDrivers (IN PDEVICE_NODE DeviceNode, IN HANDLE EnumSubKey, IN HANDLE ClassKey, IN BOOLEAN Lower)
 
VOID NTAPI IopReinitializeDrivers (VOID)
 
VOID NTAPI IopReinitializeBootDrivers (VOID)
 
VOID NTAPI IopDeleteDevice (IN PVOID ObjectBody)
 
NTSTATUS NTAPI IopParseDevice (IN PVOID ParseObject, IN PVOID ObjectType, IN OUT PACCESS_STATE AccessState, IN KPROCESSOR_MODE AccessMode, IN ULONG Attributes, IN OUT PUNICODE_STRING CompleteName, IN OUT PUNICODE_STRING RemainingName, IN OUT PVOID Context, IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL, OUT PVOID *Object)
 
NTSTATUS NTAPI IopParseFile (IN PVOID ParseObject, IN PVOID ObjectType, IN OUT PACCESS_STATE AccessState, IN KPROCESSOR_MODE AccessMode, IN ULONG Attributes, IN OUT PUNICODE_STRING CompleteName, IN OUT PUNICODE_STRING RemainingName, IN OUT PVOID Context OPTIONAL, IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL, OUT PVOID *Object)
 
VOID NTAPI IopDeleteFile (IN PVOID ObjectBody)
 
NTSTATUS NTAPI IopGetSetSecurityObject (IN PVOID ObjectBody, IN SECURITY_OPERATION_CODE OperationCode, IN PSECURITY_INFORMATION SecurityInformation, IN OUT PSECURITY_DESCRIPTOR SecurityDescriptor, IN OUT PULONG BufferLength, OUT PSECURITY_DESCRIPTOR *OldSecurityDescriptor, IN POOL_TYPE PoolType, IN OUT PGENERIC_MAPPING GenericMapping)
 
NTSTATUS NTAPI IopQueryName (IN PVOID ObjectBody, IN BOOLEAN HasName, OUT POBJECT_NAME_INFORMATION ObjectNameInfo, IN ULONG Length, OUT PULONG ReturnLength, IN KPROCESSOR_MODE PreviousMode)
 
NTSTATUS NTAPI IopQueryNameInternal (IN PVOID ObjectBody, IN BOOLEAN HasName, IN BOOLEAN QueryDosName, OUT POBJECT_NAME_INFORMATION ObjectNameInfo, IN ULONG Length, OUT PULONG ReturnLength, IN KPROCESSOR_MODE PreviousMode)
 
VOID NTAPI IopCloseFile (IN PEPROCESS Process OPTIONAL, IN PVOID Object, IN ACCESS_MASK GrantedAccess, IN ULONG ProcessHandleCount, IN ULONG SystemHandleCount)
 
NTSTATUS NTAPI IopAcquireFileObjectLock (_In_ PFILE_OBJECT FileObject, _In_ KPROCESSOR_MODE AccessMode, _In_ BOOLEAN Alertable, _Out_ PBOOLEAN LockFailed)
 
PVOID NTAPI IoGetFileObjectFilterContext (IN PFILE_OBJECT FileObject)
 
NTSTATUS NTAPI IoChangeFileObjectFilterContext (IN PFILE_OBJECT FileObject, IN PVOID FilterContext, IN BOOLEAN Define)
 
VOID NTAPI IopDoNameTransmogrify (IN PIRP Irp, IN PFILE_OBJECT FileObject, IN PREPARSE_DATA_BUFFER DataBuffer)
 
NTSTATUS NTAPI IoComputeDesiredAccessFileObject (IN PFILE_OBJECT FileObject, IN PACCESS_MASK DesiredAccess)
 
NTSTATUS NTAPI IopGetFileInformation (IN PFILE_OBJECT FileObject, IN ULONG Length, IN FILE_INFORMATION_CLASS FileInfoClass, OUT PVOID Buffer, OUT PULONG ReturnedLength)
 
BOOLEAN NTAPI IopVerifyDeviceObjectOnStack (IN PDEVICE_OBJECT BaseDeviceObject, IN PDEVICE_OBJECT TopDeviceObjectHint)
 
VOID FASTCALL IopInitTimerImplementation (VOID)
 
VOID NTAPI IopRemoveTimerFromTimerList (IN PIO_TIMER Timer)
 
VOID NTAPI IopDeleteIoCompletion (PVOID ObjectBody)
 
NTSTATUS NTAPI IoSetIoCompletion (IN PVOID IoCompletion, IN PVOID KeyContext, IN PVOID ApcContext, IN NTSTATUS IoStatus, IN ULONG_PTR IoStatusInformation, IN BOOLEAN Quota)
 
NTSTATUS NTAPI IopStartRamdisk (IN PLOADER_PARAMETER_BLOCK LoaderBlock)
 
NTSTATUS IopFetchConfigurationInformation (_Out_ PWSTR *SymbolicLinkList, _In_ GUID Guid, _In_ ULONG ExpectedInterfaces, _Out_ PULONG Interfaces)
 
VOID IopStoreSystemPartitionInformation (_In_ PUNICODE_STRING NtSystemPartitionDeviceName, _In_ PUNICODE_STRING OsLoaderPathName)
 
VOID PiQueueDeviceAction (_In_ PDEVICE_OBJECT DeviceObject, _In_ DEVICE_ACTION Action, _In_opt_ PKEVENT CompletionEvent, _Out_opt_ NTSTATUS *CompletionStatus)
 Queue a device operation to a worker thread.
 
NTSTATUS PiPerformSyncDeviceAction (_In_ PDEVICE_OBJECT DeviceObject, _In_ DEVICE_ACTION Action)
 Perfom a device operation synchronously via PiQueueDeviceAction.
 
VOID PiNotifyDeviceInterfaceChange (_In_ LPCGUID Event, _In_ LPCGUID InterfaceClassGuid, _In_ PUNICODE_STRING SymbolicLinkName)
 Delivers the event to all drivers subscribed to EventCategoryDeviceInterfaceChange.
 
VOID PiNotifyHardwareProfileChange (_In_ LPCGUID Event)
 Delivers the event to all drivers subscribed to EventCategoryHardwareProfileChange PnP event.
 
VOID PiNotifyTargetDeviceChange (_In_ LPCGUID Event, _In_ PDEVICE_OBJECT DeviceObject, _In_opt_ PTARGET_DEVICE_CUSTOM_NOTIFICATION CustomNotification)
 Delivers the event to all drivers subscribed to EventCategoryTargetDeviceChange PnP event.
 
NTSTATUS PiIrpStartDevice (_In_ PDEVICE_NODE DeviceNode)
 
NTSTATUS PiIrpStopDevice (_In_ PDEVICE_NODE DeviceNode)
 
NTSTATUS PiIrpQueryStopDevice (_In_ PDEVICE_NODE DeviceNode)
 
NTSTATUS PiIrpCancelStopDevice (_In_ PDEVICE_NODE DeviceNode)
 
NTSTATUS PiIrpQueryDeviceRelations (_In_ PDEVICE_NODE DeviceNode, _In_ DEVICE_RELATION_TYPE Type)
 
NTSTATUS PiIrpQueryResources (_In_ PDEVICE_NODE DeviceNode, _Out_ PCM_RESOURCE_LIST *Resources)
 
NTSTATUS PiIrpQueryResourceRequirements (_In_ PDEVICE_NODE DeviceNode, _Out_ PIO_RESOURCE_REQUIREMENTS_LIST *Resources)
 
NTSTATUS PiIrpQueryDeviceText (_In_ PDEVICE_NODE DeviceNode, _In_ LCID LocaleId, _In_ DEVICE_TEXT_TYPE Type, _Out_ PWSTR *DeviceText)
 
NTSTATUS PiIrpQueryPnPDeviceState (_In_ PDEVICE_NODE DeviceNode, _Out_ PPNP_DEVICE_STATE DeviceState)
 

Variables

PIO_BUS_TYPE_GUID_LIST IopBusTypeGuidList
 
POBJECT_TYPE IoCompletionType
 
PDEVICE_NODE IopRootDeviceNode
 
KSPIN_LOCK IopDeviceTreeLock
 
ULONG IopTraceLevel
 
GENERAL_LOOKASIDE IopMdlLookasideList
 
GENERIC_MAPPING IopCompletionMapping
 
GENERIC_MAPPING IopFileMapping
 
POBJECT_TYPE _IoFileObjectType
 
HAL_DISPATCH _HalDispatchTable
 
LIST_ENTRY IopErrorLogListHead
 
ULONG IopNumTriageDumpDataBlocks
 
PVOID IopTriageDumpDataBlocks [64]
 
PIO_BUS_TYPE_GUID_LIST PnpBusTypeGuidList
 
PDRIVER_OBJECT IopRootDriverObject
 
KSPIN_LOCK IopDeviceActionLock
 
LIST_ENTRY IopDeviceActionRequestList
 
RESERVE_IRP_ALLOCATOR IopReserveIrpAllocator
 
BOOLEAN IoRemoteBootClient
 

Macro Definition Documentation

◆ _IO_DEBUG_

#define _IO_DEBUG_   0x00

Definition at line 14 of file io.h.

◆ ENUM_ROOT

#define ENUM_ROOT   L"\\Registry\\Machine\\System\\CurrentControlSet\\Enum"

Definition at line 53 of file io.h.

◆ IO_API_DEBUG

#define IO_API_DEBUG   0x04

Definition at line 21 of file io.h.

◆ IO_CTL_DEBUG

#define IO_CTL_DEBUG   0x08

Definition at line 22 of file io.h.

◆ IO_FILE_DEBUG

#define IO_FILE_DEBUG   0x02

Definition at line 20 of file io.h.

◆ IO_IRP_DEBUG

#define IO_IRP_DEBUG   0x01

Definition at line 19 of file io.h.

◆ IO_METHOD_FROM_CTL_CODE

#define IO_METHOD_FROM_CTL_CODE (   c)    (c & 0x00000003)

Definition at line 58 of file io.h.

◆ IoGetDevObjExtension

#define IoGetDevObjExtension (   DeviceObject)
Value:
(DeviceObject->DeviceObjectExtension)) \
struct _EXTENDED_DEVOBJ_EXTENSION * PEXTENDED_DEVOBJ_EXTENSION
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055

Definition at line 129 of file io.h.

◆ IoGetDrvObjExtension

#define IoGetDrvObjExtension (   DriverObject)
Value:
(DriverObject->DriverExtension)) \
struct _EXTENDED_DRIVER_EXTENSION * PEXTENDED_DRIVER_EXTENSION
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213

Definition at line 136 of file io.h.

◆ IOP_CREATE_FILE_OBJECT_EXTENSION

#define IOP_CREATE_FILE_OBJECT_EXTENSION   0x02

Definition at line 97 of file io.h.

◆ IOP_MAX_REPARSE_TRAVERSAL

#define IOP_MAX_REPARSE_TRAVERSAL   0x20

Definition at line 91 of file io.h.

◆ IOP_USE_TOP_LEVEL_DEVICE_HINT

#define IOP_USE_TOP_LEVEL_DEVICE_HINT   0x01

Definition at line 96 of file io.h.

◆ IopAllocateMdlFromLookaside

#define IopAllocateMdlFromLookaside    ObpAllocateObjectCreateInfoBuffer

Definition at line 112 of file io.h.

◆ IopDeviceNodeClearFlag

#define IopDeviceNodeClearFlag (   DeviceNode,
  Flag 
)     ((DeviceNode)->Flags &= ~(Flag))

Definition at line 155 of file io.h.

◆ IopDeviceNodeClearProblem

#define IopDeviceNodeClearProblem (   DeviceNode,
  Problem 
)     ((DeviceNode)->Problem &= ~(Problem))

Definition at line 209 of file io.h.

◆ IopDeviceNodeClearUserFlag

#define IopDeviceNodeClearUserFlag (   DeviceNode,
  UserFlag 
)     ((DeviceNode)->UserFlags &= ~(UserFlag))

Definition at line 182 of file io.h.

◆ IopDeviceNodeHasFlag

#define IopDeviceNodeHasFlag (   DeviceNode,
  Flag 
)     (((DeviceNode)->Flags & (Flag)) > 0)

Definition at line 164 of file io.h.

◆ IopDeviceNodeHasProblem

#define IopDeviceNodeHasProblem (   DeviceNode,
  Problem 
)     (((DeviceNode)->Problem & (Problem)) > 0)

Definition at line 218 of file io.h.

◆ IopDeviceNodeHasUserFlag

#define IopDeviceNodeHasUserFlag (   DeviceNode,
  UserFlag 
)     (((DeviceNode)->UserFlags & (UserFlag)) > 0)

Definition at line 191 of file io.h.

◆ IopDeviceNodeSetFlag

#define IopDeviceNodeSetFlag (   DeviceNode,
  Flag 
)     ((DeviceNode)->Flags |= (Flag))

Definition at line 146 of file io.h.

◆ IopDeviceNodeSetProblem

#define IopDeviceNodeSetProblem (   DeviceNode,
  Problem 
)     ((DeviceNode)->Problem |= (Problem))

Definition at line 200 of file io.h.

◆ IopDeviceNodeSetUserFlag

#define IopDeviceNodeSetUserFlag (   DeviceNode,
  UserFlag 
)     ((DeviceNode)->UserFlags |= (UserFlag))

Definition at line 173 of file io.h.

◆ IopFreeMdlFromLookaside

#define IopFreeMdlFromLookaside    ObpFreeCapturedAttributes

Definition at line 114 of file io.h.

◆ IopInitDeviceTreeTraverseContext

#define IopInitDeviceTreeTraverseContext (   _DeviceTreeTraverseContext,
  _DeviceNode,
  _Action,
  _Context 
)
Value:
{ \
(_DeviceTreeTraverseContext)->FirstDeviceNode = \
(_DeviceNode); \
(_DeviceTreeTraverseContext)->Action = (_Action); \
(_DeviceTreeTraverseContext)->Context = (_Context); }
_In_ WDFIOTARGET _In_ _Strict_type_match_ WDF_IO_TARGET_SENT_IO_ACTION Action
Definition: wdfiotarget.h:510

Definition at line 229 of file io.h.

◆ IopIsValidPhysicalDeviceObject

#define IopIsValidPhysicalDeviceObject (   PhysicalDeviceObject)
Value:
(((PEXTENDED_DEVOBJ_EXTENSION)PhysicalDeviceObject->DeviceObjectExtension)->DeviceNode) && \
@ DeviceNode
Definition: Node.h:9
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1157
#define DNF_ENUMERATED
Definition: iotypes.h:174

Definition at line 242 of file io.h.

◆ IOTRACE

#define IOTRACE (   x,
  fmt,
  ... 
)    DPRINT(fmt, ##__VA_ARGS__)

Definition at line 47 of file io.h.

◆ IsIrpSynchronous

#define IsIrpSynchronous (   Irp,
  FileObject 
)
Value:
((Irp->Flags & IRP_SYNCHRONOUS_API) || \
(!(FileObject) ? \
FALSE : \
_In_ PIRP Irp
Definition: csq.h:116
#define FALSE
Definition: types.h:117
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
#define IRP_SYNCHRONOUS_API
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1776

Definition at line 120 of file io.h.

◆ RD_FSCTL_FAILED

#define RD_FSCTL_FAILED   3

Definition at line 74 of file io.h.

◆ RD_GUID_CONVERT_FAILED

#define RD_GUID_CONVERT_FAILED   4

Definition at line 78 of file io.h.

◆ RD_NO_RAMDISK_DRIVER

#define RD_NO_RAMDISK_DRIVER   2

Definition at line 70 of file io.h.

◆ RD_NO_XIPROM_DESCRIPTOR

#define RD_NO_XIPROM_DESCRIPTOR   1

Definition at line 66 of file io.h.

◆ RD_SYMLINK_CREATE_FAILED

#define RD_SYMLINK_CREATE_FAILED   5

Definition at line 82 of file io.h.

◆ RD_SYSROOT_INIT_FAILED

#define RD_SYSROOT_INIT_FAILED   6

Definition at line 86 of file io.h.

Typedef Documentation

◆ COMPLETION_PACKET_TYPE

◆ DEVICE_ACTION

◆ DEVICETREE_TRAVERSE_CONTEXT

◆ DEVICETREE_TRAVERSE_ROUTINE

typedef NTSTATUS(* DEVICETREE_TRAVERSE_ROUTINE) (IN PDEVICE_NODE DeviceNode, IN PVOID Context)

Definition at line 465 of file io.h.

◆ DRIVER_INFORMATION

◆ DRIVER_REINIT_ITEM

◆ DUMMY_FILE_OBJECT

◆ ERROR_LOG_ENTRY

◆ EXTENDED_IO_REMOVE_LOCK

◆ FILE_OBJECT_EXTENSION

◆ FS_CHANGE_NOTIFY_ENTRY

◆ IO_BUS_TYPE_GUID_LIST

◆ IO_INTERRUPT

◆ IO_UNLOAD_SAFE_COMPLETION_CONTEXT

◆ IO_WORKITEM

◆ IOP_DEVICE_LIST_OPERATION

◆ IOP_MINI_COMPLETION_PACKET

◆ IOP_TRANSFER_TYPE

◆ OPEN_PACKET

◆ PCOMPLETION_PACKET_TYPE

◆ PDEVICETREE_TRAVERSE_CONTEXT

◆ PDRIVER_INFORMATION

◆ PDRIVER_REINIT_ITEM

◆ PDUMMY_FILE_OBJECT

◆ PERROR_LOG_ENTRY

◆ PEXTENDED_IO_REMOVE_LOCK

◆ PFILE_OBJECT_EXTENSION

◆ PFS_CHANGE_NOTIFY_ENTRY

◆ PIO_BUS_TYPE_GUID_LIST

◆ PIO_INTERRUPT

◆ PIO_UNLOAD_SAFE_COMPLETION_CONTEXT

◆ PIOP_DEVICE_LIST_OPERATION

◆ PIOP_MINI_COMPLETION_PACKET

◆ PIOP_TRANSFER_TYPE

◆ POPEN_PACKET

◆ PRESERVE_IRP_ALLOCATOR

◆ PSECURITY_DESCRIPTOR_TYPE

◆ PSHUTDOWN_ENTRY

◆ RESERVE_IRP_ALLOCATOR

◆ SECURITY_DESCRIPTOR_TYPE

◆ SHUTDOWN_ENTRY

Enumeration Type Documentation

◆ _COMPLETION_PACKET_TYPE

Enumerator
IopCompletionPacketIrp 
IopCompletionPacketMini 
IopCompletionPacketQuota 

Definition at line 269 of file io.h.

270 {
@ IopCompletionPacketIrp
Definition: io.h:271
@ IopCompletionPacketMini
Definition: io.h:272
@ IopCompletionPacketQuota
Definition: io.h:273
enum _COMPLETION_PACKET_TYPE COMPLETION_PACKET_TYPE
enum _COMPLETION_PACKET_TYPE * PCOMPLETION_PACKET_TYPE

◆ _DEVICE_ACTION

Enumerator
PiActionEnumDeviceTree 
PiActionEnumRootDevices 
PiActionResetDevice 
PiActionAddBootDevices 
PiActionStartDevice 
PiActionQueryState 

Definition at line 524 of file io.h.

525{
@ PiActionResetDevice
Definition: io.h:528
@ PiActionQueryState
Definition: io.h:531
@ PiActionAddBootDevices
Definition: io.h:529
@ PiActionStartDevice
Definition: io.h:530
@ PiActionEnumRootDevices
Definition: io.h:527
@ PiActionEnumDeviceTree
Definition: io.h:526
enum _DEVICE_ACTION DEVICE_ACTION

◆ _IOP_DEVICE_LIST_OPERATION

Enumerator
IopRemove 
IopAdd 

Definition at line 250 of file io.h.

251{
252 IopRemove,
253 IopAdd
enum _IOP_DEVICE_LIST_OPERATION * PIOP_DEVICE_LIST_OPERATION
@ IopAdd
Definition: io.h:253
@ IopRemove
Definition: io.h:252
enum _IOP_DEVICE_LIST_OPERATION IOP_DEVICE_LIST_OPERATION

◆ _IOP_TRANSFER_TYPE

Enumerator
IopReadTransfer 
IopWriteTransfer 
IopOtherTransfer 

Definition at line 259 of file io.h.

260{
enum _IOP_TRANSFER_TYPE IOP_TRANSFER_TYPE
@ IopWriteTransfer
Definition: io.h:262
@ IopReadTransfer
Definition: io.h:261
@ IopOtherTransfer
Definition: io.h:263
enum _IOP_TRANSFER_TYPE * PIOP_TRANSFER_TYPE

◆ _SECURITY_DESCRIPTOR_TYPE

Enumerator
RestrictedPublic 
UnrestrictedPublic 
RestrictedPublicOpen 
UnrestrictedPublicOpen 
SystemDefault 

Definition at line 512 of file io.h.

513{
enum _SECURITY_DESCRIPTOR_TYPE SECURITY_DESCRIPTOR_TYPE
@ RestrictedPublicOpen
Definition: io.h:516
@ RestrictedPublic
Definition: io.h:514
@ UnrestrictedPublicOpen
Definition: io.h:517
@ SystemDefault
Definition: io.h:518
@ UnrestrictedPublic
Definition: io.h:515
enum _SECURITY_DESCRIPTOR_TYPE * PSECURITY_DESCRIPTOR_TYPE

Function Documentation

◆ IoCancelThreadIo()

VOID NTAPI IoCancelThreadIo ( IN PETHREAD  Thread)

Definition at line 1146 of file irp.c.

1147{
1148 KIRQL OldIrql;
1149 ULONG Retries = 3000;
1151 PLIST_ENTRY ListHead, NextEntry;
1152 PIRP Irp;
1153 PAGED_CODE();
1154
1155 /* Windows isn't using given thread, but using current. */
1157
1159 "%s - Canceling IRPs for Thread %p\n",
1161 Thread);
1162
1163 /* Raise to APC to protect the IrpList */
1165
1166 /* Start by cancelling all the IRPs in the current thread queue. */
1167 ListHead = &Thread->IrpList;
1168 NextEntry = ListHead->Flink;
1169 while (ListHead != NextEntry)
1170 {
1171 /* Get the IRP */
1172 Irp = CONTAINING_RECORD(NextEntry, IRP, ThreadListEntry);
1173
1174 /* Cancel it */
1176
1177 /* Move to the next entry */
1178 NextEntry = NextEntry->Flink;
1179 }
1180
1181 /* Wait 100 milliseconds */
1182 Interval.QuadPart = -1000000;
1183
1184 /* Wait till all the IRPs are completed or cancelled. */
1185 while (!IsListEmpty(&Thread->IrpList))
1186 {
1187 /* Now we can lower */
1189
1190 /* Wait a short while and then look if all our IRPs were completed. */
1192
1193 /*
1194 * Don't stay here forever if some broken driver doesn't complete
1195 * the IRP.
1196 */
1197 if (!(Retries--))
1198 {
1199 /* Print out a message and remove the IRP */
1200 DPRINT1("Broken driver did not complete!\n");
1202 }
1203
1204 /* Raise the IRQL Again */
1206 }
1207
1208 /* We're done, lower the IRQL */
1210}
#define PAGED_CODE()
#define DPRINT1
Definition: precomp.h:8
#define __FUNCTION__
Definition: types.h:116
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define APC_LEVEL
Definition: env_spec_w32.h:695
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define KeDelayExecutionThread(mode, foo, t)
Definition: env_spec_w32.h:484
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define KernelMode
Definition: asm.h:34
DWORD Interval
Definition: netstat.c:30
#define IO_IRP_DEBUG
Definition: io.h:19
#define IOTRACE(x, fmt,...)
Definition: io.h:47
VOID NTAPI IopDisassociateThreadIrp(VOID)
Definition: irp.c:115
BOOLEAN NTAPI IoCancelIrp(IN PIRP Irp)
Definition: irp.c:1101
LIST_ENTRY IrpList
Definition: pstypes.h:1144
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

Referenced by PspExitThread().

◆ IoChangeFileObjectFilterContext()

NTSTATUS NTAPI IoChangeFileObjectFilterContext ( IN PFILE_OBJECT  FileObject,
IN PVOID  FilterContext,
IN BOOLEAN  Define 
)

Definition at line 2511 of file file.c.

2514{
2516 PFILE_OBJECT_EXTENSION FileObjectExtension;
2517
2519 {
2521 }
2522
2523 FileObjectExtension = FileObject->FileObjectExtension;
2524 if (Define)
2525 {
2526 /* If define, just set the new value if not value is set
2527 * Success will only contain old value. It is valid if it is NULL
2528 */
2530 }
2531 else
2532 {
2533 /* If not define, we want to reset filter context.
2534 * We will remove value (provided by the caller) and set NULL instead.
2535 * This will only success if caller provides correct previous value.
2536 * To catch whether it worked, we substract previous value to expect value:
2537 * If it matches (and thus, we reset), Success will contain 0
2538 * Otherwise, it will contain a non-zero value.
2539 */
2541 }
2542
2543 /* If success isn't 0, it means we failed somewhere (set or unset) */
2544 if (Success != 0)
2545 {
2547 }
2548
2549 return STATUS_SUCCESS;
2550}
#define NULL
Definition: types.h:112
#define ULONG_PTR
Definition: config.h:101
@ Success
Definition: eventcreate.c:712
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
_In_ PLIST_ENTRY _In_ PSTRING _In_ USHORT _In_opt_ PSTRING _In_opt_ PSTRING _In_ ULONG _In_ ULONG _In_opt_ PVOID _In_opt_ PVOID FilterContext
Definition: fsrtlfuncs.h:746
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
#define FO_FILE_OBJECT_HAS_EXTENSION
Definition: iotypes.h:144
#define STATUS_ALREADY_COMMITTED
Definition: ntstatus.h:270
#define STATUS_SUCCESS
Definition: shellext.h:65
PVOID FilterContext
Definition: io.h:103
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135

Referenced by FsRtlInsertPerFileObjectContext(), and FsRtlPTeardownPerFileObjectContexts().

◆ IoComputeDesiredAccessFileObject()

NTSTATUS NTAPI IoComputeDesiredAccessFileObject ( IN PFILE_OBJECT  FileObject,
IN PACCESS_MASK  DesiredAccess 
)

Definition at line 26 of file util.c.

28{
29 /* Assume failure */
30 *DesiredAccess = 0;
31
32 /* First check we really have a FileObject */
34 {
36 }
37
38 /* Then compute desired access:
39 * Check if the handle has either FILE_WRITE_DATA or FILE_APPEND_DATA was
40 * granted. However, if this is a named pipe, make sure we don't ask for
41 * FILE_APPEND_DATA as it interferes with the FILE_CREATE_PIPE_INSTANCE
42 * access right!
43 */
45
46 return STATUS_SUCCESS;
47}
Type
Definition: Type.h:7
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
#define OBJECT_TO_OBJECT_HEADER(o)
Definition: obtypes.h:111
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define FILE_APPEND_DATA
Definition: nt_native.h:634
#define STATUS_OBJECT_TYPE_MISMATCH
Definition: ntstatus.h:273
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2658
#define FO_NAMED_PIPE
Definition: iotypes.h:1782

Referenced by ObReferenceFileObjectForWrite().

◆ IoCreateDriverList()

NTSTATUS IoCreateDriverList ( VOID  )

◆ IoDestroyDriverList()

NTSTATUS IoDestroyDriverList ( VOID  )

◆ IoGetFileObjectFilterContext()

PVOID NTAPI IoGetFileObjectFilterContext ( IN PFILE_OBJECT  FileObject)

Definition at line 2496 of file file.c.

2497{
2499 {
2500 PFILE_OBJECT_EXTENSION FileObjectExtension;
2501
2502 FileObjectExtension = FileObject->FileObjectExtension;
2503 return FileObjectExtension->FilterContext;
2504 }
2505
2506 return NULL;
2507}

Referenced by FsRtlInsertPerFileObjectContext(), FsRtlLookupPerFileObjectContext(), FsRtlPTeardownPerFileObjectContexts(), and FsRtlRemovePerFileObjectContext().

◆ 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}
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:25
NTSTATUS NTAPI IopGetRelatedTargetDevice(IN PFILE_OBJECT FileObject, OUT PDEVICE_NODE *DeviceNode)
Definition: device.c:653

Referenced by FsRtlNotifyVolumeEvent(), and NtSetVolumeInformationFile().

◆ IoInitCancelHandling()

VOID IoInitCancelHandling ( VOID  )

◆ IoInitFileSystemImplementation()

VOID NTAPI IoInitFileSystemImplementation ( VOID  )

◆ IoInitializeCrashDump()

BOOLEAN NTAPI IoInitializeCrashDump ( IN HANDLE  PageFileHandle)

Definition at line 649 of file iomgr.c.

650{
652 return FALSE;
653}
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by NtCreatePagingFile().

◆ IoInitShutdownNotification()

VOID IoInitShutdownNotification ( VOID  )

◆ IoInitSystem()

BOOLEAN NTAPI IoInitSystem ( IN PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 465 of file iomgr.c.

466{
467 LARGE_INTEGER ExpireTime;
469 CHAR Buffer[256];
470 ANSI_STRING NtBootPath, RootString;
471
472 /* Initialize empty NT Boot Path */
473 RtlInitEmptyAnsiString(&NtBootPath, Buffer, sizeof(Buffer));
474
475 /* Initialize the lookaside lists */
477
478 /* Initialize all locks and lists */
497
498 /* Initialize PnP notifications */
500
501 /* Initialize the reserve IRP */
503 {
504 DPRINT1("IopInitializeReserveIrp failed!\n");
505 return FALSE;
506 }
507
508 /* Initialize Timer List Lock */
510
511 /* Initialize Timer List */
513
514 /* Initialize the DPC/Timer which will call the other Timer Routines */
515 ExpireTime.QuadPart = -10000000;
518 KeSetTimerEx(&IopTimer, ExpireTime, 1000, &IopTimerDpc);
519
520 /* Create Object Types */
522 {
523 DPRINT1("IopCreateObjectTypes failed!\n");
524 return FALSE;
525 }
526
527 /* Create Object Directories */
529 {
530 DPRINT1("IopCreateRootDirectories failed!\n");
531 return FALSE;
532 }
533
534 /* Initialize PnP manager */
536
537 /* Initialize SHIM engine */
539
540 /* Initialize WMI */
542
543 /* Initialize HAL Root Bus Driver */
545
546 /* Reenumerate what HAL has added (synchronously)
547 * This function call should eventually become a 2nd stage of the PnP initialization */
550 NULL,
551 NULL);
552
553 /* Make loader block available for the whole kernel */
554 IopLoaderBlock = LoaderBlock;
555
556 /* Load boot start drivers */
558
559 /* Call back drivers that asked for */
561
562 /* Check if this was a ramdisk boot */
563 if (!_strnicmp(LoaderBlock->ArcBootDeviceName, "ramdisk(0)", 10))
564 {
565 /* Initialize the ramdisk driver */
566 IopStartRamdisk(LoaderBlock);
567 }
568
569 /* No one should need loader block any longer */
571
572 /* Create ARC names for boot devices */
573 Status = IopCreateArcNames(LoaderBlock);
574 if (!NT_SUCCESS(Status))
575 {
576 DPRINT1("IopCreateArcNames failed: %lx\n", Status);
577 return FALSE;
578 }
579
580 /* Mark the system boot partition */
581 if (!IopMarkBootPartition(LoaderBlock))
582 {
583 DPRINT1("IopMarkBootPartition failed!\n");
584 return FALSE;
585 }
586
587 /* The disk subsystem is initialized here and the SystemRoot is set too.
588 * We can finally load other drivers from the boot volume. */
590
591 /* Load system start drivers */
594
595 /* Reinitialize drivers that requested it */
597
598 /* Convert SystemRoot from ARC to NT path */
599 Status = IopReassignSystemRoot(LoaderBlock, &NtBootPath);
600 if (!NT_SUCCESS(Status))
601 {
602 DPRINT1("IopReassignSystemRoot failed: %lx\n", Status);
603 return FALSE;
604 }
605
606 /* Set the ANSI_STRING for the root path */
607 RootString.MaximumLength = NtSystemRoot.MaximumLength / sizeof(WCHAR);
608 RootString.Length = 0;
610 RootString.MaximumLength,
611 TAG_IO);
612
613 /* Convert the path into the ANSI_STRING */
615 if (!NT_SUCCESS(Status))
616 {
617 DPRINT1("RtlUnicodeStringToAnsiString failed: %lx\n", Status);
618 return FALSE;
619 }
620
621 /* Assign drive letters */
622 IoAssignDriveLetters(LoaderBlock,
623 &NtBootPath,
624 (PUCHAR)RootString.Buffer,
625 &RootString);
626
627 /* Update system root */
629 if (!NT_SUCCESS(Status))
630 {
631 DPRINT1("RtlAnsiStringToUnicodeString failed: %lx\n", Status);
632 return FALSE;
633 }
634
635 /* Load the System DLL and its entrypoints */
637 if (!NT_SUCCESS(Status))
638 {
639 DPRINT1("PsLocateSystemDll failed: %lx\n", Status);
640 return FALSE;
641 }
642
643 /* Return success */
644 return TRUE;
645}
VOID FASTCALL IoAssignDriveLetters(IN struct _LOADER_PARAMETER_BLOCK *LoaderBlock, IN PSTRING NtDeviceName, OUT PUCHAR NtSystemPath, OUT PSTRING NtSystemPathString)
Definition: ntoskrnl.c:36
Definition: bufpool.h:45
#define TRUE
Definition: types.h:120
#define _strnicmp(_String1, _String2, _MaxCount)
Definition: compat.h:23
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
#define PagedPool
Definition: env_spec_w32.h:308
LIST_ENTRY IopErrorLogListHead
Definition: error.c:30
LIST_ENTRY DriverReinitListHead
Definition: driver.c:22
KDPC IopTimerDpc
Definition: iotimer.c:22
VOID NTAPI IopInitLookasideLists(VOID)
Definition: iomgr.c:94
BOOLEAN NTAPI IopCreateRootDirectories(VOID)
Definition: iomgr.c:330
LIST_ENTRY ShutdownListHead
Definition: device.c:21
ERESOURCE IopDriverLoadResource
Definition: driver.c:20
ERESOURCE IopSecurityResource
Definition: iomgr.c:60
BOOLEAN PnPBootDriversInitialized
Definition: pnpinit.c:21
BOOLEAN PnpSystemInit
Definition: iomgr.c:17
KSPIN_LOCK DriverBootReinitListLock
Definition: driver.c:28
BOOLEAN NTAPI WmiInitialize(VOID)
Definition: wmi.c:38
KSPIN_LOCK IoStatisticsLock
Definition: iomgr.c:45
BOOLEAN NTAPI IopMarkBootPartition(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: iomgr.c:395
KSPIN_LOCK IopTimerLock
Definition: iotimer.c:18
KSPIN_LOCK ShutdownListLock
Definition: device.c:22
LIST_ENTRY IopCdRomFileSystemQueueHead
Definition: volume.c:22
ERESOURCE IopDatabaseResource
Definition: volume.c:20
LIST_ENTRY DriverBootReinitListHead
Definition: driver.c:27
KSPIN_LOCK IopLogListLock
Definition: error.c:31
KSPIN_LOCK DriverReinitListLock
Definition: driver.c:23
KTIMER IopTimer
Definition: iotimer.c:23
LIST_ENTRY LastChanceShutdownListHead
Definition: device.c:21
VOID NTAPI IopTimerDispatch(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: iotimer.c:32
LIST_ENTRY IopNetworkFileSystemQueueHead
Definition: volume.c:21
LIST_ENTRY IopDiskFileSystemQueueHead
Definition: volume.c:21
PLOADER_PARAMETER_BLOCK IopLoaderBlock
Definition: iomgr.c:87
LIST_ENTRY IopFsNotifyChangeQueueHead
Definition: volume.c:23
BOOLEAN NTAPI IopCreateObjectTypes(VOID)
Definition: iomgr.c:241
LIST_ENTRY IopTimerQueueHead
Definition: iotimer.c:19
LIST_ENTRY IopTapeFileSystemQueueHead
Definition: volume.c:22
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToAnsiString(PANSI_STRING DestinationString, PUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
@ SynchronizationTimer
UNICODE_STRING NtSystemRoot
Definition: init.c:76
VOID NTAPI IopReinitializeBootDrivers(VOID)
Definition: driver.c:1532
BOOLEAN NTAPI IopInitializeReserveIrp(IN PRESERVE_IRP_ALLOCATOR ReserveIrpAllocator)
Definition: irp.c:549
VOID FASTCALL IopInitializeSystemDrivers(VOID)
Definition: driver.c:1210
NTSTATUS NTAPI IopInitializePlugPlayServices(VOID)
Definition: pnpinit.c:287
VOID FASTCALL IopInitializeBootDrivers(VOID)
Definition: driver.c:1023
NTSTATUS NTAPI IopStartRamdisk(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: ramdisk.c:26
VOID NTAPI IopReinitializeDrivers(VOID)
Definition: driver.c:1496
NTSTATUS NTAPI IopReassignSystemRoot(IN PLOADER_PARAMETER_BLOCK LoaderBlock, OUT PANSI_STRING NtBootPath)
Definition: arcname.c:840
VOID PiQueueDeviceAction(_In_ PDEVICE_OBJECT DeviceObject, _In_ DEVICE_ACTION Action, _In_opt_ PKEVENT CompletionEvent, _Out_opt_ NTSTATUS *CompletionStatus)
Queue a device operation to a worker thread.
Definition: devaction.c:2659
VOID PiInitializeNotifications(VOID)
Definition: pnpnotify.c:55
PDEVICE_NODE IopRootDeviceNode
Definition: devnode.c:18
NTSTATUS NTAPI IopCreateArcNames(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: arcname.c:39
RESERVE_IRP_ALLOCATOR IopReserveIrpAllocator
Definition: irp.c:19
NTSTATUS NTAPI ApphelpCacheInitialize(VOID)
Definition: apphelp.c:439
NTSTATUS NTAPI PsLocateSystemDll(VOID)
Definition: psmgr.c:187
USHORT MaximumLength
Definition: env_spec_w32.h:377
PDEVICE_OBJECT PhysicalDeviceObject
Definition: iotypes.h:892
USHORT MaximumLength
Definition: env_spec_w32.h:370
#define TAG_IO
Definition: tag.h:80
BOOLEAN NTAPI KeSetTimerEx(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN LONG Period, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:294
VOID NTAPI KeInitializeTimerEx(OUT PKTIMER Timer, IN TIMER_TYPE Type)
Definition: timerobj.c:244
unsigned char * PUCHAR
Definition: typedefs.h:53
LONGLONG QuadPart
Definition: typedefs.h:114
#define HalInitPnpDriver
Definition: haltypes.h:300
__wchar_t WCHAR
Definition: xmlstorage.h:180
char CHAR
Definition: xmlstorage.h:175

Referenced by Phase1InitializationDiscard().

◆ IoInitVpbImplementation()

VOID NTAPI IoInitVpbImplementation ( VOID  )

◆ IoOpenFileOnDevice()

PVOID IoOpenFileOnDevice ( IN PVOID  SymbolicLink,
IN PWCHAR  Name 
)

◆ IoOpenSymlink()

PVOID IoOpenSymlink ( IN PVOID  SymbolicLink)

◆ IopAbortInterruptedIrp()

VOID NTAPI IopAbortInterruptedIrp ( IN PKEVENT  EventObject,
IN PIRP  Irp 
)

Definition at line 67 of file irp.c.

69{
71 BOOLEAN CancelResult;
73 PAGED_CODE();
74
75 /* Raise IRQL to APC */
77
78 /* Check if nobody completed it yet */
79 if (!KeReadStateEvent(EventObject))
80 {
81 /* First, cancel it */
82 CancelResult = IoCancelIrp(Irp);
84
85 /* Check if we cancelled it */
86 if (CancelResult)
87 {
88 /* Wait for the IRP to be cancelled */
89 Wait.QuadPart = -100000;
90 while (!KeReadStateEvent(EventObject))
91 {
92 /* Delay indefintely */
94 }
95 }
96 else
97 {
98 /* No cancellation done, so wait for the I/O system to kill it */
99 KeWaitForSingleObject(EventObject,
100 Executive,
102 FALSE,
103 NULL);
104 }
105 }
106 else
107 {
108 /* We got preempted, so give up */
110 }
111}
unsigned char BOOLEAN
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
LONG NTAPI KeReadStateEvent(IN PKEVENT Event)
Definition: eventobj.c:120
_In_ WDFDPC _In_ BOOLEAN Wait
Definition: wdfdpc.h:170
@ Executive
Definition: ketypes.h:415

Referenced by IopFinalizeAsynchronousIo(), IopPerformSynchronousRequest(), IopQueryDeviceInformation(), IoSetInformation(), NtQueryInformationFile(), and NtSetInformationFile().

◆ IopAcquireFileObjectLock()

NTSTATUS NTAPI IopAcquireFileObjectLock ( _In_ PFILE_OBJECT  FileObject,
_In_ KPROCESSOR_MODE  AccessMode,
_In_ BOOLEAN  Alertable,
_Out_ PBOOLEAN  LockFailed 
)

Definition at line 2450 of file file.c.

2455{
2457
2458 PAGED_CODE();
2459
2461
2463 do
2464 {
2466 {
2467 break;
2468 }
2470 Executive,
2471 WaitMode,
2472 Alertable,
2473 NULL);
2474 } while (Status == STATUS_SUCCESS);
2475
2477 if (Status == STATUS_SUCCESS)
2478 {
2480 *LockFailed = FALSE;
2481 }
2482 else
2483 {
2484 if (!FileObject->Busy && FileObject->Waiters)
2485 {
2487 }
2488 *LockFailed = TRUE;
2489 }
2490
2491 return Status;
2492}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedExchange
Definition: armddk.h:54
#define InterlockedDecrement
Definition: armddk.h:52
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
_In_ PVOID _In_ BOOLEAN Alertable
Definition: exfuncs.h:453
int32_t * PLONG
Definition: typedefs.h:58
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define ObReferenceObject
Definition: obfuncs.h:204

Referenced by IopLockFileObject().

◆ IopAllocateIrpMustSucceed()

PIRP NTAPI IopAllocateIrpMustSucceed ( IN CCHAR  StackSize)

Definition at line 716 of file irp.c.

717{
718 LONG i;
719 PIRP Irp;
721
722 /* Try to get an IRP */
724 if (Irp)
725 return Irp;
726
727 /* If we fail, start looping till we may get one */
728 i = LONG_MAX;
729 do {
730 i--;
731
732 /* First, sleep for 10ms */
733 Sleep.QuadPart = -10 * 1000 * 10;
735
736 /* Then, retry allocation */
738 if (Irp)
739 return Irp;
740 } while (i > 0);
741
742 return Irp;
743}
static ULONG StackSize
Definition: StackOverflow.c:19
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define LONG_MAX
Definition: limits.h:43
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
long LONG
Definition: pedump.c:60
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790

Referenced by IoCancelFileOpen(), IopCloseFile(), and IopDeleteFile().

◆ IopAllocateReserveIrp()

PIRP NTAPI IopAllocateReserveIrp ( IN CCHAR  StackSize)

Definition at line 573 of file irp.c.

574{
575 /* If we need a stack size higher than what was allocated, then fail */
577 {
578 return NULL;
579 }
580
581 /* Now, wait until the IRP becomes available and reserve it immediately */
583 {
585 Executive,
587 FALSE,
588 NULL);
589 }
590
591 /* It's ours! Initialize it */
593
594 /* And return it to the caller */
596}
VOID NTAPI IoInitializeIrp(IN PIRP Irp, IN USHORT PacketSize, IN CCHAR StackSize)
Definition: irp.c:1854
RESERVE_IRP_ALLOCATOR IopReserveIrpAllocator
Definition: irp.c:19
volatile LONG ReserveIrpInUse
Definition: io.h:504
KEVENT WaitEvent
Definition: io.h:505
#define IoSizeOfIrp(_StackSize)

Referenced by IoPageRead().

◆ IopAssignDeviceResources()

NTSTATUS NTAPI IopAssignDeviceResources ( IN PDEVICE_NODE  DeviceNode)

Definition at line 1116 of file pnpres.c.

1118{
1120 ULONG ListSize;
1121
1123 if (!NT_SUCCESS(Status))
1124 goto ByeBye;
1125
1126 if (!DeviceNode->BootResources && !DeviceNode->ResourceRequirements)
1127 {
1128 /* No resource needed for this device */
1129 DeviceNode->ResourceList = NULL;
1130 DeviceNode->ResourceListTranslated = NULL;
1133
1134 return STATUS_SUCCESS;
1135 }
1136
1137 if (DeviceNode->BootResources)
1138 {
1139 ListSize = PnpDetermineResourceListSize(DeviceNode->BootResources);
1140
1141 DeviceNode->ResourceList = ExAllocatePool(PagedPool, ListSize);
1142 if (!DeviceNode->ResourceList)
1143 {
1145 goto ByeBye;
1146 }
1147
1148 RtlCopyMemory(DeviceNode->ResourceList, DeviceNode->BootResources, ListSize);
1149
1151 if (!NT_SUCCESS(Status))
1152 {
1153 DPRINT1("Boot resources for %wZ cause a resource conflict!\n", &DeviceNode->InstancePath);
1154 ExFreePool(DeviceNode->ResourceList);
1155 DeviceNode->ResourceList = NULL;
1156 }
1157 }
1158 else
1159 {
1160 /* We'll make this from the requirements */
1161 DeviceNode->ResourceList = NULL;
1162 }
1163
1164 /* No resources requirements */
1165 if (!DeviceNode->ResourceRequirements)
1166 goto Finish;
1167
1168 /* Call HAL to fixup our resource requirements list */
1169 HalAdjustResourceList(&DeviceNode->ResourceRequirements);
1170
1171 /* Add resource requirements that aren't in the list we already got */
1173 &DeviceNode->ResourceList);
1174 if (!NT_SUCCESS(Status))
1175 {
1176 DPRINT1("Failed to fixup a resource list from supplied resources for %wZ\n", &DeviceNode->InstancePath);
1178 goto ByeBye;
1179 }
1180
1181 /* IopFixupResourceListWithRequirements should NEVER give us a conflicting list */
1183
1184Finish:
1186 if (!NT_SUCCESS(Status))
1187 {
1189 DPRINT1("Failed to translate resources for %wZ\n", &DeviceNode->InstancePath);
1190 goto ByeBye;
1191 }
1192
1194 if (!NT_SUCCESS(Status))
1195 goto ByeBye;
1196
1198 if (!NT_SUCCESS(Status))
1199 goto ByeBye;
1200
1202
1203 return STATUS_SUCCESS;
1204
1205ByeBye:
1206 if (DeviceNode->ResourceList)
1207 {
1208 ExFreePool(DeviceNode->ResourceList);
1209 DeviceNode->ResourceList = NULL;
1210 }
1211
1212 DeviceNode->ResourceListTranslated = NULL;
1213
1214 return Status;
1215}
#define CM_PROB_TRANSLATION_FAILED
Definition: cfg.h:63
#define CM_PROB_NORMAL_CONFLICT
Definition: cfg.h:42
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
NTSTATUS NTAPI HalAdjustResourceList(IN PIO_RESOURCE_REQUIREMENTS_LIST *ResourceList)
Definition: bus.c:26
#define ASSERT(a)
Definition: mode.c:44
@ DeviceNodeResourcesAssigned
Definition: iotypes.h:425
#define DNF_NO_RESOURCE_REQUIRED
Definition: iotypes.h:178
ULONG NTAPI PnpDetermineResourceListSize(IN PCM_RESOURCE_LIST ResourceList)
Definition: pnpmgr.c:1237
PNP_DEVNODE_STATE PiSetDevNodeState(_In_ PDEVICE_NODE DeviceNode, _In_ PNP_DEVNODE_STATE NewState)
Definition: devnode.c:108
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define STATUS_CONFLICTING_ADDRESSES
Definition: ntstatus.h:261
NTSTATUS IopUpdateResourceMapForPnPDevice(IN PDEVICE_NODE DeviceNode)
Definition: pnpres.c:961
NTSTATUS NTAPI IopFixupResourceListWithRequirements(IN PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList, OUT PCM_RESOURCE_LIST *ResourceList)
Definition: pnpres.c:219
static NTSTATUS IopTranslateDeviceResources(IN PDEVICE_NODE DeviceNode)
Definition: pnpres.c:969
static NTSTATUS IopUpdateControlKeyWithResources(IN PDEVICE_NODE DeviceNode)
Definition: pnpres.c:716
static NTSTATUS IopFilterResourceRequirements(IN PDEVICE_NODE DeviceNode)
Definition: pnpres.c:773
NTSTATUS NTAPI IopDetectResourceConflict(IN PCM_RESOURCE_LIST ResourceList, IN BOOLEAN Silent, OUT OPTIONAL PCM_PARTIAL_RESOURCE_DESCRIPTOR ConflictingDescriptor)
Definition: pnpres.c:1255
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263

Referenced by IoReportDetectedDevice(), and PiDevNodeStateMachine().

◆ IopAttachFilterDrivers()

NTSTATUS FASTCALL IopAttachFilterDrivers ( IN PDEVICE_NODE  DeviceNode,
IN HANDLE  EnumSubKey,
IN HANDLE  ClassKey,
IN BOOLEAN  Lower 
)

◆ IopBootLog()

VOID IopBootLog ( IN PUNICODE_STRING  DriverName,
IN BOOLEAN  Success 
)

◆ IopCheckVpbMounted()

PVPB NTAPI IopCheckVpbMounted ( IN POPEN_PACKET  OpenPacket,
IN PDEVICE_OBJECT  DeviceObject,
IN PUNICODE_STRING  RemainingName,
OUT PNTSTATUS  Status 
)

Definition at line 76 of file volume.c.

80{
83 PVPB Vpb = NULL;
84
85 /* Lock the VPBs */
87
88 /* Set VPB mount settings */
89 Raw = !RemainingName->Length && !OpenPacket->RelatedFileObject;
90 Alertable = (OpenPacket->CreateOptions & FILE_SYNCHRONOUS_IO_ALERT) ?
91 TRUE: FALSE;
92
93 /* Start looping until the VPB is mounted */
94 while (!(DeviceObject->Vpb->Flags & VPB_MOUNTED))
95 {
96 /* Release the lock */
98
99 /* Mount the volume */
101 Raw,
102 FALSE,
103 Alertable,
104 &Vpb);
105
106 /* Check if we failed or if we were alerted */
107 if (!(NT_SUCCESS(*Status)) ||
108 (*Status == STATUS_USER_APC) ||
110 {
111 /* Dereference the device, since IopParseDevice referenced it */
113
114 /* Check if it was a total failure */
115 if (!NT_SUCCESS(*Status)) return NULL;
116
117 /* Otherwise we were alerted */
119 return NULL;
120 }
121 /*
122 * In case IopMountVolume returns a valid VPB
123 * Then, the volume is mounted, return it
124 */
125 else if (Vpb != NULL)
126 {
127 return Vpb;
128 }
129
130 /* Re-acquire the lock */
132 }
133
134 /* Make sure the VPB isn't locked */
136 if (Vpb->Flags & VPB_LOCKED)
137 {
138 /* We're locked, so fail */
140 Vpb = NULL;
141 }
142 else
143 {
144 /* Success! Reference the VPB */
145 Vpb->ReferenceCount++;
146 }
147
148 /* Release the lock and return the VPB */
150 return Vpb;
151}
_Inout_ PFCB _Inout_ PUNICODE_STRING RemainingName
Definition: cdprocs.h:802
IN OUT PVCB IN PDEVICE_OBJECT IN PVPB Vpb
Definition: fatprocs.h:1675
#define FILE_SYNCHRONOUS_IO_ALERT
Definition: from_kernel.h:30
VOID NTAPI IopDereferenceDeviceObject(IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN ForceUnload)
Definition: device.c:462
VOID NTAPI IoReleaseVpbSpinLock(IN KIRQL Irql)
Definition: volume.c:1215
NTSTATUS NTAPI IopMountVolume(IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN AllowRawMount, IN BOOLEAN DeviceIsLocked, IN BOOLEAN Alertable, OUT PVPB *Vpb)
Definition: volume.c:462
VOID NTAPI IoAcquireVpbSpinLock(OUT PKIRQL Irql)
Definition: volume.c:1204
#define STATUS_ALERTED
Definition: ntstatus.h:80
#define STATUS_USER_APC
Definition: ntstatus.h:78
@ Raw
Definition: sacdrv.h:279
PVPB Vpb
Definition: cdstruc.h:511
Definition: iotypes.h:189
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define STATUS_WRONG_VOLUME
Definition: udferr_usr.h:140
#define VPB_MOUNTED
Definition: iotypes.h:1807
#define VPB_LOCKED
Definition: iotypes.h:1808

Referenced by IopParseDevice().

◆ IopCleanupFailedIrp()

NTSTATUS NTAPI IopCleanupFailedIrp ( IN PFILE_OBJECT  FileObject,
IN PKEVENT  EventObject,
IN PVOID Buffer  OPTIONAL 
)

Definition at line 45 of file irp.c.

48{
49 PAGED_CODE();
50
51 /* Dereference the event */
52 if (EventObject) ObDereferenceObject(EventObject);
53
54 /* Free a buffer, if any */
56
57 /* If this was a file opened for synch I/O, then unlock it */
59
60 /* Now dereference it and return */
63}
static __inline VOID IopUnlockFileObject(IN PFILE_OBJECT FileObject)
Definition: io_x.h:36
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by IopDeviceFsIoControl(), IopGetSetSecurityObject(), IopQueryDeviceInformation(), IoSetInformation(), NtFlushBuffersFile(), NtLockFile(), NtNotifyChangeDirectoryFile(), NtQueryDirectoryFile(), NtQueryInformationFile(), NtQueryVolumeInformationFile(), NtReadFile(), NtSetInformationFile(), NtSetVolumeInformationFile(), NtUnlockFile(), and NtWriteFile().

◆ IopCloseFile()

VOID NTAPI IopCloseFile ( IN PEPROCESS Process  OPTIONAL,
IN PVOID  Object,
IN ACCESS_MASK  GrantedAccess,
IN ULONG  ProcessHandleCount,
IN ULONG  SystemHandleCount 
)

Definition at line 2178 of file file.c.

2183{
2184 PFILE_OBJECT FileObject = (PFILE_OBJECT)ObjectBody;
2185 KEVENT Event;
2186 PIRP Irp;
2187 PIO_STACK_LOCATION StackPtr;
2190 KIRQL OldIrql;
2192 IOTRACE(IO_FILE_DEBUG, "ObjectBody: %p\n", ObjectBody);
2193
2194 /* If this isn't the last handle for the current process, quit */
2195 if (HandleCount != 1) return;
2196
2197 /* Check if the file is locked and has more then one handle opened */
2198 if ((FileObject->LockOperation) && (SystemHandleCount != 1))
2199 {
2200 /* Check if this is a direct open or not */
2202 {
2203 /* Get the attached device */
2205 }
2206 else
2207 {
2208 /* Get the FO's device */
2210 }
2211
2212 /* Check if this is a sync FO and lock it */
2214 {
2216 }
2217
2218 /* Go the FastIO path if possible, otherwise fall back to IRP */
2219 if (DeviceObject->DriverObject->FastIoDispatch == NULL ||
2220 DeviceObject->DriverObject->FastIoDispatch->FastIoUnlockAll == NULL ||
2221 !DeviceObject->DriverObject->FastIoDispatch->FastIoUnlockAll(FileObject, PsGetCurrentProcess(), &IoStatusBlock, DeviceObject))
2222 {
2223 /* Clear and set up Events */
2224 KeClearEvent(&FileObject->Event);
2226
2227 /* Allocate an IRP */
2229
2230 /* Set it up */
2231 Irp->UserEvent = &Event;
2232 Irp->UserIosb = &Irp->IoStatus;
2233 Irp->Tail.Overlay.Thread = PsGetCurrentThread();
2234 Irp->Tail.Overlay.OriginalFileObject = FileObject;
2235 Irp->RequestorMode = KernelMode;
2236 Irp->Flags = IRP_SYNCHRONOUS_API;
2237 Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
2239
2240 /* Set up Stack Pointer Data */
2241 StackPtr = IoGetNextIrpStackLocation(Irp);
2243 StackPtr->MinorFunction = IRP_MN_UNLOCK_ALL;
2244 StackPtr->FileObject = FileObject;
2245
2246 /* Queue the IRP */
2248
2249 /* Call the FS Driver */
2251 if (Status == STATUS_PENDING)
2252 {
2253 /* Wait for completion */
2255 }
2256
2257 /* IO will unqueue & free for us */
2258 }
2259
2260 /* Release the lock if we were holding it */
2262 {
2264 }
2265 }
2266
2267 /* Make sure this is the last handle */
2268 if (SystemHandleCount != 1) return;
2269
2270 /* Check if this is a direct open or not */
2271 if (FileObject->Flags & FO_DIRECT_DEVICE_OPEN)
2272 {
2273 /* Get the attached device */
2275 }
2276 else
2277 {
2278 /* Get the FO's device */
2280 }
2281
2282 /* Set the handle created flag */
2283 FileObject->Flags |= FO_HANDLE_CREATED;
2284
2285 /* Check if this is a sync FO and lock it */
2286 if (Process != NULL &&
2288 {
2290 }
2291
2292 /* Clear and set up Events */
2293 KeClearEvent(&FileObject->Event);
2295
2296 /* Allocate an IRP */
2298
2299 /* Set it up */
2300 Irp->UserEvent = &Event;
2301 Irp->UserIosb = &Irp->IoStatus;
2302 Irp->Tail.Overlay.Thread = PsGetCurrentThread();
2303 Irp->Tail.Overlay.OriginalFileObject = FileObject;
2304 Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
2306
2307 /* Set up Stack Pointer Data */
2308 StackPtr = IoGetNextIrpStackLocation(Irp);
2309 StackPtr->MajorFunction = IRP_MJ_CLEANUP;
2310 StackPtr->FileObject = FileObject;
2311
2312 /* Queue the IRP */
2314
2315 /* Update operation counts */
2317
2318 /* Call the FS Driver */
2320 if (Status == STATUS_PENDING)
2321 {
2322 /* Wait for completion */
2324 }
2325
2326 /* Unqueue the IRP */
2330
2331 /* Free the IRP */
2332 IoFreeIrp(Irp);
2333
2334 /* Release the lock if we were holding it */
2335 if (Process != NULL &&
2337 {
2339 }
2340}
#define VOID
Definition: acefi.h:82
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
static __inline NTSTATUS IopLockFileObject(_In_ PFILE_OBJECT FileObject, _In_ KPROCESSOR_MODE WaitMode)
Definition: io_x.h:12
FORCEINLINE VOID IopQueueIrpToThread(IN PIRP Irp)
Definition: io_x.h:49
static __inline VOID IopUpdateOperationCount(IN IOP_TRANSFER_TYPE Type)
Definition: io_x.h:82
FORCEINLINE VOID IopUnQueueIrpFromThread(IN PIRP Irp)
Definition: io_x.h:66
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
@ SynchronizationEvent
PIRP NTAPI IopAllocateIrpMustSucceed(IN CCHAR StackSize)
Definition: irp.c:716
#define IO_FILE_DEBUG
Definition: io.h:20
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
PDEVICE_OBJECT NTAPI IoGetAttachedDevice(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1385
#define IoCallDriver
Definition: irp.c:1225
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
#define STATUS_PENDING
Definition: ntstatus.h:82
#define IRP_MJ_LOCK_CONTROL
Definition: rdpdr.c:53
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
#define IRP_MN_UNLOCK_ALL
Definition: iotypes.h:4412
#define IRP_CLOSE_OPERATION
#define FO_HANDLE_CREATED
Definition: iotypes.h:1794
#define FO_DIRECT_DEVICE_OPEN
Definition: iotypes.h:1787
* PFILE_OBJECT
Definition: iotypes.h:1998
#define IRP_MJ_CLEANUP
@ UserRequest
Definition: ketypes.h:421
#define PsGetCurrentProcess
Definition: psfuncs.h:17

Referenced by IopCreateObjectTypes(), and IopDeleteFile().

◆ IopCompleteRequest()

VOID NTAPI IopCompleteRequest ( IN PKAPC  Apc,
IN PKNORMAL_ROUTINE NormalRoutine,
IN PVOID NormalContext,
IN PVOID SystemArgument1,
IN PVOID SystemArgument2 
)

Definition at line 238 of file irp.c.

243{
245 PIRP Irp;
246 PMDL Mdl, NextMdl;
247 PVOID Port = NULL, Key = NULL;
248 BOOLEAN SignaledCreateRequest = FALSE;
249
250 /* Get data from the APC */
252 Irp = CONTAINING_RECORD(Apc, IRP, Tail.Apc);
254 "%s - Completing IRP %p for %p\n",
256 Irp,
257 FileObject);
258
259 /* Sanity check */
260 ASSERT(Irp->IoStatus.Status != (NTSTATUS)0xFFFFFFFF);
261
262 /* Check if we have a file object */
263 if (*SystemArgument2)
264 {
265 /* Check if we're reparsing */
266 if ((Irp->IoStatus.Status == STATUS_REPARSE) &&
267 (Irp->IoStatus.Information == IO_REPARSE_TAG_MOUNT_POINT))
268 {
269 PREPARSE_DATA_BUFFER ReparseData;
270
272
276
277 IopDoNameTransmogrify(Irp, FileObject, ReparseData);
278 }
279 }
280
281 /* Handle Buffered case first */
282 if (Irp->Flags & IRP_BUFFERED_IO)
283 {
284 /* Check if we have an input buffer and if we succeeded */
285 if ((Irp->Flags & IRP_INPUT_OPERATION) &&
286 (Irp->IoStatus.Status != STATUS_VERIFY_REQUIRED) &&
287 !(NT_ERROR(Irp->IoStatus.Status)))
288 {
290 {
291 /* Copy the buffer back to the user */
292 RtlCopyMemory(Irp->UserBuffer,
293 Irp->AssociatedIrp.SystemBuffer,
294 Irp->IoStatus.Information);
295 }
297 {
298 /* Fail the IRP */
299 Irp->IoStatus.Status = _SEH2_GetExceptionCode();
300 }
301 _SEH2_END;
302 }
303
304 /* Also check if we should de-allocate it */
305 if (Irp->Flags & IRP_DEALLOCATE_BUFFER)
306 {
307 /* Deallocate it */
308 ExFreePool(Irp->AssociatedIrp.SystemBuffer);
309 }
310 }
311
312 /* Now we got rid of these two... */
314
315 /* Check if there's an MDL */
316 for (Mdl = Irp->MdlAddress; Mdl; Mdl = NextMdl)
317 {
318 /* Free it */
319 NextMdl = Mdl->Next;
320 IoFreeMdl(Mdl);
321 }
322
323 /* No MDLs left */
324 Irp->MdlAddress = NULL;
325
326 /*
327 * Check if either the request was completed without any errors
328 * (but warnings are OK!), or if it was completed with an error, but
329 * did return from a pending I/O Operation and is not synchronous.
330 */
331 if (!NT_ERROR(Irp->IoStatus.Status) ||
332 (Irp->PendingReturned &&
334 {
335 /* Get any information we need from the FO before we kill it */
336 if ((FileObject) && (FileObject->CompletionContext))
337 {
338 /* Save Completion Data */
339 Port = FileObject->CompletionContext->Port;
340 Key = FileObject->CompletionContext->Key;
341 }
342
343 /* Check for UserIos */
344 if (Irp->UserIosb != NULL)
345 {
346 /* Use SEH to make sure we don't write somewhere invalid */
348 {
349 /* Save the IOSB Information */
350 *Irp->UserIosb = Irp->IoStatus;
351 }
353 {
354 /* Ignore any error */
355 }
356 _SEH2_END;
357 }
358
359 /* Check if we have an event or a file object */
360 if (Irp->UserEvent)
361 {
362 /* At the very least, this is a PKEVENT, so signal it always */
363 KeSetEvent(Irp->UserEvent, 0, FALSE);
364
365 /* Check if we also have a File Object */
366 if (FileObject)
367 {
368 /* Check if this is an Asynch API */
369 if (!(Irp->Flags & IRP_SYNCHRONOUS_API))
370 {
371 /* Dereference the event */
372 ObDereferenceObject(Irp->UserEvent);
373 }
374
375 /*
376 * Now, if this is a Synch I/O File Object, then this event is
377 * NOT an actual Executive Event, so we won't dereference it,
378 * and instead, we will signal the File Object
379 */
380 if ((FileObject->Flags & FO_SYNCHRONOUS_IO) &&
381 !(Irp->Flags & IRP_OB_QUERY_NAME))
382 {
383 /* Signal the file object and set the status */
384 KeSetEvent(&FileObject->Event, 0, FALSE);
385 FileObject->FinalStatus = Irp->IoStatus.Status;
386 }
387
388 /*
389 * This could also be a create operation, in which case we want
390 * to make sure there's no APC fired.
391 */
392 if (Irp->Flags & IRP_CREATE_OPERATION)
393 {
394 /* Clear the APC Routine and remember this */
395 Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
396 SignaledCreateRequest = TRUE;
397 }
398 }
399 }
400 else if (FileObject)
401 {
402 /* Signal the file object and set the status */
403 KeSetEvent(&FileObject->Event, 0, FALSE);
404 FileObject->FinalStatus = Irp->IoStatus.Status;
405
406 /*
407 * This could also be a create operation, in which case we want
408 * to make sure there's no APC fired.
409 */
410 if (Irp->Flags & IRP_CREATE_OPERATION)
411 {
412 /* Clear the APC Routine and remember this */
413 Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
414 SignaledCreateRequest = TRUE;
415 }
416 }
417
418 /* Update transfer count for everything but create operation */
419 if (!(Irp->Flags & IRP_CREATE_OPERATION))
420 {
421 if (Irp->Flags & IRP_WRITE_OPERATION)
422 {
423 /* Update write transfer count */
425 (ULONG)Irp->IoStatus.Information);
426 }
427 else if (Irp->Flags & IRP_READ_OPERATION)
428 {
429 /* Update read transfer count */
431 (ULONG)Irp->IoStatus.Information);
432 }
433 else
434 {
435 /* Update other transfer count */
437 (ULONG)Irp->IoStatus.Information);
438 }
439 }
440
441 /* Now that we've signaled the events, de-associate the IRP */
443
444 /* Now check if a User APC Routine was requested */
445 if (Irp->Overlay.AsynchronousParameters.UserApcRoutine)
446 {
447 /* Initialize it */
448 KeInitializeApc(&Irp->Tail.Apc,
454 Overlay.AsynchronousParameters.UserApcRoutine,
455 Irp->RequestorMode,
456 Irp->
457 Overlay.AsynchronousParameters.UserApcContext);
458
459 /* Queue it */
460 KeInsertQueueApc(&Irp->Tail.Apc, Irp->UserIosb, NULL, 2);
461 }
462 else if ((Port) &&
463 (Irp->Overlay.AsynchronousParameters.UserApcContext))
464 {
465 /* We have an I/O Completion setup... create the special Overlay */
466 Irp->Tail.CompletionKey = Key;
467 Irp->Tail.Overlay.PacketType = IopCompletionPacketIrp;
468 KeInsertQueue(Port, &Irp->Tail.Overlay.ListEntry);
469 }
470 else
471 {
472 /* Free the IRP since we don't need it anymore */
473 IoFreeIrp(Irp);
474 }
475
476 /* Check if we have a file object that wasn't part of a create */
477 if ((FileObject) && !(SignaledCreateRequest))
478 {
479 /* Dereference it, since it's not needed anymore either */
481 }
482 }
483 else
484 {
485 /*
486 * Either we didn't return from the request, or we did return but this
487 * request was synchronous.
488 */
489 if ((Irp->PendingReturned) && (FileObject))
490 {
491 /* So we did return with a synch operation, was it the IRP? */
492 if (Irp->Flags & IRP_SYNCHRONOUS_API)
493 {
494 /* Yes, this IRP was synchronous, so return the I/O Status */
495 *Irp->UserIosb = Irp->IoStatus;
496
497 /* Now check if the user gave an event */
498 if (Irp->UserEvent)
499 {
500 /* Signal it */
501 KeSetEvent(Irp->UserEvent, 0, FALSE);
502 }
503 else
504 {
505 /* No event was given, so signal the FO instead */
506 KeSetEvent(&FileObject->Event, 0, FALSE);
507 }
508 }
509 else
510 {
511 /*
512 * It's not the IRP that was synchronous, it was the FO
513 * that was opened this way. Signal its event.
514 */
515 FileObject->FinalStatus = Irp->IoStatus.Status;
516 KeSetEvent(&FileObject->Event, 0, FALSE);
517 }
518 }
519
520 /* Now that we got here, we do this for incomplete I/Os as well */
521 if ((FileObject) && !(Irp->Flags & IRP_CREATE_OPERATION))
522 {
523 /* Dereference the File Object unless this was a create */
525 }
526
527 /*
528 * Check if this was an Executive Event (remember that we know this
529 * by checking if the IRP is synchronous)
530 */
531 if ((Irp->UserEvent) &&
532 (FileObject) &&
533 !(Irp->Flags & IRP_SYNCHRONOUS_API))
534 {
535 /* This isn't a PKEVENT, so dereference it */
536 ObDereferenceObject(Irp->UserEvent);
537 }
538
539 /* Now that we've signaled the events, de-associate the IRP */
541
542 /* Free the IRP as well */
543 IoFreeIrp(Irp);
544 }
545}
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define IoFreeMdl
Definition: fxmdl.h:89
#define KeGetCurrentThread
Definition: hal.h:55
CPPORT Port[4]
Definition: headless.c:35
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
static __inline VOID IopUpdateTransferCount(IN IOP_TRANSFER_TYPE Type, IN ULONG TransferCount)
Definition: io_x.h:116
@ CurrentApcEnvironment
Definition: ketypes.h:769
VOID(NTAPI * PKNORMAL_ROUTINE)(IN PVOID NormalContext OPTIONAL, IN PVOID SystemArgument1 OPTIONAL, IN PVOID SystemArgument2 OPTIONAL)
Definition: ketypes.h:744
VOID NTAPI IopDoNameTransmogrify(IN PIRP Irp, IN PFILE_OBJECT FileObject, IN PREPARSE_DATA_BUFFER DataBuffer)
Definition: file.c:170
#define IsIrpSynchronous(Irp, FileObject)
Definition: io.h:120
VOID NTAPI IopAbortIrpKernelApc(IN PKAPC Apc)
Definition: irp.c:37
VOID NTAPI IopFreeIrpKernelApc(IN PKAPC Apc, IN PKNORMAL_ROUTINE *NormalRoutine, IN PVOID *NormalContext, IN PVOID *SystemArgument1, IN PVOID *SystemArgument2)
Definition: irp.c:25
BOOLEAN NTAPI KeInsertQueueApc(IN PKAPC Apc, IN PVOID SystemArgument1, IN PVOID SystemArgument2, IN KPRIORITY PriorityBoost)
Definition: apc.c:735
VOID NTAPI KeInitializeApc(IN PKAPC Apc, IN PKTHREAD Thread, IN KAPC_ENVIRONMENT TargetEnvironment, IN PKKERNEL_ROUTINE KernelRoutine, IN PKRUNDOWN_ROUTINE RundownRoutine OPTIONAL, IN PKNORMAL_ROUTINE NormalRoutine, IN KPROCESSOR_MODE Mode, IN PVOID Context)
Definition: apc.c:651
LONG NTAPI KeInsertQueue(IN PKQUEUE Queue, IN PLIST_ENTRY Entry)
Definition: queue.c:198
#define STATUS_REPARSE
Definition: ntstatus.h:83
VOID NTAPI ObDereferenceObjectDeferDelete(IN PVOID Object)
Definition: obref.c:358
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:159
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:34
struct _REPARSE_DATA_BUFFER * PREPARSE_DATA_BUFFER
Key()
Definition: map_test.cpp:305
USHORT ReparseDataLength
Definition: shellext.h:166
#define STATUS_VERIFY_REQUIRED
Definition: udferr_usr.h:130
#define NT_ERROR(Status)
Definition: umtypes.h:106
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl
#define IRP_DEALLOCATE_BUFFER
#define IRP_INPUT_OPERATION
#define IRP_OB_QUERY_NAME
#define IRP_WRITE_OPERATION
#define IRP_CREATE_OPERATION
#define MAXIMUM_REPARSE_DATA_BUFFER_SIZE
Definition: iotypes.h:7213
#define IRP_READ_OPERATION
#define IO_REPARSE_TAG_MOUNT_POINT
Definition: iotypes.h:7231
#define IRP_BUFFERED_IO
_In_opt_ PVOID _In_opt_ PVOID SystemArgument1
Definition: ketypes.h:688
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2
Definition: ketypes.h:689

Referenced by IofCompleteRequest(), IopPerformSynchronousRequest(), NtQueryInformationFile(), and NtSetInformationFile().

◆ IopCreateArcNames()

NTSTATUS NTAPI IopCreateArcNames ( IN PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 39 of file arcname.c.

40{
43 CHAR Buffer[128];
44 BOOLEAN SingleDisk;
45 BOOLEAN FoundBoot = FALSE;
46 UNICODE_STRING SystemDevice, LoaderPathNameW, BootDeviceName;
47 PARC_DISK_INFORMATION ArcDiskInfo = LoaderBlock->ArcDiskInformation;
48 ANSI_STRING ArcSystemString, ArcString, LanmanRedirector, LoaderPathNameA;
49
50 /* Check if we only have one disk on the machine */
51 SingleDisk = (ArcDiskInfo->DiskSignatureListHead.Flink->Flink ==
52 &ArcDiskInfo->DiskSignatureListHead);
53
54 /* Create the global HAL partition name */
55 sprintf(Buffer, "\\ArcName\\%s", LoaderBlock->ArcHalDeviceName);
56 RtlInitAnsiString(&ArcString, Buffer);
58 if (!NT_SUCCESS(Status))
59 return Status;
60
61 /* Create the global system partition name */
62 sprintf(Buffer, "\\ArcName\\%s", LoaderBlock->ArcBootDeviceName);
63 RtlInitAnsiString(&ArcString, Buffer);
65 if (!NT_SUCCESS(Status))
66 return Status;
67
68 /* Allocate memory for the string */
69 Length = strlen(LoaderBlock->ArcBootDeviceName) + sizeof(ANSI_NULL);
71 Length,
72 TAG_IO);
74 {
75 /* Copy the name */
77 LoaderBlock->ArcBootDeviceName,
78 Length);
79 }
80
81 /* Check if we only found a disk, but we're booting from CD-ROM */
82 if ((SingleDisk) && strstr(LoaderBlock->ArcBootDeviceName, "cdrom"))
83 {
84 /* Then disable single-disk mode, since there's a CD drive out there */
85 SingleDisk = FALSE;
86 }
87
88 /* Build the boot strings */
89 RtlInitAnsiString(&ArcSystemString, LoaderBlock->ArcHalDeviceName);
90
91 /* If we are doing remote booting */
93 {
94 /* Yes, we have found boot device */
95 FoundBoot = TRUE;
96
97 /* Get NT device name */
98 RtlInitAnsiString(&LanmanRedirector, "\\Device\\LanmanRedirector");
99 Status = RtlAnsiStringToUnicodeString(&SystemDevice, &LanmanRedirector, TRUE);
100 if (!NT_SUCCESS(Status))
101 {
102 return Status;
103 }
104
105 /* Get ARC booting device name (in net(0) something) */
106 sprintf(Buffer, "\\ArcName\\%s", LoaderBlock->ArcBootDeviceName);
107 RtlInitAnsiString(&ArcString, Buffer);
108 Status = RtlAnsiStringToUnicodeString(&BootDeviceName, &ArcString, TRUE);
109 if (NT_SUCCESS(Status))
110 {
111 /* Map ARC to NT name */
112 IoAssignArcName(&BootDeviceName, &SystemDevice);
113 RtlFreeUnicodeString(&BootDeviceName);
114
115 /* Now, get loader path name */
116 RtlInitAnsiString(&LoaderPathNameA, LoaderBlock->NtHalPathName);
117 Status = RtlAnsiStringToUnicodeString(&LoaderPathNameW, &LoaderPathNameA, TRUE);
118 if (!NT_SUCCESS(Status))
119 {
120 RtlFreeUnicodeString(&SystemDevice);
121 return Status;
122 }
123
124 /* And set it has system partition */
125 IopStoreSystemPartitionInformation(&SystemDevice, &LoaderPathNameW);
126 }
127
128 RtlFreeUnicodeString(&SystemDevice);
129
130 /* Don't quit here, even if everything went fine!
131 * We need IopCreateArcNamesDisk to properly map
132 * devices with symlinks.
133 * It will return success if the mapping process went fine
134 * even if it didn't find boot device.
135 * It won't reset boot device finding status as well.
136 */
137 }
138
139 /* Loop every disk and try to find boot disk */
140 Status = IopCreateArcNamesDisk(LoaderBlock, SingleDisk, &FoundBoot);
141 /* If it succeeded but we didn't find boot device, try to browse Cds */
142 if (NT_SUCCESS(Status) && !FoundBoot)
143 {
144 Status = IopCreateArcNamesCd(LoaderBlock);
145 }
146
147 /* Return success */
148 return Status;
149}
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define sprintf(buf, format,...)
Definition: sprintf.c:55
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define ANSI_NULL
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
BOOLEAN IoRemoteBootClient
Definition: init.c:70
VOID IopStoreSystemPartitionInformation(_In_ PUNICODE_STRING NtSystemPartitionDeviceName, _In_ PUNICODE_STRING OsLoaderPathName)
Definition: iorsrce.c:860
NTSTATUS NTAPI IopCreateArcNamesDisk(IN PLOADER_PARAMETER_BLOCK LoaderBlock, IN BOOLEAN SingleDisk, OUT PBOOLEAN FoundBoot)
Definition: arcname.c:416
NTSTATUS NTAPI IopCreateArcNamesCd(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Definition: arcname.c:154
UNICODE_STRING IoArcHalDeviceName
Definition: arcname.c:19
UNICODE_STRING IoArcBootDeviceName
Definition: arcname.c:19
PCHAR IoLoaderArcBootDeviceName
Definition: arcname.c:20
LIST_ENTRY DiskSignatureListHead
Definition: arc.h:268
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define IoAssignArcName(_ArcName, _DeviceName)

Referenced by IoInitSystem().

◆ IopCreateDeviceKeyPath()

NTSTATUS NTAPI IopCreateDeviceKeyPath ( IN PCUNICODE_STRING  RegistryPath,
IN ULONG  CreateOptions,
OUT PHANDLE  Handle 
)

Definition at line 522 of file pnpmgr.c.

525{
527 HANDLE hParent = NULL, hKey;
530 PCWSTR Current, Last;
533
534 /* Assume failure */
535 *Handle = NULL;
536
537 /* Open root key for device instances */
539 if (!NT_SUCCESS(Status))
540 {
541 DPRINT1("ZwOpenKey('%wZ') failed with status 0x%08lx\n", &EnumU, Status);
542 return Status;
543 }
544
545 Current = KeyName.Buffer = RegistryPath->Buffer;
546 Last = &RegistryPath->Buffer[RegistryPath->Length / sizeof(WCHAR)];
547
548 /* Go up to the end of the string */
549 while (Current <= Last)
550 {
551 if (Current != Last && *Current != L'\\')
552 {
553 /* Not the end of the string and not a separator */
554 Current++;
555 continue;
556 }
557
558 /* Prepare relative key name */
559 Length = (USHORT)((ULONG_PTR)Current - (ULONG_PTR)KeyName.Buffer);
560 KeyName.MaximumLength = KeyName.Length = Length;
561 DPRINT("Create '%wZ'\n", &KeyName);
562
563 /* Open key */
565 &KeyName,
567 hParent,
568 NULL);
569 Status = ZwCreateKey(&hKey,
570 Current == Last ? KEY_ALL_ACCESS : KEY_CREATE_SUB_KEY,
572 0,
573 NULL,
575 NULL);
576
577 /* Close parent key handle, we don't need it anymore */
578 if (hParent)
579 ZwClose(hParent);
580
581 /* Key opening/creating failed? */
582 if (!NT_SUCCESS(Status))
583 {
584 DPRINT1("ZwCreateKey('%wZ') failed with status 0x%08lx\n", &KeyName, Status);
585 return Status;
586 }
587
588 /* Check if it is the end of the string */
589 if (Current == Last)
590 {
591 /* Yes, return success */
592 *Handle = hKey;
593 return STATUS_SUCCESS;
594 }
595
596 /* Start with this new parent key */
597 hParent = hKey;
598 Current++;
599 KeyName.Buffer = (PWSTR)Current;
600 }
601
602 return STATUS_UNSUCCESSFUL;
603}
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
FxAutoRegKey hKey
ULONG Handle
Definition: gdb_input.c:15
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define KEY_CREATE_SUB_KEY
Definition: nt_native.h:1018
#define ENUM_ROOT
Definition: io.h:53
#define L(x)
Definition: ntvdm.h:50
unsigned short USHORT
Definition: pedump.c:61
NTSTATUS NTAPI IopOpenRegistryKeyEx(PHANDLE KeyHandle, HANDLE ParentKey, PUNICODE_STRING Name, ACCESS_MASK DesiredAccess)
Definition: pnpmgr.c:885
#define DPRINT
Definition: sndvol32.h:71
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
uint16_t * PWSTR
Definition: typedefs.h:56
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2699
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_opt_ WDFKEY _In_ PCUNICODE_STRING _In_ ACCESS_MASK _In_ ULONG CreateOptions
Definition: wdfregistry.h:118

Referenced by IopInstallCriticalDevice(), IopQueryDeviceCapabilities(), IoReportDetectedDevice(), PiControlInitializeDevice(), and PiInitializeDevNode().

◆ IopCreateRegistryKeyEx()

NTSTATUS NTAPI IopCreateRegistryKeyEx ( OUT PHANDLE  Handle,
IN HANDLE BaseHandle  OPTIONAL,
IN PUNICODE_STRING  KeyName,
IN ACCESS_MASK  DesiredAccess,
IN ULONG  CreateOptions,
OUT PULONG Disposition  OPTIONAL 
)

◆ IopCreateVpb()

NTSTATUS NTAPI IopCreateVpb ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 158 of file volume.c.

159{
160 PVPB Vpb;
161
162 /* Allocate the Vpb */
164 sizeof(VPB),
165 TAG_VPB);
167
168 /* Clear it so we don't waste time manually */
169 RtlZeroMemory(Vpb, sizeof(VPB));
170
171 /* Set the Header and Device Field */
172 Vpb->Type = IO_TYPE_VPB;
173 Vpb->Size = sizeof(VPB);
174 Vpb->RealDevice = DeviceObject;
175
176 /* Link it to the Device Object */
177 DeviceObject->Vpb = Vpb;
178 return STATUS_SUCCESS;
179}
#define TAG_VPB
Definition: cdprocs.h:106
#define NonPagedPool
Definition: env_spec_w32.h:307
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IO_TYPE_VPB
struct _VPB VPB

Referenced by IoCreateDevice(), and IoVerifyVolume().

◆ 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().

◆ IopDeleteDriver()

VOID NTAPI IopDeleteDriver ( IN PVOID  ObjectBody)

Definition at line 77 of file driver.c.

78{
79 PDRIVER_OBJECT DriverObject = ObjectBody;
80 PIO_CLIENT_EXTENSION DriverExtension, NextDriverExtension;
81 PAGED_CODE();
82
83 DPRINT1("Deleting driver object '%wZ'\n", &DriverObject->DriverName);
84
85 /* There must be no device objects remaining at this point */
86 ASSERT(!DriverObject->DeviceObject);
87
88 /* Get the extension and loop them */
89 DriverExtension = IoGetDrvObjExtension(DriverObject)->ClientDriverExtension;
90 while (DriverExtension)
91 {
92 /* Get the next one */
93 NextDriverExtension = DriverExtension->NextExtension;
95
96 /* Move on */
97 DriverExtension = NextDriverExtension;
98 }
99
100 /* Check if the driver image is still loaded */
101 if (DriverObject->DriverSection)
102 {
103 /* Unload it */
104 MmUnloadSystemImage(DriverObject->DriverSection);
105 }
106
107 /* Check if it has a name */
108 if (DriverObject->DriverName.Buffer)
109 {
110 /* Free it */
111 ExFreePool(DriverObject->DriverName.Buffer);
112 }
113
114 /* Check if it has a service key name */
115 if (DriverObject->DriverExtension->ServiceKeyName.Buffer)
116 {
117 /* Free it */
118 ExFreePool(DriverObject->DriverExtension->ServiceKeyName.Buffer);
119 }
120}
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define IoGetDrvObjExtension(DriverObject)
Definition: io.h:136
NTSTATUS NTAPI MmUnloadSystemImage(IN PVOID ImageHandle)
Definition: sysldr.c:945
PPCI_DRIVER_EXTENSION DriverExtension
Definition: pci.c:31
#define TAG_DRIVER_EXTENSION
Definition: tag.h:61

Referenced by IopCreateObjectTypes().

◆ IopDeleteFile()

VOID NTAPI IopDeleteFile ( IN PVOID  ObjectBody)

Definition at line 1355 of file file.c.

1356{
1357 PFILE_OBJECT FileObject = (PFILE_OBJECT)ObjectBody;
1358 PIRP Irp;
1359 PIO_STACK_LOCATION StackPtr;
1361 KEVENT Event;
1363 BOOLEAN DereferenceDone = FALSE;
1364 PVPB Vpb;
1365 KIRQL OldIrql;
1366 IOTRACE(IO_FILE_DEBUG, "ObjectBody: %p\n", ObjectBody);
1367
1368 /* Check if the file has a device object */
1369 if (FileObject->DeviceObject)
1370 {
1371 /* Check if this is a direct open or not */
1372 if (FileObject->Flags & FO_DIRECT_DEVICE_OPEN)
1373 {
1374 /* Get the attached device */
1376 }
1377 else
1378 {
1379 /* Use the file object's device object */
1381 }
1382
1383 /* Sanity check */
1384 ASSERT(!(FileObject->Flags & FO_SYNCHRONOUS_IO) ||
1386
1387 /* Check if the handle wasn't created yet */
1388 if (!(FileObject->Flags & FO_HANDLE_CREATED))
1389 {
1390 /* Send the cleanup IRP */
1391 IopCloseFile(NULL, ObjectBody, 0, 1, 1);
1392 }
1393
1394 /* Clear and set up Events */
1395 KeClearEvent(&FileObject->Event);
1397
1398 /* Allocate an IRP */
1400
1401 /* Set it up */
1402 Irp->UserEvent = &Event;
1403 Irp->UserIosb = &Irp->IoStatus;
1404 Irp->Tail.Overlay.Thread = PsGetCurrentThread();
1405 Irp->Tail.Overlay.OriginalFileObject = FileObject;
1407
1408 /* Set up Stack Pointer Data */
1409 StackPtr = IoGetNextIrpStackLocation(Irp);
1410 StackPtr->MajorFunction = IRP_MJ_CLOSE;
1411 StackPtr->FileObject = FileObject;
1412
1413 /* Queue the IRP */
1415
1416 /* Get the VPB and check if this isn't a direct open */
1417 Vpb = FileObject->Vpb;
1418 if ((Vpb) && !(FileObject->Flags & FO_DIRECT_DEVICE_OPEN))
1419 {
1420 /* Dereference the VPB before the close */
1421 InterlockedDecrement((PLONG)&Vpb->ReferenceCount);
1422 }
1423
1424 /* Check if the FS will never disappear by itself */
1425 if (FileObject->DeviceObject->Flags & DO_NEVER_LAST_DEVICE)
1426 {
1427 /* Dereference it */
1428 InterlockedDecrement(&FileObject->DeviceObject->ReferenceCount);
1429 DereferenceDone = TRUE;
1430 }
1431
1432 /* Call the FS Driver */
1434 if (Status == STATUS_PENDING)
1435 {
1436 /* Wait for completion */
1438 }
1439
1440 /* De-queue the IRP */
1444
1445 /* Free the IRP */
1446 IoFreeIrp(Irp);
1447
1448 /* Clear the file name */
1449 if (FileObject->FileName.Buffer)
1450 {
1451 /*
1452 * Don't use TAG_IO_NAME since the FileObject's FileName
1453 * may have been re-allocated using a different tag
1454 * by a filesystem.
1455 */
1456 ExFreePoolWithTag(FileObject->FileName.Buffer, 0);
1457 FileObject->FileName.Buffer = NULL;
1458 }
1459
1460 /* Check if the FO had a completion port */
1461 if (FileObject->CompletionContext)
1462 {
1463 /* Free it */
1464 ObDereferenceObject(FileObject->CompletionContext->Port);
1465 ExFreePool(FileObject->CompletionContext);
1466 }
1467
1468 /* Check if the FO had extension */
1470 {
1471 /* Release filter context structure if any */
1473 }
1474
1475 /* Check if dereference has been done yet */
1476 if (!DereferenceDone)
1477 {
1478 /* Dereference device object */
1480 }
1481 }
1482}
#define DO_NEVER_LAST_DEVICE
Definition: env_spec_w32.h:402
VOID NTAPI FsRtlPTeardownPerFileObjectContexts(IN PFILE_OBJECT FileObject)
Definition: filtrctx.c:28
VOID NTAPI IopCloseFile(IN PEPROCESS Process OPTIONAL, IN PVOID ObjectBody, IN ACCESS_MASK GrantedAccess, IN ULONG HandleCount, IN ULONG SystemHandleCount)
Definition: file.c:2178
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45

Referenced by IopCreateObjectTypes(), and IopParseDevice().

◆ IopDeleteIoCompletion()

VOID NTAPI IopDeleteIoCompletion ( PVOID  ObjectBody)

Definition at line 100 of file iocomp.c.

101{
102 PKQUEUE Queue = ObjectBody;
103 PLIST_ENTRY FirstEntry;
104 PLIST_ENTRY CurrentEntry;
105 PIRP Irp;
107
108 /* Rundown the Queue */
109 FirstEntry = KeRundownQueue(Queue);
110 if (FirstEntry)
111 {
112 /* Loop the packets */
113 CurrentEntry = FirstEntry;
114 do
115 {
116 /* Get the Packet */
117 Packet = CONTAINING_RECORD(CurrentEntry,
119 ListEntry);
120
121 /* Go to next Entry */
122 CurrentEntry = CurrentEntry->Flink;
123
124 /* Check if it's part of an IRP, or a separate packet */
125 if (Packet->PacketType == IopCompletionPacketIrp)
126 {
127 /* Get the IRP and free it */
128 Irp = CONTAINING_RECORD(Packet, IRP, Tail.Overlay.ListEntry);
129 IoFreeIrp(Irp);
130 }
131 else
132 {
133 /* Use common routine */
135 }
136 } while (FirstEntry != CurrentEntry);
137 }
138}
VOID NTAPI IopFreeMiniPacket(PIOP_MINI_COMPLETION_PACKET Packet)
Definition: iocomp.c:63
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1549
PLIST_ENTRY NTAPI KeRundownQueue(IN PKQUEUE Queue)
Definition: queue.c:438
_Must_inspect_result_ _In_ WDFDEVICE _In_ PIRP _In_ WDFQUEUE Queue
Definition: wdfdevice.h:2225

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 DOE_DELETE_PENDING
Definition: iotypes.h:150
#define IoGetDevObjExtension(DeviceObject)
Definition: io.h:129
VOID NTAPI IopUnloadDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:390

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

◆ IopDereferenceVpbAndFree()

VOID NTAPI IopDereferenceVpbAndFree ( IN PVPB  Vpb)

Definition at line 186 of file volume.c.

187{
189
190 /* Lock the VPBs and decrease references */
192 Vpb->ReferenceCount--;
193
194 /* Check if we're out of references */
195 if (!Vpb->ReferenceCount && Vpb->RealDevice->Vpb == Vpb &&
196 !(Vpb->Flags & VPB_PERSISTENT))
197 {
198 /* Release VPB lock */
200
201 /* And free VPB */
203 }
204 else
205 {
206 /* Release VPB lock */
208 }
209}
#define VPB_PERSISTENT
Definition: iotypes.h:1809

Referenced by IopParseDevice(), and IoVerifyVolume().

◆ IopDetectResourceConflict()

NTSTATUS NTAPI IopDetectResourceConflict ( IN PCM_RESOURCE_LIST  ResourceList,
IN BOOLEAN  Silent,
OUT OPTIONAL PCM_PARTIAL_RESOURCE_DESCRIPTOR  ConflictingDescriptor 
)

Definition at line 1255 of file pnpres.c.

1259{
1262 HANDLE ResourceMapKey = NULL, ChildKey2 = NULL, ChildKey3 = NULL;
1263 ULONG KeyInformationLength, RequiredLength, KeyValueInformationLength, KeyNameInformationLength;
1264 PKEY_BASIC_INFORMATION KeyInformation;
1265 PKEY_VALUE_PARTIAL_INFORMATION KeyValueInformation;
1267 ULONG ChildKeyIndex1 = 0, ChildKeyIndex2, ChildKeyIndex3;
1269
1270 RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\HARDWARE\\RESOURCEMAP");
1272 &KeyName,
1274 NULL,
1275 NULL);
1276 Status = ZwOpenKey(&ResourceMapKey, KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE, &ObjectAttributes);
1277 if (!NT_SUCCESS(Status))
1278 {
1279 /* The key is missing which means we are the first device */
1280 return STATUS_SUCCESS;
1281 }
1282
1283 while (TRUE)
1284 {
1285 Status = ZwEnumerateKey(ResourceMapKey,
1286 ChildKeyIndex1,
1288 NULL,
1289 0,
1292 break;
1294 {
1295 KeyInformationLength = RequiredLength;
1296 KeyInformation = ExAllocatePoolWithTag(PagedPool,
1297 KeyInformationLength,
1298 TAG_IO);
1299 if (!KeyInformation)
1300 {
1302 goto cleanup;
1303 }
1304
1305 Status = ZwEnumerateKey(ResourceMapKey,
1306 ChildKeyIndex1,
1308 KeyInformation,
1309 KeyInformationLength,
1311 }
1312 else
1313 goto cleanup;
1314 ChildKeyIndex1++;
1315 if (!NT_SUCCESS(Status))
1316 {
1317 ExFreePoolWithTag(KeyInformation, TAG_IO);
1318 goto cleanup;
1319 }
1320
1321 KeyName.Buffer = KeyInformation->Name;
1322 KeyName.MaximumLength = KeyName.Length = (USHORT)KeyInformation->NameLength;
1324 &KeyName,
1326 ResourceMapKey,
1327 NULL);
1328 Status = ZwOpenKey(&ChildKey2,
1331 ExFreePoolWithTag(KeyInformation, TAG_IO);
1332 if (!NT_SUCCESS(Status))
1333 goto cleanup;
1334
1335 ChildKeyIndex2 = 0;
1336 while (TRUE)
1337 {
1338 Status = ZwEnumerateKey(ChildKey2,
1339 ChildKeyIndex2,
1341 NULL,
1342 0,
1345 break;
1346 else if (Status == STATUS_BUFFER_TOO_SMALL)
1347 {
1348 KeyInformationLength = RequiredLength;
1349 KeyInformation = ExAllocatePoolWithTag(PagedPool,
1350 KeyInformationLength,
1351 TAG_IO);
1352 if (!KeyInformation)
1353 {
1355 goto cleanup;
1356 }
1357
1358 Status = ZwEnumerateKey(ChildKey2,
1359 ChildKeyIndex2,
1361 KeyInformation,
1362 KeyInformationLength,
1364 }
1365 else
1366 goto cleanup;
1367 ChildKeyIndex2++;
1368 if (!NT_SUCCESS(Status))
1369 {
1370 ExFreePoolWithTag(KeyInformation, TAG_IO);
1371 goto cleanup;
1372 }
1373
1374 KeyName.Buffer = KeyInformation->Name;
1375 KeyName.MaximumLength = KeyName.Length = (USHORT)KeyInformation->NameLength;
1377 &KeyName,
1379 ChildKey2,
1380 NULL);
1381 Status = ZwOpenKey(&ChildKey3, KEY_QUERY_VALUE, &ObjectAttributes);
1382 ExFreePoolWithTag(KeyInformation, TAG_IO);
1383 if (!NT_SUCCESS(Status))
1384 goto cleanup;
1385
1386 ChildKeyIndex3 = 0;
1387 while (TRUE)
1388 {
1389 Status = ZwEnumerateValueKey(ChildKey3,
1390 ChildKeyIndex3,
1392 NULL,
1393 0,
1396 break;
1397 else if (Status == STATUS_BUFFER_TOO_SMALL)
1398 {
1399 KeyValueInformationLength = RequiredLength;
1400 KeyValueInformation = ExAllocatePoolWithTag(PagedPool,
1401 KeyValueInformationLength,
1402 TAG_IO);
1403 if (!KeyValueInformation)
1404 {
1406 goto cleanup;
1407 }
1408
1409 Status = ZwEnumerateValueKey(ChildKey3,
1410 ChildKeyIndex3,
1412 KeyValueInformation,
1413 KeyValueInformationLength,
1415 }
1416 else
1417 goto cleanup;
1418 if (!NT_SUCCESS(Status))
1419 {
1420 ExFreePoolWithTag(KeyValueInformation, TAG_IO);
1421 goto cleanup;
1422 }
1423
1424 Status = ZwEnumerateValueKey(ChildKey3,
1425 ChildKeyIndex3,
1427 NULL,
1428 0,
1431 {
1432 KeyNameInformationLength = RequiredLength;
1434 KeyNameInformationLength + sizeof(WCHAR),
1435 TAG_IO);
1436 if (!KeyNameInformation)
1437 {
1439 goto cleanup;
1440 }
1441
1442 Status = ZwEnumerateValueKey(ChildKey3,
1443 ChildKeyIndex3,
1446 KeyNameInformationLength,
1448 }
1449 else
1450 goto cleanup;
1451 ChildKeyIndex3++;
1452 if (!NT_SUCCESS(Status))
1453 {
1455 goto cleanup;
1456 }
1457
1458 KeyNameInformation->Name[KeyNameInformation->NameLength / sizeof(WCHAR)] = UNICODE_NULL;
1459
1460 /* Skip translated entries */
1461 if (wcsstr(KeyNameInformation->Name, L".Translated"))
1462 {
1464 ExFreePoolWithTag(KeyValueInformation, TAG_IO);
1465 continue;
1466 }
1467
1469
1471 (PCM_RESOURCE_LIST)KeyValueInformation->Data,
1472 Silent,
1473 ConflictingDescriptor))
1474 {
1475 ExFreePoolWithTag(KeyValueInformation, TAG_IO);
1477 goto cleanup;
1478 }
1479
1480 ExFreePoolWithTag(KeyValueInformation, TAG_IO);
1481 }
1482 }
1483 }
1484
1485cleanup:
1486 if (ResourceMapKey != NULL)
1487 ObCloseHandle(ResourceMapKey, KernelMode);
1488 if (ChildKey2 != NULL)
1489 ObCloseHandle(ChildKey2, KernelMode);
1490 if (ChildKey3 != NULL)
1491 ObCloseHandle(ChildKey3, KernelMode);
1492
1495
1496 return Status;
1497}
static void cleanup(void)
Definition: main.c:1335
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
@ KeyNameInformation
Definition: winternl.h:831
@ KeyBasicInformation
Definition: nt_native.h:1131
@ KeyValueBasicInformation
Definition: nt_native.h:1180
@ KeyValuePartialInformation
Definition: nt_native.h:1182
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019
#define UNICODE_NULL
#define STATUS_NO_MORE_ENTRIES
Definition: ntstatus.h:205
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3379
static BOOLEAN IopCheckForResourceConflict(IN PCM_RESOURCE_LIST ResourceList1, IN PCM_RESOURCE_LIST ResourceList2, IN BOOLEAN Silent, OUT OPTIONAL PCM_PARTIAL_RESOURCE_DESCRIPTOR ConflictingDescriptor)
Definition: pnpres.c:1219
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:309
_In_ ULONG _Out_opt_ PULONG RequiredLength
Definition: wmifuncs.h:30

Referenced by IopAssignDeviceResources(), IopCheckDescriptorForConflict(), IoReportResourceForDetection(), and IoReportResourceUsage().

◆ IopDoNameTransmogrify()

VOID NTAPI IopDoNameTransmogrify ( IN PIRP  Irp,
IN PFILE_OBJECT  FileObject,
IN PREPARSE_DATA_BUFFER  DataBuffer 
)

Definition at line 170 of file file.c.

173{
177 PWSTR NewBuffer;
178
179 PAGED_CODE();
180
181 ASSERT(Irp->IoStatus.Status == STATUS_REPARSE);
182 ASSERT(Irp->IoStatus.Information == IO_REPARSE_TAG_MOUNT_POINT);
183 ASSERT(Irp->Tail.Overlay.AuxiliaryBuffer != NULL);
184 ASSERT(DataBuffer != NULL);
185 ASSERT(DataBuffer->ReparseTag == IO_REPARSE_TAG_MOUNT_POINT);
186 ASSERT(DataBuffer->ReparseDataLength < MAXIMUM_REPARSE_DATA_BUFFER_SIZE);
187 ASSERT(DataBuffer->Reserved < MAXIMUM_REPARSE_DATA_BUFFER_SIZE);
188
189 /* First of all, validate data */
190 if (DataBuffer->ReparseDataLength < REPARSE_DATA_BUFFER_HEADER_SIZE ||
191 (DataBuffer->SymbolicLinkReparseBuffer.PrintNameLength +
192 DataBuffer->SymbolicLinkReparseBuffer.SubstituteNameLength +
194 {
195 Irp->IoStatus.Status = STATUS_IO_REPARSE_DATA_INVALID;
196 }
197
198 /* Everything went right */
199 if (NT_SUCCESS(Irp->IoStatus.Status))
200 {
201 /* Compute buffer & length */
202 Buffer = (PWSTR)((ULONG_PTR)DataBuffer->MountPointReparseBuffer.PathBuffer +
203 DataBuffer->MountPointReparseBuffer.SubstituteNameOffset);
204 Length = DataBuffer->MountPointReparseBuffer.SubstituteNameLength;
205
206 /* Check we don't overflow */
207 if (((ULONG)MAXUSHORT - DataBuffer->Reserved) <= (Length + sizeof(UNICODE_NULL)))
208 {
209 Irp->IoStatus.Status = STATUS_IO_REPARSE_DATA_INVALID;
210 }
211 else
212 {
213 /* Compute how much memory we'll need */
214 RequiredLength = DataBuffer->Reserved + Length + sizeof(UNICODE_NULL);
215
216 /* Check if FileObject can already hold what we need */
217 if (FileObject->FileName.MaximumLength >= RequiredLength)
218 {
219 NewBuffer = FileObject->FileName.Buffer;
220 }
221 else
222 {
223 /* Allocate otherwise */
225 if (NewBuffer == NULL)
226 {
227 Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
228 }
229 }
230 }
231 }
232
233 /* Everything went right */
234 if (NT_SUCCESS(Irp->IoStatus.Status))
235 {
236 /* Copy the reserved data */
237 if (DataBuffer->Reserved)
238 {
239 RtlMoveMemory((PWSTR)((ULONG_PTR)NewBuffer + Length),
240 (PWSTR)((ULONG_PTR)FileObject->FileName.Buffer + FileObject->FileName.Length - DataBuffer->Reserved),
241 DataBuffer->Reserved);
242 }
243
244 /* Then the buffer */
245 if (Length)
246 {
247 RtlCopyMemory(NewBuffer, Buffer, Length);
248 }
249
250 /* And finally replace buffer if new one was allocated */
251 FileObject->FileName.Length = RequiredLength - sizeof(UNICODE_NULL);
252 if (NewBuffer != FileObject->FileName.Buffer)
253 {
254 if (FileObject->FileName.Buffer)
255 {
256 /*
257 * Don't use TAG_IO_NAME since the FileObject's FileName
258 * may have been re-allocated using a different tag
259 * by a filesystem.
260 */
261 ExFreePoolWithTag(FileObject->FileName.Buffer, 0);
262 }
263
264 FileObject->FileName.Buffer = NewBuffer;
265 FileObject->FileName.MaximumLength = RequiredLength;
266 FileObject->FileName.Buffer[RequiredLength / sizeof(WCHAR) - 1] = UNICODE_NULL;
267 }
268 }
269
270 /* We don't need them anymore - it was allocated by the driver */
271 ExFreePool(DataBuffer);
272}
#define REPARSE_DATA_BUFFER_HEADER_SIZE
Definition: vista.c:17
#define STATUS_IO_REPARSE_DATA_INVALID
Definition: ntstatus.h:756
WCHAR PathBuffer[1]
Definition: shellext.h:176
#define TAG_IO_NAME
Definition: tag.h:83
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define MAXUSHORT
Definition: typedefs.h:83
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264

Referenced by IopCompleteRequest(), and IopParseDevice().

◆ IopFetchConfigurationInformation()

NTSTATUS IopFetchConfigurationInformation ( _Out_ PWSTR SymbolicLinkList,
_In_ GUID  Guid,
_In_ ULONG  ExpectedInterfaces,
_Out_ PULONG  Interfaces 
)

Definition at line 821 of file iorsrce.c.

826{
828 ULONG interfaces = 0;
829 PWSTR symbolicLinkList;
830
831 /* Get the associated enabled interfaces with the given GUID */
833 if (!NT_SUCCESS(Status))
834 {
835 /* Zero output and leave */
838
839 return STATUS_UNSUCCESSFUL;
840 }
841
842 symbolicLinkList = *SymbolicLinkList;
843
844 /* Count the number of enabled interfaces by counting the number of symbolic links */
845 while (*symbolicLinkList != UNICODE_NULL)
846 {
847 interfaces++;
848 symbolicLinkList += (wcslen(symbolicLinkList) + 1);
849 }
850
851 /* Matching result will define the result */
853 /* Finally, give back to the caller the number of found interfaces */
854 *Interfaces = interfaces;
855
856 return Status;
857}
static const CLASS_AND_INTERFACES ExpectedInterfaces[]
Definition: browseui.c:13
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
NTSTATUS NTAPI IoGetDeviceInterfaces(IN CONST GUID *InterfaceClassGuid, IN PDEVICE_OBJECT PhysicalDeviceObject OPTIONAL, IN ULONG Flags, OUT PWSTR *SymbolicLinkList)
Definition: deviface.c:454
_Must_inspect_result_ _In_ WDFOBJECT _In_ CONST GUID * Guid
Definition: wdfobject.h:762
_In_opt_ PDEVICE_OBJECT _In_ ULONG _Outptr_result_nullonfailure_ _At_ * SymbolicLinkList(return==0, __drv_allocatesMem(Mem))) PZZWSTR *SymbolicLinkList

Referenced by IopCreateArcNamesCd(), and IopCreateArcNamesDisk().

◆ IopFixupResourceListWithRequirements()

NTSTATUS NTAPI IopFixupResourceListWithRequirements ( IN PIO_RESOURCE_REQUIREMENTS_LIST  RequirementsList,
OUT PCM_RESOURCE_LIST ResourceList 
)

Definition at line 219 of file pnpres.c.

222{
223 ULONG i, OldCount;
224 BOOLEAN AlternateRequired = FALSE;
225 PIO_RESOURCE_LIST ResList;
226
227 /* Save the initial resource count when we got here so we can restore if an alternate fails */
228 if (*ResourceList != NULL)
229 OldCount = (*ResourceList)->List[0].PartialResourceList.Count;
230 else
231 OldCount = 0;
232
233 ResList = &RequirementsList->List[0];
234 for (i = 0; i < RequirementsList->AlternativeLists; i++, ResList = IopGetNextResourceList(ResList))
235 {
236 ULONG ii;
237
238 /* We need to get back to where we were before processing the last alternative list */
239 if (OldCount == 0 && *ResourceList != NULL)
240 {
241 /* Just free it and kill the pointer */
244 }
245 else if (OldCount != 0)
246 {
247 PCM_RESOURCE_LIST NewList;
248
249 /* Let's resize it */
250 (*ResourceList)->List[0].PartialResourceList.Count = OldCount;
251
252 /* Allocate the new smaller list */
254 if (!NewList)
255 return STATUS_NO_MEMORY;
256
257 /* Copy the old stuff back */
259
260 /* Free the old one */
262
263 /* Store the pointer to the new one */
264 *ResourceList = NewList;
265 }
266
267 for (ii = 0; ii < ResList->Count; ii++)
268 {
269 ULONG iii;
270 PCM_PARTIAL_RESOURCE_LIST PartialList = (*ResourceList) ? &(*ResourceList)->List[0].PartialResourceList : NULL;
271 PIO_RESOURCE_DESCRIPTOR IoDesc = &ResList->Descriptors[ii];
272 BOOLEAN Matched = FALSE;
273
274 /* Skip alternates if we don't need one */
275 if (!AlternateRequired && (IoDesc->Option & IO_RESOURCE_ALTERNATIVE))
276 {
277 DPRINT("Skipping unneeded alternate\n");
278 continue;
279 }
280
281 /* Check if we couldn't satsify a requirement or its alternates */
282 if (AlternateRequired && !(IoDesc->Option & IO_RESOURCE_ALTERNATIVE))
283 {
284 DPRINT1("Unable to satisfy preferred resource or alternates in list %lu\n", i);
285
286 /* Break out of this loop and try the next list */
287 break;
288 }
289
290 for (iii = 0; PartialList && iii < PartialList->Count && !Matched; iii++)
291 {
292 /* Partial resource descriptors can be of variable size (CmResourceTypeDeviceSpecific),
293 but only one is allowed and it must be the last one in the list! */
294 PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDesc = &PartialList->PartialDescriptors[iii];
295
296 /* First check types */
297 if (IoDesc->Type != CmDesc->Type)
298 continue;
299
300 switch (IoDesc->Type)
301 {
303 /* Make sure it satisfies our vector range */
304 if (CmDesc->u.Interrupt.Vector >= IoDesc->u.Interrupt.MinimumVector &&
305 CmDesc->u.Interrupt.Vector <= IoDesc->u.Interrupt.MaximumVector)
306 {
307 /* Found it */
308 Matched = TRUE;
309 }
310 else
311 {
312 DPRINT("Interrupt - Not a match! 0x%x not inside 0x%x to 0x%x\n",
313 CmDesc->u.Interrupt.Vector,
314 IoDesc->u.Interrupt.MinimumVector,
315 IoDesc->u.Interrupt.MaximumVector);
316 }
317 break;
318
321 /* Make sure the length matches and it satisfies our address range */
322 if (CmDesc->u.Memory.Length == IoDesc->u.Memory.Length &&
323 (ULONGLONG)CmDesc->u.Memory.Start.QuadPart >= (ULONGLONG)IoDesc->u.Memory.MinimumAddress.QuadPart &&
324 (ULONGLONG)CmDesc->u.Memory.Start.QuadPart + CmDesc->u.Memory.Length - 1 <= (ULONGLONG)IoDesc->u.Memory.MaximumAddress.QuadPart)
325 {
326 /* Found it */
327 Matched = TRUE;
328 }
329 else
330 {
331 DPRINT("Memory/Port - Not a match! 0x%I64x with length 0x%x not inside 0x%I64x to 0x%I64x with length 0x%x\n",
332 CmDesc->u.Memory.Start.QuadPart,
333 CmDesc->u.Memory.Length,
334 IoDesc->u.Memory.MinimumAddress.QuadPart,
335 IoDesc->u.Memory.MaximumAddress.QuadPart,
336 IoDesc->u.Memory.Length);
337 }
338 break;
339
341 /* Make sure the length matches and it satisfies our bus number range */
342 if (CmDesc->u.BusNumber.Length == IoDesc->u.BusNumber.Length &&
343 CmDesc->u.BusNumber.Start >= IoDesc->u.BusNumber.MinBusNumber &&
344 CmDesc->u.BusNumber.Start + CmDesc->u.BusNumber.Length - 1 <= IoDesc->u.BusNumber.MaxBusNumber)
345 {
346 /* Found it */
347 Matched = TRUE;
348 }
349 else
350 {
351 DPRINT("Bus Number - Not a match! 0x%x with length 0x%x not inside 0x%x to 0x%x with length 0x%x\n",
352 CmDesc->u.BusNumber.Start,
353 CmDesc->u.BusNumber.Length,
354 IoDesc->u.BusNumber.MinBusNumber,
355 IoDesc->u.BusNumber.MaxBusNumber,
356 IoDesc->u.BusNumber.Length);
357 }
358 break;
359
361 /* Make sure it fits in our channel range */
362 if (CmDesc->u.Dma.Channel >= IoDesc->u.Dma.MinimumChannel &&
363 CmDesc->u.Dma.Channel <= IoDesc->u.Dma.MaximumChannel)
364 {
365 /* Found it */
366 Matched = TRUE;
367 }
368 else
369 {
370 DPRINT("DMA - Not a match! 0x%x not inside 0x%x to 0x%x\n",
371 CmDesc->u.Dma.Channel,
372 IoDesc->u.Dma.MinimumChannel,
373 IoDesc->u.Dma.MaximumChannel);
374 }
375 break;
376
377 default:
378 /* Other stuff is fine */
379 Matched = TRUE;
380 break;
381 }
382 }
383
384 /* Check if we found a matching descriptor */
385 if (!Matched)
386 {
387 PCM_RESOURCE_LIST NewList;
390 BOOLEAN FoundResource = TRUE;
391
392 /* Setup the new CM descriptor */
393 NewDesc.Type = IoDesc->Type;
394 NewDesc.Flags = IoDesc->Flags;
395 NewDesc.ShareDisposition = IoDesc->ShareDisposition;
396
397 /* Let'se see if we can find a resource to satisfy this */
398 switch (IoDesc->Type)
399 {
401 /* Find an available interrupt */
402 if (!IopFindInterruptResource(IoDesc, &NewDesc))
403 {
404 DPRINT1("Failed to find an available interrupt resource (0x%x to 0x%x)\n",
405 IoDesc->u.Interrupt.MinimumVector, IoDesc->u.Interrupt.MaximumVector);
406
407 FoundResource = FALSE;
408 }
409 break;
410
412 /* Find an available port range */
413 if (!IopFindPortResource(IoDesc, &NewDesc))
414 {
415 DPRINT1("Failed to find an available port resource (0x%I64x to 0x%I64x length: 0x%x)\n",
416 IoDesc->u.Port.MinimumAddress.QuadPart, IoDesc->u.Port.MaximumAddress.QuadPart,
417 IoDesc->u.Port.Length);
418
419 FoundResource = FALSE;
420 }
421 break;
422
424 /* Find an available memory range */
425 if (!IopFindMemoryResource(IoDesc, &NewDesc))
426 {
427 DPRINT1("Failed to find an available memory resource (0x%I64x to 0x%I64x length: 0x%x)\n",
428 IoDesc->u.Memory.MinimumAddress.QuadPart, IoDesc->u.Memory.MaximumAddress.QuadPart,
429 IoDesc->u.Memory.Length);
430
431 FoundResource = FALSE;
432 }
433 break;
434
436 /* Find an available bus address range */
437 if (!IopFindBusNumberResource(IoDesc, &NewDesc))
438 {
439 DPRINT1("Failed to find an available bus number resource (0x%x to 0x%x length: 0x%x)\n",
440 IoDesc->u.BusNumber.MinBusNumber, IoDesc->u.BusNumber.MaxBusNumber,
441 IoDesc->u.BusNumber.Length);
442
443 FoundResource = FALSE;
444 }
445 break;
446
448 /* Find an available DMA channel */
449 if (!IopFindDmaResource(IoDesc, &NewDesc))
450 {
451 DPRINT1("Failed to find an available dma resource (0x%x to 0x%x)\n",
452 IoDesc->u.Dma.MinimumChannel, IoDesc->u.Dma.MaximumChannel);
453
454 FoundResource = FALSE;
455 }
456 break;
457
458 default:
459 DPRINT1("Unsupported resource type: %x\n", IoDesc->Type);
460 FoundResource = FALSE;
461 break;
462 }
463
464 /* Check if it's missing and required */
465 if (!FoundResource && IoDesc->Option == 0)
466 {
467 /* Break out of this loop and try the next list */
468 DPRINT1("Unable to satisfy required resource in list %lu\n", i);
469 break;
470 }
471 else if (!FoundResource)
472 {
473 /* Try an alternate for this preferred descriptor */
474 AlternateRequired = TRUE;
475 continue;
476 }
477 else
478 {
479 /* Move on to the next preferred or required descriptor after this one */
480 AlternateRequired = FALSE;
481 }
482
483 /* Figure out what we need */
484 if (PartialList == NULL)
485 {
486 /* We need a new list */
487 NewList = ExAllocatePool(PagedPool, sizeof(CM_RESOURCE_LIST));
488 if (!NewList)
489 return STATUS_NO_MEMORY;
490
491 /* Set it up */
492 NewList->Count = 1;
493 NewList->List[0].InterfaceType = RequirementsList->InterfaceType;
494 NewList->List[0].BusNumber = RequirementsList->BusNumber;
495 NewList->List[0].PartialResourceList.Version = 1;
496 NewList->List[0].PartialResourceList.Revision = 1;
497 NewList->List[0].PartialResourceList.Count = 1;
498
499 /* Set our pointer */
500 DescPtr = &NewList->List[0].PartialResourceList.PartialDescriptors[0];
501 }
502 else
503 {
504 /* Allocate the new larger list */
506 if (!NewList)
507 return STATUS_NO_MEMORY;
508
509 /* Copy the old stuff back */
511
512 /* Set our pointer */
513 DescPtr = &NewList->List[0].PartialResourceList.PartialDescriptors[NewList->List[0].PartialResourceList.Count];
514
515 /* Increment the descriptor count */
516 NewList->List[0].PartialResourceList.Count++;
517
518 /* Free the old list */
520 }
521
522 /* Copy the descriptor in */
523 *DescPtr = NewDesc;
524
525 /* Store the new list */
526 *ResourceList = NewList;
527 }
528 }
529
530 /* Check if we need an alternate with no resources left */
531 if (AlternateRequired)
532 {
533 DPRINT1("Unable to satisfy preferred resource or alternates in list %lu\n", i);
534
535 /* Try the next alternate list */
536 continue;
537 }
538
539 /* We're done because we satisfied one of the alternate lists */
540 return STATUS_SUCCESS;
541 }
542
543 /* We ran out of alternates */
544 DPRINT1("Out of alternate lists!\n");
545
546 /* Free the list */
547 if (*ResourceList)
548 {
551 }
552
553 /* Fail */
555}
#define IO_RESOURCE_ALTERNATIVE
Definition: edit.c:119
#define CmResourceTypeMemory
Definition: hwresource.cpp:125
#define CmResourceTypeDma
Definition: hwresource.cpp:126
#define CmResourceTypePort
Definition: hwresource.cpp:123
#define CmResourceTypeBusNumber
Definition: hwresource.cpp:128
#define CmResourceTypeInterrupt
Definition: hwresource.cpp:124
static BOOLEAN IopFindPortResource(IN PIO_RESOURCE_DESCRIPTOR IoDesc, OUT PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDesc)
Definition: pnpres.c:122
static BOOLEAN IopFindMemoryResource(IN PIO_RESOURCE_DESCRIPTOR IoDesc, OUT PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDesc)
Definition: pnpres.c:84
static BOOLEAN IopFindDmaResource(IN PIO_RESOURCE_DESCRIPTOR IoDesc, OUT PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDesc)
Definition: pnpres.c:160
static BOOLEAN IopFindInterruptResource(IN PIO_RESOURCE_DESCRIPTOR IoDesc, OUT PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDesc)
Definition: pnpres.c:188
FORCEINLINE PIO_RESOURCE_LIST IopGetNextResourceList(_In_ const IO_RESOURCE_LIST *ResourceList)
Definition: pnpres.c:17
static BOOLEAN IopFindBusNumberResource(IN PIO_RESOURCE_DESCRIPTOR IoDesc, OUT PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDesc)
Definition: pnpres.c:51
CM_PARTIAL_RESOURCE_LIST PartialResourceList
Definition: hwresource.cpp:160
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@393 u
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@393::@396 Interrupt
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@393::@398 Memory
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@393::@401 BusNumber
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@393::@399 Dma
CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1]
Definition: hwresource.cpp:119
CM_FULL_RESOURCE_DESCRIPTOR List[1]
Definition: hwresource.cpp:165
struct _IO_RESOURCE_DESCRIPTOR::@21::@28 BusNumber
union _IO_RESOURCE_DESCRIPTOR::@21 u
struct _IO_RESOURCE_DESCRIPTOR::@21::@25 Dma
struct _IO_RESOURCE_DESCRIPTOR::@21::@22 Port
struct _IO_RESOURCE_DESCRIPTOR::@21::@24 Interrupt
UCHAR ShareDisposition
Definition: edit.c:61
struct _IO_RESOURCE_DESCRIPTOR::@21::@23 Memory
ULONG Count
Definition: edit.c:124
uint64_t ULONGLONG
Definition: typedefs.h:67
_In_ WDFIORESREQLIST RequirementsList
Definition: wdfresource.h:65

Referenced by IopAssignDeviceResources(), and IopLegacyResourceAllocation().

◆ IopFreeDeviceNode()

NTSTATUS IopFreeDeviceNode ( IN PDEVICE_NODE  DeviceNode)

◆ IopGetDeviceAttachmentBase()

PDEVICE_OBJECT NTAPI IopGetDeviceAttachmentBase ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 1486 of file file.c.

1487{
1489
1490 /* Go down the stack to attempt to get the PDO */
1491 for (; ((PEXTENDED_DEVOBJ_EXTENSION)PDO->DeviceObjectExtension)->AttachedTo != NULL;
1492 PDO = ((PEXTENDED_DEVOBJ_EXTENSION)PDO->DeviceObjectExtension)->AttachedTo);
1493
1494 return PDO;
1495}

Referenced by IopGetDevicePDO(), and IopVerifyDriverObjectOnStack().

◆ IopGetDeviceNode()

◆ IopGetDriverNames()

NTSTATUS IopGetDriverNames ( _In_ HANDLE  ServiceHandle,
_Out_ PUNICODE_STRING  DriverName,
_Out_opt_ PUNICODE_STRING  ServiceName 
)

Definition at line 123 of file driver.c.

127{
128 UNICODE_STRING driverName = {.Buffer = NULL}, serviceName;
131
132 PAGED_CODE();
133
134 /* 1. Check the "ObjectName" field in the driver's registry key (it has priority) */
135 status = IopGetRegistryValue(ServiceHandle, L"ObjectName", &kvInfo);
136 if (NT_SUCCESS(status))
137 {
138 /* We've got the ObjectName, use it as the driver name */
139 if (kvInfo->Type != REG_SZ || kvInfo->DataLength == 0)
140 {
141 ExFreePool(kvInfo);
143 }
144
145 driverName.Length = kvInfo->DataLength - sizeof(UNICODE_NULL);
146 driverName.MaximumLength = kvInfo->DataLength;
148 if (!driverName.Buffer)
149 {
150 ExFreePool(kvInfo);
152 }
153
154 RtlMoveMemory(driverName.Buffer,
155 (PVOID)((ULONG_PTR)kvInfo + kvInfo->DataOffset),
156 driverName.Length);
157 driverName.Buffer[driverName.Length / sizeof(WCHAR)] = UNICODE_NULL;
158 ExFreePool(kvInfo);
159 }
160
161 /* Check whether we need to get ServiceName as well, either to construct
162 * the driver name (because we could not use "ObjectName"), or because
163 * it is requested by the caller. */
164 PKEY_BASIC_INFORMATION basicInfo = NULL;
165 if (!NT_SUCCESS(status) || ServiceName != NULL)
166 {
167 /* Retrieve the necessary buffer size */
168 ULONG infoLength;
169 status = ZwQueryKey(ServiceHandle, KeyBasicInformation, NULL, 0, &infoLength);
171 {
173 goto Cleanup;
174 }
175
176 /* Allocate the buffer and retrieve the data */
177 basicInfo = ExAllocatePoolWithTag(PagedPool, infoLength, TAG_IO);
178 if (!basicInfo)
179 {
181 goto Cleanup;
182 }
183
184 status = ZwQueryKey(ServiceHandle, KeyBasicInformation, basicInfo, infoLength, &infoLength);
185 if (!NT_SUCCESS(status))
186 {
187 goto Cleanup;
188 }
189
190 serviceName.Length = basicInfo->NameLength;
191 serviceName.MaximumLength = basicInfo->NameLength;
192 serviceName.Buffer = basicInfo->Name;
193 }
194
195 /* 2. There is no "ObjectName" - construct it ourselves. Depending on the driver type,
196 * it will be either "\Driver<ServiceName>" or "\FileSystem<ServiceName>" */
197 if (driverName.Buffer == NULL)
198 {
199 ASSERT(basicInfo); // Container for serviceName
200
201 /* Retrieve the driver type */
202 ULONG driverType;
203 status = IopGetRegistryValue(ServiceHandle, L"Type", &kvInfo);
204 if (!NT_SUCCESS(status))
205 {
206 goto Cleanup;
207 }
208 if (kvInfo->Type != REG_DWORD || kvInfo->DataLength != sizeof(ULONG))
209 {
210 ExFreePool(kvInfo);
212 goto Cleanup;
213 }
214
215 RtlMoveMemory(&driverType,
216 (PVOID)((ULONG_PTR)kvInfo + kvInfo->DataOffset),
217 sizeof(ULONG));
218 ExFreePool(kvInfo);
219
220 /* Compute the necessary driver name string size */
221 if (driverType == SERVICE_RECOGNIZER_DRIVER || driverType == SERVICE_FILE_SYSTEM_DRIVER)
222 driverName.MaximumLength = sizeof(FILESYSTEM_ROOT_NAME);
223 else
224 driverName.MaximumLength = sizeof(DRIVER_ROOT_NAME);
225
226 driverName.MaximumLength += serviceName.Length;
227 driverName.Length = 0;
228
229 /* Allocate and build it */
231 if (!driverName.Buffer)
232 {
234 goto Cleanup;
235 }
236
237 if (driverType == SERVICE_RECOGNIZER_DRIVER || driverType == SERVICE_FILE_SYSTEM_DRIVER)
239 else
241
243 }
244
245 if (ServiceName != NULL)
246 {
247 ASSERT(basicInfo); // Container for serviceName
248
249 /* Allocate a copy for the caller */
251 if (!buf)
252 {
254 goto Cleanup;
255 }
256 RtlMoveMemory(buf, serviceName.Buffer, serviceName.Length);
257 ServiceName->MaximumLength = serviceName.Length;
258 ServiceName->Length = serviceName.Length;
259 ServiceName->Buffer = buf;
260 }
261
262 *DriverName = driverName;
264
265Cleanup:
266 if (basicInfo)
267 ExFreePoolWithTag(basicInfo, TAG_IO);
268
269 if (!NT_SUCCESS(status) && driverName.Buffer)
270 ExFreePoolWithTag(driverName.Buffer, TAG_IO);
271
272 return status;
273}
static WCHAR ServiceName[]
Definition: browser.c:19
static const WCHAR Cleanup[]
Definition: register.c:80
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define REG_SZ
Definition: layer.c:22
#define DRIVER_ROOT_NAME
Definition: ldr.h:5
#define FILESYSTEM_ROOT_NAME
Definition: ldr.h:6
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
NTSTATUS NTAPI IopGetRegistryValue(IN HANDLE Handle, IN PWSTR ValueName, OUT PKEY_VALUE_FULL_INFORMATION *Information)
Definition: pnpmgr.c:1036
#define STATUS_ILL_FORMED_SERVICE_ENTRY
Definition: ntstatus.h:588
#define REG_DWORD
Definition: sdbapi.c:596
Definition: ps.c:97
char serviceName[]
Definition: tftpd.cpp:34
uint16_t * PWCHAR
Definition: typedefs.h:56
#define SERVICE_RECOGNIZER_DRIVER
Definition: cmtypes.h:956
#define SERVICE_FILE_SYSTEM_DRIVER
Definition: cmtypes.h:954

Referenced by IopInitializeDriverModule(), and PiAttachFilterDriversCallback().

◆ IopGetFileInformation()

NTSTATUS NTAPI IopGetFileInformation ( IN PFILE_OBJECT  FileObject,
IN ULONG  Length,
IN FILE_INFORMATION_CLASS  FileInfoClass,
OUT PVOID  Buffer,
OUT PULONG  ReturnedLength 
)

Definition at line 777 of file iofunc.c.

782{
783 PIRP Irp;
789
790 PAGED_CODE();
791
792 /* Allocate an IRP */
795 Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
796 if (Irp == NULL)
797 {
800 }
801
802 /* Init event */
804
805 /* Setup the IRP */
806 Irp->UserIosb = &IoStatusBlock;
807 Irp->UserEvent = &Event;
808 Irp->Overlay.AsynchronousParameters.UserApcRoutine = NULL;
809 Irp->RequestorMode = KernelMode;
810 Irp->AssociatedIrp.SystemBuffer = Buffer;
812 Irp->Tail.Overlay.OriginalFileObject = FileObject;
813 Irp->Tail.Overlay.Thread = PsGetCurrentThread();
814
816 Stack->MajorFunction = IRP_MJ_QUERY_INFORMATION;
817 Stack->FileObject = FileObject;
818 Stack->Parameters.QueryFile.FileInformationClass = FileInfoClass;
819 Stack->Parameters.QueryFile.Length = Length;
820
821
822 /* Queue the IRP */
824
825 /* Call the driver */
827 if (Status == STATUS_PENDING)
828 {
831 }
832
834 return Status;
835}
_In_ ULONG _In_ BATTERY_QUERY_INFORMATION_LEVEL _In_ LONG _In_ ULONG _Out_ PULONG ReturnedLength
Definition: batclass.h:188
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
_In_ WDFREQUEST _In_ PIO_STACK_LOCATION Stack
Definition: wdfrequest.h:639

Referenced by IopGetBasicInformationFile(), and IopQueryNameInternal().

◆ IopGetRegistryValue()

NTSTATUS NTAPI IopGetRegistryValue ( IN HANDLE  Handle,
IN PWSTR  ValueName,
OUT PKEY_VALUE_FULL_INFORMATION Information 
)

Definition at line 1036 of file pnpmgr.c.

1039{
1040 UNICODE_STRING ValueString;
1042 PKEY_VALUE_FULL_INFORMATION FullInformation;
1043 ULONG Size;
1044 PAGED_CODE();
1045
1046 RtlInitUnicodeString(&ValueString, ValueName);
1047
1048 Status = ZwQueryValueKey(Handle,
1049 &ValueString,
1051 NULL,
1052 0,
1053 &Size);
1054 if ((Status != STATUS_BUFFER_OVERFLOW) &&
1056 {
1057 return Status;
1058 }
1059
1060 FullInformation = ExAllocatePool(NonPagedPool, Size);
1061 if (!FullInformation) return STATUS_INSUFFICIENT_RESOURCES;
1062
1063 Status = ZwQueryValueKey(Handle,
1064 &ValueString,
1066 FullInformation,
1067 Size,
1068 &Size);
1069 if (!NT_SUCCESS(Status))
1070 {
1071 ExFreePool(FullInformation);
1072 return Status;
1073 }
1074
1075 *Information = FullInformation;
1076 return STATUS_SUCCESS;
1077}
@ KeyValueFullInformation
Definition: nt_native.h:1181
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
_In_ WDFREQUEST _In_ NTSTATUS _In_ ULONG_PTR Information
Definition: wdfrequest.h:1049

Referenced by IopGetDriverNames(), IopInitializeBuiltinDriver(), IopLoadDriver(), IopSetServiceEnumData(), PiAttachFilterDriversCallback(), PiCallDriverAddDevice(), PiGetDeviceRegistryProperty(), PiInitCacheGroupInformation(), PipGetDriverTagPriority(), and PpInitGetGroupOrderIndex().

◆ 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
NTSTATUS IopSynchronousCall(IN PDEVICE_OBJECT DeviceObject, IN PIO_STACK_LOCATION IoStackLocation, OUT PVOID *Information)
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2163
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136
@ TargetDeviceRelation
Definition: iotypes.h:2156
#define IRP_MN_QUERY_DEVICE_RELATIONS

Referenced by IoGetRelatedTargetDevice(), and IoRegisterPlugPlayNotification().

◆ IopGetSetSecurityObject()

NTSTATUS NTAPI IopGetSetSecurityObject ( IN PVOID  ObjectBody,
IN SECURITY_OPERATION_CODE  OperationCode,
IN PSECURITY_INFORMATION  SecurityInformation,
IN OUT PSECURITY_DESCRIPTOR  SecurityDescriptor,
IN OUT PULONG  BufferLength,
OUT PSECURITY_DESCRIPTOR OldSecurityDescriptor,
IN POOL_TYPE  PoolType,
IN OUT PGENERIC_MAPPING  GenericMapping 
)

Referenced by IopCreateObjectTypes().

◆ IopGetSystemPowerDeviceObject()

NTSTATUS IopGetSystemPowerDeviceObject ( IN PDEVICE_OBJECT DeviceObject)

Referenced by PopSetSystemPowerState().

◆ IopInitBootLog()

VOID IopInitBootLog ( IN BOOLEAN  StartBootLog)

◆ IopInitDriverImplementation()

VOID IopInitDriverImplementation ( VOID  )

◆ IopInitErrorLog()

VOID NTAPI IopInitErrorLog ( VOID  )

◆ IopInitializeBootDrivers()

VOID FASTCALL IopInitializeBootDrivers ( VOID  )

Definition at line 1023 of file driver.c.

1024{
1025 PLIST_ENTRY ListHead, NextEntry, NextEntry2;
1026 PLDR_DATA_TABLE_ENTRY LdrEntry;
1028 UNICODE_STRING DriverName;
1029 ULONG i, Index;
1030 PDRIVER_INFORMATION DriverInfo, DriverInfoTag;
1032 PBOOT_DRIVER_LIST_ENTRY BootEntry;
1033 DPRINT("IopInitializeBootDrivers()\n");
1034
1035 /* Create the RAW FS built-in driver */
1036 RtlInitUnicodeString(&DriverName, L"\\FileSystem\\RAW");
1037
1038 Status = IoCreateDriver(&DriverName, RawFsDriverEntry);
1039 if (!NT_SUCCESS(Status))
1040 {
1041 /* Fail */
1042 return;
1043 }
1044
1045 /* Get highest group order index */
1047 if (IopGroupIndex == 0xFFFF)
1048 {
1050 }
1051
1052 /* Allocate the group table */
1054 IopGroupIndex * sizeof(LIST_ENTRY),
1055 TAG_IO);
1056 if (IopGroupTable == NULL)
1057 {
1059 }
1060
1061 /* Initialize the group table lists */
1062 for (i = 0; i < IopGroupIndex; i++) InitializeListHead(&IopGroupTable[i]);
1063
1064 /* Loop the boot modules */
1065 ListHead = &KeLoaderBlock->LoadOrderListHead;
1066 for (NextEntry = ListHead->Flink;
1067 NextEntry != ListHead;
1068 NextEntry = NextEntry->Flink)
1069 {
1070 /* Get the entry */
1071 LdrEntry = CONTAINING_RECORD(NextEntry,
1073 InLoadOrderLinks);
1074
1075 /* Check if the DLL needs to be initialized */
1076 if (LdrEntry->Flags & LDRP_DRIVER_DEPENDENT_DLL)
1077 {
1078 /* Call its entrypoint */
1079 MmCallDllInitialize(LdrEntry, NULL);
1080 }
1081 }
1082
1083 /* Loop the boot drivers */
1084 ListHead = &KeLoaderBlock->BootDriverListHead;
1085 for (NextEntry = ListHead->Flink;
1086 NextEntry != ListHead;
1087 NextEntry = NextEntry->Flink)
1088 {
1089 /* Get the entry */
1090 BootEntry = CONTAINING_RECORD(NextEntry,
1092 Link);
1093
1094 // FIXME: TODO: This LdrEntry is to be used in a special handling
1095 // for SETUPLDR (a similar procedure is done on Windows), where
1096 // the loader would, under certain conditions, be loaded in the
1097 // SETUPLDR-specific code block below...
1098#if 0
1099 /* Get the driver loader entry */
1100 LdrEntry = BootEntry->LdrEntry;
1101#endif
1102
1103 /* Allocate our internal accounting structure */
1105 sizeof(DRIVER_INFORMATION),
1106 TAG_IO);
1107 if (DriverInfo)
1108 {
1109 /* Zero it and initialize it */
1112 DriverInfo->DataTableEntry = BootEntry;
1113
1114 /* Open the registry key */
1116 NULL,
1117 &BootEntry->RegistryPath,
1118 KEY_READ);
1119 DPRINT("IopOpenRegistryKeyEx(%wZ) returned 0x%08lx\n", &BootEntry->RegistryPath, Status);
1120#if 0
1121 if (NT_SUCCESS(Status))
1122#else // Hack still needed...
1123 if ((NT_SUCCESS(Status)) || /* ReactOS HACK for SETUPLDR */
1124 ((KeLoaderBlock->SetupLdrBlock) && ((KeyHandle = (PVOID)1)))) // yes, it's an assignment!
1125#endif
1126 {
1127 /* Save the handle */
1129
1130 /* Get the group oder index */
1132
1133 /* Get the tag position */
1135
1136 /* Insert it into the list, at the right place */
1138 NextEntry2 = IopGroupTable[Index].Flink;
1139 while (NextEntry2 != &IopGroupTable[Index])
1140 {
1141 /* Get the driver info */
1142 DriverInfoTag = CONTAINING_RECORD(NextEntry2,
1144 Link);
1145
1146 /* Check if we found the right tag position */
1147 if (DriverInfoTag->TagPosition > DriverInfo->TagPosition)
1148 {
1149 /* We're done */
1150 break;
1151 }
1152
1153 /* Next entry */
1154 NextEntry2 = NextEntry2->Flink;
1155 }
1156
1157 /* Insert us right before the next entry */
1158 NextEntry2 = NextEntry2->Blink;
1159 InsertHeadList(NextEntry2, &DriverInfo->Link);
1160 }
1161 }
1162 }
1163
1164 /* Loop each group index */
1165 for (i = 0; i < IopGroupIndex; i++)
1166 {
1167 /* Loop each group table */
1168 for (NextEntry = IopGroupTable[i].Flink;
1169 NextEntry != &IopGroupTable[i];
1170 NextEntry = NextEntry->Flink)
1171 {
1172 /* Get the entry */
1173 DriverInfo = CONTAINING_RECORD(NextEntry,
1175 Link);
1176
1177 /* Get the driver loader entry */
1178 LdrEntry = DriverInfo->DataTableEntry->LdrEntry;
1179
1180 /* Initialize it */
1181 if (IopInitializeBuiltinDriver(LdrEntry))
1182 {
1183 // it does not make sense to enumerate the tree if there are no new devices added
1186 NULL,
1187 NULL);
1188 }
1189 }
1190 }
1191
1192 /* HAL Root Bus is being initialized before loading the boot drivers so this may cause issues
1193 * when some devices are not being initialized with their drivers. This flag is used to delay
1194 * all actions with devices (except PnP root device) until boot drivers are loaded.
1195 * See PiQueueDeviceAction function
1196 */
1198
1199 DbgPrint("BOOT DRIVERS LOADED\n");
1200
1203 NULL,
1204 NULL);
1205}
#define UNIMPLEMENTED_DBGBREAK(...)
Definition: debug.h:57
#define InsertHeadList(ListHead, Entry)
#define DbgPrint
Definition: hal.h:12
PLOADER_PARAMETER_BLOCK KeLoaderBlock
Definition: krnlinit.c:29
#define LDRP_DRIVER_DEPENDENT_DLL
Definition: ldrtypes.h:56
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
DRIVER_INFORMATION DriverInfo
Definition: main.c:59
#define KEY_READ
Definition: nt_native.h:1023
NTSTATUS NTAPI IopOpenRegistryKeyEx(PHANDLE KeyHandle, HANDLE ParentKey, PUNICODE_STRING Name, ACCESS_MASK DesiredAccess)
Definition: pnpmgr.c:885
NTSTATUS NTAPI RawFsDriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
Definition: rawfs.c:1193
USHORT NTAPI PpInitGetGroupOrderIndex(IN HANDLE ServiceHandle)
Definition: pnpinit.c:149
USHORT NTAPI PipGetDriverTagPriority(IN HANDLE ServiceHandle)
Definition: pnpinit.c:192
NTSTATUS NTAPI MmCallDllInitialize(_In_ PLDR_DATA_TABLE_ENTRY LdrEntry, _In_ PLIST_ENTRY ModuleListHead)
Definition: sysldr.c:433
static BOOLEAN IopInitializeBuiltinDriver(IN PLDR_DATA_TABLE_ENTRY BootLdrEntry)
Definition: driver.c:807
NTSTATUS NTAPI IoCreateDriver(_In_opt_ PUNICODE_STRING DriverName, _In_ PDRIVER_INITIALIZE InitializationFunction)
Definition: driver.c:1576
PLIST_ENTRY IopGroupTable
Definition: driver.c:41
USHORT IopGroupIndex
Definition: driver.c:40
BOOLEAN PnPBootDriversLoaded
Definition: pnpinit.c:20
Definition: arc.h:246
UNICODE_STRING RegistryPath
Definition: arc.h:249
struct _LDR_DATA_TABLE_ENTRY * LdrEntry
Definition: arc.h:250
HANDLE ServiceHandle
Definition: io.h:406
PBOOT_DRIVER_LIST_ENTRY DataTableEntry
Definition: io.h:405
LIST_ENTRY Link
Definition: io.h:403
USHORT TagPosition
Definition: io.h:407
Definition: btrfs_drv.h:1876
ULONG Flags
Definition: ntddk_ex.h:207
struct _LIST_ENTRY * Blink
Definition: typedefs.h:122
LIST_ENTRY BootDriverListHead
Definition: arc.h:542
LIST_ENTRY LoadOrderListHead
Definition: arc.h:540
struct _SETUP_LOADER_BLOCK * SetupLdrBlock
Definition: arc.h:558
static int Link(const char **args)
Definition: vfdcmd.c:2414
_In_ WDFCOLLECTION _In_ ULONG Index

Referenced by IoInitSystem().

◆ IopInitializeDriverModule()

NTSTATUS IopInitializeDriverModule ( _In_ PLDR_DATA_TABLE_ENTRY  ModuleObject,
_In_ HANDLE  ServiceHandle,
_Out_ PDRIVER_OBJECT OutDriverObject,
_Out_ NTSTATUS DriverEntryStatus 
)

Initialize a loaded driver.

Parameters
[in]ModuleObjectModule object representing the driver. It can be retrieved by IopLoadServiceModule. Freed on failure, so in a such case this should not be accessed anymore
[in]ServiceHandleHandle to a driver's CCS/Services/<ServiceName> key
[out]DriverObjectThis contains the driver object if it was created (even with unsuccessfull result)
[out]DriverEntryStatusThis contains the status value returned by the driver's DriverEntry routine (will not be valid of the return value is not STATUS_SUCCESS or STATUS_FAILED_DRIVER_ENTRY)
Returns
Status of the operation

Definition at line 443 of file driver.c.

448{
451
452 PAGED_CODE();
453
454 Status = IopGetDriverNames(ServiceHandle, &DriverName, &ServiceName);
455 if (!NT_SUCCESS(Status))
456 {
457 MmUnloadSystemImage(ModuleObject);
458 return Status;
459 }
460
461 DPRINT("Driver name: '%wZ'\n", &DriverName);
462
463 /*
464 * Retrieve the driver's PE image NT header and perform some sanity checks.
465 * NOTE: We suppose that since the driver has been successfully loaded,
466 * its NT and optional headers are all valid and have expected sizes.
467 */
468 PIMAGE_NT_HEADERS NtHeaders = RtlImageNtHeader(ModuleObject->DllBase);
469 ASSERT(NtHeaders);
470 // NOTE: ModuleObject->SizeOfImage is actually (number of PTEs)*PAGE_SIZE.
471 ASSERT(ModuleObject->SizeOfImage == ROUND_TO_PAGES(NtHeaders->OptionalHeader.SizeOfImage));
472 ASSERT(ModuleObject->EntryPoint == RVA(ModuleObject->DllBase, NtHeaders->OptionalHeader.AddressOfEntryPoint));
473
474 /* Obtain the registry path for the DriverInit routine */
475 PKEY_NAME_INFORMATION nameInfo;
476 ULONG infoLength;
477 Status = ZwQueryKey(ServiceHandle, KeyNameInformation, NULL, 0, &infoLength);
479 {
480 nameInfo = ExAllocatePoolWithTag(NonPagedPool, infoLength, TAG_IO);
481 if (nameInfo)
482 {
483 Status = ZwQueryKey(ServiceHandle,
485 nameInfo,
486 infoLength,
487 &infoLength);
488 if (NT_SUCCESS(Status))
489 {
490 RegistryPath.Length = nameInfo->NameLength;
491 RegistryPath.MaximumLength = nameInfo->NameLength;
492 RegistryPath.Buffer = nameInfo->Name;
493 }
494 else
495 {
496 ExFreePoolWithTag(nameInfo, TAG_IO);
497 }
498 }
499 else
500 {
502 }
503 }
504 else
505 {
507 }
508
509 if (!NT_SUCCESS(Status))
510 {
512 RtlFreeUnicodeString(&DriverName);
513 MmUnloadSystemImage(ModuleObject);
514 return Status;
515 }
516
517 /* Create the driver object */
518 ULONG ObjectSize = sizeof(DRIVER_OBJECT) + sizeof(EXTENDED_DRIVER_EXTENSION);
519 OBJECT_ATTRIBUTES objAttrs;
520 PDRIVER_OBJECT driverObject;
522 &DriverName,
524 NULL,
525 NULL);
526
529 &objAttrs,
531 NULL,
532 ObjectSize,
533 0,
534 0,
535 (PVOID*)&driverObject);
536 if (!NT_SUCCESS(Status))
537 {
538 ExFreePoolWithTag(nameInfo, TAG_IO); // container for RegistryPath
540 RtlFreeUnicodeString(&DriverName);
541 MmUnloadSystemImage(ModuleObject);
542 DPRINT1("Error while creating driver object \"%wZ\" status %x\n", &DriverName, Status);
543 return Status;
544 }
545
546 DPRINT("Created driver object 0x%p for \"%wZ\"\n", driverObject, &DriverName);
547
548 RtlZeroMemory(driverObject, ObjectSize);
549 driverObject->Type = IO_TYPE_DRIVER;
550 driverObject->Size = sizeof(DRIVER_OBJECT);
551
552 /* Set the legacy flag if this is not a WDM driver */
554 driverObject->Flags |= DRVO_LEGACY_DRIVER;
555
556 driverObject->DriverSection = ModuleObject;
557 driverObject->DriverStart = ModuleObject->DllBase;
558 driverObject->DriverSize = ModuleObject->SizeOfImage;
559 driverObject->DriverInit = ModuleObject->EntryPoint;
561 driverObject->DriverExtension = (PDRIVER_EXTENSION)(driverObject + 1);
562 driverObject->DriverExtension->DriverObject = driverObject;
563
564 /* Loop all Major Functions */
565 for (INT i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
566 {
567 /* Invalidate each function */
568 driverObject->MajorFunction[i] = IopInvalidDeviceRequest;
569 }
570
571 /* Add the Object and get its handle */
573 Status = ObInsertObject(driverObject, NULL, FILE_READ_DATA, 0, NULL, &hDriver);
574 if (!NT_SUCCESS(Status))
575 {
576 ExFreePoolWithTag(nameInfo, TAG_IO);
578 RtlFreeUnicodeString(&DriverName);
579 return Status;
580 }
581
582 /* Now reference it */
584 0,
587 (PVOID*)&driverObject,
588 NULL);
589
590 /* Close the extra handle */
592
593 if (!NT_SUCCESS(Status))
594 {
595 ExFreePoolWithTag(nameInfo, TAG_IO); // container for RegistryPath
597 RtlFreeUnicodeString(&DriverName);
598 return Status;
599 }
600
601 /* Set up the service key name buffer */
602 UNICODE_STRING serviceKeyName;
603 serviceKeyName.Length = 0;
604 // NULL-terminate for Windows compatibility
605 serviceKeyName.MaximumLength = ServiceName.MaximumLength + sizeof(UNICODE_NULL);
607 serviceKeyName.MaximumLength,
608 TAG_IO);
609 if (!serviceKeyName.Buffer)
610 {
611 ObMakeTemporaryObject(driverObject);
612 ObDereferenceObject(driverObject);
613 ExFreePoolWithTag(nameInfo, TAG_IO); // container for RegistryPath
615 RtlFreeUnicodeString(&DriverName);
617 }
618
619 /* Copy the name and set it in the driver extension */
620 RtlCopyUnicodeString(&serviceKeyName, &ServiceName);
622 driverObject->DriverExtension->ServiceKeyName = serviceKeyName;
623
624 /* Make a copy of the driver name to store in the driver object */
625 UNICODE_STRING driverNamePaged;
626 driverNamePaged.Length = 0;
627 // NULL-terminate for Windows compatibility
628 driverNamePaged.MaximumLength = DriverName.MaximumLength + sizeof(UNICODE_NULL);
629 driverNamePaged.Buffer = ExAllocatePoolWithTag(PagedPool,
630 driverNamePaged.MaximumLength,
631 TAG_IO);
632 if (!driverNamePaged.Buffer)
633 {
634 ObMakeTemporaryObject(driverObject);
635 ObDereferenceObject(driverObject);
636 ExFreePoolWithTag(nameInfo, TAG_IO); // container for RegistryPath
637 RtlFreeUnicodeString(&DriverName);
639 }
640
641 RtlCopyUnicodeString(&driverNamePaged, &DriverName);
642 driverObject->DriverName = driverNamePaged;
643
644 /* Finally, call its init function */
645 Status = driverObject->DriverInit(driverObject, &RegistryPath);
646 *DriverEntryStatus = Status;
647 if (!NT_SUCCESS(Status))
648 {
649 DPRINT1("'%wZ' initialization failed, status (0x%08lx)\n", &DriverName, Status);
650 // return a special status value in case of failure
652 }
653
654 /* HACK: We're going to say if we don't have any DOs from DriverEntry, then we're not legacy.
655 * Other parts of the I/O manager depend on this behavior */
656 if (!driverObject->DeviceObject)
657 {
658 driverObject->Flags &= ~DRVO_LEGACY_DRIVER;
659 }
660
661 /* Windows does this fixup, keep it for compatibility */
662 for (INT i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
663 {
664 /*
665 * Make sure the driver didn't set any dispatch entry point to NULL!
666 * Doing so is illegal; drivers shouldn't touch entry points they
667 * do not implement.
668 */
669
670 /* Check if it did so anyway */
671 if (!driverObject->MajorFunction[i])
672 {
673 /* Print a warning in the debug log */
674 DPRINT1("Driver <%wZ> set DriverObject->MajorFunction[%lu] to NULL!\n",
675 &driverObject->DriverName, i);
676
677 /* Fix it up */
678 driverObject->MajorFunction[i] = IopInvalidDeviceRequest;
679 }
680 }
681
682 // TODO: for legacy drivers, unload the driver if it didn't create any DO
683
684 ExFreePoolWithTag(nameInfo, TAG_IO); // container for RegistryPath
685 RtlFreeUnicodeString(&DriverName);
686
687 if (!NT_SUCCESS(Status))
688 {
689 // if the driver entry has been failed, clear the object
690 ObMakeTemporaryObject(driverObject);
691 ObDereferenceObject(driverObject);
692 return Status;
693 }
694
695 *OutDriverObject = driverObject;
696
698
699 /* Set the driver as initialized */
700 IopReadyDeviceObjects(driverObject);
701
703
704 return STATUS_SUCCESS;
705}
DWORD RVA
Definition: compat.h:1262
#define RtlImageNtHeader
Definition: compat.h:806
#define OBJ_PERMANENT
Definition: winternl.h:226
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
#define FILE_READ_DATA
Definition: nt_native.h:628
#define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER
Definition: ntimage.h:462
VOID NTAPI IopReadyDeviceObjects(IN PDRIVER_OBJECT Driver)
Definition: device.c:34
VOID NTAPI MmFreeDriverInitialization(IN PLDR_DATA_TABLE_ENTRY LdrEntry)
Definition: sysldr.c:1673
POBJECT_TYPE IoDriverObjectType
Definition: driver.c:34
BOOLEAN PnpSystemInit
Definition: iomgr.c:17
NTSTATUS NTAPI IopInvalidDeviceRequest(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: driver.c:65
NTSTATUS IopGetDriverNames(_In_ HANDLE ServiceHandle, _Out_ PUNICODE_STRING DriverName, _Out_opt_ PUNICODE_STRING ServiceName)
Definition: driver.c:123
VOID NTAPI IopReinitializeDrivers(VOID)
Definition: driver.c:1496
UNICODE_STRING IopHardwareDatabaseKey
Definition: driver.c:30
#define STATUS_FAILED_DRIVER_ENTRY
Definition: ntstatus.h:911
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
VOID NTAPI ObMakeTemporaryObject(IN PVOID ObjectBody)
Definition: oblife.c:1449
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
struct _DRIVER_OBJECT * DriverObject
Definition: iotypes.h:2219
UNICODE_STRING ServiceKeyName
Definition: iotypes.h:2222
PUNICODE_STRING HardwareDatabase
Definition: iotypes.h:2284
PVOID DriverStart
Definition: iotypes.h:2279
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2289
PVOID DriverSection
Definition: iotypes.h:2281
CSHORT Size
Definition: iotypes.h:2276
ULONG DriverSize
Definition: iotypes.h:2280
PDRIVER_INITIALIZE DriverInit
Definition: iotypes.h:2286
PDRIVER_EXTENSION DriverExtension
Definition: iotypes.h:2282
CSHORT Type
Definition: iotypes.h:2275
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2277
UNICODE_STRING DriverName
Definition: iotypes.h:2283
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
int32_t INT
Definition: typedefs.h:58
_In_ LPWSTR _In_ ULONG _In_ ULONG _In_ ULONG _Out_ DEVINFO _In_ HDEV _In_ LPWSTR _In_ HANDLE hDriver
Definition: winddi.h:3557
struct _DRIVER_OBJECT DRIVER_OBJECT
#define IO_TYPE_DRIVER
#define DRVO_LEGACY_DRIVER
Definition: iotypes.h:2226
#define IRP_MJ_MAXIMUM_FUNCTION
#define ROUND_TO_PAGES(Size)

Referenced by IopInitializeBuiltinDriver(), and IopLoadDriver().

◆ IopInitializePlugPlayServices()

NTSTATUS NTAPI IopInitializePlugPlayServices ( VOID  )

Definition at line 287 of file pnpinit.c.

288{
291 HANDLE KeyHandle, EnumHandle, ParentHandle, TreeHandle, ControlHandle;
292 UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\REGISTRY\\MACHINE\\SYSTEM\\CURRENTCONTROLSET");
293 UNICODE_STRING PnpManagerDriverName = RTL_CONSTANT_STRING(DRIVER_ROOT_NAME L"PnpManager");
295
296 /* Initialize locks and such */
301
302 /* Get the default interface */
304
305 /* Initialize arbiters */
307 if (!NT_SUCCESS(Status)) return Status;
308
309 /* Setup the group cache */
311 if (!NT_SUCCESS(Status)) return Status;
312
313 /* Open the current control set */
315 NULL,
316 &KeyName,
318 if (!NT_SUCCESS(Status)) return Status;
319
320 /* Create the control key */
321 RtlInitUnicodeString(&KeyName, L"Control");
322 Status = IopCreateRegistryKeyEx(&ControlHandle,
323 KeyHandle,
324 &KeyName,
327 &Disposition);
328 if (!NT_SUCCESS(Status)) return Status;
329
330 /* Check if it's a new key */
332 {
333 HANDLE DeviceClassesHandle;
334
335 /* Create the device classes key */
336 RtlInitUnicodeString(&KeyName, L"DeviceClasses");
337 Status = IopCreateRegistryKeyEx(&DeviceClassesHandle,
338 ControlHandle,
339 &KeyName,
342 &Disposition);
343 if (!NT_SUCCESS(Status)) return Status;
344
345 ZwClose(DeviceClassesHandle);
346 }
347
348 ZwClose(ControlHandle);
349
350 /* Create the enum key */
352 Status = IopCreateRegistryKeyEx(&EnumHandle,
353 KeyHandle,
354 &KeyName,
357 &Disposition);
358 if (!NT_SUCCESS(Status)) return Status;
359
360 /* Check if it's a new key */
362 {
363 /* FIXME: DACLs */
364 }
365
366 /* Create the root key */
367 ParentHandle = EnumHandle;
369 Status = IopCreateRegistryKeyEx(&EnumHandle,
370 ParentHandle,
371 &KeyName,
374 &Disposition);
375 NtClose(ParentHandle);
376 if (!NT_SUCCESS(Status)) return Status;
377 NtClose(EnumHandle);
378
379 /* Open the root key now */
380 RtlInitUnicodeString(&KeyName, L"\\REGISTRY\\MACHINE\\SYSTEM\\CURRENTCONTROLSET\\ENUM");
381 Status = IopOpenRegistryKeyEx(&EnumHandle,
382 NULL,
383 &KeyName,
385 if (NT_SUCCESS(Status))
386 {
387 /* Create the root dev node */
389 Status = IopCreateRegistryKeyEx(&TreeHandle,
390 EnumHandle,
391 &KeyName,
394 NULL);
395 NtClose(EnumHandle);
396 if (NT_SUCCESS(Status)) NtClose(TreeHandle);
397 }
398
399 /* Create the root driver */
400 Status = IoCreateDriver(&PnpManagerDriverName, PnpRootDriverEntry);
401 if (!NT_SUCCESS(Status))
402 {
403 DPRINT1("IoCreateDriverObject() failed\n");
404 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0);
405 }
406
407 /* Create the root PDO */
409 0,
410 NULL,
412 0,
413 FALSE,
414 &Pdo);
415 if (!NT_SUCCESS(Status))
416 {
417 DPRINT1("IoCreateDevice() failed\n");
418 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0);
419 }
420
421 /* This is a bus enumerated device */
423
424 /* Create the root device node */
426
427 /* Set flags */
430
431 /* Create instance path */
433 {
434 DPRINT1("RtlCreateUnicodeString() failed\n");
435 KeBugCheckEx(PHASE1_INITIALIZATION_FAILED, Status, 0, 0, 0);
436 }
437
439
441
442 /* Initialize PnP-Event notification support */
444 if (!NT_SUCCESS(Status)) return Status;
445
446 /* Initialize the Bus Type GUID List */
450
451 /* Initialize PnP root relations (this is a syncronous operation) */
453
454 /* Launch the firmware mapper */
456 if (!NT_SUCCESS(Status)) return Status;
457
458 /* Close the handle to the control set */
460
461 /* Initialize PnP root relations (this is a syncronous operation) */
463
464 /* We made it */
465 return STATUS_SUCCESS;
466}
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:56
@ DeviceNodeStarted
Definition: iotypes.h:429
#define DNF_IDS_QUERIED
Definition: iotypes.h:175
#define DNF_MADEUP
Definition: iotypes.h:170
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define REG_CREATED_NEW_KEY
Definition: nt_native.h:1084
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
@ NotificationEvent
LIST_ENTRY IopDeviceActionRequestList
Definition: devaction.c:46
KSPIN_LOCK IopDeviceActionLock
Definition: devaction.c:49
NTSTATUS IopInitPlugPlayEvents(VOID)
Definition: plugplay.c:40
VOID PnpRootInitializeDevExtension(VOID)
Definition: pnproot.c:1440
PDEVICE_NODE PipAllocateDeviceNode(IN PDEVICE_OBJECT PhysicalDeviceObject)
KSPIN_LOCK IopDeviceTreeLock
Definition: devnode.c:19
NTSTATUS NTAPI PnpRootDriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
Definition: pnproot.c:1488
NTSTATUS NTAPI IopUpdateRootKey(VOID)
Definition: pnpmap.c:670
NTSTATUS NTAPI IopCreateRegistryKeyEx(OUT PHANDLE Handle, IN HANDLE BaseHandle OPTIONAL, IN PUNICODE_STRING KeyName, IN ACCESS_MASK DesiredAccess, IN ULONG CreateOptions, OUT PULONG Disposition OPTIONAL)
PIO_BUS_TYPE_GUID_LIST PnpBusTypeGuidList
Definition: pnpmgr.c:27
PDRIVER_OBJECT IopRootDriverObject
Definition: pnpmgr.c:26
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: device.c:1031
NTSTATUS NTAPI IopInitializeArbiters(VOID)
Definition: pnpinit.c:49
KEVENT PiEnumerationFinished
Definition: devaction.c:50
INTERFACE_TYPE NTAPI IopDetermineDefaultInterfaceType(VOID)
Definition: pnpinit.c:41
NTSTATUS NTAPI PiInitCacheGroupInformation(VOID)
Definition: pnpinit.c:94
INTERFACE_TYPE PnpDefaultInterfaceType
Definition: pnpinit.c:19
#define FILE_DEVICE_CONTROLLER
Definition: winioctl.h:110
#define REGSTR_VAL_ROOT_DEVNODE
Definition: regstr.h:405
#define REGSTR_KEY_ROOTENUM
Definition: regstr.h:10
#define REGSTR_KEY_ENUM
Definition: regstr.h:9
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
Definition: rtlcompat.c:108
ULONG Flags
Definition: iotypes.h:889
UNICODE_STRING InstancePath
Definition: iotypes.h:895
FAST_MUTEX Lock
Definition: io.h:419
WDF_EXTERN_C_START typedef _Must_inspect_result_ _In_ WDFDRIVER _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ PDEVICE_OBJECT _In_opt_ PDEVICE_OBJECT _In_opt_ PDEVICE_OBJECT Pdo
Definition: wdfminiport.h:72
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
#define DO_BUS_ENUMERATED_DEVICE

Referenced by IoInitSystem().

◆ IopInitializeReserveIrp()

BOOLEAN NTAPI IopInitializeReserveIrp ( IN PRESERVE_IRP_ALLOCATOR  ReserveIrpAllocator)

Definition at line 549 of file irp.c.

550{
551 /* Our allocated stack size */
552 ReserveIrpAllocator->StackSize = 20;
553
554 /* Allocate the IRP now */
555 ReserveIrpAllocator->ReserveIrp = IoAllocateIrp(ReserveIrpAllocator->StackSize, FALSE);
556 /* If we cannot, abort system boot */
557 if (ReserveIrpAllocator->ReserveIrp == NULL)
558 {
559 return FALSE;
560 }
561
562 /* It's not in use */
563 ReserveIrpAllocator->ReserveIrpInUse = 0;
564 /* And init the event */
565 KeInitializeEvent(&ReserveIrpAllocator->WaitEvent, SynchronizationEvent, FALSE);
566
567 /* All good, keep booting */
568 return TRUE;
569}

Referenced by IoInitSystem().

◆ IopInitializeSystemDrivers()

VOID FASTCALL IopInitializeSystemDrivers ( VOID  )

Definition at line 1210 of file driver.c.

1211{
1212 PUNICODE_STRING *DriverList, *SavedList;
1213
1215
1216 /* HACK: No system drivers on the BootCD */
1217 if (KeLoaderBlock->SetupLdrBlock) return;
1218
1219 /* Get the driver list */
1220 SavedList = DriverList = CmGetSystemDriverList();
1221 ASSERT(DriverList);
1222
1223 /* Loop it */
1224 while (*DriverList)
1225 {
1226 /* Load the driver */
1227 ZwLoadDriver(*DriverList);
1228
1229 /* Free the entry */
1230 RtlFreeUnicodeString(*DriverList);
1231 ExFreePool(*DriverList);
1232
1233 /* Next entry */
1235 DriverList++;
1236 }
1237
1238 /* Free the list */
1239 ExFreePool(SavedList);
1240
1243 NULL,
1244 NULL);
1245}
PUNICODE_STRING *NTAPI CmGetSystemDriverList(VOID)
Definition: cmsysini.c:1839
VOID NTAPI InbvIndicateProgress(VOID)
Gives some progress feedback, without specifying any explicit number of progress steps or percentage....
Definition: inbv.c:626
NTSTATUS PiPerformSyncDeviceAction(_In_ PDEVICE_OBJECT DeviceObject, _In_ DEVICE_ACTION Action)
Perfom a device operation synchronously via PiQueueDeviceAction.
Definition: devaction.c:2718

Referenced by IoInitSystem().

◆ IopInitiatePnpIrp()

◆ IopInitPlugPlayEvents()

NTSTATUS IopInitPlugPlayEvents ( VOID  )

Definition at line 40 of file plugplay.c.

41{
43
46 FALSE);
47
48 return STATUS_SUCCESS;
49}
static LIST_ENTRY IopPnpEventQueueHead
Definition: plugplay.c:30
static KEVENT IopPnpNotifyEvent
Definition: plugplay.c:31

Referenced by IopInitializePlugPlayServices().

◆ IopInitTimerImplementation()

VOID FASTCALL IopInitTimerImplementation ( VOID  )

◆ IopLoadDriver()

NTSTATUS IopLoadDriver ( _In_ HANDLE  ServiceHandle,
_Out_ PDRIVER_OBJECT DriverObject 
)

Definition at line 1938 of file driver.c.

1941{
1942 UNICODE_STRING ImagePath;
1944 PLDR_DATA_TABLE_ENTRY ModuleObject;
1946
1948 Status = IopGetRegistryValue(ServiceHandle, L"ImagePath", &kvInfo);
1949 if (NT_SUCCESS(Status))
1950 {
1951 if ((kvInfo->Type != REG_EXPAND_SZ && kvInfo->Type != REG_SZ) || kvInfo->DataLength == 0)
1952 {
1953 ExFreePool(kvInfo);
1955 }
1956
1957 ImagePath.Length = kvInfo->DataLength - sizeof(UNICODE_NULL);
1958 ImagePath.MaximumLength = kvInfo->DataLength;
1960 if (!ImagePath.Buffer)
1961 {
1962 ExFreePool(kvInfo);
1964 }
1965
1966 RtlMoveMemory(ImagePath.Buffer,
1967 (PVOID)((ULONG_PTR)kvInfo + kvInfo->DataOffset),
1968 ImagePath.Length);
1969 ImagePath.Buffer[ImagePath.Length / sizeof(WCHAR)] = UNICODE_NULL;
1970 ExFreePool(kvInfo);
1971 }
1972 else
1973 {
1974 return Status;
1975 }
1976
1977 /*
1978 * Normalize the image path for all later processing.
1979 */
1980 Status = IopNormalizeImagePath(&ImagePath, NULL);
1981 if (!NT_SUCCESS(Status))
1982 {
1983 DPRINT("IopNormalizeImagePath() failed (Status %x)\n", Status);
1984 return Status;
1985 }
1986
1987 DPRINT("FullImagePath: '%wZ'\n", &ImagePath);
1988
1991
1992 /*
1993 * Load the driver module
1994 */
1995 DPRINT("Loading module from %wZ\n", &ImagePath);
1996 Status = MmLoadSystemImage(&ImagePath, NULL, NULL, 0, (PVOID)&ModuleObject, &BaseAddress);
1997 RtlFreeUnicodeString(&ImagePath);
1998
1999 if (!NT_SUCCESS(Status))
2000 {
2001 DPRINT("MmLoadSystemImage() failed (Status %lx)\n", Status);
2004 return Status;
2005 }
2006
2007 // Display the loading message
2008 ULONG infoLength;
2009 Status = ZwQueryKey(ServiceHandle, KeyBasicInformation, NULL, 0, &infoLength);
2011 {
2013 if (servName)
2014 {
2015 Status = ZwQueryKey(ServiceHandle,
2017 servName,
2018 infoLength,
2019 &infoLength);
2020 if (NT_SUCCESS(Status))
2021 {
2023 .Length = servName->NameLength,
2024 .MaximumLength = servName->NameLength,
2025 .Buffer = servName->Name
2026 };
2027
2029 }
2030 ExFreePoolWithTag(servName, TAG_IO);
2031 }
2032 }
2033
2034 NTSTATUS driverEntryStatus;
2035 Status = IopInitializeDriverModule(ModuleObject,
2036 ServiceHandle,
2038 &driverEntryStatus);
2039 if (!NT_SUCCESS(Status))
2040 {
2041 DPRINT1("IopInitializeDriverModule() failed (Status %lx)\n", Status);
2042 }
2043
2046
2047 return Status;
2048}
#define ExAcquireResourceExclusiveLite(res, wait)
Definition: env_spec_w32.h:615
#define KeLeaveCriticalRegion()
Definition: ke_x.h:119
#define KeEnterCriticalRegion()
Definition: ke_x.h:88
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1822
NTSTATUS NTAPI MmLoadSystemImage(IN PUNICODE_STRING FileName, IN PUNICODE_STRING NamePrefix OPTIONAL, IN PUNICODE_STRING LoadedName OPTIONAL, IN ULONG Flags, OUT PVOID *ModuleObject, OUT PVOID *ImageBaseAddress)
Definition: sysldr.c:2938
static VOID FASTCALL IopDisplayLoadingMessage(_In_ PCUNICODE_STRING ServiceName)
Displays a driver-loading message in SOS mode.
Definition: driver.c:328
ERESOURCE IopDriverLoadResource
Definition: driver.c:20
NTSTATUS IopInitializeDriverModule(_In_ PLDR_DATA_TABLE_ENTRY ModuleObject, _In_ HANDLE ServiceHandle, _Out_ PDRIVER_OBJECT *OutDriverObject, _Out_ NTSTATUS *DriverEntryStatus)
Initialize a loaded driver.
Definition: driver.c:443
NTSTATUS FASTCALL IopNormalizeImagePath(_Inout_ _When_(return >=0, _At_(ImagePath->Buffer, _Post_notnull_ __drv_allocatesMem(Mem))) PUNICODE_STRING ImagePath, _In_ PUNICODE_STRING ServiceName)
Definition: driver.c:369
#define TAG_RTLREGISTRY
Definition: tag.h:97

Referenced by IopLoadUnloadDriverWorker(), and PiAttachFilterDriversCallback().

◆ IopLogWorker()

VOID NTAPI IopLogWorker ( IN PVOID  Parameter)

Definition at line 148 of file error.c.

149{
150#define IO_ERROR_OBJECT_NAMES_LENGTH 100
151
155 PLIST_ENTRY ListEntry;
156 PERROR_LOG_ENTRY LogEntry;
159 ULONG RemainingLength;
161 PWCHAR NameString;
162 ULONG DriverNameLength, DeviceNameLength;
165 POBJECT_NAME_INFORMATION PoolObjectNameInfo;
166 ULONG ReturnedLength, MessageLength;
167 ULONG ExtraStringLength;
168 PWCHAR p;
169
170 PAGED_CODE();
171
173
174 /* Connect to the port */
175 if (!IopConnectLogPort()) return;
176
177 /* Allocate the message */
179 if (!Message)
180 {
181 /* Couldn't allocate, try again */
183 return;
184 }
185
186 /* Zero out the message and get the actual I/O structure */
187 RtlZeroMemory(Message, sizeof(*Message));
188 ErrorMessage = &Message->IoErrorMessage;
189
190 /* Start loop */
191 while (TRUE)
192 {
193 /* Get an entry */
194 ListEntry = IopGetErrorLogEntry();
195 if (!ListEntry) break;
196 LogEntry = CONTAINING_RECORD(ListEntry, ERROR_LOG_ENTRY, ListEntry);
197
198 /* Get pointer to the log packet */
200 sizeof(ERROR_LOG_ENTRY));
201
202 /* Calculate the total length of the message only */
203 MessageLength = sizeof(IO_ERROR_LOG_MESSAGE) -
204 sizeof(ERROR_LOG_ENTRY) -
205 sizeof(IO_ERROR_LOG_PACKET) +
206 LogEntry->Size;
207
208 /* Copy the packet */
209 RtlCopyMemory(&ErrorMessage->EntryData,
210 Packet,
211 LogEntry->Size - sizeof(ERROR_LOG_ENTRY));
212
213 /* Set the timestamp and time */
214 ErrorMessage->TimeStamp = LogEntry->TimeStamp;
216
217 /* Check if this message has any strings */
218 if (Packet->NumberOfStrings)
219 {
220 /* String buffer is after the current strings */
221 StringBuffer = (PCHAR)&ErrorMessage->EntryData +
222 Packet->StringOffset;
223 }
224 else
225 {
226 /* Otherwise, string buffer is at the end */
227 StringBuffer = (PCHAR)ErrorMessage + MessageLength;
228 }
229
230 /* Align the buffer */
232
233 /* Set the offset for the driver's name to the current buffer */
234 ErrorMessage->DriverNameOffset = (ULONG)(StringBuffer -
236
237 /* Check how much space we have left for the device string */
238 RemainingLength = (ULONG)((ULONG_PTR)Message +
241
242 NameString = NULL;
243 DriverNameLength = 0; DeviceNameLength = 0;
244 PoolObjectNameInfo = NULL;
245 ObjectNameInfo = (POBJECT_NAME_INFORMATION)&Buffer;
246
247 /* Now check if there is a driver object */
248 DriverObject = LogEntry->DriverObject;
249 if (DriverObject)
250 {
251 /* Check if the driver has a name, and use it if so */
252 if (DriverObject->DriverName.Buffer)
253 {
254 NameString = DriverObject->DriverName.Buffer;
255 DriverNameLength = DriverObject->DriverName.Length;
256 }
257 else
258 {
259 NameString = NULL;
260 DriverNameLength = 0;
261 }
262
263 /* Check if there isn't a valid name */
264 if (!DriverNameLength)
265 {
266 /* Query the name directly */
268 ObjectNameInfo,
269 sizeof(Buffer),
271 if (!NT_SUCCESS(Status) || (ObjectNameInfo->Name.Length == 0))
272 {
273 /* We don't have a name */
274 DriverNameLength = 0;
275 }
276 else
277 {
278 NameString = ObjectNameInfo->Name.Buffer;
279 DriverNameLength = ObjectNameInfo->Name.Length;
280 }
281 }
282 }
283 else
284 {
285 /* Use default name */
286 NameString = L"Application Popup";
287 DriverNameLength = (ULONG)wcslen(NameString) * sizeof(WCHAR);
288 }
289
290 /* Check if we have a driver name */
291 if (DriverNameLength)
292 {
293 /* Skip to the end of the driver's name */
294 p = &NameString[DriverNameLength / sizeof(WCHAR)];
295
296 /* Now we'll walk backwards and assume the minimum size */
297 DriverNameLength = sizeof(WCHAR);
298 p--;
299 while ((*p != L'\\') && (p != NameString))
300 {
301 /* No backslash found, keep going */
302 p--;
303 DriverNameLength += sizeof(WCHAR);
304 }
305
306 /* Now we probably hit the backslash itself, skip past it */
307 if (*p == L'\\')
308 {
309 p++;
310 DriverNameLength -= sizeof(WCHAR);
311 }
312
313 /*
314 * Now make sure that the driver name fits in the buffer, minus
315 * 3 NULL chars (driver name, device name, and remaining strings),
316 * and copy the driver name in the string buffer.
317 */
318 DriverNameLength = min(DriverNameLength,
319 RemainingLength - 3 * sizeof(UNICODE_NULL));
320 RtlCopyMemory(StringBuffer, p, DriverNameLength);
321 }
322
323 /* Null-terminate the driver name */
324 *((PWSTR)(StringBuffer + DriverNameLength)) = UNICODE_NULL;
325 DriverNameLength += sizeof(WCHAR);
326
327 /* Go to the next string buffer position */
328 StringBuffer += DriverNameLength;
329 RemainingLength -= DriverNameLength;
330
331 /* Update the string offset */
332 ErrorMessage->EntryData.StringOffset =
334
335 /* Check if we have a device object */
336 if (LogEntry->DeviceObject)
337 {
338 /* We do, query its name */
340 ObjectNameInfo,
341 sizeof(Buffer) - DriverNameLength,
343 if (!NT_SUCCESS(Status) || (ObjectNameInfo->Name.Length == 0))
344 {
345 /* Setup an empty name */
346 RtlInitEmptyUnicodeString(&ObjectNameInfo->Name, L"", 0);
347
348 /* Check if we failed because our buffer wasn't large enough */
350 {
351 /* Then we'll allocate one... we really want this name! */
352 PoolObjectNameInfo = ExAllocatePoolWithTag(PagedPool,
354 TAG_IO);
355 if (PoolObjectNameInfo)
356 {
357 /* Query it again */
358 ObjectNameInfo = PoolObjectNameInfo;
360 ObjectNameInfo,
363 if (NT_SUCCESS(Status))
364 {
365 /* Success, update the information */
366 ObjectNameInfo->Name.Length =
367 IO_ERROR_OBJECT_NAMES_LENGTH - (USHORT)DriverNameLength;
368 }
369 }
370 }
371 }
372
373 NameString = ObjectNameInfo->Name.Buffer;
374 DeviceNameLength = ObjectNameInfo->Name.Length;
375 }
376 else
377 {
378 /* No device object, setup an empty name */
379 NameString = L"";
380 DeviceNameLength = 0;
381 }
382
383 /*
384 * Now make sure that the device name fits in the buffer, minus
385 * 2 NULL chars (device name, and remaining strings), and copy
386 * the device name in the string buffer.
387 */
388 DeviceNameLength = min(DeviceNameLength,
389 RemainingLength - 2 * sizeof(UNICODE_NULL));
390 RtlCopyMemory(StringBuffer, NameString, DeviceNameLength);
391
392 /* Null-terminate the device name */
393 *((PWSTR)(StringBuffer + DeviceNameLength)) = UNICODE_NULL;
394 DeviceNameLength += sizeof(WCHAR);
395
396 /* Free the buffer if we had one */
397 if (PoolObjectNameInfo)
398 {
399 ExFreePoolWithTag(PoolObjectNameInfo, TAG_IO);
400 PoolObjectNameInfo = NULL;
401 }
402
403 /* Go to the next string buffer position */
404 ErrorMessage->EntryData.NumberOfStrings++;
405 StringBuffer += DeviceNameLength;
406 RemainingLength -= DeviceNameLength;
407
408 /* Check if we have any extra strings */
409 if (Packet->NumberOfStrings)
410 {
411 /* Find out the size of the extra strings */
412 ExtraStringLength = LogEntry->Size -
413 sizeof(ERROR_LOG_ENTRY) -
414 Packet->StringOffset;
415
416 /* Round up the length */
417 ExtraStringLength = ROUND_UP(ExtraStringLength, sizeof(WCHAR));
418
419 /* Make sure that the extra strings fit in our buffer */
420 if (ExtraStringLength > (RemainingLength - sizeof(UNICODE_NULL)))
421 {
422 /* They wouldn't, so set normalize the length */
423 MessageLength -= ExtraStringLength - RemainingLength;
424 ExtraStringLength = RemainingLength - sizeof(UNICODE_NULL);
425 }
426
427 /* Now copy the extra strings */
429 (PCHAR)Packet + Packet->StringOffset,
430 ExtraStringLength);
431
432 /* Null-terminate them */
433 *((PWSTR)(StringBuffer + ExtraStringLength)) = UNICODE_NULL;
434 }
435
436 /* Set the driver name length */
437 ErrorMessage->DriverNameLength = (USHORT)DriverNameLength;
438
439 /* Update the message length to include the driver and device names */
440 MessageLength += DriverNameLength + DeviceNameLength;
441 ErrorMessage->Size = (USHORT)MessageLength;
442
443 /* Now update it again for the size of the actual LPC */
444 MessageLength += (FIELD_OFFSET(ELF_API_MSG, IoErrorMessage) -
446
447 /* Set the total and data lengths */
448 Message->Header.u1.s1.TotalLength =
449 (USHORT)(sizeof(PORT_MESSAGE) + MessageLength);
450 Message->Header.u1.s1.DataLength = (USHORT)MessageLength;
451
452 /* Send the message */
454 if (!NT_SUCCESS(Status))
455 {
456 /*
457 * An error happened while sending the message on the port.
458 * Close the port, requeue the log message on top of the list
459 * and restart the worker.
460 */
463
465 &LogEntry->ListEntry,
467
469 break;
470 }
471
472 /* NOTE: The following is basically 'IoFreeErrorLogEntry(Packet)' */
473
474 /* Dereference both objects */
475 if (LogEntry->DeviceObject) ObDereferenceObject(LogEntry->DeviceObject);
476 if (LogEntry->DriverObject) ObDereferenceObject(LogEntry->DriverObject);
477
478 /* Decrease the total allocation size and free the entry */
481 }
482
483 /* Free the LPC Message */
485}
static VOID ErrorMessage(_In_ DWORD dwErrorCode, _In_opt_ PCWSTR pszMsg,...)
Definition: attrib.c:33
static const WCHAR Message[]
Definition: register.c:74
#define ROUND_UP(n, align)
Definition: eventvwr.h:34
GLfloat GLfloat p
Definition: glext.h:8902
@ Unknown
Definition: i8042prt.h:114
PLIST_ENTRY NTAPI ExInterlockedInsertHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PLIST_ENTRY ListEntry, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:114
#define InterlockedExchangeAdd
Definition: interlocked.h:181
WCHAR StringBuffer[156]
Definition: ldrinit.c:41
NTSYSAPI NTSTATUS NTAPI ZwRequestPort(_In_ HANDLE PortHandle, _In_ PPORT_MESSAGE LpcMessage)
#define PCHAR
Definition: match.c:90
#define min(a, b)
Definition: monoChain.cc:55
struct _OBJECT_NAME_INFORMATION OBJECT_NAME_INFORMATION
struct _OBJECT_NAME_INFORMATION * POBJECT_NAME_INFORMATION
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
struct _ERROR_LOG_ENTRY ERROR_LOG_ENTRY
LIST_ENTRY IopErrorLogListHead
Definition: error.c:30
VOID NTAPI IopRestartLogWorker(VOID)
Definition: error.c:85
BOOLEAN IopLogPortConnected
Definition: error.c:34
KSPIN_LOCK IopLogListLock
Definition: error.c:31
HANDLE IopLogPort
Definition: error.c:35
BOOLEAN NTAPI IopConnectLogPort(VOID)
Definition: error.c:110
PLIST_ENTRY NTAPI IopGetErrorLogEntry(VOID)
Definition: error.c:59
#define IO_ERROR_OBJECT_NAMES_LENGTH
LONG IopTotalLogSize
Definition: error.c:29
NTSTATUS NTAPI ObQueryNameString(IN PVOID Object, OUT POBJECT_NAME_INFORMATION ObjectNameInfo, IN ULONG Length, OUT PULONG ReturnLength)
Definition: obname.c:1207
Definition: io.h:332
LARGE_INTEGER TimeStamp
Definition: io.h:338
CSHORT Size
Definition: io.h:334
LIST_ENTRY ListEntry
Definition: io.h:335
PDEVICE_OBJECT DeviceObject
Definition: io.h:336
PDRIVER_OBJECT DriverObject
Definition: io.h:337
#define TAG_ERROR_LOG
Definition: tag.h:81
char * PCHAR
Definition: typedefs.h:51
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
#define ALIGN_UP_POINTER(ptr, type)
Definition: umtypes.h:97
#define IO_TYPE_ERROR_MESSAGE
#define IO_ERROR_LOG_MESSAGE_LENGTH
Definition: iotypes.h:2038
struct _IO_ERROR_LOG_MESSAGE IO_ERROR_LOG_MESSAGE
struct _IO_ERROR_LOG_PACKET * PIO_ERROR_LOG_PACKET
struct _IO_ERROR_LOG_PACKET IO_ERROR_LOG_PACKET
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:323
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by IopLogDpcRoutine(), and IoWriteErrorLogEntry().

◆ IopMountVolume()

NTSTATUS NTAPI IopMountVolume ( IN PDEVICE_OBJECT  DeviceObject,
IN BOOLEAN  AllowRawMount,
IN BOOLEAN  DeviceIsLocked,
IN BOOLEAN  Alertable,
OUT PVPB Vpb 
)

Definition at line 462 of file volume.c.

467{
471 PIRP Irp;
472 PIO_STACK_LOCATION StackPtr;
473 PLIST_ENTRY FsList, ListEntry;
474 LIST_ENTRY LocalList;
476 PDEVICE_OBJECT FileSystemDeviceObject, ParentFsDeviceObject;
477 ULONG FsStackOverhead, RegistrationOps;
478 PAGED_CODE();
479
480 /* Check if the device isn't already locked */
481 if (!DeviceIsLocked)
482 {
483 /* Lock it ourselves */
485 Executive,
487 Alertable,
488 NULL);
490 {
491 /* Don't mount if we were interrupted */
492 return Status;
493 }
494 }
495
496 /* Acquire the FS Lock*/
499
500 /* Make sure we weren't already mounted */
501 if (!(DeviceObject->Vpb->Flags & (VPB_MOUNTED | VPB_REMOVE_PENDING)))
502 {
503 /* Initialize the event to wait on */
505
506 /* Remove the verify flag and get the actual device to mount */
507 DeviceObject->Flags &= ~DO_VERIFY_VOLUME;
508 while (AttachedDeviceObject->AttachedDevice)
509 {
510 /* Get the next one */
512 }
513
514 /* Reference it */
516
517 /* For a mount operation, this can only be a Disk, CD-ROM or tape */
518 if ((DeviceObject->DeviceType == FILE_DEVICE_DISK) ||
519 (DeviceObject->DeviceType == FILE_DEVICE_VIRTUAL_DISK))
520 {
521 /* Use the disk list */
523 }
524 else if (DeviceObject->DeviceType == FILE_DEVICE_CD_ROM)
525 {
526 /* Use the CD-ROM list */
528 }
529 else
530 {
531 /* It's gotta be a tape... */
533 }
534
535 /* Now loop the fs list until one of the file systems accepts us */
537 ListEntry = FsList->Flink;
538 while ((ListEntry != FsList) && !(NT_SUCCESS(Status)))
539 {
540 /*
541 * If we're not allowed to mount this volume and this is our last
542 * (but not only) chance to mount it...
543 */
544 if (!(AllowRawMount) &&
545 (ListEntry->Flink == FsList) &&
546 (ListEntry != FsList->Flink))
547 {
548 /* Then fail this mount request */
549 break;
550 }
551
552 /*
553 * Also check if this is a raw mount and there are other file
554 * systems on the list.
555 */
556 if ((DeviceObject->Vpb->Flags & VPB_RAW_MOUNT) &&
557 (ListEntry->Flink != FsList))
558 {
559 /* Then skip this entry */
560 ListEntry = ListEntry->Flink;
561 continue;
562 }
563
564 /* Get the Device Object for this FS */
565 FileSystemDeviceObject = CONTAINING_RECORD(ListEntry,
567 Queue.ListEntry);
568 ParentFsDeviceObject = FileSystemDeviceObject;
569
570 /*
571 * If this file system device is attached to some other device,
572 * then we must make sure to increase the stack size for the IRP.
573 * The default is +1, for the FS device itself.
574 */
575 FsStackOverhead = 1;
576 while (FileSystemDeviceObject->AttachedDevice)
577 {
578 /* Get the next attached device and increase overhead */
579 FileSystemDeviceObject = FileSystemDeviceObject->
580 AttachedDevice;
581 FsStackOverhead++;
582 }
583
584 /* Clear the event */
586
587 /* Allocate the IRP */
589 (UCHAR)FsStackOverhead,
590 TRUE);
591 if (!Irp)
592 {
593 /* Fail */
595 break;
596 }
597
598 /* Setup the IRP */
599 Irp->UserIosb = &IoStatusBlock;
600 Irp->UserEvent = &Event;
601 Irp->Tail.Overlay.Thread = PsGetCurrentThread();
603 Irp->RequestorMode = KernelMode;
604
605 /* Get the I/O Stack location and set it up */
606 StackPtr = IoGetNextIrpStackLocation(Irp);
609 StackPtr->Flags = AllowRawMount;
610 StackPtr->Parameters.MountVolume.Vpb = DeviceObject->Vpb;
611 StackPtr->Parameters.MountVolume.DeviceObject =
613
614 /* Save registration operations */
615 RegistrationOps = IopFsRegistrationOps;
616
617 /* Release locks */
620
621 /* Call the driver */
622 Status = IoCallDriver(FileSystemDeviceObject, Irp);
623 if (Status == STATUS_PENDING)
624 {
625 /* Wait on it */
627 Executive,
629 FALSE,
630 NULL);
632 }
633
636
637 /* Check if mounting was successful */
638 if (NT_SUCCESS(Status))
639 {
640 /* Mount the VPB */
643 (DeviceObject->Vpb->Flags &
645 }
646 else
647 {
648 /* Check if we failed because of the user */
651 {
652 /* Break out and fail */
653 break;
654 }
655
656 /* If there were registration operations in the meanwhile */
657 if (RegistrationOps != IopFsRegistrationOps)
658 {
659 /* We need to setup a local list to pickup where we left */
660 LocalList.Flink = FsList->Flink;
661 ListEntry = &LocalList;
662
664 }
665
666 /* Otherwise, check if we need to load the FS driver */
668 {
669 /* We need to release the lock */
672
673 /* Release the device lock if we're holding it */
674 if (!DeviceIsLocked)
675 {
676 KeSetEvent(&DeviceObject->DeviceLock, 0, FALSE);
677 }
678
679 /* Leave critical section */
681
682 /* Load the FS */
683 IopLoadFileSystemDriver(ParentFsDeviceObject);
684
685 /* Check if the device isn't already locked */
686 if (!DeviceIsLocked)
687 {
688 /* Lock it ourselves */
690 DeviceLock,
691 Executive,
693 Alertable,
694 NULL);
695 if ((Status == STATUS_ALERTED) ||
697 {
698 /* Don't mount if we were interrupted */
700 return Status;
701 }
702 }
703
704 /* Reacquire the lock */
707
708 /* When we released the lock, make sure nobody beat us */
709 if (DeviceObject->Vpb->Flags & VPB_MOUNTED)
710 {
711 /* Someone did, break out */
713 break;
714 }
715
716 /* Start over by setting a failure */
718
719 /* We need to setup a local list to pickup where we left */
720 LocalList.Flink = FsList->Flink;
721 ListEntry = &LocalList;
722 }
723
724 /*
725 * Check if we failed with any other error then an unrecognized
726 * volume, and if this request doesn't allow mounting the raw
727 * file system.
728 */
729 if (!(AllowRawMount) &&
732 {
733 /* Break out and give up */
734 break;
735 }
736 }
737
738 /* Go to the next FS entry */
739 ListEntry = ListEntry->Flink;
740 }
741
742 /* Dereference the device if we failed */
744 }
745 else if (DeviceObject->Vpb->Flags & VPB_REMOVE_PENDING)
746 {
747 /* Someone wants to remove us */
749 }
750 else
751 {
752 /* Someone already mounted us */
754 }
755
756 /* Release the FS lock */
759
760 /* Release the device lock if we're holding it */
761 if (!DeviceIsLocked) KeSetEvent(&DeviceObject->DeviceLock, 0, FALSE);
762
763 /* Check if we failed to mount the boot partition */
764 if ((!NT_SUCCESS(Status)) &&
767 {
768 /* Bugcheck the system */
769 KeBugCheckEx(INACCESSIBLE_BOOT_DEVICE,
771 Status,
772 0,
773 0);
774 }
775
776 /* Return the mount status */
777 return Status;
778}
#define DO_SYSTEM_BOOT_PARTITION
Definition: env_spec_w32.h:400
#define ExAcquireResourceSharedLite(res, wait)
Definition: env_spec_w32.h:621
#define KeGetPreviousMode()
Definition: ketypes.h:1115
#define VPB_REMOVE_PENDING
Definition: ntifs_ex.h:428
ULONG ExpInitializationPhase
Definition: init.c:68
BOOLEAN NTAPI FsRtlIsTotalDeviceFailure(IN NTSTATUS NtStatus)
Definition: filter.c:37
ULONG FASTCALL IopInterlockedDecrementUlong(IN KSPIN_LOCK_QUEUE_NUMBER Queue, IN PULONG Ulong)
Definition: volume.c:331
ULONG FASTCALL IopInterlockedIncrementUlong(IN KSPIN_LOCK_QUEUE_NUMBER Queue, IN PULONG Ulong)
Definition: volume.c:313
LIST_ENTRY IopCdRomFileSystemQueueHead
Definition: volume.c:22
VOID NTAPI IopLoadFileSystemDriver(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:409
ERESOURCE IopDatabaseResource
Definition: volume.c:20
ULONG IopFsRegistrationOps
Definition: volume.c:24
LIST_ENTRY IopDiskFileSystemQueueHead
Definition: volume.c:21
PVPB NTAPI IopMountInitializeVpb(IN PDEVICE_OBJECT DeviceObject, IN PDEVICE_OBJECT AttachedDeviceObject, IN BOOLEAN Raw)
Definition: volume.c:249
LIST_ENTRY IopTapeFileSystemQueueHead
Definition: volume.c:22
#define STATUS_FS_DRIVER_REQUIRED
Definition: ntstatus.h:645
#define STATUS_DEVICE_DOES_NOT_EXIST
Definition: ntstatus.h:428
#define FILE_DEVICE_CD_ROM
Definition: winioctl.h:108
#define FILE_DEVICE_DISK
Definition: winioctl.h:113
#define FILE_DEVICE_VIRTUAL_DISK
Definition: winioctl.h:142
struct _IO_STACK_LOCATION::@3978::@3998 MountVolume
union _IO_STACK_LOCATION::@1564 Parameters
uint32_t * PULONG
Definition: typedefs.h:59
#define STATUS_UNRECOGNIZED_VOLUME
Definition: udferr_usr.h:173
WDF_EXTERN_C_START typedef _Must_inspect_result_ _In_ WDFDRIVER _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ PDEVICE_OBJECT _In_opt_ PDEVICE_OBJECT AttachedDeviceObject
Definition: wdfminiport.h:70
#define IoIsErrorUserInduced(Status)
Definition: iofuncs.h:2817
#define IRP_MJ_FILE_SYSTEM_CONTROL
#define VPB_RAW_MOUNT
Definition: iotypes.h:1811
#define IRP_MOUNT_COMPLETION
#define IRP_SYNCHRONOUS_PAGING_IO
#define IRP_MN_MOUNT_VOLUME
Definition: iotypes.h:4404
@ LockQueueIoDatabaseLock
Definition: ketypes.h:668

Referenced by IopCheckVpbMounted(), and IoVerifyVolume().

◆ IopOpenRegistryKeyEx()

◆ IopParseDevice()

NTSTATUS NTAPI IopParseDevice ( IN PVOID  ParseObject,
IN PVOID  ObjectType,
IN OUT PACCESS_STATE  AccessState,
IN KPROCESSOR_MODE  AccessMode,
IN ULONG  Attributes,
IN OUT PUNICODE_STRING  CompleteName,
IN OUT PUNICODE_STRING  RemainingName,
IN OUT PVOID  Context,
IN PSECURITY_QUALITY_OF_SERVICE SecurityQos  OPTIONAL,
OUT PVOID Object 
)

Definition at line 324 of file file.c.

334{
335 POPEN_PACKET OpenPacket = (POPEN_PACKET)Context;
336 PDEVICE_OBJECT OriginalDeviceObject = (PDEVICE_OBJECT)ParseObject;
337 PDEVICE_OBJECT DeviceObject, OwnerDevice;
340 PVPB Vpb = NULL;
341 PIRP Irp;
342 PIO_STACK_LOCATION StackLoc;
343 IO_SECURITY_CONTEXT SecurityContext;
345 BOOLEAN DirectOpen = FALSE, OpenCancelled, UseDummyFile;
348 PDUMMY_FILE_OBJECT LocalFileObject;
349 PFILE_BASIC_INFORMATION FileBasicInfo;
351 KPROCESSOR_MODE CheckMode;
352 BOOLEAN VolumeOpen = FALSE;
354 BOOLEAN AccessGranted, LockHeld = FALSE;
356 UNICODE_STRING FileString;
357 USHORT Attempt;
358 IOTRACE(IO_FILE_DEBUG, "ParseObject: %p. RemainingName: %wZ\n",
359 ParseObject, RemainingName);
360
361 for (Attempt = 0; Attempt < IOP_MAX_REPARSE_TRAVERSAL; ++Attempt)
362 {
363 /* Assume failure */
364 *Object = NULL;
365
366 /* Validate the open packet */
367 if (!IopValidateOpenPacket(OpenPacket)) return STATUS_OBJECT_TYPE_MISMATCH;
368
369 /* Valide reparse point in case we traversed a mountpoint */
370 if (OpenPacket->TraversedMountPoint)
371 {
372 /* This is a reparse point we understand */
374
375 /* Make sure we're dealing with correct DO */
376 if (OriginalDeviceObject->DeviceType != FILE_DEVICE_DISK &&
377 OriginalDeviceObject->DeviceType != FILE_DEVICE_CD_ROM &&
378 OriginalDeviceObject->DeviceType != FILE_DEVICE_VIRTUAL_DISK &&
379 OriginalDeviceObject->DeviceType != FILE_DEVICE_TAPE)
380 {
383 }
384 }
385
386 /* Check if we have a related file object */
387 if (OpenPacket->RelatedFileObject)
388 {
389 /* Use the related file object's device object */
390 OriginalDeviceObject = OpenPacket->RelatedFileObject->DeviceObject;
391 }
392
393 /* Validate device status */
394 Status = IopCheckDeviceAndDriver(OpenPacket, OriginalDeviceObject);
395 if (!NT_SUCCESS(Status))
396 {
397 /* We failed, return status */
398 OpenPacket->FinalStatus = Status;
399 return Status;
400 }
401
402 /* Map the generic mask and set the new mapping in the access state */
403 RtlMapGenericMask(&AccessState->RemainingDesiredAccess,
405 RtlMapGenericMask(&AccessState->OriginalDesiredAccess,
409 DesiredAccess = AccessState->RemainingDesiredAccess;
410
411 /* Check what kind of access checks to do */
412 if ((AccessMode != KernelMode) ||
413 (OpenPacket->Options & IO_FORCE_ACCESS_CHECK))
414 {
415 /* Call is from user-mode or kernel is forcing checks */
416 CheckMode = UserMode;
417 }
418 else
419 {
420 /* Call is from the kernel */
421 CheckMode = KernelMode;
422 }
423
424 /* Check privilege for backup or restore operation */
426 &OpenPacket->CreateOptions,
427 CheckMode,
428 OpenPacket->Disposition);
429
430 /* Check if we are re-parsing */
431 if (((OpenPacket->Override) && !(RemainingName->Length)) ||
433 {
434 /* Get granted access from the last call */
435 DesiredAccess |= AccessState->PreviouslyGrantedAccess;
436 }
437
438 /* Check if this is a volume open */
439 if ((OpenPacket->RelatedFileObject) &&
440 (OpenPacket->RelatedFileObject->Flags & FO_VOLUME_OPEN) &&
441 !(RemainingName->Length))
442 {
443 /* It is */
444 VolumeOpen = TRUE;
445 }
446
447 /* Now check if we need access checks */
448 if (((AccessMode != KernelMode) ||
449 (OpenPacket->Options & IO_FORCE_ACCESS_CHECK)) &&
450 (!(OpenPacket->RelatedFileObject) || (VolumeOpen)) &&
451 !(OpenPacket->Override))
452 {
455
456 /* Check if a device object is being parsed */
457 if (!RemainingName->Length)
458 {
459 /* Lock the subject context */
460 SeLockSubjectContext(&AccessState->SubjectSecurityContext);
461 LockHeld = TRUE;
462
463 /* Do access check */
464 AccessGranted = SeAccessCheck(OriginalDeviceObject->
466 &AccessState->SubjectSecurityContext,
467 LockHeld,
469 0,
470 &Privileges,
472 TypeInfo.GenericMapping,
473 UserMode,
475 &Status);
476 if (Privileges)
477 {
478 /* Append and free the privileges */
481 }
482
483 /* Check if we got access */
484 if (AccessGranted)
485 {
486 /* Update access state */
487 AccessState->PreviouslyGrantedAccess |= GrantedAccess;
488 AccessState->RemainingDesiredAccess &= ~(GrantedAccess |
490 OpenPacket->Override= TRUE;
491 }
492
493 FileString.Length = 8;
494 FileString.MaximumLength = 8;
495 FileString.Buffer = L"File";
496
497 /* Do Audit/Alarm for open operation */
498 SeOpenObjectAuditAlarm(&FileString,
499 OriginalDeviceObject,
500 CompleteName,
501 OriginalDeviceObject->SecurityDescriptor,
503 FALSE,
505 UserMode,
506 &AccessState->GenerateOnClose);
507 }
508 else
509 {
510 /* Check if we need to do traverse validation */
512 ((OriginalDeviceObject->DeviceType == FILE_DEVICE_DISK) ||
513 (OriginalDeviceObject->DeviceType == FILE_DEVICE_CD_ROM)))
514 {
515 /* Check if this is a restricted token */
516 if (!(AccessState->Flags & TOKEN_IS_RESTRICTED))
517 {
518 /* Do the FAST traverse check */
519 AccessGranted = SeFastTraverseCheck(OriginalDeviceObject->SecurityDescriptor,
522 UserMode);
523 }
524 else
525 {
526 /* Fail */
528 }
529
530 /* Check if we failed to get access */
531 if (!AccessGranted)
532 {
533 /* Lock the subject context */
534 SeLockSubjectContext(&AccessState->SubjectSecurityContext);
535 LockHeld = TRUE;
536
537 /* Do access check */
538 AccessGranted = SeAccessCheck(OriginalDeviceObject->
540 &AccessState->SubjectSecurityContext,
541 LockHeld,
543 0,
544 &Privileges,
546 TypeInfo.GenericMapping,
547 UserMode,
549 &Status);
550 if (Privileges)
551 {
552 /* Append and free the privileges */
555 }
556 }
557
558 /* FIXME: Do Audit/Alarm for traverse check */
559 }
560 else
561 {
562 /* Access automatically granted */
564 }
565 }
566
569
570 /* Check if we hold the lock */
571 if (LockHeld)
572 {
573 /* Release it */
574 SeUnlockSubjectContext(&AccessState->SubjectSecurityContext);
575 }
576
577 /* Check if access failed */
578 if (!AccessGranted)
579 {
580 /* Dereference the device and fail */
581 DPRINT1("Traverse access failed!\n");
582 IopDereferenceDeviceObject(OriginalDeviceObject, FALSE);
584 }
585 }
586
587 /* Check if we can simply use a dummy file */
588 UseDummyFile = ((OpenPacket->QueryOnly) || (OpenPacket->DeleteOnly));
589
590 /* Check if this is a direct open */
591 if (!(RemainingName->Length) &&
592 !(OpenPacket->RelatedFileObject) &&
598 WRITE_DAC)) == 0) &&
599 !(UseDummyFile))
600 {
601 /* Remember this for later */
602 DirectOpen = TRUE;
603 }
604
605 /* Check if we have a related FO that wasn't a direct open */
606 if ((OpenPacket->RelatedFileObject) &&
607 !(OpenPacket->RelatedFileObject->Flags & FO_DIRECT_DEVICE_OPEN))
608 {
609 /* The device object is the one we were given */
610 DeviceObject = ParseObject;
611
612 /* Check if the related FO had a VPB */
613 if (OpenPacket->RelatedFileObject->Vpb)
614 {
615 /* Yes, remember it */
616 Vpb = OpenPacket->RelatedFileObject->Vpb;
617
618 /* Reference it */
619 InterlockedIncrement((PLONG)&Vpb->ReferenceCount);
620
621 /* Check if we were given a specific top level device to use */
623 {
624 DeviceObject = Vpb->DeviceObject;
625 }
626 }
627 }
628 else
629 {
630 /* Check if it has a VPB */
631 if ((OriginalDeviceObject->Vpb) && !(DirectOpen))
632 {
633 /* Check if the VPB is mounted, and mount it */
634 Vpb = IopCheckVpbMounted(OpenPacket,
635 OriginalDeviceObject,
637 &Status);
638 if (!Vpb) return Status;
639
640 /* Get the VPB's device object */
641 DeviceObject = Vpb->DeviceObject;
642 }
643 else
644 {
645 /* The device object is the one we were given */
646 DeviceObject = OriginalDeviceObject;
647 }
648
649 /* If we weren't given a specific top level device, look for an attached device */
650 if (!(OpenPacket->InternalFlags & IOP_USE_TOP_LEVEL_DEVICE_HINT) &&
651 DeviceObject->AttachedDevice)
652 {
653 /* Get the attached device */
655 }
656 }
657
658 /* If we have a top level device hint, verify it */
660 {
661 Status = IopCheckTopDeviceHint(&DeviceObject, OpenPacket, DirectOpen);
662 if (!NT_SUCCESS(Status))
663 {
664 IopDereferenceDeviceObject(OriginalDeviceObject, FALSE);
666 return Status;
667 }
668 }
669
670 /* If we traversed a mount point, reset the information */
671 if (OpenPacket->TraversedMountPoint)
672 {
673 OpenPacket->TraversedMountPoint = FALSE;
674 }
675
676 /* Check if this is a secure FSD */
677 if ((DeviceObject->Characteristics & FILE_DEVICE_SECURE_OPEN) &&
678 ((OpenPacket->RelatedFileObject) || (RemainingName->Length)) &&
679 (!VolumeOpen))
680 {
682 GrantedAccess = 0;
683
686
687 /* Lock the subject context */
688 SeLockSubjectContext(&AccessState->SubjectSecurityContext);
689
690 /* Do access check */
691 AccessGranted = SeAccessCheck(OriginalDeviceObject->SecurityDescriptor,
692 &AccessState->SubjectSecurityContext,
693 TRUE,
695 0,
696 &Privileges,
698 UserMode,
700 &Status);
701 if (Privileges != NULL)
702 {
703 /* Append and free the privileges */
706 }
707
708 /* Check if we got access */
709 if (GrantedAccess)
710 {
711 AccessState->PreviouslyGrantedAccess |= GrantedAccess;
712 AccessState->RemainingDesiredAccess &= ~(GrantedAccess | MAXIMUM_ALLOWED);
713 }
714
715 FileString.Length = 8;
716 FileString.MaximumLength = 8;
717 FileString.Buffer = L"File";
718
719 /* Do Audit/Alarm for open operation
720 * NOTA: we audit target device object
721 */
722 SeOpenObjectAuditAlarm(&FileString,
724 CompleteName,
725 OriginalDeviceObject->SecurityDescriptor,
727 FALSE,
729 UserMode,
730 &AccessState->GenerateOnClose);
731
732 SeUnlockSubjectContext(&AccessState->SubjectSecurityContext);
733
736
737 /* Check if access failed */
738 if (!AccessGranted)
739 {
740 /* Dereference the device and fail */
741 IopDereferenceDeviceObject(OriginalDeviceObject, FALSE);
744 }
745 }
746
747 /* Allocate the IRP */
748 Irp = IoAllocateIrp(DeviceObject->StackSize, TRUE);
749 if (!Irp)
750 {
751 /* Dereference the device and VPB, then fail */
752 IopDereferenceDeviceObject(OriginalDeviceObject, FALSE);
755 }
756
757 /* Now set the IRP data */
758 Irp->RequestorMode = AccessMode;
760 Irp->Tail.Overlay.Thread = PsGetCurrentThread();
761 Irp->UserIosb = &IoStatusBlock;
762 Irp->MdlAddress = NULL;
763 Irp->PendingReturned = FALSE;
764 Irp->UserEvent = NULL;
765 Irp->Cancel = FALSE;
766 Irp->CancelRoutine = NULL;
767 Irp->Tail.Overlay.AuxiliaryBuffer = NULL;
768
769 /* Setup the security context */
770 SecurityContext.SecurityQos = SecurityQos;
771 SecurityContext.AccessState = AccessState;
772 SecurityContext.DesiredAccess = AccessState->RemainingDesiredAccess;
773 SecurityContext.FullCreateOptions = OpenPacket->CreateOptions;
774
775 /* Get the I/O Stack location */
776 StackLoc = IoGetNextIrpStackLocation(Irp);
777 StackLoc->Control = 0;
778
779 /* Check what kind of file this is */
780 switch (OpenPacket->CreateFileType)
781 {
782 /* Normal file */
784
785 /* Set the major function and EA Length */
786 StackLoc->MajorFunction = IRP_MJ_CREATE;
787 StackLoc->Parameters.Create.EaLength = OpenPacket->EaLength;
788
789 /* Set the flags */
790 StackLoc->Flags = (UCHAR)OpenPacket->Options;
792 break;
793
794 /* Named pipe */
796
797 /* Set the named pipe MJ and set the parameters */
799 StackLoc->Parameters.CreatePipe.Parameters = OpenPacket->ExtraCreateParameters;
800 break;
801
802 /* Mailslot */
804
805 /* Set the mailslot MJ and set the parameters */
807 StackLoc->Parameters.CreateMailslot.Parameters = OpenPacket->ExtraCreateParameters;
808 break;
809 }
810
811 /* Set the common data */
812 Irp->Overlay.AllocationSize = OpenPacket->AllocationSize;
813 Irp->AssociatedIrp.SystemBuffer = OpenPacket->EaBuffer;
814 StackLoc->Parameters.Create.Options = (OpenPacket->Disposition << 24) |
815 (OpenPacket->CreateOptions &
816 0xFFFFFF);
817 StackLoc->Parameters.Create.FileAttributes = OpenPacket->FileAttributes;
818 StackLoc->Parameters.Create.ShareAccess = OpenPacket->ShareAccess;
819 StackLoc->Parameters.Create.SecurityContext = &SecurityContext;
820
821 /* Check if we really need to create an object */
822 if (!UseDummyFile)
823 {
824 ULONG ObjectSize = sizeof(FILE_OBJECT);
825
826 /* Tag on space for a file object extension */
828 ObjectSize += sizeof(FILE_OBJECT_EXTENSION);
829
830 /* Create the actual file object */
832 NULL,
834 NULL,
835 NULL);
840 NULL,
841 ObjectSize,
842 0,
843 0,
844 (PVOID*)&FileObject);
845 if (!NT_SUCCESS(Status))
846 {
847 /* Create failed, free the IRP */
848 IoFreeIrp(Irp);
849
850 /* Dereference the device and VPB */
851 IopDereferenceDeviceObject(OriginalDeviceObject, FALSE);
853
854 /* We failed, return status */
855 OpenPacket->FinalStatus = Status;
856 return Status;
857 }
858
859 /* Clear the file object */
860 RtlZeroMemory(FileObject, ObjectSize);
861
862 /* Check if this is Synch I/O */
863 if (OpenPacket->CreateOptions &
865 {
866 /* Set the synch flag */
868
869 /* Check if it's also alertable */
871 {
872 /* It is, set the alertable flag */
873 FileObject->Flags |= FO_ALERTABLE_IO;
874 }
875 }
876
877 /* Check if this is synch I/O */
878 if (FileObject->Flags & FO_SYNCHRONOUS_IO)
879 {
880 /* Initialize the event */
882 }
883
884 /* Check if the caller requested no intermediate buffering */
886 {
887 /* Set the correct flag for the FSD to read */
889 }
890
891 /* Check if the caller requested write through support */
892 if (OpenPacket->CreateOptions & FILE_WRITE_THROUGH)
893 {
894 /* Set the correct flag for the FSD to read */
896 }
897
898 /* Check if the caller says the file will be only read sequentially */
899 if (OpenPacket->CreateOptions & FILE_SEQUENTIAL_ONLY)
900 {
901 /* Set the correct flag for the FSD to read */
903 }
904
905 /* Check if the caller believes the file will be only read randomly */
906 if (OpenPacket->CreateOptions & FILE_RANDOM_ACCESS)
907 {
908 /* Set the correct flag for the FSD to read */
910 }
911
912 /* Check if we were asked to setup a file object extension */
914 {
915 PFILE_OBJECT_EXTENSION FileObjectExtension;
916
917 /* Make sure the file object knows it has an extension */
919
920 /* Initialize file object extension */
921 FileObjectExtension = (PFILE_OBJECT_EXTENSION)(FileObject + 1);
922 FileObject->FileObjectExtension = FileObjectExtension;
923
924 /* Add the top level device which we'll send the request to */
926 {
927 FileObjectExtension->TopDeviceObjectHint = DeviceObject;
928 }
929 }
930 }
931 else
932 {
933 /* Use the dummy object instead */
934 LocalFileObject = OpenPacket->LocalFileObject;
935 RtlZeroMemory(LocalFileObject, sizeof(DUMMY_FILE_OBJECT));
936
937 /* Set it up */
938 FileObject = (PFILE_OBJECT)&LocalFileObject->ObjectHeader.Body;
939 LocalFileObject->ObjectHeader.Type = IoFileObjectType;
940 LocalFileObject->ObjectHeader.PointerCount = 1;
941 }
942
943 /* Setup the file header */
944 FileObject->Type = IO_TYPE_FILE;
945 FileObject->Size = sizeof(FILE_OBJECT);
946 FileObject->RelatedFileObject = OpenPacket->RelatedFileObject;
947 FileObject->DeviceObject = OriginalDeviceObject;
948
949 /* Check if this is a direct device open */
950 if (DirectOpen) FileObject->Flags |= FO_DIRECT_DEVICE_OPEN;
951
952 /* Check if the caller wants case sensitivity */
954 {
955 /* Tell the driver about it */
957 }
958
959 /* Now set the file object */
960 Irp->Tail.Overlay.OriginalFileObject = FileObject;
961 StackLoc->FileObject = FileObject;
962
963 /* Check if the file object has a name */
964 if (RemainingName->Length)
965 {
966 /* Setup the unicode string */
967 FileObject->FileName.MaximumLength = RemainingName->Length + sizeof(WCHAR);
968 FileObject->FileName.Buffer = ExAllocatePoolWithTag(PagedPool,
969 FileObject->FileName.MaximumLength,
971 if (!FileObject->FileName.Buffer)
972 {
973 /* Failed to allocate the name, free the IRP */
974 IoFreeIrp(Irp);
975
976 /* Dereference the device object and VPB */
977 IopDereferenceDeviceObject(OriginalDeviceObject, FALSE);
979
980 /* Clear the FO and dereference it */
981 FileObject->DeviceObject = NULL;
982 if (!UseDummyFile) ObDereferenceObject(FileObject);
983
984 /* Fail */
986 }
987 }
988
989 /* Copy the name */
991
992 /* Initialize the File Object event and set the FO */
994 OpenPacket->FileObject = FileObject;
995
996 /* Queue the IRP and call the driver */
999 if (Status == STATUS_PENDING)
1000 {
1001 /* Wait for the driver to complete the create */
1003 Executive,
1004 KernelMode,
1005 FALSE,
1006 NULL);
1007
1008 /* Get the new status */
1010 }
1011 else
1012 {
1013 /* We'll have to complete it ourselves */
1014 ASSERT(!Irp->PendingReturned);
1015 ASSERT(!Irp->MdlAddress);
1016
1017 /* Handle name change if required */
1018 if (Status == STATUS_REPARSE)
1019 {
1020 /* Check this is a mount point */
1021 if (Irp->IoStatus.Information == IO_REPARSE_TAG_MOUNT_POINT)
1022 {
1023 PREPARSE_DATA_BUFFER ReparseData;
1024
1025 /* Reparse point attributes were passed by the driver in the auxiliary buffer */
1026 ASSERT(Irp->Tail.Overlay.AuxiliaryBuffer != NULL);
1027 ReparseData = (PREPARSE_DATA_BUFFER)Irp->Tail.Overlay.AuxiliaryBuffer;
1028
1032
1033 IopDoNameTransmogrify(Irp, FileObject, ReparseData);
1034 }
1035 }
1036
1037 /* Completion happens at APC_LEVEL */
1039
1040 /* Get the new I/O Status block ourselves */
1041 IoStatusBlock = Irp->IoStatus;
1043
1044 /* Manually signal the even, we can't have any waiters */
1045 FileObject->Event.Header.SignalState = 1;
1046
1047 /* Now that we've signaled the events, de-associate the IRP */
1049
1050 /* Check if the IRP had an input buffer */
1051 if ((Irp->Flags & IRP_BUFFERED_IO) &&
1052 (Irp->Flags & IRP_DEALLOCATE_BUFFER))
1053 {
1054 /* Free it. A driver might've tacked one on */
1055 ExFreePool(Irp->AssociatedIrp.SystemBuffer);
1056 }
1057
1058 /* Free the IRP and bring the IRQL back down */
1059 IoFreeIrp(Irp);
1061 }
1062
1063 /* Copy the I/O Status */
1065
1066 /* The driver failed to create the file */
1067 if (!NT_SUCCESS(Status))
1068 {
1069 /* Check if we have a name and if so, free it */
1070 if (FileObject->FileName.Length)
1071 {
1072 /*
1073 * Don't use TAG_IO_NAME since the FileObject's FileName
1074 * may have been re-allocated using a different tag
1075 * by a filesystem.
1076 */
1077 ExFreePoolWithTag(FileObject->FileName.Buffer, 0);
1078 FileObject->FileName.Buffer = NULL;
1079 FileObject->FileName.Length = 0;
1080 }
1081
1082 /* Clear its device object */
1083 FileObject->DeviceObject = NULL;
1084
1085 /* Save this now because the FO might go away */
1086 OpenCancelled = FileObject->Flags & FO_FILE_OPEN_CANCELLED ?
1087 TRUE : FALSE;
1088
1089 /* Clear the file object in the open packet */
1090 OpenPacket->FileObject = NULL;
1091
1092 /* Dereference the file object */
1093 if (!UseDummyFile) ObDereferenceObject(FileObject);
1094
1095 /* Dereference the device object */
1096 IopDereferenceDeviceObject(OriginalDeviceObject, FALSE);
1097
1098 /* Unless the driver cancelled the open, dereference the VPB */
1099 if (!(OpenCancelled) && (Vpb)) IopDereferenceVpbAndFree(Vpb);
1100
1101 /* Set the status and return */
1102 OpenPacket->FinalStatus = Status;
1103 return Status;
1104 }
1105 else if (Status == STATUS_REPARSE)
1106 {
1107 if (OpenPacket->Information == IO_REPARSE ||
1109 {
1110 /* Update CompleteName with reparse info which got updated in IopDoNameTransmogrify() */
1111 if (CompleteName->MaximumLength < FileObject->FileName.Length)
1112 {
1113 PWSTR NewCompleteName;
1114
1115 /* Allocate a new buffer for the string */
1116 NewCompleteName = ExAllocatePoolWithTag(PagedPool, FileObject->FileName.Length, TAG_IO_NAME);
1117 if (NewCompleteName == NULL)
1118 {
1121 }
1122
1123 /* Release the old one */
1124 if (CompleteName->Buffer != NULL)
1125 {
1126 /*
1127 * Don't use TAG_IO_NAME since the FileObject's FileName
1128 * may have been re-allocated using a different tag
1129 * by a filesystem.
1130 */
1131 ExFreePoolWithTag(CompleteName->Buffer, 0);
1132 }
1133
1134 /* And setup the new one */
1135 CompleteName->Buffer = NewCompleteName;
1136 CompleteName->MaximumLength = FileObject->FileName.Length;
1137 }
1138
1139 /* Copy our new complete name */
1140 RtlCopyUnicodeString(CompleteName, &FileObject->FileName);
1141
1142 if (OpenPacket->Information == IO_REPARSE_TAG_MOUNT_POINT)
1143 {
1144 OpenPacket->RelatedFileObject = NULL;
1145 }
1146 }
1147
1148 /* Check if we have a name and if so, free it */
1149 if (FileObject->FileName.Length)
1150 {
1151 /*
1152 * Don't use TAG_IO_NAME since the FileObject's FileName
1153 * may have been re-allocated using a different tag
1154 * by a filesystem.
1155 */
1156 ExFreePoolWithTag(FileObject->FileName.Buffer, 0);
1157 FileObject->FileName.Buffer = NULL;
1158 FileObject->FileName.Length = 0;
1159 }
1160
1161 /* Clear its device object */
1162 FileObject->DeviceObject = NULL;
1163
1164 /* Clear the file object in the open packet */
1165 OpenPacket->FileObject = NULL;
1166
1167 /* Dereference the file object */
1168 if (!UseDummyFile) ObDereferenceObject(FileObject);
1169
1170 /* Dereference the device object */
1171 IopDereferenceDeviceObject(OriginalDeviceObject, FALSE);
1172
1173 /* Unless the driver cancelled the open, dereference the VPB */
1175
1176 if (OpenPacket->Information != IO_REMOUNT)
1177 {
1178 OpenPacket->RelatedFileObject = NULL;
1179
1180 /* Inform we traversed a mount point for later attempt */
1181 if (OpenPacket->Information == IO_REPARSE_TAG_MOUNT_POINT)
1182 {
1183 OpenPacket->TraversedMountPoint = 1;
1184 }
1185
1186 /* In case we override checks, but got this on volume open, fail hard */
1187 if (OpenPacket->Override)
1188 {
1189 KeBugCheckEx(DRIVER_RETURNED_STATUS_REPARSE_FOR_VOLUME_OPEN,
1190 (ULONG_PTR)OriginalDeviceObject,
1192 (ULONG_PTR)CompleteName,
1193 OpenPacket->Information);
1194 }
1195
1196 /* Return to IO/OB so that information can be upgraded */
1197 return STATUS_REPARSE;
1198 }
1199
1200 /* Loop again and reattempt an opening */
1201 continue;
1202 }
1203
1204 break;
1205 }
1206
1207 if (Attempt == IOP_MAX_REPARSE_TRAVERSAL)
1208 return STATUS_UNSUCCESSFUL;
1209
1210 /* Get the owner of the File Object */
1211 OwnerDevice = IoGetRelatedDeviceObject(FileObject);
1212
1213 /*
1214 * It's possible that the device to whom we sent the IRP to
1215 * isn't actually the device that ended opening the file object
1216 * internally.
1217 */
1218 if (OwnerDevice != DeviceObject)
1219 {
1220 /* We have to de-reference the VPB we had associated */
1222
1223 /* And re-associate with the actual one */
1224 Vpb = FileObject->Vpb;
1225 if (Vpb) InterlockedIncrement((PLONG)&Vpb->ReferenceCount);
1226 }
1227
1228 /* Make sure we are not using a dummy */
1229 if (!UseDummyFile)
1230 {
1231 /* Check if this was a volume open */
1232 if ((!(FileObject->RelatedFileObject) ||
1233 (FileObject->RelatedFileObject->Flags & FO_VOLUME_OPEN)) &&
1234 !(FileObject->FileName.Length))
1235 {
1236 /* All signs point to it, but make sure it was actually an FSD */
1237 if ((OwnerDevice->DeviceType == FILE_DEVICE_DISK_FILE_SYSTEM) ||
1238 (OwnerDevice->DeviceType == FILE_DEVICE_CD_ROM_FILE_SYSTEM) ||
1239 (OwnerDevice->DeviceType == FILE_DEVICE_TAPE_FILE_SYSTEM) ||
1240 (OwnerDevice->DeviceType == FILE_DEVICE_FILE_SYSTEM))
1241 {
1242 /* The owner device is an FSD, so this is a volume open for real */
1243 FileObject->Flags |= FO_VOLUME_OPEN;
1244 }
1245 }
1246
1247 /* Reference the object and set the parse check */
1249 *Object = FileObject;
1250 OpenPacket->FinalStatus = IoStatusBlock.Status;
1251 OpenPacket->ParseCheck = TRUE;
1252 return OpenPacket->FinalStatus;
1253 }
1254 else
1255 {
1256 /* Check if this was a query */
1257 if (OpenPacket->QueryOnly)
1258 {
1259 /* Check if the caller wants basic info only */
1260 if (!OpenPacket->FullAttributes)
1261 {
1262 /* Allocate the buffer */
1263 FileBasicInfo = ExAllocatePoolWithTag(NonPagedPool,
1264 sizeof(*FileBasicInfo),
1265 TAG_IO);
1266 if (FileBasicInfo)
1267 {
1268 /* Do the query */
1271 sizeof(*FileBasicInfo),
1272 FileBasicInfo,
1273 &ReturnLength);
1274 if (NT_SUCCESS(Status))
1275 {
1276 /* Copy the data */
1277 RtlCopyMemory(OpenPacket->BasicInformation,
1278 FileBasicInfo,
1279 ReturnLength);
1280 }
1281
1282 /* Free our buffer */
1283 ExFreePoolWithTag(FileBasicInfo, TAG_IO);
1284 }
1285 else
1286 {
1287 /* Fail */
1289 }
1290 }
1291 else
1292 {
1293 /* This is a full query */
1295 FileObject,
1298 OpenPacket->NetworkInformation,
1299 &ReturnLength);
1301 }
1302 }
1303
1304 /* Delete the file object */
1306
1307 /* Clear out the file */
1308 OpenPacket->FileObject = NULL;
1309
1310 /* Set and return status */
1311 OpenPacket->FinalStatus = Status;
1312 OpenPacket->ParseCheck = TRUE;
1313 return Status;
1314 }
1315}
BOOLEAN NTAPI SeAccessCheck(_In_ PSECURITY_DESCRIPTOR SecurityDescriptor, _In_ PSECURITY_SUBJECT_CONTEXT SubjectSecurityContext, _In_ BOOLEAN SubjectContextLocked, _In_ ACCESS_MASK DesiredAccess, _In_ ACCESS_MASK PreviouslyGrantedAccess, _Out_ PPRIVILEGE_SET *Privileges, _In_ PGENERIC_MAPPING GenericMapping, _In_ KPROCESSOR_MODE AccessMode, _Out_ PACCESS_MASK GrantedAccess, _Out_ PNTSTATUS AccessStatus)
Determines whether security access rights can be given to an object depending on the security descrip...
Definition: accesschk.c:1994
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:43
struct _DEVICE_OBJECT * PDEVICE_OBJECT
@ FileNetworkOpenInformation
Definition: from_kernel.h:95
@ FileBasicInformation
Definition: from_kernel.h:65
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define FILE_NO_INTERMEDIATE_BUFFERING
Definition: from_kernel.h:28
#define FILE_RANDOM_ACCESS
Definition: from_kernel.h:38
#define FILE_WRITE_THROUGH
Definition: from_kernel.h:26
#define FILE_SEQUENTIAL_ONLY
Definition: from_kernel.h:27
__in WDFOBJECT __in PCWDF_OBJECT_CONTEXT_TYPE_INFO TypeInfo
Definition: handleapi.cpp:601
static __inline BOOLEAN IopValidateOpenPacket(IN POPEN_PACKET OpenPacket)
Definition: io_x.h:154
NTSTATUS NTAPI IoQueryFileInformation(IN PFILE_OBJECT FileObject, IN FILE_INFORMATION_CLASS FileInformationClass, IN ULONG Length, OUT PVOID FileInformation, OUT PULONG ReturnedLength)
Definition: iofunc.c:1274
#define UserMode
Definition: asm.h:35
NTSYSAPI VOID NTAPI RtlMapGenericMask(PACCESS_MASK AccessMask, PGENERIC_MAPPING GenericMapping)
#define SYNCHRONIZE
Definition: nt_native.h:61
#define WRITE_DAC
Definition: nt_native.h:59
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define ACCESS_SYSTEM_SECURITY
Definition: nt_native.h:77
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define FILE_TRAVERSE
Definition: nt_native.h:643
#define READ_CONTROL
Definition: nt_native.h:58
#define WRITE_OWNER
Definition: nt_native.h:60
#define MAXIMUM_ALLOWED
Definition: nt_native.h:83
@ FILE_OBJECT
Definition: ntobjenum.h:17
#define IOP_USE_TOP_LEVEL_DEVICE_HINT
Definition: io.h:96
struct _OPEN_PACKET * POPEN_PACKET
PVPB NTAPI IopCheckVpbMounted(IN POPEN_PACKET OpenPacket, IN PDEVICE_OBJECT DeviceObject, IN PUNICODE_STRING RemainingName, OUT PNTSTATUS Status)
Definition: volume.c:76
struct _FILE_OBJECT_EXTENSION FILE_OBJECT_EXTENSION
#define IOP_CREATE_FILE_OBJECT_EXTENSION
Definition: io.h:97
#define IOP_MAX_REPARSE_TRAVERSAL
Definition: io.h:91
struct _FILE_OBJECT_EXTENSION * PFILE_OBJECT_EXTENSION
VOID NTAPI IopDereferenceVpbAndFree(IN PVPB Vpb)
Definition: volume.c:186
BOOLEAN NTAPI SeFastTraverseCheck(_In_ PSECURITY_DESCRIPTOR SecurityDescriptor, _In_ PACCESS_STATE AccessState, _In_ ACCESS_MASK DesiredAccess, _In_ KPROCESSOR_MODE AccessMode)
Determines whether security access rights can be given to an object depending on the security descrip...
Definition: accesschk.c:2138
ERESOURCE IopSecurityResource
Definition: iomgr.c:60
NTSTATUS IopCheckTopDeviceHint(IN OUT PDEVICE_OBJECT *DeviceObject, IN POPEN_PACKET OpenPacket, BOOLEAN DirectOpen)
Definition: file.c:275
VOID NTAPI IopCheckBackupRestorePrivilege(IN PACCESS_STATE AccessState, IN OUT PULONG CreateOptions, IN KPROCESSOR_MODE PreviousMode, IN ULONG Disposition)
Definition: file.c:25
VOID NTAPI IopDoNameTransmogrify(IN PIRP Irp, IN PFILE_OBJECT FileObject, IN PREPARSE_DATA_BUFFER DataBuffer)
Definition: file.c:170
NTSTATUS NTAPI IopCheckDeviceAndDriver(IN POPEN_PACKET OpenPacket, IN PDEVICE_OBJECT DeviceObject)
Definition: file.c:135
VOID NTAPI IopDeleteFile(IN PVOID ObjectBody)
Definition: file.c:1355
VOID NTAPI SeSetAccessStateGenericMapping(_In_ PACCESS_STATE AccessState, _In_ PGENERIC_MAPPING GenericMapping)
Sets a new generic mapping for an allocated access state.
Definition: access.c:193
VOID NTAPI SeOpenObjectAuditAlarm(_In_ PUNICODE_STRING ObjectTypeName, _In_opt_ PVOID Object, _In_opt_ PUNICODE_STRING AbsoluteObjectName, _In_ PSECURITY_DESCRIPTOR SecurityDescriptor, _In_ PACCESS_STATE AccessState, _In_ BOOLEAN ObjectCreated, _In_ BOOLEAN AccessGranted, _In_ KPROCESSOR_MODE AccessMode, _Out_ PBOOLEAN GenerateOnClose)
Creates an audit with alarm notification of an object that is being opened.
Definition: audit.c:1213
VOID NTAPI SeFreePrivileges(_In_ PPRIVILEGE_SET Privileges)
Frees a set of privileges.
Definition: priv.c:669
NTSTATUS NTAPI SeAppendPrivileges(_Inout_ PACCESS_STATE AccessState, _In_ PPRIVILEGE_SET Privileges)
Appends additional privileges.
Definition: priv.c:588
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:239
#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_FILE_SYSTEM
Definition: winioctl.h:109
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
OBJECT_HEADER ObjectHeader
Definition: io.h:358
ULONG Flags
Definition: pstypes.h:1435
PDEVICE_OBJECT TopDeviceObjectHint
Definition: io.h:102
PACCESS_STATE AccessState
Definition: iotypes.h:2867
PSECURITY_QUALITY_OF_SERVICE SecurityQos
Definition: iotypes.h:2866
ACCESS_MASK DesiredAccess
Definition: iotypes.h:2868
struct _IO_STACK_LOCATION::@3978::@3980 CreatePipe
struct _IO_STACK_LOCATION::@3978::@3981 CreateMailslot
struct _IO_STACK_LOCATION::@3978::@3979 Create
LONG_PTR PointerCount
Definition: obtypes.h:487
POBJECT_TYPE Type
Definition: obtypes.h:493
GENERIC_MAPPING GenericMapping
Definition: obtypes.h:358
OBJECT_TYPE_INITIALIZER TypeInfo
Definition: obtypes.h:390
LARGE_INTEGER AllocationSize
Definition: io.h:376
BOOLEAN Override
Definition: io.h:388
BOOLEAN DeleteOnly
Definition: io.h:390
PFILE_BASIC_INFORMATION BasicInformation
Definition: io.h:384
USHORT FileAttributes
Definition: io.h:378
PVOID ExtraCreateParameters
Definition: io.h:387
PFILE_NETWORK_OPEN_INFORMATION NetworkInformation
Definition: io.h:385
USHORT ShareAccess
Definition: io.h:379
BOOLEAN FullAttributes
Definition: io.h:391
NTSTATUS FinalStatus
Definition: io.h:371
CREATE_FILE_TYPE CreateFileType
Definition: io.h:386
PDUMMY_FILE_OBJECT LocalFileObject
Definition: io.h:392
ULONG_PTR Information
Definition: io.h:372
ULONG InternalFlags
Definition: io.h:394
ULONG Disposition
Definition: io.h:383
PFILE_OBJECT FileObject
Definition: io.h:370
ULONG Options
Definition: io.h:382
BOOLEAN TraversedMountPoint
Definition: io.h:393
PFILE_OBJECT RelatedFileObject
Definition: io.h:374
ULONG ParseCheck
Definition: io.h:373
ULONG CreateOptions
Definition: io.h:377
PVOID EaBuffer
Definition: io.h:380
ULONG EaLength
Definition: io.h:381
BOOLEAN QueryOnly
Definition: io.h:389
VOID NTAPI SeLockSubjectContext(_In_ PSECURITY_SUBJECT_CONTEXT SubjectContext)
Locks both the referenced primary and client access tokens of a security subject context.
Definition: subject.c:107
VOID NTAPI SeUnlockSubjectContext(_In_ PSECURITY_SUBJECT_CONTEXT SubjectContext)
Unlocks both the referenced primary and client access tokens of a security subject context.
Definition: subject.c:138
_Must_inspect_result_ _In_ WDFCOLLECTION _In_ WDFOBJECT Object
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES Attributes
_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_REPARSE
Definition: iotypes.h:543
#define FO_FILE_OPEN_CANCELLED
Definition: iotypes.h:1797
#define FO_SEQUENTIAL_ONLY
Definition: iotypes.h:1780
#define FO_ALERTABLE_IO
Definition: iotypes.h:1777
#define IO_FORCE_ACCESS_CHECK
Definition: iotypes.h:540
#define IRP_MJ_CREATE_NAMED_PIPE
#define IRP_MJ_CREATE_MAILSLOT
#define FO_OPENED_CASE_SENSITIVE
Definition: iotypes.h:1793
#define FO_WRITE_THROUGH
Definition: iotypes.h:1779
#define FO_RANDOM_ACCESS
Definition: iotypes.h:1796
#define FO_VOLUME_OPEN
Definition: iotypes.h:1798
#define IO_TYPE_FILE
#define IRP_DEFER_IO_COMPLETION
#define FO_NO_INTERMEDIATE_BUFFERING
Definition: iotypes.h:1778
@ CreateFileTypeNone
Definition: iotypes.h:535
@ CreateFileTypeNamedPipe
Definition: iotypes.h:536
@ CreateFileTypeMailslot
Definition: iotypes.h:537
#define IO_REMOUNT
Definition: iotypes.h:544
#define SL_CASE_SENSITIVE
Definition: iotypes.h:1820
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
_In_ PEPROCESS _In_ KPROCESSOR_MODE AccessMode
Definition: mmfuncs.h:396
_In_ PSECURITY_SUBJECT_CONTEXT _In_ BOOLEAN _In_ ACCESS_MASK _In_ ACCESS_MASK _Outptr_opt_ PPRIVILEGE_SET * Privileges
Definition: sefuncs.h:17
_In_opt_ PVOID _In_opt_ PUNICODE_STRING _In_ PSECURITY_DESCRIPTOR _In_ PACCESS_STATE _In_ BOOLEAN _In_ BOOLEAN AccessGranted
Definition: sefuncs.h:419
_In_opt_ PVOID _In_opt_ PUNICODE_STRING _In_ PSECURITY_DESCRIPTOR _In_ PACCESS_STATE AccessState
Definition: sefuncs.h:417
_In_ PSECURITY_SUBJECT_CONTEXT _In_ BOOLEAN _In_ ACCESS_MASK _In_ ACCESS_MASK _Outptr_opt_ PPRIVILEGE_SET _In_ PGENERIC_MAPPING _In_ KPROCESSOR_MODE _Out_ PACCESS_MASK GrantedAccess
Definition: sefuncs.h:20
#define TOKEN_HAS_TRAVERSE_PRIVILEGE
Definition: setypes.h:1178
#define TOKEN_IS_RESTRICTED
Definition: setypes.h:1183
#define SE_BACKUP_PRIVILEGES_CHECKED
Definition: setypes.h:1187

Referenced by IopCreateObjectTypes(), and IopParseFile().

◆ IopParseFile()

NTSTATUS NTAPI IopParseFile ( IN PVOID  ParseObject,
IN PVOID  ObjectType,
IN OUT PACCESS_STATE  AccessState,
IN KPROCESSOR_MODE  AccessMode,
IN ULONG  Attributes,
IN OUT PUNICODE_STRING  CompleteName,
IN OUT PUNICODE_STRING  RemainingName,
IN OUT PVOID Context  OPTIONAL,
IN PSECURITY_QUALITY_OF_SERVICE SecurityQos  OPTIONAL,
OUT PVOID Object 
)

Definition at line 1319 of file file.c.

1329{
1331 POPEN_PACKET OpenPacket = (POPEN_PACKET)Context;
1332
1333 /* Validate the open packet */
1334 if (!IopValidateOpenPacket(OpenPacket)) return STATUS_OBJECT_TYPE_MISMATCH;
1335
1336 /* Get the device object */
1338 OpenPacket->RelatedFileObject = ParseObject;
1339
1340 /* Call the main routine */
1342 ObjectType,
1344 AccessMode,
1345 Attributes,
1346 CompleteName,
1348 OpenPacket,
1349 SecurityQos,
1350 Object);
1351}
ObjectType
Definition: metafile.c:81
NTSTATUS NTAPI IopParseDevice(IN PVOID ParseObject, IN PVOID ObjectType, IN OUT PACCESS_STATE AccessState, IN KPROCESSOR_MODE AccessMode, IN ULONG Attributes, IN OUT PUNICODE_STRING CompleteName, IN OUT PUNICODE_STRING RemainingName, IN OUT PVOID Context, IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL, OUT PVOID *Object)
Definition: file.c:324

Referenced by IopCreateObjectTypes().

◆ IopQueryDeviceCapabilities()

NTSTATUS NTAPI IopQueryDeviceCapabilities ( PDEVICE_NODE  DeviceNode,
PDEVICE_CAPABILITIES  DeviceCaps 
)

Definition at line 854 of file devaction.c.

856{
857 IO_STATUS_BLOCK StatusBlock;
860 HANDLE InstanceKey;
862
863 /* Set up the Header */
864 RtlZeroMemory(DeviceCaps, sizeof(DEVICE_CAPABILITIES));
865 DeviceCaps->Size = sizeof(DEVICE_CAPABILITIES);
866 DeviceCaps->Version = 1;
867 DeviceCaps->Address = -1;
868 DeviceCaps->UINumber = -1;
869
870 /* Set up the Stack */
872 Stack.Parameters.DeviceCapabilities.Capabilities = DeviceCaps;
873
874 /* Send the IRP */
875 Status = IopInitiatePnpIrp(DeviceNode->PhysicalDeviceObject,
876 &StatusBlock,
878 &Stack);
879 if (!NT_SUCCESS(Status))
880 {
882 {
883 DPRINT1("IRP_MN_QUERY_CAPABILITIES failed with status 0x%lx\n", Status);
884 }
885 return Status;
886 }
887
888 /* Map device capabilities to capability flags */
889 DeviceNode->CapabilityFlags = 0;
890 if (DeviceCaps->LockSupported)
891 DeviceNode->CapabilityFlags |= 0x00000001; // CM_DEVCAP_LOCKSUPPORTED
892
893 if (DeviceCaps->EjectSupported)
894 DeviceNode->CapabilityFlags |= 0x00000002; // CM_DEVCAP_EJECTSUPPORTED
895
896 if (DeviceCaps->Removable)
897 DeviceNode->CapabilityFlags |= 0x00000004; // CM_DEVCAP_REMOVABLE
898
899 if (DeviceCaps->DockDevice)
900 DeviceNode->CapabilityFlags |= 0x00000008; // CM_DEVCAP_DOCKDEVICE
901
902 if (DeviceCaps->UniqueID)
903 DeviceNode->CapabilityFlags |= 0x00000010; // CM_DEVCAP_UNIQUEID
904
905 if (DeviceCaps->SilentInstall)
906 DeviceNode->CapabilityFlags |= 0x00000020; // CM_DEVCAP_SILENTINSTALL
907
908 if (DeviceCaps->RawDeviceOK)
909 DeviceNode->CapabilityFlags |= 0x00000040; // CM_DEVCAP_RAWDEVICEOK
910
911 if (DeviceCaps->SurpriseRemovalOK)
912 DeviceNode->CapabilityFlags |= 0x00000080; // CM_DEVCAP_SURPRISEREMOVALOK
913
914 if (DeviceCaps->HardwareDisabled)
915 DeviceNode->CapabilityFlags |= 0x00000100; // CM_DEVCAP_HARDWAREDISABLED
916
917 if (DeviceCaps->NonDynamic)
918 DeviceNode->CapabilityFlags |= 0x00000200; // CM_DEVCAP_NONDYNAMIC
919
920 if (DeviceCaps->NoDisplayInUI)
921 DeviceNode->UserFlags |= DNUF_DONT_SHOW_IN_UI;
922 else
923 DeviceNode->UserFlags &= ~DNUF_DONT_SHOW_IN_UI;
924
925 Status = IopCreateDeviceKeyPath(&DeviceNode->InstancePath, REG_OPTION_NON_VOLATILE, &InstanceKey);
926 if (NT_SUCCESS(Status))
927 {
928 /* Set 'Capabilities' value */
929 RtlInitUnicodeString(&ValueName, L"Capabilities");
930 Status = ZwSetValueKey(InstanceKey,
931 &ValueName,
932 0,
933 REG_DWORD,
934 &DeviceNode->CapabilityFlags,
935 sizeof(ULONG));
936
937 /* Set 'UINumber' value */
938 if (DeviceCaps->UINumber != MAXULONG)
939 {
940 RtlInitUnicodeString(&ValueName, L"UINumber");
941 Status = ZwSetValueKey(InstanceKey,
942 &ValueName,
943 0,
944 REG_DWORD,
945 &DeviceCaps->UINumber,
946 sizeof(ULONG));
947 }
948
949 ZwClose(InstanceKey);
950 }
951
952 return Status;
953}
#define DNUF_DONT_SHOW_IN_UI
Definition: iotypes.h:209
NTSTATUS NTAPI IopCreateDeviceKeyPath(IN PCUNICODE_STRING RegistryPath, IN ULONG CreateOptions, OUT PHANDLE Handle)
Definition: pnpmgr.c:522
NTSTATUS NTAPI IopInitiatePnpIrp(IN PDEVICE_OBJECT DeviceObject, IN PIO_STATUS_BLOCK IoStatusBlock, IN UCHAR MinorFunction, IN PIO_STACK_LOCATION Stack)
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#define MAXULONG
Definition: typedefs.h:251
DEVICE_CAPABILITIES
Definition: iotypes.h:965
#define IRP_MN_QUERY_CAPABILITIES

Referenced by IoGetDeviceProperty(), IopCreateDeviceInstancePath(), IoRequestDeviceEject(), and PiStartDeviceFinal().

◆ IopQueryName()

NTSTATUS NTAPI IopQueryName ( IN PVOID  ObjectBody,
IN BOOLEAN  HasName,
OUT POBJECT_NAME_INFORMATION  ObjectNameInfo,
IN ULONG  Length,
OUT PULONG  ReturnLength,
IN KPROCESSOR_MODE  PreviousMode 
)

Definition at line 1926 of file file.c.

1932{
1933 return IopQueryNameInternal(ObjectBody,
1934 HasName,
1935 FALSE,
1936 ObjectNameInfo,
1937 Length,
1939 PreviousMode);
1940}
NTSTATUS NTAPI IopQueryNameInternal(IN PVOID ObjectBody, IN BOOLEAN HasName, IN BOOLEAN QueryDosName, OUT POBJECT_NAME_INFORMATION ObjectNameInfo, IN ULONG Length, OUT PULONG ReturnLength, IN KPROCESSOR_MODE PreviousMode)
Definition: file.c:1944
_In_ KPROCESSOR_MODE PreviousMode
Definition: sefuncs.h:103

Referenced by IopCreateObjectTypes().

◆ IopQueryNameInternal()

NTSTATUS NTAPI IopQueryNameInternal ( IN PVOID  ObjectBody,
IN BOOLEAN  HasName,
IN BOOLEAN  QueryDosName,
OUT POBJECT_NAME_INFORMATION  ObjectNameInfo,
IN ULONG  Length,
OUT PULONG  ReturnLength,
IN KPROCESSOR_MODE  PreviousMode 
)

Definition at line 1944 of file file.c.

1951{
1952 POBJECT_NAME_INFORMATION LocalInfo;
1953 PFILE_NAME_INFORMATION LocalFileInfo;
1954 PFILE_OBJECT FileObject = (PFILE_OBJECT)ObjectBody;
1955 ULONG LocalReturnLength, FileLength;
1956 BOOLEAN LengthMismatch = FALSE;
1958 PWCHAR p;
1960 BOOLEAN NoObCall;
1961
1962 IOTRACE(IO_FILE_DEBUG, "ObjectBody: %p\n", ObjectBody);
1963
1964 /* Validate length */
1965 if (Length < sizeof(OBJECT_NAME_INFORMATION))
1966 {
1967 /* Wrong length, fail */
1970 }
1971
1972 /* Allocate Buffer */
1974 if (!LocalInfo) return STATUS_INSUFFICIENT_RESOURCES;
1975
1976 /* Query DOS name if the caller asked to */
1977 NoObCall = FALSE;
1978 if (QueryDosName)
1979 {
1980 DeviceObject = FileObject->DeviceObject;
1981
1982 /* In case of a network file system, don't call mountmgr */
1984 {
1985 /* We'll store separator and terminator */
1986 LocalReturnLength = sizeof(OBJECT_NAME_INFORMATION) + 2 * sizeof(WCHAR);
1987 if (Length < LocalReturnLength)
1988 {
1990 }
1991 else
1992 {
1993 LocalInfo->Name.Length = sizeof(WCHAR);
1994 LocalInfo->Name.MaximumLength = sizeof(WCHAR);
1995 LocalInfo->Name.Buffer = (PVOID)((ULONG_PTR)LocalInfo + sizeof(OBJECT_NAME_INFORMATION));
1996 LocalInfo->Name.Buffer[0] = OBJ_NAME_PATH_SEPARATOR;
1998 }
1999 }
2000 /* Otherwise, call mountmgr to get DOS name */
2001 else
2002 {
2004 LocalReturnLength = LocalInfo->Name.Length + sizeof(OBJECT_NAME_INFORMATION) + sizeof(WCHAR);
2005 }
2006 }
2007
2008 /* Fall back if querying DOS name failed or if caller never wanted it ;-) */
2009 if (!QueryDosName || !NT_SUCCESS(Status))
2010 {
2011 /* Query the name */
2012 Status = ObQueryNameString(FileObject->DeviceObject,
2013 LocalInfo,
2014 Length,
2015 &LocalReturnLength);
2016 }
2017 else
2018 {
2019 NoObCall = TRUE;
2020 }
2021
2023 {
2024 /* Free the buffer and fail */
2025 ExFreePoolWithTag(LocalInfo, TAG_IO);
2026 return Status;
2027 }
2028
2029 /* Get buffer pointer */
2030 p = (PWCHAR)(ObjectNameInfo + 1);
2031
2032 _SEH2_TRY
2033 {
2034 /* Copy the information */
2035 if (QueryDosName && NoObCall)
2036 {
2038
2039 /* Copy structure first */
2040 RtlCopyMemory(ObjectNameInfo,
2041 LocalInfo,
2042 (Length >= LocalReturnLength ? sizeof(OBJECT_NAME_INFORMATION) : Length));
2043 /* Name then */
2044 RtlCopyMemory(p, LocalInfo->Name.Buffer,
2045 (Length >= LocalReturnLength ? LocalInfo->Name.Length : Length - sizeof(OBJECT_NAME_INFORMATION)));
2046
2047 if (FileObject->DeviceObject->DeviceType != FILE_DEVICE_NETWORK_FILE_SYSTEM)
2048 {
2049 ExFreePool(LocalInfo->Name.Buffer);
2050 }
2051 }
2052 else
2053 {
2054 RtlCopyMemory(ObjectNameInfo,
2055 LocalInfo,
2056 (LocalReturnLength > Length) ?
2057 Length : LocalReturnLength);
2058 }
2059
2060 /* Set buffer pointer */
2061 ObjectNameInfo->Name.Buffer = p;
2062
2063 /* Advance in buffer */
2064 p += (LocalInfo->Name.Length / sizeof(WCHAR));
2065
2066 /* Check if this already filled our buffer */
2067 if (LocalReturnLength > Length)
2068 {
2069 /* Set the length mismatch to true, so that we can return
2070 * the proper buffer size to the caller later
2071 */
2072 LengthMismatch = TRUE;
2073
2074 /* Save the initial buffer length value */
2075 *ReturnLength = LocalReturnLength;
2076 }
2077
2078 /* Now get the file name buffer and check the length needed */
2079 LocalFileInfo = (PFILE_NAME_INFORMATION)LocalInfo;
2080 FileLength = Length -
2081 LocalReturnLength +
2083
2084 /* Query the File name */
2085 if (PreviousMode == KernelMode &&
2087 {
2089 LengthMismatch ? Length : FileLength,
2091 LocalFileInfo,
2092 &LocalReturnLength);
2093 }
2094 else
2095 {
2098 LengthMismatch ? Length : FileLength,
2099 LocalFileInfo,
2100 &LocalReturnLength);
2101 }
2102 if (NT_ERROR(Status))
2103 {
2104 /* Allow status that would mean it's not implemented in the storage stack */
2107 {
2109 }
2110
2111 /* In such case, zero output */
2112 LocalReturnLength = FIELD_OFFSET(FILE_NAME_INFORMATION, FileName);
2113 LocalFileInfo->FileNameLength = 0;
2114 LocalFileInfo->FileName[0] = OBJ_NAME_PATH_SEPARATOR;
2115 }
2116 else
2117 {
2118 /* We'll at least return the name length */
2119 if (LocalReturnLength < FIELD_OFFSET(FILE_NAME_INFORMATION, FileName))
2120 {
2121 LocalReturnLength = FIELD_OFFSET(FILE_NAME_INFORMATION, FileName);
2122 }
2123 }
2124
2125 /* If the provided buffer is too small, return the required size */
2126 if (LengthMismatch)
2127 {
2128 /* Add the required length */
2129 *ReturnLength += LocalFileInfo->FileNameLength;
2130
2131 /* Free the allocated buffer and return failure */
2134 }
2135
2136 /* Now calculate the new lengths left */
2137 FileLength = LocalReturnLength -
2139 LocalReturnLength = (ULONG)((ULONG_PTR)p -
2140 (ULONG_PTR)ObjectNameInfo +
2141 LocalFileInfo->FileNameLength);
2142
2143 /* Don't copy the name if it's not valid */
2144 if (LocalFileInfo->FileName[0] != OBJ_NAME_PATH_SEPARATOR)
2145 {
2146 /* Free the allocated buffer and return failure */
2149 }
2150
2151 /* Write the Name and null-terminate it */
2152 RtlCopyMemory(p, LocalFileInfo->FileName, FileLength);
2153 p += (FileLength / sizeof(WCHAR));
2154 *p = UNICODE_NULL;
2155 LocalReturnLength += sizeof(UNICODE_NULL);
2156
2157 /* Return the length needed */
2158 *ReturnLength = LocalReturnLength;
2159
2160 /* Setup the length and maximum length */
2161 FileLength = (ULONG)((ULONG_PTR)p - (ULONG_PTR)ObjectNameInfo);
2162 ObjectNameInfo->Name.Length = (USHORT)FileLength -
2164 ObjectNameInfo->Name.MaximumLength = (USHORT)ObjectNameInfo->Name.Length +
2165 sizeof(UNICODE_NULL);
2166 }
2168 {
2169 /* Free buffer and return */
2170 ExFreePoolWithTag(LocalInfo, TAG_IO);
2171 } _SEH2_END;
2172
2173 return Status;
2174}
#define OBJ_NAME_PATH_SEPARATOR
Definition: arcname_tests.c:25
#define _SEH2_FINALLY
Definition: filesup.c:21
#define _SEH2_LEAVE
Definition: filesup.c:20
@ FileNameInformation
Definition: from_kernel.h:70
struct _FILE_NAME_INFORMATION * PFILE_NAME_INFORMATION
_Out_ PNDIS_HANDLE _Out_ PUINT FileLength
Definition: ndis.h:3228
NTSTATUS NTAPI IopGetFileInformation(IN PFILE_OBJECT FileObject, IN ULONG Length, IN FILE_INFORMATION_CLASS FileInfoClass, OUT PVOID Buffer, OUT PULONG ReturnedLength)
Definition: iofunc.c:777
NTSTATUS NTAPI IoVolumeDeviceToDosName(IN PVOID VolumeDeviceObject, OUT PUNICODE_STRING DosName)
Definition: volume.c:1279
#define STATUS_OBJECT_PATH_INVALID
Definition: ntstatus.h:293
#define STATUS_INVALID_INFO_CLASS
Definition: ntstatus.h:240
#define FILE_DEVICE_NETWORK_FILE_SYSTEM
Definition: winioctl.h:126
UNICODE_STRING Name
Definition: nt_native.h:1270
void * PVOID
Definition: typedefs.h:50
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138

Referenced by IopQueryName(), and IoQueryFileDosDeviceName().

◆ IopQueueDeviceChangeEvent()

NTSTATUS IopQueueDeviceChangeEvent ( _In_ const GUID EventGuid,
_In_ const GUID InterfaceClassGuid,
_In_ PUNICODE_STRING  SymbolicLinkName 
)

Definition at line 52 of file plugplay.c.

56{
57 PPNP_EVENT_ENTRY EventEntry;
59 ULONG TotalSize;
60
61 /* Allocate a big enough buffer */
62 Copy.Length = 0;
63 Copy.MaximumLength = SymbolicLinkName->Length + sizeof(UNICODE_NULL);
64 TotalSize =
66 Copy.MaximumLength;
67
68 EventEntry = ExAllocatePool(NonPagedPool,
69 TotalSize + FIELD_OFFSET(PNP_EVENT_ENTRY, Event));
70 if (!EventEntry)
72 RtlZeroMemory(EventEntry, TotalSize + FIELD_OFFSET(PNP_EVENT_ENTRY, Event));
73
74 /* Fill the buffer with the event GUID */
75 RtlCopyMemory(&EventEntry->Event.EventGuid, EventGuid, sizeof(GUID));
77 EventEntry->Event.TotalSize = TotalSize;
78
79 /* Fill the interface class GUID */
80 RtlCopyMemory(&EventEntry->Event.DeviceClass.ClassGuid, InterfaceClassGuid, sizeof(GUID));
81
82 /* Fill the symbolic link name */
83 RtlCopyMemory(&EventEntry->Event.DeviceClass.SymbolicLinkName,
84 SymbolicLinkName->Buffer, SymbolicLinkName->Length);
85 EventEntry->Event.DeviceClass.SymbolicLinkName[SymbolicLinkName->Length / sizeof(WCHAR)] = UNICODE_NULL;
86
88 &EventEntry->ListEntry);
90 0,
91 FALSE);
92
93 return STATUS_SUCCESS;
94}
VOID Copy(PVOID Src, PVOID Dst, ULONG NumBytes)
Definition: mmixer.c:126
_Must_inspect_result_ _In_ WDFDEVICE _In_ REFGUID EventGuid
@ DeviceClassChangeEvent
Definition: cmtypes.h:258
WCHAR SymbolicLinkName[ANYSIZE_ARRAY]
Definition: cmtypes.h:416
PLUGPLAY_EVENT_CATEGORY EventCategory
Definition: cmtypes.h:406
struct _PLUGPLAY_EVENT_BLOCK::@2393::@2395 DeviceClass
Definition: plugplay.c:16
LIST_ENTRY ListEntry
Definition: plugplay.c:17
PLUGPLAY_EVENT_BLOCK Event
Definition: plugplay.c:18
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING SymbolicLinkName
Definition: wdfdevice.h:3739
_In_ CONST GUID * InterfaceClassGuid
Definition: iofuncs.h:1136

Referenced by IoSetDeviceInterfaceState().

◆ IopQueueDeviceInstallEvent()

NTSTATUS IopQueueDeviceInstallEvent ( _In_ const GUID Guid,
_In_ PUNICODE_STRING  DeviceId 
)

Definition at line 97 of file plugplay.c.

100{
101 PPNP_EVENT_ENTRY EventEntry;
103 ULONG TotalSize;
104
105 /* Allocate a big enough buffer */
106 Copy.Length = 0;
107 Copy.MaximumLength = DeviceId->Length + sizeof(UNICODE_NULL);
108 TotalSize =
110 Copy.MaximumLength;
111
112 EventEntry = ExAllocatePool(NonPagedPool,
113 TotalSize + FIELD_OFFSET(PNP_EVENT_ENTRY, Event));
114 if (!EventEntry)
116 RtlZeroMemory(EventEntry, TotalSize + FIELD_OFFSET(PNP_EVENT_ENTRY, Event));
117
118 /* Fill the buffer with the event GUID */
119 RtlCopyMemory(&EventEntry->Event.EventGuid, EventGuid, sizeof(GUID));
121 EventEntry->Event.TotalSize = TotalSize;
122
123 /* Fill the symbolic link name */
124 RtlCopyMemory(&EventEntry->Event.InstallDevice.DeviceId,
125 DeviceId->Buffer, DeviceId->Length);
126 EventEntry->Event.InstallDevice.DeviceId[DeviceId->Length / sizeof(WCHAR)] = UNICODE_NULL;
127
129
131
132 return STATUS_SUCCESS;
133}
static BOOL InstallDevice(PCWSTR DeviceInstance, BOOL ShowWizard)
Definition: install.c:55
@ DeviceInstallEvent
Definition: cmtypes.h:260
struct _PLUGPLAY_EVENT_BLOCK::@2393::@2397 InstallDevice

Referenced by PiControlInitializeDevice(), and PiInitializeDevNode().

◆ IopQueueTargetDeviceEvent()

NTSTATUS IopQueueTargetDeviceEvent ( _In_ const GUID Guid,
_In_ PUNICODE_STRING  DeviceIds 
)

◆ 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().

◆ IopReassignSystemRoot()

NTSTATUS NTAPI IopReassignSystemRoot ( IN PLOADER_PARAMETER_BLOCK  LoaderBlock,
OUT PANSI_STRING  NtBootPath 
)

Definition at line 840 of file arcname.c.

842{
845 CHAR Buffer[256], AnsiBuffer[256];
846 WCHAR ArcNameBuffer[64];
847 ANSI_STRING TargetString, ArcString, TempString;
848 UNICODE_STRING LinkName, TargetName, ArcName;
849 HANDLE LinkHandle;
850
851 /* Create the Unicode name for the current ARC boot device */
852 sprintf(Buffer, "\\ArcName\\%s", LoaderBlock->ArcBootDeviceName);
855 if (!NT_SUCCESS(Status)) return FALSE;
856
857 /* Initialize the attributes and open the link */
859 &TargetName,
861 NULL,
862 NULL);
863 Status = NtOpenSymbolicLinkObject(&LinkHandle,
866 if (!NT_SUCCESS(Status))
867 {
868 /* We failed, free the string */
870 return FALSE;
871 }
872
873 /* Query the current \\SystemRoot */
874 ArcName.Buffer = ArcNameBuffer;
875 ArcName.Length = 0;
876 ArcName.MaximumLength = sizeof(ArcNameBuffer);
877 Status = NtQuerySymbolicLinkObject(LinkHandle, &ArcName, NULL);
878 if (!NT_SUCCESS(Status))
879 {
880 /* We failed, free the string */
882 return FALSE;
883 }
884
885 /* Convert it to Ansi */
886 ArcString.Buffer = AnsiBuffer;
887 ArcString.Length = 0;
888 ArcString.MaximumLength = sizeof(AnsiBuffer);
889 Status = RtlUnicodeStringToAnsiString(&ArcString, &ArcName, FALSE);
890 AnsiBuffer[ArcString.Length] = ANSI_NULL;
891
892 /* Close the link handle and free the name */
893 ObCloseHandle(LinkHandle, KernelMode);
895
896 /* Setup the system root name again */
897 RtlInitAnsiString(&TempString, "\\SystemRoot");
898 Status = RtlAnsiStringToUnicodeString(&LinkName, &TempString, TRUE);
899 if (!NT_SUCCESS(Status)) return FALSE;
900
901 /* Open the symbolic link for it */
903 &LinkName,
905 NULL,
906 NULL);
907 Status = NtOpenSymbolicLinkObject(&LinkHandle,
910 if (!NT_SUCCESS(Status)) return FALSE;
911
912 /* Destroy it */
913 NtMakeTemporaryObject(LinkHandle);
914 ObCloseHandle(LinkHandle, KernelMode);
915
916 /* Now create the new name for it */
917 sprintf(Buffer, "%s%s", ArcString.Buffer, LoaderBlock->NtBootPathName);
918
919 /* Copy it into the passed parameter and null-terminate it */
920 RtlCopyString(NtBootPath, &ArcString);
922
923 /* Setup the Unicode-name for the new symbolic link value */
926 &LinkName,
928 NULL,
929 NULL);
931 if (!NT_SUCCESS(Status)) return FALSE;
932
933 /* Create it */
937 &ArcName);
938
939 /* Free all the strings and close the handle and return success */
940 RtlFreeUnicodeString(&ArcName);
941 RtlFreeUnicodeString(&LinkName);
942 ObCloseHandle(LinkHandle, KernelMode);
943 return TRUE;
944}
CHAR AnsiBuffer[1024]
Definition: debug.c:15
_In_z_ PCHAR TargetString
Definition: cdrom.h:954
#define SYMBOLIC_LINK_ALL_ACCESS
Definition: nt_native.h:1267
NTSYSAPI VOID NTAPI RtlCopyString(PSTRING DestinationString, PSTRING SourceString)
NTSTATUS NTAPI NtMakeTemporaryObject(IN HANDLE ObjectHandle)
Definition: oblife.c:1473
static PCWSTR TargetName
Definition: ping.c:67

Referenced by IoInitSystem().

◆ IopReferenceDeviceObject()

NTSTATUS NTAPI IopReferenceDeviceObject ( IN PDEVICE_OBJECT  DeviceObject)

◆ IopReinitializeBootDrivers()

VOID NTAPI IopReinitializeBootDrivers ( VOID  )

Definition at line 1532 of file driver.c.

1533{
1534 PDRIVER_REINIT_ITEM ReinitItem;
1536
1537 /* Get the first entry and start looping */
1540 while (Entry)
1541 {
1542 /* Get the item */
1543 ReinitItem = CONTAINING_RECORD(Entry, DRIVER_REINIT_ITEM, ItemEntry);
1544
1545 /* Increment reinitialization counter */
1546 ReinitItem->DriverObject->DriverExtension->Count++;
1547
1548 /* Remove the device object flag */
1549 ReinitItem->DriverObject->Flags &= ~DRVO_BOOTREINIT_REGISTERED;
1550
1551 /* Call the routine */
1552 ReinitItem->ReinitRoutine(ReinitItem->DriverObject,
1553 ReinitItem->Context,
1554 ReinitItem->DriverObject->
1555 DriverExtension->Count);
1556
1557 /* Free the entry */
1559
1560 /* Move to the next one */
1563 }
1564
1565 /* Wait for all device actions being finished*/
1567}
PLIST_ENTRY NTAPI ExInterlockedRemoveHeadList(IN OUT PLIST_ENTRY ListHead, IN OUT PKSPIN_LOCK Lock)
Definition: interlocked.c:166
KEVENT PiEnumerationFinished
Definition: devaction.c:50
KSPIN_LOCK DriverBootReinitListLock
Definition: driver.c:28
LIST_ENTRY DriverBootReinitListHead
Definition: driver.c:27
base of all file and directory entries
Definition: entries.h:83
PDRIVER_OBJECT DriverObject
Definition: io.h:449
PDRIVER_REINITIALIZE ReinitRoutine
Definition: io.h:450
PVOID Context
Definition: io.h:451

Referenced by IoInitSystem().

◆ IopReinitializeDrivers()

VOID NTAPI IopReinitializeDrivers ( VOID  )

Definition at line 1496 of file driver.c.

1497{
1498 PDRIVER_REINIT_ITEM ReinitItem;
1500
1501 /* Get the first entry and start looping */
1504 while (Entry)
1505 {
1506 /* Get the item */
1507 ReinitItem = CONTAINING_RECORD(Entry, DRIVER_REINIT_ITEM, ItemEntry);
1508
1509 /* Increment reinitialization counter */
1510 ReinitItem->DriverObject->DriverExtension->Count++;
1511
1512 /* Remove the device object flag */
1513 ReinitItem->DriverObject->Flags &= ~DRVO_REINIT_REGISTERED;
1514
1515 /* Call the routine */
1516 ReinitItem->ReinitRoutine(ReinitItem->DriverObject,
1517 ReinitItem->Context,
1518 ReinitItem->DriverObject->
1519 DriverExtension->Count);
1520
1521 /* Free the entry */
1523
1524 /* Move to the next one */
1527 }
1528}
LIST_ENTRY DriverReinitListHead
Definition: driver.c:22
KSPIN_LOCK DriverReinitListLock
Definition: driver.c:23

Referenced by IoInitSystem(), and IopInitializeDriverModule().

◆ IopRemoveTimerFromTimerList()

VOID NTAPI IopRemoveTimerFromTimerList ( IN PIO_TIMER  Timer)

Definition at line 70 of file iotimer.c.

71{
73
74 /* Lock Timers */
76
77 /* Remove Timer from the List and Drop the Timer Count if Enabled */
78 RemoveEntryList(&Timer->IoTimerList);
79 if (Timer->TimerEnabled) IopTimerCount--;
80
81 /* Unlock the Timers */
83}
#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
KSPIN_LOCK IopTimerLock
Definition: iotimer.c:18
ULONG IopTimerCount
Definition: iotimer.c:26

Referenced by IoDeleteDevice().

◆ IopSaveBootLogToFile()

VOID IopSaveBootLogToFile ( VOID  )

Definition at line 288 of file bootlog.c.

289{
291 WCHAR ValueNameBuffer[8];
298 ULONG i;
300
301 if (IopBootLogCreate == FALSE)
302 return;
303
304 DPRINT("IopSaveBootLogToFile() called\n");
305
307
309 if (!NT_SUCCESS(Status))
310 {
311 DPRINT1("IopCreateLogFile() failed (Status %lx)\n", Status);
313 return;
314 }
315
316 //Status = IopWriteLogFile(L"ReactOS "KERNEL_VERSION_STR);
317
318 if (!NT_SUCCESS(Status))
319 {
320 DPRINT1("IopWriteLogFile() failed (Status %lx)\n", Status);
322 return;
323 }
324
326 if (!NT_SUCCESS(Status))
327 {
328 DPRINT1("IopWriteLogFile() failed (Status %lx)\n", Status);
330 return;
331 }
332
333
334 BufferSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 256 * sizeof(WCHAR);
335 KeyInfo = ExAllocatePool(PagedPool,
336 BufferSize);
337 if (KeyInfo == NULL)
338 {
340 return;
341 }
342
344 L"\\Registry\\Machine\\System\\CurrentControlSet\\BootLog");
346 &KeyName,
348 NULL,
349 NULL);
350 Status = ZwOpenKey(&KeyHandle,
353 if (!NT_SUCCESS(Status))
354 {
355 ExFreePool(KeyInfo);
357 return;
358 }
359
360 for (i = 0; ; i++)
361 {
362 swprintf(ValueNameBuffer,
363 L"%lu", i);
364
366 ValueNameBuffer);
367
368 Status = ZwQueryValueKey(KeyHandle,
369 &ValueName,
371 KeyInfo,
373 &ResultLength);
375 {
376 break;
377 }
378
379 if (!NT_SUCCESS(Status))
380 {
382 ExFreePool(KeyInfo);
384 return;
385 }
386
387 Status = IopWriteLogFile((PWSTR)&KeyInfo->Data);
388 if (!NT_SUCCESS(Status))
389 {
391 ExFreePool(KeyInfo);
393 return;
394 }
395
396 /* Delete keys */
398 &ValueName);
399 }
400
402
403 ExFreePool(KeyInfo);
404
407
408 DPRINT("IopSaveBootLogToFile() done\n");
409}
static NTSTATUS IopCreateLogFile(VOID)
Definition: bootlog.c:225
static NTSTATUS IopWriteLogFile(PWSTR LogText)
Definition: bootlog.c:146
static ERESOURCE IopBootLogResource
Definition: bootlog.c:22
static BOOLEAN IopLogFileEnabled
Definition: bootlog.c:20
static BOOLEAN IopBootLogCreate
Definition: bootlog.c:18
#define BufferSize
Definition: mmc.h:75
#define swprintf
Definition: precomp.h:40
NTSYSAPI NTSTATUS NTAPI ZwDeleteValueKey(__in IN HANDLE Key, __in IN PUNICODE_STRING ValueName)
struct _KEY_VALUE_PARTIAL_INFORMATION KEY_VALUE_PARTIAL_INFORMATION
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3776
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

◆ IopShutdownBaseFileSystems()

VOID NTAPI IopShutdownBaseFileSystems ( IN PLIST_ENTRY  ListHead)

Definition at line 349 of file volume.c.

350{
351 PLIST_ENTRY ListEntry;
353 IO_STATUS_BLOCK StatusBlock;
354 PIRP Irp;
357
359
360 /* Get the first entry and start looping */
361 ListEntry = ListHead->Flink;
362 while (ListEntry != ListHead)
363 {
364 /* Get the device object */
367 Queue.ListEntry);
368
369 /* Go to the next entry */
370 ListEntry = ListEntry->Flink;
371
372 /* Get the attached device */
374
377
378 /* Build the shutdown IRP and call the driver */
381 NULL,
382 0,
383 NULL,
384 &Event,
385 &StatusBlock);
386 if (Irp)
387 {
389 if (Status == STATUS_PENDING)
390 {
391 /* Wait on the driver */
393 }
394 }
395
396 /* Reset the event */
398
401 }
402}
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
VOID NTAPI IopDecrementDeviceObjectRef(IN PDEVICE_OBJECT DeviceObject, IN BOOLEAN UnloadIfUnused)
Definition: volume.c:33
#define IRP_MJ_SHUTDOWN

Referenced by IoShutdownSystem().

◆ IopStartBootLog()

VOID IopStartBootLog ( VOID  )

Definition at line 38 of file bootlog.c.

39{
42}
static BOOLEAN IopBootLogEnabled
Definition: bootlog.c:19

Referenced by IopInitBootLog().

◆ IopStartRamdisk()

NTSTATUS NTAPI IopStartRamdisk ( IN PLOADER_PARAMETER_BLOCK  LoaderBlock)

Definition at line 26 of file ramdisk.c.

27{
30 PCHAR CommandLine, Offset, OffsetValue, Length, LengthValue;
32 RAMDISK_CREATE_INPUT RamdiskCreate;
35 PLIST_ENTRY ListHead, NextEntry;
38
39 //
40 // Scan memory descriptors
41 //
43 ListHead = &LoaderBlock->MemoryDescriptorListHead;
44 NextEntry = ListHead->Flink;
45 while (NextEntry != ListHead)
46 {
47 //
48 // Get the descriptor
49 //
52 ListEntry);
53
54 //
55 // Needs to be a ROM/RAM descriptor
56 //
57 if (MemoryDescriptor->MemoryType == LoaderXIPRom) break;
58
59 //
60 // Keep trying
61 //
62 NextEntry = NextEntry->Flink;
63 }
64
65 //
66 // Nothing found?
67 //
68 if (NextEntry == ListHead)
69 {
70 //
71 // Bugcheck -- no data
72 //
73 KeBugCheckEx(RAMDISK_BOOT_INITIALIZATION_FAILED,
76 0,
77 0);
78 }
79
80 //
81 // Setup the input buffer
82 //
83 RtlZeroMemory(&RamdiskCreate, sizeof(RamdiskCreate));
84 RamdiskCreate.Version = sizeof(RamdiskCreate);
85 RamdiskCreate.DiskType = RAMDISK_BOOT_DISK;
86 RamdiskCreate.BasePage = MemoryDescriptor->BasePage;
87 RamdiskCreate.DiskOffset = 0;
88 RamdiskCreate.DiskLength.QuadPart = MemoryDescriptor->PageCount << PAGE_SHIFT;
89 RamdiskCreate.DiskGuid = RAMDISK_BOOTDISK_GUID;
90 RamdiskCreate.DriveLetter = L'C';
91 RamdiskCreate.Options.Fixed = TRUE;
92
93 //
94 // Check for commandline parameters
95 //
96 CommandLine = LoaderBlock->LoadOptions;
97 if (CommandLine)
98 {
99 //
100 // Make everything upper case
101 //
102 _strupr(CommandLine);
103
104 //
105 // Check for offset parameter
106 //
107 Offset = strstr(CommandLine, "RDIMAGEOFFSET");
108 if (Offset)
109 {
110 //
111 // Get to the actual value
112 //
113 OffsetValue = strstr(Offset, "=");
114 if (OffsetValue)
115 {
116 //
117 // Set the offset
118 //
119 RamdiskCreate.DiskOffset = atol(OffsetValue + 1);
120 }
121 }
122
123 //
124 // Reduce the disk length
125 //
126 RamdiskCreate.DiskLength.QuadPart -= RamdiskCreate.DiskOffset;
127
128 //
129 // Check for length parameter
130 //
131 Length = strstr(CommandLine, "RDIMAGELENGTH");
132 if (Length)
133 {
134 //
135 // Get to the actual value
136 //
137 LengthValue = strstr(Length, "=");
138 if (LengthValue)
139 {
140 //
141 // Set the offset
142 //
143 RamdiskCreate.DiskLength.QuadPart = _atoi64(LengthValue + 1);
144 }
145 }
146 }
147
148 //
149 // Setup object attributes
150 //
151 RtlInitUnicodeString(&ObjectName, L"\\Device\\Ramdisk");
153 &ObjectName,
155 NULL,
156 NULL);
157
158 //
159 // Open a handle to the driver
160 //
168 {
169 //
170 // Bugcheck -- no driver
171 //
172 KeBugCheckEx(RAMDISK_BOOT_INITIALIZATION_FAILED,
175 0,
176 0);
177 }
178
179 //
180 // Send create command
181 //
183 NULL,
184 NULL,
185 NULL,
188 &RamdiskCreate,
189 sizeof(RamdiskCreate),
190 NULL,
191 0);
194 {
195 //
196 // Bugcheck -- driver failed
197 //
198 KeBugCheckEx(RAMDISK_BOOT_INITIALIZATION_FAILED,
201 0,
202 0);
203 }
204
205 //
206 // Convert the GUID
207 //
208 Status = RtlStringFromGUID(&RamdiskCreate.DiskGuid, &GuidString);
209 if (!NT_SUCCESS(Status))
210 {
211 //
212 // Bugcheck -- GUID convert failed
213 //
214 KeBugCheckEx(RAMDISK_BOOT_INITIALIZATION_FAILED,
216 Status,
217 0,
218 0);
219 }
220
221 //
222 // Build the symbolic link name and target
223 //
225 sizeof(SourceString)/sizeof(WCHAR),
226 L"\\Device\\Ramdisk%wZ",
227 &GuidString);
228 SymbolicLinkName.Length = 38;
229 SymbolicLinkName.MaximumLength = 38 + sizeof(UNICODE_NULL);
230 SymbolicLinkName.Buffer = L"\\ArcName\\ramdisk(0)";
231
232 //
233 // Create the symbolic link
234 //
235 RtlInitUnicodeString(&DeviceString, SourceString);
238 if (!NT_SUCCESS(Status))
239 {
240 //
241 // Bugcheck -- symlink create failed
242 //
243 KeBugCheckEx(RAMDISK_BOOT_INITIALIZATION_FAILED,
245 Status,
246 0,
247 0);
248 }
249
250 //
251 // ReactOS hack (drive letter should not be hardcoded, and maybe set by mountmgr.sys)
252 //
253 {
254 ANSI_STRING AnsiPath;
255 CHAR Buffer[256];
257 UNICODE_STRING DriveLetter = RTL_CONSTANT_STRING(L"\\??\\X:");
258
259 AnsiPath.Length = sprintf(Buffer, "X:%s", LoaderBlock->NtBootPathName);
260 AnsiPath.MaximumLength = AnsiPath.Length + 1;
261 AnsiPath.Buffer = Buffer;
262 RtlInitEmptyUnicodeString(&NtSystemRoot,
263 SharedUserData->NtSystemRoot,
264 sizeof(SharedUserData->NtSystemRoot));
266 if (!NT_SUCCESS(Status))
267 {
268 KeBugCheckEx(RAMDISK_BOOT_INITIALIZATION_FAILED,
270 Status,
271 0,
272 0);
273 }
274 IoCreateSymbolicLink(&DriveLetter, &DeviceString);
275 }
276
277 //
278 // Wait for ramdisk relations being initialized
279 //
280
282
283 //
284 // We made it
285 //
286 return STATUS_SUCCESS;
287}
static NDIS_HANDLE DriverHandle
__int64 CDECL _atoi64(const char *nptr)
Definition: atoi64.c:18
#define FILE_SHARE_READ
Definition: compat.h:136
#define PAGE_SHIFT
Definition: env_spec_w32.h:45
_Check_return_ long __cdecl atol(_In_z_ const char *_Str)
NTSYSAPI NTSTATUS WINAPI RtlStringFromGUID(REFGUID, PUNICODE_STRING)
int _snwprintf(wchar_t *buffer, size_t count, const wchar_t *format,...)
static PWSTR GuidString
Definition: apphelp.c:93
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)
_Out_ _Inout_ POEM_STRING _In_ PCUNICODE_STRING SourceString
Definition: rtlfuncs.h:1910
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define GENERIC_ALL
Definition: nt_native.h:92
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define RAMDISK_BOOT_DISK
Definition: ntddrdsk.h:52
#define FSCTL_CREATE_RAM_DISK
Definition: ntddrdsk.h:45
NTSYSAPI NTSTATUS NTAPI ZwDeviceIoControlFile(IN HANDLE DeviceHandle, IN HANDLE Event OPTIONAL, IN PIO_APC_ROUTINE UserApcRoutine OPTIONAL, IN PVOID UserApcContext OPTIONAL, OUT PIO_STATUS_BLOCK IoStatusBlock, IN ULONG IoControlCode, IN PVOID InputBuffer, IN ULONG InputBufferSize, OUT PVOID OutputBuffer, IN ULONG OutputBufferSize)
#define RD_NO_RAMDISK_DRIVER
Definition: io.h:70
#define RD_NO_XIPROM_DESCRIPTOR
Definition: io.h:66
#define RD_SYSROOT_INIT_FAILED
Definition: io.h:86
#define RD_FSCTL_FAILED
Definition: io.h:74
#define RD_GUID_CONVERT_FAILED
Definition: io.h:78
#define RD_SYMLINK_CREATE_FAILED
Definition: io.h:82
KEVENT PiEnumerationFinished
Definition: devaction.c:50
_CRTIMP char *__cdecl _strupr(_Inout_z_ char *_String)
@ LoaderXIPRom
Definition: arc.h:199
#define SharedUserData
RAMDISK_CREATE_OPTIONS Options
Definition: ntddrdsk.h:76
LARGE_INTEGER DiskLength
Definition: ntddrdsk.h:77
ULONG_PTR BasePage
Definition: ntddrdsk.h:89
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _In_ PWDF_USB_CONTROL_SETUP_PACKET _In_opt_ PWDF_MEMORY_DESCRIPTOR MemoryDescriptor
Definition: wdfusb.h:1339
_In_ PVOID _Out_opt_ PULONG_PTR _Outptr_opt_ PCUNICODE_STRING * ObjectName
Definition: cmfuncs.h:64

Referenced by IoInitSystem().

◆ IopStopBootLog()

VOID IopStopBootLog ( VOID  )

Definition at line 46 of file bootlog.c.

47{
49}

◆ IopStoreSystemPartitionInformation()

VOID IopStoreSystemPartitionInformation ( _In_ PUNICODE_STRING  NtSystemPartitionDeviceName,
_In_ PUNICODE_STRING  OsLoaderPathName 
)

Definition at line 860 of file iorsrce.c.

863{
867 HANDLE LinkHandle, RegistryHandle, KeyHandle;
868 WCHAR LinkTargetBuffer[256];
869 UNICODE_STRING CmRegistryMachineSystemName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SYSTEM");
870
871 ASSERT(NtSystemPartitionDeviceName->MaximumLength >= NtSystemPartitionDeviceName->Length + sizeof(WCHAR));
872 ASSERT(NtSystemPartitionDeviceName->Buffer[NtSystemPartitionDeviceName->Length / sizeof(WCHAR)] == UNICODE_NULL);
873 ASSERT(OsLoaderPathName->MaximumLength >= OsLoaderPathName->Length + sizeof(WCHAR));
874 ASSERT(OsLoaderPathName->Buffer[OsLoaderPathName->Length / sizeof(WCHAR)] == UNICODE_NULL);
875
876 /* First define needed stuff to open NtSystemPartitionDeviceName symbolic link */
878 NtSystemPartitionDeviceName,
880 NULL,
881 NULL);
882
883 /* Open NtSystemPartitionDeviceName symbolic link */
884 Status = ZwOpenSymbolicLinkObject(&LinkHandle,
887 if (!NT_SUCCESS(Status))
888 {
889 DPRINT("Failed to open symlink %wZ, Status=%lx\n", NtSystemPartitionDeviceName, Status);
890 return;
891 }
892
893 /* Prepare the string that will receive where symbolic link points to.
894 * We will zero the end of the string after having received it */
895 RtlInitEmptyUnicodeString(&LinkTarget, LinkTargetBuffer,
896 sizeof(LinkTargetBuffer) - sizeof(UNICODE_NULL));
897
898 /* Query target */
899 Status = ZwQuerySymbolicLinkObject(LinkHandle, &LinkTarget, NULL);
900
901 /* We are done with symbolic link */
902 ObCloseHandle(LinkHandle, KernelMode);
903
904 if (!NT_SUCCESS(Status))
905 {
906 DPRINT("Failed querying symlink %wZ, Status=%lx\n", NtSystemPartitionDeviceName, Status);
907 return;
908 }
909
910 /* As promised, we zero the end */
912
913 /* Open registry to save data (HKLM\SYSTEM) */
914 Status = IopOpenRegistryKeyEx(&RegistryHandle,
915 NULL,
916 &CmRegistryMachineSystemName,
918 if (!NT_SUCCESS(Status))
919 {
920 DPRINT("Failed to open HKLM\\SYSTEM, Status=%lx\n", Status);
921 return;
922 }
923
924 /* Open or create the Setup subkey where we'll store in */
926
928 RegistryHandle,
929 &KeyName,
932 NULL);
933
934 /* We're done with HKLM\SYSTEM */
935 ObCloseHandle(RegistryHandle, KernelMode);
936
937 if (!NT_SUCCESS(Status))
938 {
939 DPRINT("Failed opening/creating Setup key, Status=%lx\n", Status);
940 return;
941 }
942
943 /* Prepare first data writing */
944 RtlInitUnicodeString(&KeyName, L"SystemPartition");
945
946 /* Write SystemPartition value which is the target of the symbolic link */
947 Status = ZwSetValueKey(KeyHandle,
948 &KeyName,
949 0,
950 REG_SZ,
952 LinkTarget.Length + sizeof(WCHAR));
953 if (!NT_SUCCESS(Status))
954 {
955 DPRINT("Failed writing SystemPartition value, Status=%lx\n", Status);
956 }
957
958 /* Prepare for second data writing */
959 RtlInitUnicodeString(&KeyName, L"OsLoaderPath");
960
961 /* Remove trailing slash if any (one slash only excepted) */
962 if (OsLoaderPathName->Length > sizeof(WCHAR) &&
963 OsLoaderPathName->Buffer[(OsLoaderPathName->Length / sizeof(WCHAR)) - 1] == OBJ_NAME_PATH_SEPARATOR)
964 {
965 OsLoaderPathName->Length -= sizeof(WCHAR);
966 OsLoaderPathName->Buffer[OsLoaderPathName->Length / sizeof(WCHAR)] = UNICODE_NULL;
967 }
968
969 /* Then, write down data */
970 Status = ZwSetValueKey(KeyHandle,
971 &KeyName,
972 0,
973 REG_SZ,
974 OsLoaderPathName->Buffer,
975 OsLoaderPathName->Length + sizeof(UNICODE_NULL));
976 if (!NT_SUCCESS(Status))
977 {
978 DPRINT("Failed writing OsLoaderPath value, Status=%lx\n", Status);
979 }
980
981 /* We're finally done! */
983}
NTSYSAPI NTSTATUS NTAPI ZwOpenSymbolicLinkObject(_Out_ PHANDLE SymbolicLinkHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
#define SYMBOLIC_LINK_QUERY
Definition: nt_native.h:1265
_Inout_ PUNICODE_STRING LinkTarget
Definition: zwfuncs.h:292

Referenced by IopCreateArcNames(), and IopCreateArcNamesDisk().

◆ IopSynchronousCall()

NTSTATUS IopSynchronousCall ( IN PDEVICE_OBJECT  DeviceObject,
IN PIO_STACK_LOCATION  IoStackLocation,
OUT PVOID Information 
)

◆ IopTraverseDeviceTree()

◆ 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 IopEditDeviceList(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT DeviceObject, IN IOP_DEVICE_LIST_OPERATION Type)
Definition: device.c:334
VOID NTAPI ObDereferenceSecurityDescriptor(IN PSECURITY_DESCRIPTOR SecurityDescriptor, IN ULONG Count)
Definition: obsdcach.c:287
#define DRVO_UNLOAD_INVOKED
Definition: iotypes.h:2225

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

◆ IopUpdateRootKey()

NTSTATUS NTAPI IopUpdateRootKey ( VOID  )

Definition at line 670 of file pnpmap.c.

671{
672 UNICODE_STRING EnumU = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Enum");
673 UNICODE_STRING RootPathU = RTL_CONSTANT_STRING(L"Root");
674 UNICODE_STRING MultiKeyPathU = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\HARDWARE\\DESCRIPTION\\System\\MultifunctionAdapter");
676 HANDLE hEnum, hRoot;
678
681 if (!NT_SUCCESS(Status))
682 {
683 DPRINT1("ZwCreateKey() failed with status 0x%08lx\n", Status);
684 return Status;
685 }
686
689 ZwClose(hEnum);
690 if (!NT_SUCCESS(Status))
691 {
692 DPRINT1("ZwOpenKey() failed with status 0x%08lx\n", Status);
693 return Status;
694 }
695
697 {
698 Status = IopOpenRegistryKeyEx(&hEnum, NULL, &MultiKeyPathU, KEY_ENUMERATE_SUB_KEYS);
699 if (!NT_SUCCESS(Status))
700 {
701 /* Nothing to do, don't return with an error status */
702 DPRINT("ZwOpenKey() failed with status 0x%08lx\n", Status);
703 ZwClose(hRoot);
704 return STATUS_SUCCESS;
705 }
707 hEnum,
708 NULL,
709 hRoot,
710 TRUE,
711 NULL,
712 0,
713 NULL,
714 0);
715 ZwClose(hEnum);
716 }
717 else
718 {
719 /* Enumeration is disabled */
721 }
722
723 ZwClose(hRoot);
724
725 return Status;
726}
static HTREEITEM hRoot
Definition: treeview.c:381
static NTSTATUS IopEnumerateDetectedDevices(_In_ HANDLE hBaseKey, _In_opt_ PUNICODE_STRING RelativePath, _In_ HANDLE hRootKey, _In_ BOOLEAN EnumerateSubKeys, _In_opt_ PCM_FULL_RESOURCE_DESCRIPTOR BootResources, _In_opt_ ULONG BootResourcesLength, _In_ PCM_FULL_RESOURCE_DESCRIPTOR ParentBootResources, _In_ ULONG ParentBootResourcesLength)
Definition: pnpmap.c:153
static BOOLEAN IopIsFirmwareMapperDisabled(VOID)
Definition: pnpmap.c:600

Referenced by IopInitializePlugPlayServices().

◆ 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}
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
_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().

◆ IopVerifyDiskSignature()

BOOLEAN NTAPI IopVerifyDiskSignature ( IN PDRIVE_LAYOUT_INFORMATION_EX  DriveLayout,
IN PARC_DISK_SIGNATURE  ArcDiskSignature,
OUT PULONG  Signature 
)

Definition at line 948 of file arcname.c.

951{
952 /* First condition: having a valid partition table */
953 if (!ArcDiskSignature->ValidPartitionTable)
954 {
955 return FALSE;
956 }
957
958 /* If that partition table is the MBR */
959 if (DriveLayout->PartitionStyle == PARTITION_STYLE_MBR)
960 {
961 /* Then check MBR signature */
962 if (DriveLayout->Mbr.Signature == ArcDiskSignature->Signature)
963 {
964 /* And return it */
965 if (Signature)
966 {
967 *Signature = DriveLayout->Mbr.Signature;
968 }
969
970 return TRUE;
971 }
972 }
973 /* If that partition table is the GPT */
974 else if (DriveLayout->PartitionStyle == PARTITION_STYLE_GPT)
975 {
976 /* Check we are using GPT and compare GUID */
977 if (ArcDiskSignature->IsGpt &&
978 (((PULONG)ArcDiskSignature->GptSignature)[0] == DriveLayout->Gpt.DiskId.Data1 &&
979 ((PUSHORT)ArcDiskSignature->GptSignature)[2] == DriveLayout->Gpt.DiskId.Data2 &&
980 ((PUSHORT)ArcDiskSignature->GptSignature)[3] == DriveLayout->Gpt.DiskId.Data3 &&
981 ((PULONGLONG)ArcDiskSignature->GptSignature)[1] == ((PULONGLONG)DriveLayout->Gpt.DiskId.Data4)[0]))
982 {
983 /* There's no signature to give, so we just zero output */
984 if (Signature)
985 {
986 *Signature = 0;
987 }
988 return TRUE;
989 }
990 }
991
992 /* If we fall here, it means that something went wrong, so return that */
993 return FALSE;
994}
static const WCHAR Signature[]
Definition: parser.c:141
@ PARTITION_STYLE_GPT
Definition: imports.h:202
@ PARTITION_STYLE_MBR
Definition: imports.h:201
__GNU_EXTENSION typedef unsigned __int64 * PULONGLONG
Definition: ntbasedef.h:383
uint16_t * PUSHORT
Definition: typedefs.h:56

Referenced by IoGetBootDiskInformation(), and IopCreateArcNamesDisk().

◆ IoSetIoCompletion()

NTSTATUS NTAPI IoSetIoCompletion ( IN PVOID  IoCompletion,
IN PVOID  KeyContext,
IN PVOID  ApcContext,
IN NTSTATUS  IoStatus,
IN ULONG_PTR  IoStatusInformation,
IN BOOLEAN  Quota 
)

Definition at line 147 of file iocomp.c.

153{
156 PKPRCB Prcb = KeGetCurrentPrcb();
158
159 /* Get the P List */
161 PPLookasideList[LookasideCompletionList].P;
162
163 /* Try to allocate the Packet */
164 List->L.TotalAllocates++;
165 Packet = (PVOID)InterlockedPopEntrySList(&List->L.ListHead);
166
167 /* Check if that failed, use the L list if it did */
168 if (!Packet)
169 {
170 /* Let the balancer know */
171 List->L.AllocateMisses++;
172
173 /* Get L List */
175 PPLookasideList[LookasideCompletionList].L;
176
177 /* Try to allocate the Packet */
178 List->L.TotalAllocates++;
179 Packet = (PVOID)InterlockedPopEntrySList(&List->L.ListHead);
180 }
181
182 /* Still failed, use pool */
183 if (!Packet)
184 {
185 /* Let the balancer know */
186 List->L.AllocateMisses++;
187
188 /* Allocate from Nonpaged Pool */
190 }
191
192 /* Make sure we have one by now... */
193 if (Packet)
194 {
195 /* Set up the Packet */
196 Packet->PacketType = IopCompletionPacketMini;
197 Packet->KeyContext = KeyContext;
198 Packet->ApcContext = ApcContext;
199 Packet->IoStatus = IoStatus;
200 Packet->IoStatusInformation = IoStatusInformation;
201
202 /* Insert the Queue */
203 KeInsertQueue(Queue, &Packet->ListEntry);
204 }
205 else
206 {
207 /* Out of memory, fail */
209 }
210
211 /* Return Success */
212 return STATUS_SUCCESS;
213}
NTSTATUS NTAPI IoCompletion(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Ctx)
Definition: control.c:382
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1161
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE _In_opt_ PVOID ApcContext
Definition: iofuncs.h:727
@ LookasideCompletionList
Definition: mmtypes.h:174
#define IOC_TAG
Definition: tag.h:69
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
struct LOOKASIDE_ALIGN _NPAGED_LOOKASIDE_LIST * PNPAGED_LOOKASIDE_LIST
struct _KQUEUE * PKQUEUE
#define InterlockedPopEntrySList(SListHead)
Definition: rtlfuncs.h:3392

Referenced by IopDeviceFsIoControl(), NtLockFile(), and NtSetIoCompletion().

◆ 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}
VOID NTAPI IopShutdownBaseFileSystems(IN PLIST_ENTRY ListHead)
Definition: volume.c:349
LIST_ENTRY ShutdownListHead
Definition: device.c:21
KSPIN_LOCK ShutdownListLock
Definition: device.c:22
LIST_ENTRY IopCdRomFileSystemQueueHead
Definition: volume.c:22
ERESOURCE IopDatabaseResource
Definition: volume.c:20
VOID NTAPI IoShutdownPnpDevices(VOID)
Definition: device.c:125
LIST_ENTRY LastChanceShutdownListHead
Definition: device.c:21
LIST_ENTRY IopDiskFileSystemQueueHead
Definition: volume.c:21
LIST_ENTRY IopTapeFileSystemQueueHead
Definition: volume.c:22
Definition: io.h:428
PDEVICE_OBJECT DeviceObject
Definition: io.h:430
#define TAG_SHUTDOWN_ENTRY
Definition: tag.h:58

Referenced by PopGracefulShutdown().

◆ PiClearDevNodeProblem()

VOID PiClearDevNodeProblem ( _In_ PDEVICE_NODE  DeviceNode)

Definition at line 141 of file devnode.c.

143{
144 DeviceNode->Flags &= ~DNF_HAS_PROBLEM;
145 DeviceNode->Problem = 0;
146}

◆ PiInitCacheGroupInformation()

NTSTATUS NTAPI PiInitCacheGroupInformation ( VOID  )

Definition at line 94 of file pnpinit.c.

95{
98 PKEY_VALUE_FULL_INFORMATION KeyValueInformation;
99 PUNICODE_STRING GroupTable;
100 ULONG Count;
101 UNICODE_STRING GroupString =
102 RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet"
103 L"\\Control\\ServiceGroupOrder");
104
105 /* Open the registry key */
107 NULL,
108 &GroupString,
109 KEY_READ);
110 if (NT_SUCCESS(Status))
111 {
112 /* Get the list */
113 Status = IopGetRegistryValue(KeyHandle, L"List", &KeyValueInformation);
115
116 /* Make sure we got it */
117 if (NT_SUCCESS(Status))
118 {
119 /* Make sure it's valid */
120 if ((KeyValueInformation->Type == REG_MULTI_SZ) &&
121 (KeyValueInformation->DataLength))
122 {
123 /* Convert it to unicode strings */
124 Status = PnpRegMultiSzToUnicodeStrings(KeyValueInformation,
125 &GroupTable,
126 &Count);
127
128 /* Cache it for later */
129 PiInitGroupOrderTable = GroupTable;
131 }
132 else
133 {
134 /* Fail */
136 }
137
138 /* Free the information */
139 ExFreePool(KeyValueInformation);
140 }
141 }
142
143 /* Return status */
144 return Status;
145}
int Count
Definition: noreturn.cpp:7
#define REG_MULTI_SZ
Definition: nt_native.h:1501
NTSTATUS NTAPI PnpRegMultiSzToUnicodeStrings(IN PKEY_VALUE_FULL_INFORMATION KeyValueInformation, OUT PUNICODE_STRING *UnicodeStringList, OUT PULONG UnicodeStringCount)
Definition: pnputil.c:47
PUNICODE_STRING PiInitGroupOrderTable
Definition: pnpinit.c:17
USHORT PiInitGroupOrderTableCount
Definition: pnpinit.c:18

Referenced by IopInitializePlugPlayServices().

◆ PiInitializeNotifications()

VOID PiInitializeNotifications ( VOID  )

Definition at line 55 of file pnpnotify.c.

56{
60 InitializeListHead(&PiNotifyHwProfileListHead);
61 InitializeListHead(&PiNotifyDeviceInterfaceListHead);
62}
VOID FASTCALL KeInitializeGuardedMutex(OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:31
KGUARDED_MUTEX PiNotifyDeviceInterfaceLock
Definition: pnpnotify.c:21
KGUARDED_MUTEX PiNotifyTargetDeviceLock
Definition: pnpnotify.c:19
KGUARDED_MUTEX PiNotifyHwProfileLock
Definition: pnpnotify.c:20

Referenced by IoInitSystem().

◆ PiInsertDevNode()

VOID PiInsertDevNode ( _In_ PDEVICE_NODE  DeviceNode,
_In_ PDEVICE_NODE  ParentNode 
)

Definition at line 80 of file devnode.c.

83{
84 KIRQL oldIrql;
85
86 ASSERT(DeviceNode->Parent == NULL);
87
89 DeviceNode->Parent = ParentNode;
90 DeviceNode->Sibling = NULL;
91 if (ParentNode->LastChild == NULL)
92 {
93 ParentNode->Child = DeviceNode;
94 ParentNode->LastChild = DeviceNode;
95 }
96 else
97 {
98 ParentNode->LastChild->Sibling = DeviceNode;
99 ParentNode->LastChild = DeviceNode;
100 }
102 DeviceNode->Level = ParentNode->Level + 1;
103
104 DPRINT("Inserted devnode 0x%p to parent 0x%p\n", DeviceNode, ParentNode);
105}
KSPIN_LOCK IopDeviceTreeLock
Definition: devnode.c:19

Referenced by IoReportDetectedDevice(), PiControlInitializeDevice(), and PiEnumerateDevice().

◆ PiIrpCancelStopDevice()

NTSTATUS PiIrpCancelStopDevice ( _In_ PDEVICE_NODE  DeviceNode)

Definition at line 154 of file pnpirp.c.

156{
157 PAGED_CODE();
158
161
162 PVOID info;
164 .MajorFunction = IRP_MJ_PNP,
165 .MinorFunction = IRP_MN_CANCEL_STOP_DEVICE
166 };
167
168 // in fact we don't care which status is returned here
169 NTSTATUS status = IopSynchronousCall(DeviceNode->PhysicalDeviceObject, &stack, &info);
171 return status;
172}
Definition: _stack.h:55
@ DeviceNodeQueryStopped
Definition: iotypes.h:430
NTSTATUS IopSynchronousCall(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIO_STACK_LOCATION IoStackLocation, _Out_ PVOID *Information)
Definition: pnpirp.c:14
#define IRP_MN_CANCEL_STOP_DEVICE

Referenced by PiDevNodeStateMachine().

◆ PiIrpQueryDeviceRelations()

NTSTATUS PiIrpQueryDeviceRelations ( _In_ PDEVICE_NODE  DeviceNode,
_In_ DEVICE_RELATION_TYPE  Type 
)

Definition at line 176 of file pnpirp.c.

179{
180 PAGED_CODE();
181
184
186 .MajorFunction = IRP_MJ_PNP,
187 .MinorFunction = IRP_MN_QUERY_DEVICE_RELATIONS,
188 .Parameters.QueryDeviceRelations.Type = Type
189 };
190
191 // Vista+ does an asynchronous call
192 NTSTATUS status = IopSynchronousCall(DeviceNode->PhysicalDeviceObject,
193 &stack,
194 (PVOID)&DeviceNode->OverUsed1.PendingDeviceRelations);
195 DeviceNode->CompletionStatus = status;
196 return status;
197}

Referenced by PiDevNodeStateMachine().

◆ PiIrpQueryDeviceText()

NTSTATUS PiIrpQueryDeviceText ( _In_ PDEVICE_NODE  DeviceNode,
_In_ LCID  LocaleId,
_In_ DEVICE_TEXT_TYPE  Type,
_Out_ PWSTR DeviceText 
)

Definition at line 253 of file pnpirp.c.

258{
259 PAGED_CODE();
260
263
264 ULONG_PTR longText;
266 .MajorFunction = IRP_MJ_PNP,
267 .MinorFunction = IRP_MN_QUERY_DEVICE_TEXT,
268 .Parameters.QueryDeviceText.DeviceTextType = Type,
269 .Parameters.QueryDeviceText.LocaleId = LocaleId
270 };
271
273 status = IopSynchronousCall(DeviceNode->PhysicalDeviceObject, &stack, (PVOID)&longText);
274 if (NT_SUCCESS(status))
275 {
276 *DeviceText = (PVOID)longText;
277 }
278
279 return status;
280}
@ DeviceNodeUninitialized
Definition: iotypes.h:422
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ PCUNICODE_STRING _In_ PCUNICODE_STRING _In_ LCID LocaleId
Definition: wdfpdo.h:437
#define IRP_MN_QUERY_DEVICE_TEXT

Referenced by PiSetDevNodeText().

◆ PiIrpQueryPnPDeviceState()

NTSTATUS PiIrpQueryPnPDeviceState ( _In_ PDEVICE_NODE  DeviceNode,
_Out_ PPNP_DEVICE_STATE  DeviceState 
)

Definition at line 284 of file pnpirp.c.

287{
288 PAGED_CODE();
289
292 DeviceNode->State == DeviceNodeStarted);
293
294 ULONG_PTR longState;
296 .MajorFunction = IRP_MJ_PNP,
297 .MinorFunction = IRP_MN_QUERY_PNP_DEVICE_STATE
298 };
299
301 status = IopSynchronousCall(DeviceNode->PhysicalDeviceObject, &stack, (PVOID)&longState);
302 if (NT_SUCCESS(status))
303 {
304 *DeviceState = longState;
305 }
306
307 return status;
308}
@ DeviceNodeStartPostWork
Definition: iotypes.h:428
_In_ WDFDEVICE _Out_ PWDF_DEVICE_STATE DeviceState
Definition: wdfdevice.h:1999
#define IRP_MN_QUERY_PNP_DEVICE_STATE

Referenced by PiUpdateDeviceState().

◆ PiIrpQueryResourceRequirements()

NTSTATUS PiIrpQueryResourceRequirements ( _In_ PDEVICE_NODE  DeviceNode,
_Out_ PIO_RESOURCE_REQUIREMENTS_LIST Resources 
)

Definition at line 227 of file pnpirp.c.

230{
231 PAGED_CODE();
232
234
235 ULONG_PTR longRes;
237 .MajorFunction = IRP_MJ_PNP,
239 };
240
242 status = IopSynchronousCall(DeviceNode->PhysicalDeviceObject, &stack, (PVOID)&longRes);
243 if (NT_SUCCESS(status))
244 {
245 *Resources = (PVOID)longRes;
246 }
247
248 return status;
249}
#define IRP_MN_QUERY_RESOURCE_REQUIREMENTS

Referenced by PiFakeResourceRebalance().

◆ PiIrpQueryResources()

NTSTATUS PiIrpQueryResources ( _In_ PDEVICE_NODE  DeviceNode,
_Out_ PCM_RESOURCE_LIST Resources 
)

Definition at line 201 of file pnpirp.c.

204{
205 PAGED_CODE();
206
208
209 ULONG_PTR longRes;
211 .MajorFunction = IRP_MJ_PNP,
212 .MinorFunction = IRP_MN_QUERY_RESOURCES
213 };
214
216 status = IopSynchronousCall(DeviceNode->PhysicalDeviceObject, &stack, (PVOID)&longRes);
217 if (NT_SUCCESS(status))
218 {
219 *Resources = (PVOID)longRes;
220 }
221
222 return status;
223}
#define IRP_MN_QUERY_RESOURCES

Referenced by PiFakeResourceRebalance().

◆ PiIrpQueryStopDevice()

NTSTATUS PiIrpQueryStopDevice ( _In_ PDEVICE_NODE  DeviceNode)

Definition at line 133 of file pnpirp.c.

135{
136 PAGED_CODE();
137
140
141 PVOID info;
143 .MajorFunction = IRP_MJ_PNP,
144 .MinorFunction = IRP_MN_QUERY_STOP_DEVICE
145 };
146
147 NTSTATUS status = IopSynchronousCall(DeviceNode->PhysicalDeviceObject, &stack, &info);
148 DeviceNode->CompletionStatus = status;
149 return status;
150}
#define IRP_MN_QUERY_STOP_DEVICE

Referenced by PiDevNodeStateMachine().

◆ PiIrpStartDevice()

NTSTATUS PiIrpStartDevice ( _In_ PDEVICE_NODE  DeviceNode)

Definition at line 87 of file pnpirp.c.

89{
90 PAGED_CODE();
91
94
95 PVOID info;
97 .MajorFunction = IRP_MJ_PNP,
98 .MinorFunction = IRP_MN_START_DEVICE,
99 .Parameters.StartDevice.AllocatedResources = DeviceNode->ResourceList,
100 .Parameters.StartDevice.AllocatedResourcesTranslated = DeviceNode->ResourceListTranslated
101 };
102
103 // Vista+ does an asynchronous call
104 NTSTATUS status = IopSynchronousCall(DeviceNode->PhysicalDeviceObject, &stack, &info);
105 DeviceNode->CompletionStatus = status;
106 return status;
107}
#define IRP_MN_START_DEVICE

Referenced by PiDevNodeStateMachine().

◆ PiIrpStopDevice()

NTSTATUS PiIrpStopDevice ( _In_ PDEVICE_NODE  DeviceNode)

Definition at line 111 of file pnpirp.c.

113{
114 PAGED_CODE();
115
118
119 PVOID info;
121 .MajorFunction = IRP_MJ_PNP,
122 .MinorFunction = IRP_MN_STOP_DEVICE
123 };
124
125 // Drivers should never fail a IRP_MN_STOP_DEVICE request
126 NTSTATUS status = IopSynchronousCall(DeviceNode->PhysicalDeviceObject, &stack, &info);
128 return status;
129}
#define IRP_MN_STOP_DEVICE

Referenced by PiDevNodeStateMachine().

◆ PiNotifyDeviceInterfaceChange()

VOID PiNotifyDeviceInterfaceChange ( _In_ LPCGUID  Event,
_In_ LPCGUID  InterfaceClassGuid,
_In_ PUNICODE_STRING  SymbolicLinkName 
)

Delivers the event to all drivers subscribed to EventCategoryDeviceInterfaceChange.

Parameters
[in]EventThe PnP event GUID
[in]InterfaceClassGuidThe GUID of an interface class
[in]SymbolicLinkNamePointer to a string identifying the device interface name

Definition at line 161 of file pnpnotify.c.

165{
166 PAGED_CODE();
167
169 notifyStruct = ExAllocatePoolWithTag(PagedPool, sizeof(*notifyStruct), TAG_PNP_NOTIFY);
170 if (!notifyStruct)
171 {
172 return;
173 }
174
175 *notifyStruct = (DEVICE_INTERFACE_CHANGE_NOTIFICATION) {
176 .Version = 1,
178 .Event = *Event,
181 };
182
183 DPRINT("Delivering a DeviceInterfaceChange PnP event\n");
184
186
187 PLIST_ENTRY entry = PiNotifyDeviceInterfaceListHead.Flink;
188 while (entry != &PiNotifyDeviceInterfaceListHead)
189 {
191
192 if (!IsEqualGUID(&notifyStruct->InterfaceClassGuid, &nEntry->Guid))
193 {
194 entry = entry->Flink;
195 continue;
196 }
197
198 PiProcessSingleNotification(nEntry, notifyStruct, &PiNotifyDeviceInterfaceLock, &entry);
199 }
200
202 ExFreePoolWithTag(notifyStruct, TAG_PNP_NOTIFY);
203}
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
uint32_t entry
Definition: isohybrid.c:63
* PPNP_NOTIFY_ENTRY
Definition: pnpnotify.c:49
PNP_NOTIFY_ENTRY
Definition: pnpnotify.c:49
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define TAG_PNP_NOTIFY
Definition: tag.h:91
struct _DEVICE_INTERFACE_CHANGE_NOTIFICATION DEVICE_INTERFACE_CHANGE_NOTIFICATION

Referenced by IoSetDeviceInterfaceState().

◆ PiNotifyHardwareProfileChange()

VOID PiNotifyHardwareProfileChange ( _In_ LPCGUID  Event)

Delivers the event to all drivers subscribed to EventCategoryHardwareProfileChange PnP event.

Parameters
[in]EventThe PnP event GUID

Definition at line 214 of file pnpnotify.c.

216{
217 PAGED_CODE();
218
220 notifyStruct = ExAllocatePoolWithTag(PagedPool, sizeof(*notifyStruct), TAG_PNP_NOTIFY);
221 if (!notifyStruct)
222 {
223 return;
224 }
225
226 *notifyStruct = (HWPROFILE_CHANGE_NOTIFICATION) {
227 .Version = 1,
228 .Size = sizeof(HWPROFILE_CHANGE_NOTIFICATION),
229 .Event = *Event
230 };
231
232 DPRINT("Delivering a HardwareProfileChange PnP event\n");
233
235
236 PLIST_ENTRY entry = PiNotifyHwProfileListHead.Flink;
237 while (entry != &PiNotifyHwProfileListHead)
238 {
240
241 PiProcessSingleNotification(nEntry, notifyStruct, &PiNotifyHwProfileLock, &entry);
242 }
243
245 ExFreePoolWithTag(notifyStruct, TAG_PNP_NOTIFY);
246}
struct _HWPROFILE_CHANGE_NOTIFICATION HWPROFILE_CHANGE_NOTIFICATION

◆ PiNotifyTargetDeviceChange()

VOID PiNotifyTargetDeviceChange ( _In_ LPCGUID  Event,
_In_ PDEVICE_OBJECT  DeviceObject,
_In_opt_ PTARGET_DEVICE_CUSTOM_NOTIFICATION  CustomNotification 
)

Delivers the event to all drivers subscribed to EventCategoryTargetDeviceChange PnP event.

Parameters
[in]EventThe PnP event GUID
[in]DeviceObjectThe (target) device object
[in]CustomNotificationPointer to a custom notification for GUID_PNP_CUSTOM_NOTIFICATION

Definition at line 258 of file pnpnotify.c.

262{
263 PAGED_CODE();
264
265 PVOID notificationStruct;
266 // just in case our device is removed during the operation
268
270 ASSERT(deviceNode);
271
272 if (!IsEqualGUID(Event, &GUID_PNP_CUSTOM_NOTIFICATION))
273 {
275 notifStruct = ExAllocatePoolWithTag(PagedPool, sizeof(*notifStruct), TAG_PNP_NOTIFY);
276 if (!notifStruct)
277 {
278 return;
279 }
280
281 *notifStruct = (TARGET_DEVICE_REMOVAL_NOTIFICATION) {
282 .Version = 1,
284 .Event = *Event
285 };
286
287 notificationStruct = notifStruct;
288
289 DPRINT("Delivering a (non-custom) TargetDeviceChange PnP event\n");
290 }
291 else
292 {
293 ASSERT(CustomNotification);
294 // assuming everythng else is correct
295
296 notificationStruct = CustomNotification;
297
298 DPRINT("Delivering a (custom) TargetDeviceChange PnP event\n");
299 }
300
302
304 while (entry != &deviceNode->TargetDeviceNotify)
305 {
307
308 // put the file object from our saved entry to this particular notification's struct
309 ((PTARGET_DEVICE_REMOVAL_NOTIFICATION)notificationStruct)->FileObject = nEntry->FileObject;
310 // so you don't need to look at the definition ;)
313
314 PiProcessSingleNotification(nEntry, notificationStruct, &PiNotifyTargetDeviceLock, &entry);
315 }
316
318 ExFreePoolWithTag(notificationStruct, TAG_PNP_NOTIFY);
320}
#define C_ASSERT(e)
Definition: intsafe.h:73
LIST_ENTRY TargetDeviceNotify
Definition: iotypes.h:906
struct _TARGET_DEVICE_REMOVAL_NOTIFICATION TARGET_DEVICE_REMOVAL_NOTIFICATION
struct _TARGET_DEVICE_REMOVAL_NOTIFICATION * PTARGET_DEVICE_REMOVAL_NOTIFICATION

Referenced by IopCancelRemoveDevice(), IopQueryRemoveDevice(), IopSendRemoveDevice(), and PpSetCustomTargetEvent().

◆ PipAllocateDeviceNode()

◆ PipCallDriverAddDevice()

NTSTATUS NTAPI PipCallDriverAddDevice ( IN PDEVICE_NODE  DeviceNode,
IN BOOLEAN  LoadDriver,
IN PDRIVER_OBJECT  DriverObject 
)

◆ PiPerformSyncDeviceAction()

NTSTATUS PiPerformSyncDeviceAction ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ DEVICE_ACTION  Action 
)

Perfom a device operation synchronously via PiQueueDeviceAction.

Parameters
[in]DeviceObjectThe device object
[in]ActionThe action
Returns
Status of the operation

Definition at line 2718 of file devaction.c.

2721{
2722 KEVENT opFinished;
2724
2728
2729 return status;
2730}
VOID PiQueueDeviceAction(_In_ PDEVICE_OBJECT DeviceObject, _In_ DEVICE_ACTION Action, _In_opt_ PKEVENT CompletionEvent, _Out_opt_ NTSTATUS *CompletionStatus)
Queue a device operation to a worker thread.
Definition: devaction.c:2659

Referenced by IopInitializeSystemDrivers(), IoSynchronousInvalidateDeviceRelations(), and PiControlSyncDeviceAction().

◆ PipGetDriverTagPriority()

USHORT NTAPI PipGetDriverTagPriority ( IN HANDLE  ServiceHandle)

Definition at line 192 of file pnpinit.c.

193{
196 PKEY_VALUE_FULL_INFORMATION KeyValueInformation = NULL;
197 PKEY_VALUE_FULL_INFORMATION KeyValueInformationTag;
198 PKEY_VALUE_FULL_INFORMATION KeyValueInformationGroupOrderList;
201 PULONG GroupOrder;
202 ULONG Count, Tag = 0;
203 USHORT i = -1;
204 UNICODE_STRING GroupString =
205 RTL_CONSTANT_STRING(L"\\Registry\\Machine\\System\\CurrentControlSet"
206 L"\\Control\\ServiceGroupOrder");
207
208 /* Open the key */
210 if (!NT_SUCCESS(Status)) goto Quickie;
211
212 /* Read the group */
213 Status = IopGetRegistryValue(ServiceHandle, L"Group", &KeyValueInformation);
214 if (!NT_SUCCESS(Status)) goto Quickie;
215
216 /* Make sure we have a group */
217 if ((KeyValueInformation->Type == REG_SZ) &&
218 (KeyValueInformation->DataLength))
219 {
220 /* Convert to unicode string */
221 Buffer = (PVOID)((ULONG_PTR)KeyValueInformation + KeyValueInformation->DataOffset);
222 PnpRegSzToString(Buffer, KeyValueInformation->DataLength, &Group.Length);
223 Group.MaximumLength = (USHORT)KeyValueInformation->DataLength;
224 Group.Buffer = Buffer;
225 }
226
227 /* Now read the tag */
228 Status = IopGetRegistryValue(ServiceHandle, L"Tag", &KeyValueInformationTag);
229 if (!NT_SUCCESS(Status)) goto Quickie;
230
231 /* Make sure we have a tag */
232 if ((KeyValueInformationTag->Type == REG_DWORD) &&
233 (KeyValueInformationTag->DataLength))
234 {
235 /* Read it */
236 Tag = *(PULONG)((ULONG_PTR)KeyValueInformationTag +
237 KeyValueInformationTag->DataOffset);
238 }
239
240 /* We can get rid of this now */
241 ExFreePool(KeyValueInformationTag);
242
243 /* Now let's read the group's tag order */
245 Group.Buffer,
246 &KeyValueInformationGroupOrderList);
247
248 /* We can get rid of this now */
249Quickie:
250 if (KeyValueInformation) ExFreePool(KeyValueInformation);
252 if (!NT_SUCCESS(Status)) return -1;
253
254 /* We're on the success path -- validate the tag order*/
255 if ((KeyValueInformationGroupOrderList->Type == REG_BINARY) &&
256 (KeyValueInformationGroupOrderList->DataLength))
257 {
258 /* Get the order array */
259 GroupOrder = (PULONG)((ULONG_PTR)KeyValueInformationGroupOrderList +
260 KeyValueInformationGroupOrderList->DataOffset);
261
262 /* Get the count */
263 Count = *GroupOrder;
264 ASSERT(((Count + 1) * sizeof(ULONG)) <=
265 KeyValueInformationGroupOrderList->DataLength);
266
267 /* Now loop each tag */
268 GroupOrder++;
269 for (i = 1; i <= Count; i++)
270 {
271 /* If we found it, we're out */
272 if (Tag == *GroupOrder) break;
273
274 /* Try the next one */
275 GroupOrder++;
276 }
277 }
278
279 /* Last buffer to free */
280 ExFreePool(KeyValueInformationGroupOrderList);
281 return i;
282}
_In_opt_ PSID Group
Definition: rtlfuncs.h:1646
#define REG_BINARY
Definition: nt_native.h:1496
BOOLEAN NTAPI PnpRegSzToString(IN PWCHAR RegSzData, IN ULONG RegSzLength, OUT PUSHORT StringLength OPTIONAL)
Definition: pnputil.c:171
_Must_inspect_result_ _In_ WDFDEVICE _In_ BOOLEAN _In_opt_ PVOID Tag
Definition: wdfdevice.h:4065

Referenced by IopInitializeBootDrivers().

◆ PiQueueDeviceAction()

VOID PiQueueDeviceAction ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ DEVICE_ACTION  Action,
_In_opt_ PKEVENT  CompletionEvent,
_Out_opt_ NTSTATUS CompletionStatus 
)

Queue a device operation to a worker thread.

Parameters
[in]DeviceObjectThe device object
[in]ActionThe action
[in]CompletionEventThe completion event object (optional)
[out]CompletionStatusStatus returned be the action will be written here

Definition at line 2659 of file devaction.c.

2664{
2666 KIRQL OldIrql;
2667
2669
2670 DPRINT("PiQueueDeviceAction: DeviceObject - %p, Request - %p, Action - %s\n",
2671 DeviceObject, Request, ActionToStr(Action));
2672
2674
2675 Request->DeviceObject = DeviceObject;
2676 Request->Action = Action;
2677 Request->CompletionEvent = CompletionEvent;
2678 Request->CompletionStatus = CompletionStatus;
2679
2682
2684 {
2686
2690
2692 return;
2693 }
2694
2696 {
2698 return;
2699 }
2703
2706}
LIST_ENTRY IopDeviceActionRequestList
Definition: devaction.c:46
KSPIN_LOCK IopDeviceActionLock
Definition: devaction.c:49
KEVENT PiEnumerationFinished
Definition: devaction.c:50
static VOID NTAPI PipDeviceActionWorker(_In_opt_ PVOID Context)
Definition: devaction.c:2537
WORK_QUEUE_ITEM IopDeviceActionWorkItem
Definition: devaction.c:47
BOOLEAN IopDeviceActionInProgress
Definition: devaction.c:48
BOOLEAN PnPBootDriversLoaded
Definition: pnpinit.c:20
#define InsertTailList(ListHead, Entry)
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:723
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
@ DelayedWorkQueue
Definition: extypes.h:190
@ NonPagedPoolMustSucceed
Definition: ketypes.h:880

Referenced by IoInitSystem(), IoInvalidateDeviceRelations(), IoInvalidateDeviceState(), IopInitializeBootDrivers(), IopInitializeBuiltinDriver(), IopInitializePlugPlayServices(), IopInitializeSystemDrivers(), IoReportDetectedDevice(), and PiPerformSyncDeviceAction().

◆ PiSetDevNodeProblem()

VOID PiSetDevNodeProblem ( _In_ PDEVICE_NODE  DeviceNode,
_In_ UINT32  Problem 
)

Definition at line 132 of file devnode.c.

135{
136 DeviceNode->Flags |= DNF_HAS_PROBLEM;
137 DeviceNode->Problem = Problem;
138}
#define DNF_HAS_PROBLEM
Definition: iotypes.h:183

Referenced by PiAttachFilterDriversCallback(), PiCallDriverAddDevice(), PiDevNodeStateMachine(), and PiUpdateDeviceState().

◆ PiSetDevNodeState()

PNP_DEVNODE_STATE PiSetDevNodeState ( _In_ PDEVICE_NODE  DeviceNode,
_In_ PNP_DEVNODE_STATE  NewState 
)

Definition at line 108 of file devnode.c.

111{
112 KIRQL oldIrql;
113
115
116 PNP_DEVNODE_STATE prevState = DeviceNode->State;
117 if (prevState != NewState)
118 {
119 DeviceNode->State = NewState;
120 DeviceNode->PreviousState = prevState;
121 DeviceNode->StateHistory[DeviceNode->StateHistoryEntry++] = prevState;
122 DeviceNode->StateHistoryEntry %= DEVNODE_HISTORY_SIZE;
123 }
124
126
127 DPRINT("%wZ Changed state 0x%x => 0x%x\n", &DeviceNode->InstancePath, prevState, NewState);
128 return prevState;
129}
enum _PNP_DEVNODE_STATE PNP_DEVNODE_STATE
#define DEVNODE_HISTORY_SIZE
Definition: iotypes.h:869

Referenced by IopAssignDeviceResources(), IopInitializePlugPlayServices(), IopQueryRemoveChildDevices(), IopSendRemoveDevice(), IoReportDetectedDevice(), PiCallDriverAddDevice(), PiControlInitializeDevice(), PiDevNodeStateMachine(), PiEnumerateDevice(), PiInitializeDevNode(), PiStartDeviceFinal(), and PiUpdateDeviceState().

◆ PiSetDevNodeText()

VOID PiSetDevNodeText ( _In_ PDEVICE_NODE  DeviceNode,
_In_ HANDLE  InstanceKey 
)

Sets the DeviceNode's DeviceDesc and LocationInformation registry values.

Definition at line 1089 of file devaction.c.

1092{
1093 PAGED_CODE();
1094
1095 LCID localeId;
1096
1097 // Get the Locale ID
1099 if (!NT_SUCCESS(status))
1100 {
1101 DPRINT1("ZwQueryDefaultLocale() failed with status %x\n", status);
1102 return;
1103 }
1104
1105 // Step 1: Write the DeviceDesc value if does not exist
1106
1107 UNICODE_STRING valDeviceDesc = RTL_CONSTANT_STRING(L"DeviceDesc");
1108 ULONG len;
1109
1110 status = ZwQueryValueKey(InstanceKey, &valDeviceDesc, KeyValueBasicInformation, NULL, 0, &len);
1112 {
1113 PWSTR deviceDesc = NULL;
1115
1116 if (deviceDesc && deviceDesc[0] != UNICODE_NULL)
1117 {
1118 status = ZwSetValueKey(InstanceKey,
1119 &valDeviceDesc,
1120 0,
1121 REG_SZ,
1122 deviceDesc,
1123 ((ULONG)wcslen(deviceDesc) + 1) * sizeof(WCHAR));
1124
1125 if (!NT_SUCCESS(status))
1126 {
1127 DPRINT1("ZwSetValueKey() failed (Status %x)\n", status);
1128 }
1129 }
1130 else
1131 {
1132 // This key is mandatory, so even if the Irp fails, we still write it
1133 UNICODE_STRING unknownDeviceDesc = RTL_CONSTANT_STRING(L"Unknown device");
1134 DPRINT("Driver didn't return DeviceDesc (status %x)\n", status);
1135
1136 status = ZwSetValueKey(InstanceKey,
1137 &valDeviceDesc,
1138 0,
1139 REG_SZ,
1140 unknownDeviceDesc.Buffer,
1141 unknownDeviceDesc.MaximumLength);
1142 if (!NT_SUCCESS(status))
1143 {
1144 DPRINT1("ZwSetValueKey() failed (Status %x)\n", status);
1145 }
1146 }
1147
1148 if (deviceDesc)
1149 {
1150 ExFreePoolWithTag(deviceDesc, 0);
1151 }
1152 }
1153
1154 // Step 2: LocaltionInformation is overwritten unconditionally
1155
1156 PWSTR deviceLocationInfo = NULL;
1158 localeId,
1160 &deviceLocationInfo);
1161
1162 if (deviceLocationInfo && deviceLocationInfo[0] != UNICODE_NULL)
1163 {
1164 UNICODE_STRING valLocationInfo = RTL_CONSTANT_STRING(L"LocationInformation");
1165
1166 status = ZwSetValueKey(InstanceKey,
1167 &valLocationInfo,
1168 0,
1169 REG_SZ,
1170 deviceLocationInfo,
1171 ((ULONG)wcslen(deviceLocationInfo) + 1) * sizeof(WCHAR));
1172 if (!NT_SUCCESS(status))
1173 {
1174 DPRINT1("ZwSetValueKey() failed (Status %x)\n", status);
1175 }
1176 }
1177
1178 if (deviceLocationInfo)
1179 {
1180 ExFreePoolWithTag(deviceLocationInfo, 0);
1181 }
1182 else
1183 {
1184 DPRINT("Driver didn't return LocationInformation (status %x)\n", status);
1185 }
1186}
GLenum GLsizei len
Definition: glext.h:6722
NTSYSAPI NTSTATUS NTAPI ZwQueryDefaultLocale(_In_ BOOLEAN UserProfile, _Out_ PLCID DefaultLocaleId)
NTSTATUS PiIrpQueryDeviceText(_In_ PDEVICE_NODE DeviceNode, _In_ LCID LocaleId, _In_ DEVICE_TEXT_TYPE Type, _Out_ PWSTR *DeviceText)
Definition: pnpirp.c:253
DWORD LCID
Definition: nls.h:13
@ DeviceTextLocationInformation
Definition: iotypes.h:2946
@ DeviceTextDescription
Definition: iotypes.h:2945

Referenced by IoReportDetectedDevice(), and PiInitializeDevNode().

◆ PnpDetermineResourceListSize()

ULONG NTAPI PnpDetermineResourceListSize ( IN PCM_RESOURCE_LIST  ResourceList)

Definition at line 1237 of file pnpmgr.c.

1238{
1239 ULONG FinalSize, PartialSize, EntrySize, i, j;
1240 PCM_FULL_RESOURCE_DESCRIPTOR FullDescriptor;
1241 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptor;
1242
1243 /* If we don't have one, that's easy */
1244 if (!ResourceList) return 0;
1245
1246 /* Start with the minimum size possible */
1247 FinalSize = FIELD_OFFSET(CM_RESOURCE_LIST, List);
1248
1249 /* Loop each full descriptor */
1250 FullDescriptor = ResourceList->List;
1251 for (i = 0; i < ResourceList->Count; i++)
1252 {
1253 /* Start with the minimum size possible */
1254 PartialSize = FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList) +
1255 FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors);
1256
1257 /* Loop each partial descriptor */
1258 PartialDescriptor = FullDescriptor->PartialResourceList.PartialDescriptors;
1259 for (j = 0; j < FullDescriptor->PartialResourceList.Count; j++)
1260 {
1261 /* Start with the minimum size possible */
1263
1264 /* Check if there is extra data */
1265 if (PartialDescriptor->Type == CmResourceTypeDeviceSpecific)
1266 {
1267 /* Add that data */
1268 EntrySize += PartialDescriptor->u.DeviceSpecificData.DataSize;
1269 }
1270
1271 /* The size of partial descriptors is bigger */
1272 PartialSize += EntrySize;
1273
1274 /* Go to the next partial descriptor */
1275 PartialDescriptor = (PVOID)((ULONG_PTR)PartialDescriptor + EntrySize);
1276 }
1277
1278 /* The size of full descriptors is bigger */
1279 FinalSize += PartialSize;
1280
1281 /* Go to the next full descriptor */
1282 FullDescriptor = (PVOID)((ULONG_PTR)FullDescriptor + PartialSize);
1283 }
1284
1285 /* Return the final size */
1286 return FinalSize;
1287}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define CmResourceTypeDeviceSpecific
Definition: hwresource.cpp:127
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR CM_PARTIAL_RESOURCE_DESCRIPTOR
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@393::@402 DeviceSpecificData
_In_ UCHAR EntrySize
Definition: iofuncs.h:642

Referenced by IoGetDeviceProperty(), IopAssignDeviceResources(), IopFixupResourceListWithRequirements(), IopSetDeviceInstanceData(), IopTranslateDeviceResources(), IopUpdateControlKeyWithResources(), and IopUpdateResourceMap().

◆ PnpInit2()

VOID PnpInit2 ( VOID  )

◆ PnpRegMultiSzToUnicodeStrings()

NTSTATUS NTAPI PnpRegMultiSzToUnicodeStrings ( IN PKEY_VALUE_FULL_INFORMATION  KeyValueInformation,
OUT PUNICODE_STRING UnicodeStringList,
OUT PULONG  UnicodeStringCount 
)

Definition at line 47 of file pnputil.c.

50{
51 PWCHAR p, pp, ps;
52 ULONG i = 0;
53 SIZE_T n;
54 ULONG Count = 0;
55
56 /* Validate the key information */
57 if (KeyValueInformation->Type != REG_MULTI_SZ) return STATUS_INVALID_PARAMETER;
58
59 /* Set the pointers */
60 p = (PWCHAR)((ULONG_PTR)KeyValueInformation +
61 KeyValueInformation->DataOffset);
62 pp = (PWCHAR)((ULONG_PTR)p + KeyValueInformation->DataLength);
63
64 /* Loop the data */
65 while (p != pp)
66 {
67 /* If we find a NULL, that means one string is done */
68 if (!*p)
69 {
70 /* Add to our string count */
71 Count++;
72
73 /* Check for a double-NULL, which means we're done */
74 if (((p + 1) == pp) || !(*(p + 1))) break;
75 }
76
77 /* Go to the next character */
78 p++;
79 }
80
81 /* If we looped the whole list over, we missed increment a string, do it */
82 if (p == pp) Count++;
83
84 /* Allocate the list now that we know how big it is */
85 *UnicodeStringList = ExAllocatePoolWithTag(PagedPool,
86 sizeof(UNICODE_STRING) * Count,
87 'sUpP');
88 if (!(*UnicodeStringList)) return STATUS_INSUFFICIENT_RESOURCES;
89
90 /* Set pointers for second loop */
91 ps = p = (PWCHAR)((ULONG_PTR)KeyValueInformation +
92 KeyValueInformation->DataOffset);
93
94 /* Loop again, to do the copy this time */
95 while (p != pp)
96 {
97 /* If we find a NULL, that means one string is done */
98 if (!*p)
99 {
100 /* Check how long this string is */
101 n = (ULONG_PTR)p - (ULONG_PTR)ps + sizeof(UNICODE_NULL);
102
103 /* Allocate the buffer */
104 (*UnicodeStringList)[i].Buffer = ExAllocatePoolWithTag(PagedPool,
105 n,
106 'sUpP');
107 if (!(*UnicodeStringList)[i].Buffer)
108 {
109 /* Back out of everything */
110 PnpFreeUnicodeStringList(*UnicodeStringList, i);
112 }
113
114 /* Copy the string into the buffer */
115 RtlCopyMemory((*UnicodeStringList)[i].Buffer, ps, n);
116
117 /* Set the lengths */
118 (*UnicodeStringList)[i].MaximumLength = (USHORT)n;
119 (*UnicodeStringList)[i].Length = (USHORT)(n - sizeof(UNICODE_NULL));
120
121 /* One more entry done */
122 i++;
123
124 /* Check for a double-NULL, which means we're done */
125 if (((p + 1) == pp) || !(*(p + 1))) break;
126
127 /* New string */
128 ps = p + 1;
129 }
130
131 /* New string */
132 p++;
133 }
134
135 /* Check if we've reached the last string */
136 if (p == pp)
137 {
138 /* Calculate the string length */
139 n = (ULONG_PTR)p - (ULONG_PTR)ps;
140
141 /* Allocate the buffer for it */
142 (*UnicodeStringList)[i].Buffer = ExAllocatePoolWithTag(PagedPool,
143 n +
144 sizeof(UNICODE_NULL),
145 'sUpP');
146 if (!(*UnicodeStringList)[i].Buffer)
147 {
148 /* Back out of everything */
149 PnpFreeUnicodeStringList(*UnicodeStringList, i);
151 }
152
153 /* Make sure there's an actual string here */
154 if (n) RtlCopyMemory((*UnicodeStringList)[i].Buffer, ps, n);
155
156 /* Null-terminate the string ourselves */
157 (*UnicodeStringList)[i].Buffer[n / sizeof(WCHAR)] = UNICODE_NULL;
158
159 /* Set the lengths */
160 (*UnicodeStringList)[i].Length = (USHORT)n;
161 (*UnicodeStringList)[i].MaximumLength = (USHORT)(n + sizeof(UNICODE_NULL));
162 }
163
164 /* And we're done */
165 *UnicodeStringCount = Count;
166 return STATUS_SUCCESS;
167}
GLdouble n
Definition: glext.h:7729
VOID NTAPI PnpFreeUnicodeStringList(IN PUNICODE_STRING UnicodeStringList, IN ULONG StringCount)
Definition: pnputil.c:21

Referenced by PiInitCacheGroupInformation().

◆ PnpRegSzToString()

BOOLEAN NTAPI PnpRegSzToString ( IN PWCHAR  RegSzData,
IN ULONG  RegSzLength,
OUT PUSHORT StringLength  OPTIONAL 
)

Definition at line 171 of file pnputil.c.

174{
175 PWCHAR p, pp;
176
177 /* Find the end */
178 pp = RegSzData + RegSzLength / sizeof(WCHAR);
179 for (p = RegSzData; p < pp; p++)
180 {
181 if (!*p)
182 {
183 break;
184 }
185 }
186
187 /* Return the length. Truncation can happen but is of no consequence. */
188 if (StringLength)
189 {
190 *StringLength = (USHORT)(p - RegSzData) * sizeof(WCHAR);
191 }
192 return TRUE;
193}

Referenced by PipGetDriverTagPriority(), and PpInitGetGroupOrderIndex().

◆ PnpRootCreateDevice()

NTSTATUS PnpRootCreateDevice ( IN PUNICODE_STRING  ServiceName,
OUT PDEVICE_OBJECT PhysicalDeviceObject,
OUT PUNICODE_STRING  FullInstancePath 
)

Definition at line 184 of file pnproot.c.

188{
189 PPNPROOT_FDO_DEVICE_EXTENSION DeviceExtension;
190 PPNPROOT_PDO_DEVICE_EXTENSION PdoDeviceExtension;
191 UNICODE_STRING DevicePath;
192 WCHAR InstancePath[5];
195 ULONG NextInstance;
196 UNICODE_STRING EnumKeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\" REGSTR_PATH_SYSTEMENUM);
197 HANDLE EnumHandle, DeviceKeyHandle = NULL, InstanceKeyHandle;
200
201 DeviceExtension = &PnpRootDOExtension;
202 KeAcquireGuardedMutex(&DeviceExtension->DeviceListLock);
203
204 DPRINT("Creating a PnP root device for service '%wZ'\n", ServiceName);
205
206 DevicePath.Length = 0;
207 DevicePath.MaximumLength = sizeof(REGSTR_KEY_ROOTENUM) + sizeof(L'\\') + ServiceName->Length;
209 DevicePath.MaximumLength,
211 if (DevicePath.Buffer == NULL)
212 {
213 DPRINT1("ExAllocatePoolWithTag() failed\n");
215 goto cleanup;
216 }
219
220 /* Initialize a PNPROOT_DEVICE structure */
222 if (!Device)
223 {
224 DPRINT("ExAllocatePoolWithTag() failed\n");
226 goto cleanup;
227 }
229 Device->DeviceID = DevicePath; // "Root<service_name>"
230 RtlInitEmptyUnicodeString(&DevicePath, NULL, 0);
231
232 Status = IopOpenRegistryKeyEx(&EnumHandle, NULL, &EnumKeyName, KEY_READ);
233 if (NT_SUCCESS(Status))
234 {
236 &Device->DeviceID,
238 EnumHandle,
239 NULL);
240 Status = ZwCreateKey(&DeviceKeyHandle, KEY_SET_VALUE, &ObjectAttributes, 0, NULL, REG_OPTION_NON_VOLATILE, NULL);
241 ObCloseHandle(EnumHandle, KernelMode);
242 }
243
244 if (!NT_SUCCESS(Status))
245 {
246 DPRINT1("Failed to open registry key\n");
247 goto cleanup;
248 }
249
250tryagain:
252 QueryTable[0].Name = L"NextInstance";
253 QueryTable[0].EntryContext = &NextInstance;
255
257 (PWSTR)DeviceKeyHandle,
259 NULL,
260 NULL);
261 for (NextInstance = 0; NextInstance <= 9999; NextInstance++)
262 {
263 _snwprintf(InstancePath, sizeof(InstancePath) / sizeof(WCHAR), L"%04lu", NextInstance);
264 Status = LocateChildDevice(DeviceExtension, &Device->DeviceID, InstancePath, NULL);
266 break;
267 }
268
269 if (NextInstance > 9999)
270 {
271 DPRINT1("Too many legacy devices reported for service '%wZ'\n", ServiceName);
273 goto cleanup;
274 }
275
276 _snwprintf(InstancePath, sizeof(InstancePath) / sizeof(WCHAR), L"%04lu", NextInstance);
277 Status = LocateChildDevice(DeviceExtension, &Device->DeviceID, InstancePath, NULL);
278 if (Status != STATUS_NO_SUCH_DEVICE || NextInstance > 9999)
279 {
280 DPRINT1("NextInstance value is corrupt! (%lu)\n", NextInstance);
282 (PWSTR)DeviceKeyHandle,
283 L"NextInstance");
284 goto tryagain;
285 }
286
287 NextInstance++;
289 (PWSTR)DeviceKeyHandle,
290 L"NextInstance",
291 REG_DWORD,
292 &NextInstance,
293 sizeof(NextInstance));
294 if (!NT_SUCCESS(Status))
295 {
296 DPRINT1("Failed to write new NextInstance value! (0x%x)\n", Status);
297 goto cleanup;
298 }
299
300 // "0000" or higher
301 if (!RtlCreateUnicodeString(&Device->InstanceID, InstancePath))
302 {
304 goto cleanup;
305 }
306
307 /* Finish creating the instance path in the registry */
309 &Device->InstanceID,
311 DeviceKeyHandle,
312 NULL);
313 Status = ZwCreateKey(&InstanceKeyHandle, KEY_QUERY_VALUE, &ObjectAttributes, 0, NULL, REG_OPTION_NON_VOLATILE, NULL);
314 if (!NT_SUCCESS(Status))
315 {
316 DPRINT1("Failed to create instance path (0x%x)\n", Status);
317 goto cleanup;
318 }
319
320 /* Just close the handle */
321 ObCloseHandle(InstanceKeyHandle, KernelMode);
322
323 // generate the full device instance path
324 FullInstancePath->MaximumLength = Device->DeviceID.Length + sizeof(L'\\') + Device->InstanceID.Length;
325 FullInstancePath->Length = 0;
326 FullInstancePath->Buffer = ExAllocatePool(PagedPool, FullInstancePath->MaximumLength);
327 if (!FullInstancePath->Buffer)
328 {
330 goto cleanup;
331 }
332
333 RtlAppendUnicodeStringToString(FullInstancePath, &Device->DeviceID);
334 RtlAppendUnicodeToString(FullInstancePath, L"\\");
335 RtlAppendUnicodeStringToString(FullInstancePath, &Device->InstanceID);
336
337 /* Initialize a device object */
339 if (!NT_SUCCESS(Status))
340 {
341 DPRINT("IoCreateDevice() failed with status 0x%08lx\n", Status);
343 goto cleanup;
344 }
345
346 PdoDeviceExtension = (PPNPROOT_PDO_DEVICE_EXTENSION)Device->Pdo->DeviceExtension;
347 RtlZeroMemory(PdoDeviceExtension, sizeof(PNPROOT_PDO_DEVICE_EXTENSION));
348 PdoDeviceExtension->DeviceInfo = Device;
349
350 Device->Pdo->Flags |= DO_BUS_ENUMERATED_DEVICE;
351 Device->Pdo->Flags &= ~DO_DEVICE_INITIALIZING;
352
354 &DeviceExtension->DeviceListHead,
355 &Device->ListEntry);
356 DeviceExtension->DeviceListCount++;
357
359 DPRINT("Created PDO %p (%wZ\\%wZ)\n", *PhysicalDeviceObject, &Device->DeviceID, &Device->InstanceID);
360 Device = NULL;
362
363cleanup:
364 KeReleaseGuardedMutex(&DeviceExtension->DeviceListLock);
365 if (Device)
366 {
367 if (Device->Pdo)
369 RtlFreeUnicodeString(&Device->DeviceID);
370 RtlFreeUnicodeString(&Device->InstanceID);
372 }
373 RtlFreeUnicodeString(&DevicePath);
374 if (DeviceKeyHandle != NULL)
375 ObCloseHandle(DeviceKeyHandle, KernelMode);
376 return Status;
377}
NTSYSAPI NTSTATUS WINAPI RtlDeleteRegistryValue(ULONG, PCWSTR, PCWSTR)
NTSYSAPI NTSTATUS WINAPI RtlWriteRegistryValue(ULONG, PCWSTR, PCWSTR, ULONG, PVOID, ULONG)
NTSYSAPI NTSTATUS WINAPI RtlQueryRegistryValues(ULONG, PCWSTR, PRTL_QUERY_REGISTRY_TABLE, PVOID, PVOID)
_In_ PCWSTR _Inout_ _At_ QueryTable _Pre_unknown_ PRTL_QUERY_REGISTRY_TABLE QueryTable
Definition: rtlfuncs.h:4208
#define RTL_QUERY_REGISTRY_REQUIRED
Definition: nt_native.h:132
#define RTL_QUERY_REGISTRY_DIRECT
Definition: nt_native.h:144
#define RTL_REGISTRY_HANDLE
Definition: nt_native.h:168
#define KEY_SET_VALUE
Definition: nt_native.h:1017
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
static PNPROOT_FDO_DEVICE_EXTENSION PnpRootDOExtension
Definition: pnproot.c:65
struct _PNPROOT_PDO_DEVICE_EXTENSION * PPNPROOT_PDO_DEVICE_EXTENSION
static NTSTATUS LocateChildDevice(IN PPNPROOT_FDO_DEVICE_EXTENSION DeviceExtension, IN PCUNICODE_STRING DeviceId, IN PCWSTR InstanceId, OUT PPNPROOT_DEVICE *ChildDevice OPTIONAL)
Definition: pnproot.c:70
NTSTATUS PnpRootCreateDeviceObject(OUT PDEVICE_OBJECT *DeviceObject)
Definition: pnproot.c:167
#define REGSTR_PATH_SYSTEMENUM
Definition: regstr.h:483
KGUARDED_MUTEX DeviceListLock
Definition: pnproot.c:56
PPNPROOT_DEVICE DeviceInfo
Definition: pnproot.c:45
#define TAG_PNP_ROOT
Definition: tag.h:92
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474

Referenced by IoReportDetectedDevice().

◆ PnpRootCreateDeviceObject()

NTSTATUS PnpRootCreateDeviceObject ( OUT PDEVICE_OBJECT DeviceObject)

Definition at line 167 of file pnproot.c.

169{
173 NULL,
176 FALSE,
178
179 return status;
180}
#define FILE_AUTOGENERATED_DEVICE_NAME
Definition: iotypes.h:138

Referenced by PiControlInitializeDevice(), PnpRootCreateDevice(), and PnpRootQueryDeviceRelations().

◆ PnpRootDriverEntry()

NTSTATUS NTAPI PnpRootDriverEntry ( IN PDRIVER_OBJECT  DriverObject,
IN PUNICODE_STRING  RegistryPath 
)

Definition at line 1488 of file pnproot.c.

1491{
1492#if MI_TRACE_PFNS
1494 UNICODE_STRING PfnDumpDeviceName = RTL_CONSTANT_STRING(L"\\Device\\PfnDump");
1495#endif
1496
1497 DPRINT("PnpRootDriverEntry(%p %wZ)\n", DriverObject, RegistryPath);
1498
1500
1502
1503#if MI_TRACE_PFNS
1504 DriverObject->MajorFunction[IRP_MJ_CREATE] = PnpRootCreateClose;
1505 DriverObject->MajorFunction[IRP_MJ_CLOSE] = PnpRootCreateClose;
1506#endif
1507 DriverObject->MajorFunction[IRP_MJ_PNP] = PnpRootPnpControl;
1509
1510#if MI_TRACE_PFNS
1512 0,
1513 &PfnDumpDeviceName,
1515 0,
1516 FALSE,
1517 &IopPfnDumpDeviceObject);
1518 if (!NT_SUCCESS(Status))
1519 {
1520 DPRINT1("Creating PFN Dump device failed with %lx\n", Status);
1521 }
1522 else
1523 {
1524 IopPfnDumpDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
1525 }
1526#endif
1527
1528 return STATUS_SUCCESS;
1529}
static NTSTATUS NTAPI PnpRootPowerControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: pnproot.c:1418
static NTSTATUS NTAPI PnpRootPnpControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: pnproot.c:1395
NTSTATUS NTAPI PnpRootAddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject)
Definition: pnproot.c:1449
#define FILE_DEVICE_UNKNOWN
Definition: winioctl.h:140
PDRIVER_ADD_DEVICE AddDevice
Definition: iotypes.h:2220
#define IRP_MJ_POWER

Referenced by IopInitializePlugPlayServices().

◆ PnpRootInitializeDevExtension()

VOID PnpRootInitializeDevExtension ( VOID  )

◆ PnpRootRegisterDevice()

NTSTATUS PnpRootRegisterDevice ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 107 of file pnproot.c.

109{
111 PPNPROOT_PDO_DEVICE_EXTENSION PdoDeviceExtension;
114 PWSTR InstancePath;
115 UNICODE_STRING InstancePathCopy;
116
118 if (!Device) return STATUS_NO_MEMORY;
119
121 if (!RtlCreateUnicodeString(&InstancePathCopy, DeviceNode->InstancePath.Buffer))
122 {
124 return STATUS_NO_MEMORY;
125 }
126
127 InstancePath = wcsrchr(InstancePathCopy.Buffer, L'\\');
128 ASSERT(InstancePath);
129
130 if (!RtlCreateUnicodeString(&Device->InstanceID, InstancePath + 1))
131 {
132 RtlFreeUnicodeString(&InstancePathCopy);
134 return STATUS_NO_MEMORY;
135 }
136
137 InstancePath[0] = UNICODE_NULL;
138
139 if (!RtlCreateUnicodeString(&Device->DeviceID, InstancePathCopy.Buffer))
140 {
141 RtlFreeUnicodeString(&InstancePathCopy);
142 RtlFreeUnicodeString(&Device->InstanceID);
144 return STATUS_NO_MEMORY;
145 }
146
147 InstancePath[0] = L'\\';
148
149 Device->Pdo = DeviceObject;
150
151 PdoDeviceExtension = DeviceObject->DeviceExtension;
152 RtlZeroMemory(PdoDeviceExtension, sizeof(PNPROOT_PDO_DEVICE_EXTENSION));
153 PdoDeviceExtension->DeviceInfo = Device;
154
155 KeAcquireGuardedMutex(&DeviceExtension->DeviceListLock);
156 InsertTailList(&DeviceExtension->DeviceListHead,
157 &Device->ListEntry);
158 DeviceExtension->DeviceListCount++;
159 KeReleaseGuardedMutex(&DeviceExtension->DeviceListLock);
160
161 RtlFreeUnicodeString(&InstancePathCopy);
162
163 return STATUS_SUCCESS;
164}
#define wcsrchr
Definition: compat.h:16

Referenced by IoReportDetectedDevice(), and PiControlInitializeDevice().

◆ PpInitGetGroupOrderIndex()

USHORT NTAPI PpInitGetGroupOrderIndex ( IN HANDLE  ServiceHandle)

Definition at line 149 of file pnpinit.c.

150{
152 PKEY_VALUE_FULL_INFORMATION KeyValueInformation;
153 USHORT i;
156 PAGED_CODE();
157
158 /* Make sure we have a cache */
159 if (!PiInitGroupOrderTable) return -1;
160
161 /* If we don't have a handle, the rest is easy -- return the count */
162 if (!ServiceHandle) return PiInitGroupOrderTableCount + 1;
163
164 /* Otherwise, get the group value */
165 Status = IopGetRegistryValue(ServiceHandle, L"Group", &KeyValueInformation);
167
168 /* Make sure we have a valid string */
169 ASSERT(KeyValueInformation->Type == REG_SZ);
170 ASSERT(KeyValueInformation->DataLength);
171
172 /* Convert to unicode string */
173 Buffer = (PVOID)((ULONG_PTR)KeyValueInformation + KeyValueInformation->DataOffset);
174 PnpRegSzToString(Buffer, KeyValueInformation->DataLength, &Group.Length);
175 Group.MaximumLength = (USHORT)KeyValueInformation->DataLength;
176 Group.Buffer = Buffer;
177
178 /* Loop the groups */
180 {
181 /* Try to find a match */
183 }
184
185 /* We're done */
186 ExFreePool(KeyValueInformation);
187 return i;
188}
#define for
Definition: utility.h:88
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)

Referenced by IopInitializeBootDrivers().

◆ PpInitSystem()

BOOLEAN NTAPI PpInitSystem ( VOID  )

Definition at line 1142 of file pnpmgr.c.

1143{
1144 /* Check the initialization phase */
1145 switch (ExpInitializationPhase)
1146 {
1147 case 0:
1148
1149 /* Do Phase 0 */
1150 return PiInitPhase0();
1151
1152 case 1:
1153
1154 /* Do Phase 1 */
1155 return TRUE;
1156 //return PiInitPhase1();
1157
1158 default:
1159
1160 /* Don't know any other phase! Bugcheck! */
1161 KeBugCheck(UNEXPECTED_INITIALIZATION_CALL);
1162 return FALSE;
1163 }
1164}
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1430
ULONG ExpInitializationPhase
Definition: init.c:68
BOOLEAN NTAPI PiInitPhase0(VOID)
Definition: pnpmgr.c:1130

Referenced by ExpInitializeExecutive(), and Phase1InitializationDiscard().

◆ RawFsDriverEntry()

NTSTATUS NTAPI RawFsDriverEntry ( IN PDRIVER_OBJECT  DriverObject,
IN PUNICODE_STRING  RegistryPath 
)

Definition at line 1193 of file rawfs.c.

1195{
1198
1200
1201 /* Create the raw disk device */
1202 RtlInitUnicodeString(&DeviceName, L"\\Device\\RawDisk");
1204 0,
1205 &DeviceName,
1207 0,
1208 FALSE,
1210 if (!NT_SUCCESS(Status))
1211 {
1212 return Status;
1213 }
1214
1215 /* Create the raw CDROM device */
1216 RtlInitUnicodeString(&DeviceName, L"\\Device\\RawCdRom");
1218 0,
1219 &DeviceName,
1221 0,
1222 FALSE,
1224 if (!NT_SUCCESS(Status))
1225 {
1227 return Status;
1228 }
1229
1230 /* Create the raw tape device */
1231 RtlInitUnicodeString(&DeviceName, L"\\Device\\RawTape");
1233 0,
1234 &DeviceName,
1236 0,
1237 FALSE,
1239 if (!NT_SUCCESS(Status))
1240 {
1243 return Status;
1244 }
1245
1246 /* Set Direct I/O for all devices */
1250
1251 /* Set generic stubs */
1252 DriverObject->MajorFunction[IRP_MJ_CREATE] =
1253 DriverObject->MajorFunction[IRP_MJ_CLEANUP] =
1254 DriverObject->MajorFunction[IRP_MJ_CLOSE] =
1255 DriverObject->MajorFunction[IRP_MJ_READ] =
1256 DriverObject->MajorFunction[IRP_MJ_WRITE] =
1257 DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] =
1258 DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] =
1262
1263 /* Shutdown and unload */
1264 DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = RawShutdown;
1265 DriverObject->DriverUnload = RawUnload;
1266
1267 /* Register the file systems */
1271
1272#if 0 // FIXME: DriverUnload is never called
1273 /* Reference device objects */
1277#endif
1278 return STATUS_SUCCESS;
1279}
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
VOID NTAPI IoRegisterFileSystem(IN PDEVICE_OBJECT DeviceObject)
Definition: volume.c:987
NTSTATUS NTAPI RawShutdown(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: rawfs.c:1157
PDEVICE_OBJECT RawCdromDeviceObject
Definition: rawfs.c:43
PDEVICE_OBJECT RawTapeDeviceObject
Definition: rawfs.c:43
PDEVICE_OBJECT RawDiskDeviceObject
Definition: rawfs.c:43
VOID NTAPI RawUnload(IN PDRIVER_OBJECT DriverObject)
Definition: rawfs.c:1180
NTSTATUS NTAPI RawDispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: rawfs.c:1047
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_QUERY_VOLUME_INFORMATION
Definition: rdpdr.c:50
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define IRP_MJ_SET_INFORMATION
Definition: rdpdr.c:49
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275

Referenced by IopInitializeBootDrivers().

◆ RawFsIsRawFileSystemDeviceObject()

BOOLEAN RawFsIsRawFileSystemDeviceObject ( IN PDEVICE_OBJECT  DeviceObject)

Variable Documentation

◆ _HalDispatchTable

HAL_DISPATCH _HalDispatchTable
extern

◆ _IoFileObjectType

POBJECT_TYPE _IoFileObjectType
extern

◆ IoCompletionType

◆ IopBusTypeGuidList

PIO_BUS_TYPE_GUID_LIST IopBusTypeGuidList
extern

◆ IopCompletionMapping

GENERIC_MAPPING IopCompletionMapping
extern

Definition at line 20 of file iocomp.c.

Referenced by IopCreateObjectTypes().

◆ IopDeviceActionLock

KSPIN_LOCK IopDeviceActionLock
extern

◆ IopDeviceActionRequestList

LIST_ENTRY IopDeviceActionRequestList
extern

◆ IopDeviceTreeLock

◆ IopErrorLogListHead

LIST_ENTRY IopErrorLogListHead
extern

Definition at line 30 of file error.c.

◆ IopFileMapping

GENERIC_MAPPING IopFileMapping
extern

Definition at line 49 of file iomgr.c.

Referenced by IoGetFileObjectGenericMapping(), and IopCreateObjectTypes().

◆ IopMdlLookasideList

GENERAL_LOOKASIDE IopMdlLookasideList
extern

Definition at line 84 of file iomgr.c.

Referenced by IopInitLookasideLists().

◆ IopNumTriageDumpDataBlocks

ULONG IopNumTriageDumpDataBlocks
extern

Definition at line 46 of file iomgr.c.

◆ IopReserveIrpAllocator

RESERVE_IRP_ALLOCATOR IopReserveIrpAllocator
extern

Definition at line 19 of file irp.c.

Referenced by IofCompleteRequest(), IoInitSystem(), IopAllocateReserveIrp(), and IopFreeReserveIrp().

◆ IopRootDeviceNode

◆ IopRootDriverObject

PDRIVER_OBJECT IopRootDriverObject
extern

◆ IopTraceLevel

ULONG IopTraceLevel
extern

Definition at line 16 of file iomgr.c.

◆ IopTriageDumpDataBlocks

PVOID IopTriageDumpDataBlocks[64]
extern

Definition at line 47 of file iomgr.c.

◆ IoRemoteBootClient

BOOLEAN IoRemoteBootClient
extern

Definition at line 70 of file init.c.

Referenced by ExpInitializeExecutive(), IopCreateArcNames(), and xHalIoAssignDriveLetters().

◆ PnpBusTypeGuidList

PIO_BUS_TYPE_GUID_LIST PnpBusTypeGuidList
extern