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 | /* Please note that all enums defined here may be extended at any time |
29 | * without this being considered an ABI change. So take care when |
30 | * using them as indexes! */ |
31 | |
32 | #ifdef __cplusplus |
33 | extern "C" { |
34 | #endif |
35 | |
36 | typedef unsigned SkBool; |
37 | |
38 | #ifndef FALSE |
39 | #define FALSE (0) |
40 | #endif |
41 | |
42 | #ifndef TRUE |
43 | #define TRUE (!FALSE) |
44 | #endif |
45 | |
46 | /* ATA SMART test type (ATA8 7.52.5.2) */ |
47 | typedef enum SkSmartSelfTest { |
48 | SK_SMART_SELF_TEST_SHORT = 1, |
49 | SK_SMART_SELF_TEST_EXTENDED = 2, |
50 | SK_SMART_SELF_TEST_CONVEYANCE = 3, |
51 | SK_SMART_SELF_TEST_ABORT = 127 |
52 | |
53 | /* This enum may be extended at any time without this being |
54 | * considered an ABI change. So take care when you use this |
55 | * type! */ |
56 | } SkSmartSelfTest; |
57 | |
58 | const char* sk_smart_self_test_to_string(SkSmartSelfTest test); |
59 | |
60 | typedef struct SkIdentifyParsedData { |
61 | char serial[21]; |
62 | char firmware[9]; |
63 | char model[41]; |
64 | |
65 | /* This structure may be extended at any time without this being |
66 | * considered an ABI change. So take care when you copy it. */ |
67 | } SkIdentifyParsedData; |
68 | |
69 | typedef enum SkSmartOfflineDataCollectionStatus { |
70 | SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_NEVER, |
71 | SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_SUCCESS, |
72 | SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_INPROGRESS, |
73 | SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_SUSPENDED, |
74 | SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_ABORTED, |
75 | SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_FATAL, |
76 | SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_UNKNOWN, |
77 | _SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_MAX |
78 | |
79 | /* This enum may be extended at any time without this being |
80 | * considered an ABI change. So take care when you use this |
81 | * type! */ |
82 | } SkSmartOfflineDataCollectionStatus; |
83 | |
84 | const char* sk_smart_offline_data_collection_status_to_string(SkSmartOfflineDataCollectionStatus status); |
85 | |
86 | typedef enum SkSmartSelfTestExecutionStatus { |
87 | SK_SMART_SELF_TEST_EXECUTION_STATUS_SUCCESS_OR_NEVER = 0, |
88 | SK_SMART_SELF_TEST_EXECUTION_STATUS_ABORTED = 1, |
89 | SK_SMART_SELF_TEST_EXECUTION_STATUS_INTERRUPTED = 2, |
90 | SK_SMART_SELF_TEST_EXECUTION_STATUS_FATAL = 3, |
91 | SK_SMART_SELF_TEST_EXECUTION_STATUS_ERROR_UNKNOWN = 4, |
92 | SK_SMART_SELF_TEST_EXECUTION_STATUS_ERROR_ELECTRICAL = 5, |
93 | SK_SMART_SELF_TEST_EXECUTION_STATUS_ERROR_SERVO = 6, |
94 | SK_SMART_SELF_TEST_EXECUTION_STATUS_ERROR_READ = 7, |
95 | SK_SMART_SELF_TEST_EXECUTION_STATUS_ERROR_HANDLING = 8, |
96 | SK_SMART_SELF_TEST_EXECUTION_STATUS_INPROGRESS = 15, |
97 | _SK_SMART_SELF_TEST_EXECUTION_STATUS_MAX |
98 | |
99 | /* This enum may be extended at any time without this being |
100 | * considered an ABI change. So take care when you use this |
101 | * type! */ |
102 | } SkSmartSelfTestExecutionStatus; |
103 | |
104 | const char *sk_smart_self_test_execution_status_to_string(SkSmartSelfTestExecutionStatus status); |
105 | |
106 | typedef struct SkSmartParsedData { |
107 | /* Volatile data */ |
108 | SkSmartOfflineDataCollectionStatus offline_data_collection_status; |
109 | unsigned total_offline_data_collection_seconds; |
110 | SkSmartSelfTestExecutionStatus self_test_execution_status; |
111 | unsigned self_test_execution_percent_remaining; |
112 | |
113 | /* Fixed data */ |
114 | SkBool short_and_extended_test_available:1; |
115 | SkBool conveyance_test_available:1; |
116 | SkBool start_test_available:1; |
117 | SkBool abort_test_available:1; |
118 | |
119 | unsigned short_test_polling_minutes; |
120 | unsigned extended_test_polling_minutes; |
121 | unsigned conveyance_test_polling_minutes; |
122 | |
123 | /* This structure may be extended at any time without this being |
124 | * considered an ABI change. So take care when you copy it. */ |
125 | } SkSmartParsedData; |
126 | |
127 | SkBool sk_smart_self_test_available(const SkSmartParsedData *d, SkSmartSelfTest test); |
128 | unsigned sk_smart_self_test_polling_minutes(const SkSmartParsedData *d, SkSmartSelfTest test); |
129 | |
130 | typedef enum SkSmartAttributeUnit { |
131 | SK_SMART_ATTRIBUTE_UNIT_UNKNOWN, |
132 | SK_SMART_ATTRIBUTE_UNIT_NONE, |
133 | SK_SMART_ATTRIBUTE_UNIT_MSECONDS, /* milliseconds */ |
134 | SK_SMART_ATTRIBUTE_UNIT_SECTORS, |
135 | SK_SMART_ATTRIBUTE_UNIT_MKELVIN, /* millikelvin */ |
136 | SK_SMART_ATTRIBUTE_UNIT_SMALL_PERCENT, /* percentage with 3 decimal points */ |
137 | SK_SMART_ATTRIBUTE_UNIT_PERCENT, /* integer percentage */ |
138 | SK_SMART_ATTRIBUTE_UNIT_MB, |
139 | _SK_SMART_ATTRIBUTE_UNIT_MAX |
140 | |
141 | /* This enum may be extended at any time without this being |
142 | * considered an ABI change. So take care when you use this |
143 | * type! */ |
144 | } SkSmartAttributeUnit; |
145 | |
146 | const char* sk_smart_attribute_unit_to_string(SkSmartAttributeUnit unit); |
147 | |
148 | typedef struct SkSmartAttributeParsedData { |
149 | /* Fixed data */ |
150 | uint8_t id; |
151 | const char *name; |
152 | SkSmartAttributeUnit pretty_unit; /* for pretty_value */ |
153 | |
154 | uint16_t flags; |
155 | |
156 | uint8_t threshold; |
157 | SkBool threshold_valid:1; |
158 | |
159 | SkBool online:1; |
160 | SkBool prefailure:1; |
161 | |
162 | /* Volatile data */ |
163 | SkBool good_now:1, good_now_valid:1; |
164 | SkBool good_in_the_past:1, good_in_the_past_valid:1; |
165 | SkBool current_value_valid:1, worst_value_valid:1; |
166 | SkBool warn:1; |
167 | uint8_t current_value, worst_value; |
168 | uint64_t pretty_value; |
169 | uint8_t raw[6]; |
170 | |
171 | /* This structure may be extended at any time without this being |
172 | * considered an ABI change. So take care when you copy it. */ |
173 | } SkSmartAttributeParsedData; |
174 | |
175 | typedef struct SkDisk SkDisk; |
176 | |
177 | typedef enum SkSmartOverall { |
178 | SK_SMART_OVERALL_GOOD, |
179 | SK_SMART_OVERALL_BAD_ATTRIBUTE_IN_THE_PAST, /* At least one pre-fail attribute exceeded its threshold in the past */ |
180 | SK_SMART_OVERALL_BAD_SECTOR, /* At least one bad sector */ |
181 | SK_SMART_OVERALL_BAD_ATTRIBUTE_NOW, /* At least one pre-fail attribute is exceeding its threshold now */ |
182 | SK_SMART_OVERALL_BAD_SECTOR_MANY, /* Many bad sectors */ |
183 | SK_SMART_OVERALL_BAD_STATUS, /* Smart Self Assessment negative */ |
184 | _SK_SMART_OVERALL_MAX |
185 | |
186 | /* This enum may be extended at any time without this being |
187 | * considered an ABI change. So take care when you use this |
188 | * type! */ |
189 | } SkSmartOverall; |
190 | |
191 | const char* sk_smart_overall_to_string(SkSmartOverall overall); |
192 | |
193 | int sk_disk_open(const char *name, SkDisk **d); |
194 | |
195 | int sk_disk_get_size(SkDisk *d, uint64_t *bytes); |
196 | |
197 | int sk_disk_check_sleep_mode(SkDisk *d, SkBool *awake); |
198 | |
199 | int sk_disk_identify_is_available(SkDisk *d, SkBool *available); |
200 | int sk_disk_identify_parse(SkDisk *d, const SkIdentifyParsedData **data); |
201 | |
202 | typedef void (*SkSmartAttributeParseCallback)(SkDisk *d, const SkSmartAttributeParsedData *a, void* userdata); |
203 | |
204 | int sk_disk_smart_is_available(SkDisk *d, SkBool *available); |
205 | int sk_disk_smart_status(SkDisk *d, SkBool *good); |
206 | |
207 | /* Reading SMART data might cause the disk to wake up from |
208 | * sleep. Hence from monitoring daemons make sure to call |
209 | * sk_disk_check_power_mode() to check wether the disk is sleeping and |
210 | * skip the read if so. */ |
211 | int sk_disk_smart_read_data(SkDisk *d); |
212 | |
213 | int sk_disk_get_blob(SkDisk *d, const void **blob, size_t *size); |
214 | int sk_disk_set_blob(SkDisk *d, const void *blob, size_t size); |
215 | |
216 | int sk_disk_smart_parse(SkDisk *d, const SkSmartParsedData **data); |
217 | int sk_disk_smart_parse_attributes(SkDisk *d, SkSmartAttributeParseCallback cb, void* userdata); |
218 | int sk_disk_smart_self_test(SkDisk *d, SkSmartSelfTest test); |
219 | |
220 | /* High level API to get the power on time */ |
221 | int sk_disk_smart_get_power_on(SkDisk *d, uint64_t *mseconds); |
222 | |
223 | /* High level API to get the power cycle count */ |
224 | int sk_disk_smart_get_power_cycle(SkDisk *d, uint64_t *count); |
225 | |
226 | /* High level API to get the number of bad sectors (i.e. pending and reallocated) */ |
227 | int sk_disk_smart_get_bad(SkDisk *d, uint64_t *sectors); |
228 | |
229 | /* High level API to get the temperature */ |
230 | int sk_disk_smart_get_temperature(SkDisk *d, uint64_t *mkelvin); |
231 | |
232 | /* Get overall status. This integrates the values of a couple of fields into a single overall status */ |
233 | int sk_disk_smart_get_overall(SkDisk *d, SkSmartOverall *overall); |
234 | |
235 | /* Dump the current parsed status to STDOUT */ |
236 | int sk_disk_dump(SkDisk *d); |
237 | |
238 | void sk_disk_free(SkDisk *d); |
239 | |
240 | #ifdef __cplusplus |
241 | } |
242 | #endif |
243 | |
244 | #endif |
245 | |