summaryrefslogtreecommitdiffstats
path: root/smart.h
blob: cc96efb8e29fe952ebfadd9761f82fbe4edc09a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef foosmarthfoo
#define foosmarthfoo

#include <glib.h>

typedef struct SkDisk SkDisk;

typedef struct SkIdentifyParsedData {
    gchar serial[21];
    gchar firmware[9];
    gchar model[41];
} SkIdentifyParsedData;

typedef enum SkSmartOfflineDataCollectionStatus {
    SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_NEVER,
    SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_SUCCESS,
    SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_INPROGRESS,
    SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_SUSPENDED,
    SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_ABORTED,
    SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_FATAL,
    SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_UNKNOWN,
    _SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_MAX
} SkSmartOfflineDataCollectionStatus;

typedef struct SkSmartParsedData {
    SkSmartOfflineDataCollectionStatus offline_data_collection_status;
    unsigned selftest_execution_percent_remaining;
    unsigned total_offline_data_collection_seconds;

    gboolean conveyance_test_available:1;
    gboolean short_and_extended_test_available:1;
    gboolean start_test_available:1;
    gboolean abort_test_available:1;

    unsigned short_test_polling_minutes;
    unsigned extended_test_polling_minutes;
    unsigned conveyance_test_polling_minutes;

    /* This structure may be extended at any time without being
     * considered an ABI change. So take care when you copy it.  */
} SkSmartParsedData;

typedef enum SkSmartAttributeUnit {
    SK_SMART_ATTRIBUTE_UNIT_UNKNOWN,
    SK_SMART_ATTRIBUTE_UNIT_NONE,
    SK_SMART_ATTRIBUTE_UNIT_MSECONDS,
    SK_SMART_ATTRIBUTE_UNIT_SECTORS,
    SK_SMART_ATTRIBUTE_UNIT_KELVIN,
    _SK_SMART_ATTRIBUTE_UNIT_MAX
} SkSmartAttributeUnit;

typedef struct SkSmartAttribute {
    /* Static data */
    guint8 id;
    const char *name;
    SkSmartAttributeUnit pretty_unit; /* for pretty value */

    guint8 threshold;
    gboolean threshold_valid:1;

    gboolean online:1;
    gboolean prefailure:1;

    guint8 flag;

    /* Volatile data */
    gboolean bad:1;
    guint8 current_value, worst_value;
    guint64 pretty_value;
    guint8 raw[6];

    /* This structure may be extended at any time without being
     * considered an ABI change. So take care when you copy it. */
} SkSmartAttribute;

typedef void (*SkSmartAttributeCallback)(SkDisk *d, const SkSmartAttribute *a, gpointer userdata);

int sk_disk_open(const gchar *name, SkDisk **d);

int sk_disk_check_power_mode(SkDisk *d, gboolean *mode);

int sk_disk_identify_is_available(SkDisk *d, gboolean *b);
int sk_disk_identify_parse(SkDisk *d, const SkIdentifyParsedData **data);

int sk_disk_smart_is_available(SkDisk *d, gboolean *b);
int sk_disk_smart_read_data(SkDisk *d);
int sk_disk_smart_parse(SkDisk *d, const SkSmartParsedData **data);
int sk_disk_smart_parse_attributes(SkDisk *d, SkSmartAttributeCallback cb, gpointer userdata);

int sk_disk_get_size(SkDisk *d, guint64 *bytes);

int sk_disk_dump(SkDisk *d);

void sk_disk_free(SkDisk *d);

const char* sk_smart_offline_data_collection_status_to_string(SkSmartOfflineDataCollectionStatus status);
const char* sk_smart_attribute_unit_to_string(SkSmartAttributeUnit unit);

#endif