+
+// SCT (SMART Command Transport) data structures
+// See Sections 8.2 and 8.3 of:
+// AT Attachment 8 - ATA/ATAPI Command Set (ATA8-ACS)
+// T13/1699-D Revision 3f (Working Draft), December 11, 2006.
+
+// SCT Status response (read with SMART_READ_LOG page 0xe0)
+// Table 194 of T13/BSR INCITS 529 (ACS-4) Revision 20, October 26, 2017
+#pragma pack(1)
+struct ata_sct_status_response
+{
+ unsigned short format_version; // 0-1: Status response format version number (2, 3)
+ unsigned short sct_version; // 2-3: Vendor specific version number
+ unsigned short sct_spec; // 4-5: SCT level supported (1)
+ unsigned int status_flags; // 6-9: Status flags (Bit 0: Segment initialized, Bits 1-31: reserved)
+ unsigned char device_state; // 10: Device State (0-5)
+ unsigned char bytes011_013[3]; // 11-13: reserved
+ unsigned short ext_status_code; // 14-15: Status of last SCT command (0xffff if executing)
+ unsigned short action_code; // 16-17: Action code of last SCT command
+ unsigned short function_code; // 18-19: Function code of last SCT command
+ unsigned char bytes020_039[20]; // 20-39: reserved
+ uint64_t lba_current; // 40-47: LBA of SCT command executing in background
+ unsigned char bytes048_199[152]; // 48-199: reserved
+ signed char hda_temp; // 200: Current temperature in Celsius (0x80 = invalid)
+ signed char min_temp; // 201: Minimum temperature this power cycle
+ signed char max_temp; // 202: Maximum temperature this power cycle
+ signed char life_min_temp; // 203: Minimum lifetime temperature
+ signed char life_max_temp; // 204: Maximum lifetime temperature
+ signed char max_op_limit; // 205: Specified maximum operating temperature (ACS-4)
+ 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 short smart_status; // 214-215: LBA(32:8) of SMART RETURN STATUS (0, 0x2cf4, 0xc24f) (ACS-4)
+ unsigned short min_erc_time; // 216-217: Minimum supported value for ERC (ACS-4)
+ unsigned char bytes216_479[479-218+1]; // 218-479: reserved
+ unsigned char vendor_specific[32];// 480-511: vendor specific
+} ATTR_PACKED;
+#pragma pack()
+ASSERT_SIZEOF_STRUCT(ata_sct_status_response, 512);
+
+// SCT Error Recovery Control command (send with SMART_WRITE_LOG page 0xe0)
+// Table 88 of T13/1699-D Revision 6a
+#pragma pack(1)
+struct ata_sct_error_recovery_control_command
+{
+ unsigned short action_code; // 3 = Error Recovery Control
+ unsigned short function_code; // 1 = Set, 2 = Return
+ unsigned short selection_code; // 1 = Read Timer, 2 = Write Timer
+ unsigned short time_limit; // If set: Recovery time limit in 100ms units
+ unsigned short words004_255[252]; // reserved
+} ATTR_PACKED;
+#pragma pack()
+ASSERT_SIZEOF_STRUCT(ata_sct_error_recovery_control_command, 512);
+
+// SCT Feature Control command (send with SMART_WRITE_LOG page 0xe0)
+// Table 72 of T13/1699-D Revision 3f
+#pragma pack(1)
+struct ata_sct_feature_control_command
+{
+ unsigned short action_code; // 4 = Feature Control
+ unsigned short function_code; // 1 = Set, 2 = Return, 3 = Return options
+ unsigned short feature_code; // 3 = Temperature logging interval
+ unsigned short state; // Interval
+ unsigned short option_flags; // Bit 0: persistent, Bits 1-15: reserved
+ unsigned short words005_255[251]; // reserved
+} ATTR_PACKED;
+#pragma pack()
+ASSERT_SIZEOF_STRUCT(ata_sct_feature_control_command, 512);
+
+// SCT Data Table command (send with SMART_WRITE_LOG page 0xe0)
+// Table 73 of T13/1699-D Revision 3f
+#pragma pack(1)
+struct ata_sct_data_table_command
+{
+ unsigned short action_code; // 5 = Data Table
+ unsigned short function_code; // 1 = Read Table
+ unsigned short table_id; // 2 = Temperature History
+ unsigned short words003_255[253]; // reserved
+} ATTR_PACKED;
+#pragma pack()
+ASSERT_SIZEOF_STRUCT(ata_sct_data_table_command, 512);
+
+// SCT Temperature History Table (read with SMART_READ_LOG page 0xe1)
+// Table 75 of T13/1699-D Revision 3f
+#pragma pack(1)
+struct ata_sct_temperature_history_table
+{
+ unsigned short format_version; // 0-1: Data table format version number (2)
+ unsigned short sampling_period; // 2-3: Temperature sampling period in minutes
+ unsigned short interval; // 4-5: Timer interval between history entries
+ signed char max_op_limit; // 6: Maximum recommended continuous operating temperature
+ signed char over_limit; // 7: Maximum temperature limit
+ signed char min_op_limit; // 8: Minimum recommended continuous operating limit
+ signed char under_limit; // 9: Minimum temperature limit
+ unsigned char bytes010_029[20]; // 10-29: reserved
+ unsigned short cb_size; // 30-31: Number of history entries (range 128-478)
+ unsigned short cb_index; // 32-33: Index of last updated entry (zero-based)
+ signed char cb[478]; // 34-(34+cb_size-1): Circular buffer of temperature values
+} ATTR_PACKED;
+#pragma pack()
+ASSERT_SIZEOF_STRUCT(ata_sct_temperature_history_table, 512);
+
+// Possible values for span_args.mode
+enum {
+ SEL_RANGE, // MIN-MAX
+ SEL_REDO, // redo this
+ SEL_NEXT, // do next range
+ SEL_CONT // redo or next depending of last test status
+};
+
+// Arguments for selective self-test
+struct ata_selective_selftest_args
+{
+ // Arguments for each span
+ struct span_args
+ {
+ uint64_t start; // First block
+ uint64_t end; // Last block
+ int mode; // SEL_*, see above
+
+ span_args()
+ : start(0), end(0), mode(SEL_RANGE) { }
+ };
+
+ span_args span[5]; // Range and mode for 5 spans
+ int num_spans; // Number of spans
+ int pending_time; // One plus time in minutes to wait after powerup before restarting
+ // interrupted offline scan after selective self-test.
+ int scan_after_select; // Run offline scan after selective self-test:
+ // 0: don't change,
+ // 1: turn off scan after selective self-test,
+ // 2: turn on scan after selective self-test.
+
+ ata_selective_selftest_args()
+ : num_spans(0), pending_time(0), scan_after_select(0) { }
+};
+
+// Priority for vendor attribute defs
+enum ata_vendor_def_prior
+{
+ PRIOR_DEFAULT,
+ PRIOR_DATABASE,
+ PRIOR_USER
+};
+
+// Raw attribute value print formats
+enum ata_attr_raw_format
+{
+ RAWFMT_DEFAULT,
+ RAWFMT_RAW8,
+ RAWFMT_RAW16,
+ RAWFMT_RAW48,
+ RAWFMT_HEX48,
+ RAWFMT_RAW56,
+ RAWFMT_HEX56,
+ RAWFMT_RAW64,
+ RAWFMT_HEX64,
+ RAWFMT_RAW16_OPT_RAW16,
+ RAWFMT_RAW16_OPT_AVG16,
+ 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,
+};
+
+// Attribute flags
+enum {
+ ATTRFLAG_INCREASING = 0x01, // Value not reset (for reallocated/pending counts)
+ ATTRFLAG_NO_NORMVAL = 0x02, // Normalized value not valid
+ ATTRFLAG_NO_WORSTVAL = 0x04, // Worst value not valid
+ ATTRFLAG_HDD_ONLY = 0x08, // DEFAULT setting for HDD only
+ ATTRFLAG_SSD_ONLY = 0x10, // DEFAULT setting for SSD only
+};
+
+// Vendor attribute display defs for all attribute ids
+class ata_vendor_attr_defs
+{
+public:
+ struct entry
+ {
+ std::string name; // Attribute name, empty for default
+ ata_attr_raw_format raw_format; // Raw value print format
+ ata_vendor_def_prior priority; // Setting priority
+ unsigned flags; // ATTRFLAG_*
+ char byteorder[8+1]; // String [012345rvwz] to define byte order
+
+ entry()
+ : raw_format(RAWFMT_DEFAULT),
+ priority(PRIOR_DEFAULT),
+ flags(0)
+ { byteorder[0] = 0; }
+ };
+
+ entry & operator[](unsigned char id)
+ { return m_defs[id]; }
+
+ const entry & operator[](unsigned char id) const
+ { return m_defs[id]; }
+
+private:
+ entry m_defs[256];
+};
+
+
+// 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;
+