[PATCH] Expose SMART power on time as property DriveAtaPowerOnTime

Forest Bond forest at alittletooquiet.net
Tue May 3 14:06:02 PDT 2011


From: Forest Bond <forest.bond at rapidrollout.com>

---
 data/org.freedesktop.UDisks.Device.xml |    8 ++++++++
 src/device-private.c                   |   11 +++++++++++
 src/device-private.h                   |    2 ++
 src/device.c                           |   19 +++++++++++++++++++
 tools/udisks.c                         |    3 +++
 5 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/data/org.freedesktop.UDisks.Device.xml b/data/org.freedesktop.UDisks.Device.xml
index a7e120d..2370887 100644
--- a/data/org.freedesktop.UDisks.Device.xml
+++ b/data/org.freedesktop.UDisks.Device.xml
@@ -2427,6 +2427,14 @@
             is greater than zero.
       </doc:para></doc:description></doc:doc>
     </property>
+    <property name="DriveAtaSmartPowerOnTime" type="t" access="read">
+      <doc:doc><doc:description><doc:para>
+            The total power-on time for the disk in ms.
+            This property is only valid if
+            <doc:ref type="property" to="Device:DriveAtaSmartTimeCollected">DriveAtaSmartTimeCollected</doc:ref>
+            is greater than zero.
+      </doc:para></doc:description></doc:doc>
+    </property>
 
     <!-- **************************************************************************************************** -->
 
diff --git a/src/device-private.c b/src/device-private.c
index d92ee8b..ffd5527 100644
--- a/src/device-private.c
+++ b/src/device-private.c
@@ -1412,6 +1412,17 @@ device_set_drive_ata_smart_temperature (Device *device,
     }
 }
 
+void
+device_set_drive_ata_smart_power_on_time (Device *device,
+                                        uint64_t value)
+{
+  if (device->priv->drive_ata_smart_power_on_time != value)
+    {
+      device->priv->drive_ata_smart_power_on_time = value;
+      emit_changed (device, "drive_ata_smart_power_on_time");
+    }
+}
+
 
 void
 device_set_linux_lvm2_lv_name (Device *device,
diff --git a/src/device-private.h b/src/device-private.h
index 5621179..2f775c7 100644
--- a/src/device-private.h
+++ b/src/device-private.h
@@ -228,6 +228,7 @@ struct DevicePrivate
   void *drive_ata_smart_blob;
   gsize drive_ata_smart_blob_size;
   uint64_t drive_ata_smart_temperature;
+  uint64_t drive_ata_smart_power_on_time;
 
   gchar *linux_dmmp_component_holder;
 
@@ -394,6 +395,7 @@ void device_set_drive_ata_smart_is_available (Device *device, gboolean value);
 void device_set_drive_ata_smart_time_collected (Device *device, guint64 value);
 void device_set_drive_ata_smart_status (Device *device, SkSmartOverall value);
 void device_set_drive_ata_smart_temperature (Device *device, uint64_t value);
+void device_set_drive_ata_smart_power_on_time (Device *device, uint64_t value);
 void device_set_drive_ata_smart_blob_steal (Device *device, gchar *blob, gsize blob_size);
 
 G_END_DECLS
diff --git a/src/device.c b/src/device.c
index edb21d7..0ab0880 100644
--- a/src/device.c
+++ b/src/device.c
@@ -276,6 +276,7 @@ enum
     PROP_DRIVE_ATA_SMART_STATUS,
     PROP_DRIVE_ATA_SMART_BLOB,
     PROP_DRIVE_ATA_SMART_TEMPERATURE,
+    PROP_DRIVE_ATA_SMART_POWER_ON_TIME,
 
     PROP_LINUX_MD_COMPONENT_LEVEL,
     PROP_LINUX_MD_COMPONENT_POSITION,
@@ -684,6 +685,9 @@ get_property (GObject *object,
     case PROP_DRIVE_ATA_SMART_TEMPERATURE:
       g_value_set_uint64 (value, device->priv->drive_ata_smart_temperature);
       break;
+    case PROP_DRIVE_ATA_SMART_POWER_ON_TIME:
+      g_value_set_uint64 (value, device->priv->drive_ata_smart_power_on_time);
+      break;
 
     case PROP_LINUX_MD_COMPONENT_LEVEL:
       g_value_set_string (value, device->priv->linux_md_component_level);
@@ -1457,6 +1461,15 @@ device_class_init (DeviceClass *klass)
                                                         G_MAXUINT64,
                                                         0,
                                                         G_PARAM_READABLE));
+  g_object_class_install_property (object_class,
+                                   PROP_DRIVE_ATA_SMART_POWER_ON_TIME,
+                                   g_param_spec_uint64 ("drive-ata-smart-power-on-time",
+                                                        NULL,
+                                                        NULL,
+                                                        0,
+                                                        G_MAXUINT64,
+                                                        0,
+                                                        G_PARAM_READABLE));
 
   g_object_class_install_property (object_class,
                                    PROP_LINUX_MD_COMPONENT_LEVEL,
@@ -9680,6 +9693,7 @@ drive_ata_smart_refresh_data_completed_cb (DBusGMethodInvocation *context,
   time_t time_collected;
   SkSmartOverall overall;
   uint64_t temperature;
+  uint64_t power_on_time;
 
   PROFILE ("drive_ata_smart_refresh_data_completed_cb(device=%s) start", device->priv->native_path);
 
@@ -9777,9 +9791,14 @@ drive_ata_smart_refresh_data_completed_cb (DBusGMethodInvocation *context,
   if (sk_disk_smart_get_temperature (d, &temperature) != 0)
     temperature = 0;
 
+  PROFILE ("drive_ata_smart_refresh_data_completed_cb(device=%s) power on time", device->priv->native_path);
+  if (sk_disk_smart_get_power_on (d, &power_on_time) != 0)
+    power_on_time = 0;
+
   device_set_drive_ata_smart_status (device, overall);
   device_set_drive_ata_smart_blob_steal (device, blob, blob_size);
   device_set_drive_ata_smart_temperature (device, temperature);
+  device_set_drive_ata_smart_power_on_time (device, power_on_time);
   blob = NULL;
 
   /* emit change event since we've updated the smart data */
diff --git a/tools/udisks.c b/tools/udisks.c
index 007fe9c..b5fad79 100644
--- a/tools/udisks.c
+++ b/tools/udisks.c
@@ -414,6 +414,7 @@ typedef struct
   gchar *drive_ata_smart_blob;
   gsize drive_ata_smart_blob_size;
   guint64 drive_ata_smart_temperature;
+  guint64 drive_ata_smart_power_on_time;
 
   char *linux_md_component_level;
   int linux_md_component_position;
@@ -692,6 +693,8 @@ collect_props (const char *key,
     }
   else if (strcmp (key, "DriveAtaSmartTemperature") == 0)
     props->drive_ata_smart_temperature = g_value_get_uint64 (value);
+  else if (strcmp (key, "DriveAtaSmartPowerOnTime") == 0)
+    props->drive_ata_smart_power_on_time = g_value_get_uint64 (value);
 
   else if (strcmp (key, "LinuxMdComponentLevel") == 0)
     props->linux_md_component_level = g_strdup (g_value_get_string (value));
-- 
1.7.0.4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.freedesktop.org/archives/devkit-devel/attachments/20110503/5b29cb00/attachment.pgp>


More information about the devkit-devel mailing list