fcc234d026ef7a3b98f8750c74f8b6439dab925b
[oweals/busybox.git] / busybox / patches / eject.diff
1 Index: AUTHORS
2 ===================================================================
3 RCS file: /var/cvs/busybox/AUTHORS,v
4 retrieving revision 1.40
5 diff -u -r1.40 AUTHORS
6 --- a/AUTHORS   9 Oct 2003 21:19:21 -0000       1.40
7 +++ b/AUTHORS   5 Mar 2004 07:23:17 -0000
8 @@ -8,6 +8,9 @@
9
10  -----------
11
12 +Peter Willis <psyphreak@phreaker.net>
13 +    eject
14 +
15  Emanuele Aina <emanuele.aina@tiscali.it>
16         run-parts
17
18 Index: coreutils/Config.in
19 ===================================================================
20 RCS file: /var/cvs/busybox/coreutils/Config.in,v
21 retrieving revision 1.23
22 diff -u -r1.23 Config.in
23 --- a/coreutils/Config.in       5 Mar 2004 06:47:25 -0000       1.23
24 +++ b/coreutils/Config.in       5 Mar 2004 07:23:18 -0000
25 @@ -164,6 +164,13 @@
26           a command; without options it displays the current
27           environment.
28
29 +config CONFIG_EJECT
30 +       bool "eject"
31 +       default n
32 +       help
33 +         ejects a cdrom drive.
34 +         defaults to /dev/cdrom
35 +
36  config CONFIG_EXPR
37         bool "expr"
38         default n
39 Index: coreutils/Makefile.in
40 ===================================================================
41 RCS file: /var/cvs/busybox/coreutils/Makefile.in,v
42 retrieving revision 1.8
43 diff -u -r1.8 Makefile.in
44 --- a/coreutils/Makefile.in     27 Jan 2004 09:22:20 -0000      1.8
45 +++ b/coreutils/Makefile.in     5 Mar 2004 07:23:18 -0000
46 @@ -41,6 +41,7 @@
47  COREUTILS-$(CONFIG_DU)         += du.o
48  COREUTILS-$(CONFIG_ECHO)       += echo.o
49  COREUTILS-$(CONFIG_ENV)        += env.o
50 +COREUTILS-$(CONFIG_EJECT)      += eject.o
51  COREUTILS-$(CONFIG_EXPR)       += expr.o
52  COREUTILS-$(CONFIG_FALSE)      += false.o
53  COREUTILS-$(CONFIG_FOLD)       += fold.o
54 Index: coreutils/eject.c
55 ===================================================================
56 RCS file: coreutils/eject.c
57 diff -N coreutils/eject.c
58 --- /dev/null   1 Jan 1970 00:00:00 -0000
59 +++ b/coreutils/eject.c 5 Mar 2004 07:23:21 -0000
60 @@ -0,0 +1,66 @@
61 +/*
62 + * eject implementation for busybox
63 + *
64 + * Copyright (C) 2004  Peter Willis <psyphreak@phreaker.net>
65 + *
66 + * This program is free software; you can redistribute it and/or modify
67 + * it under the terms of the GNU General Public License as published by
68 + * the Free Software Foundation; either version 2 of the License, or
69 + * (at your option) any later version.
70 + *
71 + * This program is distributed in the hope that it will be useful,
72 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
73 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74 + * General Public License for more details.
75 + *
76 + * You should have received a copy of the GNU General Public License
77 + * along with this program; if not, write to the Free Software
78 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
79 + *
80 + */
81 +
82 +/*
83 + * This is a simple hack of eject based on something Erik posted in #uclibc.
84 + * Most of the dirty work blatantly ripped off from cat.c =)
85 + */
86 +
87 +#include <stdio.h>
88 +#include <string.h>
89 +#include <sys/types.h>
90 +#include <sys/stat.h>
91 +#include <fcntl.h>
92 +#include <sys/ioctl.h>
93 +#include "busybox.h"
94 +#include <linux/cdrom.h> // needs to be after busybox.h or compile problems arise
95 +
96 +#define DEFAULT_CDROM "/dev/cdrom"
97 +
98 +extern int eject_main(int argc, char **argv)
99 +{
100 +       int fd;
101 +       int flag = CDROMEJECT;
102 +       int i = 1;
103 +       char *device = NULL;
104 +
105 +       /*
106 +        * i'm too lazy to learn bb_getopt_ulflags and this is obscenely large
107 +        * for just some argument parsing so mjn3 can clean it up later.
108 +        * sorry, but PlumpOS 7.0-pre2 needs this asap :-/
109 +        */
110 +       while (++i <= argc) {
111 +               if ( (! strncmp(argv[i-1],"-t",2)) || (! strncmp(argv[i-1],"--trayclose",11)) ) {
112 +                       flag = CDROMCLOSETRAY;
113 +               } else {
114 +                       device = argv[i-1];
115 +               }
116 +       }
117 +       if ( (fd = open(device == NULL ? DEFAULT_CDROM : device, O_RDONLY | O_NONBLOCK) ) < 0 ) {
118 +               perror("eject: Can't open device");
119 +               return(EXIT_FAILURE);
120 +       }
121 +       if (ioctl(fd, flag)) {
122 +               perror("eject: Can't eject cdrom");
123 +               return(EXIT_FAILURE);
124 +       }
125 +       return EXIT_SUCCESS;
126 +}
127 Index: include/applets.h
128 ===================================================================
129 RCS file: /var/cvs/busybox/include/applets.h,v
130 retrieving revision 1.111
131 diff -u -r1.111 applets.h
132 --- a/include/applets.h 27 Jan 2004 09:22:20 -0000      1.111
133 +++ b/include/applets.h 5 Mar 2004 07:23:21 -0000
134 @@ -178,6 +178,9 @@
135  #if defined(CONFIG_FEATURE_GREP_EGREP_ALIAS)
136         APPLET_NOUSAGE("egrep", grep_main, _BB_DIR_BIN, _BB_SUID_NEVER)
137  #endif
138 +#ifdef CONFIG_EJECT
139 +       APPLET(eject, eject_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
140 +#endif
141  #ifdef CONFIG_ENV
142         APPLET(env, env_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
143  #endif
144 Index: include/usage.h
145 ===================================================================
146 RCS file: /var/cvs/busybox/include/usage.h,v
147 retrieving revision 1.191
148 diff -u -r1.191 usage.h
149 --- a/include/usage.h   25 Feb 2004 10:35:55 -0000      1.191
150 +++ b/include/usage.h   5 Mar 2004 07:23:29 -0000
151 @@ -537,6 +537,13 @@
152         "\t-, -i\tstart with an empty environment\n" \
153         "\t-u\tremove variable from the environment\n"
154
155 +#define eject_trivial_usage \
156 +       "[-t] [FILE]"
157 +#define eject_full_usage \
158 +       "Ejects the specified FILE or /dev/cdrom if FILE is unspecified.\n\n" \
159 +       "Options:\n" \
160 +       "\t-t, --trayclose \tclose tray\n"
161 +
162  #define expr_trivial_usage \
163         "EXPRESSION"
164  #define expr_full_usage \