From 9687079758bab2d3b586f89c411c06551a9a70cf Mon Sep 17 00:00:00 2001 From: rocky Date: Fri, 3 Oct 2003 01:43:45 +0000 Subject: [PATCH] BSDI fixes. --- lib/_cdio_bsdi.c | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/lib/_cdio_bsdi.c b/lib/_cdio_bsdi.c index 19a53223..ebb1ac79 100644 --- a/lib/_cdio_bsdi.c +++ b/lib/_cdio_bsdi.c @@ -1,5 +1,5 @@ /* - $Id: _cdio_bsdi.c,v 1.14 2003/10/02 02:59:58 rocky Exp $ + $Id: _cdio_bsdi.c,v 1.15 2003/10/03 01:43:45 rocky Exp $ Copyright (C) 2001 Herbert Valerio Riedel Copyright (C) 2002,2003 Rocky Bernstein @@ -27,7 +27,7 @@ # include "config.h" #endif -static const char _rcsid[] = "$Id: _cdio_bsdi.c,v 1.14 2003/10/02 02:59:58 rocky Exp $"; +static const char _rcsid[] = "$Id: _cdio_bsdi.c,v 1.15 2003/10/03 01:43:45 rocky Exp $"; #include #include @@ -45,6 +45,11 @@ static const char _rcsid[] = "$Id: _cdio_bsdi.c,v 1.14 2003/10/02 02:59:58 rocky #include #include +#define USE_ETC_FSTAB +#ifdef USE_ETC_FSTAB +#include +#endif + #include #include #include @@ -80,7 +85,7 @@ typedef struct { Return 1 if a CD-ROM. 0 if it exists but isn't a CD-ROM drive and -1 if no device exists . */ -static int +static bool cdio_is_cdrom(char *drive, char *mnttype) { bool is_cd=false; @@ -94,6 +99,11 @@ cdio_is_cdrom(char *drive, char *mnttype) /* If it does exist, verify that it's an available CD-ROM */ cdfd = open(drive, (O_RDONLY|O_EXCL|O_NONBLOCK), 0); + + /* Should we want to test the condition in more detail: + ENOENT is the error for /dev/xxxxx does not exist; + ENODEV means there's no drive present. */ + if ( cdfd >= 0 ) { if ( ioctl(cdfd, CDROMREADTOCHDR, &tochdr) != -1 ) { is_cd = true; @@ -573,29 +583,33 @@ cdio_get_devices_bsdi (void) char drive[40]; char **drives = NULL; unsigned int num_drives=0; + bool exists=true; char c; /* Scan the system for CD-ROM drives. */ -#if FINISHED - /* Now check the currently mounted CD drives */ - if (NULL != (ret_drive = cdio_check_mounts("/etc/mtab"))) { - cdio_add_device_list(&drives, drive, &num_drives); - } +#ifdef USE_ETC_FSTAB + + struct fstab *fs; + setfsent(); + + /* Check what's in /etc/fstab... */ + while (fs = getfsent()) + { + if (strncmp(fs->fs_spec, "/dev/sr", 7)) + cdio_add_device_list(&drives, fs->fs_spec, &num_drives); + } - /* Finally check possible mountable drives in /etc/fstab */ - if (NULL != (ret_drive = cdio_check_mounts("/etc/fstab"))) { - cdio_add_device_list(&drives, drive, &num_drives); - } #endif /* Scan the system for CD-ROM drives. Not always 100% reliable, so use the USE_MNTENT code above first. */ - for ( c='c'; c <='h'; c++ ) { - sprintf(drive, "/dev/rsr0%c", c); - if ( cdio_is_cdrom(drive, NULL) > 0 ) { + for ( c='0'; exists && c <='9'; c++ ) { + sprintf(drive, "/dev/rsr%cc", c); + exists = cdio_is_cdrom(drive, NULL); + if ( exists ) { cdio_add_device_list(&drives, drive, &num_drives); } }