NTSTATUS
IoCreateDevice(
IN PDRIVER_OBJECT DriverObject,
IN ULONG DeviceExtensionSize,
IN PUNICODE_STRING DeviceName, /* optional */
IN DEVICE_TYPE DeviceType,
IN ULONG DeviceCharacteristics,
IN BOOLEAN Exclusive,
OUT PDEVICE_OBJECT *DeviceObject
);
IoCreateDevice allocates memory for and initializes a device object for use by a driver. A device object represents a physical, virtual, or logical device whose driver is being loaded into the system, or it represents a virtual or logical device whose driver is required to support the reconfiguration of its device objects dynamically.
IoCreateDevice can return one of the following NTSTATUS values:
STATUS_SUCCESS
STATUS_INSUFFICIENT_RESOURCES
STATUS_OBJECT_NAME_EXISTS
STATUS_OBJECT_NAME_COLLISION
This routine allocates space in nonpaged pool for the driver-defined device extension associated with the device object, so that the device extension is accessible to the driver in any execution context and at any IRQL. The returned device extension is initialized with zeros.
In general, drivers that set Exclusive to TRUE control interactive devices, such as video, serial, parallel, or sound devices.
Device objects for disks, tapes, CD ROMs, and RAM disks are given a Volume Parameter Block (VPB) that is initialized to indicate that the volume has never been mounted on the device.
Each driver must create at least one named device object by calling IoCreateDevice. Otherwise, no I/O requests can be sent to the driver. An unnamed device object is invisible to other drivers except, possibly, FSDs and to user-mode protected subsystems because a symbolic link cannot be set up for an unnamed device object. Consequently, higher-level drivers cannot attach their device objects to an unnamed device object nor can the unnamed object be the target of an IRP.
If a driver’s call to IoCreateDevice returns an error, it should release any resources it allocated for that device. If the driver cannot set up a device object to represent any of the devices it controls, that driver should not load.
Certain device drivers call IoCreateDevice from a Dispatch routine. In particular, disk drivers must call IoCreateDevice in response to a device control request to repartition a disk dynamically.
Callers of IoCreateDevice must be running at IRQL PASSIVE_LEVEL.
DEVICE_OBJECT, IoAttachDevice, IoAttachDeviceToDeviceStack, IoCreateSymbolicLink, IoDeleteDevice