From 6029b6c3d75296e2d56e06c340956f2d982fea75 Mon Sep 17 00:00:00 2001 From: rocky Date: Sat, 23 Jul 2005 21:36:54 +0000 Subject: [PATCH] =?UTF-8?q?Patch=20from=20Diego=20'Flameeyes'=20Petten=F2?= =?UTF-8?q?=20to=20eject=5Fmedia=5Ffreebsd=5Fioctl():?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allegedly this works better than the CAM mode eject; CAM gets the error "Device not ready" when trying to eject an empty CD-ROM drive. We make use of an already open file descriptor to the CD-ROM instead of opening a new one (else we have two file descriptor open, so when it launch the ioctl() to eject the device it results busy because of the other fd). Also corrects the documentation comment about the return value. --- lib/driver/FreeBSD/freebsd_ioctl.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/lib/driver/FreeBSD/freebsd_ioctl.c b/lib/driver/FreeBSD/freebsd_ioctl.c index d5b609e4..e9ee0300 100644 --- a/lib/driver/FreeBSD/freebsd_ioctl.c +++ b/lib/driver/FreeBSD/freebsd_ioctl.c @@ -1,5 +1,5 @@ /* - $Id: freebsd_ioctl.c,v 1.3 2005/01/27 04:00:48 rocky Exp $ + $Id: freebsd_ioctl.c,v 1.4 2005/07/23 21:36:54 rocky Exp $ Copyright (C) 2003, 2004, 2005 Rocky Bernstein @@ -27,7 +27,7 @@ # include "config.h" #endif -static const char _rcsid[] = "$Id: freebsd_ioctl.c,v 1.3 2005/01/27 04:00:48 rocky Exp $"; +static const char _rcsid[] = "$Id: freebsd_ioctl.c,v 1.4 2005/07/23 21:36:54 rocky Exp $"; #ifdef HAVE_FREEBSD_CDROM @@ -140,25 +140,20 @@ get_disc_last_lsn_freebsd_ioctl (_img_private_t *_obj) } /*! - Eject media. Return 1 if successful, 0 otherwise. + Eject media. Return 0 if successful, 1 otherwise. */ int eject_media_freebsd_ioctl (_img_private_t *env) { _img_private_t *_obj = env; - int ret=2; - int fd; + int ret=1; - if ((fd = open(_obj->gen.source_name, O_RDONLY|O_NONBLOCK)) > -1) { - ret = 1; - if (ioctl(fd, CDIOCALLOW) == -1) { - cdio_warn("ioctl(fd, CDIOCALLOW) failed: %s\n", strerror(errno)); - } else if (ioctl(fd, CDIOCEJECT) == -1) { - cdio_warn("ioctl(CDIOCEJECT) failed: %s\n", strerror(errno)); - } else { - ret = 0; - } - close(fd); + if (ioctl(_obj->gen.fd, CDIOCALLOW) == -1) { + cdio_warn("ioctl(fd, CDIOCALLOW) failed: %s\n", strerror(errno)); + } else if (ioctl(_obj->gen.fd, CDIOCEJECT) == -1) { + cdio_warn("ioctl(CDIOCEJECT) failed: %s\n", strerror(errno)); + } else { + ret=0; } return ret;