[BusyBox] [PATCH] eject

Tito farmatito at tiscali.it
Tue May 10 13:30:27 UTC 2005


Hi, Rob
I just started for fun to take a look at eject.
Now I've a patch ready and i'm sending it
in the hope it could be useful to  you.

Size reduction is:

root at localhost:/dev/pts/2:/root/Desktop/busybox# size coreutils/eject.o.orig
   text    data     bss     dec     hex filename
    245       0       0     245      f5 coreutils/eject.o.orig
root at localhost:/dev/pts/2:/root/Desktop/busybox# size coreutils/eject.o
   text    data     bss     dec     hex filename
    111       0       0     111      6f coreutils/eject.o

Ciao,
Tito

PS.: this patch applies on top of eject.diff

PPS.: don't think i want to steal your job ;-)
-------------- next part --------------
--- AUTHORS.orig	2005-05-03 08:20:15.000000000 +0200
+++ AUTHORS	2005-05-10 15:09:27.000000000 +0200
@@ -8,6 +8,9 @@
 
 -----------
 
+Peter Willis <psyphreak at phreaker.net>
+    eject
+
 Emanuele Aina <emanuele.aina at tiscali.it>
     run-parts
 
@@ -139,5 +142,6 @@
     tarcat (since removed), loadkmap, various fixes, Debian maintenance
 
 Tito Ragusa <farmatito at tiscali.it>
-    devfsd and size optimizations in strings, openvt, chvt, deallocvt, hdparm and fdformat.
+    devfsd and size optimizations in strings, openvt, chvt, deallocvt, hdparm,
+    fdformat, lsattr, chattr, id and eject.
 
--- coreutils/Config.in.orig	2005-05-03 08:20:07.000000000 +0200
+++ coreutils/Config.in	2005-05-10 14:55:49.000000000 +0200
@@ -170,6 +170,20 @@
 	help
 	  printenv is used to print all or part of environment.
 
+config CONFIG_EJECT
+	bool "eject"
+	default n
+	help
+	  ejects a cdrom drive.
+	  defaults to /dev/cdrom
+
+config CONFIG_FEATURE_EJECT_LONGOPTIONS
+	bool "  Enable support for --trayclose long option (-t )"
+	default n
+	depends on CONFIG_EJECT
+	help
+	  This enables support for --trayclose long option (-t ) to eject.
+
 config CONFIG_EXPR
 	bool "expr"
 	default n
--- coreutils/Makefile.in.orig	2005-05-03 08:20:07.000000000 +0200
+++ coreutils/Makefile.in	2005-05-10 13:53:11.000000000 +0200
@@ -42,6 +42,7 @@
 COREUTILS-$(CONFIG_DU)      	+= du.o
 COREUTILS-$(CONFIG_ECHO)    	+= echo.o
 COREUTILS-$(CONFIG_ENV)     	+= env.o
+COREUTILS-$(CONFIG_EJECT)   	+= eject.o
 COREUTILS-$(CONFIG_EXPR)    	+= expr.o
 COREUTILS-$(CONFIG_FALSE)   	+= false.o
 COREUTILS-$(CONFIG_FOLD)    	+= fold.o
--- coreutils/eject.c.orig	2005-05-10 13:53:11.000000000 +0200
+++ coreutils/eject.c	2005-05-10 15:06:34.000000000 +0200
@@ -30,37 +30,38 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
+#include <getopt.h>
 #include "busybox.h"
 #include <linux/cdrom.h> // needs to be after busybox.h or compile problems arise
 
 #define DEFAULT_CDROM "/dev/cdrom"
+/*#define CLOSE_TRAY        1*/
 
 extern int eject_main(int argc, char **argv)
 {
-	int fd;
-	int flag = CDROMEJECT;
-	int i = 1;
-	char *device = NULL;
+	unsigned long f;
+	
+#ifdef CONFIG_FEATURE_EJECT_LONGOPTIONS
+static const struct option eject_long_options[] = {
+		{ "trayclose", 0, 0, 't' },
+		{ 0,           0, 0, 0 }
+	};
+	bb_applet_long_options = eject_long_options;
+#endif
 
-	/*
-	 * i'm too lazy to learn bb_getopt_ulflags and this is obscenely large
-	 * for just some argument parsing so mjn3 can clean it up later.
-	 * sorry, but PlumpOS 7.0-pre2 needs this asap :-/
-	 */
-	while (++i <= argc) {
-		if ( (! strncmp(argv[i-1],"-t",2)) || (! strncmp(argv[i-1],"--trayclose",11)) ) {
-			flag = CDROMCLOSETRAY;
-		} else {
-			device = argv[i-1];
-		}
-	}
-	if ( (fd = open(device == NULL ? DEFAULT_CDROM : device, O_RDONLY | O_NONBLOCK) ) < 0 ) {
-		perror("eject: Can't open device");
-		return(EXIT_FAILURE);
-	}
-	if (ioctl(fd, flag)) {
-		perror("eject: Can't eject cdrom");
-		return(EXIT_FAILURE);
+	f = bb_getopt_ulflags(argc, argv, "t");
+
+	argc -= optind;
+	argv += optind;
+	
+	if (ioctl(bb_xopen((argv[0])? 
+						argv[0] : 
+						DEFAULT_CDROM , 
+						O_RDONLY | O_NONBLOCK), 
+						( f /*& CLOSE_TRAY*/ ) ?
+						CDROMCLOSETRAY :
+						CDROMEJECT)) {
+		bb_perror_msg_and_die("failed");
 	}
 	return EXIT_SUCCESS;
 }
--- include/applets.h.orig	2005-05-03 08:20:10.000000000 +0200
+++ include/applets.h	2005-05-10 13:53:11.000000000 +0200
@@ -182,6 +182,9 @@
 #if defined(CONFIG_FEATURE_GREP_EGREP_ALIAS)
 	APPLET_NOUSAGE("egrep", grep_main, _BB_DIR_BIN, _BB_SUID_NEVER)
 #endif
+#ifdef CONFIG_EJECT
+	APPLET(eject, eject_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
+#endif
 #ifdef CONFIG_ENV
 	APPLET(env, env_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
 #endif
--- include/usage.h.orig	2005-05-03 08:20:10.000000000 +0200
+++ include/usage.h	2005-05-10 14:57:16.000000000 +0200
@@ -556,6 +556,19 @@
 	"$ echo \"Erik\\nis\\ncool\"\n" \
 	"Erik\\nis\\ncool\n")
 
+#ifdef CONFIG_FEATURE_EJECT_LONGOPTIONS
+#define EJECT_USAGE	"\t-t, 	--trayclose\tclose tray\n"
+#else
+#define EJECT_USAGE	"\t-t\tclose tray\n"
+#endif
+
+#define eject_trivial_usage \
+	"[-t] [FILE]"
+#define eject_full_usage \
+	"Ejects the specified FILE or /dev/cdrom if FILE is unspecified.\n\n" \
+	"Options:\n" \
+	EJECT_USAGE
+
 #define env_trivial_usage \
 	"[-iu] [-] [name=value]... [command]"
 #define env_full_usage \
@@ -565,6 +578,7 @@
 	"\t-, -i\tstart with an empty environment\n" \
 	"\t-u\tremove variable from the environment"
 
+
 #define expr_trivial_usage \
 	"EXPRESSION"
 #define expr_full_usage \


More information about the busybox mailing list