Renamed "type" field (and all related stuff) of StorageDevice to detected_type.

This commit is contained in:
Alexander Shaduri
2011-04-04 16:46:28 +00:00
parent 6d50abb3cf
commit 9a92bfec45
6 changed files with 40 additions and 45 deletions
+1 -2
View File
@@ -71,6 +71,7 @@ Add support for multiple drives behind devices.
each one with optional smartctl parameters.
Use :: as delimiter, as in device::-d_string::other_options.
Show in UI as device (-d_string).
Preferences will match it as device::-d_string
Rework drive properties UI:
add properties for each multi-drive.
@@ -106,8 +107,6 @@ Monitor:
Periodically see if drives were added / removed (possibly use OS callbacks
instead of polling?)
+Add a hint about "pd0" for Windows version.
If a drive is not recognized, suggest using -d (sat, sat,12, ...)
Refer the user to
http://sourceforge.net/apps/trac/smartmontools/wiki/Supported_USB-Devices
@@ -156,7 +156,7 @@ std::string StorageDetector::fetch_basic_data(std::vector<StorageDeviceRefPtr>&
debug_out_dump("app", "Device information for " << drive->get_device() << ":\n"
<< "\tModel: " << drive->get_model_name() << "\n"
<< "\tType: " << StorageDevice::get_type_readable_name(drive->get_type()) << "\n"
<< "\tDetected type: " << StorageDevice::get_type_readable_name(drive->get_detected_type()) << "\n"
<< "\tSMART status: " << StorageDevice::get_status_name(drive->get_smart_status()) << "\n"
);
@@ -31,7 +31,7 @@ int main()
} else {
for (unsigned int i = 0; i < drives.size(); ++i) {
std::cerr << drives[i]->get_device() <<
" (" << StorageDevice::get_type_readable_name(drives[i]->get_type()) << ")\n";
" (" << StorageDevice::get_type_readable_name(drives[i]->get_detected_type()) << ")\n";
}
}
+10 -16
View File
@@ -39,9 +39,9 @@ std::string StorageDevice::fetch_basic_data_and_parse(hz::intrusive_ptr<CmdexSyn
// This means that the old SCSI identify command isn't executed by default,
// and there is no information about the device manufacturer/etc... in the output.
// We detect this and set the device type to scsi to at least have _some_ info.
if (get_type() == type_invalid) {
if (get_detected_type() == detected_type_invalid) {
debug_out_info("app", "The device seems to be of different type than auto-detected, trying again with scsi.\n");
this->set_type(type_scsi);
this->set_detected_type(detected_type_scsi);
return this->fetch_basic_data_and_parse(smartctl_ex); // try again with scsi
}
@@ -75,13 +75,7 @@ std::string StorageDevice::parse_basic_data(bool do_set_properties, bool emit_si
// detect type. note: we can't distinguish between sata and scsi (on linux, for -d ata switch).
if (app_pcre_match("/this device: CD\\/DVD/mi", info_output_)) {
this->set_type(type_cddvd);
// } else {
// std::string dev_base = get_device_base();
// if (!dev_base.empty() && dev_base[0] == 'h') { // e.g. hda
// this->set_type(type_pata);
// }
this->set_detected_type(detected_type_cddvd);
}
// Note: We don't use SmartctlParser here, because this information
@@ -167,7 +161,7 @@ std::string StorageDevice::fetch_data_and_parse(hz::intrusive_ptr<CmdexSync> sma
// instead of -a, we use all the individual options -a encompasses, so that
// an addition to default -a output won't affect us.
if (this->get_type() == type_scsi) {
if (this->get_detected_type() == detected_type_scsi) {
// This doesn't do much yet, but just in case...
// SCSI equivalent of -a:
error_msg = execute_smartctl("-H -i -A -l error -l selftest", smartctl_ex, output);
@@ -177,9 +171,9 @@ std::string StorageDevice::fetch_data_and_parse(hz::intrusive_ptr<CmdexSync> sma
smartctl_ex, output, true); // set type to invalid if needed
}
// See notes above (in fetch_basic_data_and_parse()).
if (get_type() == type_invalid) {
if (get_detected_type() == detected_type_invalid) {
debug_out_info("app", "The device seems to be of different type than auto-detected, trying again with scsi.\n");
this->set_type(type_scsi);
this->set_detected_type(detected_type_scsi);
return this->fetch_data_and_parse(smartctl_ex); // try again with scsi
}
@@ -454,10 +448,10 @@ std::string StorageDevice::get_device_options() const
// If we have some special type, specify it on the command line (like "-d scsi").
// Note that the latter "-d" option overrides the former, so we're ok with multiple ones.
std::string type_arg = get_type_arg_name(this->get_type());
std::string type_arg = get_type_arg_name(this->get_detected_type());
if (!type_arg.empty()) {
if (!config_options.empty()) {
if (!config_options.empty()) {
config_options += " ";
}
config_options += "-d " + type_arg;
@@ -531,9 +525,9 @@ std::string StorageDevice::execute_smartctl(const std::string& command_options,
// This means that the old SCSI identify command isn't executed by default,
// and there is no information about the device manufacturer/etc... in the output.
// We detect this and set the device type to scsi to at least have _some_ info.
if (check_type && this->get_type() == type_unknown
if (check_type && this->get_detected_type() == detected_type_unknown // && this->get_type() == ""
&& app_pcre_match("/specify device type with the -d option/mi", output)) {
this->set_type(type_invalid);
this->set_detected_type(detected_type_invalid);
}
return smartctl_ex->get_error_msg();
+26 -24
View File
@@ -28,35 +28,35 @@ class StorageDevice : public hz::intrusive_ptr_referenced {
// these may be used to force smartctl to a special type, as well as
// to display the correct icon
enum type_t {
type_unknown, // unknown. will be autodetected by smartctl
type_invalid, // this is set by smartctl executor if it detects invalid type (but not if it's scsi).
type_cddvd, // unsupported by smartctl, only basic info is given.
type_scsi // this is used to force "-d scsi" to execute IDENTIFY command.
enum detected_type_t {
detected_type_unknown, // unknown. will be autodetected by smartctl
detected_type_invalid, // this is set by smartctl executor if it detects invalid type (but not if it's scsi).
detected_type_cddvd, // unsupported by smartctl, only basic info is given.
detected_type_scsi // this is used to force "-d scsi" to execute IDENTIFY command.
};
// this gives a string which can be displayed in outputs
static std::string get_type_readable_name(type_t type)
static std::string get_type_readable_name(detected_type_t type)
{
switch (type) {
case type_unknown: return "unknown";
case type_invalid: return "invalid";
case type_cddvd: return "cd/dvd";
case type_scsi: return "scsi";
case detected_type_unknown: return "unknown";
case detected_type_invalid: return "invalid";
case detected_type_cddvd: return "cd/dvd";
case detected_type_scsi: return "scsi";
}
return "[internal_error]";
}
// this gives a string which, if not empty, can be given as a parameter of "-d".
static std::string get_type_arg_name(type_t type)
static std::string get_type_arg_name(detected_type_t type)
{
switch (type) {
case type_unknown: return "";
case type_invalid: return "";
case type_cddvd: return "";
case type_scsi: return "scsi";
case detected_type_unknown: return "";
case detected_type_invalid: return "";
case detected_type_cddvd: return "";
case detected_type_scsi: return "scsi";
}
return "";
}
@@ -84,7 +84,7 @@ class StorageDevice : public hz::intrusive_ptr_referenced {
StorageDevice(const std::string& dev_or_vfile, bool is_virtual = false)
{
type_ = type_unknown;
detected_type_ = detected_type_unknown;
// force_type_ = false;
is_virtual_ = is_virtual;
is_manually_added_ = false;
@@ -120,7 +120,7 @@ class StorageDevice : public hz::intrusive_ptr_referenced {
fully_parsed_ = other.fully_parsed_;
test_is_active_ = other.test_is_active_;
type_ = other.type_;
detected_type_ = other.detected_type_;
smart_supported_ = other.smart_supported_;
smart_enabled_ = other.smart_enabled_;
aodc_status_ = other.aodc_status_;
@@ -210,6 +210,7 @@ class StorageDevice : public hz::intrusive_ptr_referenced {
}
/// Get device name without path. For example, "sda".
std::string get_device_base() const
{
if (is_virtual_)
@@ -241,14 +242,14 @@ class StorageDevice : public hz::intrusive_ptr_referenced {
void set_type(type_t t)
void set_detected_type(detected_type_t t)
{
type_ = t;
detected_type_ = t;
}
type_t get_type() const
detected_type_t get_detected_type() const
{
return type_;
return detected_type_;
}
@@ -386,6 +387,7 @@ class StorageDevice : public hz::intrusive_ptr_referenced {
std::string full_output_; // "smartctl --all" output
std::string device_; // e.g. /dev/sda. empty if virtual.
// std::string type_; //
// bool force_type_; // force "-d type" to smartctl, e.g. "-d scsi". DISCONTINUED, use per-device options.
bool is_virtual_; // if true, then this is not a real device - merely a loaded description of it.
@@ -399,7 +401,7 @@ class StorageDevice : public hz::intrusive_ptr_referenced {
bool test_is_active_;
// these are detected through info output
type_t type_; // e.g. type_ata
detected_type_t detected_type_; // e.g. type_unknown
hz::OptionalValue<bool> smart_supported_;
hz::OptionalValue<bool> smart_enabled_;
mutable hz::OptionalValue<status_t> aodc_status_; // cached aodc status.
@@ -424,8 +426,8 @@ typedef hz::intrusive_ptr<StorageDevice> StorageDeviceRefPtr;
// for sorting, hard drives first
inline bool operator< (const StorageDeviceRefPtr& d1, const StorageDeviceRefPtr& d2)
{
if (d1->get_type() != d2->get_type()) {
return (d1->get_type() == StorageDevice::type_unknown); // hard drives first
if (d1->get_detected_type() != d2->get_detected_type()) {
return (d1->get_detected_type() == StorageDevice::detected_type_unknown); // hard drives first
}
return d1->get_device_base() < d2->get_device_base();
}
+1 -1
View File
@@ -243,7 +243,7 @@ class GscMainWindowIconView : public Gtk::IconView {
Glib::RefPtr<Gdk::Pixbuf> icon;
if (drive->get_type() == StorageDevice::type_cddvd) {
if (drive->get_detected_type() == StorageDevice::detected_type_cddvd) {
icon = cddvd_icon;
} else {
icon = hd_icon;