diff --git a/configure.ac b/configure.ac index 1f068129..7c36b72d 100644 --- a/configure.ac +++ b/configure.ac @@ -19,7 +19,7 @@ define(RELEASE_NUM, 79cvs) define(CDIO_VERSION_STR, 0.$1) AC_PREREQ(2.52) -AC_REVISION([$Id: configure.ac,v 1.203 2006/11/16 00:47:28 rocky Exp $])dnl +AC_REVISION([$Id: configure.ac,v 1.204 2006/11/27 19:31:37 gmerlin Exp $])dnl AC_INIT(libcdio, CDIO_VERSION_STR(RELEASE_NUM)) AC_CONFIG_SRCDIR(src/cd-info.c) @@ -32,7 +32,7 @@ AM_INIT_AUTOMAKE([1.7]) AC_CANONICAL_HOST AM_CONFIG_HEADER(config.h) -LIBCDIO_VERSION_NUM=`echo RELEASE_NUM | cut -d . -f 1` +LIBCDIO_VERSION_NUM=`echo RELEASE_NUM | cut -d . -f 1 | tr -d a-z` AC_SUBST(LIBCDIO_VERSION_NUM) AM_MISSING_PROG(HELP2MAN, help2man, $missing_dir) @@ -480,7 +480,7 @@ AC_SUBST(LIBCDIO_SOURCE_PATH) AC_CHECK_FUNCS( [bzero drand48 ftruncate geteuid getgid \ getuid getpwuid gettimeofday lstat memcpy memset \ - rand seteuid setegid snprintf tzset vsnprintf] ) + rand seteuid setegid snprintf tzset vsnprintf readlink] ) AC_CHECK_MEMBER([struct tm.tm_gmtoff], [AC_DEFINE(HAVE_TM_GMTOFF, 1, diff --git a/include/cdio/util.h b/include/cdio/util.h index d1d3e8ac..11c8e556 100644 --- a/include/cdio/util.h +++ b/include/cdio/util.h @@ -1,5 +1,5 @@ /* - $Id: util.h,v 1.10 2006/03/18 00:53:20 rocky Exp $ + $Id: util.h,v 1.11 2006/11/27 19:31:37 gmerlin Exp $ Copyright (C) 2000 Herbert Valerio Riedel Copyright (C) 2004, 2005, 2006 Rocky Bernstein @@ -100,6 +100,8 @@ _cdio_strsplit(const char str[], char delim); uint8_t cdio_to_bcd8(uint8_t n); uint8_t cdio_from_bcd8(uint8_t p); +void cdio_follow_symlink (const char * src, char * dst); + #ifdef __cplusplus } #endif diff --git a/lib/driver/_cdio_generic.c b/lib/driver/_cdio_generic.c index 5ad63a62..13ce7ba2 100644 --- a/lib/driver/_cdio_generic.c +++ b/lib/driver/_cdio_generic.c @@ -1,5 +1,5 @@ /* - $Id: _cdio_generic.c,v 1.22 2006/03/26 02:35:26 rocky Exp $ + $Id: _cdio_generic.c,v 1.23 2006/11/27 19:31:37 gmerlin Exp $ Copyright (C) 2004, 2005, 2006 Rocky Bernstein @@ -26,7 +26,7 @@ # include "config.h" #endif -static const char _rcsid[] = "$Id: _cdio_generic.c,v 1.22 2006/03/26 02:35:26 rocky Exp $"; +static const char _rcsid[] = "$Id: _cdio_generic.c,v 1.23 2006/11/27 19:31:37 gmerlin Exp $"; #include #include @@ -38,6 +38,7 @@ static const char _rcsid[] = "$Id: _cdio_generic.c,v 1.22 2006/03/26 02:35:26 ro #endif /*HAVE_UNISTD_H*/ #include +#include #include #include @@ -221,24 +222,22 @@ cdio_add_device_list(char **device_list[], const char *drive, { if (NULL != drive) { unsigned int j; - + char real_device_1[PATH_MAX]; + char real_device_2[PATH_MAX]; + cdio_follow_symlink(drive, real_device_1); /* Check if drive is already in list. */ for (j=0; j<*num_drives; j++) { - if (strcmp((*device_list)[j], drive) == 0) break; + cdio_follow_symlink((*device_list)[j], real_device_2); + if (strcmp(real_device_1, real_device_2) == 0) break; } if (j==*num_drives) { /* Drive not in list. Add it. */ (*num_drives)++; - if (*device_list) { - *device_list = realloc(*device_list, (*num_drives) * sizeof(char *)); - } else { - /* num_drives should be 0. Add assert? */ - *device_list = malloc((*num_drives) * sizeof(char *)); + *device_list = realloc(*device_list, (*num_drives) * sizeof(char *)); + (*device_list)[*num_drives-1] = strdup(drive); } - (*device_list)[*num_drives-1] = strdup(drive); - } } else { (*num_drives)++; if (*device_list) { diff --git a/lib/driver/gnu_linux.c b/lib/driver/gnu_linux.c index c3737ea2..d07cca9e 100644 --- a/lib/driver/gnu_linux.c +++ b/lib/driver/gnu_linux.c @@ -1,5 +1,5 @@ /* - $Id: gnu_linux.c,v 1.26 2006/10/21 11:38:16 rocky Exp $ + $Id: gnu_linux.c,v 1.27 2006/11/27 19:31:37 gmerlin Exp $ Copyright (C) 2001 Herbert Valerio Riedel Copyright (C) 2002, 2003, 2004, 2005, 2006 Rocky Bernstein @@ -28,7 +28,7 @@ # include "config.h" #endif -static const char _rcsid[] = "$Id: gnu_linux.c,v 1.26 2006/10/21 11:38:16 rocky Exp $"; +static const char _rcsid[] = "$Id: gnu_linux.c,v 1.27 2006/11/27 19:31:37 gmerlin Exp $"; #include #include @@ -595,30 +595,6 @@ get_track_msf_linux(void *p_user_data, track_t i_track, msf_t *msf) } } -/*! - Follow symlinks until we have the real device file - (idea taken from libunieject). -*/ - -static void follow_symlink (const char * src, char * dst) { - char tmp_src[PATH_MAX]; - char tmp_dst[PATH_MAX]; - - int len; - - strcpy(tmp_src, src); - while(1) { - len = readlink(tmp_src, tmp_dst, PATH_MAX); - if(len < 0) { - strcpy(dst, tmp_src); - return; - } - else { - tmp_dst[len] = '\0'; - strcpy(tmp_src, tmp_dst); - } - } -} /*! Check, if a device is mounted and return the target (=mountpoint) @@ -642,12 +618,12 @@ static int is_mounted (const char * device, char * target) { if(!fp) return 0; /* Get real device */ - follow_symlink(device, real_device_1); + cdio_follow_symlink(device, real_device_1); /* Read entries */ while ( fscanf(fp, "%s %s %*s %*s %*d %*d\n", file_device, file_target) != EOF ) { - follow_symlink(file_device, real_device_2); + cdio_follow_symlink(file_device, real_device_2); if(!strcmp(real_device_1, real_device_2)) { strcpy(target, file_target); fclose(fp); @@ -1351,9 +1327,20 @@ set_arg_linux (void *p_user_data, const char key[], const char value[]) static char checklist1[][40] = { {"cdrom"}, {"dvd"}, {""} }; -static char checklist2[][40] = { - {"?a hd?"}, {"?0 scd?"}, {"?0 sr?"}, {""} -}; + +static struct + { + const char * format; + int num_min; + int num_max; + } +checklist2[] = + { + { "/dev/hd%c", 'a', 'z' }, + { "/dev/scd%d", 0, 27 }, + { "/dev/sr%d", 0, 27 }, + { /* End of array */ } + }; /* Set CD-ROM drive speed */ static driver_return_code_t @@ -1379,15 +1366,14 @@ cdio_get_devices_linux (void) unsigned int i; char drive[40]; char *ret_drive; - bool exists; char **drives = NULL; unsigned int num_drives=0; - + /* Scan the system for CD-ROM drives. */ for ( i=0; strlen(checklist1[i]) > 0; ++i ) { sprintf(drive, "/dev/%s", checklist1[i]); - if ( (exists=is_cdrom_linux(drive, NULL)) > 0 ) { + if ( is_cdrom_linux(drive, NULL) > 0 ) { cdio_add_device_list(&drives, drive, &num_drives); } } @@ -1407,17 +1393,11 @@ cdio_get_devices_linux (void) /* Scan the system for CD-ROM drives. Not always 100% reliable, so use the USE_MNTENT code above first. */ - for ( i=0; strlen(checklist2[i]) > 0; ++i ) { + for ( i=0; checklist2[i].format; ++i ) { unsigned int j; - char *insert; - exists = true; - for ( j=checklist2[i][1]; exists; ++j ) { - sprintf(drive, "/dev/%s", &checklist2[i][3]); - insert = strchr(drive, '?'); - if ( insert != NULL ) { - *insert = j; - } - if ( (exists=is_cdrom_linux(drive, NULL)) > 0 ) { + for ( j=checklist2[i].num_min; j<=checklist2[i].num_max; ++j ) { + sprintf(drive, checklist2[i].format, j); + if ( (is_cdrom_linux(drive, NULL)) > 0 ) { cdio_add_device_list(&drives, drive, &num_drives); } } @@ -1439,14 +1419,13 @@ cdio_get_default_device_linux(void) #else unsigned int i; char drive[40]; - bool exists; char *ret_drive; /* Scan the system for CD-ROM drives. */ for ( i=0; strlen(checklist1[i]) > 0; ++i ) { sprintf(drive, "/dev/%s", checklist1[i]); - if ( (exists=is_cdrom_linux(drive, NULL)) > 0 ) { + if ( is_cdrom_linux(drive, NULL) > 0 ) { return strdup(drive); } } @@ -1462,17 +1441,11 @@ cdio_get_default_device_linux(void) /* Scan the system for CD-ROM drives. Not always 100% reliable, so use the USE_MNTENT code above first. */ - for ( i=0; strlen(checklist2[i]) > 0; ++i ) { + for ( i=0; checklist2[i].format; ++i ) { unsigned int j; - char *insert; - exists = true; - for ( j=checklist2[i][1]; exists; ++j ) { - sprintf(drive, "/dev/%s", &checklist2[i][3]); - insert = strchr(drive, '?'); - if ( insert != NULL ) { - *insert = j; - } - if ( (exists=is_cdrom_linux(drive, NULL)) > 0 ) { + for ( j=checklist2[i].num_min; j<=checklist2[i].num_max; ++j ) { + sprintf(drive, checklist2[i].format, j); + if ( is_cdrom_linux(drive, NULL) > 0 ) { return(strdup(drive)); } } diff --git a/lib/driver/util.c b/lib/driver/util.c index 8eb9487b..21f22710 100644 --- a/lib/driver/util.c +++ b/lib/driver/util.c @@ -1,5 +1,5 @@ /* - $Id: util.c,v 1.3 2006/03/18 00:53:20 rocky Exp $ + $Id: util.c,v 1.4 2006/11/27 19:31:37 gmerlin Exp $ Copyright (C) 2000 Herbert Valerio Riedel Copyright (C) 2003, 2004, 2005 Rocky Bernstein @@ -27,6 +27,11 @@ #include #include #include +#include + +#ifdef HAVE_UNISTD_H // readlink +#include +#endif #ifdef HAVE_INTTYPES_H #include "inttypes.h" @@ -36,7 +41,7 @@ #include #include -static const char _rcsid[] = "$Id: util.c,v 1.3 2006/03/18 00:53:20 rocky Exp $"; +static const char _rcsid[] = "$Id: util.c,v 1.4 2006/11/27 19:31:37 gmerlin Exp $"; size_t _cdio_strlenv(char **str_array) @@ -145,6 +150,36 @@ cdio_from_bcd8(uint8_t p) return (0xf & p)+(10*(p >> 4)); } +/*! + Follow symlinks until we have the real device file + (idea taken from libunieject). +*/ + +void cdio_follow_symlink (const char * src, char * dst) { +#ifdef HAVE_READLINK + char tmp_src[PATH_MAX]; + char tmp_dst[PATH_MAX]; + + int len; + + strcpy(tmp_src, src); + while(1) { + len = readlink(tmp_src, tmp_dst, PATH_MAX); + if(len < 0) { + strcpy(dst, tmp_src); + return; + } + else { + tmp_dst[len] = '\0'; + strcpy(tmp_src, tmp_dst); + } + } +#else + strcpy(dst, src); +#endif + +} + /* * Local variables: