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/>.
32 typedef unsigned SkBool;
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
50 const char* sk_smart_self_test_to_string(SkSmartSelfTest test);
52 typedef struct SkIdentifyParsedData {
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;
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;
72 const char* sk_smart_offline_data_collection_status_to_string(SkSmartOfflineDataCollectionStatus status);
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;
88 const char *sk_smart_self_test_execution_status_to_string(SkSmartSelfTestExecutionStatus status);
90 typedef struct SkSmartParsedData {
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;
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;
103 unsigned short_test_polling_minutes;
104 unsigned extended_test_polling_minutes;
105 unsigned conveyance_test_polling_minutes;
107 /* This structure may be extended at any time without this being
108 * considered an ABI change. So take care when you copy it. */
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);
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;
123 const char* sk_smart_attribute_unit_to_string(SkSmartAttributeUnit unit);
125 typedef struct SkSmartAttributeParsedData {
129 SkSmartAttributeUnit pretty_unit; /* for pretty_value */
134 SkBool threshold_valid:1;
140 SkBool good:1, good_valid:1;
141 SkBool current_value_valid:1, worst_value_valid:1;
142 uint8_t current_value, worst_value;
143 uint64_t pretty_value;
146 /* This structure may be extended at any time without this being
147 * considered an ABI change. So take care when you copy it. */
148 } SkSmartAttributeParsedData;
150 typedef struct SkDisk SkDisk;
152 int sk_disk_open(const char *name, SkDisk **d);
154 int sk_disk_get_size(SkDisk *d, uint64_t *bytes);
156 int sk_disk_check_sleep_mode(SkDisk *d, SkBool *awake);
158 int sk_disk_identify_is_available(SkDisk *d, SkBool *available);
159 int sk_disk_identify_parse(SkDisk *d, const SkIdentifyParsedData **data);
161 typedef void (*SkSmartAttributeParseCallback)(SkDisk *d, const SkSmartAttributeParsedData *a, void* userdata);
163 int sk_disk_smart_is_available(SkDisk *d, SkBool *available);
164 int sk_disk_smart_status(SkDisk *d, SkBool *good);
165 /* Reading SMART data might cause the disk to wake up from
166 * sleep. Hence from monitoring daemons make sure to call
167 * sk_disk_check_power_mode() to check wether the disk is sleeping and
168 * skip the read if so. */
169 int sk_disk_smart_read_data(SkDisk *d);
170 int sk_disk_smart_parse(SkDisk *d, const SkSmartParsedData **data);
171 int sk_disk_smart_parse_attributes(SkDisk *d, SkSmartAttributeParseCallback cb, void* userdata);
172 int sk_disk_smart_self_test(SkDisk *d, SkSmartSelfTest test);
174 /* High level API to get the power on time */
175 int sk_disk_smart_get_power_on(SkDisk *d, uint64_t *mseconds);
177 /* High level API to get the number of bad sectors (i.e. pending and reallocated) */
178 int sk_disk_smart_get_bad(SkDisk *d, uint64_t *sectors);
180 /* High level API to get the temperature */
181 int sk_disk_smart_get_temperature(SkDisk *d, uint64_t *kelvin);
183 int sk_disk_dump(SkDisk *d);
185 void sk_disk_free(SkDisk *d);