Leggo my Eggo! (The CD-ROM eject fix)

About SheepShaver, a PPC Mac emulator for Windows, MacOS X, and Linux that can run System 7.5.3 to MacOS 9.0.4.

Moderators: Cat_7, Ronald P. Regensburg, ClockWise

Post Reply
User avatar
mrob27
Student Driver
Posts: 13
Joined: Sun Mar 18, 2012 9:35 am
Location: East coast, USA

Leggo my Eggo! (The CD-ROM eject fix)

Post by mrob27 »

This affects both BasiliskII and SheepShaver, on Mac OS X host systems, when the "nocdrom" setting is set to "true".

I keep lots of old files archived on CD-ROMs, and I often use these CD-ROMs while BasiliskII or SheepShaver is running. The CD-ROMs are for MacOS X, they wouldn't work in the emulator even if I tried, so I have "nocdrom true" in both my .basilisk_ii_prefs and .sheepshaver_prefs files.

There has been a bug for many years that causes this setting to only partly work. "nocdrom true" prevents the emulator from emulating the CD-ROM, but if you insert a disc after launching the emulator, it still grabs onto the CD-ROM as if it were being used, and it never lets go. If you want to eject the CD-ROM, the Finder removes the icon from the desktop but it doesn't eject. Disk Utility tells you it can't be unmounted. You have to quit BasiliskII or SheepShaver before ejecting it.

A little searching through the source code turns up the routine "SysMediaArrived", which is defined in sys_unix.cpp and invoked from sys_darwin.cpp. As you can see, it does perform an appropriate test:

Code: Select all

  if (type == MEDIA_CD && !PrefsFindBool("nocdrom")) 
but this test only affects whether or not it does the following "PrefsReplaceString("cdrom", path);" step.

The rest of the actions, including in particular the call to "cdrom_open(fh, path)", are performed regardless of the "nocdrom" setting.

This makes it open the CD-ROM device (such as "/dev/disk1" on one of the systems I tested) which is why the disc cannot be ejected. Unfortunately, there is no way to get it to close the device later. Because CD-ROM is turned off, the disc never appears inside the emulated MacOS, and so there is no way to ask the emulated Mac to eject it.

The fix I decided to try is relatively simple. If "nocdrom" is true, the entire SysMediaArrived routine is superfluous. So I added a test at the very beginning of SysMediaArrived that exits:

Code: Select all

    if ((type == MEDIA_CD) && PrefsFindBool("nocdrom")) {
        // Do nothing                                                           
        return;
    }
With this change I am able to insert and eject as many CD-ROMs as I want while SheepShaver is running, without having to make SheepShaver quit.

There are probably other ways to fix this. SysMediaArrived is called from media_arrived in sys_darwin.cpp, and media_arrived is installed by a call to IOServiceAddMatchingNotification. I suspect that one could put a test of PrefsFindBool("nocdrom") somewhere in here to prevent installing the notification handler in the first place. But I don't know what else that might affect (there might be other media that can arrive apart from CDROMs).

Also, the presence of the incorrect code in sys_unix.cpp makes it look like this bug might also affect Linux users.

Comments welcome...
Robert Munafo - mrob.com/mac
Myrd
Granny Smith
Posts: 107
Joined: Mon Dec 25, 2006 4:09 am

Re: Leggo my Eggo! (The CD-ROM eject fix)

Post by Myrd »

I've replied on the basilisk-dev thread.
Post Reply