diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-02 20:49:25 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-10-02 20:49:25 +0000 |
commit | 2e864cd21938eae6365b925dac1e1c29a94a0d20 (patch) | |
tree | c7ea4df8c4a4d853db74423fcca0774f6ae8e40d | |
parent | 546cd1881a1501923badf55b2c9f53f191c3f8d6 (diff) | |
download | busybox-w32-2e864cd21938eae6365b925dac1e1c29a94a0d20.tar.gz busybox-w32-2e864cd21938eae6365b925dac1e1c29a94a0d20.tar.bz2 busybox-w32-2e864cd21938eae6365b925dac1e1c29a94a0d20.zip |
eject: -T (implements single button open/close)
-rw-r--r-- | include/usage.h | 5 | ||||
-rw-r--r-- | miscutils/eject.c | 29 |
2 files changed, 25 insertions, 9 deletions
diff --git a/include/usage.h b/include/usage.h index 1da436ad4..40676c113 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -638,11 +638,12 @@ USE_FEATURE_DATE_ISOFMT( \ | |||
638 | "Erik\\nis\\ncool\n") | 638 | "Erik\\nis\\ncool\n") |
639 | 639 | ||
640 | #define eject_trivial_usage \ | 640 | #define eject_trivial_usage \ |
641 | "[-t] [DEVICE]" | 641 | "[-t] [-T] [DEVICE]" |
642 | #define eject_full_usage \ | 642 | #define eject_full_usage \ |
643 | "Eject specified DEVICE (or default /dev/cdrom).\n\n" \ | 643 | "Eject specified DEVICE (or default /dev/cdrom).\n\n" \ |
644 | "Options:\n" \ | 644 | "Options:\n" \ |
645 | "\t-t\tclose tray" | 645 | "\t-t\tclose tray\n" \ |
646 | "\t-T\topen/close tray (toggle)" | ||
646 | 647 | ||
647 | #define ed_trivial_usage "" | 648 | #define ed_trivial_usage "" |
648 | #define ed_full_usage "" | 649 | #define ed_full_usage "" |
diff --git a/miscutils/eject.c b/miscutils/eject.c index 282090d38..272d95980 100644 --- a/miscutils/eject.c +++ b/miscutils/eject.c | |||
@@ -21,25 +21,40 @@ | |||
21 | #define CDROMEJECT 0x5309 /* Ejects the cdrom media */ | 21 | #define CDROMEJECT 0x5309 /* Ejects the cdrom media */ |
22 | #define DEFAULT_CDROM "/dev/cdrom" | 22 | #define DEFAULT_CDROM "/dev/cdrom" |
23 | 23 | ||
24 | #define FLAG_CLOSE 1 | ||
25 | #define FLAG_SMART 2 | ||
26 | |||
24 | int eject_main(int argc, char **argv) | 27 | int eject_main(int argc, char **argv) |
25 | { | 28 | { |
26 | unsigned long flags; | 29 | unsigned long flags; |
27 | char *device; | 30 | char *device; |
28 | struct mntent *m; | 31 | struct mntent *m; |
32 | int dev; | ||
29 | 33 | ||
30 | flags = bb_getopt_ulflags(argc, argv, "t"); | 34 | /*bb_opt_complementally = "t--T:T--t";*/ |
35 | flags = bb_getopt_ulflags(argc, argv, "tT"); | ||
31 | device = argv[optind] ? : DEFAULT_CDROM; | 36 | device = argv[optind] ? : DEFAULT_CDROM; |
32 | 37 | ||
33 | if ((m = find_mount_point(device, bb_path_mtab_file))) { | 38 | m = find_mount_point(device, bb_path_mtab_file); |
39 | if (m) { | ||
34 | if (umount(m->mnt_dir)) { | 40 | if (umount(m->mnt_dir)) { |
35 | bb_error_msg_and_die("Can't umount"); | 41 | bb_error_msg_and_die("can't umount"); |
36 | } else if (ENABLE_FEATURE_MTAB_SUPPORT) { | 42 | } else if (ENABLE_FEATURE_MTAB_SUPPORT) { |
37 | erase_mtab(m->mnt_fsname); | 43 | erase_mtab(m->mnt_fsname); |
38 | } | 44 | } |
39 | } | 45 | } |
40 | if (ioctl(xopen(device, (O_RDONLY | O_NONBLOCK)), | 46 | |
41 | (flags ? CDROMCLOSETRAY : CDROMEJECT))) { | 47 | dev = xopen(device, O_RDONLY|O_NONBLOCK); |
42 | bb_perror_msg_and_die("%s", device); | 48 | |
49 | if (flags & FLAG_CLOSE) goto close_tray; | ||
50 | |||
51 | if (ioctl(dev, CDROMEJECT)) { | ||
52 | close_tray: | ||
53 | if (ioctl(dev, CDROMCLOSETRAY)) | ||
54 | bb_perror_msg_and_die("%s", device); | ||
43 | } | 55 | } |
44 | return (EXIT_SUCCESS); | 56 | |
57 | if (ENABLE_FEATURE_CLEAN_UP) close(dev); | ||
58 | |||
59 | return EXIT_SUCCESS; | ||
45 | } | 60 | } |