]> git.proxmox.com Git - mirror_smartmontools-debian.git/blob - atacmds.h
Merge branch 'cvs' into cvs-merge
[mirror_smartmontools-debian.git] / atacmds.h
1 /*
2 * atacmds.h
3 *
4 * Home page of code is: http://smartmontools.sourceforge.net
5 *
6 * Copyright (C) 2002-7 Bruce Allen <smartmontools-support@lists.sourceforge.net>
7 * Copyright (C) 1999-2000 Michael Cornwell <cornwell@acm.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
12 * any later version.
13 *
14 * You should have received a copy of the GNU General Public License
15 * (for example COPYING); if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *
18 * This code was originally developed as a Senior Thesis by Michael Cornwell
19 * at the Concurrent Systems Laboratory (now part of the Storage Systems
20 * Research Center), Jack Baskin School of Engineering, University of
21 * California, Santa Cruz. http://ssrc.soe.ucsc.edu/
22 *
23 */
24
25 #ifndef ATACMDS_H_
26 #define ATACMDS_H_
27
28 #define ATACMDS_H_CVSID "$Id: atacmds.h,v 1.89 2007/07/26 20:58:50 chrfranke Exp $\n"
29
30 // Macro to check expected size of struct at compile time using a
31 // dummy typedef. On size mismatch, compiler reports a negative array
32 // size. If you see an error message of this form, it means that the
33 // #pragma pack(1) pragma below is not having the desired effect on
34 // your compiler.
35 #define ASSERT_SIZEOF_STRUCT(s, n) \
36 typedef char assert_sizeof_struct_##s[(sizeof(struct s) == (n)) ? 1 : -1]
37
38 // Add __attribute__((packed)) if compiler supports it
39 // because some gcc versions (at least ARM) lack support of #pragma pack()
40 #ifdef HAVE_ATTR_PACKED
41 #define ATTR_PACKED __attribute__((packed))
42 #else
43 #define ATTR_PACKED
44 #endif
45
46 typedef enum {
47 // returns no data, just succeeds or fails
48 ENABLE,
49 DISABLE,
50 AUTOSAVE,
51 IMMEDIATE_OFFLINE,
52 AUTO_OFFLINE,
53 STATUS, // just says if SMART is working or not
54 STATUS_CHECK, // says if disk's SMART status is healthy, or failing
55 // return 512 bytes of data:
56 READ_VALUES,
57 READ_THRESHOLDS,
58 READ_LOG,
59 IDENTIFY,
60 PIDENTIFY,
61 // returns 1 byte of data
62 CHECK_POWER_MODE,
63 // writes 512 bytes of data:
64 WRITE_LOG
65 } smart_command_set;
66
67 // ATA Specification Command Register Values (Commands)
68 #define ATA_IDENTIFY_DEVICE 0xec
69 #define ATA_IDENTIFY_PACKET_DEVICE 0xa1
70 #define ATA_SMART_CMD 0xb0
71 #define ATA_CHECK_POWER_MODE 0xe5
72
73 // ATA Specification Feature Register Values (SMART Subcommands).
74 // Note that some are obsolete as of ATA-7.
75 #define ATA_SMART_READ_VALUES 0xd0
76 #define ATA_SMART_READ_THRESHOLDS 0xd1
77 #define ATA_SMART_AUTOSAVE 0xd2
78 #define ATA_SMART_SAVE 0xd3
79 #define ATA_SMART_IMMEDIATE_OFFLINE 0xd4
80 #define ATA_SMART_READ_LOG_SECTOR 0xd5
81 #define ATA_SMART_WRITE_LOG_SECTOR 0xd6
82 #define ATA_SMART_WRITE_THRESHOLDS 0xd7
83 #define ATA_SMART_ENABLE 0xd8
84 #define ATA_SMART_DISABLE 0xd9
85 #define ATA_SMART_STATUS 0xda
86 // SFF 8035i Revision 2 Specification Feature Register Value (SMART
87 // Subcommand)
88 #define ATA_SMART_AUTO_OFFLINE 0xdb
89
90 // Sector Number values for ATA_SMART_IMMEDIATE_OFFLINE Subcommand
91 #define OFFLINE_FULL_SCAN 0
92 #define SHORT_SELF_TEST 1
93 #define EXTEND_SELF_TEST 2
94 #define CONVEYANCE_SELF_TEST 3
95 #define SELECTIVE_SELF_TEST 4
96 #define ABORT_SELF_TEST 127
97 #define SHORT_CAPTIVE_SELF_TEST 129
98 #define EXTEND_CAPTIVE_SELF_TEST 130
99 #define CONVEYANCE_CAPTIVE_SELF_TEST 131
100 #define SELECTIVE_CAPTIVE_SELF_TEST 132
101 #define CAPTIVE_MASK (0x01<<7)
102
103 // Maximum allowed number of SMART Attributes
104 #define NUMBER_ATA_SMART_ATTRIBUTES 30
105
106 // Needed parts of the ATA DRIVE IDENTIFY Structure. Those labeled
107 // word* are NOT used.
108 #pragma pack(1)
109 struct ata_identify_device {
110 unsigned short words000_009[10];
111 unsigned char serial_no[20];
112 unsigned short words020_022[3];
113 unsigned char fw_rev[8];
114 unsigned char model[40];
115 unsigned short words047_079[33];
116 unsigned short major_rev_num;
117 unsigned short minor_rev_num;
118 unsigned short command_set_1;
119 unsigned short command_set_2;
120 unsigned short command_set_extension;
121 unsigned short cfs_enable_1;
122 unsigned short word086;
123 unsigned short csf_default;
124 unsigned short words088_255[168];
125 } ATTR_PACKED;
126 #pragma pack()
127 ASSERT_SIZEOF_STRUCT(ata_identify_device, 512);
128
129 /* ata_smart_attribute is the vendor specific in SFF-8035 spec */
130 #pragma pack(1)
131 struct ata_smart_attribute {
132 unsigned char id;
133 // meaning of flag bits: see MACROS just below
134 // WARNING: MISALIGNED!
135 unsigned short flags;
136 unsigned char current;
137 unsigned char worst;
138 unsigned char raw[6];
139 unsigned char reserv;
140 } ATTR_PACKED;
141 #pragma pack()
142 ASSERT_SIZEOF_STRUCT(ata_smart_attribute, 12);
143
144 // MACROS to interpret the flags bits in the previous structure.
145 // These have not been implemented using bitflags and a union, to make
146 // it portable across bit/little endian and different platforms.
147
148 // 0: Prefailure bit
149
150 // From SFF 8035i Revision 2 page 19: Bit 0 (pre-failure/advisory bit)
151 // - If the value of this bit equals zero, an attribute value less
152 // than or equal to its corresponding attribute threshold indicates an
153 // advisory condition where the usage or age of the device has
154 // exceeded its intended design life period. If the value of this bit
155 // equals one, an attribute value less than or equal to its
156 // corresponding attribute threshold indicates a prefailure condition
157 // where imminent loss of data is being predicted.
158 #define ATTRIBUTE_FLAGS_PREFAILURE(x) (x & 0x01)
159
160 // 1: Online bit
161
162 // From SFF 8035i Revision 2 page 19: Bit 1 (on-line data collection
163 // bit) - If the value of this bit equals zero, then the attribute
164 // value is updated only during off-line data collection
165 // activities. If the value of this bit equals one, then the attribute
166 // value is updated during normal operation of the device or during
167 // both normal operation and off-line testing.
168 #define ATTRIBUTE_FLAGS_ONLINE(x) (x & 0x02)
169
170
171 // The following are (probably) IBM's, Maxtors and Quantum's definitions for the
172 // vendor-specific bits:
173 // 2: Performance type bit
174 #define ATTRIBUTE_FLAGS_PERFORMANCE(x) (x & 0x04)
175
176 // 3: Errorrate type bit
177 #define ATTRIBUTE_FLAGS_ERRORRATE(x) (x & 0x08)
178
179 // 4: Eventcount bit
180 #define ATTRIBUTE_FLAGS_EVENTCOUNT(x) (x & 0x10)
181
182 // 5: Selfpereserving bit
183 #define ATTRIBUTE_FLAGS_SELFPRESERVING(x) (x & 0x20)
184
185
186 // Last ten bits are reserved for future use
187
188 /* ata_smart_values is format of the read drive Attribute command */
189 /* see Table 34 of T13/1321D Rev 1 spec (Device SMART data structure) for *some* info */
190 #pragma pack(1)
191 struct ata_smart_values {
192 unsigned short int revnumber;
193 struct ata_smart_attribute vendor_attributes [NUMBER_ATA_SMART_ATTRIBUTES];
194 unsigned char offline_data_collection_status;
195 unsigned char self_test_exec_status; //IBM # segments for offline collection
196 unsigned short int total_time_to_complete_off_line; // IBM different
197 unsigned char vendor_specific_366; // Maxtor & IBM curent segment pointer
198 unsigned char offline_data_collection_capability;
199 unsigned short int smart_capability;
200 unsigned char errorlog_capability;
201 unsigned char vendor_specific_371; // Maxtor, IBM: self-test failure checkpoint see below!
202 unsigned char short_test_completion_time;
203 unsigned char extend_test_completion_time;
204 unsigned char conveyance_test_completion_time;
205 unsigned char reserved_375_385[11];
206 unsigned char vendor_specific_386_510[125]; // Maxtor bytes 508-509 Attribute/Threshold Revision #
207 unsigned char chksum;
208 } ATTR_PACKED;
209 #pragma pack()
210 ASSERT_SIZEOF_STRUCT(ata_smart_values, 512);
211
212 /* Maxtor, IBM: self-test failure checkpoint byte meaning:
213 00 - write test
214 01 - servo basic
215 02 - servo random
216 03 - G-list scan
217 04 - Handling damage
218 05 - Read scan
219 */
220
221 /* Vendor attribute of SMART Threshold (compare to ata_smart_attribute above) */
222 #pragma pack(1)
223 struct ata_smart_threshold_entry {
224 unsigned char id;
225 unsigned char threshold;
226 unsigned char reserved[10];
227 } ATTR_PACKED;
228 #pragma pack()
229 ASSERT_SIZEOF_STRUCT(ata_smart_threshold_entry, 12);
230
231 /* Format of Read SMART THreshold Command */
232 /* Compare to ata_smart_values above */
233 #pragma pack(1)
234 struct ata_smart_thresholds_pvt {
235 unsigned short int revnumber;
236 struct ata_smart_threshold_entry thres_entries[NUMBER_ATA_SMART_ATTRIBUTES];
237 unsigned char reserved[149];
238 unsigned char chksum;
239 } ATTR_PACKED;
240 #pragma pack()
241 ASSERT_SIZEOF_STRUCT(ata_smart_thresholds_pvt, 512);
242
243
244 // Table 42 of T13/1321D Rev 1 spec (Error Data Structure)
245 #pragma pack(1)
246 struct ata_smart_errorlog_error_struct {
247 unsigned char reserved;
248 unsigned char error_register;
249 unsigned char sector_count;
250 unsigned char sector_number;
251 unsigned char cylinder_low;
252 unsigned char cylinder_high;
253 unsigned char drive_head;
254 unsigned char status;
255 unsigned char extended_error[19];
256 unsigned char state;
257 unsigned short timestamp;
258 } ATTR_PACKED;
259 #pragma pack()
260 ASSERT_SIZEOF_STRUCT(ata_smart_errorlog_error_struct, 30);
261
262
263 // Table 41 of T13/1321D Rev 1 spec (Command Data Structure)
264 #pragma pack(1)
265 struct ata_smart_errorlog_command_struct {
266 unsigned char devicecontrolreg;
267 unsigned char featuresreg;
268 unsigned char sector_count;
269 unsigned char sector_number;
270 unsigned char cylinder_low;
271 unsigned char cylinder_high;
272 unsigned char drive_head;
273 unsigned char commandreg;
274 unsigned int timestamp;
275 } ATTR_PACKED;
276 #pragma pack()
277 ASSERT_SIZEOF_STRUCT(ata_smart_errorlog_command_struct, 12);
278
279 // Table 40 of T13/1321D Rev 1 spec (Error log data structure)
280 #pragma pack(1)
281 struct ata_smart_errorlog_struct {
282 struct ata_smart_errorlog_command_struct commands[5];
283 struct ata_smart_errorlog_error_struct error_struct;
284 } ATTR_PACKED;
285 #pragma pack()
286 ASSERT_SIZEOF_STRUCT(ata_smart_errorlog_struct, 90);
287
288 // Table 39 of T13/1321D Rev 1 spec (SMART error log sector)
289 #pragma pack(1)
290 struct ata_smart_errorlog {
291 unsigned char revnumber;
292 unsigned char error_log_pointer;
293 struct ata_smart_errorlog_struct errorlog_struct[5];
294 unsigned short int ata_error_count;
295 unsigned char reserved[57];
296 unsigned char checksum;
297 } ATTR_PACKED;
298 #pragma pack()
299 ASSERT_SIZEOF_STRUCT(ata_smart_errorlog, 512);
300
301 // Table 45 of T13/1321D Rev 1 spec (Self-test log descriptor entry)
302 #pragma pack(1)
303 struct ata_smart_selftestlog_struct {
304 unsigned char selftestnumber; // Sector number register
305 unsigned char selfteststatus;
306 unsigned short int timestamp;
307 unsigned char selftestfailurecheckpoint;
308 unsigned int lbafirstfailure;
309 unsigned char vendorspecific[15];
310 } ATTR_PACKED;
311 #pragma pack()
312 ASSERT_SIZEOF_STRUCT(ata_smart_selftestlog_struct, 24);
313
314 // Table 44 of T13/1321D Rev 1 spec (Self-test log data structure)
315 #pragma pack(1)
316 struct ata_smart_selftestlog {
317 unsigned short int revnumber;
318 struct ata_smart_selftestlog_struct selftest_struct[21];
319 unsigned char vendorspecific[2];
320 unsigned char mostrecenttest;
321 unsigned char reserved[2];
322 unsigned char chksum;
323 } ATTR_PACKED;
324 #pragma pack()
325 ASSERT_SIZEOF_STRUCT(ata_smart_selftestlog, 512);
326
327 // SMART LOG DIRECTORY Table 52 of T13/1532D Vol 1 Rev 1a
328 #pragma pack(1)
329 struct ata_smart_log_entry {
330 unsigned char numsectors;
331 unsigned char reserved;
332 } ATTR_PACKED;
333 #pragma pack()
334 ASSERT_SIZEOF_STRUCT(ata_smart_log_entry, 2);
335
336 #pragma pack(1)
337 struct ata_smart_log_directory {
338 unsigned short int logversion;
339 struct ata_smart_log_entry entry[255];
340 } ATTR_PACKED;
341 #pragma pack()
342 ASSERT_SIZEOF_STRUCT(ata_smart_log_directory, 512);
343
344 // SMART SELECTIVE SELF-TEST LOG Table 61 of T13/1532D Volume 1
345 // Revision 3
346 #pragma pack(1)
347 struct test_span {
348 uint64_t start;
349 uint64_t end;
350 } ATTR_PACKED;
351 #pragma pack()
352 ASSERT_SIZEOF_STRUCT(test_span, 16);
353
354 #pragma pack(1)
355 struct ata_selective_self_test_log {
356 unsigned short logversion;
357 struct test_span span[5];
358 unsigned char reserved1[337-82+1];
359 unsigned char vendor_specific1[491-338+1];
360 uint64_t currentlba;
361 unsigned short currentspan;
362 unsigned short flags;
363 unsigned char vendor_specific2[507-504+1];
364 unsigned short pendingtime;
365 unsigned char reserved2;
366 unsigned char checksum;
367 } ATTR_PACKED;
368 #pragma pack()
369 ASSERT_SIZEOF_STRUCT(ata_selective_self_test_log, 512);
370
371 #define SELECTIVE_FLAG_DOSCAN (0x0002)
372 #define SELECTIVE_FLAG_PENDING (0x0008)
373 #define SELECTIVE_FLAG_ACTIVE (0x0010)
374
375
376 // SCT (SMART Command Transport) data structures
377 // See Sections 8.2 and 8.3 of:
378 // AT Attachment 8 - ATA/ATAPI Command Set (ATA8-ACS)
379 // T13/1699-D Revision 3f (Working Draft), December 11, 2006.
380
381 // SCT Status response (read with SMART_READ_LOG page 0xe0)
382 // Table 60 of T13/1699-D Revision 3f
383 #pragma pack(1)
384 struct ata_sct_status_response
385 {
386 unsigned short format_version; // 0-1: Status response format version number (2, 3)
387 unsigned short sct_version; // 2-3: Vendor specific version number
388 unsigned short sct_spec; // 4-5: SCT level supported (1)
389 unsigned int status_flags; // 6-9: Status flags (Bit 0: Segment initialized, Bits 1-31: reserved)
390 unsigned char device_state; // 10: Device State (0-5)
391 unsigned char bytes011_013[3]; // 11-13: reserved
392 unsigned short ext_status_code; // 14-15: Status of last SCT command (0xffff if executing)
393 unsigned short action_code; // 16-17: Action code of last SCT command
394 unsigned short function_code; // 18-19: Function code of last SCT command
395 unsigned char bytes020_039[20]; // 20-39: reserved
396 uint64_t lba_current; // 40-47: LBA of SCT command executing in background
397 unsigned char bytes048_199[152]; // 48-199: reserved
398 signed char hda_temp; // 200: Current temperature in Celsius (0x80 = invalid)
399 signed char min_temp; // 201: Minimum temperature this power cycle
400 signed char max_temp; // 202: Maximum temperature this power cycle
401 signed char life_min_temp; // 203: Minimum lifetime temperature
402 signed char life_max_temp; // 204: Maximum lifetime temperature
403 unsigned char byte205; // 205: reserved (T13/e06152r0-2: Average lifetime temperature)
404 unsigned int over_limit_count; // 206-209: # intervals since last reset with temperature > Max Op Limit
405 unsigned int under_limit_count; // 210-213: # intervals since last reset with temperature < Min Op Limit
406 unsigned char bytes214_479[266]; // 214-479: reserved
407 unsigned char vendor_specific[32];// 480-511: vendor specific
408 } ATTR_PACKED;
409 #pragma pack()
410 ASSERT_SIZEOF_STRUCT(ata_sct_status_response, 512);
411
412 // SCT Feature Control command (send with SMART_WRITE_LOG page 0xe0)
413 // Table 72 of T13/1699-D Revision 3f
414 #pragma pack(1)
415 struct ata_sct_feature_control_command
416 {
417 unsigned short action_code; // 4 = Feature Control
418 unsigned short function_code; // 1 = Set, 2 = Return, 3 = Return options
419 unsigned short feature_code; // 3 = Temperature logging interval
420 unsigned short state; // Interval
421 unsigned short option_flags; // Bit 0: persistent, Bits 1-31: reserved
422 unsigned short words005_255[251]; // reserved
423 } ATTR_PACKED;
424 #pragma pack()
425 ASSERT_SIZEOF_STRUCT(ata_sct_feature_control_command, 512);
426
427 // SCT Data Table command (send with SMART_WRITE_LOG page 0xe0)
428 // Table 73 of T13/1699-D Revision 3f
429 #pragma pack(1)
430 struct ata_sct_data_table_command
431 {
432 unsigned short action_code; // 5 = Data Table
433 unsigned short function_code; // 1 = Read Table
434 unsigned short table_id; // 2 = Temperature History
435 unsigned short words003_255[253]; // reserved
436 } ATTR_PACKED;
437 #pragma pack()
438 ASSERT_SIZEOF_STRUCT(ata_sct_data_table_command, 512);
439
440 // SCT Temperature History Table (read with SMART_READ_LOG page 0xe1)
441 // Table 75 of T13/1699-D Revision 3f
442 #pragma pack(1)
443 struct ata_sct_temperature_history_table
444 {
445 unsigned short format_version; // 0-1: Data table format version number (2)
446 unsigned short sampling_period; // 2-3: Temperature sampling period in minutes
447 unsigned short interval; // 4-5: Timer interval between history entries
448 signed char max_op_limit; // 6: Maximum recommended continuous operating temperature
449 signed char over_limit; // 7: Maximum temperature limit
450 signed char min_op_limit; // 8: Minimum recommended continuous operating limit
451 signed char under_limit; // 9: Minimum temperature limit
452 unsigned char bytes010_029[20]; // 10-29: reserved
453 unsigned short cb_size; // 30-31: Number of history entries (range 128-478)
454 unsigned short cb_index; // 32-33: Index of last updated entry (zero-based)
455 signed char cb[478]; // 34-(34+cb_size-1): Circular buffer of temperature values
456 } ATTR_PACKED;
457 #pragma pack()
458 ASSERT_SIZEOF_STRUCT(ata_sct_temperature_history_table, 512);
459
460
461 // Get information from drive
462 int ataReadHDIdentity(int device, struct ata_identify_device *buf);
463 int ataCheckPowerMode(int device);
464
465 /* Read S.M.A.R.T information from drive */
466 int ataReadSmartValues(int device,struct ata_smart_values *);
467 int ataReadSmartThresholds(int device, struct ata_smart_thresholds_pvt *);
468 int ataReadErrorLog(int device, struct ata_smart_errorlog *);
469 int ataReadSelfTestLog(int device, struct ata_smart_selftestlog *);
470 int ataReadSelectiveSelfTestLog(int device, struct ata_selective_self_test_log *data);
471 int ataSmartStatus(int device);
472 int ataSetSmartThresholds(int device, struct ata_smart_thresholds_pvt *);
473 int ataReadLogDirectory(int device, struct ata_smart_log_directory *);
474
475 // Read SCT information
476 int ataReadSCTStatus(int device, ata_sct_status_response * sts);
477 int ataReadSCTTempHist(int device, ata_sct_temperature_history_table * tmh,
478 ata_sct_status_response * sts);
479 // Set SCT temperature logging interval
480 int ataSetSCTTempInterval(int device, unsigned interval, bool persistent);
481
482
483 /* Enable/Disable SMART on device */
484 int ataEnableSmart ( int device );
485 int ataDisableSmart (int device );
486 int ataEnableAutoSave(int device);
487 int ataDisableAutoSave(int device);
488
489 /* Automatic Offline Testing */
490 int ataEnableAutoOffline ( int device );
491 int ataDisableAutoOffline (int device );
492
493 /* S.M.A.R.T. test commands */
494 int ataSmartOfflineTest (int device);
495 int ataSmartExtendSelfTest (int device);
496 int ataSmartShortSelfTest (int device);
497 int ataSmartShortCapSelfTest (int device);
498 int ataSmartExtendCapSelfTest (int device);
499 int ataSmartSelfTestAbort (int device);
500
501 // Returns the latest compatibility of ATA/ATAPI Version the device
502 // supports. Returns -1 if Version command is not supported
503 int ataVersionInfo (const char **description, struct ata_identify_device *drive, unsigned short *minor);
504
505 // If SMART supported, this is guaranteed to return 1 if SMART is enabled, else 0.
506 int ataDoesSmartWork(int device);
507
508 // returns 1 if SMART supported, 0 if not supported or can't tell
509 int ataSmartSupport ( struct ata_identify_device *drive);
510
511 // Return values:
512 // 1: SMART enabled
513 // 0: SMART disabled
514 // -1: can't tell if SMART is enabled -- try issuing ataDoesSmartWork command to see
515 int ataIsSmartEnabled(struct ata_identify_device *drive);
516
517 /* Check SMART for Threshold failure */
518 // onlyfailed=0 : are or were any age or prefailure attributes <= threshold
519 // onlyfailed=1: are any prefailure attributes <= threshold now
520 int ataCheckSmart ( struct ata_smart_values *data, struct ata_smart_thresholds_pvt *thresholds, int onlyfailed);
521
522 int ataSmartStatus2(int device);
523
524 // int isOfflineTestTime ( struct ata_smart_values data)
525 // returns S.M.A.R.T. Offline Test Time in seconds
526 int isOfflineTestTime ( struct ata_smart_values *data);
527
528 int isShortSelfTestTime ( struct ata_smart_values *data);
529
530 int isExtendedSelfTestTime ( struct ata_smart_values *data);
531
532 int isSmartErrorLogCapable(struct ata_smart_values *data, struct ata_identify_device *identity);
533
534 int isSmartTestLogCapable(struct ata_smart_values *data, struct ata_identify_device *identity);
535
536 int isGeneralPurposeLoggingCapable(struct ata_identify_device *identity);
537
538 int isSupportExecuteOfflineImmediate ( struct ata_smart_values *data);
539
540 int isSupportAutomaticTimer ( struct ata_smart_values *data);
541
542 int isSupportOfflineAbort ( struct ata_smart_values *data);
543
544 int isSupportOfflineSurfaceScan ( struct ata_smart_values *data);
545
546 int isSupportSelfTest (struct ata_smart_values *data);
547
548 int isSupportConveyanceSelfTest(struct ata_smart_values *data);
549
550 int isSupportSelectiveSelfTest(struct ata_smart_values *data);
551
552 inline bool isSCTCapable(const ata_identify_device *drive)
553 { return !!(drive->words088_255[206-88] & 0x01); } // 0x01 = SCT support
554
555 inline bool isSCTFeatureControlCapable(const ata_identify_device *drive)
556 { return ((drive->words088_255[206-88] & 0x11) == 0x11); } // 0x10 = SCT Feature Control support
557
558 inline bool isSCTDataTableCapable(const ata_identify_device *drive)
559 { return ((drive->words088_255[206-88] & 0x21) == 0x21); } // 0x20 = SCT Data Table support
560
561 int ataSmartTest(int device, int testtype, struct ata_smart_values *data, uint64_t num_sectors);
562
563 int TestTime(struct ata_smart_values *data,int testtype);
564
565 // Prints the raw value (with appropriate formatting) into the
566 // character string out.
567 int64_t ataPrintSmartAttribRawValue(char *out,
568 struct ata_smart_attribute *attribute,
569 unsigned char *defs);
570
571 // Prints Attribute Name for standard SMART attributes. Writes a
572 // 30 byte string with attribute name into output
573 void ataPrintSmartAttribName(char *output, unsigned char id, unsigned char *definitions);
574
575 // This checks the n'th attribute in the attribute list, NOT the
576 // attribute with id==n. If the attribute does not exist, or the
577 // attribute is > threshold, then returns zero. If the attribute is
578 // <= threshold (failing) then we the attribute number if it is a
579 // prefail attribute. Else we return minus the attribute number if it
580 // is a usage attribute.
581 int ataCheckAttribute(struct ata_smart_values *data,
582 struct ata_smart_thresholds_pvt *thresholds,
583 int n);
584
585 // External handler function, for when a checksum is not correct. Can
586 // simply return if no action is desired, or can print error messages
587 // as needed, or exit. Is passed a string with the name of the Data
588 // Structure with the incorrect checksum.
589 void checksumwarning(const char *string);
590
591 // Returns raw value of Attribute with ID==id. This will be in the
592 // range 0 to 2^48-1 inclusive. If the Attribute does not exist,
593 // return -1.
594 int64_t ATAReturnAttributeRawValue(unsigned char id, struct ata_smart_values *data);
595
596 // Return Temperature Attribute raw value selected according to possible
597 // non-default interpretations. If the Attribute does not exist, return 0
598 unsigned char ATAReturnTemperatureValue(/*const*/ struct ata_smart_values *data, const unsigned char *defs);
599
600
601 // This are the meanings of the Self-test failure checkpoint byte.
602 // This is in the self-test log at offset 4 bytes into the self-test
603 // descriptor and in the SMART READ DATA structure at byte offset
604 // 371. These codes are not well documented. The meanings returned by
605 // this routine are used (at least) by Maxtor and IBM. Returns NULL if
606 // not recognized.
607 const char *SelfTestFailureCodeName(unsigned char which);
608
609
610 #define MAX_ATTRIBUTE_NUM 256
611
612 extern const char *vendorattributeargs[];
613
614 // function to parse pairs like "9,minutes" or "220,temp". See end of
615 // extern.h for definition of defs[]. Returns 0 if pair recognized,
616 // else 1 if there is a problem. Allocates memory for array if the
617 // array address is *defs==NULL.
618 int parse_attribute_def(char *pair, unsigned char **defs);
619
620 // Function to return a string containing a list of the arguments in
621 // vendorattributeargs[]. Returns NULL if the required memory can't
622 // be allocated.
623 char *create_vendor_attribute_arg_list(void);
624
625
626 // These are two of the functions that are defined in os_*.c and need
627 // to be ported to get smartmontools onto another OS.
628 int ata_command_interface(int device, smart_command_set command, int select, char *data);
629 int escalade_command_interface(int fd, int escalade_port, int escalade_type, smart_command_set command, int select, char *data);
630 int marvell_command_interface(int device, smart_command_set command, int select, char *data);
631 int highpoint_command_interface(int device, smart_command_set command, int select, char *data);
632
633 // "smartctl -r ataioctl,2 ..." output parser pseudo-device
634 int parsedev_open(const char * name);
635 void parsedev_close(int fd);
636
637 // Optional functions of os_*.c
638 #ifdef HAVE_ATA_IDENTIFY_IS_CACHED
639 // Return true if OS caches the ATA identify sector
640 int ata_identify_is_cached(int fd);
641 #endif
642
643 // This function is exported to give low-level capability
644 int smartcommandhandler(int device, smart_command_set command, int select, char *data);
645
646 // Utility routines.
647 void swap2(char *location);
648 void swap4(char *location);
649 void swap8(char *location);
650 // Typesafe variants using overloading
651 inline void swapx(unsigned short * p)
652 { swap2((char*)p); }
653 inline void swapx(unsigned int * p)
654 { swap4((char*)p); }
655 inline void swapx(uint64_t * p)
656 { swap8((char*)p); }
657
658 #endif /* ATACMDS_H_ */