Contents of /trunk/mkinitrd-magellan/busybox/miscutils/eject.c
Parent Directory | Revision Log
Revision 532 -
(show annotations)
(download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 1614 byte(s)
Sat Sep 1 22:45:15 2007 UTC (16 years, 8 months ago) by niro
File MIME type: text/plain
File size: 1614 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd
1 | /* vi: set sw=4 ts=4: */ |
2 | /* |
3 | * eject implementation for busybox |
4 | * |
5 | * Copyright (C) 2004 Peter Willis <psyphreak@phreaker.net> |
6 | * Copyright (C) 2005 Tito Ragusa <farmatito@tiscali.it> |
7 | * |
8 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. |
9 | */ |
10 | |
11 | /* |
12 | * This is a simple hack of eject based on something Erik posted in #uclibc. |
13 | * Most of the dirty work blatantly ripped off from cat.c =) |
14 | */ |
15 | |
16 | #include "busybox.h" |
17 | |
18 | /* various defines swiped from linux/cdrom.h */ |
19 | #define CDROMCLOSETRAY 0x5319 /* pendant of CDROMEJECT */ |
20 | #define CDROMEJECT 0x5309 /* Ejects the cdrom media */ |
21 | #define CDROM_DRIVE_STATUS 0x5326 /* Get tray position, etc. */ |
22 | /* drive status possibilities returned by CDROM_DRIVE_STATUS ioctl */ |
23 | #define CDS_TRAY_OPEN 2 |
24 | |
25 | #define FLAG_CLOSE 1 |
26 | #define FLAG_SMART 2 |
27 | |
28 | int eject_main(int argc, char **argv) |
29 | { |
30 | unsigned long flags; |
31 | char *device; |
32 | int dev, cmd; |
33 | |
34 | opt_complementary = "?:?1:t--T:T--t"; |
35 | flags = getopt32(argc, argv, "tT"); |
36 | device = argv[optind] ? : "/dev/cdrom"; |
37 | |
38 | // We used to do "umount <device>" here, but it was buggy |
39 | // if something was mounted OVER cdrom and |
40 | // if cdrom is mounted many times. |
41 | // |
42 | // This works equally well (or better): |
43 | // #!/bin/sh |
44 | // umount /dev/cdrom |
45 | // eject |
46 | |
47 | dev = xopen(device, O_RDONLY|O_NONBLOCK); |
48 | cmd = CDROMEJECT; |
49 | if (flags & FLAG_CLOSE |
50 | || (flags & FLAG_SMART && ioctl(dev, CDROM_DRIVE_STATUS) == CDS_TRAY_OPEN)) |
51 | cmd = CDROMCLOSETRAY; |
52 | if (ioctl(dev, cmd)) { |
53 | bb_perror_msg_and_die("%s", device); |
54 | } |
55 | |
56 | if (ENABLE_FEATURE_CLEAN_UP) |
57 | close(dev); |
58 | |
59 | return EXIT_SUCCESS; |
60 | } |