aboutsummaryrefslogtreecommitdiff
path: root/miscutils/eject.c
diff options
context:
space:
mode:
authorvapier <vapier@69ca8d6d-28ef-0310-b511-8ec308f3f277>2005-05-11 00:25:47 +0000
committervapier <vapier@69ca8d6d-28ef-0310-b511-8ec308f3f277>2005-05-11 00:25:47 +0000
commit92285b9e71a77a02e3b1eb81dc00c5db0faf07ea (patch)
tree861e274991d9290735776b7f38b6b18861da1598 /miscutils/eject.c
parentecb5d65cdf94dcecefa7dfe93da62c07ef0e7613 (diff)
downloadbusybox-w32-92285b9e71a77a02e3b1eb81dc00c5db0faf07ea.tar.gz
busybox-w32-92285b9e71a77a02e3b1eb81dc00c5db0faf07ea.tar.bz2
busybox-w32-92285b9e71a77a02e3b1eb81dc00c5db0faf07ea.zip
import eject by Peter Willis / Tito Ragusa
git-svn-id: svn://busybox.net/trunk/busybox@10288 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'miscutils/eject.c')
-rw-r--r--miscutils/eject.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/miscutils/eject.c b/miscutils/eject.c
new file mode 100644
index 000000000..cbfd115f7
--- /dev/null
+++ b/miscutils/eject.c
@@ -0,0 +1,64 @@
1/*
2 * eject implementation for busybox
3 *
4 * Copyright (C) 2004 Peter Willis <psyphreak@phreaker.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22/*
23 * This is a simple hack of eject based on something Erik posted in #uclibc.
24 * Most of the dirty work blatantly ripped off from cat.c =)
25 */
26
27#include <stdio.h>
28#include <string.h>
29#include <sys/types.h>
30#include <sys/stat.h>
31#include <fcntl.h>
32#include <sys/ioctl.h>
33#include <getopt.h>
34#include "busybox.h"
35
36/* various defines swiped from linux/cdrom.h */
37#define CDROMCLOSETRAY 0x5319 /* pendant of CDROMEJECT */
38#define CDROMEJECT 0x5309 /* Ejects the cdrom media */
39#define DEFAULT_CDROM "/dev/cdrom"
40/*#define CLOSE_TRAY 1*/
41
42extern int eject_main(int argc, char **argv)
43{
44 unsigned long flags;
45
46#ifdef CONFIG_FEATURE_EJECT_LONG_OPTIONS
47 static const struct option eject_long_options[] = {
48 { "trayclose", 0, 0, 't' },
49 { 0, 0, 0, 0 }
50 };
51 bb_applet_long_options = eject_long_options;
52#endif
53
54 flags = bb_getopt_ulflags(argc, argv, "t");
55
56 if (ioctl(bb_xopen((argv[optind] ? argv[optind] : DEFAULT_CDROM),
57 (O_RDONLY | O_NONBLOCK)),
58 ( flags /*& CLOSE_TRAY*/ ? CDROMCLOSETRAY : CDROMEJECT)))
59 {
60 bb_perror_msg_and_die(bb_msg_unknown);
61 }
62
63 return EXIT_SUCCESS;
64}