From aea2a2de7645ae2c7f44425a7e720d03464130bd Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Fri, 27 Sep 2024 16:44:24 +0200 Subject: [PATCH 1/2] udiskslinuxdriveata: Respect ID_ATA_SMART_ACCESS=none Refuse any I/O as an intention. --- src/udiskslinuxdriveata.c | 16 ++++++++++++---- src/udiskslinuxdriveobject.c | 14 ++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/udiskslinuxdriveata.c b/src/udiskslinuxdriveata.c index 24e9b2dc2..0238f6c96 100644 --- a/src/udiskslinuxdriveata.c +++ b/src/udiskslinuxdriveata.c @@ -521,6 +521,16 @@ udisks_linux_drive_ata_refresh_smart_sync (UDisksLinuxDriveAta *drive, guchar count; gboolean noio = FALSE; gboolean awake; + const gchar *smart_access; + + smart_access = g_udev_device_get_property (device->udev_device, "ID_ATA_SMART_ACCESS"); + if (g_strcmp0 (smart_access, "none") == 0) + { + /* FIXME: find a better error code */ + g_set_error_literal (error, UDISKS_ERROR, UDISKS_ERROR_CANCELLED, + "Refusing any I/O due to ID_ATA_SMART_ACCESS being set to 'none'"); + goto out; + } if (drive->standby_enabled) noio = update_io_stats (drive, device); @@ -530,10 +540,8 @@ udisks_linux_drive_ata_refresh_smart_sync (UDisksLinuxDriveAta *drive, /* don't wake up disk unless specically asked to */ if (nowakeup && (!awake || noio)) { - g_set_error (error, - UDISKS_ERROR, - UDISKS_ERROR_WOULD_WAKEUP, - "Disk is in sleep mode and the nowakeup option was passed"); + g_set_error_literal (error, UDISKS_ERROR, UDISKS_ERROR_WOULD_WAKEUP, + "Disk is in sleep mode and the nowakeup option was passed"); goto out_io; } diff --git a/src/udiskslinuxdriveobject.c b/src/udiskslinuxdriveobject.c index 3535604b7..ef4ac6679 100644 --- a/src/udiskslinuxdriveobject.c +++ b/src/udiskslinuxdriveobject.c @@ -1134,23 +1134,29 @@ udisks_linux_drive_object_housekeeping (UDisksLinuxDriveObject *object, cancellable, &local_error)) { - if (nowakeup && (local_error->domain == UDISKS_ERROR && - local_error->code == UDISKS_ERROR_WOULD_WAKEUP)) + if (nowakeup && g_error_matches (local_error, UDISKS_ERROR, UDISKS_ERROR_WOULD_WAKEUP)) { udisks_info ("Drive %s is in a sleep state", g_dbus_object_get_object_path (G_DBUS_OBJECT (object))); g_clear_error (&local_error); } - else if (nowakeup && (local_error->domain == UDISKS_ERROR && - local_error->code == UDISKS_ERROR_DEVICE_BUSY)) + else if (nowakeup && g_error_matches (local_error, UDISKS_ERROR, UDISKS_ERROR_DEVICE_BUSY)) { /* typically because a "secure erase" operation is pending */ udisks_info ("Drive %s is busy", g_dbus_object_get_object_path (G_DBUS_OBJECT (object))); g_clear_error (&local_error); } + else if (g_error_matches (local_error, UDISKS_ERROR, UDISKS_ERROR_CANCELLED)) + { + /* typically because the device indicates it refuses any I/O intentionally */ + udisks_info ("Drive %s is refusing any I/O intentionally", + g_dbus_object_get_object_path (G_DBUS_OBJECT (object))); + g_clear_error (&local_error); + } else { + /* all other errors are reported within the BD_SMART_ERROR domain */ g_propagate_prefixed_error (error, local_error, "Error updating SMART data: "); goto out; } From c63dee200d74ea2c4239d1cffdc16a8c506059d7 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Fri, 27 Sep 2024 16:45:18 +0200 Subject: [PATCH 2/2] man: Document ID_ATA_SMART_ACCESS Might not fully fit the 'DEVICE INFORMATION' section but at least it's at a central place among other udev properties. --- doc/man/udisks.xml.in | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/man/udisks.xml.in b/doc/man/udisks.xml.in index 3d0ecebdf..804d8cd9d 100644 --- a/doc/man/udisks.xml.in +++ b/doc/man/udisks.xml.in @@ -280,6 +280,15 @@ + + + + + Override the access method for SMART data retrieval. Valid values include: sat16, sat12, linux-ide, sunplus, jmicron, none and auto (default). + Specify none to avoid any I/O, in such a case the SmartUpdated property will always equal to 0. + + +