fix double inclusion macro name
[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 typedef int SkBool;
29
30 #ifndef FALSE
31 #define FALSE (0)
32 #endif
33
34 #ifndef TRUE
35 #define TRUE (!FALSE)
36 #endif
37
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
44 } SkSmartSelfTest;
45
46 const char* sk_smart_self_test_to_string(SkSmartSelfTest test);
47
48 typedef struct SkIdentifyParsedData {
49         char serial[21];
50         char firmware[9];
51         char model[41];
52
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;
56
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;
67
68 const char* sk_smart_offline_data_collection_status_to_string(SkSmartOfflineDataCollectionStatus status);
69
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;
83
84 const char *sk_smart_self_test_execution_status_to_string(SkSmartSelfTestExecutionStatus status);
85
86 typedef struct SkSmartParsedData {
87         /* Volatile data */
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;
92
93         /* Fixed data */
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;
98
99         unsigned short_test_polling_minutes;
100         unsigned extended_test_polling_minutes;
101         unsigned conveyance_test_polling_minutes;
102
103         /* This structure may be extended at any time without this being
104          * considered an ABI change. So take care when you copy it.  */
105 } SkSmartParsedData;
106
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);
109
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;
118
119 const char* sk_smart_attribute_unit_to_string(SkSmartAttributeUnit unit);
120
121 typedef struct SkSmartAttributeParsedData {
122         /* Fixed data */
123         uint8_t id;
124         const char *name;
125         SkSmartAttributeUnit pretty_unit; /* for pretty_value */
126
127         uint16_t flags;
128
129         uint8_t threshold;
130         SkBool threshold_valid:1;
131
132         SkBool online:1;
133         SkBool prefailure:1;
134
135         /* Volatile data */
136         SkBool good:1;
137         uint8_t current_value, worst_value;
138         uint64_t pretty_value;
139         uint8_t raw[6];
140
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;
144
145 typedef struct SkDisk SkDisk;
146
147 int sk_disk_open(const char *name, SkDisk **d);
148
149 int sk_disk_get_size(SkDisk *d, uint64_t *bytes);
150
151 int sk_disk_check_sleep_mode(SkDisk *d, SkBool *awake);
152
153 int sk_disk_identify_is_available(SkDisk *d, SkBool *available);
154 int sk_disk_identify_parse(SkDisk *d, const SkIdentifyParsedData **data);
155
156 typedef void (*SkSmartAttributeParseCallback)(SkDisk *d, const SkSmartAttributeParsedData *a, void* userdata);
157
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);
168
169 int sk_disk_dump(SkDisk *d);
170
171 void sk_disk_free(SkDisk *d);
172
173 #endif