From ac2d3d6b331aeee54fd1650d450d6c34e2a4ed0b Mon Sep 17 00:00:00 2001 From: Alexander Shaduri Date: Tue, 14 May 2024 15:55:12 +0400 Subject: [PATCH] Implement proper SMART on/off switch support detection. --- src/applib/storage_device.cpp | 11 +++++++++++ src/applib/storage_device.h | 3 +++ src/gsc_main_window.cpp | 5 ++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/applib/storage_device.cpp b/src/applib/storage_device.cpp index adb75b2..815e1e4 100644 --- a/src/applib/storage_device.cpp +++ b/src/applib/storage_device.cpp @@ -681,6 +681,17 @@ StorageDevice::Status StorageDevice::get_smart_status() const +bool StorageDevice::get_smart_switch_supported() const +{ + const bool supported = get_smart_status() != Status::Unsupported; + // NVMe does not support on/off + const bool is_nvme = get_detected_type() == StorageDeviceDetectedType::Nvme; + + return !get_is_virtual() && supported && !is_nvme; +} + + + StorageDevice::Status StorageDevice::get_aodc_status() const { // smart-disabled drives are known to print some garbage, so diff --git a/src/applib/storage_device.h b/src/applib/storage_device.h index fe1ab4a..b022d79 100644 --- a/src/applib/storage_device.h +++ b/src/applib/storage_device.h @@ -129,6 +129,9 @@ class StorageDevice { /// Get SMART status [[nodiscard]] Status get_smart_status() const; + /// Get if SMART on/off is supported + [[nodiscard]] bool get_smart_switch_supported() const; + /// Get AODC status [[nodiscard]] Status get_aodc_status() const; diff --git a/src/gsc_main_window.cpp b/src/gsc_main_window.cpp index 3da621c..3c82d5a 100644 --- a/src/gsc_main_window.cpp +++ b/src/gsc_main_window.cpp @@ -638,6 +638,9 @@ void GscMainWindow::on_action_enable_smart_toggled(Gtk::ToggleAction* action) if (!drive || drive->get_is_virtual() || drive->get_test_is_active()) return; + if (!drive->get_smart_switch_supported()) + return; + StorageDevice::Status status = drive->get_smart_status(); if (status == StorageDevice::Status::Unsupported) // this shouldn't happen return; @@ -848,7 +851,7 @@ void GscMainWindow::set_drive_menu_status(const StorageDevicePtr& drive) if ((action = actiongroup_device_->get_action(APP_ACTION_NAME(action_remove_virtual_device)))) action->set_visible(drive && is_virtual); if ((action = actiongroup_device_->get_action(APP_ACTION_NAME(action_enable_smart)))) { - action->set_sensitive(smart_status != StorageDevice::Status::Unsupported); + action->set_sensitive(drive && drive->get_smart_switch_supported()); } if ((action = actiongroup_device_->get_action(APP_ACTION_NAME(action_enable_aodc)))) action->set_sensitive(aodc_status != StorageDevice::Status::Unsupported);