public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] eject: constify array
@ 2012-04-05 15:50 Mike Frysinger
  2012-04-05 15:50 ` [PATCH 2/3] eject(1): fix typo in mount(1) reference Mike Frysinger
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Mike Frysinger @ 2012-04-05 15:50 UTC (permalink / raw)
  To: util-linux-ng

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 sys-utils/eject.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/sys-utils/eject.c b/sys-utils/eject.c
index 2d8b0cb..68d5e9c 100644
--- a/sys-utils/eject.c
+++ b/sys-utils/eject.c
@@ -64,7 +64,7 @@
 /* eject(1) is able to eject only 'removable' devices (attribute in /sys)
  * _or_ devices connected by hotplug subsystem.
  */
-static const char *hotplug_subsystems[] = {
+static const char * const hotplug_subsystems[] = {
 	"usb",
 	"ieee1394",
 	"pcmcia",
-- 
1.7.8.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] eject(1): fix typo in mount(1) reference
  2012-04-05 15:50 [PATCH 1/3] eject: constify array Mike Frysinger
@ 2012-04-05 15:50 ` Mike Frysinger
  2012-04-10 10:24   ` Karel Zak
  2012-04-05 15:50 ` [PATCH 3/3] eject: use CDROM_DRIVE_STATUS if available for tray toggling Mike Frysinger
  2012-04-10 10:24 ` [PATCH 1/3] eject: constify array Karel Zak
  2 siblings, 1 reply; 6+ messages in thread
From: Mike Frysinger @ 2012-04-05 15:50 UTC (permalink / raw)
  To: util-linux-ng

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 sys-utils/eject.1 |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/sys-utils/eject.1 b/sys-utils/eject.1
index 8b1b11b..22cf1ae 100644
--- a/sys-utils/eject.1
+++ b/sys-utils/eject.1
@@ -59,7 +59,7 @@ This option specifies that the drive should be ejected using a tape drive
 offline command.
 .IP "\fB\-m, \-\-no-unmount\fP"
 This option allows eject to work with device drivers which automatically mount
-removable media and therefore must be always mount()ed.  The option tells eject
+removable media and therefore must be always mount(1)ed.  The option tells eject
 to not try to unmount the given device, even if it is mounted according to
 /etc/mtab or /proc/mounts.
 .IP "\fB\-n, \-\-noop\fP"
-- 
1.7.8.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] eject: use CDROM_DRIVE_STATUS if available for tray toggling
  2012-04-05 15:50 [PATCH 1/3] eject: constify array Mike Frysinger
  2012-04-05 15:50 ` [PATCH 2/3] eject(1): fix typo in mount(1) reference Mike Frysinger
@ 2012-04-05 15:50 ` Mike Frysinger
  2012-04-10 10:25   ` Karel Zak
  2012-04-10 10:24 ` [PATCH 1/3] eject: constify array Karel Zak
  2 siblings, 1 reply; 6+ messages in thread
From: Mike Frysinger @ 2012-04-05 15:50 UTC (permalink / raw)
  To: util-linux-ng

One some platforms, the -T option can be unreliable (see reference bug
report for some examples).  Instead, if the kernel supports the cdrom
status ioctl, use that to ask explicitly for the current tray status
and then open/close accordingly.

The eject_cdrom() func was reworked slightly, but none of the existing
callers care about the explicit normalization to [0,1] values, so have
it return the raw value so we can convert toggle_tray() over to using
that.

Finally, now that toggle_tray() uses a lot of helper functions, drop
the check on CDROMCLOSETRAY.  The sub-functions take care of that.

Reference: https://bugs.gentoo.org/261880
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 sys-utils/eject.c |   52 ++++++++++++++++++++++++++++++++--------------------
 1 files changed, 32 insertions(+), 20 deletions(-)

diff --git a/sys-utils/eject.c b/sys-utils/eject.c
index 68d5e9c..245c028 100644
--- a/sys-utils/eject.c
+++ b/sys-utils/eject.c
@@ -386,6 +386,22 @@ static void close_tray(int fd)
 }
 
 /*
+ * Eject using CDROMEJECT ioctl.
+ */
+static int eject_cdrom(int fd)
+{
+#if defined(CDROMEJECT)
+	return ioctl(fd, CDROMEJECT);
+#elif defined(CDIOCEJECT)
+	return ioctl(fd, CDIOCEJECT);
+#else
+	warnx(_("CD-ROM eject unsupported"));
+	errno = ENOSYS;
+	return -1;
+#endif
+}
+
+/*
  * Toggle tray.
  *
  * Written by Benjamin Schwenk <benjaminschwenk@yahoo.de> and
@@ -400,7 +416,21 @@ static void toggle_tray(int fd)
 	struct timeval time_start, time_stop;
 	int time_elapsed;
 
-#ifdef CDROMCLOSETRAY
+#ifdef CDROM_DRIVE_STATUS
+	/* First ask the CDROM for info, otherwise fall back to manual.  */
+	switch (ioctl(fd, CDROM_DRIVE_STATUS)) {
+	case CDS_TRAY_OPEN:
+		close_tray(fd);
+		return;
+
+	case CDS_NO_DISC:
+	case CDS_DISC_OK:
+		if (eject_cdrom(fd))
+			err(EXIT_FAILURE, _("CD-ROM eject command failed"));
+		return;
+	}
+#endif
+
 	/* Try to open the CDROM tray and measure the time therefor
 	 * needed.  In my experience the function needs less than 0.05
 	 * seconds if the tray was already open, and at least 1.5 seconds
@@ -408,7 +438,7 @@ static void toggle_tray(int fd)
 	gettimeofday(&time_start, NULL);
 
 	/* Send the CDROMEJECT command to the device. */
-	if (ioctl(fd, CDROMEJECT, 0) < 0)
+	if (eject_cdrom(fd) < 0)
 		err(EXIT_FAILURE, _("CD-ROM eject command failed"));
 
 	/* Get the second timestamp, to measure the time needed to open
@@ -423,10 +453,6 @@ static void toggle_tray(int fd)
 	 * closed before. This would mean that we are done.  */
 	if (time_elapsed < TRAY_WAS_ALREADY_OPEN_USECS)
 		close_tray(fd);
-#else
-	warnx(_("CD-ROM tray toggle command not supported by this kernel"));
-#endif
-
 }
 
 /*
@@ -531,20 +557,6 @@ static void list_speeds(const char *name, int fd)
 }
 
 /*
- * Eject using CDROMEJECT ioctl. Return 1 if successful, 0 otherwise.
- */
-static int eject_cdrom(int fd)
-{
-#if defined(CDROMEJECT)
-	return ioctl(fd, CDROMEJECT) == 0;
-#elif defined(CDIOCEJECT)
-	return ioctl(fd, CDIOCEJECT) == 0;
-#else
-	warnx(_("CD-ROM eject unsupported"));
-#endif
-}
-
-/*
  * Eject using SCSI SG_IO commands. Return 1 if successful, 0 otherwise.
  */
 static int eject_scsi(int fd)
-- 
1.7.8.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] eject: constify array
  2012-04-05 15:50 [PATCH 1/3] eject: constify array Mike Frysinger
  2012-04-05 15:50 ` [PATCH 2/3] eject(1): fix typo in mount(1) reference Mike Frysinger
  2012-04-05 15:50 ` [PATCH 3/3] eject: use CDROM_DRIVE_STATUS if available for tray toggling Mike Frysinger
@ 2012-04-10 10:24 ` Karel Zak
  2 siblings, 0 replies; 6+ messages in thread
From: Karel Zak @ 2012-04-10 10:24 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: util-linux-ng

On Thu, Apr 05, 2012 at 11:50:44AM -0400, Mike Frysinger wrote:
>  sys-utils/eject.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)

Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/3] eject(1): fix typo in mount(1) reference
  2012-04-05 15:50 ` [PATCH 2/3] eject(1): fix typo in mount(1) reference Mike Frysinger
@ 2012-04-10 10:24   ` Karel Zak
  0 siblings, 0 replies; 6+ messages in thread
From: Karel Zak @ 2012-04-10 10:24 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: util-linux-ng

On Thu, Apr 05, 2012 at 11:50:45AM -0400, Mike Frysinger wrote:
>  sys-utils/eject.1 |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)

 Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 3/3] eject: use CDROM_DRIVE_STATUS if available for tray toggling
  2012-04-05 15:50 ` [PATCH 3/3] eject: use CDROM_DRIVE_STATUS if available for tray toggling Mike Frysinger
@ 2012-04-10 10:25   ` Karel Zak
  0 siblings, 0 replies; 6+ messages in thread
From: Karel Zak @ 2012-04-10 10:25 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: util-linux-ng

On Thu, Apr 05, 2012 at 11:50:46AM -0400, Mike Frysinger wrote:
>  sys-utils/eject.c |   52 ++++++++++++++++++++++++++++++++--------------------
>  1 files changed, 32 insertions(+), 20 deletions(-)

 Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-04-10 10:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-05 15:50 [PATCH 1/3] eject: constify array Mike Frysinger
2012-04-05 15:50 ` [PATCH 2/3] eject(1): fix typo in mount(1) reference Mike Frysinger
2012-04-10 10:24   ` Karel Zak
2012-04-05 15:50 ` [PATCH 3/3] eject: use CDROM_DRIVE_STATUS if available for tray toggling Mike Frysinger
2012-04-10 10:25   ` Karel Zak
2012-04-10 10:24 ` [PATCH 1/3] eject: constify array Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox