13 |
* Most of the dirty work blatantly ripped off from cat.c =) |
* Most of the dirty work blatantly ripped off from cat.c =) |
14 |
*/ |
*/ |
15 |
|
|
16 |
|
#include <sys/mount.h> |
17 |
#include "libbb.h" |
#include "libbb.h" |
18 |
|
/* Must be after libbb.h: they need size_t */ |
19 |
|
#include "fix_u32.h" |
20 |
|
#include <scsi/sg.h> |
21 |
|
#include <scsi/scsi.h> |
22 |
|
|
23 |
/* various defines swiped from linux/cdrom.h */ |
/* various defines swiped from linux/cdrom.h */ |
24 |
#define CDROMCLOSETRAY 0x5319 /* pendant of CDROMEJECT */ |
#define CDROMCLOSETRAY 0x5319 /* pendant of CDROMEJECT */ |
32 |
/* Code taken from the original eject (http://eject.sourceforge.net/), |
/* Code taken from the original eject (http://eject.sourceforge.net/), |
33 |
* refactored it a bit for busybox (ne-bb@nicoerfurth.de) */ |
* refactored it a bit for busybox (ne-bb@nicoerfurth.de) */ |
34 |
|
|
|
#include <scsi/sg.h> |
|
|
#include <scsi/scsi.h> |
|
|
|
|
35 |
static void eject_scsi(const char *dev) |
static void eject_scsi(const char *dev) |
36 |
{ |
{ |
37 |
static const char sg_commands[3][6] = { |
static const char sg_commands[3][6] = { |
76 |
int cmd = CDROMEJECT; |
int cmd = CDROMEJECT; |
77 |
|
|
78 |
if (flags & FLAG_CLOSE |
if (flags & FLAG_CLOSE |
79 |
|| (flags & FLAG_SMART && ioctl(dev_fd, CDROM_DRIVE_STATUS) == CDS_TRAY_OPEN) |
|| ((flags & FLAG_SMART) && ioctl(dev_fd, CDROM_DRIVE_STATUS) == CDS_TRAY_OPEN) |
80 |
) { |
) { |
81 |
cmd = CDROMCLOSETRAY; |
cmd = CDROMCLOSETRAY; |
82 |
} |
} |
91 |
const char *device; |
const char *device; |
92 |
|
|
93 |
opt_complementary = "?1:t--T:T--t"; |
opt_complementary = "?1:t--T:T--t"; |
94 |
flags = getopt32(argv, "tT" USE_FEATURE_EJECT_SCSI("s")); |
flags = getopt32(argv, "tT" IF_FEATURE_EJECT_SCSI("s")); |
95 |
device = argv[optind] ? argv[optind] : "/dev/cdrom"; |
device = argv[optind] ? argv[optind] : "/dev/cdrom"; |
96 |
|
|
97 |
/* We used to do "umount <device>" here, but it was buggy |
/* We used to do "umount <device>" here, but it was buggy |
104 |
eject /dev/cdrom |
eject /dev/cdrom |
105 |
*/ |
*/ |
106 |
|
|
107 |
xmove_fd(xopen(device, O_RDONLY|O_NONBLOCK), dev_fd); |
xmove_fd(xopen_nonblocking(device), dev_fd); |
108 |
|
|
109 |
if (ENABLE_FEATURE_EJECT_SCSI && (flags & FLAG_SCSI)) |
if (ENABLE_FEATURE_EJECT_SCSI && (flags & FLAG_SCSI)) |
110 |
eject_scsi(device); |
eject_scsi(device); |