When having the sources helps

So, tonight I didn’t sleep at all. This was planned and intended, but that is another story.

So, while I was passing the time, I decided it was the case to work a while more on unieject. First I decided to release a 5.3.1 version to fix a segmentation fault and to update translations.

Then after looking at the new eject -h output, I decided to implement the traytoggle option, so I started adding the support inside unieject for that, but I had no idea how to check if I had to eject or close the tray, so I looked at original eject’s code, as usual. The code there is pretty experimental, I’d say: it measures the time needed for the tray to close, and if it’s lower than a given value, it then ejects the tray.

Not sure what you think, but I don’t like such a method :)

There had to be a way to tell if the tray is open or closed, so I started looking into raw MMC commands. Unfortunately I still don’t have a proper documentation for MMC commands, and that sucks, I should probably look for one, but anyway.

Googling, I was able to find from Apple’s OpenSource pages one of the headers for the SCSI interface, and in that I found some command that had an interesting name: GET_EVENT_STATUS_NOTIFICATION. Googling again for that, I found the IOSCSIMultimediaCommandsDevice::GetTrayState() function, that was exactly what I needed :)

After looking a bit also to libcdio sources, I was able to put that in a function that actually checks the status of the tray before deciding to open or close it, adding support for traytoggle to unieject in a saner way than original eject.

Now, who said that having access to the source, even under a restrictive license, is not a good thing? :)

One thought on “When having the sources helps

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s