1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
3 #ifndef fooatasmarthfoo
4 #define fooatasmarthfoo
7 This file is part of libatasmart.
9 Copyright 2008 Lennart Poettering
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.
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.
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/>.
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! */
36 typedef unsigned SkBool;
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
54 const char* sk_smart_self_test_to_string(SkSmartSelfTest test);
56 typedef struct SkIdentifyParsedData {
61 /* This structure may be extended at any time without this being
62 * considered an ABI change. So take care when you copy it. */
63 } SkIdentifyParsedData;
65 typedef enum SkSmartOfflineDataCollectionStatus {
66 SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_NEVER,
67 SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_SUCCESS,
68 SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_INPROGRESS,
69 SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_SUSPENDED,
70 SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_ABORTED,
71 SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_FATAL,
72 SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_UNKNOWN,
73 _SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_MAX
74 } SkSmartOfflineDataCollectionStatus;
76 const char* sk_smart_offline_data_collection_status_to_string(SkSmartOfflineDataCollectionStatus status);
78 typedef enum SkSmartSelfTestExecutionStatus {
79 SK_SMART_SELF_TEST_EXECUTION_STATUS_SUCCESS_OR_NEVER = 0,
80 SK_SMART_SELF_TEST_EXECUTION_STATUS_ABORTED = 1,
81 SK_SMART_SELF_TEST_EXECUTION_STATUS_INTERRUPTED = 2,
82 SK_SMART_SELF_TEST_EXECUTION_STATUS_FATAL = 3,
83 SK_SMART_SELF_TEST_EXECUTION_STATUS_ERROR_UNKNOWN = 4,
84 SK_SMART_SELF_TEST_EXECUTION_STATUS_ERROR_ELECTRICAL = 5,
85 SK_SMART_SELF_TEST_EXECUTION_STATUS_ERROR_SERVO = 6,
86 SK_SMART_SELF_TEST_EXECUTION_STATUS_ERROR_READ = 7,
87 SK_SMART_SELF_TEST_EXECUTION_STATUS_ERROR_HANDLING = 8,
88 SK_SMART_SELF_TEST_EXECUTION_STATUS_INPROGRESS = 15,
89 _SK_SMART_SELF_TEST_EXECUTION_STATUS_MAX
90 } SkSmartSelfTestExecutionStatus;
92 const char *sk_smart_self_test_execution_status_to_string(SkSmartSelfTestExecutionStatus status);
94 typedef struct SkSmartParsedData {
96 SkSmartOfflineDataCollectionStatus offline_data_collection_status;
97 unsigned total_offline_data_collection_seconds;
98 SkSmartSelfTestExecutionStatus self_test_execution_status;
99 unsigned self_test_execution_percent_remaining;
102 SkBool short_and_extended_test_available:1;
103 SkBool conveyance_test_available:1;
104 SkBool start_test_available:1;
105 SkBool abort_test_available:1;
107 unsigned short_test_polling_minutes;
108 unsigned extended_test_polling_minutes;
109 unsigned conveyance_test_polling_minutes;
111 /* This structure may be extended at any time without this being
112 * considered an ABI change. So take care when you copy it. */
115 SkBool sk_smart_self_test_available(const SkSmartParsedData *d, SkSmartSelfTest test);
116 unsigned sk_smart_self_test_polling_minutes(const SkSmartParsedData *d, SkSmartSelfTest test);
118 typedef enum SkSmartAttributeUnit {
119 SK_SMART_ATTRIBUTE_UNIT_UNKNOWN,
120 SK_SMART_ATTRIBUTE_UNIT_NONE,
121 SK_SMART_ATTRIBUTE_UNIT_MSECONDS, /* milliseconds */
122 SK_SMART_ATTRIBUTE_UNIT_SECTORS,
123 SK_SMART_ATTRIBUTE_UNIT_MKELVIN, /* millikelvin */
124 _SK_SMART_ATTRIBUTE_UNIT_MAX
125 } SkSmartAttributeUnit;
127 const char* sk_smart_attribute_unit_to_string(SkSmartAttributeUnit unit);
129 typedef struct SkSmartAttributeParsedData {
133 SkSmartAttributeUnit pretty_unit; /* for pretty_value */
138 SkBool threshold_valid:1;
144 SkBool good:1, good_valid:1;
145 SkBool current_value_valid:1, worst_value_valid:1;
146 uint8_t current_value, worst_value;
147 uint64_t pretty_value;
150 /* This structure may be extended at any time without this being
151 * considered an ABI change. So take care when you copy it. */
152 } SkSmartAttributeParsedData;
154 typedef struct SkDisk SkDisk;
156 typedef enum SkSmartOverall {
157 SK_SMART_OVERALL_GOOD,
158 SK_SMART_OVERALL_BAD_STATUS, /* Smart Self Assessment negative */
159 SK_SMART_OVERALL_BAD_SECTOR, /* At least one bad sector */
160 SK_SMART_OVERALL_BAD_ATTRIBUTE, /* At least one attribute exceeded its threshold */
161 _SK_SMART_OVERALL_MAX
164 const char* sk_smart_overall_to_string(SkSmartOverall overall);
166 int sk_disk_open(const char *name, SkDisk **d);
168 int sk_disk_get_size(SkDisk *d, uint64_t *bytes);
170 int sk_disk_check_sleep_mode(SkDisk *d, SkBool *awake);
172 int sk_disk_identify_is_available(SkDisk *d, SkBool *available);
173 int sk_disk_identify_parse(SkDisk *d, const SkIdentifyParsedData **data);
175 typedef void (*SkSmartAttributeParseCallback)(SkDisk *d, const SkSmartAttributeParsedData *a, void* userdata);
177 int sk_disk_smart_is_available(SkDisk *d, SkBool *available);
178 int sk_disk_smart_status(SkDisk *d, SkBool *good);
180 /* Reading SMART data might cause the disk to wake up from
181 * sleep. Hence from monitoring daemons make sure to call
182 * sk_disk_check_power_mode() to check wether the disk is sleeping and
183 * skip the read if so. */
184 int sk_disk_smart_read_data(SkDisk *d);
185 int sk_disk_smart_parse(SkDisk *d, const SkSmartParsedData **data);
186 int sk_disk_smart_parse_attributes(SkDisk *d, SkSmartAttributeParseCallback cb, void* userdata);
187 int sk_disk_smart_self_test(SkDisk *d, SkSmartSelfTest test);
189 /* High level API to get the power on time */
190 int sk_disk_smart_get_power_on(SkDisk *d, uint64_t *mseconds);
192 /* High level API to get the number of bad sectors (i.e. pending and reallocated) */
193 int sk_disk_smart_get_bad(SkDisk *d, uint64_t *sectors);
195 /* High level API to get the temperature */
196 int sk_disk_smart_get_temperature(SkDisk *d, uint64_t *kelvin);
198 /* Get overall status. This integrates the values of a couple of fields into a single overall status */
199 int sk_disk_smart_get_overall(SkDisk *d, SkSmartOverall *overall);
201 int sk_disk_dump(SkDisk *d);
203 void sk_disk_free(SkDisk *d);