]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - sys-utils/eject.c
Merge branch 'patch-23' of https://github.com/mariobl/util-linux
[thirdparty/util-linux.git] / sys-utils / eject.c
index d534b61b6d19a39dc9dae8748b11e91474e88b43..166d591ec77f112df3e0c645a3f1366e67282fde 100644 (file)
@@ -55,7 +55,7 @@
 #include "monotonic.h"
 
 /*
- * sg_io_hdr_t driver_status -- see kernel include/scsi/scsi.h
+ * sg_io_hdr_t driver_status -- see kernel include/scsi/sg.h
  */
 #ifndef DRIVER_SENSE
 # define DRIVER_SENSE  0x08
@@ -164,10 +164,10 @@ static void __attribute__((__noreturn__)) usage(void)
                out);
 
        fputs(USAGE_SEPARATOR, out);
-       printf(USAGE_HELP_OPTIONS(29));
+       fprintf(out, USAGE_HELP_OPTIONS(29));
 
        fputs(_("\nBy default tries -r, -s, -f, and -q in order until success.\n"), out);
-       printf(USAGE_MAN_TAIL("eject(1)"));
+       fprintf(out, USAGE_MAN_TAIL("eject(1)"));
 
        exit(EXIT_SUCCESS);
 }
@@ -526,15 +526,15 @@ static int read_speed(const char *devname)
                /* find line "drive speed" and read the correct speed */
                } else {
                        if (strncmp(line, "drive speed:", 12) == 0) {
-                               uint64_t n;
+                               int n;
 
                                fclose(f);
 
                                str = line + 12;
                                normalize_whitespace((unsigned char *) str);
 
-                               if (ul_strtou64(str, &n, 10) == 0 && n <= INT_MAX)
-                                       return (int) n;
+                               if (ul_strtos32(str, &n, 10) == 0)
+                                       return n;
 
                                errx(EXIT_FAILURE, _("%s: failed to read speed"),
                                                _PATH_PROC_CDROMINFO);
@@ -807,7 +807,7 @@ done:
        return count;
 }
 
-static int is_hotpluggable(const struct eject_control *ctl)
+static int is_ejectable(const struct eject_control *ctl)
 {
        struct path_cxt *pc = NULL;
        dev_t devno;
@@ -819,7 +819,7 @@ static int is_hotpluggable(const struct eject_control *ctl)
        if (!pc)
                return 0;
 
-       rc = sysfs_blkdev_is_hotpluggable(pc);
+       rc = sysfs_blkdev_is_hotpluggable(pc) || sysfs_blkdev_is_removable(pc);
        ul_unref_path(pc);
        return rc;
 }
@@ -911,8 +911,8 @@ int main(int argc, char **argv)
                verbose(&ctl, _("%s: is whole-disk device"), ctl.device);
        }
 
-       if (ctl.F_option == 0 && is_hotpluggable(&ctl) == 0)
-               errx(EXIT_FAILURE, _("%s: is not hot-pluggable device"), ctl.device);
+       if (ctl.F_option == 0 && is_ejectable(&ctl) == 0)
+               errx(EXIT_FAILURE, _("%s: is not ejectable device"), ctl.device);
 
        /* handle -n option */
        if (ctl.n_option) {