Previous Topic Next Topic
 

Windows' CD-ROM class driver includes support for an IOCTL_CDROM_EXCLUSIVE_ACCESS request. This request instructs the CD-ROM class driver to:

  • Report the access state of a CD-ROM device
  • Lock a CD-ROM device for exclusive access
  • Unlock a CD-ROM device for exclusive access

CD/DVD/BD recording applications use this IOCTL to ensure that they have exclusive access to the device while they are recording to it. This utility, included with busTRACE 10.0, provides a means for you to monitor which application has received exclusive access to the device. You can run this utility from the busTRACE Start Menu. Here is a sample screenshot:

In this sample, we are using Windows to erase a CD-RW disc in our HL-DT-ST DVD recorder. Note how the application shows you that "Windows" currently has exclusive access to the device.

When you select a CD/DVD/BD device, the toolbar buttons will become enabled. If you are a software developer, you can use these buttons to force a lock of the drive to see how your software handles a "locked" condition.

Lock (dismount)

This option is used to lock a CD-ROM device for exclusive access. The RequestType field is set to ExclusiveAccessLockDevice and the Flags field is set to 0. See below for a detailed description.

NOTE: If the lock fails, because a file system is mounted on the drive, this utility will ask you if you want to dismount the file system and try again.

Lock (no dismount)

This option is used to lock a CD-ROM device for exclusive access. The RequestType field is set to ExclusiveAccessLockDevice and the Flags field is set to 1. See below for a detailed description.

Unlock

This option is used to unlock a CD-ROM device that the application locked for exclusive access. The RequestType field is set to ExclusiveAccessUnlockDevice. See below for a detailed description.

Even if the device is locked by a different application, we will leave this button enabled and allow you to attempt to unlock it. Such a request will fail, as expected. We leave this button enabled to allow the class driver to be exercised with Unlock requests coming from an application that did not receive the exclusive lock.

Extra

Clicking on this option will bring down a drop down menu of a few simple IOCTLs that you can send. Prefer to the Windows Driver Kit (WDK) for details. The following IOCTLs are available:

IOCTL_STORAGE_MCN_CONTROL - Disable MCN
IOCTL_STORAGE_MCN_CONTROL - Enable MCN
IOCTL_STORAGE_EJECT_MEDIA
IOCTL_STORAGE_LOAD_MEDIA
IOCTL_STORAGE_LOAD_MEDIA2

The following information is available in more detail within the Windows Driver Kit (WDK). We provide some basic information so that you can better understand what our application is doing.

Report the access state of a CD-ROM device

To determine the current access state of a CD-ROM device, we issue an IOCTL_CDROM_EXCLUSIVE_ACCESS with a CDROM_EXCLUSIVE_ACCESS structure to the class driver. This structure is defined in the WDK as follows:

typedef struct _CDROM_EXCLUSIVE_ACCESS {

    EXCLUSIVE_ACCESS_REQUEST_TYPE RequestType;

    ULONG Flags;

} CDROM_EXCLUSIVE_ACCESS, *PCDROM_EXCLUSIVE_ACCESS;

 

The EXCLUSIVE_ACCESS_REQUEST_TYPE-typed enumeration value is defined as:

typedef enum _EXCLUSIVE_ACCESS_REQUEST_TYPE {

    ExclusiveAccessQueryState,

    ExclusiveAccessLockDevice,

    ExclusiveAccessUnlockDevice

} EXCLUSIVE_ACCESS_REQUEST_TYPE, *PEXCLUSIVE_ACCESS_REQUEST_TYPE;

 

We set the RequestType field to ExclusiveAccessQueryState and set the Flags field to zero. The CD-ROM class driver then returns to us a CDROM_EXCLUSIVE_LOCK_STATE structure. This structure is defined as:

typedef struct _CDROM_EXCLUSIVE_LOCK_STATE {

    BOOLEAN LockState;

    UCHAR CallerName[CDROM_EXCLUSIVE_CALLER_LENGTH];

} CDROM_EXCLUSIVE_LOCK_STATE, *PCDROM_EXCLUSIVE_LOCK_STATE;

 

The LockState field returns TRUE if the device is locked, else FALSE. If the device is locked, we can look at the returned CallerName field to determine who has received an exclusive lock on the device.

Lock a CD-ROM device for exclusive access

To gain exclusive access to a CD/DVD/BD device, we issue an IOCTL_CDROM_EXCLUSIVE_ACCESS with a CDROM_EXCLUSIVE_LOCK structure to the class driver. This structure is defined in the WDK as follows:

typedef struct _CDROM_EXCLUSIVE_LOCK {

    CDROM_EXCLUSIVE_ACCESS Access;

    UCHAR CallerName[CDROM_EXCLUSIVE_CALLER_LENGTH];

} CDROM_EXCLUSIVE_LOCK, *PCDROM_EXCLUSIVE_LOCK;

 

See above for a definition of the CDROM_EXCLUSIVE_ACCESS structure. To lock the device, we set the Access.RequestType field to ExclusiveAccessLockDevice. We set the Flags field to 0 to use with a dismounted file system or 1 to ignore the file system mount. We also set the CallerName field with an identifier string.

Unlock a CD-ROM device

To release our exclusive lock on a CD/DVD/BD device, we issue an IOCTL_CDROM_EXCLUSIVE_ACCESS with a CDROM_EXCLUSIVE_LOCK structure to the class driver. See above for a definition. We set the Access.RequestType field to ExclusiveAccessUnlockDevice.

Additional Information

Full information on IOCTL_CDROM_EXCLUSIVE_ACCESS can be found in Microsoft's Windows Driver Kit (WDK). Structure declarations can be found in the WDK file ntddcdrm.h.