IOCTL_STORAGE_MCN_CONTROL - NtDoc

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

// CTL_CODE(0x002d, 0x251, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_STORAGE_MCN_CONTROL 0x002D0944
View the official Windows Driver Kit DDI reference
// winioctl.h

// CTL_CODE(0x002d, 0x251, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_STORAGE_MCN_CONTROL 0x002D0944
View the official Win32 API reference

NtDoc

No description available.

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

IOCTL_STORAGE_MCN_CONTROL IOCTL

Description

Temporarily enables or disables delivery of the custom PnP events GUID_IO_MEDIA_ARRIVAL and GUID_IO_MEDIA_REMOVAL on a removable-media device. This, in turn, enables or disables media change detection (AutoPlay) for the device if the caller has opened the device with FILE_READ_ATTRIBUTES access and if the device has AutoPlay enabled in the registry. The caller must not open the device for read or write access or the IOCTL operation will fail. This IOCTL has no effect on the AutoPlay setting in the registry.

A driver for such a removable-media device must do the following:

  1. Keep a count of disable requests, per physical device, in the device object extension.
  2. When called with this IOCTL, if the flag to disable media change detection is set, increment the count; if the flag is clear, decrement the count.
  3. Set the media change event for the device when the media state is changed only if the disable request count is zero.

When the IRP_MJ_DEVICE_CONTROL IRP that contains this IOCTL is passed to the SCSI class driver, the FileObject member of the current IO_STACK_LOCATION must point to a valid file object. The SCSI class driver requires a file object for cases where a user-mode application that is disabling or enabling AutoPlay terminates unexpectedly. In such cases, the SCSI class driver uses the file object to reenable media change detection. Because the file object is necessary for proper clean-up, the SCSI class driver will cause the IRP to fail with an error message of STATUS_INVALID_PARAMETER if the FileObject member of IO_STACK_LOCATION does not point to a valid file object. If a user-mode application opens the device, then the I/O manager initializes this member, but kernel-mode driver writers should not assume that FileObject will be properly initialized when the IRP is generated by a user-mode application. If, for instance, a user-mode application mistakenly opens the device for either read or write access before sending the IOCTL, then the device control IRP will be routed through the file system, preventing the SCSI class driver and the device driver from directly accessing the device's file object.

Parameters

Major code

Input buffer

The buffer at Irp->AssociatedIrp.SystemBuffer contains a Boolean value, with TRUE indicating that the driver should disable media change detection.

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_BUFFER_TOO_SMALL, STATUS_INVALID_PARAMETER, or STATUS_INVALID_DEVICE_STATE.

See also

IO_STACK_LOCATION


Win32 API reference (ni-winioctl-ioctl_storage_mcn_control)

IOCTL_STORAGE_MCN_CONTROL IOCTL

Description

Enables or disables media change notification. Disabling media change notification prevents the GUID_IO_MEDIA_ARRIVAL and GUID_IO_MEDIA_REMOVAL events.

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

BOOL DeviceIoControl(
  (HANDLE) hDevice,             // handle to device
  IOCTL_STORAGE_MCN_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.

See also