[PATCH] Check runtime_pm status

Phillip Susi psusi at ubuntu.com
Fri Nov 15 19:25:12 PST 2013


Check the kernel runtime pm status to see if a drive is sleeping
before attempting the ata CHECK POWER command.
---
 src/udiskslinuxdriveata.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/src/udiskslinuxdriveata.c b/src/udiskslinuxdriveata.c
index 1575b3d..6d42d48 100644
--- a/src/udiskslinuxdriveata.c
+++ b/src/udiskslinuxdriveata.c
@@ -427,6 +427,26 @@ selftest_status_to_string (SkSmartSelfTestExecutionStatus status)
   return ret;
 }
 
+static gchar *
+get_sysfs_attr (GUdevDevice *device,
+                const gchar *attr)
+{
+  gchar *filename;
+  gchar *value;
+  filename = g_strconcat (g_udev_device_get_sysfs_path (device),
+                          "/",
+                          attr,
+                          NULL);
+  value = NULL;
+  /* don't care about errors */
+  g_file_get_contents (filename,
+                       &value,
+                       NULL,
+                       NULL);
+  g_free (filename);
+  return value;
+}
+
 static gboolean get_pm_state (UDisksLinuxDevice *device, GError **error, guchar *count)
 {
   int fd = open (g_udev_device_get_device_file (device->udev_device), O_RDONLY|O_NONBLOCK);
@@ -434,7 +454,15 @@ static gboolean get_pm_state (UDisksLinuxDevice *device, GError **error, guchar
   /* ATA8: 7.8 CHECK POWER MODE - E5h, Non-Data */
   UDisksAtaCommandInput input = {.command = 0xe5};
   UDisksAtaCommandOutput output = {0};
+  gchar *rt_status;
 
+  rt_status = get_sysfs_attr(device->udev_device, "device/power/runtime_status");
+  if (rt_status && g_str_has_prefix (rt_status, "suspend"))
+    {
+      *count = 0;
+      rc = TRUE;
+      goto out;
+    }
   if (fd == -1)
     {
       g_set_error (error, UDISKS_ERROR, UDISKS_ERROR_FAILED,
@@ -459,6 +487,8 @@ static gboolean get_pm_state (UDisksLinuxDevice *device, GError **error, guchar
  out:
   if (fd != -1)
     close(fd);
+  if (rt_status)
+    g_free (rt_status);
   return rc;
 }
 
-- 
1.8.3.2



More information about the devkit-devel mailing list