diff --git a/libscsicmd/.gitignore b/libscsicmd/.gitignore index ab60f53..8a708a1 100644 --- a/libscsicmd/.gitignore +++ b/libscsicmd/.gitignore @@ -3,8 +3,6 @@ .gdb_history tags libscsicmd.a -include/ata_parse.h -smartdb_gen.c ata_identify ata_identify_dump.[ch] ata_smart_return_status diff --git a/libscsicmd/README.md b/libscsicmd/README.md index bae9d9a..84b4352 100644 --- a/libscsicmd/README.md +++ b/libscsicmd/README.md @@ -10,10 +10,10 @@ tries to be OS agnostic. Build ===== -The build system is using [ninja-build](https://martine.github.io/ninja/), you need to get it before you can build. +The build system is using cmake, you need to get it before you can build. To build, run: - ./configure && ninja + cmake . && make Author ====== diff --git a/libscsicmd/include/ata_parse.h b/libscsicmd/include/ata_parse.h new file mode 100644 index 0000000..d63f685 --- /dev/null +++ b/libscsicmd/include/ata_parse.h @@ -0,0 +1,316 @@ +/* Generated file, do not edit */ +#ifndef ATA_PARSE_H +#define ATA_PARSE_H +#include "ata.h" +static inline bool ata_get_ata_identify_smart_enabled(const char *buf) { + ata_word_t val = ata_get_word(buf, 85); + return val & (1 << 0); +} + +static inline bool ata_get_ata_identify_cfast_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 69); + return val & (1 << 15); +} + +static inline bool ata_get_ata_identify_sct_write_same_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 206); + return val & (1 << 2); +} + +static inline bool ata_get_ata_identify_lps_misalignment_reporting_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 69); + return val & (1 << 13); +} + +static inline bool ata_get_ata_identify_extended_number_of_user_addressable_sectors(const char *buf) { + ata_word_t val = ata_get_word(buf, 69); + return val & (1 << 3); +} + +static inline bool ata_get_ata_identify_sense_data_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 119); + return val & (1 << 6); +} + +static inline bool ata_get_ata_identify_fields_valid_words_64_70(const char *buf) { + ata_word_t val = ata_get_word(buf, 53); + return val & (1 << 1); +} + +static inline bool ata_get_ata_identify_crypto_scramble_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 59); + return val & (1 << 13); +} + +static inline bool ata_get_ata_identify_rzat_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 69); + return val & (1 << 5); +} + +static inline bool ata_get_ata_identify_address_48bit_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 83); + return val & (1 << 10); +} + +static inline bool ata_get_ata_identify_set_max_set_password_dma_and_set_max_unlock_dma_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 69); + return val & (1 << 9); +} + +static inline bool ata_get_ata_identify_volatile_write_cache_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 82); + return val & (1 << 5); +} + +static inline bool ata_get_ata_identify_standby_timer_values_settable(const char *buf) { + ata_word_t val = ata_get_word(buf, 49); + return val & (1 << 13); +} + +static inline bool ata_get_ata_identify_sata_dma_setup_auto_activation_enabled(const char *buf) { + ata_word_t val = ata_get_word(buf, 79); + return val & (1 << 2); +} + +static inline void ata_get_ata_identify_fw_rev(const char *buf, char *out) { + ata_get_string(buf, 23, 26, out); +} + +static inline bool ata_get_ata_identify_write_buffer_dma_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 69); + return val & (1 << 10); +} + +static inline bool ata_get_ata_identify_major_version_ata_atapi_6(const char *buf) { + ata_word_t val = ata_get_word(buf, 80); + return val & (1 << 6); +} + +static inline bool ata_get_ata_identify_major_version_ata_atapi_5(const char *buf) { + ata_word_t val = ata_get_word(buf, 80); + return val & (1 << 5); +} + +static inline bool ata_get_ata_identify_sct_error_recovery_control_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 206); + return val & (1 << 3); +} + +static inline bool ata_get_ata_identify_block_erase_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 59); + return val & (1 << 15); +} + +static inline bool ata_get_ata_identify_sata_software_settings_preservation_enabled(const char *buf) { + ata_word_t val = ata_get_word(buf, 79); + return val & (1 << 6); +} + +static inline bool ata_get_ata_identify_dma_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 49); + return val & (1 << 8); +} + +static inline bool ata_get_ata_identify_write_uncorrectable_enabled(const char *buf) { + ata_word_t val = ata_get_word(buf, 120); + return val & (1 << 2); +} + +static inline bool ata_get_ata_identify_sct_command_transport_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 206); + return val & (1 << 0); +} + +static inline bool ata_get_ata_identify_not_ata_device(const char *buf) { + ata_word_t val = ata_get_word(buf, 0); + return val & (1 << 15); +} + +static inline bool ata_get_ata_identify_read_buffer_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 82); + return val & (1 << 13); +} + +static inline bool ata_get_ata_identify_read_buffer_dma_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 69); + return val & (1 << 11); +} + +static inline bool ata_get_ata_identify_address_28bit_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 69); + return val & (1 << 6); +} + +static inline bool ata_get_ata_identify_download_microcode_dma_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 69); + return val & (1 << 8); +} + +static inline bool ata_get_ata_identify_mandatory_power_management_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 82); + return val & (1 << 3); +} + +static inline bool ata_get_ata_identify_fields_valid_word_88(const char *buf) { + ata_word_t val = ata_get_word(buf, 53); + return val & (1 << 2); +} + +static inline bool ata_get_ata_identify_packet_feature_set_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 82); + return val & (1 << 4); +} + +static inline bool ata_get_ata_identify_smart_self_test_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 84); + return val & (1 << 1); +} + +static inline bool ata_get_ata_identify_sata_in_order_data_delivery_enabled(const char *buf) { + ata_word_t val = ata_get_word(buf, 79); + return val & (1 << 4); +} + +static inline bool ata_get_ata_identify_major_version_acs_2(const char *buf) { + ata_word_t val = ata_get_word(buf, 80); + return val & (1 << 9); +} + +static inline bool ata_get_ata_identify_encrypt_all_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 69); + return val & (1 << 4); +} + +static inline bool ata_get_ata_identify_iordy_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 49); + return val & (1 << 11); +} + +static inline bool ata_get_ata_identify_nop_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 82); + return val & (1 << 14); +} + +static inline bool ata_get_ata_identify_sata_device_initiated_power_management_enabled(const char *buf) { + ata_word_t val = ata_get_word(buf, 79); + return val & (1 << 3); +} + +static inline bool ata_get_ata_identify_response_incomplete(const char *buf) { + ata_word_t val = ata_get_word(buf, 0); + return val & (1 << 2); +} + +static inline bool ata_get_ata_identify_sata_automatic_partial_to_slumber_transitions_enabled(const char *buf) { + ata_word_t val = ata_get_word(buf, 79); + return val & (1 << 7); +} + +static inline bool ata_get_ata_identify_sct_feature_control_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 206); + return val & (1 << 4); +} + +static inline bool ata_get_ata_identify_major_version_ata_8_acs(const char *buf) { + ata_word_t val = ata_get_word(buf, 80); + return val & (1 << 8); +} + +static inline bool ata_get_ata_identify_trusted_computing_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 48); + return val & (1 << 0); +} + +static inline bool ata_get_ata_identify_sanitize_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 59); + return val & (1 << 12); +} + +static inline bool ata_get_ata_identify_non_volatile_cache(const char *buf) { + ata_word_t val = ata_get_word(buf, 69); + return val & (1 << 2); +} + +static inline void ata_get_ata_identify_serial_number(const char *buf, char *out) { + ata_get_string(buf, 10, 19, out); +} + +static inline ata_longword_t ata_get_ata_identify_total_addressable_sectors_28bit(const char *buf) { + return ata_get_longword(buf, 60); +} + +static inline void ata_get_ata_identify_model(const char *buf, char *out) { + ata_get_string(buf, 27, 46, out); +} + +static inline bool ata_get_ata_identify_overwrite_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 59); + return val & (1 << 14); +} + +static inline bool ata_get_ata_identify_write_uncorrectable_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 119); + return val & (1 << 2); +} + +static inline bool ata_get_ata_identify_smart_error_logging_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 84); + return val & (1 << 0); +} + +static inline bool ata_get_ata_identify_sense_data_enabled(const char *buf) { + ata_word_t val = ata_get_word(buf, 120); + return val & (1 << 6); +} + +static inline bool ata_get_ata_identify_smart_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 82); + return val & (1 << 0); +} + +static inline bool ata_get_ata_identify_sct_data_tables_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 206); + return val & (1 << 5); +} + +static inline bool ata_get_ata_identify_major_version_ata_atapi_7(const char *buf) { + ata_word_t val = ata_get_word(buf, 80); + return val & (1 << 7); +} + +static inline bool ata_get_ata_identify_iordy_disable_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 49); + return val & (1 << 10); +} + +static inline bool ata_get_ata_identify_sata_non_zero_buffer_offsets_enabled(const char *buf) { + ata_word_t val = ata_get_word(buf, 79); + return val & (1 << 1); +} + +static inline bool ata_get_ata_identify_sata_hardware_feature_control_enabled(const char *buf) { + ata_word_t val = ata_get_word(buf, 79); + return val & (1 << 5); +} + +static inline bool ata_get_ata_identify_write_buffer_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 82); + return val & (1 << 12); +} + +static inline bool ata_get_ata_identify_drat_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 69); + return val & (1 << 14); +} + +static inline bool ata_get_ata_identify_read_look_ahead_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 82); + return val & (1 << 6); +} + +static inline bool ata_get_ata_identify_security_feature_set_supported(const char *buf) { + ata_word_t val = ata_get_word(buf, 82); + return val & (1 << 1); +} + +#endif diff --git a/libscsicmd/regen.sh b/libscsicmd/regen.sh new file mode 100755 index 0000000..2471830 --- /dev/null +++ b/libscsicmd/regen.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +echo "Regenerate generated files" + +src/smartdb/smartdb_gen_c.py src/smartdb/smartdb.xml > src/smartdb/smartdb_gen.c +git add src/smartdb/smartdb_gen.c + +structs/ata_struct_2_h.py structs/ata_identify.yaml > include/ata_parse.h +git add include/ata_parse.h diff --git a/libscsicmd/src/CMakeLists.txt b/libscsicmd/src/CMakeLists.txt index 11f641d..c10e2eb 100644 --- a/libscsicmd/src/CMakeLists.txt +++ b/libscsicmd/src/CMakeLists.txt @@ -1,10 +1 @@ -add_custom_command(OUTPUT smartdb/smartdb_gen.c - COMMAND smartdb/smartdb_gen_c.py smartdb/smartdb.xml > smartdb/smartdb_gen.c - DEPENDS smartdb/smartdb_gen_c.py smartdb/smartdb.xml - ) -add_custom_target(ata_parse.h - COMMAND ../structs/ata_struct_2_h.py ../structs/ata_identify.yaml > ../include/ata_parse.h - DEPENDS ../structs/ata_struct_2_h.py ../structs/ata_identify.yaml) - add_library(scsicmd STATIC ata.c ata_smart.c cdb.c parse_inquiry.c parse_read_cap.c parse_sense.c str_map.c smartdb/smartdb.c smartdb/smartdb_gen.c) -add_dependencies(scsicmd ata_parse.h) diff --git a/libscsicmd/src/smartdb/smartdb_gen.c b/libscsicmd/src/smartdb/smartdb_gen.c new file mode 100644 index 0000000..8006017 --- /dev/null +++ b/libscsicmd/src/smartdb/smartdb_gen.c @@ -0,0 +1,39 @@ +#include "smartdb.h" +static const smart_table_t defaults = { +.num_attrs = 26, +.attrs = { +{.id=1, .type=SMART_ATTR_TYPE_NONE, .name="Raw Read Error Rate", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, +{.id=2, .type=SMART_ATTR_TYPE_NONE, .name="Throughput Performance", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, +{.id=3, .type=SMART_ATTR_TYPE_NONE, .name="Spin Up Time", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, +{.id=4, .type=SMART_ATTR_TYPE_NONE, .name="Start/Stop Count", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, +{.id=5, .type=SMART_ATTR_TYPE_REALLOC, .name="Reallocated Sectors Count", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, +{.id=7, .type=SMART_ATTR_TYPE_NONE, .name="Seek Error Rate", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, +{.id=8, .type=SMART_ATTR_TYPE_NONE, .name="Seek Time Performance", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, +{.id=9, .type=SMART_ATTR_TYPE_POH, .name="Power On Hours", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, +{.id=10, .type=SMART_ATTR_TYPE_NONE, .name="Spin Retry Count", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, +{.id=11, .type=SMART_ATTR_TYPE_NONE, .name="Drive Calibration Retry Count", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, +{.id=12, .type=SMART_ATTR_TYPE_NONE, .name="Device Power Cycle Count", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, +{.id=13, .type=SMART_ATTR_TYPE_NONE, .name="Read Soft Error Rate", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, +{.id=191, .type=SMART_ATTR_TYPE_NONE, .name="G Sense Error Rate", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, +{.id=192, .type=SMART_ATTR_TYPE_NONE, .name="Power Off Retract Count", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, +{.id=193, .type=SMART_ATTR_TYPE_NONE, .name="Load/Unload Cycle Count", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, +{.id=194, .type=SMART_ATTR_TYPE_TEMP, .name="Temperature", .raw=SMART_ATTR_RAW_DEC48, .offset=150}, +{.id=195, .type=SMART_ATTR_TYPE_NONE, .name="Hardware ECC Recovered", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, +{.id=196, .type=SMART_ATTR_TYPE_NONE, .name="Reallocation Event Count", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, +{.id=197, .type=SMART_ATTR_TYPE_REALLOC_PENDING, .name="Pending Sector Reallocation Count", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, +{.id=198, .type=SMART_ATTR_TYPE_NONE, .name="Off-Line Scan Uncorrecable Sector Count", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, +{.id=199, .type=SMART_ATTR_TYPE_CRC_ERRORS, .name="CRC Error Count", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, +{.id=200, .type=SMART_ATTR_TYPE_NONE, .name="Multi-zone Error Rate", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, +{.id=240, .type=SMART_ATTR_TYPE_NONE, .name="Head Flying Hours", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, +{.id=241, .type=SMART_ATTR_TYPE_NONE, .name="Total LBAs Written", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, +{.id=242, .type=SMART_ATTR_TYPE_NONE, .name="Total LBAs Read", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, +{.id=254, .type=SMART_ATTR_TYPE_NONE, .name="Free Fall Sensor", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, +} +}; +const smart_table_t * smart_table_for_disk(const char *vendor, const char *model, const char *firmware) +{ +(void)vendor; +(void)model; +(void)firmware; +return &defaults; +}