1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
/* $OpenBSD: atasmart.h,v 1.2 2002/06/15 10:59:06 gluk Exp $ */
/*
* Copyright (c) 2002 Alexander Yurchenko <grange@rt.mipt.ru>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
/* ATA SMART subcommands */
#define ATA_SMART_READ 0xd0 /* SMART read data */
#define ATA_SMART_THRESHOLD 0xd1 /* SMART read threshold */
#define ATA_SMART_AUTOSAVE 0xd2 /* SMART en-/disable attr. autosave */
#define ATA_SMART_SAVE 0xd3 /* SMART save attributes */
#define ATA_SMART_OFFLINE 0xd4 /* SMART execute offline immediately */
#define ATA_SMART_READLOG 0xd5 /* SMART read log */
#define ATA_SMART_WRITELOG 0xd6 /* SMART write log */
#define ATA_SMART_EN 0xd8 /* SMART enable operations */
#define ATA_SMART_DS 0xd9 /* SMART disable operations */
#define ATA_SMART_STATUS 0xda /* SMART return status */
/* device attribute */
struct attribute {
u_int8_t id; /* Attribute ID */
u_int16_t status; /* Status flags */
u_int8_t value; /* Attribute value */
u_int8_t raw[8]; /* Vendor specific */
} __attribute__((packed));
/* read data sector */
struct smart_read {
u_int16_t revision; /* Data structure revision */
struct attribute attribute[30]; /* Device attribute */
u_int8_t offstat; /* Off-line data collection status */
#define SMART_OFFSTAT_NOTSTART 0x00
#define SMART_OFFSTAT_COMPLETE 0x02
#define SMART_OFFSTAT_SUSPEND 0x04
#define SMART_OFFSTAT_INTR 0x05
#define SMART_OFFSTAT_ERROR 0x06
u_int8_t selfstat; /* Self-test execution status */
#define SMART_SELFSTAT_COMPLETE 0x00
#define SMART_SELFSTAT_ABORT 0x01
#define SMART_SELFSTAT_INTR 0x02
#define SMART_SELFSTAT_ERROR 0x03
#define SMART_SELFSTAT_UNKFAIL 0x04
#define SMART_SELFSTAT_ELFAIL 0x05
#define SMART_SELFSTAT_SRVFAIL 0x06
#define SMART_SELFSTAT_RDFAIL 0x07
#define SMART_SELFSTAT_PROGRESS 0x0f
u_int16_t time; /* Time to complete data collection activity */
u_int8_t vendor1; /* Vendor specific */
u_int8_t offcap; /* Off-line data collection capability */
#define SMART_OFFCAP_EXEC 0x01
#define SMART_OFFCAP_ABORT 0x04
#define SMART_OFFCAP_READSCAN 0x08
#define SMART_OFFCAP_SELFTEST 0x10
u_int16_t smartcap; /* SMART capability */
#define SMART_SMARTCAP_SAVE 0x01
#define SMART_SMARTCAP_AUTOSAVE 0x02
u_int8_t errcap; /* Error logging capability */
#define SMART_ERRCAP_ERRLOG 0x01
u_int8_t vendor2; /* Vendor specific */
u_int8_t shtime; /* Short self-test polling time */
u_int8_t extime; /* Extended self-test polling time */
u_int8_t res[12]; /* Reserved */
u_int8_t vendor3[125]; /* Vendor specific */
u_int8_t cksum; /* Data structure checksum */
};
/* threshold entry */
struct threshold {
u_int8_t id; /* Threshold ID */
u_int8_t value; /* Threshold value */
u_int8_t reserve[10];
};
/* read thresholds sector */
struct smart_threshold {
u_int16_t revision; /* Data structure revision */
struct threshold threshold[30];
u_int8_t reserve[18];
u_int8_t vendor[131];
u_int8_t cksum; /* Data structure checksum */
};
/* log directory entry */
struct smart_log_dir_entry {
u_int8_t sec_num;
u_int8_t res;
};
/* log directory sector */
struct smart_log_dir {
u_int16_t version;
struct smart_log_dir_entry entry[255];
};
/* command data structure */
struct smart_log_cmd {
u_int8_t reg_ctl;
u_int8_t reg_feat;
u_int8_t reg_seccnt;
u_int8_t reg_lbalo;
u_int8_t reg_lbamid;
u_int8_t reg_lbahi;
u_int8_t reg_dev;
u_int8_t reg_cmd;
u_int8_t time1;
u_int8_t time2;
u_int8_t time3;
u_int8_t time4;
};
/* error data structure */
struct smart_log_err {
u_int8_t res;
u_int8_t reg_err;
u_int8_t reg_seccnt;
u_int8_t reg_lbalo;
u_int8_t reg_lbamid;
u_int8_t reg_lbahi;
u_int8_t reg_dev;
u_int8_t reg_stat;
u_int8_t ext[19];
u_int8_t state;
#define SMART_LOG_STATE_UNK 0x0
#define SMART_LOG_STATE_SLEEP 0x1
#define SMART_LOG_STATE_ACTIDL 0x2
#define SMART_LOG_STATE_OFFSELF 0x3
u_int8_t time1;
u_int8_t time2;
};
/* error log data structure */
struct smart_log_errdata {
struct smart_log_cmd cmd[5];
struct smart_log_err err;
};
/* summary error log sector */
struct smart_log_sum {
u_int8_t version;
u_int8_t index;
struct smart_log_errdata errdata[5];
u_int16_t err_cnt;
u_int8_t res[57];
u_int8_t cksum;
};
/* comprehensive error log sector */
struct smart_log_comp {
u_int8_t version;
u_int8_t index;
struct smart_log_errdata errdata[5];
u_int16_t err_cnt;
u_int8_t res[57];
u_int8_t cksum;
};
/* self-test descriptor entry */
struct smart_log_self_desc {
u_int8_t reg_lbalo;
u_int8_t selfstat;
u_int8_t time1;
u_int8_t time2;
u_int8_t chkpnt;
u_int8_t lbafail1;
u_int8_t lbafail2;
u_int8_t lbafail3;
u_int8_t lbafail4;
u_int8_t vendor[15];
};
/* self-test log sector */
struct smart_log_self {
u_int16_t rev;
struct smart_log_self_desc desc[21];
u_int8_t vendor[2];
u_int8_t index;
u_int8_t res[2];
u_int8_t cksum;
};
#define SMART_SELFSTAT_PCNT(s) ((s & 0x0f) * 10)
#define SMART_SELFSTAT_STAT(s) (s >> 4)
#define SMART_OFFLINE_COLLECT 0
#define SMART_OFFLINE_SHORTOFF 1
#define SMART_OFFLINE_EXTENOFF 2
#define SMART_OFFLINE_ABORT 127
#define SMART_OFFLINE_SHORTCAP 129
#define SMART_OFFLINE_EXTENCAP 130
#define SMART_AUTOSAVE_DS 0x00
#define SMART_AUTOSAVE_EN 0xf1
#define SMART_READLOG_DIR 0x00
#define SMART_READLOG_SUM 0x01
#define SMART_READLOG_COMP 0x02
#define SMART_READLOG_ECOMP 0x03
#define SMART_READLOG_SELF 0x06
#define SMART_READLOG_ESELF 0x07
#define SMART_LOG_MSECT 0x01
|