]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
eject: tolerate ILLEGAL REQUEST on ALLOW_MEDIUM_REMOVAL
authorAlessandro Ratti <alessandro@0x65c.net>
Wed, 8 Apr 2026 16:25:07 +0000 (18:25 +0200)
committerAlessandro Ratti <alessandro@0x65c.net>
Wed, 8 Apr 2026 20:26:25 +0000 (22:26 +0200)
Some USB devices using the UAS driver do not support the SCSI
ALLOW_MEDIUM_REMOVAL command and return ILLEGAL REQUEST (sense
key 0x05). Previously, eject_scsi() treated any non-zero
driver_status as fatal, aborting before attempting START_STOP.

Now, when the device reports DRIVER_SENSE with sense key ILLEGAL
REQUEST, we continue to the START_STOP eject commands instead
of bailing out.

Addresses: https://github.com/util-linux/util-linux/issues/4125

Signed-off-by: Alessandro Ratti <alessandro@0x65c.net>
sys-utils/eject.c

index 7ebbdaab5747abed9b169c0b1405542b392673a0..d8d4131779259b1d01705c6bc2602daf5b42660d 100644 (file)
@@ -597,7 +597,17 @@ static int eject_scsi(const struct eject_control *ctl)
 
        io_hdr.cmdp = allowRmBlk;
        status = ioctl(ctl->fd, SG_IO, (void *)&io_hdr);
-       if (status < 0 || io_hdr.host_status || io_hdr.driver_status)
+       if (status < 0 || io_hdr.host_status)
+               return 0;
+
+       /*
+        * Ignore ILLEGAL REQUEST -- the device does not support
+        * ALLOW_MEDIUM_REMOVAL, but it may still support START_STOP
+        * for eject (e.g. USB mass storage devices).
+        */
+       if (io_hdr.driver_status != 0 &&
+           !(io_hdr.driver_status == DRIVER_SENSE && io_hdr.sbp &&
+                                            (io_hdr.sbp[2] & 0x0f) == ILLEGAL_REQUEST))
                return 0;
 
        io_hdr.cmdp = startStop1Blk;