Hi all,

I just updated gmerlin (http://gmerlin.sf.net/) for use of libcdio.
It's was really easy and everything works great so far (tested
analog audio playback and ripping via cdparanoia) except for one:
The linux driver detects CD Drives only, when a disk is in the
drive. I managed to track the problem down to 2 issues:

1. In the function is_cdrom_linux(...) in the file lib/driver/gnu_linux.c,
   the CDROMREADTOCHDR ioctl gets called, which fails when the drive is
   empty. The CDROM_GET_CAPABILITY ioctl always succeeds for CDrom drives
   and fails for hard disks etc.

2. For some reasons, at least my (2.6.10) Kernel fails to open empty drives,
   when only O_RDONLY is used. Changing the open flag to
   O_RDONLY|O_NONBLOCK, the call succeeds also for emtpy drives.
   By the way, the cdrom header file in the kernel says explicitely,
   that O_RDONLY|O_NONBLOCK should used whenever a cdrom is touched.

The attached patch against 0.73 (1) fixes the ioctl and (2) introduces
an additional flag argument for the function cdio_generic_init. The
linux driver will use O_RDONLY|O_NONBLOCK, the other drivers which use
this function (osx and solaris) use O_RDONLY to resemble the old behaviour
(I don't have access to these systems).

Please cc me, I'm not subscribed

Cheers

Burkhard


diff -ur libcdio-0.73.orig/lib/driver/_cdio_generic.c 
libcdio-0.73/lib/driver/_cdio_generic.c
--- libcdio-0.73.orig/lib/driver/_cdio_generic.c        2005-03-01 
01:40:39.000000000 +0100
+++ libcdio-0.73/lib/driver/_cdio_generic.c     2005-04-22 22:52:47.513505168 
+0200
@@ -105,7 +105,7 @@
   Initialize CD device.
  */
 bool
-cdio_generic_init (void *user_data)
+cdio_generic_init (void *user_data, int open_flags)
 {
   generic_img_private_t *p_env = user_data;
   if (p_env->init) {
@@ -113,7 +113,7 @@
     return false;
   }
   
-  p_env->fd = open (p_env->source_name, O_RDONLY, 0);
+  p_env->fd = open (p_env->source_name, open_flags, 0);
 
   if (p_env->fd < 0)
     {
diff -ur libcdio-0.73.orig/lib/driver/generic.h 
libcdio-0.73/lib/driver/generic.h
--- libcdio-0.73.orig/lib/driver/generic.h      2005-03-01 01:40:39.000000000 
+0100
+++ libcdio-0.73/lib/driver/generic.h   2005-04-22 22:53:53.453480768 +0200
@@ -101,7 +101,7 @@
   /*!
     Initialize CD device.
   */
-  bool cdio_generic_init (void *p_env);
+  bool cdio_generic_init (void *p_env, int open_mode);
 
   /*!
     Reads into buf the next size bytes.
diff -ur libcdio-0.73.orig/lib/driver/gnu_linux.c 
libcdio-0.73/lib/driver/gnu_linux.c
--- libcdio-0.73.orig/lib/driver/gnu_linux.c    2005-03-29 14:00:23.000000000 
+0200
+++ libcdio-0.73/lib/driver/gnu_linux.c 2005-04-22 22:54:55.817000072 +0200
@@ -724,7 +724,6 @@
 {
   bool is_cd=false;
   int cdfd;
-  struct cdrom_tochdr    tochdr;
   
   /* If it doesn't exist, return -1 */
   if ( !cdio_is_device_quiet_generic(drive) ) {
@@ -734,7 +733,7 @@
   /* If it does exist, verify that it's an available CD-ROM */
   cdfd = open(drive, (O_RDONLY|O_NONBLOCK), 0);
   if ( cdfd >= 0 ) {
-    if ( ioctl(cdfd, CDROMREADTOCHDR, &tochdr) != -1 ) {
+    if ( ioctl(cdfd, CDROM_GET_CAPABILITY, 0) != -1 ) {
       is_cd = true;
     }
     close(cdfd);
@@ -1499,7 +1498,7 @@
 
   ret->driver_id = DRIVER_LINUX;
 
-  if (cdio_generic_init(_data)) {
+  if (cdio_generic_init(_data, O_RDONLY|O_NONBLOCK)) {
     return ret;
   } else {
     cdio_generic_free (_data);
diff -ur libcdio-0.73.orig/lib/driver/osx.c libcdio-0.73/lib/driver/osx.c
--- libcdio-0.73.orig/lib/driver/osx.c  2005-03-13 16:24:47.000000000 +0100
+++ libcdio-0.73/lib/driver/osx.c       2005-04-22 22:56:29.555749616 +0200
@@ -1821,7 +1821,7 @@
 
   ret->driver_id = DRIVER_OSX;
 
-  if (cdio_generic_init(_data) && init_osx(_data))
+  if (cdio_generic_init(_data, O_RDONLY) && init_osx(_data))
     return ret;
   else {
     cdio_generic_free (_data);
diff -ur libcdio-0.73.orig/lib/driver/solaris.c 
libcdio-0.73/lib/driver/solaris.c
--- libcdio-0.73.orig/lib/driver/solaris.c      2005-03-19 19:51:30.000000000 
+0100
+++ libcdio-0.73/lib/driver/solaris.c   2005-04-22 22:56:50.660541200 +0200
@@ -258,7 +258,7 @@
 init_solaris (_img_private_t *p_env)
 {
 
-  if (!cdio_generic_init(p_env)) return false;
+  if (!cdio_generic_init(p_env, O_RDONLY)) return false;
   
   p_env->access_mode = _AM_SUN_CTRL_SCSI;    
 

_______________________________________________
Libcdio-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/libcdio-devel

Reply via email to