From: Alessandro Ratti Date: Wed, 8 Apr 2026 16:25:07 +0000 (+0200) Subject: eject: tolerate ILLEGAL REQUEST on ALLOW_MEDIUM_REMOVAL X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=910c6f066534db3a531bca5f077b34adbc350c92;p=thirdparty%2Futil-linux.git eject: tolerate ILLEGAL REQUEST on ALLOW_MEDIUM_REMOVAL 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 --- diff --git a/sys-utils/eject.c b/sys-utils/eject.c index 7ebbdaab5..d8d413177 100644 --- a/sys-utils/eject.c +++ b/sys-utils/eject.c @@ -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;