Debian Codegraph @

src/lib/plugin_apis/smart.api

raw
1 #include <glib.h>
2 #include <glib-object.h>
3
4 #ifndef BD_SMART_API
5 #define BD_SMART_API
6
7 GQuark bd_smart_error_quark (void) {
8 return g_quark_from_static_string ("g-bd-smart-error-quark");
9 }
10
11 #define BD_SMART_ERROR bd_smart_error_quark ()
12 /* BpG-skip */
13 /**
14 * BDSmartError:
15 * @BD_SMART_ERROR_TECH_UNAVAIL: SMART support not available.
16 * @BD_SMART_ERROR_FAILED: General error.
17 * @BD_SMART_ERROR_INVALID_ARGUMENT: Invalid argument.
18 */
19 /* BpG-skip-end */
20 typedef enum {
21 BD_SMART_ERROR_TECH_UNAVAIL,
22 BD_SMART_ERROR_FAILED,
23 BD_SMART_ERROR_INVALID_ARGUMENT,
24 } BDSmartError;
25
26 typedef enum {
27 BD_SMART_TECH_ATA = 0,
28 BD_SMART_TECH_SCSI = 1,
29 } BDSmartTech;
30
31 typedef enum {
32 BD_SMART_TECH_MODE_INFO = 1 << 0,
33 BD_SMART_TECH_MODE_SELFTEST = 1 << 1,
34 } BDSmartTechMode;
35
36 /**
37 * bd_smart_is_tech_avail:
38 * @tech: the queried tech
39 * @mode: a bit mask of queried modes of operation (#BDSmartTechMode) for @tech
40 * @error: (out) (nullable): place to store error (details about why the @tech-@mode combination is not available)
41 *
42 * Returns: whether the @tech-@mode combination is available -- supported by the
43 * plugin implementation and having all the runtime dependencies available
44 */
45 gboolean bd_smart_is_tech_avail (BDSmartTech tech, G_GNUC_UNUSED guint64 mode, GError **error);
46
47 /* BpG-skip */
48 /**
49 * BDSmartATAOfflineDataCollectionStatus:
50 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_NEVER_STARTED: Offline data collection activity was never started.
51 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_NO_ERROR: Offline data collection activity was completed without error. Indicates a passed test.
52 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_IN_PROGRESS: Offline data collection activity is in progress.
53 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_SUSPENDED_INTR: Offline data collection activity was suspended by an interrupting command from host.
54 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_ABORTED_INTR: Offline data collection activity was aborted by an interrupting command from host.
55 * @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.
56 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_VENDOR_SPECIFIC: Offline data collection activity is in a Vendor Specific state.
57 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_RESERVED: Offline data collection activity is in a Reserved state.
58 */
59 /* BpG-skip-end */
60 typedef enum {
61 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_NEVER_STARTED = 0x00,
62 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_NO_ERROR = 0x02,
63 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_IN_PROGRESS = 0x03,
64 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_SUSPENDED_INTR = 0x04,
65 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_ABORTED_INTR = 0x05,
66 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_ABORTED_ERROR = 0x06,
67 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_VENDOR_SPECIFIC = 0x40,
68 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_STATUS_RESERVED = 0x3F,
69 } BDSmartATAOfflineDataCollectionStatus;
70
71 /* BpG-skip */
72 /**
73 * BDSmartATAOfflineDataCollectionCapabilities:
74 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_NOT_SUPPORTED: Offline data collection not supported.
75 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_EXEC_OFFLINE_IMMEDIATE: Execute Offline Immediate function supported.
76 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_OFFLINE_ABORT: Abort Offline collection upon new command.
77 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_OFFLINE_SURFACE_SCAN: Offline surface scan supported.
78 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_SELF_TEST: Self-test supported.
79 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_CONVEYANCE_SELF_TEST: Conveyance Self-test supported.
80 * @BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_SELECTIVE_SELF_TEST: Selective Self-test supported.
81 */
82 /* BpG-skip-end */
83 typedef enum {
84 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_NOT_SUPPORTED = 0x00,
85 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_EXEC_OFFLINE_IMMEDIATE = 0x01,
86 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_OFFLINE_ABORT = 0x04,
87 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_OFFLINE_SURFACE_SCAN = 0x08,
88 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_SELF_TEST = 0x10,
89 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_CONVEYANCE_SELF_TEST = 0x20,
90 BD_SMART_ATA_OFFLINE_DATA_COLLECTION_CAP_SELECTIVE_SELF_TEST = 0x40,
91 } BDSmartATAOfflineDataCollectionCapabilities;
92
93 /* BpG-skip */
94 /**
95 * BDSmartATASelfTestStatus:
96 * @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.
97 * @BD_SMART_ATA_SELF_TEST_STATUS_ABORTED_HOST: The self-test routine was aborted by the host.
98 * @BD_SMART_ATA_SELF_TEST_STATUS_INTR_HOST_RESET: The self-test routine was interrupted by the host with a hard or soft reset.
99 * @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.
100 * @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.
101 * @BD_SMART_ATA_SELF_TEST_STATUS_ERROR_ELECTRICAL: The previous self-test completed having the electrical element of the test failed.
102 * @BD_SMART_ATA_SELF_TEST_STATUS_ERROR_SERVO: The previous self-test completed having the servo (and/or seek) element of the test failed.
103 * @BD_SMART_ATA_SELF_TEST_STATUS_ERROR_READ: The previous self-test completed having the read element of the test failed.
104 * @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.
105 * @BD_SMART_ATA_SELF_TEST_STATUS_IN_PROGRESS: Self-test routine in progress.
106 */
107 /* BpG-skip-end */
108 typedef enum {
109 BD_SMART_ATA_SELF_TEST_STATUS_COMPLETED_NO_ERROR = 0x00,
110 BD_SMART_ATA_SELF_TEST_STATUS_ABORTED_HOST = 0x01,
111 BD_SMART_ATA_SELF_TEST_STATUS_INTR_HOST_RESET = 0x02,
112 BD_SMART_ATA_SELF_TEST_STATUS_ERROR_FATAL = 0x03,
113 BD_SMART_ATA_SELF_TEST_STATUS_ERROR_UNKNOWN = 0x04,
114 BD_SMART_ATA_SELF_TEST_STATUS_ERROR_ELECTRICAL = 0x05,
115 BD_SMART_ATA_SELF_TEST_STATUS_ERROR_SERVO = 0x06,
116 BD_SMART_ATA_SELF_TEST_STATUS_ERROR_READ = 0x07,
117 BD_SMART_ATA_SELF_TEST_STATUS_ERROR_HANDLING = 0x08,
118 BD_SMART_ATA_SELF_TEST_STATUS_IN_PROGRESS = 0x0F,
119 } BDSmartATASelfTestStatus;
120
121 /* BpG-skip */
122 /**
123 * BDSmartATACapabilities:
124 * @BD_SMART_ATA_CAP_ATTRIBUTE_AUTOSAVE: Saves SMART data before entering power-saving mode.
125 * @BD_SMART_ATA_CAP_AUTOSAVE_TIMER: Supports SMART auto save timer.
126 * @BD_SMART_ATA_CAP_ERROR_LOGGING: Error logging supported.
127 * @BD_SMART_ATA_CAP_GP_LOGGING: General Purpose Logging supported.
128 */
129 /* BpG-skip-end */
130 typedef enum {
131 BD_SMART_ATA_CAP_ATTRIBUTE_AUTOSAVE = 1 << 0,
132 BD_SMART_ATA_CAP_AUTOSAVE_TIMER = 1 << 1,
133 BD_SMART_ATA_CAP_ERROR_LOGGING = 1 << 2,
134 BD_SMART_ATA_CAP_GP_LOGGING = 1 << 3,
135 } BDSmartATACapabilities;
136
137 /* BpG-skip */
138 /**
139 * BDSmartATAAttributeUnit:
140 * @BD_SMART_ATA_ATTRIBUTE_UNIT_UNKNOWN: Unknown.
141 * @BD_SMART_ATA_ATTRIBUTE_UNIT_NONE: Dimensionless value.
142 * @BD_SMART_ATA_ATTRIBUTE_UNIT_MSECONDS: Milliseconds.
143 * @BD_SMART_ATA_ATTRIBUTE_UNIT_SECTORS: Sectors.
144 * @BD_SMART_ATA_ATTRIBUTE_UNIT_MKELVIN: Millikelvin.
145 * @BD_SMART_ATA_ATTRIBUTE_UNIT_SMALL_PERCENT: Percentage with 3 decimal points.
146 * @BD_SMART_ATA_ATTRIBUTE_UNIT_PERCENT: Integer percentage.
147 * @BD_SMART_ATA_ATTRIBUTE_UNIT_MB: Megabytes.
148 */
149 /* BpG-skip-end */
150 typedef enum {
151 BD_SMART_ATA_ATTRIBUTE_UNIT_UNKNOWN,
152 BD_SMART_ATA_ATTRIBUTE_UNIT_NONE,
153 BD_SMART_ATA_ATTRIBUTE_UNIT_MSECONDS,
154 BD_SMART_ATA_ATTRIBUTE_UNIT_SECTORS,
155 BD_SMART_ATA_ATTRIBUTE_UNIT_MKELVIN,
156 BD_SMART_ATA_ATTRIBUTE_UNIT_SMALL_PERCENT,
157 BD_SMART_ATA_ATTRIBUTE_UNIT_PERCENT,
158 BD_SMART_ATA_ATTRIBUTE_UNIT_MB,
159 } BDSmartATAAttributeUnit;
160
161 /* BpG-skip */
162 /**
163 * BDSmartATAAttributeFlag:
164 * @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.
165 * @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.
166 * @BD_SMART_ATA_ATTRIBUTE_FLAG_PERFORMANCE: Performance type bit (vendor specific).
167 * @BD_SMART_ATA_ATTRIBUTE_FLAG_ERROR_RATE: Errorrate type bit (vendor specific).
168 * @BD_SMART_ATA_ATTRIBUTE_FLAG_EVENT_COUNT: Eventcount bit (vendor specific).
169 * @BD_SMART_ATA_ATTRIBUTE_FLAG_SELF_PRESERVING: Self-preserving bit (vendor specific).
170 * @BD_SMART_ATA_ATTRIBUTE_FLAG_OTHER: Reserved.
171 */
172 /* BpG-skip-end */
173 typedef enum {
174 BD_SMART_ATA_ATTRIBUTE_FLAG_PREFAILURE = 0x0001,
175 BD_SMART_ATA_ATTRIBUTE_FLAG_ONLINE = 0x0002,
176 BD_SMART_ATA_ATTRIBUTE_FLAG_PERFORMANCE = 0x0004,
177 BD_SMART_ATA_ATTRIBUTE_FLAG_ERROR_RATE = 0x0008,
178 BD_SMART_ATA_ATTRIBUTE_FLAG_EVENT_COUNT = 0x0010,
179 BD_SMART_ATA_ATTRIBUTE_FLAG_SELF_PRESERVING = 0x0020,
180 BD_SMART_ATA_ATTRIBUTE_FLAG_OTHER = 0xffc0,
181 } BDSmartATAAttributeFlag;
182
183
184 #define BD_SMART_TYPE_ATA_ATTRIBUTE (bd_smart_ata_attribute_get_type ())
185 GType bd_smart_ata_attribute_get_type ();
186
187 /**
188 * BDSmartATAAttribute:
189 * @id: Attribute Identifier.
190 * @name: A free-form representation of the attribute name, implementation-dependent (e.g. libatasmart internal strings or smartmontools' drivedb.h names).
191 * @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.
192 * @value: The normalized value or -1 if unknown.
193 * @worst: The worst normalized value of -1 if unknown.
194 * @threshold: The threshold of a normalized value or -1 if unknown.
195 * @failed_past: Indicates a failure that happened in the past (the normalized worst value is below the threshold).
196 * @failing_now: Indicates a failure that is happening now (the normalized value is below the threshold).
197 * @value_raw: The raw value of the attribute.
198 * @flags: Bitmask of attribute flags. See #BDSmartATAAttributeFlag.
199 * @pretty_value: Numerical representation of the parsed raw value, presented in @pretty_value_unit units.
200 * @pretty_value_unit: The unit of the parsed raw value.
201 * @pretty_value_string: A free-form string representation of the raw value intended for user presentation or %NULL.
202 */
203 typedef struct BDSmartATAAttribute {
204 guint8 id;
205 gchar *name;
206 gchar *well_known_name;
207 gint value;
208 gint worst;
209 gint threshold;
210 gboolean failed_past;
211 gboolean failing_now;
212 guint64 value_raw;
213 guint16 flags;
214 gint64 pretty_value;
215 BDSmartATAAttributeUnit pretty_value_unit;
216 gchar *pretty_value_string;
217 } BDSmartATAAttribute;
218
219 /**
220 * bd_smart_ata_attribute_free: (skip)
221 * @attr: (nullable): %BDSmartATAAttribute to free
222 *
223 * Frees @attr.
224 */
225 void bd_smart_ata_attribute_free (BDSmartATAAttribute *attr) {
226 if (attr == NULL)
227 return;
228 g_free (attr->name);
229 g_free (attr->well_known_name);
230 g_free (attr->pretty_value_string);
231 g_free (attr);
232 }
233
234 /**
235 * bd_smart_ata_attribute_copy: (skip)
236 * @attr: (nullable): %BDSmartATAAttribute to copy
237 *
238 * Creates a new copy of @attr.
239 */
240 BDSmartATAAttribute * bd_smart_ata_attribute_copy (BDSmartATAAttribute *attr) {
241 BDSmartATAAttribute *new_attr;
242
243 if (attr == NULL)
244 return NULL;
245
246 new_attr = g_new0 (BDSmartATAAttribute, 1);
247 memcpy (new_attr, attr, sizeof (BDSmartATAAttribute));
248 new_attr->name = g_strdup (attr->name);
249 new_attr->well_known_name = g_strdup (attr->well_known_name);
250 new_attr->pretty_value_string = g_strdup (attr->pretty_value_string);
251
252 return new_attr;
253 }
254
255 GType bd_smart_ata_attribute_get_type () {
256 static GType type = 0;
257
258 if (G_UNLIKELY (type == 0)) {
259 type = g_boxed_type_register_static ("BDSmartATAAttribute",
260 (GBoxedCopyFunc) bd_smart_ata_attribute_copy,
261 (GBoxedFreeFunc) bd_smart_ata_attribute_free);
262 }
263 return type;
264 }
265
266
267 #define BD_SMART_TYPE_ATA (bd_smart_ata_get_type ())
268 GType bd_smart_ata_get_type ();
269
270 /**
271 * BDSmartATA:
272 * @smart_supported: Indicates that the device has SMART capability.
273 * @smart_enabled: Indicates that the SMART support is enabled.
274 * @overall_status_passed: %TRUE if the device SMART overall-health self-assessment test result has passed.
275 * @offline_data_collection_status: The offline data collection status. See #BDSmartATAOfflineDataCollectionStatus.
276 * @auto_offline_data_collection_enabled: %TRUE if Automatic Offline Data Collection is enabled. Only supported with the smartmontools plugin.
277 * @offline_data_collection_completion: Total time in seconds to complete Offline data collection.
278 * @offline_data_collection_capabilities: Bitmask of offline data collection capabilities, see #BDSmartATAOfflineDataCollectionCapabilities. Only supported with the smartmontools plugin.
279 * @self_test_status: Self-test execution status. See #BDSmartATASelfTestStatus.
280 * @self_test_percent_remaining: The percentage remaining of a running self-test.
281 * @self_test_polling_short: Short self-test routine recommended polling time in minutes or 0 if not supported.
282 * @self_test_polling_extended: Extended self-test routine recommended polling time in minutes or 0 if not supported.
283 * @self_test_polling_conveyance: Conveyance self-test routine recommended polling time in minutes or 0 if not supported.
284 * @smart_capabilities: Bitmask of device misc. SMART capabilities. See #BDSmartATACapabilities. Only supported with the smartmontools plugin.
285 * @attributes: (array zero-terminated=1): A list of reported SMART attributes.
286 * @power_on_time: The count of minutes in power-on state.
287 * @power_cycle_count: The count of full hard disk power on/off cycles.
288 * @temperature: The current drive temperature in Kelvin or 0 when temperature is not reported.
289 */
290 typedef struct BDSmartATA {
291 gboolean smart_supported;
292 gboolean smart_enabled;
293 gboolean overall_status_passed;
294 BDSmartATAOfflineDataCollectionStatus offline_data_collection_status;
295 gboolean auto_offline_data_collection_enabled;
296 gint offline_data_collection_completion;
297 guint offline_data_collection_capabilities;
298 BDSmartATASelfTestStatus self_test_status;
299 gint self_test_percent_remaining;
300 gint self_test_polling_short;
301 gint self_test_polling_extended;
302 gint self_test_polling_conveyance;
303 guint smart_capabilities;
304 BDSmartATAAttribute **attributes;
305 guint power_on_time;
306 guint64 power_cycle_count;
307 guint temperature;
308 } BDSmartATA;
309
310 /**
311 * bd_smart_ata_free: (skip)
312 * @data: (nullable): %BDSmartATA to free
313 *
314 * Frees @data.
315 */
316 void bd_smart_ata_free (BDSmartATA *data) {
317 BDSmartATAAttribute **attr;
318
319 if (data == NULL)
320 return;
321
322 for (attr = data->attributes; attr && *attr; attr++)
323 bd_smart_ata_attribute_free (*attr);
324 g_free (data->attributes);
325 g_free (data);
326 }
327
328 /**
329 * bd_smart_ata_copy: (skip)
330 * @data: (nullable): %BDSmartATA to copy
331 *
332 * Creates a new copy of @data.
333 */
334 BDSmartATA * bd_smart_ata_copy (BDSmartATA *data) {
335 BDSmartATA *new_data;
336 BDSmartATAAttribute **attr;
337 GPtrArray *ptr_array;
338
339 if (data == NULL)
340 return NULL;
341
342 new_data = g_new0 (BDSmartATA, 1);
343 memcpy (new_data, data, sizeof (BDSmartATA));
344
345 ptr_array = g_ptr_array_new ();
346 for (attr = data->attributes; attr && *attr; attr++)
347 g_ptr_array_add (ptr_array, bd_smart_ata_attribute_copy (*attr));
348 g_ptr_array_add (ptr_array, NULL);
349 new_data->attributes = (BDSmartATAAttribute **) g_ptr_array_free (ptr_array, FALSE);
350
351 return new_data;
352 }
353
354 GType bd_smart_ata_get_type () {
355 static GType type = 0;
356
357 if (G_UNLIKELY (type == 0)) {
358 type = g_boxed_type_register_static ("BDSmartATA",
359 (GBoxedCopyFunc) bd_smart_ata_copy,
360 (GBoxedFreeFunc) bd_smart_ata_free);
361 }
362 return type;
363 }
364
365
366 /* BpG-skip */
367 /**
368 * BDSmartSCSIInformationalException:
369 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_NONE: No SCSI Informational Exception raised.
370 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_ABORTED_COMMAND: Warning - aborted command [asc 0x0b, ascq 0x00].
371 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_TEMPERATURE_EXCEEDED: Warning - specified temperature exceeded [asc 0x0b, ascq 0x01].
372 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_ENCLOSURE_DEGRADED: Warning - enclosure degraded [asc 0x0b, ascq 0x02].
373 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_BACKGROUND_SELFTEST_FAILED: Warning - background self-test failed [asc 0x0b, ascq 0x03].
374 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_BACKGROUND_PRESCAN_MEDIUM_ERROR: Warning - background pre-scan detected medium error [asc 0x0b, ascq 0x04].
375 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_BACKGROUND_SCAN_MEDIUM_ERROR: Warning - background medium scan detected medium error [asc 0x0b, ascq 0x05].
376 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_NV_CACHE_VOLATILE: Warning - non-volatile cache now volatile [asc 0x0b, ascq 0x06].
377 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_NV_CACHE_DEGRADED_POWER: Warning - degraded power to non-volatile cache [asc 0x0b, ascq 0x07].
378 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_POWER_LOSS_EXPECTED: Warning - power loss expected [asc 0x0b, ascq 0x08].
379 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_STATISTICS_NOTIFICATION: Warning - device statistics notification active [asc 0x0b, ascq 0x09].
380 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_HIGH_CRITICAL_TEMP: Warning - high critical temperature limit exceeded [asc 0x0b, ascq 0x0a].
381 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_LOW_CRITICAL_TEMP: Warning - low critical temperature limit exceeded [asc 0x0b, ascq 0x0b].
382 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_HIGH_OPERATING_TEMP: Warning - high operating temperature limit exceeded [asc 0x0b, ascq 0x0c].
383 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_LOW_OPERATING_TEMP: Warning - low operating temperature limit exceeded [asc 0x0b, ascq 0x0d].
384 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_HIGH_CRITICAL_HUMIDITY: Warning - high critical humidity limit exceeded [asc 0x0b, ascq 0x0e].
385 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_LOW_CRITICAL_HUMIDITY: Warning - low critical humidity limit exceeded [asc 0x0b, ascq 0x0f].
386 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_HIGH_OPERATING_HUMIDITY: Warning - high operating humidity limit exceeded [asc 0x0b, ascq 0x10].
387 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_LOW_OPERATING_HUMIDITY: Warning - low operating humidity limit exceeded [asc 0x0b, ascq 0x11].
388 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_MICROCODE_SECURITY_RISK: Warning - microcode security at risk [asc 0x0b, ascq 0x12].
389 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_MICROCODE_SIGNATURE_VALIDATION_FAILURE: Warning - microcode digital signature validation failure [asc 0x0b, ascq 0x13].
390 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_PHYSICAL_ELEMENT_STATUS_CHANGE: Warning - physical element status change [asc 0x0b, ascq 0x14].
391 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_FAILURE_PREDICTION_THRESH: Failure prediction threshold exceeded [asc 0x5d, ascq 0x00, ascq 0xff].
392 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_MEDIA_FAILURE_PREDICTION_THRESH: Media failure prediction threshold exceeded [asc 0x5d, ascq 0x01].
393 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_LOGICAL_UNIT_FAILURE_PREDICTION_THRESH: Logical unit failure prediction threshold exceeded [asc 0x5d, ascq 0x02].
394 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_SPARE_EXHAUSTION_PREDICTION_THRESH: Spare area exhaustion prediction threshold exceeded [asc 0x5d, ascq 0x03].
395 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_HARDWARE_IMPENDING_FAILURE: Hardware impending failure [asc 0x5d, ascq 0x10..0x1d].
396 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_CONTROLLER_IMPENDING_FAILURE: Controller impending failure [asc 0x5d, ascq 0x20..0x2c].
397 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_DATA_CHANNEL_IMPENDING_FAILURE: Data channel impending failure [asc 0x5d, ascq 0x30..0x3c].
398 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_SERVO_IMPENDING_FAILURE: Servo impending failure [asc 0x5d, ascq 0x40..0x4c].
399 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_SPINDLE_IMPENDING_FAILURE: Spindle impending failure [asc 0x5d, ascq 0x50..0x5c].
400 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_FIRMWARE_IMPENDING_FAILURE: Firmware impending failure [asc 0x5d, ascq 0x60..0x6c].
401 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_MEDIA_ENDURANCE_LIMIT: Media impending failure endurance limit met [asc 0x5d, ascq 0x73].
402 * @BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_UNSPECIFIED: Unspecified warning.
403 */
404 /* BpG-skip-end */
405 typedef enum {
406 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_NONE,
407 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_ABORTED_COMMAND,
408 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_TEMPERATURE_EXCEEDED,
409 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_ENCLOSURE_DEGRADED,
410 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_BACKGROUND_SELFTEST_FAILED,
411 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_BACKGROUND_PRESCAN_MEDIUM_ERROR,
412 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_BACKGROUND_SCAN_MEDIUM_ERROR,
413 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_NV_CACHE_VOLATILE,
414 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_NV_CACHE_DEGRADED_POWER,
415 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_POWER_LOSS_EXPECTED,
416 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_STATISTICS_NOTIFICATION,
417 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_HIGH_CRITICAL_TEMP,
418 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_LOW_CRITICAL_TEMP,
419 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_HIGH_OPERATING_TEMP,
420 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_LOW_OPERATING_TEMP,
421 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_HIGH_CRITICAL_HUMIDITY,
422 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_LOW_CRITICAL_HUMIDITY,
423 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_HIGH_OPERATING_HUMIDITY,
424 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_LOW_OPERATING_HUMIDITY,
425 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_MICROCODE_SECURITY_RISK,
426 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_MICROCODE_SIGNATURE_VALIDATION_FAILURE,
427 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_PHYSICAL_ELEMENT_STATUS_CHANGE,
428 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_FAILURE_PREDICTION_THRESH,
429 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_MEDIA_FAILURE_PREDICTION_THRESH,
430 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_LOGICAL_UNIT_FAILURE_PREDICTION_THRESH,
431 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_SPARE_EXHAUSTION_PREDICTION_THRESH,
432 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_HARDWARE_IMPENDING_FAILURE,
433 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_CONTROLLER_IMPENDING_FAILURE,
434 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_DATA_CHANNEL_IMPENDING_FAILURE,
435 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_SERVO_IMPENDING_FAILURE,
436 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_SPINDLE_IMPENDING_FAILURE,
437 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_FIRMWARE_IMPENDING_FAILURE,
438 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_MEDIA_ENDURANCE_LIMIT,
439 BD_SMART_SCSI_INFORMATIONAL_EXCEPTION_UNSPECIFIED,
440 } BDSmartSCSIInformationalException;
441
442 /* BpG-skip */
443 /**
444 * BDSmartSCSIBackgroundScanStatus:
445 * @BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_NO_SCANS_ACTIVE: No scans active.
446 * @BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_SCAN_ACTIVE: Scan is active.
447 * @BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_PRESCAN_ACTIVE: Pre-scan is active.
448 * @BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_HALTED_ERROR_FATAL: Halted due to fatal error.
449 * @BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_HALTED_PATTERN_VENDOR_SPECIFIC: Halted due to a vendor specific pattern of error.
450 * @BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_HALTED_ERROR_PLIST: Halted due to medium formatted without P-List.
451 * @BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_HALTED_VENDOR_SPECIFIC: Halted - vendor specific cause.
452 * @BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_HALTED_TEMPERATURE: Halted due to temperature out of range.
453 * @BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_BMS_TIMER: Waiting until BMS interval timer expires.
454 */
455 /* BpG-skip-end */
456 typedef enum {
457 BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_NO_SCANS_ACTIVE = 0x00,
458 BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_SCAN_ACTIVE = 0x01,
459 BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_PRESCAN_ACTIVE = 0x02,
460 BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_HALTED_ERROR_FATAL = 0x03,
461 BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_HALTED_PATTERN_VENDOR_SPECIFIC = 0x04,
462 BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_HALTED_ERROR_PLIST = 0x05,
463 BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_HALTED_VENDOR_SPECIFIC = 0x06,
464 BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_HALTED_TEMPERATURE = 0x07,
465 BD_SMART_SCSI_BACKGROUND_SCAN_STATUS_BMS_TIMER = 0x08,
466 } BDSmartSCSIBackgroundScanStatus;
467
468
469 #define BD_SMART_TYPE_SCSI (bd_smart_scsi_get_type ())
470 GType bd_smart_scsi_get_type ();
471
472 /**
473 * BDSmartSCSI:
474 * @smart_supported: Indicates that the device has SMART capability.
475 * @smart_enabled: Indicates that the SMART support is enabled.
476 * @overall_status_passed: %TRUE if the device SMART overall-health self-assessment test result has passed, %FALSE otherwise with @scsi_ie fields set.
477 * @scsi_ie: The reported SCSI Informational Exception in a simplified form. See #BDSmartSCSIInformationalException.
478 * @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).
479 * @scsi_ie_ascq: The reported SCSI Informational Exception ASCQ (Additional Sense Code Qualifier) value.
480 * @scsi_ie_string: String representation of the current SCSI Informational Exception.
481 * @background_scan_status: Background scan status, see #BDSmartSCSIBackgroundScanStatus.
482 * @background_scan_progress: Percent of a background scan progress.
483 * @background_scan_runs: Number of background scans performed.
484 * @background_medium_scan_runs: Number of background medium scans performed.
485 * @read_errors_corrected_eccfast: Error counter log - read errors corrected by ECC fast.
486 * @read_errors_corrected_eccdelayed: Error counter log - read errors corrected by ECC delayed.
487 * @read_errors_corrected_rereads: Error counter log - read errors corrected by rereads.
488 * @read_errors_corrected_total: Error counter log - total read errors corrected.
489 * @read_errors_uncorrected: Error counter log - total uncorrected read errors.
490 * @read_processed_bytes: Error counter log - total bytes processed.
491 * @write_errors_corrected_eccfast: Error counter log - write errors corrected by ECC fast.
492 * @write_errors_corrected_eccdelayed: Error counter log - write errors corrected by ECC delayed.
493 * @write_errors_corrected_rewrites: Error counter log - write errors corrected by rewrites.
494 * @write_errors_corrected_total: Error counter log - total write errors corrected.
495 * @write_errors_uncorrected: Error counter log - total uncorrected write errors.
496 * @write_processed_bytes: Error counter log - total bytes processed.
497 * @start_stop_cycle_count: Accumulated start-stop cycles.
498 * @start_stop_cycle_lifetime: Specified cycle count over device lifetime.
499 * @load_unload_cycle_count: Accumulated load-unload cycles.
500 * @load_unload_cycle_lifetime: Specified load-unload count over device lifetime.
501 * @scsi_grown_defect_list: Elements in grown defect list.
502 * @power_on_time: Accumulated power on time in minutes.
503 * @temperature_warning_enabled: Indicates that temperature warning is enabled.
504 * @temperature: The current drive temperature in Kelvin or 0 when temperature is not reported.
505 * @temperature_drive_trip: The drive trip temperature in Kelvin or 0 when temperature is not reported.
506 */
507 typedef struct BDSmartSCSI {
508 gboolean smart_supported;
509 gboolean smart_enabled;
510 gboolean overall_status_passed;
511 BDSmartSCSIInformationalException scsi_ie;
512 guint8 scsi_ie_asc;
513 guint8 scsi_ie_ascq;
514 gchar *scsi_ie_string;
515 BDSmartSCSIBackgroundScanStatus background_scan_status;
516 gdouble background_scan_progress;
517 guint background_scan_runs;
518 guint background_medium_scan_runs;
519 guint read_errors_corrected_eccfast;
520 guint read_errors_corrected_eccdelayed;
521 guint read_errors_corrected_rereads;
522 guint read_errors_corrected_total;
523 guint read_errors_uncorrected;
524 guint64 read_processed_bytes;
525 guint write_errors_corrected_eccfast;
526 guint write_errors_corrected_eccdelayed;
527 guint write_errors_corrected_rewrites;
528 guint write_errors_corrected_total;
529 guint write_errors_uncorrected;
530 guint64 write_processed_bytes;
531 guint start_stop_cycle_count;
532 guint start_stop_cycle_lifetime;
533 guint load_unload_cycle_count;
534 guint load_unload_cycle_lifetime;
535 guint scsi_grown_defect_list;
536 guint power_on_time;
537 gboolean temperature_warning_enabled;
538 guint temperature;
539 guint temperature_drive_trip;
540 } BDSmartSCSI;
541
542 /**
543 * bd_smart_scsi_free: (skip)
544 * @data: (nullable): %BDSmartSCSI to free
545 *
546 * Frees @data.
547 */
548 void bd_smart_scsi_free (BDSmartSCSI *data) {
549 if (data == NULL)
550 return;
551
552 g_free (data->scsi_ie_string);
553 g_free (data);
554 }
555
556 /**
557 * bd_smart_scsi_copy: (skip)
558 * @data: (nullable): %BDSmartSCSI to copy
559 *
560 * Creates a new copy of @data.
561 */
562 BDSmartSCSI * bd_smart_scsi_copy (BDSmartSCSI *data) {
563 BDSmartSCSI *new_data;
564
565 if (data == NULL)
566 return NULL;
567
568 new_data = g_new0 (BDSmartSCSI, 1);
569 memcpy (new_data, data, sizeof (BDSmartSCSI));
570 new_data->scsi_ie_string = g_strdup (data->scsi_ie_string);
571
572 return new_data;
573 }
574
575 GType bd_smart_scsi_get_type () {
576 static GType type = 0;
577
578 if (G_UNLIKELY (type == 0)) {
579 type = g_boxed_type_register_static ("BDSmartSCSI",
580 (GBoxedCopyFunc) bd_smart_scsi_copy,
581 (GBoxedFreeFunc) bd_smart_scsi_free);
582 }
583 return type;
584 }
585
586
587 /* BpG-skip */
588 /**
589 * BDSmartSelfTestOp:
590 * @BD_SMART_SELF_TEST_OP_ABORT: Abort a running SMART self-test.
591 * @BD_SMART_SELF_TEST_OP_OFFLINE: SMART Immediate Offline Test in background (ATA) or a default self test in foreground (SCSI).
592 * @BD_SMART_SELF_TEST_OP_SHORT: SMART Short Self Test in background (ATA) or "Background short" self-test (SCSI).
593 * @BD_SMART_SELF_TEST_OP_LONG: SMART Extended Self Test in background (ATA) or "Background long" self-test (SCSI).
594 * @BD_SMART_SELF_TEST_OP_CONVEYANCE: SMART Conveyance Self Test in background (ATA only).
595 */
596 /* BpG-skip-end */
597 typedef enum {
598 BD_SMART_SELF_TEST_OP_ABORT,
599 BD_SMART_SELF_TEST_OP_OFFLINE,
600 BD_SMART_SELF_TEST_OP_SHORT,
601 BD_SMART_SELF_TEST_OP_LONG,
602 BD_SMART_SELF_TEST_OP_CONVEYANCE,
603 } BDSmartSelfTestOp;
604
605
606 /**
607 * bd_smart_ata_get_info:
608 * @device: device to check.
609 * @extra: (nullable) (array zero-terminated=1): extra options to pass through.
610 * @error: (out) (optional): place to store error (if any).
611 *
612 * Retrieve SMART information from the drive.
613 *
614 * Returns: (transfer full): ATA SMART log or %NULL in case of an error (with @error set).
615 *
616 * Tech category: %BD_SMART_TECH_ATA-%BD_SMART_TECH_MODE_INFO
617 */
618 BDSmartATA * bd_smart_ata_get_info (const gchar *device, const BDExtraArg **extra, GError **error);
619
620 /**
621 * bd_smart_ata_get_info_from_data:
622 * @data: (array length=data_len): binary data to parse.
623 * @data_len: length of the data supplied.
624 * @error: (out) (optional): place to store error (if any).
625 *
626 * Retrieve SMART information from the supplied data.
627 *
628 * Returns: (transfer full): ATA SMART log or %NULL in case of an error (with @error set).
629 *
630 * Tech category: %BD_SMART_TECH_ATA-%BD_SMART_TECH_MODE_INFO
631 */
632 BDSmartATA * bd_smart_ata_get_info_from_data (const guint8 *data, gsize data_len, GError **error);
633
634 /**
635 * bd_smart_scsi_get_info:
636 * @device: device to check.
637 * @extra: (nullable) (array zero-terminated=1): extra options to pass through.
638 * @error: (out) (optional): place to store error (if any).
639 *
640 * Retrieve SMART information from SCSI or SAS-compliant drive.
641 *
642 * Returns: (transfer full): SCSI SMART log or %NULL in case of an error (with @error set).
643 *
644 * Tech category: %BD_SMART_TECH_SCSI-%BD_SMART_TECH_MODE_INFO
645 */
646 BDSmartSCSI * bd_smart_scsi_get_info (const gchar *device, const BDExtraArg **extra, GError **error);
647
648 /**
649 * bd_smart_set_enabled:
650 * @device: SMART-capable device.
651 * @enabled: whether to enable or disable the SMART functionality
652 * @extra: (nullable) (array zero-terminated=1): extra options to pass through.
653 * @error: (out) (optional): place to store error (if any).
654 *
655 * Enables or disables SMART functionality on device.
656 *
657 * Returns: %TRUE when the functionality was set successfully or %FALSE in case of an error (with @error set).
658 *
659 * Tech category: %BD_SMART_TECH_ATA-%BD_SMART_TECH_MODE_INFO
660 */
661 gboolean bd_smart_set_enabled (const gchar *device, gboolean enabled, const BDExtraArg **extra, GError **error);
662
663 /**
664 * bd_smart_device_self_test:
665 * @device: device to trigger the test on.
666 * @operation: #BDSmartSelfTestOp self-test operation.
667 * @extra: (nullable) (array zero-terminated=1): extra options to pass through.
668 * @error: (out) (optional): place to store error (if any).
669 *
670 * Executes or aborts device self-test.
671 *
672 * Returns: %TRUE when the self-test was triggered successfully or %FALSE in case of an error (with @error set).
673 *
674 * Tech category: %BD_SMART_TECH_ATA-%BD_SMART_TECH_MODE_SELFTEST
675 */
676 gboolean bd_smart_device_self_test (const gchar *device, BDSmartSelfTestOp operation, const BDExtraArg **extra, GError **error);
677
678 #endif /* BD_SMART_API */