[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH] eject -T support
From:       Aurelien Jacobs <aurel () gnuage ! org>
Date:       2006-09-28 21:59:29
Message-ID: 20060928235929.81f82b47.aurel () gnuage ! org
[Download RAW message or body]

Hi,

This patch add support for the -T option to eject.
It allows to open or close the tray depending on it's current state.
It's very handy on embeded systems where you want to bind a single button
to the tray opening/closing.

Aurel

["bb-eject.diff" (text/x-diff)]

diff -Naur busybox.orig/include/usage.h busybox/include/usage.h
--- busybox.orig/include/usage.h	2006-09-28 23:02:35.000000000 +0200
+++ busybox/include/usage.h	2006-09-28 23:02:48.000000000 +0200
@@ -638,11 +638,12 @@
 	"Erik\\nis\\ncool\n")
 
 #define eject_trivial_usage \
-	"[-t] [DEVICE]"
+	"[-t] [-T] [DEVICE]"
 #define eject_full_usage \
 	"Eject specified DEVICE (or default /dev/cdrom).\n\n" \
 	"Options:\n" \
-	"\t-t\tclose tray"
+	"\t-t\tclose tray" \
+	"\t-T\tsmart open and close tray"
 
 #define ed_trivial_usage ""
 #define ed_full_usage ""
diff -Naur busybox.orig/miscutils/eject.c busybox/miscutils/eject.c
--- busybox.orig/miscutils/eject.c	2006-09-28 23:02:35.000000000 +0200
+++ busybox/miscutils/eject.c	2006-09-28 23:14:09.000000000 +0200
@@ -19,15 +19,22 @@
 /* various defines swiped from linux/cdrom.h */
 #define CDROMCLOSETRAY            0x5319  /* pendant of CDROMEJECT  */
 #define CDROMEJECT                0x5309  /* Ejects the cdrom media */
+#define CDROM_DRIVE_STATUS        0x5326  /* Get tray position, etc. */
 #define DEFAULT_CDROM             "/dev/cdrom"
+/* drive status possibilities returned by CDROM_DRIVE_STATUS ioctl */
+#define CDS_TRAY_OPEN        2
+
+#define FLAG_CLOSE  1
+#define FLAG_SMART  2
 
 int eject_main(int argc, char **argv)
 {
 	unsigned long flags;
 	char *device;
 	struct mntent *m;
+	int dev, cmd;
 
-	flags = bb_getopt_ulflags(argc, argv, "t");
+	flags = bb_getopt_ulflags(argc, argv, "tT");
 	device = argv[optind] ? : DEFAULT_CDROM;
 
 	if ((m = find_mount_point(device, bb_path_mtab_file))) {
@@ -37,9 +44,19 @@
 			erase_mtab(m->mnt_fsname);
 		}
 	}
-	if (ioctl(xopen(device, (O_RDONLY | O_NONBLOCK)),
-				(flags ? CDROMCLOSETRAY : CDROMEJECT))) {
+
+	dev = xopen(device, O_RDONLY|O_NONBLOCK);
+	if (flags & FLAG_CLOSE ||
+		(flags & FLAG_SMART && ioctl(dev,CDROM_DRIVE_STATUS) == CDS_TRAY_OPEN))
+		cmd = CDROMCLOSETRAY;
+	else
+		cmd = CDROMEJECT;
+	if (ioctl(dev, cmd)) {
 		bb_perror_msg_and_die("%s", device);
 	}
+
+	if (ENABLE_FEATURE_CLEAN_UP)
+		close(dev);
+
 	return (EXIT_SUCCESS);
 }


_______________________________________________
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic