Debian Codegraph @

src/plugins/smart/smart.h

raw
1 #include <glib.h>
2 #include <glib-object.h>
3 #include <blockdev/utils.h>
4
5 #ifndef BD_SMART
6 #define BD_SMART
7
8 GQuark bd_smart_error_quark (void);
9 #define BD_SMART_ERROR bd_smart_error_quark ()
10
11 /**
12 * BDSmartError:
13 * @BD_SMART_ERROR_TECH_UNAVAIL: SMART support not available.
14 * @BD_SMART_ERROR_FAILED: General error.
15 * @BD_SMART_ERROR_INVALID_ARGUMENT: Invalid argument.
16 */
17 typedef enum {
18 BD_SMART_ERROR_TECH_UNAVAIL,
19 BD_SMART_ERROR_FAILED,
20 BD_SMART_ERROR_INVALID_ARGUMENT,
21 } BDSmartError;
22
23 typedef enum {
24 BD_SMART_TECH_ATA = 0,
25 BD_SMART_TECH_SCSI = 1,
26 } BDSmartTech;
27
28 typedef enum {
29 BD_SMART_TECH_MODE_INFO = 1 << 0,
30 BD_SMART_TECH_MODE_SELFTEST = 1 << 1,
31 } BDSmartTechMode;
32
33 /**
34 * BDSmartATAOfflineDataCollectionStatus:
35 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_NEVER_STARTED: Offline data collection activity was never started.
36 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_NO_ERROR: Offline data collection activity was completed without error. Indicates a passed test.
37 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_IN_PROGRESS: Offline data collection activity is in progress.
38 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_SUSPENDED_INTR: Offline data collection activity was suspended by an interrupting command from host.
39 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_ABORTED_INTR: Offline data collection activity was aborted by an interrupting command from host.
40 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_ABORTED_ERROR: Offline data collection activity was aborted by the device with a fatal error. Indicates a failed test.
41 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_VENDOR_SPECIFIC: Offline data collection activity is in a Vendor Specific state.
42 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_RESERVED: Offline data collection activity is in a Reserved state.
43 */
44 typedef enum {
45 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_NEVER_STARTED = 0x00,
46 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_NO_ERROR = 0x02,
47 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_IN_PROGRESS = 0x03,
48 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_SUSPENDED_INTR = 0x04,
49 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_ABORTED_INTR = 0x05,
50 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_ABORTED_ERROR = 0x06,
51 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_VENDOR_SPECIFIC = 0x40,
52 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_RESERVED = 0x3F,
53 } BDSmartATAOfflineDataCollectionStatus;
54
55 /**
56 * BDSmartATAOfflineDataCollectionCapabilities:
57 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_NOT_SUPPORTED: Offline data collection not supported.
58 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_EXEC_OFFLINE_IMMEDIATE: Execute Offline Immediate function supported.
59 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_OFFLINE_ABORT: Abort Offline collection upon new command.
60 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_OFFLINE_SURFACE_SCAN: Offline surface scan supported.
61 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_SELF_TEST: Self-test supported.
62 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_CONVEYANCE_SELF_TEST: Conveyance Self-test supported.
63 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_SELECTIVE_SELF_TEST: Selective Self-test supported.
64 */
65 typedef enum {
66 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_NOT_SUPPORTED = 0x00,
67 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_EXEC_OFFLINE_IMMEDIATE = 0x01,
68 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_OFFLINE_ABORT = 0x04,
69 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_OFFLINE_SURFACE_SCAN = 0x08,
70 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_SELF_TEST = 0x10,
71 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_CONVEYANCE_SELF_TEST = 0x20,
72 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_SELECTIVE_SELF_TEST = 0x40,
73 } BDSmartATAOfflineDataCollectionCapabilities;
74
75 /**
76 * BDSmartATASelfTestStatus:
77 * @BD_SMART_ATA_SELF_TEST_STATUS_COMPLETED_NO_ERROR: The previous self-test routine completed without error or no self-test has ever been run.
78 * @BD_SMART_ATA_SELF_TEST_STATUS_ABORTED_HOST: The self-test routine was aborted by the host.
79 * @BD_SMART_ATA_SELF_TEST_STATUS_INTR_HOST_RESET: The self-test routine was interrupted by the host with a hard or soft reset.
80 * @BD_SMART_ATA_SELF_TEST_STATUS_ERROR_FATAL: A fatal error or unknown test error occurred while the device was executing its self-test routine and the device was unable to complete the self-test routine.
81 * @BD_SMART_ATA_SELF_TEST_STATUS_ERROR_UNKNOWN: The previous self-test completed having a test element that failed and the test element that failed is not known.
82 * @BD_SMART_ATA_SELF_TEST_STATUS_ERROR_ELECTRICAL: The previous self-test completed having the electrical element of the test failed.
83 * @BD_SMART_ATA_SELF_TEST_STATUS_ERROR_SERVO: The previous self-test completed having the servo (and/or seek) element of the test failed.
84 * @BD_SMART_ATA_SELF_TEST_STATUS_ERROR_READ: The previous self-test completed having the read element of the test failed.
85 * @BD_SMART_ATA_SELF_TEST_STATUS_ERROR_HANDLING: The previous self-test completed having a test element that failed and the device is suspected of having handling damage.
86 * @BD_SMART_ATA_SELF_TEST_STATUS_IN_PROGRESS: Self-test routine in progress.
87 */
88 typedef enum {
89 BD_SMART_ATA_SELF_TEST_STATUS_COMPLETED_NO_ERROR = 0x00,
90 BD_SMART_ATA_SELF_TEST_STATUS_ABORTED_HOST = 0x01,
91 BD_SMART_ATA_SELF_TEST_STATUS_INTR_HOST_RESET = 0x02,
92 BD_SMART_ATA_SELF_TEST_STATUS_ERROR_FATAL = 0x03,
93 BD_SMART_ATA_SELF_TEST_STATUS_ERROR_UNKNOWN = 0x04,
94 BD_SMART_ATA_SELF_TEST_STATUS_ERROR_ELECTRICAL = 0x05,
95 BD_SMART_ATA_SELF_TEST_STATUS_ERROR_SERVO = 0x06,
96 BD_SMART_ATA_SELF_TEST_STATUS_ERROR_READ = 0x07,
97 BD_SMART_ATA_SELF_TEST_STATUS_ERROR_HANDLING = 0x08,
98 BD_SMART_ATA_SELF_TEST_STATUS_IN_PROGRESS = 0x0F,
99 } BDSmartATASelfTestStatus;
100
101 /**
102 * BDSmartATACapabilities:
103 * @BD_SMART_ATA_CAP_ATTRIBUTE_AUTOSAVE: Saves SMART data before entering power-saving mode.
104 * @BD_SMART_ATA_CAP_AUTOSAVE_TIMER: Supports SMART auto save timer.
105 * @BD_SMART_ATA_CAP_ERROR_LOGGING: Error logging supported.
106 * @BD_SMART_ATA_CAP_GP_LOGGING: General Purpose Logging supported.
107 */
108 typedef enum {
109 BD_SMART_ATA_CAP_ATTRIBUTE_AUTOSAVE = 1 << 0,
110 BD_SMART_ATA_CAP_AUTOSAVE_TIMER = 1 << 1,
111 BD_SMART_ATA_CAP_ERROR_LOGGING = 1 << 2,
112 BD_SMART_ATA_CAP_GP_LOGGING = 1 << 3,
113 } BDSmartATACapabilities;
114
115 /**
116 * BDSmartATAAttributeUnit:
117 * @BD_SMART_ATA_ATTRIBUTE_UNIT_UNKNOWN: Unknown.
118 * @BD_SMART_ATA_ATTRIBUTE_UNIT_NONE: Dimensionless value.
119 * @BD_SMART_ATA_ATTRIBUTE_UNIT_MSECONDS: Milliseconds.
120 * @BD_SMART_ATA_ATTRIBUTE_UNIT_SECTORS: Sectors.
121 * @BD_SMART_ATA_ATTRIBUTE_UNIT_MKELVIN: Millikelvin.
122 * @BD_SMART_ATA_ATTRIBUTE_UNIT_SMALL_PERCENT: Percentage with 3 decimal points.
123 * @BD_SMART_ATA_ATTRIBUTE_UNIT_PERCENT: Integer percentage.
124 * @BD_SMART_ATA_ATTRIBUTE_UNIT_MB: Megabytes.
125 */
126 typedef enum {
127 BD_SMART_ATA_ATTRIBUTE_UNIT_UNKNOWN,
128 BD_SMART_ATA_ATTRIBUTE_UNIT_NONE,
129 BD_SMART_ATA_ATTRIBUTE_UNIT_MSECONDS,
130 BD_SMART_ATA_ATTRIBUTE_UNIT_SECTORS,
131 BD_SMART_ATA_ATTRIBUTE_UNIT_MKELVIN,
132 BD_SMART_ATA_ATTRIBUTE_UNIT_SMALL_PERCENT,
133 BD_SMART_ATA_ATTRIBUTE_UNIT_PERCENT,
134 BD_SMART_ATA_ATTRIBUTE_UNIT_MB,
135 } BDSmartATAAttributeUnit;
136
137 /**
138 * BDSmartATAAttributeFlag:
139 * @BD_SMART_ATA_ATTRIBUTE_FLAG_PREFAILURE: Pre-failure/advisory bit: If the value of this bit equals zero, an attribute value less than or equal to its corresponding attribute threshold indicates an advisory condition where the usage or age of the device has exceeded its intended design life period. If the value of this bit equals one, an attribute value less than or equal to its corresponding attribute threshold indicates a prefailure condition where imminent loss of data is being predicted.
140 * @BD_SMART_ATA_ATTRIBUTE_FLAG_ONLINE: On-line data collection bit: If the value of this bit equals zero, then the attribute value is updated only during off-line data collection activities. If the value of this bit equals one, then the attribute value is updated during normal operation of the device or during both normal operation and off-line testing.
141 * @BD_SMART_ATA_ATTRIBUTE_FLAG_PERFORMANCE: Performance type bit (vendor specific).
142 * @BD_SMART_ATA_ATTRIBUTE_FLAG_ERROR_RATE: Errorrate type bit (vendor specific).
143 * @BD_SMART_ATA_ATTRIBUTE_FLAG_EVENT_COUNT: Eventcount bit (vendor specific).
144 * @BD_SMART_ATA_ATTRIBUTE_FLAG_SELF_PRESERVING: Self-preserving bit (vendor specific).
145 * @BD_SMART_ATA_ATTRIBUTE_FLAG_OTHER: Reserved.
146 */
147 typedef enum {
148 BD_SMART_ATA_ATTRIBUTE_FLAG_PREFAILURE = 0x0001,
149 BD_SMART_ATA_ATTRIBUTE_FLAG_ONLINE = 0x0002,
150 BD_SMART_ATA_ATTRIBUTE_FLAG_PERFORMANCE = 0x0004,
151 BD_SMART_ATA_ATTRIBUTE_FLAG_ERROR_RATE = 0x0008,
152 BD_SMART_ATA_ATTRIBUTE_FLAG_EVENT_COUNT = 0x0010,
153 BD_SMART_ATA_ATTRIBUTE_FLAG_SELF_PRESERVING = 0x0020,
154 BD_SMART_ATA_ATTRIBUTE_FLAG_OTHER = 0xffc0,
155 } BDSmartATAAttributeFlag;
156
157 /**
158 * BDSmartATAAttribute:
159 * @id: Attribute Identifier.
160 * @name: A free-form representation of the attribute name, implementation-dependent (e.g. libatasmart internal strings or smartmontools' drivedb.h names).
161 * @well_known_name: Translated well-known attribute name (in libatasmart style, e.g. 'raw-read-error-rate') or %NULL in case of unknown, untrusted or vendor-specific value.
162 * @value: The normalized value or -1 if unknown.
163 * @worst: The worst normalized value of -1 if unknown.
164 * @threshold: The threshold of a normalized value or -1 if unknown.
165 * @failed_past: Indicates a failure that happened in the past (the normalized worst value is below the threshold).
166 * @failing_now: Indicates a failure that is happening now (the normalized value is below the threshold).
167 * @value_raw: The raw value of the attribute.
168 * @flags: Bitmask of attribute flags. See #BDSmartATAAttributeFlag.
169 * @pretty_value: Numerical representation of the parsed raw value, presented in @pretty_value_unit units.
170 * @pretty_value_unit: The unit of the parsed raw value.
171 * @pretty_value_string: A free-form string representation of the raw value intended for user presentation or %NULL.
172 */
173 typedef struct BDSmartATAAttribute {
174 guint8 id;
175 gchar *name;
176 gchar *well_known_name;
177 gint value;
178 gint worst;
179 gint threshold;
180 gboolean failed_past;
181 gboolean failing_now;
182 guint64 value_raw;
183 guint16 flags;
184 gint64 pretty_value;
185 BDSmartATAAttributeUnit pretty_value_unit;
186 gchar *pretty_value_string;
187 } BDSmartATAAttribute;
188
189 /**
190 * BDSmartATA:
191 * @smart_supported: Indicates that the device has SMART capability.
192 * @smart_enabled: Indicates that the SMART support is enabled.
193 * @overall_status_passed: %TRUE if the device SMART overall-health self-assessment test result has passed.
194 * @offline_data_collection_status: The offline data collection status. See #BDSmartATAOfflineDataCollectionStatus.
195 * @auto_offline_data_collection_enabled: %TRUE if Automatic Offline Data Collection is enabled. Only supported with the smartmontools plugin.
196 * @offline_data_collection_completion: Total time in seconds to complete Offline data collection.
197 * @offline_data_collection_capabilities: Bitmask of offline data collection capabilities, see #BDSmartATAOfflineDataCollectionCapabilities. Only supported with the smartmontools plugin.
198 * @self_test_status: Self-test execution status. See #BDSmartATASelfTestStatus.
199 * @self_test_percent_remaining: The percentage remaining of a running self-test.
200 * @self_test_polling_short: Short self-test routine recommended polling time in minutes or 0 if not supported.
201 * @self_test_polling_extended: Extended self-test routine recommended polling time in minutes or 0 if not supported.
202 * @self_test_polling_conveyance: Conveyance self-test routine recommended polling time in minutes or 0 if not supported.
203 * @smart_capabilities: Bitmask of device misc. SMART capabilities. See #BDSmartATACapabilities. Only supported with the smartmontools plugin.
204 * @attributes: (array zero-terminated=1): A list of reported SMART attributes.
205 * @power_on_time: The count of minutes in power-on state.
206 * @power_cycle_count: The count of full hard disk power on/off cycles.
207 * @temperature: The current drive temperature in Kelvin or 0 when temperature is not reported.
208 */
209 typedef struct BDSmartATA {
210 gboolean smart_supported;
211 gboolean smart_enabled;
212 gboolean overall_status_passed;
213 BDSmartATAOfflineDataCollectionStatus offline_data_collection_status;
214 gboolean auto_offline_data_collection_enabled;
215 gint offline_data_collection_completion;
216 guint offline_data_collection_capabilities;
217 BDSmartATASelfTestStatus self_test_status;
218 gint self_test_percent_remaining;
219 gint self_test_polling_short;
220 gint self_test_polling_extended;
221 gint self_test_polling_conveyance;
222 guint smart_capabilities;
223 BDSmartATAAttribute **attributes;
224 guint power_on_time;
225 guint64 power_cycle_count;
226 guint temperature;
227 } BDSmartATA;
228
229
230 /* TODO: check against some other SCSI implementation for the right wording */
231 /**
232 * BDSmartSCSIInformationalException:
233 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_NONE: No SCSI Informational Exception raised.
234 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_ABORTED_COMMAND: Warning - aborted command [asc 0x0b, ascq 0x00].
235 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_TEMPERATURE_EXCEEDED: Warning - specified temperature exceeded [asc 0x0b, ascq 0x01].
236 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_ENCLOSURE_DEGRADED: Warning - enclosure degraded [asc 0x0b, ascq 0x02].
237 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_BACKGROUND_SELFTEST_FAILED: Warning - background self-test failed [asc 0x0b, ascq 0x03].
238 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_BACKGROUND_PRESCAN_MEDIUM_ERROR: Warning - background pre-scan detected medium error [asc 0x0b, ascq 0x04].
239 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_BACKGROUND_SCAN_MEDIUM_ERROR: Warning - background medium scan detected medium error [asc 0x0b, ascq 0x05].
240 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_NV_CACHE_VOLATILE: Warning - non-volatile cache now volatile [asc 0x0b, ascq 0x06].
241 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_NV_CACHE_DEGRADED_POWER: Warning - degraded power to non-volatile cache [asc 0x0b, ascq 0x07].
242 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_POWER_LOSS_EXPECTED: Warning - power loss expected [asc 0x0b, ascq 0x08].
243 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_STATISTICS_NOTIFICATION: Warning - device statistics notification active [asc 0x0b, ascq 0x09].
244 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_HIGH_CRITICAL_TEMP: Warning - high critical temperature limit exceeded [asc 0x0b, ascq 0x0a].
245 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_LOW_CRITICAL_TEMP: Warning - low critical temperature limit exceeded [asc 0x0b, ascq 0x0b].
246 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_HIGH_OPERATING_TEMP: Warning - high operating temperature limit exceeded [asc 0x0b, ascq 0x0c].
247 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_LOW_OPERATING_TEMP: Warning - low operating temperature limit exceeded [asc 0x0b, ascq 0x0d].
248 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_HIGH_CRITICAL_HUMIDITY: Warning - high critical humidity limit exceeded [asc 0x0b, ascq 0x0e].
249 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_LOW_CRITICAL_HUMIDITY: Warning - low critical humidity limit exceeded [asc 0x0b, ascq 0x0f].
250 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_HIGH_OPERATING_HUMIDITY: Warning - high operating humidity limit exceeded [asc 0x0b, ascq 0x10].
251 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_LOW_OPERATING_HUMIDITY: Warning - low operating humidity limit exceeded [asc 0x0b, ascq 0x11].
252 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_MICROCODE_SECURITY_RISK: Warning - microcode security at risk [asc 0x0b, ascq 0x12].
253 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_MICROCODE_SIGNATURE_VALIDATION_FAILURE: Warning - microcode digital signature validation failure [asc 0x0b, ascq 0x13].
254 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_PHYSICAL_ELEMENT_STATUS_CHANGE: Warning - physical element status change [asc 0x0b, ascq 0x14].
255 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_FAILURE_PREDICTION_THRESH: Failure prediction threshold exceeded [asc 0x5d, ascq 0x00, ascq 0xff].
256 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_MEDIA_FAILURE_PREDICTION_THRESH: Media failure prediction threshold exceeded [asc 0x5d, ascq 0x01].
257 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_LOGICAL_UNIT_FAILURE_PREDICTION_THRESH: Logical unit failure prediction threshold exceeded [asc 0x5d, ascq 0x02].
258 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_SPARE_EXHAUSTION_PREDICTION_THRESH: Spare area exhaustion prediction threshold exceeded [asc 0x5d, ascq 0x03].
259 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_HARDWARE_IMPENDING_FAILURE: Hardware impending failure [asc 0x5d, ascq 0x10..0x1d].
260 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_CONTROLLER_IMPENDING_FAILURE: Controller impending failure [asc 0x5d, ascq 0x20..0x2c].
261 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_DATA_CHANNEL_IMPENDING_FAILURE: Data channel impending failure [asc 0x5d, ascq 0x30..0x3c].
262 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_SERVO_IMPENDING_FAILURE: Servo impending failure [asc 0x5d, ascq 0x40..0x4c].
263 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_SPINDLE_IMPENDING_FAILURE: Spindle impending failure [asc 0x5d, ascq 0x50..0x5c].
264 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_FIRMWARE_IMPENDING_FAILURE: Firmware impending failure [asc 0x5d, ascq 0x60..0x6c].
265 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_MEDIA_ENDURANCE_LIMIT: Media impending failure endurance limit met [asc 0x5d, ascq 0x73].
266 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_UNSPECIFIED: Unspecified warning.
267 */
268 typedef enum {
269 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_NONE,
270 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_ABORTED_COMMAND,
271 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_TEMPERATURE_EXCEEDED,
272 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_ENCLOSURE_DEGRADED,
273 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_BACKGROUND_SELFTEST_FAILED,
274 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_BACKGROUND_PRESCAN_MEDIUM_ERROR,
275 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_BACKGROUND_SCAN_MEDIUM_ERROR,
276 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_NV_CACHE_VOLATILE,
277 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_NV_CACHE_DEGRADED_POWER,
278 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_POWER_LOSS_EXPECTED,
279 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_STATISTICS_NOTIFICATION,
280 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_HIGH_CRITICAL_TEMP,
281 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_LOW_CRITICAL_TEMP,
282 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_HIGH_OPERATING_TEMP,
283 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_LOW_OPERATING_TEMP,
284 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_HIGH_CRITICAL_HUMIDITY,
285 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_LOW_CRITICAL_HUMIDITY,
286 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_HIGH_OPERATING_HUMIDITY,
287 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_LOW_OPERATING_HUMIDITY,
288 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_MICROCODE_SECURITY_RISK,
289 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_MICROCODE_SIGNATURE_VALIDATION_FAILURE,
290 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_PHYSICAL_ELEMENT_STATUS_CHANGE,
291 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_FAILURE_PREDICTION_THRESH,
292 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_MEDIA_FAILURE_PREDICTION_THRESH,
293 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_LOGICAL_UNIT_FAILURE_PREDICTION_THRESH,
294 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_SPARE_EXHAUSTION_PREDICTION_THRESH,
295 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_HARDWARE_IMPENDING_FAILURE,
296 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_CONTROLLER_IMPENDING_FAILURE,
297 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_DATA_CHANNEL_IMPENDING_FAILURE,
298 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_SERVO_IMPENDING_FAILURE,
299 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_SPINDLE_IMPENDING_FAILURE,
300 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_FIRMWARE_IMPENDING_FAILURE,
301 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_MEDIA_ENDURANCE_LIMIT,
302 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_UNSPECIFIED,
303 } BDSmartSCSIInformationalException;
304
305 /**
306 * BDSmartSCSIBackgroundScanStatus:
307 * @BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_NO_SCANS_ACTIVE: No scans active.
308 * @BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_SCAN_ACTIVE: Scan is active.
309 * @BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_PRESCAN_ACTIVE: Pre-scan is active.
310 * @BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_HALTED_ERROR_FATAL: Halted due to fatal error.
311 * @BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_HALTED_PATTERN_VENDOR_SPECIFIC: Halted due to a vendor specific pattern of error.
312 * @BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_HALTED_ERROR_PLIST: Halted due to medium formatted without P-List.
313 * @BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_HALTED_VENDOR_SPECIFIC: Halted - vendor specific cause.
314 * @BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_HALTED_TEMPERATURE: Halted due to temperature out of range.
315 * @BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_BMS_TIMER: Waiting until BMS interval timer expires.
316 */
317 typedef enum {
318 BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_NO_SCANS_ACTIVE = 0x00,
319 BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_SCAN_ACTIVE = 0x01,
320 BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_PRESCAN_ACTIVE = 0x02,
321 BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_HALTED_ERROR_FATAL = 0x03,
322 BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_HALTED_PATTERN_VENDOR_SPECIFIC = 0x04,
323 BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_HALTED_ERROR_PLIST = 0x05,
324 BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_HALTED_VENDOR_SPECIFIC = 0x06,
325 BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_HALTED_TEMPERATURE = 0x07,
326 BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_BMS_TIMER = 0x08,
327 } BDSmartSCSIBackgroundScanStatus;
328
329 /**
330 * BDSmartSCSI:
331 * @smart_supported: Indicates that the device has SMART capability.
332 * @smart_enabled: Indicates that the SMART support is enabled.
333 * @overall_status_passed: %TRUE if the device SMART overall-health self-assessment test result has passed, %FALSE otherwise with @scsi_ie fields set.
334 * @scsi_ie: The reported SCSI Informational Exception in a simplified form. See #BDSmartSCSIInformationalException.
335 * @scsi_ie_asc: The reported SCSI Informational Exception ASC (Additional Sense Code) value (only values of 0xb - warnings and 0x5d - impending failures are taken in account).
336 * @scsi_ie_ascq: The reported SCSI Informational Exception ASCQ (Additional Sense Code Qualifier) value.
337 * @scsi_ie_string: String representation of the current SCSI Informational Exception.
338 * @background_scan_status: Background scan status, see #BDSmartSCSIBackgroundScanStatus.
339 * @background_scan_progress: Percent of a background scan progress.
340 * @background_scan_runs: Number of background scans performed.
341 * @background_medium_scan_runs: Number of background medium scans performed.
342 * @read_errors_corrected_eccfast: Error counter log - read errors corrected by ECC fast.
343 * @read_errors_corrected_eccdelayed: Error counter log - read errors corrected by ECC delayed.
344 * @read_errors_corrected_rereads: Error counter log - read errors corrected by rereads.
345 * @read_errors_corrected_total: Error counter log - total read errors corrected.
346 * @read_errors_uncorrected: Error counter log - total uncorrected read errors.
347 * @read_processed_bytes: Error counter log - total bytes processed.
348 * @write_errors_corrected_eccfast: Error counter log - write errors corrected by ECC fast.
349 * @write_errors_corrected_eccdelayed: Error counter log - write errors corrected by ECC delayed.
350 * @write_errors_corrected_rewrites: Error counter log - write errors corrected by rewrites.
351 * @write_errors_corrected_total: Error counter log - total write errors corrected.
352 * @write_errors_uncorrected: Error counter log - total uncorrected write errors.
353 * @write_processed_bytes: Error counter log - total bytes processed.
354 * @start_stop_cycle_count: Accumulated start-stop cycles.
355 * @start_stop_cycle_lifetime: Specified cycle count over device lifetime.
356 * @load_unload_cycle_count: Accumulated load-unload cycles.
357 * @load_unload_cycle_lifetime: Specified load-unload count over device lifetime.
358 * @scsi_grown_defect_list: Elements in grown defect list.
359 * @power_on_time: Accumulated power on time in minutes.
360 * @temperature_warning_enabled: Indicates that temperature warning is enabled.
361 * @temperature: The current drive temperature in Kelvin or 0 when temperature is not reported.
362 * @temperature_drive_trip: The drive trip temperature in Kelvin or 0 when temperature is not reported.
363 */
364 typedef struct BDSmartSCSI {
365 gboolean smart_supported;
366 gboolean smart_enabled;
367 gboolean overall_status_passed;
368 BDSmartSCSIInformationalException scsi_ie;
369 guint8 scsi_ie_asc;
370 guint8 scsi_ie_ascq;
371 gchar *scsi_ie_string;
372 BDSmartSCSIBackgroundScanStatus background_scan_status;
373 gdouble background_scan_progress;
374 guint background_scan_runs;
375 guint background_medium_scan_runs;
376 guint read_errors_corrected_eccfast;
377 guint read_errors_corrected_eccdelayed;
378 guint read_errors_corrected_rereads;
379 guint read_errors_corrected_total;
380 guint read_errors_uncorrected;
381 guint64 read_processed_bytes;
382 guint write_errors_corrected_eccfast;
383 guint write_errors_corrected_eccdelayed;
384 guint write_errors_corrected_rewrites;
385 guint write_errors_corrected_total;
386 guint write_errors_uncorrected;
387 guint64 write_processed_bytes;
388 guint start_stop_cycle_count;
389 guint start_stop_cycle_lifetime;
390 guint load_unload_cycle_count;
391 guint load_unload_cycle_lifetime;
392 guint scsi_grown_defect_list;
393 guint power_on_time;
394 gboolean temperature_warning_enabled;
395 guint temperature;
396 guint temperature_drive_trip;
397 } BDSmartSCSI;
398
399
400 /**
401 * BDSmartSelfTestOp:
402 * @BD_SMART_SELF_TEST_OP_ABORT: Abort a running SMART self-test.
403 * @BD_SMART_SELF_TEST_OP_OFFLINE: SMART Immediate Offline Test in background (ATA) or a default self test in foreground (SCSI).
404 * @BD_SMART_SELF_TEST_OP_SHORT: SMART Short Self Test in background (ATA) or "Background short" self-test (SCSI).
405 * @BD_SMART_SELF_TEST_OP_LONG: SMART Extended Self Test in background (ATA) or "Background long" self-test (SCSI).
406 * @BD_SMART_SELF_TEST_OP_CONVEYANCE: SMART Conveyance Self Test in background (ATA only).
407 */
408 typedef enum {
409 BD_SMART_SELF_TEST_OP_ABORT,
410 BD_SMART_SELF_TEST_OP_OFFLINE,
411 BD_SMART_SELF_TEST_OP_SHORT,
412 BD_SMART_SELF_TEST_OP_LONG,
413 BD_SMART_SELF_TEST_OP_CONVEYANCE,
414 } BDSmartSelfTestOp;
415
416
417 void bd_smart_ata_free (BDSmartATA *data);
418 BDSmartATA * bd_smart_ata_copy (BDSmartATA *data);
419
420 void bd_smart_ata_attribute_free (BDSmartATAAttribute *attr);
421 BDSmartATAAttribute * bd_smart_ata_attribute_copy (BDSmartATAAttribute *attr);
422
423 void bd_smart_scsi_free (BDSmartSCSI *data);
424 BDSmartSCSI * bd_smart_scsi_copy (BDSmartSCSI *data);
425
426 /*
427 * If using the plugin as a standalone library, the following functions should
428 * be called to:
429 *
430 * check_deps() - check plugin's dependencies, returning TRUE if satisfied
431 * init() - initialize the plugin, returning TRUE on success
432 * close() - clean after the plugin at the end or if no longer used
433 *
434 */
435 gboolean bd_smart_check_deps (void);
436 gboolean bd_smart_init (void);
437 void bd_smart_close (void);
438
439 gboolean bd_smart_is_tech_avail (BDSmartTech tech, guint64 mode, GError **error);
440
441
442 BDSmartATA * bd_smart_ata_get_info (const gchar *device,
443 const BDExtraArg **extra,
444 GError **error);
445 BDSmartATA * bd_smart_ata_get_info_from_data (const guint8 *data,
446 gsize data_len,
447 GError **error);
448 BDSmartSCSI * bd_smart_scsi_get_info (const gchar *device,
449 const BDExtraArg **extra,
450 GError **error);
451 gboolean bd_smart_set_enabled (const gchar *device,
452 gboolean enabled,
453 const BDExtraArg **extra,
454 GError **error);
455 gboolean bd_smart_device_self_test (const gchar *device,
456 BDSmartSelfTestOp operation,
457 const BDExtraArg **extra,
458 GError **error);
459
460 #endif /* BD_SMART */