verify parsing of all attributes
[platform/upstream/libatasmart.git] / atasmart.h
index 25b0f13..c0baec5 100644 (file)
@@ -1,7 +1,7 @@
 /*-*- Mode: C; c-basic-offset: 8 -*-*/
 
-#ifndef foosmarthfoo
-#define foosmarthfoo
+#ifndef fooatasmarthfoo
+#define fooatasmarthfoo
 
 /***
     This file is part of libatasmart.
 
 #include <inttypes.h>
 
-typedef int SkBool;
+/* Please note that all enums defined here may be extended at any time
+ * without this being considered an ABI change. So take care when
+ * using them as indexes! */
 
-#ifndef TRUE
-#define TRUE 1
+#ifdef __cplusplus
+extern "C" {
 #endif
 
+typedef unsigned SkBool;
+
 #ifndef FALSE
-#define FALSE (!TRUE)
+#define FALSE (0)
+#endif
+
+#ifndef TRUE
+#define TRUE (!FALSE)
 #endif
 
 /* ATA SMART test type (ATA8 7.52.5.2) */
@@ -41,6 +49,10 @@ typedef enum SkSmartSelfTest {
         SK_SMART_SELF_TEST_EXTENDED = 2,
         SK_SMART_SELF_TEST_CONVEYANCE = 3,
         SK_SMART_SELF_TEST_ABORT = 127
+
+        /* This enum may be extended at any time without this being
+         * considered an ABI change. So take care when you use this
+         * type! */
 } SkSmartSelfTest;
 
 const char* sk_smart_self_test_to_string(SkSmartSelfTest test);
@@ -63,6 +75,10 @@ typedef enum SkSmartOfflineDataCollectionStatus {
         SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_FATAL,
         SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_UNKNOWN,
         _SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_MAX
+
+        /* This enum may be extended at any time without this being
+         * considered an ABI change. So take care when you use this
+         * type! */
 } SkSmartOfflineDataCollectionStatus;
 
 const char* sk_smart_offline_data_collection_status_to_string(SkSmartOfflineDataCollectionStatus status);
@@ -79,6 +95,10 @@ typedef enum SkSmartSelfTestExecutionStatus {
         SK_SMART_SELF_TEST_EXECUTION_STATUS_ERROR_HANDLING = 8,
         SK_SMART_SELF_TEST_EXECUTION_STATUS_INPROGRESS = 15,
         _SK_SMART_SELF_TEST_EXECUTION_STATUS_MAX
+
+        /* This enum may be extended at any time without this being
+         * considered an ABI change. So take care when you use this
+         * type! */
 } SkSmartSelfTestExecutionStatus;
 
 const char *sk_smart_self_test_execution_status_to_string(SkSmartSelfTestExecutionStatus status);
@@ -114,6 +134,10 @@ typedef enum SkSmartAttributeUnit {
         SK_SMART_ATTRIBUTE_UNIT_SECTORS,
         SK_SMART_ATTRIBUTE_UNIT_MKELVIN,     /* millikelvin */
         _SK_SMART_ATTRIBUTE_UNIT_MAX
+
+        /* This enum may be extended at any time without this being
+         * considered an ABI change. So take care when you use this
+         * type! */
 } SkSmartAttributeUnit;
 
 const char* sk_smart_attribute_unit_to_string(SkSmartAttributeUnit unit);
@@ -133,7 +157,8 @@ typedef struct SkSmartAttributeParsedData {
         SkBool prefailure:1;
 
         /* Volatile data */
-        SkBool good:1;
+        SkBool good:1, good_valid:1;
+        SkBool current_value_valid:1, worst_value_valid:1;
         uint8_t current_value, worst_value;
         uint64_t pretty_value;
         uint8_t raw[6];
@@ -144,6 +169,20 @@ typedef struct SkSmartAttributeParsedData {
 
 typedef struct SkDisk SkDisk;
 
+typedef enum SkSmartOverall  {
+        SK_SMART_OVERALL_GOOD,
+        SK_SMART_OVERALL_BAD_STATUS,     /* Smart Self Assessment negative */
+        SK_SMART_OVERALL_BAD_SECTOR,     /* At least one bad sector */
+        SK_SMART_OVERALL_BAD_ATTRIBUTE,  /* At least one pre-fail attribute exceeded its threshold in the past or now */
+        _SK_SMART_OVERALL_MAX
+
+        /* This enum may be extended at any time without this being
+         * considered an ABI change. So take care when you use this
+         * type! */
+} SkSmartOverall;
+
+const char* sk_smart_overall_to_string(SkSmartOverall overall);
+
 int sk_disk_open(const char *name, SkDisk **d);
 
 int sk_disk_get_size(SkDisk *d, uint64_t *bytes);
@@ -157,17 +196,42 @@ typedef void (*SkSmartAttributeParseCallback)(SkDisk *d, const SkSmartAttributeP
 
 int sk_disk_smart_is_available(SkDisk *d, SkBool *available);
 int sk_disk_smart_status(SkDisk *d, SkBool *good);
+
 /* Reading SMART data might cause the disk to wake up from
  * sleep. Hence from monitoring daemons make sure to call
  * sk_disk_check_power_mode() to check wether the disk is sleeping and
  * skip the read if so. */
 int sk_disk_smart_read_data(SkDisk *d);
+
+int sk_disk_get_blob(SkDisk *d, const void **blob, size_t *size);
+int sk_disk_set_blob(SkDisk *d, const void *blob, size_t size);
+
 int sk_disk_smart_parse(SkDisk *d, const SkSmartParsedData **data);
 int sk_disk_smart_parse_attributes(SkDisk *d, SkSmartAttributeParseCallback cb, void* userdata);
 int sk_disk_smart_self_test(SkDisk *d, SkSmartSelfTest test);
 
+/* High level API to get the power on time */
+int sk_disk_smart_get_power_on(SkDisk *d, uint64_t *mseconds);
+
+/* High level API to get the power cycle count */
+int sk_disk_smart_get_power_cycle(SkDisk *d, uint64_t *count);
+
+/* High level API to get the number of bad sectors (i.e. pending and reallocated) */
+int sk_disk_smart_get_bad(SkDisk *d, uint64_t *sectors);
+
+/* High level API to get the temperature */
+int sk_disk_smart_get_temperature(SkDisk *d, uint64_t *mkelvin);
+
+/* Get overall status. This integrates the values of a couple of fields into a single overall status */
+int sk_disk_smart_get_overall(SkDisk *d, SkSmartOverall *overall);
+
+/* Dump the current parsed status to STDOUT */
 int sk_disk_dump(SkDisk *d);
 
 void sk_disk_free(SkDisk *d);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif