add C++ headers
[platform/upstream/libatasmart.git] / atasmart.h
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3 #ifndef fooatasmarthfoo
4 #define fooatasmarthfoo
5
6 /***
7     This file is part of libatasmart.
8
9     Copyright 2008 Lennart Poettering
10
11     libatasmart is free software; you can redistribute it and/or modify
12     it under the terms of the GNU Lesser General Public License as
13     published by the Free Software Foundation, either version 2.1 of the
14     License, or (at your option) any later version.
15
16     libatasmart is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19     Lesser General Public License for more details.
20
21     You should have received a copy of the GNU Lesser General Public
22     License along with libatasmart. If not, If not, see
23     <http://www.gnu.org/licenses/>.
24 ***/
25
26 #include <inttypes.h>
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 typedef int SkBool;
33
34 #ifndef FALSE
35 #define FALSE (0)
36 #endif
37
38 #ifndef TRUE
39 #define TRUE (!FALSE)
40 #endif
41
42 /* ATA SMART test type (ATA8 7.52.5.2) */
43 typedef enum SkSmartSelfTest {
44         SK_SMART_SELF_TEST_SHORT = 1,
45         SK_SMART_SELF_TEST_EXTENDED = 2,
46         SK_SMART_SELF_TEST_CONVEYANCE = 3,
47         SK_SMART_SELF_TEST_ABORT = 127
48 } SkSmartSelfTest;
49
50 const char* sk_smart_self_test_to_string(SkSmartSelfTest test);
51
52 typedef struct SkIdentifyParsedData {
53         char serial[21];
54         char firmware[9];
55         char model[41];
56
57         /* This structure may be extended at any time without this being
58          * considered an ABI change. So take care when you copy it. */
59 } SkIdentifyParsedData;
60
61 typedef enum SkSmartOfflineDataCollectionStatus {
62         SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_NEVER,
63         SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_SUCCESS,
64         SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_INPROGRESS,
65         SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_SUSPENDED,
66         SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_ABORTED,
67         SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_FATAL,
68         SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_UNKNOWN,
69         _SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_MAX
70 } SkSmartOfflineDataCollectionStatus;
71
72 const char* sk_smart_offline_data_collection_status_to_string(SkSmartOfflineDataCollectionStatus status);
73
74 typedef enum SkSmartSelfTestExecutionStatus {
75         SK_SMART_SELF_TEST_EXECUTION_STATUS_SUCCESS_OR_NEVER = 0,
76         SK_SMART_SELF_TEST_EXECUTION_STATUS_ABORTED = 1,
77         SK_SMART_SELF_TEST_EXECUTION_STATUS_INTERRUPTED = 2,
78         SK_SMART_SELF_TEST_EXECUTION_STATUS_FATAL = 3,
79         SK_SMART_SELF_TEST_EXECUTION_STATUS_ERROR_UNKNOWN = 4,
80         SK_SMART_SELF_TEST_EXECUTION_STATUS_ERROR_ELECTRICAL = 5,
81         SK_SMART_SELF_TEST_EXECUTION_STATUS_ERROR_SERVO = 6,
82         SK_SMART_SELF_TEST_EXECUTION_STATUS_ERROR_READ = 7,
83         SK_SMART_SELF_TEST_EXECUTION_STATUS_ERROR_HANDLING = 8,
84         SK_SMART_SELF_TEST_EXECUTION_STATUS_INPROGRESS = 15,
85         _SK_SMART_SELF_TEST_EXECUTION_STATUS_MAX
86 } SkSmartSelfTestExecutionStatus;
87
88 const char *sk_smart_self_test_execution_status_to_string(SkSmartSelfTestExecutionStatus status);
89
90 typedef struct SkSmartParsedData {
91         /* Volatile data */
92         SkSmartOfflineDataCollectionStatus offline_data_collection_status;
93         unsigned total_offline_data_collection_seconds;
94         SkSmartSelfTestExecutionStatus self_test_execution_status;
95         unsigned self_test_execution_percent_remaining;
96
97         /* Fixed data */
98         SkBool short_and_extended_test_available:1;
99         SkBool conveyance_test_available:1;
100         SkBool start_test_available:1;
101         SkBool abort_test_available:1;
102
103         unsigned short_test_polling_minutes;
104         unsigned extended_test_polling_minutes;
105         unsigned conveyance_test_polling_minutes;
106
107         /* This structure may be extended at any time without this being
108          * considered an ABI change. So take care when you copy it.  */
109 } SkSmartParsedData;
110
111 SkBool sk_smart_self_test_available(const SkSmartParsedData *d, SkSmartSelfTest test);
112 unsigned sk_smart_self_test_polling_minutes(const SkSmartParsedData *d, SkSmartSelfTest test);
113
114 typedef enum SkSmartAttributeUnit {
115         SK_SMART_ATTRIBUTE_UNIT_UNKNOWN,
116         SK_SMART_ATTRIBUTE_UNIT_NONE,
117         SK_SMART_ATTRIBUTE_UNIT_MSECONDS,    /* milliseconds */
118         SK_SMART_ATTRIBUTE_UNIT_SECTORS,
119         SK_SMART_ATTRIBUTE_UNIT_MKELVIN,     /* millikelvin */
120         _SK_SMART_ATTRIBUTE_UNIT_MAX
121 } SkSmartAttributeUnit;
122
123 const char* sk_smart_attribute_unit_to_string(SkSmartAttributeUnit unit);
124
125 typedef struct SkSmartAttributeParsedData {
126         /* Fixed data */
127         uint8_t id;
128         const char *name;
129         SkSmartAttributeUnit pretty_unit; /* for pretty_value */
130
131         uint16_t flags;
132
133         uint8_t threshold;
134         SkBool threshold_valid:1;
135
136         SkBool online:1;
137         SkBool prefailure:1;
138
139         /* Volatile data */
140         SkBool good:1;
141         uint8_t current_value, worst_value;
142         uint64_t pretty_value;
143         uint8_t raw[6];
144
145         /* This structure may be extended at any time without this being
146          * considered an ABI change. So take care when you copy it. */
147 } SkSmartAttributeParsedData;
148
149 typedef struct SkDisk SkDisk;
150
151 int sk_disk_open(const char *name, SkDisk **d);
152
153 int sk_disk_get_size(SkDisk *d, uint64_t *bytes);
154
155 int sk_disk_check_sleep_mode(SkDisk *d, SkBool *awake);
156
157 int sk_disk_identify_is_available(SkDisk *d, SkBool *available);
158 int sk_disk_identify_parse(SkDisk *d, const SkIdentifyParsedData **data);
159
160 typedef void (*SkSmartAttributeParseCallback)(SkDisk *d, const SkSmartAttributeParsedData *a, void* userdata);
161
162 int sk_disk_smart_is_available(SkDisk *d, SkBool *available);
163 int sk_disk_smart_status(SkDisk *d, SkBool *good);
164 /* Reading SMART data might cause the disk to wake up from
165  * sleep. Hence from monitoring daemons make sure to call
166  * sk_disk_check_power_mode() to check wether the disk is sleeping and
167  * skip the read if so. */
168 int sk_disk_smart_read_data(SkDisk *d);
169 int sk_disk_smart_parse(SkDisk *d, const SkSmartParsedData **data);
170 int sk_disk_smart_parse_attributes(SkDisk *d, SkSmartAttributeParseCallback cb, void* userdata);
171 int sk_disk_smart_self_test(SkDisk *d, SkSmartSelfTest test);
172
173 int sk_disk_dump(SkDisk *d);
174
175 void sk_disk_free(SkDisk *d);
176
177 #ifdef __cplusplus
178 }
179 #endif
180
181 #endif