IOCTL_STORAGE_EJECTION_CONTROL - NtDoc

Native API online documentation, based on the System Informer (formerly Process Hacker) phnt headers
// ntddstor.h

// CTL_CODE(0x002d, 0x250, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_STORAGE_EJECTION_CONTROL 0x002D0940
View the official Windows Driver Kit DDI reference
// winioctl.h

// CTL_CODE(0x002d, 0x250, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_STORAGE_EJECTION_CONTROL 0x002D0940
View the official Win32 API reference

NtDoc

No description available.

Windows Driver Kit DDI reference (ni-ntddstor-ioctl_storage_ejection_control)

IOCTL_STORAGE_EJECTION_CONTROL IOCTL

Description

Locks the device to prevent removal of the media. If the driver can prevent the media from being removed while the drive is in use, the driver disables or enables the mechanism that ejects media, thereby locking the drive. A caller must open the device with FILE_READ_ATTRIBUTES to send this request.

Unlike IOCTL_STORAGE_MEDIA_REMOVAL, the driver tracks IOCTL_STORAGE_EJECTION_CONTROL requests by caller and ignores unlock requests for which it has not received a lock request from the same caller, thereby preventing other callers from unlocking the drive.

A driver for a removable-media device - can support this IOCTL must do the following:

  1. Keep a lock count, tagged by caller, in the device object extension.
  2. Keep the lock count per physical device.
  3. When called with this IOCTL, if the flag to prevent removing the media is set, increment the count; if the flag is clear and the driver has previously received a lock request from the same caller, decrement the count.
  4. Prevent removal of the media unless all lock counts are zero.

Under normal circumstances, the caller who locked the device using IOCTL_STORAGE_EJECTION_CONTROL, unlocks the device by sending IOCTL_STORAGE_EJECTION_CONTROL again with Irp->AssociatedIrp.SystemBuffer set to a boolean value of FALSE. However, sometimes the caller fails to unlock the device properly.

To ensure that media removal locks are released properly, the class driver keeps track of callers who lock the media with IOCTL_STORAGE_EJECTION_CONTROL. If the caller terminates without unlocking the device, the class driver unlocks the device.

Parameters

Major code

Input buffer

The buffer at Irp->AssociatedIrp.SystemBuffer contains a Boolean value, with TRUE indicating that the driver should lock the media in the drive.

Input buffer length

The length of a Boolean.

Output buffer

None.

Output buffer length

None.

Input/output buffer

Input/output buffer length

Status block

The Information field is set to zero. The Status field is set to STATUS_SUCCESS, or possibly to STATUS_INVALID_DEVICE_REQUEST, STATUS_NO_MEDIA_IN_DEVICE, or STATUS_DEVICE_NOT_CONNECTED.

See also

IOCTL_STORAGE_EJECT_MEDIA


Win32 API reference (ni-winioctl-ioctl_storage_ejection_control)

IOCTL_STORAGE_EJECTION_CONTROL IOCTL

Description

Enables or disables the mechanism that ejects media. Disabling the mechanism locks the drive.

To perform this operation, call the DeviceIoControl function with the following parameters.

BOOL DeviceIoControl(
  (HANDLE) hDevice,                 // handle to device
  IOCTL_STORAGE_EJECTION_CONTROL,   // dwIoControlCode
  (LPVOID) lpInBuffer,              // input buffer
  (DWORD) nInBufferSize,            // size of input buffer
  NULL,                             // lpOutBuffer
  0,                                // nOutBufferSize
  (LPDWORD) lpBytesReturned,        // number of bytes returned
  (LPOVERLAPPED) lpOverlapped       // OVERLAPPED structure
);

Parameters

Input buffer

Input buffer length

Output buffer

Output buffer length

Input/output buffer

Input/output buffer length

Status block

Irp->IoStatus.Status is set to STATUS_SUCCESS if the request is successful.

Otherwise, Status to the appropriate error condition as a NTSTATUS code.

For more information, see NTSTATUS Values.

Remarks

The driver tracks IOCTL_STORAGE_EJECTION_CONTROL requests by caller. It ignores requests to enable the ejection mechanism unless it has received a request to disable the ejection mechanism from the same caller. This prevents other callers from unlocking the drive.

See also