From bdae4343e1c34dbdc55af307419354a7cfd2afd4 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 1 Jul 2008 00:03:01 +0200 Subject: add basic self test support to g-d-h --- gnome-disk-health.glade | 279 ++++++++++++++++++++++++------------------------ gnome-disk-health.vala | 140 ++++++++++++++++++++++-- 2 files changed, 270 insertions(+), 149 deletions(-) diff --git a/gnome-disk-health.glade b/gnome-disk-health.glade index 5453e84..c345aba 100644 --- a/gnome-disk-health.glade +++ b/gnome-disk-health.glade @@ -1,6 +1,6 @@ - + 5 @@ -48,66 +48,54 @@ 6 6 - + True - 0 - label + 1 + <b>Path:</b> + True - 1 - 2 - 4 - 5 + GTK_FILL + GTK_FILL - + True - 0 - label + 1 + <b>Size:</b> + True - 1 - 2 - 3 - 4 + 1 + 2 + GTK_FILL - + True - 0 - label + 1 + <b>Model:</b> + True - 1 - 2 2 3 + GTK_FILL - - True - 0 - label - - - 1 - 2 - 1 - 2 - - - - + True - 0 - label + 1 + <b>Serial Number:</b> + True - 1 - 2 + 3 + 4 + GTK_FILL @@ -124,54 +112,66 @@ - + True - 1 - <b>Serial Number:</b> - True + 0 + label - 3 - 4 - GTK_FILL + 1 + 2 - + True - 1 - <b>Model:</b> - True + 0 + label + + + 1 + 2 + 1 + 2 + + + + + True + 0 + label + 1 + 2 2 3 - GTK_FILL - + True - 1 - <b>Size:</b> - True + 0 + label - 1 - 2 - GTK_FILL + 1 + 2 + 3 + 4 - + True - 1 - <b>Path:</b> - True + 0 + label - GTK_FILL - GTK_FILL + 1 + 2 + 4 + 5 @@ -299,58 +299,67 @@ 6 6 - + True - 0 - label + 1 + <b>Name:</b> + True - 1 - 2 - 6 - 7 GTK_FILL GTK_FILL - + True 1 - <b>Verdict:</b> + <b>ID:</b> True - 6 - 7 + 1 + 2 GTK_FILL GTK_FILL - + True - 0 - label + 1 + <b>Current Value:</b> + True - 1 - 2 - 5 - 6 + 2 + 3 GTK_FILL GTK_FILL - + True - 0 - label + 1 + <b>Worst Value:</b> + True + + + 3 + 4 + GTK_FILL + GTK_FILL + + + + + True + 1 + <b>Threshold:</b> + True - 1 - 2 4 5 GTK_FILL @@ -358,22 +367,21 @@ - + True - 0 - label + 1 + <b>Type:</b> + True - 1 - 2 - 3 - 4 + 5 + 6 GTK_FILL GTK_FILL - + True 0 label @@ -381,8 +389,6 @@ 1 2 - 2 - 3 GTK_FILL GTK_FILL @@ -403,7 +409,7 @@ - + True 0 label @@ -411,32 +417,36 @@ 1 2 + 2 + 3 GTK_FILL GTK_FILL - + True - 1 - <b>Type:</b> - True + 0 + label - 5 - 6 + 1 + 2 + 3 + 4 GTK_FILL GTK_FILL - + True - 1 - <b>Threshold:</b> - True + 0 + label + 1 + 2 4 5 GTK_FILL @@ -444,55 +454,45 @@ - - True - 1 - <b>Worst Value:</b> - True - - - 3 - 4 - GTK_FILL - GTK_FILL - - - - + True - 1 - <b>Current Value:</b> - True + 0 + label - 2 - 3 + 1 + 2 + 5 + 6 GTK_FILL GTK_FILL - + True 1 - <b>ID:</b> + <b>Verdict:</b> True - 1 - 2 + 6 + 7 GTK_FILL GTK_FILL - + True - 1 - <b>Name:</b> - True + 0 + label + 1 + 2 + 6 + 7 GTK_FILL GTK_FILL @@ -540,12 +540,12 @@ True 6 - + True - + True True True @@ -563,9 +563,10 @@ - + True Self-test functionality available. Approximate run-time is 120 min. + GTK_JUSTIFY_CENTER True @@ -599,7 +600,7 @@ True GTK_BUTTONBOX_END - + True True True diff --git a/gnome-disk-health.vala b/gnome-disk-health.vala index 6bf064c..9595f15 100644 --- a/gnome-disk-health.vala +++ b/gnome-disk-health.vala @@ -33,11 +33,17 @@ public class DiskHealth : Gtk.Builder { add_from_file (uifile); Gtk.Widget window = (Gtk.Widget) get_object("DiskHealthDialog"); - if (!fill_in_data(disk_string)) + if (!setup_connection(disk_string)) + return false; + + if (!fill_in_data()) return false; window.show_all(); window.destroy += Gtk.main_quit; + + ((Gtk.Button) get_object("closeButton")).clicked += Gtk.main_quit; + } catch (GLib.Error e) { stderr.printf("Failed to create main window: %s\n", e.message); return false; @@ -51,8 +57,7 @@ public class DiskHealth : Gtk.Builder { private DBus.ObjectPath dbus_path; private dynamic DBus.Object disk; - public bool fill_in_data(string disk_string) { - + public bool setup_connection(string disk_string) { try { connection = DBus.Bus.get(DBus.BusType.SYSTEM); @@ -73,7 +78,17 @@ public class DiskHealth : Gtk.Builder { stderr.printf("Using D-Bus path %s\n", p); disk = connection.get_object("net.poettering.SmartKit", p, "net.poettering.SmartKit.Disk"); + } catch (DBus.Error e) { + stderr.printf("D-Bus error: %s\n", e.message); + return false; + } + + return true; + } + + public bool fill_in_data() { + try { ((Gtk.Label) get_object("pathLabel")).set_label(disk.getPath()); ((Gtk.Label) get_object("sizeLabel")).set_label(pretty_size(disk.getSize())); @@ -92,15 +107,112 @@ public class DiskHealth : Gtk.Builder { if (b) b = disk.isSmartAvailable(); - if (b) { - ((Gtk.Label) get_object("smartLabel")).set_label("Disk health functionality (S.M.A.R.T.) is available."); - } else { - ((Gtk.Label) get_object("smartLabel")).set_markup("Disk health functionality (S.M.A.R.T.) is not available."); - ((Gtk.Label) get_object("healthLabel")).set_label(""); - ((Gtk.Label) get_object("badSectorsLabel")).set_label(""); - ((Gtk.Label) get_object("temperatureLabel")).set_label(""); + if (b) + return fill_in_smart_data(); + else + return fill_in_no_smart_data(); + + } catch (DBus.Error e) { + stderr.printf("D-Bus error: %s\n", e.message); + return false; + } + } + + public bool fill_in_no_smart_data() { + + ((Gtk.Label) get_object("smartLabel")).set_markup("Disk health functionality (S.M.A.R.T.) is not available."); + ((Gtk.Label) get_object("healthLabel")).set_label(""); + ((Gtk.Label) get_object("badSectorsLabel")).set_label(""); + ((Gtk.Label) get_object("temperatureLabel")).set_label(""); + + return fill_in_no_self_test_data(); + } + + public bool fill_in_smart_data() { + try { + + ((Gtk.Label) get_object("smartLabel")).set_label("Disk health functionality (S.M.A.R.T.) is available."); + + bool b = disk.checkSmartStatus(); + + if (b) + ((Gtk.Label) get_object("healthLabel")).set_label("Disk reports to be healthy."); + else + ((Gtk.Label) get_object("healthLabel")).set_label("Disk reports that it has already failed or is expected to fail in the next 24h."); + + bool a = disk.getStartTestAvailable(); + b = disk.getConveyanceTestAvailable(); + bool c = disk.getShortAndExtendedTestAvailable(); + + if (a && (b || c)) + return fill_in_self_test_data(); + else + return fill_in_no_self_test_data(); + + } catch (DBus.Error e) { + stderr.printf("D-Bus error: %s\n", e.message); + return false; + } + } + + public bool fill_in_self_test_data() { + try { + bool show_percent = false; + string text; + + string state = disk.getSelfTestExecutionStatus(); + + switch (state) { + case "success-or-never": + text = "The previous self-test completed without error or no self-test has ever been run."; + break; + case "aborted": + text = "The previous self-test was aborted by the user."; + break; + case "interrupted": + text = "The previous self-test was interrupted by the host with a hardware or software reset."; + break; + case "fatal": + text = "A fatal error or unknown test error occurred while the device was executing the previous self-test and the device was unable to complete the self-test."; + break; + case "error-unknown": + text = "The previous self-test completed having a test element that failed."; + break; + case "error-electrical": + text = "The previous self-test completed having the electrical element of the test failed."; + break; + case "eror-servo": + text = "The previous self-test completed having the servo (and/or seek) test element of the test failed."; + break; + case "error-read": + text = "The previous self-test completed having the read element of the test failed."; + break; + case "error-handling": + text = "The previous self-test completed having a test element that failed and the device is suspected of having handling damage."; + break; + case "inprogress": + text = "Self-test in progres..."; + show_percent = true; + break; + + default: + text = "Unknown state"; + break; } + + ((Gtk.Label) get_object("selfTestLabel")).set_label(text); + + if (show_percent) { + uint percent = disk.getSelfTestExecutionPercentRemaining(); + + ((Gtk.ProgressBar) get_object("selfTestProgressBar")).set_fraction((double) (100-percent)/100); + ((Gtk.ProgressBar) get_object("selfTestProgressBar")).set_text("%u%% remaining".printf(percent)); + } else + ((Gtk.ProgressBar) get_object("selfTestProgressBar")).set_text("n/a"); + + ((Gtk.ProgressBar) get_object("selfTestProgressBar")).set_sensitive(show_percent); + } catch (DBus.Error e) { stderr.printf("D-Bus error: %s\n", e.message); return false; @@ -109,6 +221,14 @@ public class DiskHealth : Gtk.Builder { return true; } + public bool fill_in_no_self_test_data() { + ((Gtk.Label) get_object("selfTestLabel")).set_label("Self-test functionality is not available."); + ((Gtk.Button) get_object("selfTestButton")).set_sensitive(false); + ((Gtk.ProgressBar) get_object("selfTestProgressBar")).set_sensitive(false); + + return true; + } + public static string pretty_size(uint64 size) { if (size >= (uint64)1024*(uint64)1024*(uint64)1024*(uint64)1024) -- cgit