IOCTL_STORAGE_MEDIA_REMOVAL - NtDoc

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

// CTL_CODE(0x002d, 0x201, METHOD_BUFFERED, FILE_READ_ACCESS)
#define IOCTL_STORAGE_MEDIA_REMOVAL 0x002D4804
View the official Windows Driver Kit DDI reference
// winioctl.h

// CTL_CODE(0x002d, 0x201, METHOD_BUFFERED, FILE_READ_ACCESS)
#define IOCTL_STORAGE_MEDIA_REMOVAL 0x002D4804
View the official Win32 API reference

NtDoc

No description available.

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

IOCTL_STORAGE_MEDIA_REMOVAL 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, it disables or enables the mechanism that ejects media on a device - the caller has opened for read or write access.

Unlike IOCTL_STORAGE_EJECTION_CONTROL, for which the driver tracks requests by caller, the driver ignores IOCTL_STORAGE_MEDIA_REMOVAL unlock requests only if its lock count is already zero, thereby allowing any caller to unlock the drive.

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

  1. Keep a lock count 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, decrement the count.
  4. Prevent removal of the media unless all lock counts are zero.

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_EJECTION_CONTROL


Win32 API reference (ni-winioctl-ioctl_storage_media_removal)

IOCTL_STORAGE_MEDIA_REMOVAL IOCTL

Description

Enables or disables the mechanism that ejects media, for those devices possessing that locking capability.

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

BOOL DeviceIoControl(
  (HANDLE) hDevice,             // handle to device
  IOCTL_STORAGE_MEDIA_REMOVAL,  // 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 IOCTL_STORAGE_MEDIA_REMOVAL control code is valid only for devices that support removable media.

See also