I'm using cdaudio both as a lib for use in client code, and via cdcd. Now, when trying to eject the CD (in a USB DVD drive named /dev/sr0 attached to a Raspi 3B), I get the following error message:
ioctl returned -1
I do not get any other error messages, not even though dmesg.
What puzzles me a bit, is your use of the CDAUDIO_EJECT command. I can't find it neither in linux/cdrom.h, nor in ioctl_list, but I do find a command named CDROMEJECT.
What's wrong here? Thank you.
Hello,
In src/compat.h we define:
So we really use CDROMEJECT.
The error message comes from this function in src/cdaudio.c:
What we could add here is an additional print of the errno (with e.g. perror()) to better understand the error. Note that libcdaudio and cdcd are currently in search for a maintainer; if you would like to improve it, please contact me.
The Linux kernel source says (in Documentation/ioctl/cdrom.txt):
Probably your error is one of the errors above. For more information on what's going on, please search for information on the Linux kernel part (internet search, ask maintainers...) as I wouldn't be able to help here.
Thanks!
Best regards
Thank you for the hints. I have already decoded the errno: It gives me 5, which means "input output error" — so the error can be literally anywhere.
UPDATE: After another user's hint, I used
straceto hunt down the cause of the error. Here is its output:For comparison, here is the
straceoutput of theejectcommand-line utility, which works flawlessly:The
ioctlcommand is exactly the same, but the CD drive is opened in a slightly different manner, namely in RDWR mode, in contrast to what you are doing:UPDATE: Looking into the sourcecode of
ejectreveals that they first check for whether the drive is read-write, or not, and then open it read-write or read-only: eject.c, lines 686 thru 694Last edit: Jacek Ruzyczka 2019-05-04
OK, I've adapted the
cd_ejectfollowing theejectutility and recompiled the library as well ascdcd, but no use: Instead of the CD, I only get theioctlerror. See the file attached for a complete output ofstracewhen invokingcdcdwith theejectcommand directly from the shell.UPDATE: After fiddling around with the
ejectutility, I found out that my drive (and many others as well, I suppose) apparently would only accept SCSI commands, so it's basically a SCSI-over-USB device:cdaudio, on the other hand, seems to support CD-ROM commands only, so this way will never work. As you may see in the sourcecode ofeject, it's a fairly complicated task. Who can implement this feature incdaudio?Last edit: Jacek Ruzyczka 2019-05-08
I've now got a solution based on the
eject_scsi ()method from theejectutility: If the oldCDROMEJECTfails, just switch to a series of SCSI commands as a fallback. Continue here: Patch #7