X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=atacmds.h;h=a5c71a5e64ee815fc572ed0a45236bd08b6f2302;hb=1863f918813989ff858e31c71fb230e88f233e52;hp=8dc913a875a023e2af862723f4caa89889bfc362;hpb=85c9041f518edf486642458d4647c301cd9b188e;p=mirror_smartmontools-debian.git diff --git a/atacmds.h b/atacmds.h index 8dc913a..a5c71a5 100644 --- a/atacmds.h +++ b/atacmds.h @@ -3,8 +3,8 @@ * * Home page of code is: http://smartmontools.sourceforge.net * - * Copyright (C) 2002-9 Bruce Allen - * Copyright (C) 2008-9 Christian Franke + * Copyright (C) 2002-11 Bruce Allen + * Copyright (C) 2008-14 Christian Franke * Copyright (C) 1999-2000 Michael Cornwell * * This program is free software; you can redistribute it and/or modify @@ -13,8 +13,7 @@ * any later version. * * You should have received a copy of the GNU General Public License - * (for example COPYING); if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * (for example COPYING); If not, see . * * This code was originally developed as a Senior Thesis by Michael Cornwell * at the Concurrent Systems Laboratory (now part of the Storage Systems @@ -26,7 +25,7 @@ #ifndef ATACMDS_H_ #define ATACMDS_H_ -#define ATACMDS_H_CVSID "$Id: atacmds.h 3065 2010-02-10 22:16:50Z chrfranke $" +#define ATACMDS_H_CVSID "$Id: atacmds.h 3998 2014-10-06 15:20:25Z chrfranke $" #include "dev_interface.h" // ata_device @@ -67,20 +66,27 @@ typedef enum { WRITE_LOG } smart_command_set; -// Possible values for fix_firmwarebug. -enum { - FIX_NOTSPECIFIED = 0, - FIX_NONE, - FIX_SAMSUNG, - FIX_SAMSUNG2, - FIX_SAMSUNG3 -}; // ATA Specification Command Register Values (Commands) +#define ATA_CHECK_POWER_MODE 0xe5 #define ATA_IDENTIFY_DEVICE 0xec #define ATA_IDENTIFY_PACKET_DEVICE 0xa1 +#define ATA_IDLE 0xe3 #define ATA_SMART_CMD 0xb0 -#define ATA_CHECK_POWER_MODE 0xe5 +#define ATA_SECURITY_FREEZE_LOCK 0xf5 +#define ATA_SET_FEATURES 0xef +#define ATA_STANDBY_IMMEDIATE 0xe0 + +// SET_FEATURES subcommands +#define ATA_DISABLE_AAM 0xc2 +#define ATA_DISABLE_APM 0x85 +#define ATA_DISABLE_WRITE_CACHE 0x82 +#define ATA_DISABLE_READ_LOOK_AHEAD 0x55 +#define ATA_ENABLE_AAM 0x42 +#define ATA_ENABLE_APM 0x05 +#define ATA_ENABLE_WRITE_CACHE 0x02 +#define ATA_ENABLE_READ_LOOK_AHEAD 0xaa + // 48-bit commands #define ATA_READ_LOG_EXT 0x2F @@ -196,11 +202,12 @@ ASSERT_SIZEOF_STRUCT(ata_smart_attribute, 12); // 5: Selfpereserving bit #define ATTRIBUTE_FLAGS_SELFPRESERVING(x) (x & 0x20) +// 6-15: Reserved for future use +#define ATTRIBUTE_FLAGS_OTHER(x) ((x) & 0xffc0) -// Last ten bits are reserved for future use -/* ata_smart_values is format of the read drive Attribute command */ -/* see Table 34 of T13/1321D Rev 1 spec (Device SMART data structure) for *some* info */ +// Format of data returned by SMART READ DATA +// Table 62 of T13/1699-D (ATA8-ACS) Revision 6a, September 2008 #pragma pack(1) struct ata_smart_values { unsigned short int revnumber; @@ -214,9 +221,10 @@ struct ata_smart_values { unsigned char errorlog_capability; unsigned char vendor_specific_371; // Maxtor, IBM: self-test failure checkpoint see below! unsigned char short_test_completion_time; - unsigned char extend_test_completion_time; + unsigned char extend_test_completion_time_b; // If 0xff, use 16-bit value below unsigned char conveyance_test_completion_time; - unsigned char reserved_375_385[11]; + unsigned short extend_test_completion_time_w; // e04130r2, added to T13/1699-D Revision 1c, April 2005 + unsigned char reserved_377_385[9]; unsigned char vendor_specific_386_510[125]; // Maxtor bytes 508-509 Attribute/Threshold Revision # unsigned char chksum; } ATTR_PACKED; @@ -513,7 +521,7 @@ ASSERT_SIZEOF_STRUCT(ata_selective_self_test_log, 512); // T13/1699-D Revision 3f (Working Draft), December 11, 2006. // SCT Status response (read with SMART_READ_LOG page 0xe0) -// Table 60 of T13/1699-D Revision 3f +// Table 182 of T13/BSR INCITS 529 (ACS-4) Revision 04, August 25, 2014 #pragma pack(1) struct ata_sct_status_response { @@ -537,7 +545,8 @@ struct ata_sct_status_response unsigned char byte205; // 205: reserved (T13/e06152r0-2: Average lifetime temperature) unsigned int over_limit_count; // 206-209: # intervals since last reset with temperature > Max Op Limit unsigned int under_limit_count; // 210-213: # intervals since last reset with temperature < Min Op Limit - unsigned char bytes214_479[266]; // 214-479: reserved + unsigned short smart_status; // 214-215: LBA(32:8) of SMART RETURN STATUS (0, 0x2cf4, 0xc24f) (ACS-4) + unsigned char bytes216_479[479-216+1]; // 216-479: reserved unsigned char vendor_specific[32];// 480-511: vendor specific } ATTR_PACKED; #pragma pack() @@ -656,14 +665,19 @@ enum ata_attr_raw_format RAWFMT_RAW16, RAWFMT_RAW48, RAWFMT_HEX48, + RAWFMT_RAW56, + RAWFMT_HEX56, RAWFMT_RAW64, RAWFMT_HEX64, RAWFMT_RAW16_OPT_RAW16, RAWFMT_RAW16_OPT_AVG16, - RAWFMT_RAW24_RAW24, + RAWFMT_RAW24_OPT_RAW8, + RAWFMT_RAW24_DIV_RAW24, + RAWFMT_RAW24_DIV_RAW32, RAWFMT_SEC2HOUR, RAWFMT_MIN2HOUR, RAWFMT_HALFMIN2HOUR, + RAWFMT_MSEC24_HOUR32, RAWFMT_TEMPMINMAX, RAWFMT_TEMP10X, }; @@ -705,19 +719,62 @@ private: }; +// Possible values for firmwarebugs +enum firmwarebug_t { + BUG_NONE = 0, + BUG_NOLOGDIR, + BUG_SAMSUNG, + BUG_SAMSUNG2, + BUG_SAMSUNG3, + BUG_XERRORLBA +}; + +// Set of firmware bugs +class firmwarebug_defs +{ +public: + firmwarebug_defs() + : m_bugs(0) { } + + bool is_set(firmwarebug_t bug) const + { return !!(m_bugs & (1 << bug)); } + + void set(firmwarebug_t bug) + { m_bugs |= (1 << bug); } + + void set(firmwarebug_defs bugs) + { m_bugs |= bugs.m_bugs; } + +private: + unsigned m_bugs; +}; + + +// Print ATA debug messages? +extern unsigned char ata_debugmode; + +// Suppress serial number? +extern bool dont_print_serial_number; + // Get information from drive -int ataReadHDIdentity(ata_device * device, struct ata_identify_device *buf); +int ata_read_identity(ata_device * device, ata_identify_device * buf, bool fix_swapped_id, + unsigned char * raw_buf = 0); int ataCheckPowerMode(ata_device * device); +// Issue a no-data ATA command with optional sector count register value +bool ata_nodata_command(ata_device * device, unsigned char command, int sector_count = -1); + +// Issue SET FEATURES command with optional sector count register value +bool ata_set_features(ata_device * device, unsigned char features, int sector_count = -1); + /* Read S.M.A.R.T information from drive */ int ataReadSmartValues(ata_device * device,struct ata_smart_values *); int ataReadSmartThresholds(ata_device * device, struct ata_smart_thresholds_pvt *); int ataReadErrorLog (ata_device * device, ata_smart_errorlog *data, - unsigned char fix_firmwarebug); + firmwarebug_defs firmwarebugs); int ataReadSelfTestLog(ata_device * device, ata_smart_selftestlog * data, - unsigned char fix_firmwarebug); + firmwarebug_defs firmwarebugs); int ataReadSelectiveSelfTestLog(ata_device * device, struct ata_selective_self_test_log *data); -int ataSetSmartThresholds(ata_device * device, struct ata_smart_thresholds_pvt *); int ataReadLogDirectory(ata_device * device, ata_smart_log_directory *, bool gpl); // Read GP Log page(s) @@ -729,7 +786,7 @@ bool ataReadSmartLog(ata_device * device, unsigned char logaddr, void * data, unsigned nsectors); // Read SMART Extended Comprehensive Error Log bool ataReadExtErrorLog(ata_device * device, ata_smart_exterrlog * log, - unsigned nsectors); + unsigned nsectors, firmwarebug_defs firwarebugs); // Read SMART Extended Self-test Log bool ataReadExtSelfTestLog(ata_device * device, ata_smart_extselftestlog * log, unsigned nsectors); @@ -757,18 +814,21 @@ int ataEnableAutoOffline (ata_device * device); int ataDisableAutoOffline (ata_device * device); /* S.M.A.R.T. test commands */ -int ataSmartOfflineTest (ata_device * device); -int ataSmartExtendSelfTest (ata_device * device); -int ataSmartShortSelfTest (ata_device * device); -int ataSmartShortCapSelfTest (ata_device * device); -int ataSmartExtendCapSelfTest (ata_device * device); -int ataSmartSelfTestAbort (ata_device * device); +int ataSmartTest(ata_device * device, int testtype, bool force, + const ata_selective_selftest_args & args, + const ata_smart_values * sv, uint64_t num_sectors); + int ataWriteSelectiveSelfTestLog(ata_device * device, ata_selective_selftest_args & args, - const ata_smart_values * sv, uint64_t num_sectors); + const ata_smart_values * sv, uint64_t num_sectors, + const ata_selective_selftest_args * prev_spans = 0); + +// Get World Wide Name (WWN) fields. +// Return NAA field or -1 if WWN is unsupported. +int ata_get_wwn(const ata_identify_device * id, unsigned & oui, uint64_t & unique_id); -// Returns the latest compatibility of ATA/ATAPI Version the device -// supports. Returns -1 if Version command is not supported -int ataVersionInfo(const char ** description, const ata_identify_device * drive, unsigned short * minor); +// Get nominal media rotation rate. +// Returns: 0 = not reported, 1 = SSD, >1 = HDD rpm, < 0 = -(Unknown value) +int ata_get_rotation_rate(const ata_identify_device * id); // If SMART supported, this is guaranteed to return 1 if SMART is enabled, else 0. int ataDoesSmartWork(ata_device * device); @@ -776,6 +836,12 @@ int ataDoesSmartWork(ata_device * device); // returns 1 if SMART supported, 0 if not supported or can't tell int ataSmartSupport(const ata_identify_device * drive); +// Return values: +// 1: Write Cache Reordering enabled +// 2: Write Cache Reordering disabled +// -1: error +int ataGetSetSCTWriteCacheReordering(ata_device * device, bool enable, bool persistent, bool set); + // Return values: // 1: SMART enabled // 0: SMART disabled @@ -816,9 +882,6 @@ inline bool isSCTFeatureControlCapable(const ata_identify_device *drive) inline bool isSCTDataTableCapable(const ata_identify_device *drive) { return ((drive->words088_255[206-88] & 0x21) == 0x21); } // 0x20 = SCT Data Table support -int ataSmartTest(ata_device * device, int testtype, const ata_selective_selftest_args & args, - const ata_smart_values * sv, uint64_t num_sectors); - int TestTime(const ata_smart_values * data, int testtype); // Attribute state @@ -826,7 +889,6 @@ enum ata_attr_state { ATTRSTATE_NON_EXISTING, // No such Attribute ATTRSTATE_NO_NORMVAL, // Normalized value not valid - ATTRSTATE_BAD_THRESHOLD, // Threshold not valid ATTRSTATE_NO_THRESHOLD, // Unknown or no threshold ATTRSTATE_OK, // Never failed ATTRSTATE_FAILED_PAST, // Failed in the past @@ -835,8 +897,10 @@ enum ata_attr_state // Get attribute state ata_attr_state ata_get_attr_state(const ata_smart_attribute & attr, - const ata_smart_threshold_entry & thre, - const ata_vendor_attr_defs & defs); + int attridx, + const ata_smart_threshold_entry * thresholds, + const ata_vendor_attr_defs & defs, + unsigned char * threshval = 0); // Get attribute raw value. uint64_t ata_get_attr_raw_value(const ata_smart_attribute & attr, @@ -848,7 +912,8 @@ std::string ata_format_attr_raw_value(const ata_smart_attribute & attr, // Get attribute name std::string ata_get_smart_attr_name(unsigned char id, - const ata_vendor_attr_defs & defs); + const ata_vendor_attr_defs & defs, + int rpm = 0); // External handler function, for when a checksum is not correct. Can // simply return if no action is desired, or can print error messages @@ -864,15 +929,6 @@ int ata_find_attr_index(unsigned char id, const ata_smart_values & smartval); unsigned char ata_return_temperature_value(const ata_smart_values * data, const ata_vendor_attr_defs & defs); -// This are the meanings of the Self-test failure checkpoint byte. -// This is in the self-test log at offset 4 bytes into the self-test -// descriptor and in the SMART READ DATA structure at byte offset -// 371. These codes are not well documented. The meanings returned by -// this routine are used (at least) by Maxtor and IBM. Returns NULL if -// not recognized. -const char *SelfTestFailureCodeName(unsigned char which); - - #define MAX_ATTRIBUTE_NUM 256 // Parse vendor attribute display def (-v option). @@ -889,6 +945,13 @@ unsigned char get_unc_attr_id(bool offline, const ata_vendor_attr_defs & defs, // parse_attribute_def(). std::string create_vendor_attribute_arg_list(); +// Parse firmwarebug def (-F option). +// Return false on error. +bool parse_firmwarebug_def(const char * opt, firmwarebug_defs & firmwarebugs); + +// Return a string of valid argument words for parse_firmwarebug_def() +const char * get_valid_firmwarebug_args(); + // These are two of the functions that are defined in os_*.c and need // to be ported to get smartmontools onto another OS. @@ -900,33 +963,38 @@ std::string create_vendor_attribute_arg_list(); //int areca_command_interface(int fd, int disknum, smart_command_set command, int select, char *data); -// Optional functions of os_*.c -#ifdef HAVE_ATA_IDENTIFY_IS_CACHED -// Return true if OS caches the ATA identify sector -//int ata_identify_is_cached(int fd); -#endif - // This function is exported to give low-level capability int smartcommandhandler(ata_device * device, smart_command_set command, int select, char *data); // Print one self-test log entry. -bool ataPrintSmartSelfTestEntry(unsigned testnum, unsigned char test_type, - unsigned char test_status, - unsigned short timestamp, - uint64_t failing_lba, - bool print_error_only, bool & print_header); +// Returns: +// -1: failed self-test +// 1: extended self-test completed without error +// 0: otherwise +int ataPrintSmartSelfTestEntry(unsigned testnum, unsigned char test_type, + unsigned char test_status, + unsigned short timestamp, + uint64_t failing_lba, + bool print_error_only, bool & print_header); // Print Smart self-test log, used by smartctl and smartd. int ataPrintSmartSelfTestlog(const ata_smart_selftestlog * data, bool allentries, - unsigned char fix_firmwarebug); + firmwarebug_defs firmwarebugs); + +// Get capacity and sector sizes from IDENTIFY data +struct ata_size_info +{ + uint64_t sectors; + uint64_t capacity; + unsigned log_sector_size; + unsigned phy_sector_size; + unsigned log_sector_offset; +}; -// Get number of sectors from IDENTIFY sector. -uint64_t get_num_sectors(const ata_identify_device * drive); +void ata_get_size_info(const ata_identify_device * id, ata_size_info & sizes); // Convenience function for formatting strings from ata_identify_device. -void format_ata_string(char * out, const char * in, int n, bool fix_swap); -inline void format_ata_string(char * out, const unsigned char * in, int n, bool fix_swap) - { format_ata_string(out, (const char *)in, n, fix_swap); } +void ata_format_id_string(char * out, const unsigned char * in, int n); // Utility routines. unsigned char checksum(const void * data);