Why does accessing sr0 close the tray but return an error while the drive selects CD/DVD/Blu-Ray?
1
vote
0
answers
50
views
I've seen this behavior across distros (probably across operating systems, too) and across optical-media drive makes/models. It appears any CD, DVD, and/or Blu-Ray drive, if an attempt is made to
open()
/dev/sr0
while the tray is open, the tray will close, and until it is finished closing the call to open()
will block. Once the tray finishes closing, the drive enters an "identification" state in which will attempt to determine what type of media is in it (whether there's a CD, DvD, Blu-Ray, or something else in it, and therefore which laser it should use), which usually takes a few seconds, during which any calls to open()
on the device (including the call that caused the tray to close in the first place) will fail with a no media error.
Put another way:
1. The CD tray is opened and a disc is put in by the user.
2. Some command is run that will open /dev/sr0 for reading or writing (e.g. mount
, dd
, dvdbackup
etc.)
3. The CD tray will close itself, and the command will block until the tray has closed all the way.
4. Once the tray finishes closing, the command immediately reports no media and exits. The drive begins to identify the newly-loaded media.
5. The user tries to run the command again before the identification phase is complete (during which some "media present" flag is evidently not set). The command fails instantaneously with the same No Media error.
6. After a few seconds, the drive is ready to read the media.
7. The user runs the command a third time. This time the command succeeds.
My theory as to what's happening (this is only a theory):
1. During step 2 of the above, Linux makes a request to the drive. The drive sees that its tray is open, and closes it.
2. The tray finishes closing, and the drive reports to the operating system that it has entered an identification phase, probably by setting some "busy" flag and clearing "media present" or what have you.
3. Linux, seeing that the "media present" flag is clear, immediately reports to the application that there is nothing for it to do.
My first question is, why does this happen? Why doesn't Linux check the busy flag? Windows does (or at least it looks like it does; in some versions a CD icon appears next to the cursor during this identification phase). My second question is, is there any way around this? Is there any way to know, without completely bypassing the kernel, if the DVD drive is in the identification phase or if there really is no media in it?
Asked by wallefan
(199 rep)
Aug 18, 2018, 10:07 PM
Last activity: Aug 19, 2018, 03:29 AM
Last activity: Aug 19, 2018, 03:29 AM