summaryrefslogtreecommitdiffstats
path: root/smart.h
blob: f1150bf3bde065fbf3e84ce2e99d40b758c7dd61 (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 SkDevice SkDevice;

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

typedef enum SkOfflineDataCollectionStatus {
    SK_OFFLINE_DATA_COLLECTION_STATUS_NEVER,
    SK_OFFLINE_DATA_COLLECTION_STATUS_SUCCESS,
    SK_OFFLINE_DATA_COLLECTION_STATUS_INPROGRESS,
    SK_OFFLINE_DATA_COLLECTION_STATUS_SUSPENDED,
    SK_OFFLINE_DATA_COLLECTION_STATUS_ABORTED,
    SK_OFFLINE_DATA_COLLECTION_STATUS_FATAL,
    SK_OFFLINE_DATA_COLLECTION_STATUS_UNKNOWN,
    _SK_OFFLINE_DATA_COLLECTION_STATUS_MAX
} SkOfflineDataCollectionStatus;

typedef struct SkSmartParsedData {
    SkOfflineDataCollectionStatus 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)(SkDevice *d, const SkSmartAttribute *a, gpointer userdata);

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

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

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

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

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

int sk_disk_dump(SkDevice *d);

void sk_disk_free(SkDevice *d);

const char* sk_offline_data_collection_status_to_string(SkOfflineDataCollectionStatus status);
const char* sk_smart_attribute_unit_to_string(SkSmartAttributeUnit unit);

#endif