]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * atacmds.h | |
3 | * | |
4 | * Home page of code is: http://smartmontools.sourceforge.net | |
5 | * | |
6 | * Copyright (C) 2002-11 Bruce Allen <smartmontools-support@lists.sourceforge.net> | |
7 | * Copyright (C) 2008-12 Christian Franke <smartmontools-support@lists.sourceforge.net> | |
8 | * Copyright (C) 1999-2000 Michael Cornwell <cornwell@acm.org> | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License as published by | |
12 | * the Free Software Foundation; either version 2, or (at your option) | |
13 | * any later version. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * (for example COPYING); if not, write to the Free | |
17 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 | * | |
19 | * This code was originally developed as a Senior Thesis by Michael Cornwell | |
20 | * at the Concurrent Systems Laboratory (now part of the Storage Systems | |
21 | * Research Center), Jack Baskin School of Engineering, University of | |
22 | * California, Santa Cruz. http://ssrc.soe.ucsc.edu/ | |
23 | * | |
24 | */ | |
25 | ||
26 | #ifndef ATACMDS_H_ | |
27 | #define ATACMDS_H_ | |
28 | ||
29 | #define ATACMDS_H_CVSID "$Id: atacmds.h 3528 2012-03-25 17:13:47Z chrfranke $" | |
30 | ||
31 | #include "dev_interface.h" // ata_device | |
32 | ||
33 | // Macro to check expected size of struct at compile time using a | |
34 | // dummy typedef. On size mismatch, compiler reports a negative array | |
35 | // size. If you see an error message of this form, it means that the | |
36 | // #pragma pack(1) pragma below is not having the desired effect on | |
37 | // your compiler. | |
38 | #define ASSERT_SIZEOF_STRUCT(s, n) \ | |
39 | typedef char assert_sizeof_struct_##s[(sizeof(struct s) == (n)) ? 1 : -1] | |
40 | ||
41 | // Add __attribute__((packed)) if compiler supports it | |
42 | // because some gcc versions (at least ARM) lack support of #pragma pack() | |
43 | #ifdef HAVE_ATTR_PACKED | |
44 | #define ATTR_PACKED __attribute__((packed)) | |
45 | #else | |
46 | #define ATTR_PACKED | |
47 | #endif | |
48 | ||
49 | typedef enum { | |
50 | // returns no data, just succeeds or fails | |
51 | ENABLE, | |
52 | DISABLE, | |
53 | AUTOSAVE, | |
54 | IMMEDIATE_OFFLINE, | |
55 | AUTO_OFFLINE, | |
56 | STATUS, // just says if SMART is working or not | |
57 | STATUS_CHECK, // says if disk's SMART status is healthy, or failing | |
58 | // return 512 bytes of data: | |
59 | READ_VALUES, | |
60 | READ_THRESHOLDS, | |
61 | READ_LOG, | |
62 | IDENTIFY, | |
63 | PIDENTIFY, | |
64 | // returns 1 byte of data | |
65 | CHECK_POWER_MODE, | |
66 | // writes 512 bytes of data: | |
67 | WRITE_LOG | |
68 | } smart_command_set; | |
69 | ||
70 | // Possible values for fix_firmwarebug. | |
71 | enum { | |
72 | FIX_NOTSPECIFIED = 0, | |
73 | FIX_NONE, | |
74 | FIX_SAMSUNG, | |
75 | FIX_SAMSUNG2, | |
76 | FIX_SAMSUNG3 | |
77 | }; | |
78 | ||
79 | // ATA Specification Command Register Values (Commands) | |
80 | #define ATA_CHECK_POWER_MODE 0xe5 | |
81 | #define ATA_IDENTIFY_DEVICE 0xec | |
82 | #define ATA_IDENTIFY_PACKET_DEVICE 0xa1 | |
83 | #define ATA_IDLE 0xe3 | |
84 | #define ATA_SMART_CMD 0xb0 | |
85 | #define ATA_SECURITY_FREEZE_LOCK 0xf5 | |
86 | #define ATA_SET_FEATURES 0xef | |
87 | #define ATA_STANDBY_IMMEDIATE 0xe0 | |
88 | ||
89 | // SET_FEATURES subcommands | |
90 | #define ATA_DISABLE_AAM 0xc2 | |
91 | #define ATA_DISABLE_APM 0x85 | |
92 | #define ATA_DISABLE_WRITE_CACHE 0x82 | |
93 | #define ATA_DISABLE_READ_LOOK_AHEAD 0x55 | |
94 | #define ATA_ENABLE_AAM 0x42 | |
95 | #define ATA_ENABLE_APM 0x05 | |
96 | #define ATA_ENABLE_WRITE_CACHE 0x02 | |
97 | #define ATA_ENABLE_READ_LOOK_AHEAD 0xaa | |
98 | ||
99 | // 48-bit commands | |
100 | #define ATA_READ_LOG_EXT 0x2F | |
101 | ||
102 | // ATA Specification Feature Register Values (SMART Subcommands). | |
103 | // Note that some are obsolete as of ATA-7. | |
104 | #define ATA_SMART_READ_VALUES 0xd0 | |
105 | #define ATA_SMART_READ_THRESHOLDS 0xd1 | |
106 | #define ATA_SMART_AUTOSAVE 0xd2 | |
107 | #define ATA_SMART_SAVE 0xd3 | |
108 | #define ATA_SMART_IMMEDIATE_OFFLINE 0xd4 | |
109 | #define ATA_SMART_READ_LOG_SECTOR 0xd5 | |
110 | #define ATA_SMART_WRITE_LOG_SECTOR 0xd6 | |
111 | #define ATA_SMART_WRITE_THRESHOLDS 0xd7 | |
112 | #define ATA_SMART_ENABLE 0xd8 | |
113 | #define ATA_SMART_DISABLE 0xd9 | |
114 | #define ATA_SMART_STATUS 0xda | |
115 | // SFF 8035i Revision 2 Specification Feature Register Value (SMART | |
116 | // Subcommand) | |
117 | #define ATA_SMART_AUTO_OFFLINE 0xdb | |
118 | ||
119 | // Sector Number values for ATA_SMART_IMMEDIATE_OFFLINE Subcommand | |
120 | #define OFFLINE_FULL_SCAN 0 | |
121 | #define SHORT_SELF_TEST 1 | |
122 | #define EXTEND_SELF_TEST 2 | |
123 | #define CONVEYANCE_SELF_TEST 3 | |
124 | #define SELECTIVE_SELF_TEST 4 | |
125 | #define ABORT_SELF_TEST 127 | |
126 | #define SHORT_CAPTIVE_SELF_TEST 129 | |
127 | #define EXTEND_CAPTIVE_SELF_TEST 130 | |
128 | #define CONVEYANCE_CAPTIVE_SELF_TEST 131 | |
129 | #define SELECTIVE_CAPTIVE_SELF_TEST 132 | |
130 | #define CAPTIVE_MASK (0x01<<7) | |
131 | ||
132 | // Maximum allowed number of SMART Attributes | |
133 | #define NUMBER_ATA_SMART_ATTRIBUTES 30 | |
134 | ||
135 | // Needed parts of the ATA DRIVE IDENTIFY Structure. Those labeled | |
136 | // word* are NOT used. | |
137 | #pragma pack(1) | |
138 | struct ata_identify_device { | |
139 | unsigned short words000_009[10]; | |
140 | unsigned char serial_no[20]; | |
141 | unsigned short words020_022[3]; | |
142 | unsigned char fw_rev[8]; | |
143 | unsigned char model[40]; | |
144 | unsigned short words047_079[33]; | |
145 | unsigned short major_rev_num; | |
146 | unsigned short minor_rev_num; | |
147 | unsigned short command_set_1; | |
148 | unsigned short command_set_2; | |
149 | unsigned short command_set_extension; | |
150 | unsigned short cfs_enable_1; | |
151 | unsigned short word086; | |
152 | unsigned short csf_default; | |
153 | unsigned short words088_255[168]; | |
154 | } ATTR_PACKED; | |
155 | #pragma pack() | |
156 | ASSERT_SIZEOF_STRUCT(ata_identify_device, 512); | |
157 | ||
158 | /* ata_smart_attribute is the vendor specific in SFF-8035 spec */ | |
159 | #pragma pack(1) | |
160 | struct ata_smart_attribute { | |
161 | unsigned char id; | |
162 | // meaning of flag bits: see MACROS just below | |
163 | // WARNING: MISALIGNED! | |
164 | unsigned short flags; | |
165 | unsigned char current; | |
166 | unsigned char worst; | |
167 | unsigned char raw[6]; | |
168 | unsigned char reserv; | |
169 | } ATTR_PACKED; | |
170 | #pragma pack() | |
171 | ASSERT_SIZEOF_STRUCT(ata_smart_attribute, 12); | |
172 | ||
173 | // MACROS to interpret the flags bits in the previous structure. | |
174 | // These have not been implemented using bitflags and a union, to make | |
175 | // it portable across bit/little endian and different platforms. | |
176 | ||
177 | // 0: Prefailure bit | |
178 | ||
179 | // From SFF 8035i Revision 2 page 19: Bit 0 (pre-failure/advisory bit) | |
180 | // - If the value of this bit equals zero, an attribute value less | |
181 | // than or equal to its corresponding attribute threshold indicates an | |
182 | // advisory condition where the usage or age of the device has | |
183 | // exceeded its intended design life period. If the value of this bit | |
184 | // equals one, an attribute value less than or equal to its | |
185 | // corresponding attribute threshold indicates a prefailure condition | |
186 | // where imminent loss of data is being predicted. | |
187 | #define ATTRIBUTE_FLAGS_PREFAILURE(x) (x & 0x01) | |
188 | ||
189 | // 1: Online bit | |
190 | ||
191 | // From SFF 8035i Revision 2 page 19: Bit 1 (on-line data collection | |
192 | // bit) - If the value of this bit equals zero, then the attribute | |
193 | // value is updated only during off-line data collection | |
194 | // activities. If the value of this bit equals one, then the attribute | |
195 | // value is updated during normal operation of the device or during | |
196 | // both normal operation and off-line testing. | |
197 | #define ATTRIBUTE_FLAGS_ONLINE(x) (x & 0x02) | |
198 | ||
199 | ||
200 | // The following are (probably) IBM's, Maxtors and Quantum's definitions for the | |
201 | // vendor-specific bits: | |
202 | // 2: Performance type bit | |
203 | #define ATTRIBUTE_FLAGS_PERFORMANCE(x) (x & 0x04) | |
204 | ||
205 | // 3: Errorrate type bit | |
206 | #define ATTRIBUTE_FLAGS_ERRORRATE(x) (x & 0x08) | |
207 | ||
208 | // 4: Eventcount bit | |
209 | #define ATTRIBUTE_FLAGS_EVENTCOUNT(x) (x & 0x10) | |
210 | ||
211 | // 5: Selfpereserving bit | |
212 | #define ATTRIBUTE_FLAGS_SELFPRESERVING(x) (x & 0x20) | |
213 | ||
214 | // 6-15: Reserved for future use | |
215 | #define ATTRIBUTE_FLAGS_OTHER(x) ((x) & 0xffc0) | |
216 | ||
217 | ||
218 | // Format of data returned by SMART READ DATA | |
219 | // Table 62 of T13/1699-D (ATA8-ACS) Revision 6a, September 2008 | |
220 | #pragma pack(1) | |
221 | struct ata_smart_values { | |
222 | unsigned short int revnumber; | |
223 | struct ata_smart_attribute vendor_attributes [NUMBER_ATA_SMART_ATTRIBUTES]; | |
224 | unsigned char offline_data_collection_status; | |
225 | unsigned char self_test_exec_status; //IBM # segments for offline collection | |
226 | unsigned short int total_time_to_complete_off_line; // IBM different | |
227 | unsigned char vendor_specific_366; // Maxtor & IBM curent segment pointer | |
228 | unsigned char offline_data_collection_capability; | |
229 | unsigned short int smart_capability; | |
230 | unsigned char errorlog_capability; | |
231 | unsigned char vendor_specific_371; // Maxtor, IBM: self-test failure checkpoint see below! | |
232 | unsigned char short_test_completion_time; | |
233 | unsigned char extend_test_completion_time_b; // If 0xff, use 16-bit value below | |
234 | unsigned char conveyance_test_completion_time; | |
235 | unsigned short extend_test_completion_time_w; // e04130r2, added to T13/1699-D Revision 1c, April 2005 | |
236 | unsigned char reserved_377_385[9]; | |
237 | unsigned char vendor_specific_386_510[125]; // Maxtor bytes 508-509 Attribute/Threshold Revision # | |
238 | unsigned char chksum; | |
239 | } ATTR_PACKED; | |
240 | #pragma pack() | |
241 | ASSERT_SIZEOF_STRUCT(ata_smart_values, 512); | |
242 | ||
243 | /* Maxtor, IBM: self-test failure checkpoint byte meaning: | |
244 | 00 - write test | |
245 | 01 - servo basic | |
246 | 02 - servo random | |
247 | 03 - G-list scan | |
248 | 04 - Handling damage | |
249 | 05 - Read scan | |
250 | */ | |
251 | ||
252 | /* Vendor attribute of SMART Threshold (compare to ata_smart_attribute above) */ | |
253 | #pragma pack(1) | |
254 | struct ata_smart_threshold_entry { | |
255 | unsigned char id; | |
256 | unsigned char threshold; | |
257 | unsigned char reserved[10]; | |
258 | } ATTR_PACKED; | |
259 | #pragma pack() | |
260 | ASSERT_SIZEOF_STRUCT(ata_smart_threshold_entry, 12); | |
261 | ||
262 | /* Format of Read SMART THreshold Command */ | |
263 | /* Compare to ata_smart_values above */ | |
264 | #pragma pack(1) | |
265 | struct ata_smart_thresholds_pvt { | |
266 | unsigned short int revnumber; | |
267 | struct ata_smart_threshold_entry thres_entries[NUMBER_ATA_SMART_ATTRIBUTES]; | |
268 | unsigned char reserved[149]; | |
269 | unsigned char chksum; | |
270 | } ATTR_PACKED; | |
271 | #pragma pack() | |
272 | ASSERT_SIZEOF_STRUCT(ata_smart_thresholds_pvt, 512); | |
273 | ||
274 | ||
275 | // Table 42 of T13/1321D Rev 1 spec (Error Data Structure) | |
276 | #pragma pack(1) | |
277 | struct ata_smart_errorlog_error_struct { | |
278 | unsigned char reserved; | |
279 | unsigned char error_register; | |
280 | unsigned char sector_count; | |
281 | unsigned char sector_number; | |
282 | unsigned char cylinder_low; | |
283 | unsigned char cylinder_high; | |
284 | unsigned char drive_head; | |
285 | unsigned char status; | |
286 | unsigned char extended_error[19]; | |
287 | unsigned char state; | |
288 | unsigned short timestamp; | |
289 | } ATTR_PACKED; | |
290 | #pragma pack() | |
291 | ASSERT_SIZEOF_STRUCT(ata_smart_errorlog_error_struct, 30); | |
292 | ||
293 | ||
294 | // Table 41 of T13/1321D Rev 1 spec (Command Data Structure) | |
295 | #pragma pack(1) | |
296 | struct ata_smart_errorlog_command_struct { | |
297 | unsigned char devicecontrolreg; | |
298 | unsigned char featuresreg; | |
299 | unsigned char sector_count; | |
300 | unsigned char sector_number; | |
301 | unsigned char cylinder_low; | |
302 | unsigned char cylinder_high; | |
303 | unsigned char drive_head; | |
304 | unsigned char commandreg; | |
305 | unsigned int timestamp; | |
306 | } ATTR_PACKED; | |
307 | #pragma pack() | |
308 | ASSERT_SIZEOF_STRUCT(ata_smart_errorlog_command_struct, 12); | |
309 | ||
310 | // Table 40 of T13/1321D Rev 1 spec (Error log data structure) | |
311 | #pragma pack(1) | |
312 | struct ata_smart_errorlog_struct { | |
313 | struct ata_smart_errorlog_command_struct commands[5]; | |
314 | struct ata_smart_errorlog_error_struct error_struct; | |
315 | } ATTR_PACKED; | |
316 | #pragma pack() | |
317 | ASSERT_SIZEOF_STRUCT(ata_smart_errorlog_struct, 90); | |
318 | ||
319 | // Table 39 of T13/1321D Rev 1 spec (SMART error log sector) | |
320 | #pragma pack(1) | |
321 | struct ata_smart_errorlog { | |
322 | unsigned char revnumber; | |
323 | unsigned char error_log_pointer; | |
324 | struct ata_smart_errorlog_struct errorlog_struct[5]; | |
325 | unsigned short int ata_error_count; | |
326 | unsigned char reserved[57]; | |
327 | unsigned char checksum; | |
328 | } ATTR_PACKED; | |
329 | #pragma pack() | |
330 | ASSERT_SIZEOF_STRUCT(ata_smart_errorlog, 512); | |
331 | ||
332 | ||
333 | // Extended Comprehensive SMART Error Log data structures | |
334 | // See Section A.7 of | |
335 | // AT Attachment 8 - ATA/ATAPI Command Set (ATA8-ACS) | |
336 | // T13/1699-D Revision 6a (Working Draft), September 6, 2008. | |
337 | ||
338 | // Command data structure | |
339 | // Table A.9 of T13/1699-D Revision 6a | |
340 | #pragma pack(1) | |
341 | struct ata_smart_exterrlog_command | |
342 | { | |
343 | unsigned char device_control_register; | |
344 | unsigned char features_register; | |
345 | unsigned char features_register_hi; | |
346 | unsigned char count_register; | |
347 | unsigned char count_register_hi; | |
348 | unsigned char lba_low_register; | |
349 | unsigned char lba_low_register_hi; | |
350 | unsigned char lba_mid_register; | |
351 | unsigned char lba_mid_register_hi; | |
352 | unsigned char lba_high_register; | |
353 | unsigned char lba_high_register_hi; | |
354 | unsigned char device_register; | |
355 | unsigned char command_register; | |
356 | ||
357 | unsigned char reserved; | |
358 | unsigned int timestamp; | |
359 | } ATTR_PACKED; | |
360 | #pragma pack() | |
361 | ASSERT_SIZEOF_STRUCT(ata_smart_exterrlog_command, 18); | |
362 | ||
363 | // Error data structure | |
364 | // Table A.10 T13/1699-D Revision 6a | |
365 | #pragma pack(1) | |
366 | struct ata_smart_exterrlog_error | |
367 | { | |
368 | unsigned char device_control_register; | |
369 | unsigned char error_register; | |
370 | unsigned char count_register; | |
371 | unsigned char count_register_hi; | |
372 | unsigned char lba_low_register; | |
373 | unsigned char lba_low_register_hi; | |
374 | unsigned char lba_mid_register; | |
375 | unsigned char lba_mid_register_hi; | |
376 | unsigned char lba_high_register; | |
377 | unsigned char lba_high_register_hi; | |
378 | unsigned char device_register; | |
379 | unsigned char status_register; | |
380 | ||
381 | unsigned char extended_error[19]; | |
382 | unsigned char state; | |
383 | unsigned short timestamp; | |
384 | } ATTR_PACKED; | |
385 | #pragma pack() | |
386 | ASSERT_SIZEOF_STRUCT(ata_smart_exterrlog_error, 34); | |
387 | ||
388 | // Error log data structure | |
389 | // Table A.8 of T13/1699-D Revision 6a | |
390 | #pragma pack(1) | |
391 | struct ata_smart_exterrlog_error_log | |
392 | { | |
393 | ata_smart_exterrlog_command commands[5]; | |
394 | ata_smart_exterrlog_error error; | |
395 | } ATTR_PACKED; | |
396 | #pragma pack() | |
397 | ASSERT_SIZEOF_STRUCT(ata_smart_exterrlog_error_log, 124); | |
398 | ||
399 | // Ext. Comprehensive SMART error log | |
400 | // Table A.7 of T13/1699-D Revision 6a | |
401 | #pragma pack(1) | |
402 | struct ata_smart_exterrlog | |
403 | { | |
404 | unsigned char version; | |
405 | unsigned char reserved1; | |
406 | unsigned short error_log_index; | |
407 | ata_smart_exterrlog_error_log error_logs[4]; | |
408 | unsigned short device_error_count; | |
409 | unsigned char reserved2[9]; | |
410 | unsigned char checksum; | |
411 | } ATTR_PACKED; | |
412 | #pragma pack() | |
413 | ASSERT_SIZEOF_STRUCT(ata_smart_exterrlog, 512); | |
414 | ||
415 | ||
416 | // Table 45 of T13/1321D Rev 1 spec (Self-test log descriptor entry) | |
417 | #pragma pack(1) | |
418 | struct ata_smart_selftestlog_struct { | |
419 | unsigned char selftestnumber; // Sector number register | |
420 | unsigned char selfteststatus; | |
421 | unsigned short int timestamp; | |
422 | unsigned char selftestfailurecheckpoint; | |
423 | unsigned int lbafirstfailure; | |
424 | unsigned char vendorspecific[15]; | |
425 | } ATTR_PACKED; | |
426 | #pragma pack() | |
427 | ASSERT_SIZEOF_STRUCT(ata_smart_selftestlog_struct, 24); | |
428 | ||
429 | // Table 44 of T13/1321D Rev 1 spec (Self-test log data structure) | |
430 | #pragma pack(1) | |
431 | struct ata_smart_selftestlog { | |
432 | unsigned short int revnumber; | |
433 | struct ata_smart_selftestlog_struct selftest_struct[21]; | |
434 | unsigned char vendorspecific[2]; | |
435 | unsigned char mostrecenttest; | |
436 | unsigned char reserved[2]; | |
437 | unsigned char chksum; | |
438 | } ATTR_PACKED; | |
439 | #pragma pack() | |
440 | ASSERT_SIZEOF_STRUCT(ata_smart_selftestlog, 512); | |
441 | ||
442 | // Extended SMART Self-test log data structures | |
443 | // See Section A.8 of | |
444 | // AT Attachment 8 - ATA/ATAPI Command Set (ATA8-ACS) | |
445 | // T13/1699-D Revision 6a (Working Draft), September 6, 2008. | |
446 | ||
447 | // Extended Self-test log descriptor entry | |
448 | // Table A.13 of T13/1699-D Revision 6a | |
449 | #pragma pack(1) | |
450 | struct ata_smart_extselftestlog_desc | |
451 | { | |
452 | unsigned char self_test_type; | |
453 | unsigned char self_test_status; | |
454 | unsigned short timestamp; | |
455 | unsigned char checkpoint; | |
456 | unsigned char failing_lba[6]; | |
457 | unsigned char vendorspecific[15]; | |
458 | } ATTR_PACKED; | |
459 | #pragma pack() | |
460 | ASSERT_SIZEOF_STRUCT(ata_smart_extselftestlog_desc, 26); | |
461 | ||
462 | // Extended Self-test log data structure | |
463 | // Table A.12 of T13/1699-D Revision 6a | |
464 | #pragma pack(1) | |
465 | struct ata_smart_extselftestlog | |
466 | { | |
467 | unsigned char version; | |
468 | unsigned char reserved1; | |
469 | unsigned short log_desc_index; | |
470 | struct ata_smart_extselftestlog_desc log_descs[19]; | |
471 | unsigned char vendor_specifc[2]; | |
472 | unsigned char reserved2[11]; | |
473 | unsigned char chksum; | |
474 | } ATTR_PACKED; | |
475 | #pragma pack() | |
476 | ASSERT_SIZEOF_STRUCT(ata_smart_extselftestlog, 512); | |
477 | ||
478 | // SMART LOG DIRECTORY Table 52 of T13/1532D Vol 1 Rev 1a | |
479 | #pragma pack(1) | |
480 | struct ata_smart_log_entry { | |
481 | unsigned char numsectors; | |
482 | unsigned char reserved; | |
483 | } ATTR_PACKED; | |
484 | #pragma pack() | |
485 | ASSERT_SIZEOF_STRUCT(ata_smart_log_entry, 2); | |
486 | ||
487 | #pragma pack(1) | |
488 | struct ata_smart_log_directory { | |
489 | unsigned short int logversion; | |
490 | struct ata_smart_log_entry entry[255]; | |
491 | } ATTR_PACKED; | |
492 | #pragma pack() | |
493 | ASSERT_SIZEOF_STRUCT(ata_smart_log_directory, 512); | |
494 | ||
495 | // SMART SELECTIVE SELF-TEST LOG Table 61 of T13/1532D Volume 1 | |
496 | // Revision 3 | |
497 | #pragma pack(1) | |
498 | struct test_span { | |
499 | uint64_t start; | |
500 | uint64_t end; | |
501 | } ATTR_PACKED; | |
502 | #pragma pack() | |
503 | ASSERT_SIZEOF_STRUCT(test_span, 16); | |
504 | ||
505 | #pragma pack(1) | |
506 | struct ata_selective_self_test_log { | |
507 | unsigned short logversion; | |
508 | struct test_span span[5]; | |
509 | unsigned char reserved1[337-82+1]; | |
510 | unsigned char vendor_specific1[491-338+1]; | |
511 | uint64_t currentlba; | |
512 | unsigned short currentspan; | |
513 | unsigned short flags; | |
514 | unsigned char vendor_specific2[507-504+1]; | |
515 | unsigned short pendingtime; | |
516 | unsigned char reserved2; | |
517 | unsigned char checksum; | |
518 | } ATTR_PACKED; | |
519 | #pragma pack() | |
520 | ASSERT_SIZEOF_STRUCT(ata_selective_self_test_log, 512); | |
521 | ||
522 | #define SELECTIVE_FLAG_DOSCAN (0x0002) | |
523 | #define SELECTIVE_FLAG_PENDING (0x0008) | |
524 | #define SELECTIVE_FLAG_ACTIVE (0x0010) | |
525 | ||
526 | ||
527 | // SCT (SMART Command Transport) data structures | |
528 | // See Sections 8.2 and 8.3 of: | |
529 | // AT Attachment 8 - ATA/ATAPI Command Set (ATA8-ACS) | |
530 | // T13/1699-D Revision 3f (Working Draft), December 11, 2006. | |
531 | ||
532 | // SCT Status response (read with SMART_READ_LOG page 0xe0) | |
533 | // Table 60 of T13/1699-D Revision 3f | |
534 | #pragma pack(1) | |
535 | struct ata_sct_status_response | |
536 | { | |
537 | unsigned short format_version; // 0-1: Status response format version number (2, 3) | |
538 | unsigned short sct_version; // 2-3: Vendor specific version number | |
539 | unsigned short sct_spec; // 4-5: SCT level supported (1) | |
540 | unsigned int status_flags; // 6-9: Status flags (Bit 0: Segment initialized, Bits 1-31: reserved) | |
541 | unsigned char device_state; // 10: Device State (0-5) | |
542 | unsigned char bytes011_013[3]; // 11-13: reserved | |
543 | unsigned short ext_status_code; // 14-15: Status of last SCT command (0xffff if executing) | |
544 | unsigned short action_code; // 16-17: Action code of last SCT command | |
545 | unsigned short function_code; // 18-19: Function code of last SCT command | |
546 | unsigned char bytes020_039[20]; // 20-39: reserved | |
547 | uint64_t lba_current; // 40-47: LBA of SCT command executing in background | |
548 | unsigned char bytes048_199[152]; // 48-199: reserved | |
549 | signed char hda_temp; // 200: Current temperature in Celsius (0x80 = invalid) | |
550 | signed char min_temp; // 201: Minimum temperature this power cycle | |
551 | signed char max_temp; // 202: Maximum temperature this power cycle | |
552 | signed char life_min_temp; // 203: Minimum lifetime temperature | |
553 | signed char life_max_temp; // 204: Maximum lifetime temperature | |
554 | unsigned char byte205; // 205: reserved (T13/e06152r0-2: Average lifetime temperature) | |
555 | unsigned int over_limit_count; // 206-209: # intervals since last reset with temperature > Max Op Limit | |
556 | unsigned int under_limit_count; // 210-213: # intervals since last reset with temperature < Min Op Limit | |
557 | unsigned char bytes214_479[266]; // 214-479: reserved | |
558 | unsigned char vendor_specific[32];// 480-511: vendor specific | |
559 | } ATTR_PACKED; | |
560 | #pragma pack() | |
561 | ASSERT_SIZEOF_STRUCT(ata_sct_status_response, 512); | |
562 | ||
563 | // SCT Error Recovery Control command (send with SMART_WRITE_LOG page 0xe0) | |
564 | // Table 88 of T13/1699-D Revision 6a | |
565 | #pragma pack(1) | |
566 | struct ata_sct_error_recovery_control_command | |
567 | { | |
568 | unsigned short action_code; // 3 = Error Recovery Control | |
569 | unsigned short function_code; // 1 = Set, 2 = Return | |
570 | unsigned short selection_code; // 1 = Read Timer, 2 = Write Timer | |
571 | unsigned short time_limit; // If set: Recovery time limit in 100ms units | |
572 | unsigned short words004_255[252]; // reserved | |
573 | } ATTR_PACKED; | |
574 | #pragma pack() | |
575 | ASSERT_SIZEOF_STRUCT(ata_sct_error_recovery_control_command, 512); | |
576 | ||
577 | // SCT Feature Control command (send with SMART_WRITE_LOG page 0xe0) | |
578 | // Table 72 of T13/1699-D Revision 3f | |
579 | #pragma pack(1) | |
580 | struct ata_sct_feature_control_command | |
581 | { | |
582 | unsigned short action_code; // 4 = Feature Control | |
583 | unsigned short function_code; // 1 = Set, 2 = Return, 3 = Return options | |
584 | unsigned short feature_code; // 3 = Temperature logging interval | |
585 | unsigned short state; // Interval | |
586 | unsigned short option_flags; // Bit 0: persistent, Bits 1-15: reserved | |
587 | unsigned short words005_255[251]; // reserved | |
588 | } ATTR_PACKED; | |
589 | #pragma pack() | |
590 | ASSERT_SIZEOF_STRUCT(ata_sct_feature_control_command, 512); | |
591 | ||
592 | // SCT Data Table command (send with SMART_WRITE_LOG page 0xe0) | |
593 | // Table 73 of T13/1699-D Revision 3f | |
594 | #pragma pack(1) | |
595 | struct ata_sct_data_table_command | |
596 | { | |
597 | unsigned short action_code; // 5 = Data Table | |
598 | unsigned short function_code; // 1 = Read Table | |
599 | unsigned short table_id; // 2 = Temperature History | |
600 | unsigned short words003_255[253]; // reserved | |
601 | } ATTR_PACKED; | |
602 | #pragma pack() | |
603 | ASSERT_SIZEOF_STRUCT(ata_sct_data_table_command, 512); | |
604 | ||
605 | // SCT Temperature History Table (read with SMART_READ_LOG page 0xe1) | |
606 | // Table 75 of T13/1699-D Revision 3f | |
607 | #pragma pack(1) | |
608 | struct ata_sct_temperature_history_table | |
609 | { | |
610 | unsigned short format_version; // 0-1: Data table format version number (2) | |
611 | unsigned short sampling_period; // 2-3: Temperature sampling period in minutes | |
612 | unsigned short interval; // 4-5: Timer interval between history entries | |
613 | signed char max_op_limit; // 6: Maximum recommended continuous operating temperature | |
614 | signed char over_limit; // 7: Maximum temperature limit | |
615 | signed char min_op_limit; // 8: Minimum recommended continuous operating limit | |
616 | signed char under_limit; // 9: Minimum temperature limit | |
617 | unsigned char bytes010_029[20]; // 10-29: reserved | |
618 | unsigned short cb_size; // 30-31: Number of history entries (range 128-478) | |
619 | unsigned short cb_index; // 32-33: Index of last updated entry (zero-based) | |
620 | signed char cb[478]; // 34-(34+cb_size-1): Circular buffer of temperature values | |
621 | } ATTR_PACKED; | |
622 | #pragma pack() | |
623 | ASSERT_SIZEOF_STRUCT(ata_sct_temperature_history_table, 512); | |
624 | ||
625 | // Possible values for span_args.mode | |
626 | enum { | |
627 | SEL_RANGE, // MIN-MAX | |
628 | SEL_REDO, // redo this | |
629 | SEL_NEXT, // do next range | |
630 | SEL_CONT // redo or next depending of last test status | |
631 | }; | |
632 | ||
633 | // Arguments for selective self-test | |
634 | struct ata_selective_selftest_args | |
635 | { | |
636 | // Arguments for each span | |
637 | struct span_args | |
638 | { | |
639 | uint64_t start; // First block | |
640 | uint64_t end; // Last block | |
641 | int mode; // SEL_*, see above | |
642 | ||
643 | span_args() | |
644 | : start(0), end(0), mode(SEL_RANGE) { } | |
645 | }; | |
646 | ||
647 | span_args span[5]; // Range and mode for 5 spans | |
648 | int num_spans; // Number of spans | |
649 | int pending_time; // One plus time in minutes to wait after powerup before restarting | |
650 | // interrupted offline scan after selective self-test. | |
651 | int scan_after_select; // Run offline scan after selective self-test: | |
652 | // 0: don't change, | |
653 | // 1: turn off scan after selective self-test, | |
654 | // 2: turn on scan after selective self-test. | |
655 | ||
656 | ata_selective_selftest_args() | |
657 | : num_spans(0), pending_time(0), scan_after_select(0) { } | |
658 | }; | |
659 | ||
660 | // Priority for vendor attribute defs | |
661 | enum ata_vendor_def_prior | |
662 | { | |
663 | PRIOR_DEFAULT, | |
664 | PRIOR_DATABASE, | |
665 | PRIOR_USER | |
666 | }; | |
667 | ||
668 | // Raw attribute value print formats | |
669 | enum ata_attr_raw_format | |
670 | { | |
671 | RAWFMT_DEFAULT, | |
672 | RAWFMT_RAW8, | |
673 | RAWFMT_RAW16, | |
674 | RAWFMT_RAW48, | |
675 | RAWFMT_HEX48, | |
676 | RAWFMT_RAW56, | |
677 | RAWFMT_HEX56, | |
678 | RAWFMT_RAW64, | |
679 | RAWFMT_HEX64, | |
680 | RAWFMT_RAW16_OPT_RAW16, | |
681 | RAWFMT_RAW16_OPT_AVG16, | |
682 | RAWFMT_RAW24_OPT_RAW8, | |
683 | RAWFMT_RAW24_DIV_RAW24, | |
684 | RAWFMT_RAW24_DIV_RAW32, | |
685 | RAWFMT_SEC2HOUR, | |
686 | RAWFMT_MIN2HOUR, | |
687 | RAWFMT_HALFMIN2HOUR, | |
688 | RAWFMT_MSEC24_HOUR32, | |
689 | RAWFMT_TEMPMINMAX, | |
690 | RAWFMT_TEMP10X, | |
691 | }; | |
692 | ||
693 | // Attribute flags | |
694 | enum { | |
695 | ATTRFLAG_INCREASING = 0x01, // Value not reset (for reallocated/pending counts) | |
696 | ATTRFLAG_NO_NORMVAL = 0x02, // Normalized value not valid | |
697 | ATTRFLAG_NO_WORSTVAL = 0x04 // Worst value not valid | |
698 | }; | |
699 | ||
700 | // Vendor attribute display defs for all attribute ids | |
701 | class ata_vendor_attr_defs | |
702 | { | |
703 | public: | |
704 | struct entry | |
705 | { | |
706 | std::string name; // Attribute name, empty for default | |
707 | ata_attr_raw_format raw_format; // Raw value print format | |
708 | ata_vendor_def_prior priority; // Setting priority | |
709 | unsigned flags; // ATTRFLAG_* | |
710 | char byteorder[8+1]; // String [012345rvwz] to define byte order | |
711 | ||
712 | entry() | |
713 | : raw_format(RAWFMT_DEFAULT), | |
714 | priority(PRIOR_DEFAULT), | |
715 | flags(0) | |
716 | { byteorder[0] = 0; } | |
717 | }; | |
718 | ||
719 | entry & operator[](unsigned char id) | |
720 | { return m_defs[id]; } | |
721 | ||
722 | const entry & operator[](unsigned char id) const | |
723 | { return m_defs[id]; } | |
724 | ||
725 | private: | |
726 | entry m_defs[256]; | |
727 | }; | |
728 | ||
729 | ||
730 | // Print ATA debug messages? | |
731 | extern unsigned char ata_debugmode; | |
732 | ||
733 | // Suppress serial number? | |
734 | extern bool dont_print_serial_number; | |
735 | ||
736 | // Get information from drive | |
737 | int ata_read_identity(ata_device * device, ata_identify_device * buf, bool fix_swapped_id); | |
738 | int ataCheckPowerMode(ata_device * device); | |
739 | ||
740 | // Issue a no-data ATA command with optional sector count register value | |
741 | bool ata_nodata_command(ata_device * device, unsigned char command, int sector_count = -1); | |
742 | ||
743 | // Issue SET FEATURES command with optional sector count register value | |
744 | bool ata_set_features(ata_device * device, unsigned char features, int sector_count = -1); | |
745 | ||
746 | /* Read S.M.A.R.T information from drive */ | |
747 | int ataReadSmartValues(ata_device * device,struct ata_smart_values *); | |
748 | int ataReadSmartThresholds(ata_device * device, struct ata_smart_thresholds_pvt *); | |
749 | int ataReadErrorLog (ata_device * device, ata_smart_errorlog *data, | |
750 | unsigned char fix_firmwarebug); | |
751 | int ataReadSelfTestLog(ata_device * device, ata_smart_selftestlog * data, | |
752 | unsigned char fix_firmwarebug); | |
753 | int ataReadSelectiveSelfTestLog(ata_device * device, struct ata_selective_self_test_log *data); | |
754 | int ataSetSmartThresholds(ata_device * device, struct ata_smart_thresholds_pvt *); | |
755 | int ataReadLogDirectory(ata_device * device, ata_smart_log_directory *, bool gpl); | |
756 | ||
757 | // Read GP Log page(s) | |
758 | bool ataReadLogExt(ata_device * device, unsigned char logaddr, | |
759 | unsigned char features, unsigned page, | |
760 | void * data, unsigned nsectors); | |
761 | // Read SMART Log page(s) | |
762 | bool ataReadSmartLog(ata_device * device, unsigned char logaddr, | |
763 | void * data, unsigned nsectors); | |
764 | // Read SMART Extended Comprehensive Error Log | |
765 | bool ataReadExtErrorLog(ata_device * device, ata_smart_exterrlog * log, | |
766 | unsigned nsectors); | |
767 | // Read SMART Extended Self-test Log | |
768 | bool ataReadExtSelfTestLog(ata_device * device, ata_smart_extselftestlog * log, | |
769 | unsigned nsectors); | |
770 | ||
771 | // Read SCT information | |
772 | int ataReadSCTStatus(ata_device * device, ata_sct_status_response * sts); | |
773 | int ataReadSCTTempHist(ata_device * device, ata_sct_temperature_history_table * tmh, | |
774 | ata_sct_status_response * sts); | |
775 | // Set SCT temperature logging interval | |
776 | int ataSetSCTTempInterval(ata_device * device, unsigned interval, bool persistent); | |
777 | ||
778 | // Get/Set SCT Error Recovery Control | |
779 | int ataGetSCTErrorRecoveryControltime(ata_device * device, unsigned type, unsigned short & time_limit); | |
780 | int ataSetSCTErrorRecoveryControltime(ata_device * device, unsigned type, unsigned short time_limit); | |
781 | ||
782 | ||
783 | /* Enable/Disable SMART on device */ | |
784 | int ataEnableSmart (ata_device * device); | |
785 | int ataDisableSmart (ata_device * device); | |
786 | int ataEnableAutoSave(ata_device * device); | |
787 | int ataDisableAutoSave(ata_device * device); | |
788 | ||
789 | /* Automatic Offline Testing */ | |
790 | int ataEnableAutoOffline (ata_device * device); | |
791 | int ataDisableAutoOffline (ata_device * device); | |
792 | ||
793 | /* S.M.A.R.T. test commands */ | |
794 | int ataSmartTest(ata_device * device, int testtype, bool force, | |
795 | const ata_selective_selftest_args & args, | |
796 | const ata_smart_values * sv, uint64_t num_sectors); | |
797 | ||
798 | int ataWriteSelectiveSelfTestLog(ata_device * device, ata_selective_selftest_args & args, | |
799 | const ata_smart_values * sv, uint64_t num_sectors, | |
800 | const ata_selective_selftest_args * prev_spans = 0); | |
801 | ||
802 | // Returns the latest compatibility of ATA/ATAPI Version the device | |
803 | // supports. Returns -1 if Version command is not supported | |
804 | int ataVersionInfo(const char ** description, const ata_identify_device * drive, unsigned short * minor); | |
805 | ||
806 | // Get World Wide Name (WWN) fields. | |
807 | // Return NAA field or -1 if WWN is unsupported. | |
808 | int ata_get_wwn(const ata_identify_device * id, unsigned & oui, uint64_t & unique_id); | |
809 | ||
810 | // If SMART supported, this is guaranteed to return 1 if SMART is enabled, else 0. | |
811 | int ataDoesSmartWork(ata_device * device); | |
812 | ||
813 | // returns 1 if SMART supported, 0 if not supported or can't tell | |
814 | int ataSmartSupport(const ata_identify_device * drive); | |
815 | ||
816 | // Return values: | |
817 | // 1: SMART enabled | |
818 | // 0: SMART disabled | |
819 | // -1: can't tell if SMART is enabled -- try issuing ataDoesSmartWork command to see | |
820 | int ataIsSmartEnabled(const ata_identify_device * drive); | |
821 | ||
822 | int ataSmartStatus2(ata_device * device); | |
823 | ||
824 | int isSmartErrorLogCapable(const ata_smart_values * data, const ata_identify_device * identity); | |
825 | ||
826 | int isSmartTestLogCapable(const ata_smart_values * data, const ata_identify_device * identity); | |
827 | ||
828 | int isGeneralPurposeLoggingCapable(const ata_identify_device * identity); | |
829 | ||
830 | int isSupportExecuteOfflineImmediate(const ata_smart_values * data); | |
831 | ||
832 | int isSupportAutomaticTimer(const ata_smart_values * data); | |
833 | ||
834 | int isSupportOfflineAbort(const ata_smart_values * data); | |
835 | ||
836 | int isSupportOfflineSurfaceScan(const ata_smart_values * data); | |
837 | ||
838 | int isSupportSelfTest(const ata_smart_values * data); | |
839 | ||
840 | int isSupportConveyanceSelfTest(const ata_smart_values * data); | |
841 | ||
842 | int isSupportSelectiveSelfTest(const ata_smart_values * data); | |
843 | ||
844 | inline bool isSCTCapable(const ata_identify_device *drive) | |
845 | { return !!(drive->words088_255[206-88] & 0x01); } // 0x01 = SCT support | |
846 | ||
847 | inline bool isSCTErrorRecoveryControlCapable(const ata_identify_device *drive) | |
848 | { return ((drive->words088_255[206-88] & 0x09) == 0x09); } // 0x08 = SCT Error Recovery Control support | |
849 | ||
850 | inline bool isSCTFeatureControlCapable(const ata_identify_device *drive) | |
851 | { return ((drive->words088_255[206-88] & 0x11) == 0x11); } // 0x10 = SCT Feature Control support | |
852 | ||
853 | inline bool isSCTDataTableCapable(const ata_identify_device *drive) | |
854 | { return ((drive->words088_255[206-88] & 0x21) == 0x21); } // 0x20 = SCT Data Table support | |
855 | ||
856 | int TestTime(const ata_smart_values * data, int testtype); | |
857 | ||
858 | // Attribute state | |
859 | enum ata_attr_state | |
860 | { | |
861 | ATTRSTATE_NON_EXISTING, // No such Attribute | |
862 | ATTRSTATE_NO_NORMVAL, // Normalized value not valid | |
863 | ATTRSTATE_NO_THRESHOLD, // Unknown or no threshold | |
864 | ATTRSTATE_OK, // Never failed | |
865 | ATTRSTATE_FAILED_PAST, // Failed in the past | |
866 | ATTRSTATE_FAILED_NOW // Failed now | |
867 | }; | |
868 | ||
869 | // Get attribute state | |
870 | ata_attr_state ata_get_attr_state(const ata_smart_attribute & attr, | |
871 | int attridx, | |
872 | const ata_smart_threshold_entry * thresholds, | |
873 | const ata_vendor_attr_defs & defs, | |
874 | unsigned char * threshval = 0); | |
875 | ||
876 | // Get attribute raw value. | |
877 | uint64_t ata_get_attr_raw_value(const ata_smart_attribute & attr, | |
878 | const ata_vendor_attr_defs & defs); | |
879 | ||
880 | // Format attribute raw value. | |
881 | std::string ata_format_attr_raw_value(const ata_smart_attribute & attr, | |
882 | const ata_vendor_attr_defs & defs); | |
883 | ||
884 | // Get attribute name | |
885 | std::string ata_get_smart_attr_name(unsigned char id, | |
886 | const ata_vendor_attr_defs & defs); | |
887 | ||
888 | // External handler function, for when a checksum is not correct. Can | |
889 | // simply return if no action is desired, or can print error messages | |
890 | // as needed, or exit. Is passed a string with the name of the Data | |
891 | // Structure with the incorrect checksum. | |
892 | void checksumwarning(const char *string); | |
893 | ||
894 | // Find attribute index for attribute id, -1 if not found. | |
895 | int ata_find_attr_index(unsigned char id, const ata_smart_values & smartval); | |
896 | ||
897 | // Return Temperature Attribute raw value selected according to possible | |
898 | // non-default interpretations. If the Attribute does not exist, return 0 | |
899 | unsigned char ata_return_temperature_value(const ata_smart_values * data, const ata_vendor_attr_defs & defs); | |
900 | ||
901 | ||
902 | // This are the meanings of the Self-test failure checkpoint byte. | |
903 | // This is in the self-test log at offset 4 bytes into the self-test | |
904 | // descriptor and in the SMART READ DATA structure at byte offset | |
905 | // 371. These codes are not well documented. The meanings returned by | |
906 | // this routine are used (at least) by Maxtor and IBM. Returns NULL if | |
907 | // not recognized. | |
908 | const char *SelfTestFailureCodeName(unsigned char which); | |
909 | ||
910 | ||
911 | #define MAX_ATTRIBUTE_NUM 256 | |
912 | ||
913 | // Parse vendor attribute display def (-v option). | |
914 | // Return false on error. | |
915 | bool parse_attribute_def(const char * opt, ata_vendor_attr_defs & defs, | |
916 | ata_vendor_def_prior priority); | |
917 | ||
918 | // Get ID and increase flag of current pending or offline | |
919 | // uncorrectable attribute. | |
920 | unsigned char get_unc_attr_id(bool offline, const ata_vendor_attr_defs & defs, | |
921 | bool & increase); | |
922 | ||
923 | // Return a multiline string containing a list of valid arguments for | |
924 | // parse_attribute_def(). | |
925 | std::string create_vendor_attribute_arg_list(); | |
926 | ||
927 | ||
928 | // These are two of the functions that are defined in os_*.c and need | |
929 | // to be ported to get smartmontools onto another OS. | |
930 | // Moved to C++ interface | |
931 | //int ata_command_interface(int device, smart_command_set command, int select, char *data); | |
932 | //int escalade_command_interface(int fd, int escalade_port, int escalade_type, smart_command_set command, int select, char *data); | |
933 | //int marvell_command_interface(int device, smart_command_set command, int select, char *data); | |
934 | //int highpoint_command_interface(int device, smart_command_set command, int select, char *data); | |
935 | //int areca_command_interface(int fd, int disknum, smart_command_set command, int select, char *data); | |
936 | ||
937 | ||
938 | // Optional functions of os_*.c | |
939 | #ifdef HAVE_ATA_IDENTIFY_IS_CACHED | |
940 | // Return true if OS caches the ATA identify sector | |
941 | //int ata_identify_is_cached(int fd); | |
942 | #endif | |
943 | ||
944 | // This function is exported to give low-level capability | |
945 | int smartcommandhandler(ata_device * device, smart_command_set command, int select, char *data); | |
946 | ||
947 | // Print one self-test log entry. | |
948 | // Returns: | |
949 | // -1: failed self-test | |
950 | // 1: extended self-test completed without error | |
951 | // 0: otherwise | |
952 | int ataPrintSmartSelfTestEntry(unsigned testnum, unsigned char test_type, | |
953 | unsigned char test_status, | |
954 | unsigned short timestamp, | |
955 | uint64_t failing_lba, | |
956 | bool print_error_only, bool & print_header); | |
957 | ||
958 | // Print Smart self-test log, used by smartctl and smartd. | |
959 | int ataPrintSmartSelfTestlog(const ata_smart_selftestlog * data, bool allentries, | |
960 | unsigned char fix_firmwarebug); | |
961 | ||
962 | // Get capacity and sector sizes from IDENTIFY data | |
963 | struct ata_size_info | |
964 | { | |
965 | uint64_t sectors; | |
966 | uint64_t capacity; | |
967 | unsigned log_sector_size; | |
968 | unsigned phy_sector_size; | |
969 | unsigned log_sector_offset; | |
970 | }; | |
971 | ||
972 | void ata_get_size_info(const ata_identify_device * id, ata_size_info & sizes); | |
973 | ||
974 | // Convenience function for formatting strings from ata_identify_device. | |
975 | void ata_format_id_string(char * out, const unsigned char * in, int n); | |
976 | ||
977 | // Utility routines. | |
978 | unsigned char checksum(const void * data); | |
979 | ||
980 | void swap2(char *location); | |
981 | void swap4(char *location); | |
982 | void swap8(char *location); | |
983 | // Typesafe variants using overloading | |
984 | inline void swapx(unsigned short * p) | |
985 | { swap2((char*)p); } | |
986 | inline void swapx(unsigned int * p) | |
987 | { swap4((char*)p); } | |
988 | inline void swapx(uint64_t * p) | |
989 | { swap8((char*)p); } | |
990 | ||
991 | // Return pseudo-device to parse "smartctl -r ataioctl,2 ..." output | |
992 | // and simulate an ATA device with same behaviour | |
993 | ata_device * get_parsed_ata_device(smart_interface * intf, const char * dev_name); | |
994 | ||
995 | #endif /* ATACMDS_H_ */ |