]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
eject: add --manualeject from fedora
authorKarel Zak <kzak@redhat.com>
Tue, 27 Mar 2012 15:09:12 +0000 (17:09 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 27 Mar 2012 15:11:17 +0000 (17:11 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/eject.1
misc-utils/eject.c

index ae92b7fc57ae802a1b4187f359fae6281346286b..26a427dbfea59bea6517d5780b4a88cafbef5a0e 100644 (file)
@@ -17,6 +17,8 @@ eject [\-vn] \-a on|off|1|0 [<name>]
 .br
 eject [\-vn] \-c slot [<name>]
 .br
+eject [\-vn] \-i on|off|1|0 [<name>]
+.br
 eject [\-vn] \-t [<name>]
 .br
 eject [-vn] -T [<name>]
@@ -80,6 +82,13 @@ CD-ROM drive can not be in use (mounted data CD or playing a music CD)
 for a change request to work. Please also note that the first slot of
 the changer is referred to as 0, not 1.
 
+.TP 0.5i
+.B \-i on|1|off|0
+This option controls locking of the hardware eject button. When
+enabled, the drive will not be ejected when the button is pressed.
+This is useful when you are carrying a laptop in a bag or case and
+don't want it to eject if the button is inadvertently pressed.
+
 .TP 0.5i
 .B \-t
 With this option the drive is given a CD-ROM tray close command. Not
index c3b540cecc7aa8ba8e512fcd0f9058edce3b5934..daa9b0630196795230fe380463c095d16ac1f737 100644 (file)
@@ -75,7 +75,9 @@ static int v_option;
 static int x_option;
 static int p_option;
 static int m_option;
+static int i_option;
 static int a_arg;
+static int i_arg;
 static long int c_arg;
 static long int x_arg;
 
@@ -136,6 +138,7 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
                " -d, --default      display default device\n"
                " -a, --auto         turn auto-eject feature on or off\n"
                " -c, --changerslot  switch discs on a CD-ROM changer\n"
+               " -i, --manualeject <on|off> toggle manual eject protection on/off\n"
                " -t, --trayclose    close tray\n"
                " -T, --traytoggle   toggle tray\n"
                " -x, --cdspeed      set CD-ROM max speed\n"
@@ -166,6 +169,7 @@ static void parse_args(int argc, char **argv, char **device)
                {"default",     no_argument,       NULL, 'd'},
                {"auto",        required_argument, NULL, 'a'},
                {"changerslot", required_argument, NULL, 'c'},
+               {"manualeject", required_argument, NULL, 'i'},
                {"trayclose",   no_argument,       NULL, 't'},
                {"traytoggle",  no_argument,       NULL, 'T'},
                {"cdspeed",     required_argument, NULL, 'x'},
@@ -182,7 +186,7 @@ static void parse_args(int argc, char **argv, char **device)
        int c;
 
        while ((c = getopt_long(argc, argv,
-                               "a:c:x:dfhnqrstTvVpm", long_opts, NULL)) != -1) {
+                               "a:c:i:x:dfhnqrstTvVpm", long_opts, NULL)) != -1) {
                switch (c) {
                case 'a':
                        a_option = 1;
@@ -210,6 +214,15 @@ static void parse_args(int argc, char **argv, char **device)
                case 'h':
                        usage(stdout);
                        break;
+               case 'i':
+                       i_option = 1;
+                       if (!strcmp(optarg, "0") || !strcmp(optarg, "off"))
+                               i_arg = 0;
+                       else if (!strcmp(optarg, "1") || !strcmp(optarg, "on"))
+                               i_arg = 1;
+                       else
+                               errx(EXIT_FAILURE, _("invalid argument to --manualeject/-i option"));
+                       break;
                case 'm':
                        m_option = 1;
                        break;
@@ -287,6 +300,27 @@ static void auto_eject(int fd, int on)
                err(EXIT_FAILURE, _("CD-ROM auto-eject command failed"));
 }
 
+/*
+ * Stops CDROM from opening on manual eject pressing the button.
+ * This can be useful when you carry your laptop
+ * in your bag while it's on and no CD inserted in it's drive.
+ * Implemented as found in Documentation/ioctl/cdrom.txt
+ *
+ * TODO: Maybe we should check this also:
+ * EDRIVE_CANT_DO_THIS   Door lock function not supported.
+ * EBUSY                 Attempt to unlock when multiple users
+ *                       have the drive open and not CAP_SYS_ADMIN
+ */
+static void manual_eject(int fd, int on)
+{
+       if (ioctl(fd, CDROM_LOCKDOOR, on) < 0)
+               err(EXIT_FAILURE, _("CD-ROM lock door command failed"));
+
+       if (on)
+               info(_("CD-Drive may NOT be ejected with device button"));
+       else
+               info(_("CD-Drive may be ejected with device button"));
+}
 
 /*
  * Changer select. CDROM_SELECT_DISC is preferred, older kernels used
@@ -717,6 +751,13 @@ int main(int argc, char **argv)
                exit(0);
        }
 
+       /* handle -i option */
+       if (i_option) {
+               fd = open_device(device);
+               manual_eject(fd, i_arg);
+               exit(0);
+       }
+
        /* handle -a option */
        if (a_option) {
                if (a_arg)