udisks called in gnome-disks issues cd eject command when removing hot swap-able HDD or SSD SATA drives leading to an IOCTL error
As reported here at the gnome-disk-utility package who asked me to report this upstream as well: [https://bugs.launchpad.net/ubuntu/+source/gnome-disk-utility/+bug/1858860]
Use case:
As a user of hot swap-able SATA disks using a Harddrive Riser over eSATA. I need a safe, easy and convenient way to remove the hot swap-able SATA disk without rebooting and without having to go to the command line.
When attempting to eject an harddisk or a solid state disk using the eject button in "Gnome Disk Utility" it issues the 'eject' command which results in an IOCTL error. The correct commands the eject button in the GUI should issue to eject a SATA HDD or SSD are:
The correct commands to issue:
# where X is the drive letter of the drive being worked with
# -Y Put drive to sleep
sudo hdparm -Y /dev/sdX
# remove the device from the kernel
sudo sh -c 'echo 1 > /sys/block/sdX/device/delete'
Please see the screen shots for the error. This should be an easy fix (20 minutes) for someone who is a good programmer.
ProblemType: Bug DistroRelease: Ubuntu 18.04 Package: gnome-disk-utility 3.28.3-0ubuntu1~18.04.1 ProcVersionSignature: Ubuntu 4.15.0-74.84-generic 4.15.18 Uname: Linux 4.15.0-74-generic x86_64 NonfreeKernelModules: nvidia_modeset nvidia ApportVersion: 2.20.9-0ubuntu7.9 Architecture: amd64 CurrentDesktop: ubuntu:GNOME Date: Wed Jan 8 21:07:32 2020 InstallationDate: Installed on 2018-11-11 (423 days ago) InstallationMedia: Ubuntu 18.04.1 LTS "Bionic Beaver" - Release amd64 (20180725) SourcePackage: gnome-disk-utility UpgradeStatus: No upgrade log present (probably fresh install)
The Source code file location where this happens I'm pretty sure is here:
/src/disks/gduwindow.c
/* ---------------------------------------------------------------------------------------------------- */
static void
eject_cb (UDisksDrive *drive,
GAsyncResult *res,
gpointer user_data)
{
GduWindow *window = GDU_WINDOW (user_data);
GError *error;
error = NULL;
if (!udisks_drive_call_eject_finish (drive,
res,
&error))
{
gdu_utils_show_error (GTK_WINDOW (window),
_("Error ejecting media"),
error);
g_error_free (error);
}
g_object_unref (window);
}
static void
eject_ensure_unused_cb (GduWindow *window,
GAsyncResult *res,
gpointer user_data)
{
UDisksObject *object = UDISKS_OBJECT (user_data);
if (gdu_window_ensure_unused_finish (window, res, NULL))
{
UDisksDrive *drive = udisks_object_peek_drive (object);
udisks_drive_call_eject (drive,
g_variant_new ("a{sv}", NULL), /* options */
NULL, /* cancellable */
(GAsyncReadyCallback) eject_cb,
g_object_ref (window));
}
g_object_unref (object);
}
static void
on_devtab_drive_eject_button_clicked (GtkButton *button,
gpointer user_data)
{
GduWindow *window = GDU_WINDOW (user_data);
gdu_window_ensure_unused (window,
window->current_object,
(GAsyncReadyCallback) eject_ensure_unused_cb,
NULL, /* GCancellable */
g_object_ref (window->current_object));
}
/* ---------------------------------------------------------------------------------------------------- */

Translation of the Error message to English:
Removal of the medium has failed
Error ejecting /dev/sdi: Command-line `eject"/dev/sdi"' exited with a non-zero status 1: eject: could not eject, last error: Incorrect ioctl() for device (udisks-error-quark, 0)
So you can see in the error message that the incorrect command was used for the type of drive.
Example use case riser device in question
This one is eSATA and USB
