source: MondoRescue/branches/2.2.5/mindi-busybox/miscutils/eject.c@ 1765

Last change on this file since 1765 was 1765, checked in by Bruno Cornec, 16 years ago

Update to busybox 1.7.2

File size: 1.6 KB
RevLine 
[821]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
[1765]16#include "libbb.h"
[821]17
18/* various defines swiped from linux/cdrom.h */
19#define CDROMCLOSETRAY 0x5319 /* pendant of CDROMEJECT */
20#define CDROMEJECT 0x5309 /* Ejects the cdrom media */
[1765]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
[821]24
[1765]25#define FLAG_CLOSE 1
26#define FLAG_SMART 2
27
28int eject_main(int argc, char **argv);
[821]29int eject_main(int argc, char **argv)
30{
31 unsigned long flags;
[1765]32 const char *device;
33 int dev, cmd;
[821]34
[1765]35 opt_complementary = "?1:t--T:T--t";
36 flags = getopt32(argv, "tT");
37 device = argv[optind] ? : "/dev/cdrom";
[821]38
[1765]39 // We used to do "umount <device>" here, but it was buggy
40 // if something was mounted OVER cdrom and
41 // if cdrom is mounted many times.
42 //
43 // This works equally well (or better):
44 // #!/bin/sh
45 // umount /dev/cdrom
46 // eject
47
48 dev = xopen(device, O_RDONLY|O_NONBLOCK);
49 cmd = CDROMEJECT;
50 if (flags & FLAG_CLOSE
51 || (flags & FLAG_SMART && ioctl(dev, CDROM_DRIVE_STATUS) == CDS_TRAY_OPEN))
52 cmd = CDROMCLOSETRAY;
53
54 ioctl_or_perror_and_die(dev, cmd, NULL, "%s", device);
55
56 if (ENABLE_FEATURE_CLEAN_UP)
57 close(dev);
58
59 return EXIT_SUCCESS;
[821]60}
Note: See TracBrowser for help on using the repository browser.