[BusyBox] [PATCH] eject

Tito farmatito at tiscali.it
Tue May 10 21:04:35 UTC 2005


On Tuesday 10 May 2005 21:28, Erik Andersen wrote:
> On Tue May 10, 2005 at 03:30:27PM +0200, Tito wrote:
> > --- coreutils/eject.c.orig	2005-05-10 13:53:11.000000000 +0200

<snip>

> As fond as I am of linux/cdrom.h (cdrom.h and I go way back)
> please remove '#include <linux/cdrom.h>' and instead copy in
> all needed defines so we do not include kernel headers.  i.e.
> 
> -#include <linux/cdrom.h> // needs to be after busybox.h or compile problems arise
> +// various defines swiped from linux/cdrom.h
> +#define CDROMCLOSETRAY		0x5319	/* pendant of CDROMEJECT */
> +#define CDROMEJECT		0x5309 /* Ejects the cdrom media */
> 
>  -Erik
> 
> --
> Erik B. Andersen             http://codepoet-consulting.com/
> --This message was written using 73% post-consumer electrons--
> 
Hi, 
Done.
The new patch is STANDALONE and does not apply on top of
eject.diff  ( I've messed up the test dirs......... :-( ) but all informations
about the original author  are preserved.

Please apply if you think it's ok.

Ciao,
Tito 
-------------- next part --------------
diff -uNr a/AUTHORS b/AUTHORS
--- a/AUTHORS	2005-05-03 08:20:15.000000000 +0200
+++ b/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.
 
diff -uNr a/coreutils/Config.in b/coreutils/Config.in
--- a/coreutils/Config.in	2005-05-03 08:20:07.000000000 +0200
+++ b/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
diff -uNr a/coreutils/eject.c b/coreutils/eject.c
--- a/coreutils/eject.c	1970-01-01 01:00:00.000000000 +0100
+++ b/coreutils/eject.c	2005-05-10 22:14:31.000000000 +0200
@@ -0,0 +1,65 @@
+/*
+ * eject implementation for busybox
+ *
+ * Copyright (C) 2004  Peter Willis <psyphreak at phreaker.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+/*
+ * This is a simple hack of eject based on something Erik posted in #uclibc.
+ * Most of the dirty work blatantly ripped off from cat.c =)
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <getopt.h>
+#include "busybox.h"
+/*various defines swiped from linux/cdrom.h */
+#define CDROMCLOSETRAY            0x5319  /* pendant of CDROMEJECT  */
+#define CDROMEJECT                0x5309  /* Ejects the cdrom media */
+#define DEFAULT_CDROM             "/dev/cdrom"
+/*#define CLOSE_TRAY              1*/
+
+extern int eject_main(int argc, char **argv)
+{
+	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
+
+	f = bb_getopt_ulflags(argc, argv, "t");
+
+	if (ioctl(bb_xopen((argv[optind])? 
+						argv[optind] : 
+						DEFAULT_CDROM, 
+						O_RDONLY | O_NONBLOCK), 
+						( f /*& CLOSE_TRAY*/ ) ?
+						CDROMCLOSETRAY :
+						CDROMEJECT)) {
+		bb_perror_msg_and_die("failed");
+	}
+	return EXIT_SUCCESS;
+}
diff -uNr a/coreutils/Makefile.in b/coreutils/Makefile.in
--- a/coreutils/Makefile.in	2005-05-03 08:20:07.000000000 +0200
+++ b/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
diff -uNr a/include/applets.h b/include/applets.h
--- a/include/applets.h	2005-05-03 08:20:10.000000000 +0200
+++ b/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
diff -uNr a/include/usage.h b/include/usage.h
--- a/include/usage.h	2005-05-03 08:20:10.000000000 +0200
+++ b/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