Annotation of embedaddon/smartmontools/atacmds.h, revision 1.1.1.3

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>