eject: -T (implements single button open/close)
authorDenis Vlasenko <vda.linux@googlemail.com>
Mon, 2 Oct 2006 20:49:25 +0000 (20:49 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Mon, 2 Oct 2006 20:49:25 +0000 (20:49 -0000)
include/usage.h
miscutils/eject.c

index 1da436ad4dbd02a9502790a42ba9d4cfb8063a20..40676c113652a996d972ac6f50c94be23a8beb43 100644 (file)
@@ -638,11 +638,12 @@ USE_FEATURE_DATE_ISOFMT( \
        "Erik\\nis\\ncool\n")
 
 #define eject_trivial_usage \
-       "[-t] [DEVICE]"
+       "[-t] [-T] [DEVICE]"
 #define eject_full_usage \
        "Eject specified DEVICE (or default /dev/cdrom).\n\n" \
        "Options:\n" \
-       "\t-t\tclose tray"
+       "\t-t\tclose tray\n" \
+       "\t-T\topen/close tray (toggle)"
 
 #define ed_trivial_usage ""
 #define ed_full_usage ""
index 282090d38e9c6399ce5b0ceeba85395436674afa..272d95980c34d85aca0afb1f8d44f8f2ef93f655 100644 (file)
 #define CDROMEJECT                0x5309  /* Ejects the cdrom media */
 #define DEFAULT_CDROM             "/dev/cdrom"
 
+#define FLAG_CLOSE  1
+#define FLAG_SMART  2
+
 int eject_main(int argc, char **argv)
 {
        unsigned long flags;
        char *device;
        struct mntent *m;
+       int dev;
 
-       flags = bb_getopt_ulflags(argc, argv, "t");
+       /*bb_opt_complementally = "t--T:T--t";*/
+       flags = bb_getopt_ulflags(argc, argv, "tT");
        device = argv[optind] ? : DEFAULT_CDROM;
 
-       if ((m = find_mount_point(device, bb_path_mtab_file))) {
+       m = find_mount_point(device, bb_path_mtab_file);
+       if (m) {
                if (umount(m->mnt_dir)) {
-                       bb_error_msg_and_die("Can't umount");
+                       bb_error_msg_and_die("can't umount");
                } else if (ENABLE_FEATURE_MTAB_SUPPORT) {
                        erase_mtab(m->mnt_fsname);
                }
        }
-       if (ioctl(xopen(device, (O_RDONLY | O_NONBLOCK)),
-                               (flags ? CDROMCLOSETRAY : CDROMEJECT))) {
-               bb_perror_msg_and_die("%s", device);
+
+       dev = xopen(device, O_RDONLY|O_NONBLOCK);
+
+       if (flags & FLAG_CLOSE) goto close_tray;
+
+       if (ioctl(dev, CDROMEJECT)) {
+close_tray:
+               if (ioctl(dev, CDROMCLOSETRAY))
+                       bb_perror_msg_and_die("%s", device);
        }
-       return (EXIT_SUCCESS);
+
+       if (ENABLE_FEATURE_CLEAN_UP) close(dev);
+
+       return EXIT_SUCCESS;
 }