1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
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/>.
38 /* ATA SMART test type (ATA8 7.52.5.2) */
39 typedef enum SkSmartSelfTest {
40 SK_SMART_SELF_TEST_SHORT = 1,
41 SK_SMART_SELF_TEST_EXTENDED = 2,
42 SK_SMART_SELF_TEST_CONVEYANCE = 3,
43 SK_SMART_SELF_TEST_ABORT = 127
46 const char* sk_smart_self_test_to_string(SkSmartSelfTest test);
48 typedef struct SkIdentifyParsedData {
53 /* This structure may be extended at any time without this being
54 * considered an ABI change. So take care when you copy it. */
55 } SkIdentifyParsedData;
57 typedef enum SkSmartOfflineDataCollectionStatus {
58 SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_NEVER,
59 SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_SUCCESS,
60 SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_INPROGRESS,
61 SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_SUSPENDED,
62 SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_ABORTED,
63 SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_FATAL,
64 SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_UNKNOWN,
65 _SK_SMART_OFFLINE_DATA_COLLECTION_STATUS_MAX
66 } SkSmartOfflineDataCollectionStatus;
68 const char* sk_smart_offline_data_collection_status_to_string(SkSmartOfflineDataCollectionStatus status);
70 typedef enum SkSmartSelfTestExecutionStatus {
71 SK_SMART_SELF_TEST_EXECUTION_STATUS_SUCCESS_OR_NEVER = 0,
72 SK_SMART_SELF_TEST_EXECUTION_STATUS_ABORTED = 1,
73 SK_SMART_SELF_TEST_EXECUTION_STATUS_INTERRUPTED = 2,
74 SK_SMART_SELF_TEST_EXECUTION_STATUS_FATAL = 3,
75 SK_SMART_SELF_TEST_EXECUTION_STATUS_ERROR_UNKNOWN = 4,
76 SK_SMART_SELF_TEST_EXECUTION_STATUS_ERROR_ELECTRICAL = 5,
77 SK_SMART_SELF_TEST_EXECUTION_STATUS_ERROR_SERVO = 6,
78 SK_SMART_SELF_TEST_EXECUTION_STATUS_ERROR_READ = 7,
79 SK_SMART_SELF_TEST_EXECUTION_STATUS_ERROR_HANDLING = 8,
80 SK_SMART_SELF_TEST_EXECUTION_STATUS_INPROGRESS = 15,
81 _SK_SMART_SELF_TEST_EXECUTION_STATUS_MAX
82 } SkSmartSelfTestExecutionStatus;
84 const char *sk_smart_self_test_execution_status_to_string(SkSmartSelfTestExecutionStatus status);
86 typedef struct SkSmartParsedData {
88 SkSmartOfflineDataCollectionStatus offline_data_collection_status;
89 unsigned total_offline_data_collection_seconds;
90 SkSmartSelfTestExecutionStatus self_test_execution_status;
91 unsigned self_test_execution_percent_remaining;
94 SkBool short_and_extended_test_available:1;
95 SkBool conveyance_test_available:1;
96 SkBool start_test_available:1;
97 SkBool abort_test_available:1;
99 unsigned short_test_polling_minutes;
100 unsigned extended_test_polling_minutes;
101 unsigned conveyance_test_polling_minutes;
103 /* This structure may be extended at any time without this being
104 * considered an ABI change. So take care when you copy it. */
107 SkBool sk_smart_self_test_available(const SkSmartParsedData *d, SkSmartSelfTest test);
108 unsigned sk_smart_self_test_polling_minutes(const SkSmartParsedData *d, SkSmartSelfTest test);
110 typedef enum SkSmartAttributeUnit {
111 SK_SMART_ATTRIBUTE_UNIT_UNKNOWN,
112 SK_SMART_ATTRIBUTE_UNIT_NONE,
113 SK_SMART_ATTRIBUTE_UNIT_MSECONDS, /* milliseconds */
114 SK_SMART_ATTRIBUTE_UNIT_SECTORS,
115 SK_SMART_ATTRIBUTE_UNIT_MKELVIN, /* millikelvin */
116 _SK_SMART_ATTRIBUTE_UNIT_MAX
117 } SkSmartAttributeUnit;
119 const char* sk_smart_attribute_unit_to_string(SkSmartAttributeUnit unit);
121 typedef struct SkSmartAttributeParsedData {
125 SkSmartAttributeUnit pretty_unit; /* for pretty_value */
130 SkBool threshold_valid:1;
137 uint8_t current_value, worst_value;
138 uint64_t pretty_value;
141 /* This structure may be extended at any time without this being
142 * considered an ABI change. So take care when you copy it. */
143 } SkSmartAttributeParsedData;
145 typedef struct SkDisk SkDisk;
147 int sk_disk_open(const char *name, SkDisk **d);
149 int sk_disk_get_size(SkDisk *d, uint64_t *bytes);
151 int sk_disk_check_sleep_mode(SkDisk *d, SkBool *awake);
153 int sk_disk_identify_is_available(SkDisk *d, SkBool *available);
154 int sk_disk_identify_parse(SkDisk *d, const SkIdentifyParsedData **data);
156 typedef void (*SkSmartAttributeParseCallback)(SkDisk *d, const SkSmartAttributeParsedData *a, void* userdata);
158 int sk_disk_smart_is_available(SkDisk *d, SkBool *available);
159 int sk_disk_smart_status(SkDisk *d, SkBool *good);
160 /* Reading SMART data might cause the disk to wake up from
161 * sleep. Hence from monitoring daemons make sure to call
162 * sk_disk_check_power_mode() to check wether the disk is sleeping and
163 * skip the read if so. */
164 int sk_disk_smart_read_data(SkDisk *d);
165 int sk_disk_smart_parse(SkDisk *d, const SkSmartParsedData **data);
166 int sk_disk_smart_parse_attributes(SkDisk *d, SkSmartAttributeParseCallback cb, void* userdata);
167 int sk_disk_smart_self_test(SkDisk *d, SkSmartSelfTest test);
169 int sk_disk_dump(SkDisk *d);
171 void sk_disk_free(SkDisk *d);