Because the definitions have been removed from the headers,
#define B_LARGE_ICON 32
#define B_MINI_ICON 16
uchar icon[B_LARGE_ICON * B_LARGE_ICON];
uchar icon_mini[B_MINI_ICON * B_MINI_ICON];
status_t
vd_control (void *cookie, uint32 msg, void *arg1, size_t len)
{
switch (msg)
{
case B_GET_ICON:
switch (((device_icon *)arg1)->icon_size)
{
case B_LARGE_ICON:
memcpy(((device_icon *)arg1)->icon_data, icon_disk,
B_LARGE_ICON * B_LARGE_ICON);
break;
case B_MINI_ICON:
memcpy(((device_icon *)arg1)->icon_data, icon_disk_mini,
B_MINI_ICON * B_MINI_ICON);
break;
default:
return B_BAD_TYPE;
};
default:
return B_NO_ERROR;
}
}
"
You may remember that BeOS Release 3 wasn't up to handling removable
media in a flexible way. The SCSI and IDE drivers would fail to open
if there
was no media in a drive. This caused applications like DriveSetup
and Tracker to open and close devices to check whether the media in
the drives had changed. There are several disadvantages to doing this:
-
The driver may be reloaded each time you check for media
-
You can't get information about drives with no media
-
You can't operate devices with no media
-
The driver decides if you should wait on a busy drive
Let's look more closely at these problems. First, since BeOS unloads
drivers that are not in use, using open/close to detect media presence
often causes the driver to be reloaded. If the driver doesn't publish
other devices that are in use, keeping the driver loaded, the device
can never be opened when there is no media. The result is that every
time you check for media the driver has to be loaded and initialized,
then open is called, open fails, and the driver is unloaded.
Since the IDE and SCSI drivers are built into the kernel, this is
only a problem in Release 3 if you use third party drivers.
The second problem is more serious. That is, you can't get any information
about a device. This means that an application like CDPlayer in Release
3 uses special devices that store information about all IDE and SCSI
devices.
It then uses this information to tell which devices are CD-ROM drives.
So, for example, if you want to add a driver for a sound card CD-ROM
interface, CDPlayer would not find your device.
A less serious problem is that you can't see the icon for a device
unless there is media in the drive.
Third, you can't operate devices with no media. This means that
you can only eject media, you can't open an empty tray or close the
tray of a CD-ROM drive.
Finally, the driver decides if you should wait on a busy drive.
This means that
either the open fails or it blocks until the drive is ready. The application
may
want to make that decision, so it can inform the user that the drive
is busy,
instead of just blocking.
R4 solves these problems by adding an ioctl, B_GET_MEDIA_STATUS
,
to get the media status. Open will succeed even if there is no media
in the drive, and the driver will accept commands that do not require
the media to be present.
The following code shows how this ioctl can be used.
status_t media_status;
if( ioctl( devfd,
B_GET_MEDIA_STATUS,
&media_status,
sizeof(status_t)) < 0 )
{
// old driver, abort
}
switch( media_status ) {
case B_NO_ERROR:
// drive ready with media
// enable all controls
break;
case B_DEV_NO_MEDIA:
// no media in drive
// disable controls that need media
// delete information about media
// load eject still works
break;
case B_DEV_NOT_READY:
// drive not ready.
// disable controls, keep media information
break;
case B_DEV_MEDIA_CHANGED:
// media in drive has changed
// delete old and collect new information about media
break;
case B_DEV_MEDIA_CHANGE_REQUESTED:
// user pressed eject button on drive
break;
#if R5
case B_DEV_DOOR_OPEN;
// eject/load button loads
// handle ad B_DEV_NO_MEDIA;
break;
#endif
default:
// unknown state
break;
}
R4 adds another ioctl, B_LOAD_MEDIA
, that tries to
load media into the
drive. Most CD-ROM drives use a tray to load CDs; for these drives
B_LOAD_MEDIA
closes the tray if it is open. R4 does not
define a separate status for a drive with the door/tray open. If you
want a combined load/eject button, you need to know if the door is
open or not. If you need to do this, you can contact me about how
to use the raw SCSI/ATAPI command interface, or you can wait for R5.
"
BE ENGINEERING INSIGHTS: Removable Media
By Arve Hjonnevag arve@be.com CD Rom Drive Issues