📄 atacmds.h
字号:
unsigned char reserved;} ATTR_PACKED;#pragma pack()ASSERT_SIZEOF_STRUCT(ata_smart_log_entry, 2);#pragma pack(1)struct ata_smart_log_directory { unsigned short int logversion; struct ata_smart_log_entry entry[255];} ATTR_PACKED;#pragma pack()ASSERT_SIZEOF_STRUCT(ata_smart_log_directory, 512);// SMART SELECTIVE SELF-TEST LOG Table 61 of T13/1532D Volume 1// Revision 3#pragma pack(1)struct test_span { uint64_t start; uint64_t end;} ATTR_PACKED;#pragma pack()ASSERT_SIZEOF_STRUCT(test_span, 16);#pragma pack(1)struct ata_selective_self_test_log { unsigned short logversion; struct test_span span[5]; unsigned char reserved1[337-82+1]; unsigned char vendor_specific1[491-338+1]; uint64_t currentlba; unsigned short currentspan; unsigned short flags; unsigned char vendor_specific2[507-504+1]; unsigned short pendingtime; unsigned char reserved2; unsigned char checksum;} ATTR_PACKED;#pragma pack()ASSERT_SIZEOF_STRUCT(ata_selective_self_test_log, 512);#define SELECTIVE_FLAG_DOSCAN (0x0002)#define SELECTIVE_FLAG_PENDING (0x0008)#define SELECTIVE_FLAG_ACTIVE (0x0010)// 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 60 of T13/1699-D Revision 3f #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 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 char vendor_specific[32];// 480-511: vendor specific} ATTR_PACKED;#pragma pack()ASSERT_SIZEOF_STRUCT(ata_sct_status_response, 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-31: 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);// Get information from driveint ataReadHDIdentity(int device, struct ata_identify_device *buf);int ataCheckPowerMode(int device);/* Read S.M.A.R.T information from drive */int ataReadSmartValues(int device,struct ata_smart_values *);int ataReadSmartThresholds(int device, struct ata_smart_thresholds_pvt *);int ataReadErrorLog(int device, struct ata_smart_errorlog *);int ataReadSelfTestLog(int device, struct ata_smart_selftestlog *);int ataReadSelectiveSelfTestLog(int device, struct ata_selective_self_test_log *data);int ataSmartStatus(int device);int ataSetSmartThresholds(int device, struct ata_smart_thresholds_pvt *);int ataReadLogDirectory(int device, struct ata_smart_log_directory *);// Read SCT informationint ataReadSCTStatus(int device, ata_sct_status_response * sts);int ataReadSCTTempHist(int device, ata_sct_temperature_history_table * tmh, ata_sct_status_response * sts);// Set SCT temperature logging intervalint ataSetSCTTempInterval(int device, unsigned interval, bool persistent);/* Enable/Disable SMART on device */int ataEnableSmart ( int device );int ataDisableSmart (int device );int ataEnableAutoSave(int device);int ataDisableAutoSave(int device);/* Automatic Offline Testing */int ataEnableAutoOffline ( int device );int ataDisableAutoOffline (int device );/* S.M.A.R.T. test commands */int ataSmartOfflineTest (int device);int ataSmartExtendSelfTest (int device);int ataSmartShortSelfTest (int device);int ataSmartShortCapSelfTest (int device);int ataSmartExtendCapSelfTest (int device);int ataSmartSelfTestAbort (int device);// Returns the latest compatibility of ATA/ATAPI Version the device// supports. Returns -1 if Version command is not supportedint ataVersionInfo (const char **description, struct ata_identify_device *drive, unsigned short *minor);// If SMART supported, this is guaranteed to return 1 if SMART is enabled, else 0.int ataDoesSmartWork(int device);// returns 1 if SMART supported, 0 if not supported or can't tellint ataSmartSupport ( struct ata_identify_device *drive);// Return values:// 1: SMART enabled// 0: SMART disabled// -1: can't tell if SMART is enabled -- try issuing ataDoesSmartWork command to seeint ataIsSmartEnabled(struct ata_identify_device *drive);/* Check SMART for Threshold failure */// onlyfailed=0 : are or were any age or prefailure attributes <= threshold// onlyfailed=1: are any prefailure attributes <= threshold nowint ataCheckSmart ( struct ata_smart_values *data, struct ata_smart_thresholds_pvt *thresholds, int onlyfailed);int ataSmartStatus2(int device);// int isOfflineTestTime ( struct ata_smart_values data)// returns S.M.A.R.T. Offline Test Time in secondsint isOfflineTestTime ( struct ata_smart_values *data);int isShortSelfTestTime ( struct ata_smart_values *data);int isExtendedSelfTestTime ( struct ata_smart_values *data);int isSmartErrorLogCapable(struct ata_smart_values *data, struct ata_identify_device *identity);int isSmartTestLogCapable(struct ata_smart_values *data, struct ata_identify_device *identity);int isGeneralPurposeLoggingCapable(struct ata_identify_device *identity);int isSupportExecuteOfflineImmediate ( struct ata_smart_values *data);int isSupportAutomaticTimer ( struct ata_smart_values *data);int isSupportOfflineAbort ( struct ata_smart_values *data);int isSupportOfflineSurfaceScan ( struct ata_smart_values *data);int isSupportSelfTest (struct ata_smart_values *data);int isSupportConveyanceSelfTest(struct ata_smart_values *data);int isSupportSelectiveSelfTest(struct ata_smart_values *data);inline bool isSCTCapable(const ata_identify_device *drive) { return !!(drive->words088_255[206-88] & 0x01); } // 0x01 = SCT supportinline bool isSCTFeatureControlCapable(const ata_identify_device *drive) { return ((drive->words088_255[206-88] & 0x11) == 0x11); } // 0x10 = SCT Feature Control supportinline bool isSCTDataTableCapable(const ata_identify_device *drive) { return ((drive->words088_255[206-88] & 0x21) == 0x21); } // 0x20 = SCT Data Table supportint ataSmartTest(int device, int testtype, struct ata_smart_values *data, uint64_t num_sectors);int TestTime(struct ata_smart_values *data,int testtype);// Prints the raw value (with appropriate formatting) into the// character string out.int64_t ataPrintSmartAttribRawValue(char *out, struct ata_smart_attribute *attribute, unsigned char *defs);// Prints Attribute Name for standard SMART attributes. Writes a// 30 byte string with attribute name into outputvoid ataPrintSmartAttribName(char *output, unsigned char id, unsigned char *definitions);// This checks the n'th attribute in the attribute list, NOT the// attribute with id==n. If the attribute does not exist, or the// attribute is > threshold, then returns zero. If the attribute is// <= threshold (failing) then we the attribute number if it is a// prefail attribute. Else we return minus the attribute number if it// is a usage attribute.int ataCheckAttribute(struct ata_smart_values *data, struct ata_smart_thresholds_pvt *thresholds, int n);// External handler function, for when a checksum is not correct. Can// simply return if no action is desired, or can print error messages// as needed, or exit. Is passed a string with the name of the Data// Structure with the incorrect checksum.void checksumwarning(const char *string);// Returns raw value of Attribute with ID==id. This will be in the// range 0 to 2^48-1 inclusive. If the Attribute does not exist,// return -1.int64_t ATAReturnAttributeRawValue(unsigned char id, struct ata_smart_values *data);// Return Temperature Attribute raw value selected according to possible// non-default interpretations. If the Attribute does not exist, return 0unsigned char ATAReturnTemperatureValue(/*const*/ struct ata_smart_values *data, const unsigned char *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 256extern const char *vendorattributeargs[];// function to parse pairs like "9,minutes" or "220,temp". See end of// extern.h for definition of defs[]. Returns 0 if pair recognized,// else 1 if there is a problem. Allocates memory for array if the// array address is *defs==NULL.int parse_attribute_def(char *pair, unsigned char **defs);// Function to return a string containing a list of the arguments in// vendorattributeargs[]. Returns NULL if the required memory can't// be allocated.char *create_vendor_attribute_arg_list(void);// These are two of the functions that are defined in os_*.c and need// to be ported to get smartmontools onto another OS.int ata_command_interface(int device, smart_command_set command, int select, char *data);int escalade_command_interface(int fd, int escalade_port, int escalade_type, smart_command_set command, int select, char *data);int marvell_command_interface(int device, smart_command_set command, int select, char *data);int highpoint_command_interface(int device, smart_command_set command, int select, char *data);// "smartctl -r ataioctl,2 ..." output parser pseudo-deviceint parsedev_open(const char * name);void parsedev_close(int fd);// Optional functions of os_*.c#ifdef HAVE_ATA_IDENTIFY_IS_CACHED// Return true if OS caches the ATA identify sectorint ata_identify_is_cached(int fd);#endif// This function is exported to give low-level capabilityint smartcommandhandler(int device, smart_command_set command, int select, char *data);// Utility routines.void swap2(char *location);void swap4(char *location);void swap8(char *location);// Typesafe variants using overloadinginline void swapx(unsigned short * p) { swap2((char*)p); }inline void swapx(unsigned int * p) { swap4((char*)p); }inline void swapx(uint64_t * p) { swap8((char*)p); }#endif /* ATACMDS_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -