├── .github └── workflows │ └── cmake-single-platform.yml ├── .gitignore ├── CMakeLists.txt ├── COPYING ├── DEVELOP.md ├── Documentation ├── .gitignore └── diskscan.1.in ├── README.md ├── arch ├── arch-freebsd.c ├── arch-generic.c ├── arch-linux.c ├── arch-linux.h ├── arch-posix.c └── arch-posix.h ├── cli ├── cli.c └── verbose.c ├── diskscan.c ├── distclean.sh ├── hdrhistogram ├── .gitignore ├── CMakeLists.txt ├── COPYING.txt ├── LICENSE.txt ├── README.md ├── examples │ ├── CMakeLists.txt │ ├── hdr_decoder.c │ └── hiccup.c ├── ide │ └── codestyle.jar ├── src │ ├── CMakeLists.txt │ ├── hdr_encoding.c │ ├── hdr_encoding.h │ ├── hdr_histogram.c │ ├── hdr_histogram.h │ ├── hdr_histogram_log.c │ ├── hdr_histogram_log.h │ ├── hdr_interval_recorder.c │ ├── hdr_interval_recorder.h │ ├── hdr_tests.h │ ├── hdr_time.h │ ├── hdr_writer_reader_phaser.c │ └── hdr_writer_reader_phaser.h └── test │ ├── CMakeLists.txt │ ├── hdr_histogram_log_test.c │ ├── hdr_histogram_perf.c │ ├── hdr_histogram_test.c │ ├── hiccup.140623.1028.10646.hlog │ ├── jHiccup-2.0.1.logV0.hlog │ ├── jHiccup-2.0.6.logV1.hlog │ ├── jHiccup-2.0.7S.logV2.hlog │ └── minunit.h ├── include ├── arch.h ├── cli.h ├── compiler.h ├── disk.h ├── diskscan.h ├── median.h └── verbose.h ├── lib ├── data.c ├── data.h ├── disk.c ├── diskscan.c ├── sha1.c ├── sha1.h ├── system_id.c ├── system_id.h └── verbose.c ├── libscsicmd ├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── afl │ └── testcase │ │ ├── 186704e9f39832c4c7b4f2ab71c52762017bd728 │ │ ├── 1b5fac8682806d6e823c301159d6da81e30f421a │ │ ├── 28eeac63bfcf7ad2126d2eddcdc04019270075ec │ │ ├── 2b34251f3421af9a5c53a41f7e27f1cc3e8a13b0 │ │ ├── 39c99f32ec43d6ee12857a64e031114ae7cf23cd.csv │ │ ├── 4941885df82498d8ca26375728606d41be818e27 │ │ ├── 554ff10f0a6f35849db7e44176aa94c6dc232872.csv │ │ ├── 5b7d04cbfbe29ec8f91526131c87e7cc8e9ea10e │ │ ├── 617ce3a43c7dbb1ba99a422ce455c1b55d2260b4.csv │ │ ├── 6184436113637747407bf86315ebd987300b8799 │ │ ├── 657af263aa78ee4d6b755df9e00a159d5c88dc2a.csv │ │ ├── 745f69394ad87d7d234e796b1a54a31f970e2510.csv │ │ ├── 7c597125d72d146425d1899f6512b82df99b59c1 │ │ ├── 7e1e393db35bd119ab38a395829ff5deadd9501a │ │ ├── 7eeaad7ca0a2197d1283c87d441a15f6c8d5e6f6 │ │ ├── 801bc5987bfe420b04e07eb1cd5ae0462a0b750c │ │ ├── 8329e3313860bfd6b8dd1252b4a4542d4c791f13.csv │ │ ├── 86f870fdeb8e99954869aaf1b58e456109e2e6c8 │ │ ├── 90548a1ef4bae0b9b7382497097a01691333fb4f │ │ ├── 9062ca40d53bbf790d9338ed79b5215ca76178d2.csv │ │ ├── 961ce3b94d711105a238b82068012e5b765b4027 │ │ ├── 9c3040be62f1785b6387524185ae7508966a8fca │ │ ├── 9da9f3b23df2a728a486968d9e4f4a87aff34bf6.csv │ │ ├── a051877bf52e199210ffd96778f7698e3dc6978e.csv │ │ ├── a3a3b5b0ea540bc579228dfe70b21f40d9c0df96 │ │ ├── a4005cb54f820f0dc3889aab343ea1698b1dd5f4.csv │ │ ├── a6b72fc2c30cf1d9ff74a2d5054bcb5dca317c15 │ │ ├── a750591769e551117e3144c8927a05d96fdfb362 │ │ ├── b2eeafbc752b681e5d68332192c8097ef43ab687.csv │ │ ├── b40a88e1e4a0e0044936b2e61de5364d48b16e8c.csv │ │ ├── c144c7638bb08162db1ae53954e6cd20e66474f7 │ │ ├── ca52cd17cb1a061767830cb4e49867be9b637e56 │ │ ├── ce03e25003a16fc03abb3d4f337a39e622962c60 │ │ ├── d2f9abc5e26020e42b45a32fcf3777cc61ea711c │ │ ├── e71ac2a14ce3dd789a00eae0c656b36e2c07186a │ │ ├── ebc80a44e5ef0a66fddb29c48373701b2eeb5227 │ │ ├── ee66ad0b8b05525c54c4538059714a92646c39fb │ │ ├── eebceb65beacbe25d0db149e5c37198ee5be1912.csv │ │ ├── ef22fafdd3041dc08043fe2bb908e96dffa34ff5 │ │ ├── f007593acbf7f63773efa1b65ef61da7fcefbb34 │ │ ├── f3492a44323a0bf7bea4e59b536feaf7620b8e8b │ │ ├── f40e3999c3fe73cd2e50083874537ec000697cb7 │ │ ├── f5272bcea41574f9cd663f33334c530abcca01d7 │ │ ├── f7db47bebdfb5888fae0fbe826b37df33a450292 │ │ ├── f7faaa230cdb97e1aec1e5ca75f89b7ea8b78726 │ │ ├── fb0082d5df4c4f237f65ac2c2717ae46408c17b8.csv │ │ ├── fbc7b5cc87f1afa84d70c82f152761258a3b0ca6 │ │ ├── fc52fecd84a8f8a478b99b4965333a7f9dfa002c │ │ ├── fcc19a8cc98ada27c4b6a605adca5bb497ad618e │ │ ├── fcd8ce757f7d3f54ab0ee3d01007e0a6d70fa288 │ │ ├── febd83d39f830202ca6081514960b4242e536df7 │ │ ├── fec38c54692c2fcff269370fc1bbb9e598b821a7 │ │ ├── fec50c6c3f5486958b33beada06857deeff177dd.csv │ │ ├── fedb716d47c930bafffff38b6c274ce9202187ac │ │ ├── ff0232f5144d65579feeccb6b65687c5056501a7 │ │ ├── ff3242c96b948a6ded16dd8ae51b1e61c40c5a66 │ │ ├── ff5a0c3111af229b7f4ec8c4a38d82ccf7e553a2 │ │ ├── ff5f50f7b5d36b765da768ef583a8b289be09a7e.csv │ │ ├── ff82315f17a9d582afd6aba974c222e00d14af15 │ │ ├── ff980b7b6e39f929b8ddb08e419a2904abd44b33 │ │ ├── ffb313726fc6fa8b68381e5df22e960cb623b62c.csv │ │ ├── ffe9cd6ca4dbbdd2b2429c8d8023183b84c2962f │ │ ├── ffefa3f6034cc5680792a8cae855bc7a2d9f9019 │ │ ├── fff9db19407d43fdb18735c075071a866a5f0795 │ │ ├── fffa5f13587a7e46023238c9e7db91fd61414105 │ │ ├── id:000001,sig:11,src:005156,op:ext_AO,pos:34 │ │ ├── id:000001,src:000141,op:arith8,pos:118,val:-34 │ │ ├── id:000002,src:000200,op:ext_AO,pos:571 │ │ ├── id:000003,src:000314,op:flip1,pos:19 │ │ ├── id:000005,sig:11,src:005234,op:havoc,rep:2 │ │ ├── id:000005,src:000445,op:flip1,pos:132 │ │ ├── id:000007,sig:11,src:005483,op:flip2,pos:43 │ │ ├── id:000008,src:001208,op:flip1,pos:89 │ │ ├── id:000013,sig:11,src:005882,op:havoc,rep:2 │ │ ├── id:000015,src:001216,op:flip1,pos:229 │ │ ├── id:000018,sig:11,src:001807,op:flip1,pos:93 │ │ ├── id:000018,src:001179,op:ext_AO,pos:826 │ │ ├── id:000019,sig:11,src:001807,op:flip1,pos:670 │ │ ├── id:000019,src:001231,op:flip1,pos:72 │ │ ├── id:000020,sig:11,src:001807,op:flip1,pos:2325 │ │ ├── id:000021,sig:11,src:001807,op:flip2,pos:238 │ │ ├── log_sense_9bd3419f85d952cf54a38196fc0775a2bfa4c6ff.csv │ │ ├── log_sense_ac03383386fa3d77d3d460480a52e0b99a1c580e.csv │ │ ├── log_sense_c52c16bd44de5cf72ba1a55c0b6258349a74e5d6.csv │ │ ├── log_sense_d192aef3ac66f84b8996edeb95ef1e7e9d6660cb.csv │ │ ├── log_sense_dc08fbd86ddd3f34a56532faf9b46f0ae135e644.csv │ │ ├── log_sense_f2ca65053fcb0a0b0a479e181fa8b497beb40d9c.csv │ │ ├── log_sense_fb4080b69b8ca7d50d16f424305467a18d8eded9.csv │ │ ├── log_sense_fc58600bcf8dc103f911bb2a6a867ab2c8e42fe2.csv │ │ ├── log_sense_ffe62c433d9a885d2a5670ff890f5b00089739aa.csv │ │ └── log_sense_ffee0af0b99b68b9d287e6f65ad08a4e11967daa.csv ├── include │ ├── asc_num_list.h │ ├── ata.h │ ├── ata_parse.h │ ├── ata_smart.h │ ├── parse_extended_inquiry.h │ ├── parse_log_sense.h │ ├── parse_mode_sense.h │ ├── parse_read_defect_data.h │ ├── parse_receive_diagnostics.h │ ├── scsicmd.h │ ├── scsicmd_utils.h │ ├── sense_key_list.h │ └── smartdb.h ├── regen.sh ├── src │ ├── CMakeLists.txt │ ├── ata.c │ ├── ata_smart.c │ ├── cdb.c │ ├── log_sense.c │ ├── parse.c │ ├── parse_inquiry.c │ ├── parse_read_cap.c │ ├── parse_sense.c │ ├── smartdb │ │ ├── smartdb.c │ │ ├── smartdb.xml │ │ ├── smartdb_gen.c │ │ └── smartdb_gen_c.py │ └── str_map.c ├── structs │ ├── asc-num-to-list │ ├── asc-num.txt │ ├── ata_identify.yaml │ ├── ata_struct_2_c_dump.py │ ├── ata_struct_2_h.py │ ├── ata_struct_2_h_dump.py │ └── update-asc-num └── test │ ├── CMakeLists.txt │ ├── ata_check_power_mode.c │ ├── ata_identify.c │ ├── ata_smart_read_data.c │ ├── ata_smart_return_status.c │ ├── collect_raw_data.c │ ├── main.c │ ├── main.h │ ├── parse_scsi.c │ ├── samples │ ├── breakout.py │ └── parse_file.py │ ├── scsi_inquiry.c │ ├── scsi_log_sense.c │ ├── scsi_mode_sense.c │ ├── scsi_read_capacity_10.c │ ├── scsi_read_capacity_16.c │ ├── scsi_receive_diagnostics.c │ ├── sense_decode.c │ ├── sense_dump.c │ └── sense_dump.h └── progressbar ├── .gitignore ├── Doxyfile ├── LICENSE ├── Makefile ├── README.mdown ├── example_output ├── demo.png └── demo@2x.png ├── include ├── progressbar.h └── statusbar.h ├── lib ├── progressbar.c └── statusbar.c ├── package.json └── test └── demo.c /.github/workflows/cmake-single-platform.yml: -------------------------------------------------------------------------------- 1 | # This starter workflow is for a CMake project running on a single platform. There is a different starter workflow if you need cross-platform coverage. 2 | # See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-multi-platform.yml 3 | name: CMake on a single platform 4 | 5 | on: 6 | push: 7 | branches: [ "master" ] 8 | pull_request: 9 | branches: [ "master" ] 10 | 11 | env: 12 | # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.) 13 | BUILD_TYPE: Release 14 | 15 | jobs: 16 | build: 17 | # The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac. 18 | # You can convert this to a matrix build if you need cross-platform coverage. 19 | # See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix 20 | runs-on: ubuntu-latest 21 | 22 | steps: 23 | - uses: actions/checkout@v3 24 | 25 | - name: Configure CMake 26 | # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. 27 | # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type 28 | run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} 29 | 30 | - name: Build 31 | # Build your program with the given configuration 32 | run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} 33 | 34 | - name: Test 35 | working-directory: ${{github.workspace}}/build 36 | # Execute tests defined by the CMake configuration. 37 | # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail 38 | run: ctest -C ${{env.BUILD_TYPE}} 39 | 40 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.a 3 | *.d 4 | diskscan 5 | arch/arch.c 6 | include/arch-internal.h 7 | arch/arch.id 8 | *~ 9 | CMakeCache.txt 10 | CMakeFiles 11 | cmake_install.cmake 12 | install_manifest.txt 13 | Makefile 14 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0.2) 2 | project(diskscan 3 | VERSION 0.19) 4 | 5 | export(PACKAGE diskscan) 6 | 7 | set(PACKAGE_VERSION ${PROJECT_VERSION}) 8 | 9 | # Default to a debug build 10 | if(NOT CMAKE_BUILD_TYPE) 11 | set(CMAKE_BUILD_TYPE Debug) 12 | endif(NOT CMAKE_BUILD_TYPE) 13 | 14 | # Pull in zlib 15 | find_package(ZLIB REQUIRED) 16 | 17 | # Ensure clock_gettime can build with or without -lrt as needed 18 | include(CheckLibraryExists) 19 | CHECK_LIBRARY_EXISTS(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME) 20 | if (NOT HAVE_CLOCK_GETTIME) 21 | set(CMAKE_EXTRA_INCLUDE_FILES time.h) 22 | CHECK_FUNCTION_EXISTS(clock_gettime HAVE_CLOCK_GETTIME) 23 | SET(CMAKE_EXTRA_INCLUDE_FILES) 24 | else() 25 | list(APPEND LIBS rt) 26 | endif() 27 | 28 | # Find tinfo for termcap functions 29 | INCLUDE (CheckIncludeFiles) 30 | CHECK_INCLUDE_FILES(termcap.h HAVE_TERMCAP_H) 31 | find_library(tinfo_LIBRARY NAMES tinfo curses) 32 | 33 | # Architecture files 34 | message("SYSTEM NAME: ${CMAKE_SYSTEM_NAME}") 35 | if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") 36 | set(ARCH_SRC "arch/arch-linux.c") 37 | set(ARCH_INCLUDE "arch/arch-linux.h") 38 | elseif (${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD") 39 | set(ARCH_SRC "arch/arch-freebsd.c") 40 | set(ARCH_INCLUDE "arch/arch-posix.h") 41 | elseif (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD") 42 | set(ARCH_SRC "arch/arch-freebsd.c") 43 | set(ARCH_INCLUDE "arch/arch-posix.h") 44 | else() 45 | set(ARCH_SRC "arch/arch-generic.c") 46 | set(ARCH_INCLUDE "arch/arch-posix.h") 47 | endif() 48 | 49 | add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/include/arch-internal.h 50 | COMMAND ln -fs ${CMAKE_CURRENT_SOURCE_DIR}/${ARCH_INCLUDE} ${CMAKE_CURRENT_SOURCE_DIR}/include/arch-internal.h 51 | ) 52 | 53 | # Build diskscan 54 | include_directories("include") 55 | add_compile_options(-Wall -Wextra -Wshadow -Wmissing-prototypes -Winit-self) 56 | add_definitions(-D_GNU_SOURCE -D_FORTIFY_SOURCE=2) 57 | add_definitions(-DVERSION="${PROJECT_VERSION}") 58 | include_directories(.) 59 | include_directories(progressbar/include) 60 | 61 | # Build libscsicmd for diskscan 62 | include_directories(libscsicmd/include) 63 | add_subdirectory(libscsicmd/src) 64 | 65 | # Build diskscan library 66 | add_library(diskscanlib STATIC lib/data.c lib/diskscan.c lib/sha1.c lib/system_id.c lib/verbose.c lib/disk.c 67 | hdrhistogram/src/hdr_histogram.c hdrhistogram/src/hdr_histogram_log.c 68 | hdrhistogram/src/hdr_encoding.c ${ARCH_SRC} ${CMAKE_CURRENT_SOURCE_DIR}/include/arch-internal.h) 69 | add_dependencies(diskscanlib scsicmd) 70 | 71 | # Build diskscan cli command 72 | add_executable(diskscan diskscan.c cli/cli.c cli/verbose.c progressbar/lib/progressbar.c) 73 | target_link_libraries(diskscan diskscanlib scsicmd m ${tinfo_LIBRARY} ${ZLIB_LIBRARIES} ${LIBS}) 74 | 75 | install(TARGETS diskscan 76 | RUNTIME DESTINATION bin) 77 | 78 | configure_file(Documentation/diskscan.1.in Documentation/diskscan.1) 79 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Documentation/diskscan.1 80 | DESTINATION share/man/man1 COMPONENT doc) 81 | -------------------------------------------------------------------------------- /DEVELOP.md: -------------------------------------------------------------------------------- 1 | # Developing 2 | 3 | ## Debug build 4 | 5 | To create a debug build you can tell cmake: 6 | 7 | cmake -DCMAKE_BUILD_TYPE=DEBUG . 8 | 9 | ## Updating Libraries 10 | 11 | Update libscsicmd: 12 | 13 | git subtree pull --squash --prefix libscsicmd https://github.com/baruch/libscsicmd master 14 | 15 | Update libprogressbar: 16 | 17 | git subtree pull --squash --prefix progressbar https://github.com/doches/progressbar master 18 | 19 | Update HdrHistogram: 20 | 21 | git subtree pull --squash --prefix hdrhistogram https://github.com/HdrHistogram/HdrHistogram_c master 22 | -------------------------------------------------------------------------------- /Documentation/.gitignore: -------------------------------------------------------------------------------- 1 | /*.1 2 | -------------------------------------------------------------------------------- /Documentation/diskscan.1.in: -------------------------------------------------------------------------------- 1 | .TH DISKSCAN 1 2013-10-25 "DiskScan @PACKAGE_VERSION@" "User Commands" 2 | .ad l 3 | .nh 4 | .SH NAME 5 | diskscan - scan a disk for failed and near failure sectors 6 | .SH SYNOPSIS 7 | \fBdiskscan\fR [options...] \fIblock_device\fR 8 | .SH DESCRIPTION 9 | \fBdiskscan\fR is intended to check a disk and find any bad sectors already present 10 | and assess it for any possible sectors that are in the process of going bad. 11 | The operation is all read-only and can cause no direct damage to the data on 12 | the disk. 13 | .PP 14 | diskscan reads the entire block device and notes the time it took to read a 15 | block. When there is an error it is immediately noted and also when there is a 16 | higher latency to read a block. A histogram of the block latency times is also 17 | given to assess the health of the disk. 18 | .PP 19 | The output of diskscan will show any serious errors or very high latency and 20 | will also emit an histogram at the end of the run in the form: 21 | .RS +4n 22 | .nf 23 | .PP 24 | I: Validating path /dev/sdg 25 | I: Opened disk /dev/sdg 26 | I: Scanning disk /dev/sdg 27 | Access time histogram: 28 | 1: 0 29 | 10: 0 30 | 100: 0 31 | 500: 120 32 | 1000: 0 33 | 2000: 1 34 | 3000: 0 35 | 4000: 0 36 | 5000: 0 37 | 6000: 0 38 | 7000: 0 39 | 8000: 0 40 | 9000: 0 41 | 10000: 0 42 | 15000: 0 43 | 20000: 0 44 | 25000: 0 45 | 30000: 0 46 | above that: 0 47 | I: Closed disk /dev/sdg 48 | .fi 49 | .RE 50 | .PP 51 | This means that all I/Os in this case were between 100 and 600 msec and there 52 | were 120 chunks being read. Current these chunks are 1MB in size. 53 | .SH OPTIONS 54 | \fB-v\fR, \fB--verbose\fR 55 | display verbose information from the workings of the scan 56 | use multiple times for increased verbosity. 57 | .PP 58 | \fB-f\fR, \fB--fix\fR 59 | Attempt to fix areas that are nearing failure. This should only be 60 | attempted on an unmounted block device and never on an inuse filesystem or 61 | corruption is likely. 62 | .PP 63 | \fB-s \fR, \fB--scan \fR 64 | Scan mode can be either \fBseq\fR or \fBrandom\fR, random reduces the chance that the 65 | disk will be able spend time to recover data before we try to access a sector 66 | but the seeks add noise to the latency measurement. Sequential test is the 67 | default and random test is still experimental with regard to its usefulness. 68 | .PP 69 | \fB-e \fR, \fB--size \fR 70 | Set the size in which the scan will be done, this must be a multiple of the sector size 71 | which is normally 512 bytes. 72 | .PP 73 | \fB-o \fR, \fB--output \fR 74 | Set the output file that the scan will generate. This is a JSON file with the 75 | summary and details about the exceptional events found during the scan. 76 | .PP 77 | \fB-r \fR, \fB--raw-log \fR 78 | Set the output file for the raw log which logs everything done and seen during 79 | the scan. This is a rather large file but it can help get the finer details of 80 | the scan progress and the disk behavior during the scan. This is too a JSON file. 81 | .SH "SEE ALSO" 82 | \fBbadblocks\fR(1), \fBfsck\fR(1) 83 | .SH AUTHOR 84 | Baruch Even 85 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DiskScan -- Scan HDD/SSD for failed and near failed sectors 2 | 3 | DiskScan is a Unix/Linux tool to scan a block device and check if there are 4 | unreadable sectors, in addition it uses read latency times as an assessment for 5 | a near failure as sectors that are problematic to read usually entail many 6 | retries. This can be used to assess the state of the disk and maybe decide on a 7 | replacement in advance to its imminent failure. The disk self test may or may 8 | not pick up on such clues depending on the disk vendor decision making logic. 9 | 10 | ## diskscan vs. badblocks 11 | 12 | badblocks is intended for a simple task, to find bad blocks in the media. diskscan is trying to say a lot more about the media, specifically it is trying not just to say where is a bad block but also what blocks are already deteriorated but still readable and also give information on the latency of reading each block which should help to give an overall assessment of the disk media. 13 | 14 | In essence badblocks looks for fatal issues already happening and diskscan is for upcoming issues that can be fixed. 15 | 16 | Also, badblocks is essentially obsolete in this day and age since the disks themselves will reallocate the data and there is no real need to map the bad blocks in the filesystem level anymore. 17 | 18 | # Supported Drives 19 | 20 | This tool is focused on SAS/SATA drives that work through the SCSI interface of the kernel. 21 | 22 | SD Cards and NVMe devices are not currently scannable with this tool. 23 | 24 | ## Build 25 | 26 | This project is using CMake, on Debian/Ubuntu it is as simple as: 27 | apt-get install cmake make libtinfo-dev libncurses5-dev zlib1g-dev python-yaml 28 | 29 | For RedHat/SuSe based distros you need to install ninja-build first and then: 30 | yum install compat-libtermcap libtermcap-devel cmake python-yaml zlib-devel 31 | 32 | A Makefile is provided to avoid learning the ninja commands and do the non-build stuff (install, etc.) 33 | 34 | To do the build: 35 | 36 | cmake . && make 37 | 38 | ## Install 39 | 40 | make install 41 | 42 | You can control the DESTDIR when building packages and PREFIX if /usr is not right. 43 | 44 | ## License 45 | 46 | diskscan is licensed under the GPL version 3 or later. 47 | -------------------------------------------------------------------------------- /arch/arch-freebsd.c: -------------------------------------------------------------------------------- 1 | #include "arch.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "arch-posix.c" 11 | #include 12 | 13 | int disk_dev_identify(disk_dev_t *dev, char *vendor, char *model, char *fw_rev, char *serial, bool *is_ata, unsigned char *ata_buf, unsigned *ata_buf_len) 14 | { 15 | (void)dev; 16 | strcpy(vendor, "UNKNOWN"); 17 | strcpy(model, "UNKNOWN"); 18 | strcpy(fw_rev, "UNKN"); 19 | strcpy(serial, "UNKNOWN"); 20 | *is_ata = 0; 21 | *ata_buf_len = 0; 22 | *ata_buf = 0; 23 | return 0; 24 | } 25 | 26 | int disk_dev_read_cap(disk_dev_t *dev, uint64_t *size_bytes, uint64_t *sector_size) 27 | { 28 | if (ioctl(dev->fd, DIOCGMEDIASIZE, size_bytes) < 0) { 29 | return -1; 30 | } 31 | 32 | if (ioctl(dev->fd, DIOCGSECTORSIZE, sector_size) < 0) { 33 | return -1; 34 | } 35 | 36 | return 0; 37 | } 38 | 39 | disk_mount_e disk_dev_mount_state(const char *path) 40 | { 41 | int num_mounts; 42 | struct statfs *mntbuf; 43 | disk_mount_e last_state; 44 | int i; 45 | 46 | num_mounts = getmntinfo(&mntbuf, MNT_WAIT); 47 | if (num_mounts == 0) { 48 | ERROR("Failed to get the mount information, errno=%d", errno); 49 | return DISK_MOUNTED_RW; 50 | } 51 | 52 | last_state = DISK_NOT_MOUNTED; 53 | for (i = 0; i < num_mounts; i++) { 54 | struct statfs *mnt = &mntbuf[i]; 55 | 56 | if (strncmp(path, mnt->f_mntfromname, strlen(path)) == 0) { 57 | disk_mount_e cur_state = DISK_NOT_MOUNTED; 58 | if (mnt->f_flags == MNT_RDONLY) 59 | cur_state = DISK_MOUNTED_RO; 60 | else 61 | cur_state = DISK_MOUNTED_RW; 62 | 63 | if (cur_state > last_state) 64 | last_state = cur_state; 65 | } 66 | } 67 | 68 | return last_state; 69 | } 70 | void mac_read(unsigned char *buf, int len) 71 | { 72 | struct ifreq ifr; 73 | struct ifconf ifc; 74 | char data[1024]; 75 | int success = 0; 76 | 77 | buf[0] = 0; 78 | 79 | int sock = socket(AF_INET, SOCK_DGRAM, 0); 80 | if (sock == -1) { 81 | return; 82 | }; 83 | 84 | ifc.ifc_len = sizeof(data); 85 | ifc.ifc_buf = data; 86 | if (ioctl(sock, SIOCGIFCONF, &ifc) == -1) { 87 | /* handle error */ 88 | goto Exit; 89 | } 90 | 91 | struct ifreq* it = ifc.ifc_req; 92 | const struct ifreq* const end = it + (ifc.ifc_len / sizeof(struct ifreq)); 93 | 94 | for (; it != end; ++it) { 95 | strcpy(ifr.ifr_name, it->ifr_name); 96 | if (ioctl(sock, SIOCGIFFLAGS, &ifr) == 0) { 97 | if (! (ifr.ifr_flags & IFF_LOOPBACK)) { // don't count loopback 98 | if (ioctl(sock, SIOCGIFMAC, &ifr) == 0) { 99 | success = 1; 100 | break; 101 | } 102 | } 103 | } 104 | else { /* handle error */ } 105 | } 106 | 107 | if (success) { 108 | memcpy(buf, ifr.ifr_ifru.ifru_data, len >= 6 ? 6 : len); 109 | } else { 110 | memset(buf, 0, len); 111 | } 112 | 113 | Exit: 114 | close(sock); 115 | } 116 | -------------------------------------------------------------------------------- /arch/arch-generic.c: -------------------------------------------------------------------------------- 1 | #include "arch.h" 2 | 3 | #include 4 | #include 5 | 6 | #include "arch-posix.c" 7 | 8 | int disk_dev_read_cap(disk_dev_t *dev, uint64_t *size_bytes, uint64_t *sector_size) 9 | { 10 | off_t end = lseek(dev->fd, 0, SEEK_END); 11 | 12 | if (end == (off_t)-1) 13 | return -1; 14 | 15 | *size_bytes = end; 16 | *sector_size = 512; 17 | 18 | return 0; 19 | } 20 | 21 | int disk_dev_identify(disk_dev_t *dev, char *vendor, char *model, char *fw_rev, char *serial, bool *is_ata, unsigned char *ata_buf, unsigned *ata_buf_len) 22 | { 23 | (void)dev; 24 | strcpy(vendor, "UNKNOWN"); 25 | strcpy(model, "UNKNOWN"); 26 | strcpy(fw_rev, "UNKN"); 27 | strcpy(serial, "UNKNOWN"); 28 | *is_ata = 0; 29 | *ata_buf_len = 0; 30 | *ata_buf = 0; 31 | return 0; 32 | } 33 | 34 | void mac_read(unsigned char *buf, int len) 35 | { 36 | (void)len; 37 | *buf = 0; 38 | } 39 | -------------------------------------------------------------------------------- /arch/arch-linux.h: -------------------------------------------------------------------------------- 1 | #ifndef ARCH_INTERNAL_LINUX_H 2 | #define ARCH_INTERNAL_LINUX_H 3 | 4 | struct disk_dev_t { 5 | int fd; 6 | uint32_t sector_size; 7 | }; 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /arch/arch-posix.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "verbose.h" 10 | #include "arch.h" 11 | 12 | bool disk_dev_open(disk_dev_t *dev, const char *path) 13 | { 14 | dev->fd = open(path, O_RDWR|O_DIRECT); 15 | if (dev->fd < 0) { 16 | INFO("Failed to open device %s with write permission, retrying without", path); 17 | dev->fd = open(path, O_RDONLY|O_DIRECT); 18 | } 19 | return dev->fd >= 0; 20 | } 21 | 22 | void disk_dev_close(disk_dev_t *dev) 23 | { 24 | close(dev->fd); 25 | dev->fd = -1; 26 | } 27 | 28 | ssize_t disk_dev_read(disk_dev_t *dev, uint64_t offset_bytes, uint32_t len_bytes, void *buf, io_result_t *io_res) 29 | { 30 | ssize_t ret = pread(dev->fd, buf, len_bytes, offset_bytes); 31 | if (ret == len_bytes) { 32 | io_res->data = DATA_FULL; 33 | io_res->error = ERROR_NONE; 34 | return ret; 35 | } else if (ret > 0) { 36 | io_res->data = DATA_PARTIAL; 37 | io_res->error = ERROR_NONE; 38 | return ret; 39 | } else if (ret == 0) { 40 | io_res->data = DATA_NONE; 41 | io_res->error = ERROR_NONE; 42 | return ret; 43 | } else { 44 | // ret < 0, i.e. error 45 | INFO("Error reading from disk, offset=%lu len=%u errno=%d (%s)", 46 | offset_bytes, len_bytes, errno, strerror(errno)); 47 | io_res->data = DATA_NONE; 48 | io_res->error = ERROR_UNCORRECTED; 49 | io_res->sense_len = 0; 50 | memset(&io_res->info, 0, sizeof(io_res->info)); 51 | return -1; 52 | } 53 | 54 | //TODO: Handle EINTR with a retry 55 | } 56 | 57 | ssize_t disk_dev_write(disk_dev_t *dev, uint64_t offset_bytes, uint32_t len_bytes, void *buf, io_result_t *io_res) 58 | { 59 | ssize_t ret = pwrite(dev->fd, buf, len_bytes, offset_bytes); 60 | if (ret == len_bytes) { 61 | io_res->data = DATA_FULL; 62 | io_res->error = ERROR_NONE; 63 | return ret; 64 | } else if (ret > 0) { 65 | io_res->data = DATA_PARTIAL; 66 | io_res->error = ERROR_NONE; 67 | return ret; 68 | } else if (ret == 0) { 69 | io_res->data = DATA_NONE; 70 | io_res->error = ERROR_NONE; 71 | return ret; 72 | } else { 73 | // ret < 0, i.e. error 74 | io_res->data = DATA_NONE; 75 | io_res->error = ERROR_UNCORRECTED; 76 | io_res->sense_len = 0; 77 | memset(&io_res->info, 0, sizeof(io_res->info)); 78 | return -1; 79 | } 80 | 81 | //TODO: Handle EINTR with a retry 82 | } 83 | 84 | void disk_dev_cdb_in(disk_dev_t *dev, unsigned char *cdb, unsigned cdb_len, unsigned char *buf, unsigned buf_size, unsigned *buf_read, unsigned char *sense, unsigned sense_size, unsigned *sense_read, io_result_t *io_res) 85 | { 86 | (void)sense_size; 87 | (void)sense; 88 | (void)buf_size; 89 | (void)buf; 90 | (void)cdb_len; 91 | (void)cdb; 92 | (void)dev; 93 | 94 | *sense_read = 0; 95 | *buf_read = 0; 96 | memset(&io_res, 0, sizeof(*io_res)); 97 | io_res->data = DATA_NONE; 98 | io_res->error = ERROR_NONE; 99 | } 100 | -------------------------------------------------------------------------------- /arch/arch-posix.h: -------------------------------------------------------------------------------- 1 | #ifndef ARCH_INTERNAL_POSIX_H 2 | #define ARCH_INTERNAL_POSIX_H 3 | 4 | struct disk_dev_t { 5 | int fd; 6 | }; 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /cli/verbose.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Baruch Even 3 | * 4 | * This file is part of DiskScan. 5 | * 6 | * DiskScan is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * DiskScan is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with DiskScan. If not, see . 18 | * 19 | */ 20 | 21 | #include "verbose.h" 22 | #include 23 | #include 24 | 25 | int verbose_extra_newline; 26 | 27 | void verbose_out(const char *fmt, ...) 28 | { 29 | va_list ap; 30 | if (verbose_extra_newline) 31 | printf("\n"); 32 | va_start(ap, fmt); 33 | vprintf(fmt, ap); 34 | va_end(ap); 35 | printf("\n"); 36 | } 37 | -------------------------------------------------------------------------------- /diskscan.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Baruch Even 3 | * 4 | * This file is part of DiskScan. 5 | * 6 | * DiskScan is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * DiskScan is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with DiskScan. If not, see . 18 | * 19 | */ 20 | 21 | #include "cli.h" 22 | 23 | int main(int argc, char **argv) 24 | { 25 | return diskscan_cli(argc, argv); 26 | } 27 | -------------------------------------------------------------------------------- /distclean.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # distclean.sh for diskscan 4 | # Copyright 2015 Joao Eriberto Mota Filho 5 | # v2015111402 6 | # This file can used under GPL-3+ license or BSD-3-Clause. 7 | 8 | PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 9 | 10 | PREFIX="." 11 | 12 | # Files and directories to remove 13 | 14 | OBJS=" CMakeFiles/ \ 15 | Makefile \ 16 | CMakeCache.txt \ 17 | Documentation/diskscan.1 \ 18 | cmake_install.cmake \ 19 | install_manifest.txt \ 20 | libscsicmd/src/CMakeFiles/ \ 21 | libscsicmd/src/Makefile \ 22 | libscsicmd/src/cmake_install.cmake \ 23 | tags" 24 | 25 | # Main procedures 26 | 27 | remove_files () { 28 | if [ -e "$PREFIX/$TARGET" ]; then 29 | echo "Removing $PREFIX/$TARGET" 30 | rm -rf "${PREFIX:?}/$TARGET" 31 | else 32 | echo "$PREFIX/$TARGET NOT FOUND." 33 | fi 34 | } 35 | 36 | # Distclean 37 | 38 | echo "DOING DISTCLEAN..." 39 | 40 | for TARGET in $OBJS 41 | do 42 | remove_files 43 | done 44 | 45 | echo "DONE." 46 | echo 47 | -------------------------------------------------------------------------------- /hdrhistogram/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | .idea 3 | out 4 | gh-pages 5 | HdrHistogram.iml 6 | .classpath 7 | .project 8 | .settings 9 | release.properties 10 | /bin 11 | alltests 12 | format_example 13 | *.a 14 | *.iml 15 | .sconsign.dblite 16 | *.o 17 | *.os 18 | .DS_Store 19 | build 20 | CMakeCache.txt 21 | CMakeFiles/ 22 | CPackConfig.cmake 23 | CPackSourceConfig.cmake 24 | CTestTestfile.cmake 25 | Makefile 26 | Testing/ 27 | cmake_install.cmake 28 | examples/CMakeFiles/ 29 | examples/CTestTestfile.cmake 30 | examples/Makefile 31 | examples/cmake_install.cmake 32 | examples/hdr_decoder 33 | examples/hiccup 34 | src/CMakeFiles/ 35 | src/CTestTestfile.cmake 36 | src/Makefile 37 | src/cmake_install.cmake 38 | src/libhdr_histogram.so 39 | test/CMakeFiles/ 40 | test/CTestTestfile.cmake 41 | test/Makefile 42 | test/cmake_install.cmake 43 | test/hdr_dbl_histogram_test 44 | test/hdr_histogram_log_test 45 | test/hdr_histogram_test 46 | test/perftest 47 | .gdb_history 48 | debug 49 | 50 | -------------------------------------------------------------------------------- /hdrhistogram/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | if("${CMAKE_VERSION}" VERSION_GREATER 3.0.0) 4 | cmake_policy(SET CMP0042 NEW) 5 | endif() 6 | 7 | project("hdr_histogram") 8 | 9 | ENABLE_TESTING() 10 | 11 | if(UNIX) 12 | set(CMAKE_C_FLAGS "-Wall -Wno-unknown-pragmas -Wextra -Wshadow -Winit-self -Wmissing-prototypes -D_GNU_SOURCE") 13 | set(CMAKE_C_FLAGS_DEBUG "-O0 -g") 14 | set(CMAKE_C_FLAGS_RELEASE "-O3 -g") 15 | endif() 16 | 17 | include_directories("${CMAKE_SOURCE_DIR}/src") 18 | add_subdirectory("${CMAKE_SOURCE_DIR}/src") 19 | add_subdirectory("${CMAKE_SOURCE_DIR}/test") 20 | add_subdirectory("${CMAKE_SOURCE_DIR}/examples") 21 | 22 | SET(CPACK_GENERATOR "TGZ") 23 | SET(CPACK_PACKAGE_VERSION "0.9.1") 24 | 25 | INCLUDE(CPack) 26 | -------------------------------------------------------------------------------- /hdrhistogram/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The code in this repository code was Written by Gil Tene, Michael Barker, 2 | and Matt Warren, and released to the public domain, as explained at 3 | http://creativecommons.org/publicdomain/zero/1.0/ 4 | 5 | For users of this code who wish to consume it under the "BSD" license 6 | rather than under the public domain or CC0 contribution text mentioned 7 | above, the code found under this directory is *also* provided under the 8 | following license (commonly referred to as the BSD 2-Clause License). This 9 | license does not detract from the above stated release of the code into 10 | the public domain, and simply represents an additional license granted by 11 | the Author. 12 | 13 | ----------------------------------------------------------------------------- 14 | ** Beginning of "BSD 2-Clause License" text. ** 15 | 16 | Copyright (c) 2012, 2013, 2014 Gil Tene 17 | Copyright (c) 2014 Michael Barker 18 | Copyright (c) 2014 Matt Warren 19 | All rights reserved. 20 | 21 | Redistribution and use in source and binary forms, with or without 22 | modification, are permitted provided that the following conditions are met: 23 | 24 | 1. Redistributions of source code must retain the above copyright notice, 25 | this list of conditions and the following disclaimer. 26 | 27 | 2. Redistributions in binary form must reproduce the above copyright notice, 28 | this list of conditions and the following disclaimer in the documentation 29 | and/or other materials provided with the distribution. 30 | 31 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 32 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 33 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 34 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 35 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 36 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 38 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 39 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 40 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 41 | THE POSSIBILITY OF SUCH DAMAGE. 42 | -------------------------------------------------------------------------------- /hdrhistogram/README.md: -------------------------------------------------------------------------------- 1 | HdrHistogram_c: 'C' port of High Dynamic Range (HDR) Histogram 2 | 3 | HdrHistogram 4 | ---------------------------------------------- 5 | [![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/HdrHistogram/HdrHistogram?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 6 | 7 | This port contains a subset of the functionality supported by the Java 8 | implementation. The current supported features are: 9 | 10 | * Standard histogram with 64 bit counts (32/16 bit counts not supported) 11 | * All iterator types (all values, recorded, percentiles, linear, logarithmic) 12 | * Histogram serialisation (encoding version 1.2, decoding 1.0-1.2) 13 | * Reader/writer phaser and interval recorder 14 | 15 | Features not supported, but planned 16 | 17 | * Auto-resizing of histograms 18 | 19 | Features unlikely to be implemented 20 | 21 | * Double histograms 22 | * Atomic/Concurrent histograms 23 | * 16/32 bit histograms 24 | 25 | # Simple Tutorial 26 | 27 | ## Recording values 28 | 29 | ```C 30 | #include 31 | 32 | struct hdr_histogram* histogram; 33 | 34 | // Initialise the histogram 35 | hdr_init( 36 | 1, // Minimum value 37 | INT64_C(3600000000), // Maximum value 38 | 3, // Number of significant figures 39 | &histogram) // Pointer to initialise 40 | 41 | // Record value 42 | hdr_record_value( 43 | histogram, // Histogram to record to 44 | value) // Value to record 45 | 46 | // Record value n times 47 | hdr_record_value( 48 | histogram, // Histogram to record to 49 | value, // Value to record 50 | 10) // Record value 10 times 51 | 52 | // Record value with correction for co-ordinated omission. 53 | hdr_record_corrected_value( 54 | histogram, // Histogram to record to 55 | value, // Value to record 56 | 1000) // Record with expected interval of 1000. 57 | 58 | // Print out the values of the histogram 59 | hdr_percentiles_print( 60 | histogram, 61 | stdout, // File to write to 62 | 5, // Granularity of printed values 63 | 1.0, // Multiplier for results 64 | CLASSIC); // Format CLASSIC/CSV supported. 65 | ``` 66 | 67 | ## More examples 68 | 69 | For more detailed examples of recording and logging results look at the 70 | [hdr_decoder](examples/hdr_decoder.c) 71 | and [hiccup](examples/hiccup.c) 72 | examples. You can run hiccup and decoder 73 | and pipe the results of one into the other. 74 | 75 | ``` 76 | $ ./examples/hiccup | ./examples/hdr_decoder 77 | ``` -------------------------------------------------------------------------------- /hdrhistogram/examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(hdr_decoder hdr_decoder.c) 2 | target_link_libraries(hdr_decoder hdr_histogram m z) 3 | install(TARGETS hdr_decoder DESTINATION bin) 4 | 5 | if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") 6 | add_executable(hiccup hiccup.c) 7 | target_link_libraries(hiccup hdr_histogram m z pthread rt) 8 | install(TARGETS hiccup DESTINATION bin) 9 | endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") 10 | -------------------------------------------------------------------------------- /hdrhistogram/examples/hdr_decoder.c: -------------------------------------------------------------------------------- 1 | /** 2 | * hdr_decoder.c 3 | * Written by Michael Barker and released to the public domain, 4 | * as explained at http://creativecommons.org/publicdomain/zero/1.0/ 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | 18 | int main(int argc, char** argv) 19 | { 20 | int rc = 0; 21 | FILE* f; 22 | 23 | if (argc == 1) 24 | { 25 | f = stdin; 26 | } 27 | else 28 | { 29 | f = fopen(argv[1], "r"); 30 | } 31 | 32 | if (!f) 33 | { 34 | fprintf(stderr, "Failed to open file(%s):%s\n", argv[1], strerror(errno)); 35 | return -1; 36 | } 37 | 38 | struct hdr_log_reader reader; 39 | if (hdr_log_reader_init(&reader)) 40 | { 41 | fprintf(stderr, "Failed to init reader\n"); 42 | return -1; 43 | } 44 | 45 | struct hdr_histogram* h = NULL; 46 | struct timespec timestamp; 47 | struct timespec interval; 48 | 49 | rc = hdr_log_read_header(&reader, f); 50 | if(rc) 51 | { 52 | fprintf(stderr, "Failed to read header: %s\n", hdr_strerror(rc)); 53 | return -1; 54 | } 55 | 56 | while (true) 57 | { 58 | rc = hdr_log_read(&reader, f, &h, ×tamp, &interval); 59 | 60 | if (0 == rc) 61 | { 62 | hdr_percentiles_print(h, stdout, 5, 1.0, CLASSIC); 63 | } 64 | else if (EOF == rc) 65 | { 66 | break; 67 | } 68 | else 69 | { 70 | fprintf(stderr, "Failed to print histogram: %s\n", hdr_strerror(rc)); 71 | return -1; 72 | } 73 | } 74 | 75 | return 0; 76 | } -------------------------------------------------------------------------------- /hdrhistogram/ide/codestyle.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baruch/diskscan/4773146060a1696c52c880ce65410dad2f861c08/hdrhistogram/ide/codestyle.jar -------------------------------------------------------------------------------- /hdrhistogram/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | FILE(GLOB histogram_files "*.c") 2 | 3 | add_library(hdr_histogram SHARED ${histogram_files}) 4 | add_library(hdr_histogram_static STATIC ${histogram_files}) 5 | 6 | target_link_libraries(hdr_histogram m z) 7 | target_link_libraries(hdr_histogram_static m z) 8 | 9 | install(TARGETS hdr_histogram DESTINATION lib) 10 | install(TARGETS hdr_histogram_static DESTINATION lib) 11 | install(FILES hdr_histogram.h hdr_histogram_log.h hdr_writer_reader_phaser.h hdr_interval_recorder.h DESTINATION include/hdr) 12 | -------------------------------------------------------------------------------- /hdrhistogram/src/hdr_encoding.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by barkerm on 9/09/15. 3 | // 4 | 5 | #ifndef HDR_ENCODING_H 6 | #define HDR_ENCODING_H 7 | 8 | #include 9 | 10 | #define MAX_BYTES_LEB128 9 11 | 12 | /** 13 | * Writes a int64_t value to the given buffer in LEB128 ZigZag encoded format 14 | * 15 | * @param buffer the buffer to write to 16 | * @param signed_value the value to write to the buffer 17 | * @return the number of bytes written to the buffer 18 | */ 19 | int zig_zag_encode_i64(uint8_t* buffer, int64_t signed_value); 20 | 21 | /** 22 | * Read an LEB128 ZigZag encoded long value from the given buffer 23 | * 24 | * @param buffer the buffer to read from 25 | * @param retVal out value to capture the read value 26 | * @return the number of bytes read from the buffer 27 | */ 28 | int zig_zag_decode_i64(const uint8_t* buffer, int64_t* signed_value); 29 | 30 | /** 31 | * Gets the length in bytes of base64 data, given the input size. 32 | * 33 | * @param decoded_size the size of the unencoded values. 34 | * @return the encoded size 35 | */ 36 | size_t hdr_base64_encoded_len(size_t decoded_size); 37 | 38 | /** 39 | * Encode into base64. 40 | * 41 | * @param input the data to encode 42 | * @param input_len the length of the data to encode 43 | * @param output the buffer to write the output to 44 | * @param output_len the number of bytes to write to the output 45 | */ 46 | int hdr_base64_encode( 47 | const uint8_t* input, size_t input_len, char* output, size_t output_len); 48 | 49 | /** 50 | * Gets the length in bytes of decoded base64 data, given the size of the base64 encoded 51 | * data. 52 | * 53 | * @param encoded_size the size of the encoded value. 54 | * @return the decoded size 55 | */ 56 | size_t hdr_base64_decoded_len(size_t encoded_size); 57 | 58 | /** 59 | * Decode from base64. 60 | * 61 | * @param input the base64 encoded data 62 | * @param input_len the size in bytes of the endcoded data 63 | * @param output the buffer to write the decoded data to 64 | * @param output_len the number of bytes to write to the output data 65 | */ 66 | int hdr_base64_decode( 67 | const char* input, size_t input_len, uint8_t* output, size_t output_len); 68 | 69 | 70 | #endif //HDR_HISTOGRAM_HDR_ENCODING_H 71 | -------------------------------------------------------------------------------- /hdrhistogram/src/hdr_interval_recorder.c: -------------------------------------------------------------------------------- 1 | /** 2 | * hdr_interval_recorder.h 3 | * Written by Michael Barker and released to the public domain, 4 | * as explained at http://creativecommons.org/publicdomain/zero/1.0/ 5 | */ 6 | 7 | #include "hdr_interval_recorder.h" 8 | 9 | int hdr_interval_recorder_init(struct hdr_interval_recorder* r) 10 | { 11 | return hdr_writer_reader_phaser_init(&r->phaser); 12 | } 13 | 14 | void hdr_interval_recorder_destroy(struct hdr_interval_recorder* r) 15 | { 16 | hdr_writer_reader_phaser_destory(&r->phaser); 17 | } 18 | 19 | void hdr_interval_recorder_update( 20 | struct hdr_interval_recorder* r, 21 | void(*update_action)(void*, void*), 22 | void* arg) 23 | { 24 | int64_t val = hdr_phaser_writer_enter(&r->phaser); 25 | 26 | void* active = __atomic_load_n(&r->active, __ATOMIC_SEQ_CST); 27 | 28 | update_action(active, arg); 29 | 30 | hdr_phaser_writer_exit(&r->phaser, val); 31 | } 32 | 33 | void* hdr_interval_recorder_sample(struct hdr_interval_recorder* r) 34 | { 35 | void* temp; 36 | 37 | hdr_phaser_reader_lock(&r->phaser); 38 | 39 | temp = r->inactive; 40 | 41 | // volatile read 42 | r->inactive = __atomic_load_n(&r->active, __ATOMIC_SEQ_CST); 43 | 44 | // volatile write 45 | __atomic_store_n(&r->active, temp, __ATOMIC_SEQ_CST); 46 | 47 | hdr_phaser_flip_phase(&r->phaser, 0); 48 | 49 | hdr_phaser_reader_unlock(&r->phaser); 50 | 51 | return r->inactive; 52 | } 53 | -------------------------------------------------------------------------------- /hdrhistogram/src/hdr_interval_recorder.h: -------------------------------------------------------------------------------- 1 | /** 2 | * hdr_interval_recorder.h 3 | * Written by Michael Barker and released to the public domain, 4 | * as explained at http://creativecommons.org/publicdomain/zero/1.0/ 5 | */ 6 | 7 | #ifndef HDR_INTERVAL_RECORDER_H 8 | #define HDR_INTERVAL_RECORDER_H 1 9 | 10 | #include "hdr_writer_reader_phaser.h" 11 | 12 | struct hdr_interval_recorder 13 | { 14 | void* active; 15 | void* inactive; 16 | struct hdr_writer_reader_phaser phaser; 17 | } __attribute__((aligned (8))); 18 | 19 | int hdr_interval_recorder_init(struct hdr_interval_recorder* r); 20 | 21 | void hdr_interval_recorder_destroy(struct hdr_interval_recorder* r); 22 | 23 | void hdr_interval_recorder_update( 24 | struct hdr_interval_recorder* r, 25 | void(*update_action)(void*, void*), 26 | void* arg); 27 | 28 | void* hdr_interval_recorder_sample(struct hdr_interval_recorder* r); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /hdrhistogram/src/hdr_tests.h: -------------------------------------------------------------------------------- 1 | #ifndef HDR_TESTS_H 2 | #define HDR_TESTS_H 3 | 4 | /* These are functions used in tests and are not intended for normal usage. */ 5 | 6 | #include "hdr_histogram.h" 7 | 8 | void hdr_reset_internal_counters(struct hdr_histogram* h); 9 | int32_t counts_index_for(const struct hdr_histogram* h, int64_t value); 10 | int hdr_encode_compressed(struct hdr_histogram* h, uint8_t** compressed_histogram, size_t* compressed_len); 11 | int hdr_decode_compressed(uint8_t* buffer, size_t length, struct hdr_histogram** histogram); 12 | void hdr_base64_decode_block(const char* input, uint8_t* output); 13 | void hdr_base64_encode_block(const uint8_t* input, char* output); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /hdrhistogram/src/hdr_time.h: -------------------------------------------------------------------------------- 1 | /** 2 | * hdr_time.h 3 | * Written by Michael Barker and released to the public domain, 4 | * as explained at http://creativecommons.org/publicdomain/zero/1.0/ 5 | */ 6 | 7 | #include 8 | 9 | #if defined(__APPLE__) 10 | #include 11 | #include 12 | 13 | static void hdr_gettime(struct timespec* ts) 14 | { 15 | clock_serv_t cclock; 16 | mach_timespec_t mts; 17 | host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); 18 | clock_get_time(cclock, &mts); 19 | mach_port_deallocate(mach_task_self(), cclock); 20 | ts->tv_sec = mts.tv_sec; 21 | ts->tv_nsec = mts.tv_nsec; 22 | } 23 | 24 | #elif defined(__linux__) 25 | 26 | static void hdr_gettime(struct timespec* t) 27 | { 28 | clock_gettime(CLOCK_MONOTONIC, t); 29 | } 30 | 31 | #else 32 | 33 | #warning "Platform not supported\n" 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /hdrhistogram/src/hdr_writer_reader_phaser.c: -------------------------------------------------------------------------------- 1 | /** 2 | * hdr_writer_reader_phaser.h 3 | * Written by Michael Barker and released to the public domain, 4 | * as explained at http://creativecommons.org/publicdomain/zero/1.0/ 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "hdr_writer_reader_phaser.h" 16 | 17 | static int64_t _hdr_phaser_get_epoch(int64_t* field) 18 | { 19 | return __atomic_load_n(field, __ATOMIC_SEQ_CST); 20 | } 21 | 22 | static void _hdr_phaser_set_epoch(int64_t* field, int64_t val) 23 | { 24 | __atomic_store_n(field, val, __ATOMIC_SEQ_CST); 25 | } 26 | 27 | static int64_t _hdr_phaser_reset_epoch(int64_t* field, int64_t initial_value) 28 | { 29 | return __atomic_exchange_n(field, initial_value, __ATOMIC_SEQ_CST); 30 | } 31 | 32 | int hdr_writer_reader_phaser_init(struct hdr_writer_reader_phaser* p) 33 | { 34 | if (NULL == p) 35 | { 36 | return EINVAL; 37 | } 38 | 39 | p->start_epoch = 0; 40 | p->even_end_epoch = 0; 41 | p->odd_end_epoch = INT64_MIN; 42 | p->reader_mutex = malloc(sizeof(pthread_mutex_t)); 43 | 44 | if (!p->reader_mutex) 45 | { 46 | return ENOMEM; 47 | } 48 | 49 | int rc = pthread_mutex_init(p->reader_mutex, NULL); 50 | if (0 != rc) 51 | { 52 | return rc; 53 | } 54 | 55 | // TODO: Should I fence here. 56 | 57 | return 0; 58 | } 59 | 60 | void hdr_writer_reader_phaser_destory(struct hdr_writer_reader_phaser* p) 61 | { 62 | pthread_mutex_destroy(p->reader_mutex); 63 | } 64 | 65 | int64_t hdr_phaser_writer_enter(struct hdr_writer_reader_phaser* p) 66 | { 67 | return __atomic_add_fetch(&p->start_epoch, 1, __ATOMIC_SEQ_CST); 68 | } 69 | 70 | void hdr_phaser_writer_exit( 71 | struct hdr_writer_reader_phaser* p, int64_t critical_value_at_enter) 72 | { 73 | int64_t* end_epoch = 74 | (critical_value_at_enter < 0) ? &p->odd_end_epoch : &p->even_end_epoch; 75 | __atomic_add_fetch(end_epoch, 1, __ATOMIC_SEQ_CST); 76 | } 77 | 78 | void hdr_phaser_reader_lock(struct hdr_writer_reader_phaser* p) 79 | { 80 | pthread_mutex_lock(p->reader_mutex); 81 | } 82 | 83 | void hdr_phaser_reader_unlock(struct hdr_writer_reader_phaser* p) 84 | { 85 | pthread_mutex_unlock(p->reader_mutex); 86 | } 87 | 88 | void hdr_phaser_flip_phase( 89 | struct hdr_writer_reader_phaser* p, int64_t sleep_time_ns) 90 | { 91 | // TODO: is_held_by_current_thread 92 | 93 | int64_t start_epoch = _hdr_phaser_get_epoch(&p->start_epoch); 94 | 95 | bool next_phase_is_even = (start_epoch < 0); 96 | 97 | // Clear currently used phase end epoch. 98 | int64_t initial_start_value; 99 | if (next_phase_is_even) 100 | { 101 | initial_start_value = 0; 102 | _hdr_phaser_set_epoch(&p->even_end_epoch, initial_start_value); 103 | } 104 | else 105 | { 106 | initial_start_value = INT64_MIN; 107 | _hdr_phaser_set_epoch(&p->odd_end_epoch, initial_start_value); 108 | } 109 | 110 | // Reset start value, indicating new phase. 111 | int64_t start_value_at_flip = 112 | _hdr_phaser_reset_epoch(&p->start_epoch, initial_start_value); 113 | 114 | bool caught_up = false; 115 | do 116 | { 117 | int64_t* end_epoch = 118 | next_phase_is_even ? &p->odd_end_epoch : &p->even_end_epoch; 119 | 120 | caught_up = _hdr_phaser_get_epoch(end_epoch) == start_value_at_flip; 121 | 122 | if (!caught_up) 123 | { 124 | if (sleep_time_ns == 0) 125 | { 126 | sched_yield(); 127 | } 128 | else 129 | { 130 | usleep(sleep_time_ns / 1000); 131 | } 132 | } 133 | } 134 | while (!caught_up); 135 | } 136 | -------------------------------------------------------------------------------- /hdrhistogram/src/hdr_writer_reader_phaser.h: -------------------------------------------------------------------------------- 1 | /** 2 | * hdr_writer_reader_phaser.h 3 | * Written by Michael Barker and released to the public domain, 4 | * as explained at http://creativecommons.org/publicdomain/zero/1.0/ 5 | */ 6 | 7 | #ifndef HDR_WRITER_READER_PHASER_H 8 | #define HDR_WRITER_READER_PHASER_H 1 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | struct hdr_writer_reader_phaser 18 | { 19 | int64_t start_epoch; 20 | int64_t even_end_epoch; 21 | int64_t odd_end_epoch; 22 | pthread_mutex_t* reader_mutex; 23 | } __attribute__((aligned (8))); 24 | 25 | int hdr_writer_reader_phaser_init(struct hdr_writer_reader_phaser* p); 26 | 27 | void hdr_writer_reader_phaser_destory(struct hdr_writer_reader_phaser* p); 28 | 29 | int64_t hdr_phaser_writer_enter(struct hdr_writer_reader_phaser* p); 30 | 31 | void hdr_phaser_writer_exit( 32 | struct hdr_writer_reader_phaser* p, int64_t critical_value_at_enter); 33 | 34 | void hdr_phaser_reader_lock(struct hdr_writer_reader_phaser* p); 35 | 36 | void hdr_phaser_reader_unlock(struct hdr_writer_reader_phaser* p); 37 | 38 | void hdr_phaser_flip_phase( 39 | struct hdr_writer_reader_phaser* p, int64_t sleep_time_ns); 40 | 41 | #endif -------------------------------------------------------------------------------- /hdrhistogram/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | INCLUDE(CheckLibraryExists) 2 | 3 | add_executable(hdr_histogram_test hdr_histogram_test.c) 4 | add_executable(hdr_histogram_log_test hdr_histogram_log_test.c) 5 | 6 | add_executable(perftest hdr_histogram_perf.c) 7 | 8 | target_link_libraries(hdr_histogram_test hdr_histogram m) 9 | target_link_libraries(hdr_histogram_log_test hdr_histogram m z) 10 | target_link_libraries(perftest hdr_histogram m z) 11 | 12 | CHECK_LIBRARY_EXISTS(rt clock_gettime "" RT_EXISTS) 13 | if (RT_EXISTS) 14 | target_link_libraries(hdr_histogram_log_test rt) 15 | target_link_libraries(perftest rt) 16 | endif (RT_EXISTS) 17 | 18 | install(TARGETS hdr_histogram_test DESTINATION bin) 19 | install(TARGETS hdr_histogram_log_test DESTINATION bin) 20 | install(TARGETS perftest DESTINATION bin) 21 | 22 | add_test(Histogram hdr_histogram_test) 23 | add_test(HistogramLogging hdr_histogram_log_test) 24 | 25 | configure_file(jHiccup-2.0.1.logV0.hlog jHiccup-2.0.1.logV0.hlog COPYONLY) 26 | configure_file(jHiccup-2.0.6.logV1.hlog jHiccup-2.0.6.logV1.hlog COPYONLY) 27 | configure_file(jHiccup-2.0.7S.logV2.hlog jHiccup-2.0.7S.logV2.hlog COPYONLY) 28 | -------------------------------------------------------------------------------- /hdrhistogram/test/hdr_histogram_perf.c: -------------------------------------------------------------------------------- 1 | /** 2 | * hdr_histogram_perf.c 3 | * Written by Michael Barker and released to the public domain, 4 | * as explained at http://creativecommons.org/publicdomain/zero/1.0/ 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include "hdr_time.h" 15 | 16 | static struct timespec diff(struct timespec start, struct timespec end) 17 | { 18 | struct timespec temp; 19 | if ((end.tv_nsec-start.tv_nsec) < 0) 20 | { 21 | temp.tv_sec = end.tv_sec - start.tv_sec - 1; 22 | temp.tv_nsec = 1000000000 + end.tv_nsec-start.tv_nsec; 23 | } 24 | else 25 | { 26 | temp.tv_sec = end.tv_sec - start.tv_sec; 27 | temp.tv_nsec = end.tv_nsec - start.tv_nsec; 28 | } 29 | return temp; 30 | } 31 | 32 | int main() 33 | { 34 | struct hdr_histogram* histogram; 35 | int64_t max_value = INT64_C(24) * 60 * 60 * 1000000; 36 | int64_t min_value = 1; 37 | int result = -1; 38 | 39 | result = hdr_init(min_value, max_value, 4, &histogram); 40 | if (result != 0) 41 | { 42 | fprintf(stderr, "Failed to allocate histogram: %d\n", result); 43 | return -1; 44 | } 45 | 46 | 47 | struct timespec t0; 48 | struct timespec t1; 49 | setlocale(LC_NUMERIC, ""); 50 | int64_t iterations = 400000000; 51 | 52 | int i; 53 | for (i = 0; i < 100; i++) 54 | { 55 | int64_t j; 56 | hdr_gettime(&t0); 57 | for (j = 1; j < iterations; j++) 58 | { 59 | hdr_record_value(histogram, j); 60 | } 61 | hdr_gettime(&t1); 62 | 63 | 64 | struct timespec taken = diff(t0, t1); 65 | double time_taken = taken.tv_sec + taken.tv_nsec / 1000000000.0; 66 | double ops_sec = (iterations - 1) / time_taken; 67 | 68 | printf("%s - %d, ops/sec: %'.2f\n", "Iteration", i + 1, ops_sec); 69 | } 70 | 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /hdrhistogram/test/hiccup.140623.1028.10646.hlog: -------------------------------------------------------------------------------- 1 | #[Logged with jHiccup version 2.0.3-SNAPSHOT] 2 | #[Histogram log format version 1.01] 3 | #[StartTime: 1403476110.183 (seconds since epoch), Mon Jun 23 10:28:30 NZST 2014] 4 | "StartTimestamp","EndTimestamp","Interval_Max","Interval_Compressed_Histogram" 5 | 0.042,5.004,0.115,HISTiQAAAEV42pNpmdzBwMDAxAAGfgoMDMxuBjsWQLgMQt4QmrkKQvNugkq8g9KKUJoHSjMzoAJGhlEwCkbBKBgFo2AUDDkAANEpBrU= 6 | 5.046,5.000,1.294,HISTiQAAAEh42pNpmdzBwMDAxAAGfgoMDMxuBjsWQLgMQm5QBhuEYraF0LyuEJoxFypvA6UFoTQzwygYBZQDxtEgGAWjYBSMgoEBAItJBaw= 7 | 10.046,5.000,3.113,HISTiQAAAEZ42pNpmdzBwMDAxAAGfgoMDMxuBjsWQLgMQlFQBiMqzX8RQjNJQMVDobQwlGZCo0fB8ASMo0EwGs+jYDS+R8HwBAC+mAXU 8 | 15.046,5.005,0.131,HISTiQAAAEd42pNpmdzBwMDAxAAGfgoMDMxuBjsWQLgMQhlQBiOU5oBQAuxQ4a9QcW8oLQKlmRlQASPDKBgFo2AUjIJRMAqGDAAAoysF8A== 9 | 20.051,4.995,0.147,HISTiQAAAEp42pNpmdzBwMDAxAAGfgoMDMxuBjsWQLgMQglQBlSegRlCCXhAaMbtUHE3KM0PpVmhNCMDKkDnj4JRMApGwSgYBaNgEAIAJgsF4A== 10 | 25.046,5.000,0.115,HISTiQAAAEZ42pNpmdzBwMDAxAAGfgoMDMxuBjsWQLgMQilQBiOUZoNQAnJQ4bNQ8UgoLQylWaA01NxRMApGwSgYBaNgFAwlAABjqwXo 11 | 30.046,5.000,0.131,HISTiQAAAEJ42pNpmdzBwMDAxAAGfgoMDMxuBjsWQLgMQqkMqIARQgl4Q7n7oOJeUJoPSjNh1zcKRsEoGAWjYBSMgqEAAHWdBeo= 12 | 35.046,5.000,0.115,HISTiQAAAEV42pNpmdzBwMDAxAAGfgoMDMxuBjsWQLgMQqlQBlSegRlCCWhDaMYzUPFgKC0CpRnR6FEwCkbBKBgFo2AUDCEAAHRlBeo= 13 | 40.046,5.000,0.131,HISTiQAAAER42pNpmdzBwMDAxAAGfgoMDMxuBjsWQLgMQikMqIAZQgloQWjGy1DxACjNi6oOTjMyjIJRMApGwSgYBaNgyAAAZDsF6A== 14 | 45.046,5.000,0.131,HISTiQAAAEl42pNpmdzBwMDAxAAGfgoMDMxuBjsWQLgMQvFQBlSegQNC8W2BCp+Bis+H0hpQmgtKM0NpRoZRMApGwSgYBaNgFAwZAADuSAbd 15 | 50.046,5.000,0.246,HISTiQAAAEt42pNpmdzBwMDAxAAGfgoMDMxuBjsWQLgMQvFQBlSegQ1CMd6G0PxuUPFbUNoJSotDaUY0mlRArr5RMApGwSgYBaNgFFAAAOooBt0= 16 | 17 | -------------------------------------------------------------------------------- /hdrhistogram/test/minunit.h: -------------------------------------------------------------------------------- 1 | /** 2 | * minunit.h 3 | * Written by Michael Barker and released to the public domain, 4 | * as explained at http://creativecommons.org/publicdomain/zero/1.0/ 5 | */ 6 | 7 | #ifndef MINUNIT_H 8 | #define MINUNIT_H 9 | 10 | #include 11 | #include 12 | 13 | struct mu_result 14 | { 15 | char* test; 16 | char* message; 17 | }; 18 | 19 | #define mu_assert(message, test) \ 20 | do { \ 21 | if (!(test)) \ 22 | return message; \ 23 | } while (0) 24 | 25 | #define mu_run_test(name) \ 26 | do { \ 27 | char *message = name(); \ 28 | tests_run++; \ 29 | if (message) { \ 30 | struct mu_result r; \ 31 | r.test = #name; \ 32 | r.message = message; \ 33 | return r; \ 34 | } \ 35 | } while (0) 36 | 37 | #define mu_ok \ 38 | do { \ 39 | struct mu_result r; \ 40 | r.test = 0; \ 41 | r.message = 0; \ 42 | return r; \ 43 | } while (0) 44 | 45 | extern int tests_run; 46 | 47 | static bool compare_double(double a, double b, double delta) 48 | { 49 | if (fabs(a - b) < delta) 50 | { 51 | return true; 52 | } 53 | 54 | printf("[compare_double] fabs(%f, %f) < %f == false\n", a, b, delta); 55 | return false; 56 | } 57 | 58 | static bool compare_int64(int64_t a, int64_t b) 59 | { 60 | if (a == b) 61 | { 62 | return true; 63 | } 64 | 65 | printf("[compare_int64] %" PRIu64 " == %" PRIu64 " == false\n", a, b); 66 | return false; 67 | } 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /include/arch.h: -------------------------------------------------------------------------------- 1 | #ifndef _DISKSCAN_ARCH_H 2 | #define _DISKSCAN_ARCH_H 3 | 4 | #include "libscsicmd/include/scsicmd.h" 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | typedef struct disk_dev_t disk_dev_t; 11 | 12 | typedef struct { 13 | enum result_data_e { 14 | DATA_FULL, /* All data received for the request */ 15 | DATA_PARTIAL, /* Only some of the data was received/sent */ 16 | DATA_NONE /* No data was received/sent */ 17 | } data; 18 | enum result_error_e { 19 | ERROR_NONE, /* No error encountered */ 20 | ERROR_CORRECTED, /* A corrected error encountered */ 21 | ERROR_UNCORRECTED, /* Unocrrected but non-fatal (i.e. local) error */ 22 | ERROR_NEED_RETRY, /* Temporary error that only merits a retry to complete */ 23 | ERROR_FATAL, /* A fatal error encountered, no reason to continue using disk */ 24 | ERROR_UNKNOWN, /* An unknown error encountered, continue for a while unless it persists */ 25 | } error; 26 | 27 | sense_info_t info; 28 | unsigned char sense[256]; 29 | unsigned sense_len; 30 | } io_result_t; 31 | 32 | typedef enum { 33 | DISK_NOT_MOUNTED = 0, 34 | DISK_MOUNTED_RO = 1, 35 | DISK_MOUNTED_RW = 2, 36 | } disk_mount_e; 37 | 38 | disk_mount_e disk_dev_mount_state(const char *path); 39 | 40 | bool disk_dev_open(disk_dev_t *dev, const char *path); 41 | void disk_dev_close(disk_dev_t *dev); 42 | void disk_dev_cdb_out(disk_dev_t *dev, unsigned char *cdb, unsigned cdb_len, unsigned char *buf, unsigned buf_size, unsigned *buf_read, 43 | unsigned char *sense, unsigned sense_size, unsigned *sense_read, io_result_t *io_res); 44 | void disk_dev_cdb_in(disk_dev_t *dev, unsigned char *cdb, unsigned cdb_len, unsigned char *buf, unsigned buf_size, unsigned *buf_read, 45 | unsigned char *sense, unsigned sense_size, unsigned *sense_read, io_result_t *io_res); 46 | 47 | ssize_t disk_dev_read(disk_dev_t *dev, uint64_t offset_bytes, uint32_t len_bytes, void *buf, io_result_t *io_res); 48 | ssize_t disk_dev_write(disk_dev_t *dev, uint64_t offset_bytes, uint32_t len_bytes, void *buf, io_result_t *io_res); 49 | int disk_dev_read_cap(disk_dev_t *dev, uint64_t *size_bytes, uint64_t *sector_size); 50 | int disk_dev_identify(disk_dev_t *dev, char *vendor, char *model, char *fw_rev, char *serial, bool *is_ata, unsigned char *ata_buf, unsigned *ata_buf_len); 51 | 52 | void mac_read(unsigned char *buf, int len); 53 | 54 | #include "arch-internal.h" 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /include/cli.h: -------------------------------------------------------------------------------- 1 | #ifndef DISKSCAN_CLI 2 | #define DISKSCAN_CLI 3 | 4 | int diskscan_cli(int argc, char **argv); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /include/compiler.h: -------------------------------------------------------------------------------- 1 | #ifndef _COMPILER_H 2 | #define _COMPILER_H 3 | 4 | #ifdef __GNUC__ 5 | # define UNUSED(x) UNUSED_ ## x __attribute__((__unused__)) 6 | #else 7 | # define UNUSED(x) UNUSED_ ## x 8 | #endif 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /include/disk.h: -------------------------------------------------------------------------------- 1 | #ifndef DISKSCAN_DISK_H 2 | #define DISKSCAN_DISK_H 3 | 4 | #include "arch.h" 5 | #include "libscsicmd/include/ata.h" 6 | 7 | /** Check if the disk had a smart trip, only relevant for ATA disks. 8 | * 9 | * Returns -1 on error, 0 if there is no smart trip and 1 if there is a smart trip. 10 | */ 11 | int disk_smart_trip(disk_dev_t *dev); 12 | 13 | /** Read the disk SMART attributes into the pre-defined array. 14 | * Returns -1 on error, number of attributes on success. 15 | */ 16 | int disk_smart_attributes(disk_dev_t *dev, ata_smart_attr_t *attrs, int max_attrs); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /include/diskscan.h: -------------------------------------------------------------------------------- 1 | #ifndef _DISKSCAN_H_ 2 | #define _DISKSCAN_H_ 3 | 4 | #include 5 | #include 6 | #include "arch.h" 7 | 8 | #include "libscsicmd/include/ata.h" 9 | #include "hdrhistogram/src/hdr_histogram.h" 10 | 11 | #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) 12 | 13 | enum scan_mode { 14 | SCAN_MODE_UNKNOWN, 15 | SCAN_MODE_SEQ, 16 | SCAN_MODE_RANDOM, 17 | }; 18 | 19 | enum conclusion { 20 | CONCLUSION_SCAN_PROBLEM, /* Problem in the scan, no real conclusion */ 21 | CONCLUSION_ABORTED, /* Scan aborted by used */ 22 | CONCLUSION_PASSED, /* Disk looks fine */ 23 | /* Disk looks bad, and the reason it failed the test */ 24 | CONCLUSION_FAILED_MAX_LATENCY, 25 | CONCLUSION_FAILED_LATENCY_PERCENTILE, 26 | CONCLUSION_FAILED_IO_ERRORS, 27 | }; 28 | 29 | typedef struct latency_t { 30 | uint64_t start_sector; 31 | uint64_t end_sector; 32 | uint32_t latency_min_msec; 33 | uint32_t latency_max_msec; 34 | uint32_t latency_median_msec; 35 | } latency_t; 36 | 37 | typedef struct data_log_raw_t { 38 | FILE *f; 39 | bool is_first; 40 | } data_log_raw_t; 41 | 42 | typedef struct data_log_t { 43 | FILE *f; 44 | bool is_first; 45 | } data_log_t; 46 | 47 | typedef struct ata_state_t { 48 | bool is_smart_tripped; 49 | const struct smart_table *smart_table; 50 | ata_smart_attr_t smart[MAX_SMART_ATTRS]; 51 | int smart_num; 52 | int last_temp; 53 | int last_reallocs; 54 | int last_pending_reallocs; 55 | int last_crc_errors; 56 | } ata_state_t; 57 | 58 | typedef struct scsi_state_t { 59 | } scsi_state_t; 60 | 61 | typedef struct disk_t { 62 | disk_dev_t dev; 63 | char path[128]; 64 | char vendor[64]; 65 | char model[64]; 66 | char fw_rev[64]; 67 | char serial[64]; 68 | bool is_ata; 69 | union { 70 | ata_state_t ata; 71 | scsi_state_t scsi; 72 | } state; 73 | unsigned char ata_buf[512]; 74 | unsigned ata_buf_len; 75 | uint64_t num_bytes; 76 | uint64_t sector_size; 77 | int run; 78 | int fix; 79 | 80 | uint64_t num_errors; 81 | struct hdr_histogram *histogram; 82 | unsigned latency_graph_len; 83 | latency_t *latency_graph; 84 | enum conclusion conclusion; 85 | 86 | data_log_raw_t data_raw; 87 | data_log_t data_log; 88 | } disk_t; 89 | 90 | int disk_open(disk_t *disk, const char *path, int fix, unsigned latency_graph_len, disk_mount_e allowed_mount); 91 | int disk_scan(disk_t *disk, enum scan_mode mode, unsigned data_size); 92 | int disk_close(disk_t *disk); 93 | void disk_scan_stop(disk_t *disk); 94 | 95 | enum scan_mode str_to_scan_mode(const char *s); 96 | const char *conclusion_to_str(enum conclusion conclusion); 97 | 98 | /* Implemented by the user (gui/cli) */ 99 | void report_progress(disk_t *disk, int percent_part, int percent_full); 100 | void report_scan_success(disk_t *disk, uint64_t offset_bytes, uint64_t data_size, uint64_t time); 101 | void report_scan_error(disk_t *disk, uint64_t offset_bytes, uint64_t data_size, uint64_t time); 102 | void report_scan_done(disk_t *disk); 103 | 104 | /* Used to log data to files */ 105 | void data_log_raw_start(data_log_raw_t *log_raw, const char *filename, disk_t *disk); 106 | void data_log_raw_end(data_log_raw_t *log_raw); 107 | void data_log_start(data_log_t *log, const char *filename, disk_t *disk); 108 | void data_log_end(data_log_t *log, disk_t *disk); 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /include/median.h: -------------------------------------------------------------------------------- 1 | #ifndef _MEDIAN_H 2 | #define _MEDIAN_H 3 | 4 | /* This is taken from http://ndevilla.free.fr/median/median/src/wirth.c */ 5 | 6 | /* 7 | * Algorithm from N. Wirth's book, implementation by N. Devillard. 8 | * This code in public domain. 9 | */ 10 | 11 | #include 12 | 13 | #define elem_type uint32_t 14 | 15 | #define ELEM_SWAP(a,b) { register elem_type t=(a);(a)=(b);(b)=t; } 16 | 17 | 18 | /*--------------------------------------------------------------------------- 19 | Function : kth_smallest() 20 | In : array of elements, # of elements in the array, rank k 21 | Out : one element 22 | Job : find the kth smallest element in the array 23 | Notice : use the median() macro defined below to get the median. 24 | 25 | Reference: 26 | 27 | Author: Wirth, Niklaus 28 | Title: Algorithms + data structures = programs 29 | Publisher: Englewood Cliffs: Prentice-Hall, 1976 30 | Physical description: 366 p. 31 | Series: Prentice-Hall Series in Automatic Computation 32 | 33 | ---------------------------------------------------------------------------*/ 34 | 35 | 36 | static elem_type kth_smallest(elem_type a[], int n, int k) 37 | { 38 | register int i,j,l,m ; 39 | register elem_type x ; 40 | 41 | l=0 ; m=n-1 ; 42 | while (l 0) verbose_out("V: " __VA_ARGS__) 10 | #define VVERBOSE(...) if (verbose > 1) verbose_out("V: " __VA_ARGS__) 11 | #define VVVERBOSE(...) if (verbose > 2) verbose_out("V: " __VA_ARGS__) 12 | #define INFO(...) verbose_out("I: " __VA_ARGS__) 13 | #define ERROR(...) verbose_out("E: " __VA_ARGS__) 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /lib/data.h: -------------------------------------------------------------------------------- 1 | #ifndef DISKSCAN_DATA_H 2 | #define DISKSCAN_DATA_H 3 | 4 | #include "arch.h" 5 | 6 | void data_log(data_log_t *log, uint64_t lba, uint32_t len, io_result_t *io_res, uint32_t t_nsec); 7 | void data_log_raw(data_log_raw_t *log_raw, uint64_t lba, uint32_t len, io_result_t *io_res, uint32_t t_nsec); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /lib/disk.c: -------------------------------------------------------------------------------- 1 | #include "disk.h" 2 | 3 | #include "libscsicmd/include/ata.h" 4 | 5 | int disk_smart_trip(disk_dev_t *dev) 6 | { 7 | int cdb_len; 8 | unsigned char cdb[32]; 9 | unsigned char buf[512]; 10 | unsigned char sense[128]; 11 | unsigned buf_read = 0; 12 | unsigned sense_read = 0; 13 | io_result_t io_res; 14 | bool smart_ok; 15 | 16 | cdb_len = cdb_ata_smart_return_status(cdb); 17 | disk_dev_cdb_in(dev, cdb, cdb_len, buf, sizeof(buf), &buf_read, sense, sizeof(sense), &sense_read, &io_res); 18 | if (!ata_smart_return_status_result(sense, sense_read, &smart_ok)) 19 | return -1; 20 | 21 | return smart_ok ? 0 : 1; 22 | } 23 | 24 | int disk_smart_attributes(disk_dev_t *dev, ata_smart_attr_t *attrs, int max_attrs) 25 | { 26 | int cdb_len; 27 | unsigned char cdb[32]; 28 | unsigned char buf[512]; 29 | unsigned char sense[128]; 30 | unsigned buf_read = 0; 31 | unsigned sense_read = 0; 32 | io_result_t io_res; 33 | 34 | cdb_len = cdb_ata_smart_read_data(cdb); 35 | disk_dev_cdb_in(dev, cdb, cdb_len, buf, sizeof(buf), &buf_read, sense, sizeof(sense), &sense_read, &io_res); 36 | 37 | // TODO: Need to report about the SMART failure, once. 38 | if (io_res.data != DATA_FULL) 39 | return -1; 40 | 41 | return ata_parse_ata_smart_read_data(buf, attrs, max_attrs); 42 | } 43 | -------------------------------------------------------------------------------- /lib/sha1.h: -------------------------------------------------------------------------------- 1 | /* public api for steve reid's public domain SHA-1 implementation */ 2 | /* this file is in the public domain */ 3 | 4 | #ifndef __SHA1_H 5 | #define __SHA1_H 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #include 12 | #include 13 | 14 | typedef struct { 15 | uint32_t state[5]; 16 | uint32_t count[2]; 17 | uint8_t buffer[64]; 18 | } SHA1_CTX; 19 | 20 | #define SHA1_DIGEST_SIZE 20 21 | 22 | void SHA1_Init(SHA1_CTX* context); 23 | void SHA1_Update(SHA1_CTX* context, const uint8_t* data, const size_t len); 24 | void SHA1_Final(SHA1_CTX* context, uint8_t digest[SHA1_DIGEST_SIZE]); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif /* __SHA1_H */ 31 | -------------------------------------------------------------------------------- /lib/system_id.c: -------------------------------------------------------------------------------- 1 | #include "system_id.h" 2 | 3 | #include "sha1.h" 4 | #include "arch.h" 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | static void sha1_calc(const unsigned char *src, int src_len, char *out, int out_size) 14 | { 15 | assert(out_size >= SHA1_DIGEST_SIZE*2+1); 16 | 17 | unsigned char digest[SHA1_DIGEST_SIZE]; 18 | SHA1_CTX sha1_ctx; 19 | SHA1_Init(&sha1_ctx); 20 | SHA1_Update(&sha1_ctx, src, src_len); 21 | SHA1_Final(&sha1_ctx, digest); 22 | 23 | int i; 24 | for (i = 0; i < SHA1_DIGEST_SIZE; i++) { 25 | sprintf(out + i*2, "%02X", digest[i]); 26 | } 27 | } 28 | 29 | static bool cmd_str(const char *cmd, char *buf, int len) 30 | { 31 | FILE *f = popen(cmd, "r"); 32 | if (!f) 33 | return false; 34 | 35 | char *ret = fgets(buf, len, f); 36 | pclose(f); 37 | return ret != NULL; 38 | } 39 | 40 | static void dmidecode_read(const char *field_name, char *buf, int len) 41 | { 42 | char cmd[128]; 43 | 44 | memset(buf, 0, len); 45 | 46 | snprintf(cmd, sizeof(cmd), "dmidecode -s %s", field_name); 47 | if (!cmd_str(cmd, buf, len)) 48 | return; 49 | 50 | int actual_len = strlen(buf); 51 | switch (buf[actual_len-1]) { 52 | case '\r': 53 | case '\n': 54 | buf[actual_len-1] = 0; 55 | actual_len--; 56 | break; 57 | } 58 | 59 | sha1_calc((unsigned char *)buf, actual_len, buf, len); 60 | } 61 | 62 | static void system_serial_read(char *buf, int len) 63 | { 64 | dmidecode_read("system-serial-number", buf, len); 65 | } 66 | 67 | static void chassis_serial_read(char *buf, int len) 68 | { 69 | dmidecode_read("chassis-serial-number", buf, len); 70 | } 71 | 72 | static void baseboard_serial_read(char *buf, int len) 73 | { 74 | dmidecode_read("baseboard-serial-number", buf, len); 75 | } 76 | 77 | static void os_read(char *buf, int len) 78 | { 79 | cmd_str("uname -o", buf, len); 80 | 81 | int i; 82 | for (i = strlen(buf) - 1; i >= 0; i--) { 83 | if (!isspace(buf[i])) 84 | break; 85 | buf[i] = 0; 86 | } 87 | } 88 | 89 | bool system_identifier_read(system_identifier_t *system_id) 90 | { 91 | os_read(system_id->os, sizeof(system_id->os)); 92 | system_serial_read(system_id->system, sizeof(system_id->system)); 93 | chassis_serial_read(system_id->chassis, sizeof(system_id->chassis)); 94 | baseboard_serial_read(system_id->baseboard, sizeof(system_id->baseboard)); 95 | 96 | unsigned char mac[6]; 97 | mac_read(mac, sizeof(mac)); 98 | sha1_calc(mac, sizeof(mac), system_id->mac, sizeof(system_id->mac)); 99 | 100 | return true; 101 | } 102 | -------------------------------------------------------------------------------- /lib/system_id.h: -------------------------------------------------------------------------------- 1 | #ifndef SYSTEM_ID_H 2 | #define SYSTEM_ID_H 3 | 4 | #include 5 | 6 | typedef struct system_identifier_t { 7 | char os[64]; 8 | char system[64]; 9 | char chassis[64]; 10 | char baseboard[64]; 11 | char mac[64]; 12 | } system_identifier_t; 13 | 14 | bool system_identifier_read(system_identifier_t *system_id); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /lib/verbose.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Baruch Even 3 | * 4 | * This file is part of DiskScan. 5 | * 6 | * DiskScan is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * DiskScan is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with DiskScan. If not, see . 18 | * 19 | */ 20 | 21 | #include "verbose.h" 22 | 23 | int verbose; 24 | -------------------------------------------------------------------------------- /libscsicmd/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | .*.d 3 | .gdb_history 4 | tags 5 | libscsicmd.a 6 | ata_identify 7 | ata_identify_dump.[ch] 8 | ata_smart_return_status 9 | ata_smart_read_data 10 | ata_check_power_mode 11 | sense_decode 12 | scsi_read_capacity_10 13 | scsi_read_capacity_16 14 | scsi_inquiry 15 | scsi_log_sense 16 | scsi_mode_sense 17 | scsi_receive_diagnostics 18 | parse_scsi 19 | collect_raw_data 20 | test/libtestlib.a 21 | 22 | CMakeCache.txt 23 | CMakeFiles 24 | Makefile 25 | cmake_install.cmake 26 | -------------------------------------------------------------------------------- /libscsicmd/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(libscsicmd) 3 | 4 | export(PACKAGE libscsicmd) 5 | 6 | include_directories("include") 7 | add_compile_options(-Wall -Wextra -Wshadow -Wmissing-prototypes -Winit-self -g) 8 | add_definitions(-D_GNU_SOURCE -D_FORTIFY_SOURCE=2) 9 | 10 | set(CMAKE_C_FLAGS_DEBUG "-Werror -O0 ${CMAKE_C_FLAGS_DEBUG}") 11 | set(CMAKE_C_FLAGS_RELEASE "-Wall -O3 ${CMAKE_C_FLAGS_RELEASE}") 12 | 13 | add_subdirectory(src) 14 | add_subdirectory(test) 15 | -------------------------------------------------------------------------------- /libscsicmd/README.md: -------------------------------------------------------------------------------- 1 | # libscsicmd 2 | 3 | A library to create SCSI commands (CDBs) and parse the results, also for ATA commands and results. 4 | 5 | This library doesn't deal with actually submitting the CDBs or getting the results from the storage device, only with 6 | the commands themselves. The actual sending of the command is different between the different OSes and this library 7 | tries to be OS agnostic. 8 | 9 | ## Build 10 | 11 | The build system is using cmake, you need to get it before you can build. 12 | 13 | To build, run: 14 | 15 | cmake . && make 16 | 17 | For a developer debug build use: 18 | 19 | cmake -DCMAKE_BUILD_TYPE=Debug . 20 | 21 | To build for American Fuzzy Lop instrumentation: 22 | 23 | cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=/usr/bin/afl-gcc -DCMAKE_C_FLAGS=-DAFL_HARDEN=1 . 24 | 25 | ## Testing 26 | 27 | Testing is either done manually with some raw data collected from SCSI devices 28 | with test/collect\_raw\_data or with American Fuzzy Lop (AFL) for parsing 29 | problems. 30 | 31 | Using AFL: 32 | 33 | afl-fuzz -t 200 -i afl/testcase -o afl/finding test/parse_scsi 34 | 35 | ## Author 36 | 37 | Baruch Even 38 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/1b5fac8682806d6e823c301159d6da81e30f421a: -------------------------------------------------------------------------------- 1 | ,4d 00 40 03 00 00 00 40 00 00,70 00 05 00 00 00 00 18 00 00 00 00 24 00 00 c0 00 03 00 00 f8 23 00 00 00 00 00 00 00 00 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/28eeac63bfcf7ad2126d2eddcdc04019270075ec: -------------------------------------------------------------------------------- 1 | ,1c 01 05 40 00 00,,05 00 01 50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 46 41 14 0f 76 73 14 0f 76 73 14 0f 76 73 14 0f 76 73 14 0f 55 52 14 0f 55 52 14 0f 76 73 14 0f 76 73 14 0f 55 52 14 0f 55 52 14 0f 76 73 14 0f 76 73 14 0f 55 52 14 0f 55 52 14 0f 76 73 14 0f 76 73 14 0f 55 52 14 0f 55 52 14 0f 76 73 14 0f 76 73 14 0f 00 00 00 00 0e 0a 0a 14 0e 0a 0a 14 0e 0a 0a 14 0e 0a 0a 14 0e 0a 0a 14 0e 0a 0a 14 0e 0a 0a 14 0e 0a 0a 14 0e 0a 0a 14 0e 0a 0a 14 0e 0a 0a 14 0e 0a 0a 14 0e 0a 0a 14 0e 0a 0a 14 0e 0a 0a 14 0e 0a 0a 14 0e 0a 0a 14 0e 0a 0a 14 0e 0a 0a 14 0e 0a 0a 14 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/2b34251f3421af9a5c53a41f7e27f1cc3e8a13b0: -------------------------------------------------------------------------------- 1 | ,5a 00 3f ff 00 00 00 10 00 00,,00 3a 00 00 00 00 00 00 02 0e 00 00 00 00 00 00 27 10 00 09 00 00 00 00 0a 0a 00 00 00 00 00 00 00 00 00 00 18 06 06 00 00 00 00 00 19 0e 46 00 07 d0 00 00 00 00 00 00 00 00 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/39c99f32ec43d6ee12857a64e031114ae7cf23cd.csv: -------------------------------------------------------------------------------- 1 | ,25 00 00 00 00 00 00 00 00 00,, 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/4941885df82498d8ca26375728606d41be818e27: -------------------------------------------------------------------------------- 1 | ,4d 00 40 ff 00 00 00 40 00 00,,00 00 00 4c 00 00 00 ff 02 00 02 ff 03 00 03 ff 05 00 05 ff 06 00 06 ff 0c 00 0c ff 0d 00 0d ff 0e 00 0e ff 0f 00 0f ff 10 00 10 ff 11 00 11 ff 15 00 15 ff 18 00 18 ff 19 00 19 ff 1a 00 1a ff 2f 00 2f ff 30 00 30 ff 31 00 31 ff 38 00 38 ff 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/554ff10f0a6f35849db7e44176aa94c6dc232872.csv: -------------------------------------------------------------------------------- 1 | ,9e 10 00 00 00 00 00 00 00 00 00 00 02 00 00 00,, 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/5b7d04cbfbe29ec8f91526131c87e7cc8e9ea10e: -------------------------------------------------------------------------------- 1 | ,4d 00 40 ff 00 00 00 40 00 00,,40 ff 00 44 00 00 00 ff 02 00 02 ff 03 00 03 ff 05 00 05 ff 06 00 06 ff 0d 00 0d ff 0e 00 0e ff 0f 00 0f ff 10 00 10 ff 11 00 11 ff 15 00 15 ff 18 00 18 ff 1a 00 1a ff 2f 00 2f ff 30 00 30 ff 31 00 31 ff 37 00 37 ff 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/617ce3a43c7dbb1ba99a422ce455c1b55d2260b4.csv: -------------------------------------------------------------------------------- 1 | ,1c 01 00 40 00 00,,00 00 00 0a 00 01 02 04 05 07 0d 0e 0f 1d 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/6184436113637747407bf86315ebd987300b8799: -------------------------------------------------------------------------------- 1 | ,37 00 0a 00 00 00 00 02 00 00,,00 0a 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/657af263aa78ee4d6b755df9e00a159d5c88dc2a.csv: -------------------------------------------------------------------------------- 1 | ,1c 01 00 40 00 00,,00 00 00 02 00 3f 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/745f69394ad87d7d234e796b1a54a31f970e2510.csv: -------------------------------------------------------------------------------- 1 | ,1a 00 3f ff ff 00,,37 00 00 08 00 00 00 00 00 00 02 00 01 0a 80 00 00 00 00 00 00 00 00 00 08 12 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0a 0a 02 00 00 00 00 00 ff ff 00 1e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/7c597125d72d146425d1899f6512b82df99b59c1: -------------------------------------------------------------------------------- 1 | ,b7 14 00 00 00 00 00 00 02 00 00 00,,00 16 00 00 00 00 17 f8 00 00 00 72 00 00 00 33 00 00 00 0f 00 00 00 70 00 00 00 17 00 00 00 cc 00 00 00 17 00 00 00 d0 00 00 00 61 00 00 01 85 00 00 00 0f 00 00 02 00 00 00 00 00 00 00 02 02 00 00 00 00 00 00 02 03 00 00 00 01 00 00 02 02 00 00 00 01 00 00 02 03 00 00 00 02 00 00 02 02 00 00 00 02 00 00 02 03 00 00 00 03 00 00 02 02 00 00 00 03 00 00 02 03 00 00 00 04 00 00 02 02 00 00 00 04 00 00 02 03 00 00 00 05 00 00 02 02 00 00 00 05 00 00 02 03 00 00 00 06 00 00 02 02 00 00 00 06 00 00 02 03 00 00 00 07 00 00 02 02 00 00 00 07 00 00 02 03 00 00 00 08 00 00 02 02 00 00 00 08 00 00 02 03 00 00 00 09 00 00 02 02 00 00 00 09 00 00 02 03 00 00 00 0a 00 00 02 02 00 00 00 0a 00 00 02 03 00 00 00 0b 00 00 02 02 00 00 00 0b 00 00 02 03 00 00 00 0c 00 00 02 02 00 00 00 0c 00 00 02 03 00 00 00 0d 00 00 02 02 00 00 00 0d 00 00 02 03 00 00 00 0e 00 00 02 02 00 00 00 0e 00 00 02 03 00 00 00 0f 00 00 02 02 00 00 00 0f 00 00 02 03 00 00 00 10 00 00 02 02 00 00 00 10 00 00 02 03 00 00 00 11 00 00 02 02 00 00 00 11 00 00 02 03 00 00 00 12 00 00 02 02 00 00 00 12 00 00 02 03 00 00 00 13 00 00 02 02 00 00 00 13 00 00 02 03 00 00 00 14 00 00 02 02 00 00 00 14 00 00 02 03 00 00 00 15 00 00 02 02 00 00 00 15 00 00 02 03 00 00 00 16 00 00 02 02 00 00 00 16 00 00 02 03 00 00 00 17 00 00 02 02 00 00 00 17 00 00 02 03 00 00 00 18 00 00 02 02 00 00 00 18 00 00 02 03 00 00 00 19 00 00 02 02 00 00 00 19 00 00 02 03 00 00 00 1a 00 00 02 02 00 00 00 1a 00 00 02 03 00 00 00 1b 00 00 02 02 00 00 00 1b 00 00 02 0 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/7e1e393db35bd119ab38a395829ff5deadd9501a: -------------------------------------------------------------------------------- 1 | ,1c 01 1b 40 00 00,,1b 00 00 04 00 01 00 03 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/7eeaad7ca0a2197d1283c87d441a15f6c8d5e6f6: -------------------------------------------------------------------------------- 1 | ,25 00 00 00 00 00 00 00 00 00,70 00 04 00 00 00 00 18 00 00 00 00 29 07 00 00 00 00 00 00 f5 19 00 00 00 00 00 00 00 00 00 00, 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/801bc5987bfe420b04e07eb1cd5ae0462a0b750c: -------------------------------------------------------------------------------- 1 | ,37 00 0e 00 00 00 00 00 08 00,70 00 01 00 00 00 00 10 00 00 00 00 1c 00 00 80 00 00 00 21 1c 00 00 00,00 0c 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/8329e3313860bfd6b8dd1252b4a4542d4c791f13.csv: -------------------------------------------------------------------------------- 1 | ,37 00 08 00 00 00 00 00 08 00,,00 00 00 05 00 3f 45 46 82 27 21 60 00 00 02 00 81 0a c4 01 00 00 00 00 00 00 0c 00 82 0e 00 00 00 00 00 00 01 f4 00 00 00 00 00 00 03 16 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 40 00 00 00 04 16 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 87 0a 04 01 00 00 00 00 00 00 0c 00 88 12 10 00 ff ff 00 00 ff ff ff ff 00 00 00 00 00 00 00 00 8a 0a 00 10 00 00 00 00 00 00 00 06 ca 01 00 1c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ca 02 01 8c 00 00 00 00 00 00 00 00 00 00 00 00 80 00 00 00 00 00 ff ff 00 00 00 00 00 00 00 00 ff ff ff ff ff ff ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/86f870fdeb8e99954869aaf1b58e456109e2e6c8: -------------------------------------------------------------------------------- 1 | ,37 00 0a 00 00 00 00 00 08 00,70 00 01 00 00 00 00 18 00 00 00 00 1c 02 00 c0 00 02 00 00 17 48 00 00 00 00 00 00 00 00 00 00,00 0e 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/90548a1ef4bae0b9b7382497097a01691333fb4f: -------------------------------------------------------------------------------- 1 | ,1c 01 01 40 00 00,,01 04 04 68 00 00 00 08 11 00 0a ea 50 06 04 80 a0 1c 19 3e 45 4d 43 20 20 20 20 20 44 65 72 72 69 6e 67 65 72 20 4c 43 43 20 20 20 30 42 33 30 07 81 42 02 00 01 02 55 53 31 44 30 31 31 30 35 30 30 30 35 39 00 00 05 40 a6 20 31 35 31 20 53 58 50 20 33 36 78 36 47 73 65 63 00 40 20 20 33 31 34 20 53 58 50 20 33 36 78 36 47 73 65 63 00 40 21 20 32 32 32 20 53 58 50 20 33 36 78 36 47 73 65 63 00 40 22 20 32 31 36 20 53 58 50 20 33 36 78 36 47 73 65 63 00 40 23 20 30 32 31 20 43 44 45 46 00 00 00 00 00 00 00 00 00 10 02 80 00 01 03 00 02 01 04 80 02 00 05 01 40 00 06 03 40 00 07 85 00 00 08 86 00 00 09 02 00 00 0a 02 01 00 0b 02 02 00 0c 02 03 00 0d 02 04 00 0e 02 05 00 0f 02 06 00 10 02 07 00 11 04 00 00 02 c0 c1 05 4c 43 43 20 42 11 01 06 b5 50 06 04 80 d8 21 42 be 45 4d 43 20 20 20 20 20 44 65 72 72 69 6e 67 65 72 20 4c 43 43 20 20 20 30 42 33 30 07 80 41 02 01 00 01 4a 57 58 45 4c 31 33 30 35 30 30 35 35 31 00 00 05 5a 06 20 31 35 31 20 53 58 50 20 33 36 78 36 47 73 65 63 00 5a 00 20 33 31 34 20 53 58 50 20 33 36 78 36 47 73 65 63 00 5a 01 20 32 32 32 20 53 58 50 20 33 36 78 36 47 73 65 63 00 5a 02 20 32 31 36 20 53 58 50 20 33 36 78 36 47 73 65 63 00 5a 03 20 30 32 31 20 43 44 45 46 00 00 00 00 00 00 00 00 00 03 12 00 03 01 13 80 03 00 14 03 5a 00 01 c2 05 4c 43 43 20 41 11 02 04 4f 50 06 04 80 00 00 00 00 45 4d 43 20 20 20 20 20 44 65 72 72 69 6e 67 65 72 20 45 6e 63 6c 20 20 30 30 31 31 0e 1f 4d 02 02 02 00 43 4b 4d 30 30 31 33 31 38 30 31 37 35 38 00 00 00 02 00 00 01 01 01 80 01 00 01 c3 07 43 68 61 73 73 69 73 11 03 03 6a 50 06 04 80 00 00 00 00 45 4d 43 20 20 20 20 20 30 30 30 42 30 30 31 39 00 00 00 00 00 00 00 00 32 41 31 30 02 81 42 02 00 04 33 41 43 37 42 30 31 33 30 32 31 37 38 31 39 20 20 01 86 a4 20 35 2e 33 33 53 58 50 33 36 78 36 47 00 00 00 00 00 02 15 00 04 01 16 80 04 00 01 c4 0e 50 6f 77 65 72 20 53 75 70 70 6c 79 20 42 11 04 03 56 50 06 04 80 00 00 00 00 45 4d 43 20 20 20 20 20 45 4d 43 20 44 45 52 52 49 4e 47 45 52 20 50 53 43 30 33 30 02 80 41 02 01 03 32 41 43 37 42 30 31 33 30 32 31 37 35 31 38 20 20 00 02 17 00 05 01 18 80 05 00 01 c5 0e 50 6f 77 65 72 20 53 75 70 70 6c 79 20 41 17 19 00 0c 04 01 00 0e 0e 01 00 05 81 25 00 0c 18 01 00 0a 07 01 00 0c 19 0a 00 0f 0c 02 00 0d 0c 01 00 0c 10 01 00 08 04 01 01 0e 0e 01 01 05 81 08 01 0c 18 01 01 0a 07 01 01 0c 19 0a 01 0f 0e 01 02 09 03 00 02 0d 04 01 02 0e 19 1a 02 0f 03 02 03 0d 04 02 03 0e 02 01 03 0e 03 02 04 0d 04 02 04 0e 02 01 04 0e 41 72 72 61 79 20 44 65 76 69 63 65 54 65 6d 70 2e 20 53 65 6e 73 6f 72 20 42 4c 43 43 20 42 45 78 70 61 6e 64 65 72 20 50 68 79 45 78 70 61 6e 64 65 72 20 42 43 6f 6e 74 72 6f 6c 6c 65 72 20 42 53 41 53 20 43 6f 6e 6e 65 63 74 6f 72 20 42 44 69 73 70 6c 61 79 20 47 72 65 65 6e 44 69 73 70 6c 61 79 20 42 6c 75 65 4c 61 6e 67 75 61 67 65 54 65 6d 70 2e 20 53 65 6e 73 6f 72 20 41 4c 43 43 20 41 45 78 70 61 6e 64 65 72 20 50 68 79 45 78 70 61 6e 64 65 72 20 41 43 6f 6e 74 72 6f 6c 6c 65 72 20 41 53 41 53 20 43 6f 6e 6e 65 63 74 6f 72 20 41 45 6e 63 6c 6f 73 75 72 65 43 6f 6f 6c 69 6e 67 20 46 61 6e 20 4d 54 65 6d 70 2e 20 53 65 6e 73 6f 72 20 4d 53 41 53 20 43 6f 6e 6e 65 63 74 6f 72 20 4d 43 6f 6f 6c 69 6e 67 20 46 61 6e 20 42 54 65 6d 70 2e 20 53 65 6e 73 6f 72 20 42 50 6f 77 65 72 20 53 75 70 70 6c 79 20 42 43 6f 6f 6c 69 6e 67 20 46 61 6e 20 41 54 65 6d 70 2e 20 53 65 6e 73 6f 72 20 41 50 6f 77 65 72 20 53 75 70 70 6c 79 20 41 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/9062ca40d53bbf790d9338ed79b5215ca76178d2.csv: -------------------------------------------------------------------------------- 1 | ,1c 01 00 40 00 00,,00 00 00 03 00 3f 82 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/961ce3b94d711105a238b82068012e5b765b4027: -------------------------------------------------------------------------------- 1 | ,1c 01 00 40 00 00,70 00 02 00 00 00 00 18 00 00 00 00 31 01 00 00 00 00 00 00 f5 07 00 00 00 00 00 00 00 00 00 00, 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/9c3040be62f1785b6387524185ae7508966a8fca: -------------------------------------------------------------------------------- 1 | ,4d 00 40 ff 00 00 00 40 00 00,,40 ff 00 04 00 ff 34 ff 00 00 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/9da9f3b23df2a728a486968d9e4f4a87aff34bf6.csv: -------------------------------------------------------------------------------- 1 | ,1c 01 00 40 00 00,,00 00 00 11 00 01 02 04 05 0a 0e 10 11 80 81 82 83 90 91 f0 f1 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/a051877bf52e199210ffd96778f7698e3dc6978e.csv: -------------------------------------------------------------------------------- 1 | ,1c 01 04 40 00 00,,04 00 01 fa 30 37 3a 30 32 3a 31 31 3a 35 34 3a 35 33 37 20 74 6e 6c 2f 74 75 6e 6e 65 6c 5f 73 74 65 5f 72 65 63 76 5f 64 69 61 67 5f 6d 73 67 5f 68 61 6e 64 6c 65 72 3a 20 74 75 6e 6e 65 6c 69 6e 67 20 52 45 43 56 20 44 49 41 47 4e 4f 53 54 49 43 20 72 65 63 65 69 76 65 64 20 66 72 6f 6d 20 53 54 45 2e 0a 30 37 3a 30 32 3a 31 31 3a 35 34 3a 37 34 38 20 64 65 76 2f 70 68 79 2e 32 32 3a 20 72 65 61 64 79 0a 30 37 3a 30 32 3a 31 31 3a 35 34 3a 37 35 31 20 64 65 76 2f 70 68 79 2e 32 32 3a 20 6c 69 6e 6b 20 72 65 61 64 79 0a 30 37 3a 30 32 3a 31 31 3a 35 34 3a 37 35 38 20 64 65 76 2f 70 68 79 2e 32 32 3a 20 72 61 74 65 20 75 6e 6b 6e 6f 77 6e 2d 3e 36 47 0a 30 37 3a 30 32 3a 31 31 3a 35 34 3a 37 36 32 20 64 65 76 2f 70 68 79 2e 32 32 3a 20 61 74 74 61 63 68 65 64 20 70 68 79 20 69 64 20 30 78 66 66 2d 3e 30 78 30 30 0a 30 37 3a 30 32 3a 31 31 3a 35 34 3a 37 38 37 20 45 53 45 53 3a 20 66 77 64 6c 20 70 72 74 74 6e 20 63 6e 74 72 6c 20 73 74 61 74 75 73 20 72 65 63 65 69 76 65 64 3a 20 61 63 74 69 76 65 3a 20 31 20 64 61 74 61 3a 20 30 20 69 6d 67 30 63 72 63 3a 20 30 78 62 64 20 69 6d 67 31 63 72 63 3a 20 30 78 61 34 0a 30 37 3a 30 32 3a 31 31 3a 35 36 3a 37 37 35 20 45 4d 43 20 53 54 45 3a 20 54 6f 74 61 6c 20 6e 75 6d 62 65 72 20 6f 66 20 56 50 44 20 70 61 67 65 73 20 77 61 73 20 31 30 2c 20 6e 6f 77 20 31 30 0a 30 37 3a 30 32 3a 31 31 3a 35 36 3a 37 38 34 20 45 4d 43 20 53 54 45 3a 20 54 6f 74 61 6c 20 6e 75 6d 62 65 72 20 6f 66 20 56 50 44 20 70 61 67 65 73 20 77 61 73 20 31 30 2c 20 6e 6f 77 20 31 30 0a 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/a4005cb54f820f0dc3889aab343ea1698b1dd5f4.csv: -------------------------------------------------------------------------------- 1 | ,b7 0d 00 00 00 00 00 00 02 00 00 00,,00 0e 00 00 00 00 01 98 00 00 00 00 00 00 00 b6 00 00 00 00 00 00 04 62 00 00 00 00 00 00 00 70 00 00 00 00 00 00 00 98 00 00 00 00 00 00 02 ce 00 00 00 00 00 00 02 14 00 00 00 00 00 00 06 64 00 00 00 00 00 00 05 4a 00 00 00 00 00 00 07 02 00 00 00 00 00 00 04 bc 00 00 00 00 00 00 04 08 00 00 00 00 00 00 04 54 00 00 00 00 00 00 03 98 00 00 00 00 00 00 06 6e 00 00 00 00 00 00 00 9e 00 00 00 00 00 00 03 c0 00 00 00 00 00 00 01 12 00 00 00 00 00 00 02 92 00 00 00 00 00 00 02 a8 00 00 00 00 00 00 02 8c 00 00 00 00 00 00 04 de 00 00 00 00 00 00 03 a2 00 00 00 00 00 00 07 36 00 00 00 00 00 00 07 3e 00 00 00 00 00 00 04 40 00 00 00 00 00 00 05 0e 00 00 00 00 00 00 01 52 00 00 00 00 00 00 02 34 00 00 00 00 00 00 00 36 00 00 00 00 00 00 00 8c 00 00 00 00 00 00 05 b4 00 00 00 00 00 00 01 82 00 00 00 00 00 00 05 36 00 00 00 00 00 00 02 16 00 00 00 00 00 00 06 f2 00 00 00 00 00 00 04 ea 00 00 00 00 00 00 02 86 00 00 00 00 00 00 03 b8 00 00 00 00 00 00 01 60 00 00 00 00 00 00 05 cc 00 00 00 00 00 00 07 56 00 00 00 00 00 00 01 dc 00 00 00 00 00 00 01 3a 00 00 00 00 00 00 05 a0 00 00 00 00 00 00 05 08 00 00 00 00 00 00 01 a6 00 00 00 00 00 00 06 c0 00 00 00 00 00 00 05 d4 00 00 00 00 00 00 05 aa 00 00 00 00 00 00 00 e8 00 00 00 00 00 00 04 24 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/a6b72fc2c30cf1d9ff74a2d5054bcb5dca317c15: -------------------------------------------------------------------------------- 1 | ,25 00 00 00 00 00 00 00 00 00,70 00 06 00 00 00 00 18 00 00 00 00 3f 01 00 00 00 00 00 00 f5 22 00 00 00 00 00 00 00 00 00 00, 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/a750591769e551117e3144c8927a05d96fdfb362: -------------------------------------------------------------------------------- 1 | ,4d 00 42 00 00 00 00 40 00 00,,02 00 00 36 00 00 00 04 00 00 00 00 00 01 00 04 00 00 00 00 00 02 00 04 00 00 00 00 00 03 00 04 00 00 00 00 00 05 00 0a 00 00 00 00 00 00 00 01 80 00 00 06 00 04 00 00 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/b2eeafbc752b681e5d68332192c8097ef43ab687.csv: -------------------------------------------------------------------------------- 1 | ,37 00 08 00 00 00 00 00 08 00,, 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/b40a88e1e4a0e0044936b2e61de5364d48b16e8c.csv: -------------------------------------------------------------------------------- 1 | ,1a 00 7f ff ff 00,, 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/c144c7638bb08162db1ae53954e6cd20e66474f7: -------------------------------------------------------------------------------- 1 | ,b7 0a 00 00 00 00 00 00 02 00 00 00,,00 83 00 48 01 03 00 08 50 00 cc a0 2b 03 e0 b0 61 93 00 08 50 00 cc a0 2b 03 e0 b2 61 94 00 04 00 00 00 02 61 a3 00 08 50 00 cc a0 2b 03 e0 b3 63 a8 00 18 6e 61 61 2e 35 30 30 30 43 43 41 30 32 42 30 33 45 30 42 33 00 00 00 00 00 00 02 03 00 00 00 03 00 00 02 02 00 00 00 03 00 00 02 03 00 00 00 04 00 00 02 02 00 00 00 04 00 00 02 03 00 00 00 05 00 00 02 02 00 00 00 05 00 00 02 03 00 00 00 06 00 00 02 02 00 00 00 06 00 00 02 03 00 00 00 07 00 00 02 02 00 00 00 07 00 00 02 03 00 00 00 08 00 00 02 02 00 00 00 08 00 00 02 03 00 00 00 09 00 00 02 02 00 00 00 09 00 00 02 03 00 00 00 0a 00 00 02 02 00 00 00 0a 00 00 02 03 00 00 00 0b 00 00 02 02 00 00 00 0b 00 00 02 03 00 00 00 0c 00 00 02 02 00 00 00 0c 00 00 02 03 00 00 00 0d 00 00 02 02 00 00 00 0d 00 00 02 03 00 00 00 0e 00 00 02 02 00 00 00 0e 00 00 02 03 00 00 00 0f 00 00 02 02 00 00 00 0f 00 00 02 03 00 00 00 10 00 00 02 02 00 00 00 10 00 00 02 03 00 00 00 11 00 00 02 02 00 00 00 11 00 00 02 03 00 00 00 12 00 00 02 02 00 00 00 12 00 00 02 03 00 00 00 13 00 00 02 02 00 00 00 13 00 00 02 03 00 00 00 14 00 00 02 02 00 00 00 14 00 00 02 03 00 00 00 15 00 00 02 02 00 00 00 15 00 00 02 03 00 00 00 16 00 00 02 02 00 00 00 16 00 00 02 03 00 00 00 17 00 00 02 02 00 00 00 17 00 00 02 03 00 00 00 18 00 00 02 02 00 00 00 18 00 00 02 03 00 00 00 19 00 00 02 02 00 00 00 19 00 00 02 03 00 00 00 1a 00 00 02 02 00 00 00 1a 00 00 02 03 00 00 00 1b 00 00 02 02 00 00 00 1b 00 00 02 03 00 00 00 1c 00 00 02 02 00 00 00 1c 00 00 02 03 00 00 00 1d 00 00 02 02 00 00 00 1d 00 00 02 03 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/ca52cd17cb1a061767830cb4e49867be9b637e56: -------------------------------------------------------------------------------- 1 | ,1c 01 04 40 00 00,,04 00 04 5f 30 33 3a 31 36 3a 35 38 3a 31 32 3a 32 30 39 20 45 4d 43 20 53 54 45 3a 20 54 6f 74 61 6c 20 6e 75 6d 62 65 72 20 6f 66 20 56 50 44 20 70 61 67 65 73 20 77 61 73 20 31 30 2c 20 6e 6f 77 20 31 30 0a 30 33 3a 31 36 3a 35 38 3a 31 32 3a 32 31 38 20 45 4d 43 20 53 54 45 3a 20 54 6f 74 61 6c 20 6e 75 6d 62 65 72 20 6f 66 20 56 50 44 20 70 61 67 65 73 20 77 61 73 20 31 30 2c 20 6e 6f 77 20 31 30 0a 30 33 3a 31 36 3a 35 38 3a 31 32 3a 32 32 39 20 64 65 76 2f 70 68 79 2e 30 3a 20 45 4e 41 42 4c 45 44 2d 3e 44 49 53 41 42 4c 45 44 0a 30 33 3a 31 36 3a 35 38 3a 31 32 3a 32 34 31 20 64 65 76 2f 70 68 79 2e 31 3a 20 45 4e 41 42 4c 45 44 2d 3e 44 49 53 41 42 4c 45 44 0a 30 33 3a 31 36 3a 35 38 3a 31 32 3a 32 35 33 20 64 65 76 2f 70 68 79 2e 32 3a 20 45 4e 41 42 4c 45 44 2d 3e 44 49 53 41 42 4c 45 44 0a 30 33 3a 31 36 3a 35 38 3a 31 32 3a 32 36 32 20 64 65 76 2f 70 68 79 2e 33 3a 20 45 4e 41 42 4c 45 44 2d 3e 44 49 53 41 42 4c 45 44 0a 30 33 3a 31 36 3a 35 38 3a 31 32 3a 32 36 37 20 64 65 76 2f 70 68 79 2e 30 3a 20 6e 6f 74 20 72 65 61 64 79 0a 30 33 3a 31 36 3a 35 38 3a 31 32 3a 32 37 32 20 64 65 76 2f 70 68 79 2e 30 3a 20 6c 69 6e 6b 20 6e 6f 74 20 72 65 61 64 79 0a 30 33 3a 31 36 3a 35 38 3a 31 32 3a 32 38 33 20 64 65 76 2f 70 68 79 2e 30 3a 20 72 61 74 65 20 36 47 2d 3e 75 6e 6b 6e 6f 77 6e 0a 30 33 3a 31 36 3a 35 38 3a 31 32 3a 32 38 39 20 64 65 76 2f 70 68 79 2e 30 3a 20 61 74 74 61 63 68 65 64 20 70 68 79 20 69 64 20 30 78 30 34 2d 3e 30 78 66 66 0a 30 33 3a 31 36 3a 35 38 3a 31 32 3a 33 30 31 20 64 65 76 2f 70 68 79 2e 31 3a 20 6e 6f 74 20 72 65 61 64 79 0a 30 33 3a 31 36 3a 35 38 3a 31 32 3a 33 30 36 20 64 65 76 2f 70 68 79 2e 31 3a 20 6c 69 6e 6b 20 6e 6f 74 20 72 65 61 64 79 0a 30 33 3a 31 36 3a 35 38 3a 31 32 3a 33 31 30 20 64 65 76 2f 70 68 79 2e 31 3a 20 72 61 74 65 20 36 47 2d 3e 75 6e 6b 6e 6f 77 6e 0a 30 33 3a 31 36 3a 35 38 3a 31 32 3a 33 31 35 20 64 65 76 2f 70 68 79 2e 31 3a 20 61 74 74 61 63 68 65 64 20 70 68 79 20 69 64 20 30 78 30 35 2d 3e 30 78 66 66 0a 30 33 3a 31 36 3a 35 38 3a 31 32 3a 33 32 37 20 74 6e 6c 2f 74 75 6e 6e 65 6c 5f 73 74 65 5f 72 65 63 76 5f 64 69 61 67 5f 6d 73 67 5f 68 61 6e 64 6c 65 72 3a 20 74 75 6e 6e 65 6c 69 6e 67 20 52 45 43 56 20 44 49 41 47 4e 4f 53 54 49 43 20 72 65 63 65 69 76 65 64 20 66 72 6f 6d 20 53 54 45 2e 0a 30 33 3a 31 36 3a 35 38 3a 31 32 3a 33 32 38 20 64 65 76 2f 70 68 79 2e 32 3a 20 6e 6f 74 20 72 65 61 64 79 0a 30 33 3a 31 36 3a 35 38 3a 31 32 3a 33 34 34 20 64 65 76 2f 70 68 79 2e 32 3a 20 6c 69 6e 6b 20 6e 6f 74 20 72 65 61 64 79 0a 30 33 3a 31 36 3a 35 38 3a 31 32 3a 33 34 38 20 64 65 76 2f 70 68 79 2e 32 3a 20 72 61 74 65 20 36 47 2d 3e 75 6e 6b 6e 6f 77 6e 0a 30 33 3a 31 36 3a 35 38 3a 31 32 3a 33 35 32 20 64 65 76 2f 70 68 79 2e 32 3a 20 61 74 74 61 63 68 65 64 20 70 68 79 20 69 64 20 30 78 30 36 2d 3e 30 78 66 66 0a 30 33 3a 31 36 3a 35 38 3a 31 32 3a 33 36 34 20 64 65 76 2f 70 68 79 2e 33 3a 20 6e 6f 74 20 72 65 61 64 79 0a 30 33 3a 31 36 3a 35 38 3a 31 32 3a 33 36 38 20 64 65 76 2f 70 68 79 2e 33 3a 20 6c 69 6e 6b 20 6e 6f 74 20 72 65 61 64 79 0a 30 33 3a 31 36 3a 35 38 3a 31 32 3a 33 37 33 20 64 65 76 2f 70 68 79 2e 33 3a 20 72 61 74 65 20 36 47 2d 3e 75 6e 6b 6e 6f 77 6e 0a 30 33 3a 31 36 3a 35 38 3a 31 32 3a 33 37 38 20 64 65 76 2f 70 68 79 2e 33 3a 20 61 74 74 61 63 68 65 64 20 70 68 79 20 69 64 20 30 78 30 37 2d 3e 30 78 66 66 0a 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/ce03e25003a16fc03abb3d4f337a39e622962c60: -------------------------------------------------------------------------------- 1 | ,1c 01 02 40 00 00,,02 00 01 00 00 00 00 00 00 00 00 00 11 00 00 00 11 00 00 00 11 00 00 00 11 00 00 00 11 00 00 00 11 00 00 00 11 00 00 00 11 00 00 00 11 00 00 00 11 00 00 00 11 00 00 00 11 00 00 00 11 00 00 00 11 00 00 00 11 00 00 00 11 00 00 00 11 00 00 00 11 00 00 00 00 00 00 00 01 00 2f 00 01 00 30 00 01 00 30 00 01 00 30 00 01 00 30 00 01 00 31 00 01 00 33 00 01 00 34 00 01 00 37 00 01 00 34 00 01 00 34 00 01 00 31 00 01 00 31 00 01 00 30 00 01 00 30 00 01 00 30 00 01 00 30 00 01 00 2e 00 00 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 01 20 00 00 01 20 00 00 01 20 00 00 01 20 00 00 01 20 00 00 01 20 00 00 01 20 00 00 01 20 00 00 01 20 00 00 01 20 00 00 01 20 00 00 01 20 00 00 01 20 00 00 01 20 00 00 01 20 00 00 01 20 00 00 01 20 00 00 01 20 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/d2f9abc5e26020e42b45a32fcf3777cc61ea711c: -------------------------------------------------------------------------------- 1 | ,1a 08 ff ff ff 00,70 00 02 00 00 00 00 18 00 00 00 00 04 03 00 00 00 00 00 00 02 04 03 00 ff ff ff ff ff ff 00 00,01 aa 00 10 01 00 00 10 00 00 00 00 68 cb 9e 30 00 00 00 00 00 00 02 00 81 0a 04 14 ff 00 00 00 05 00 0c 00 82 0e 00 00 00 00 00 00 00 00 01 3a 00 00 00 00 83 16 bb d0 00 00 00 00 03 80 04 c4 02 08 00 01 00 a0 00 18 40 00 00 00 84 16 02 d3 c1 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 27 31 00 00 87 0a 04 14 ff 00 00 00 00 00 0c 00 88 12 10 00 ff ff 00 00 ff ff ff ff 80 03 00 00 00 00 00 00 8a 0a 00 10 00 80 00 00 00 00 00 06 18 06 06 00 00 00 00 00 99 0e 06 00 23 28 1b 58 00 00 00 00 00 00 00 00 59 01 00 64 00 06 00 02 00 00 00 00 10 49 0e 00 50 00 c5 00 68 59 9c bd 50 01 e6 78 7a c0 e0 00 01 00 00 00 00 00 00 00 88 aa 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 50 00 c5 00 68 59 9c be 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/e71ac2a14ce3dd789a00eae0c656b36e2c07186a: -------------------------------------------------------------------------------- 1 | ,1a 08 3f ff ff 00,70 00 02 00 00 00 00 18 00 00 00 00 04 01 00 00 00 00 00 00 f5 02 00 00 00 00 00 00 00 00 00 00, 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/ebc80a44e5ef0a66fddb29c48373701b2eeb5227: -------------------------------------------------------------------------------- 1 | ,4d 00 71 00 00 00 00 40 00 00,,31 00 00 68 80 00 03 08 00 00 00 00 00 00 01 bd 80 01 03 08 00 00 00 00 00 00 01 bd 80 02 03 08 00 00 00 00 00 00 01 97 80 03 03 08 00 00 00 00 00 00 01 a6 8f fa 03 08 00 00 00 00 00 00 01 97 8f fb 03 08 00 00 00 00 00 00 01 a6 8f fc 03 04 00 00 00 63 8f fd 03 04 00 00 00 00 8f fe 03 04 00 00 10 70 8f ff 03 04 00 00 74 04 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/ee66ad0b8b05525c54c4538059714a92646c39fb: -------------------------------------------------------------------------------- 1 | ,1c 01 80 40 00 00,,80 00 00 1c 56 45 4e 44 4f 52 20 20 03 01 41 30 35 30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/eebceb65beacbe25d0db149e5c37198ee5be1912.csv: -------------------------------------------------------------------------------- 1 | ,25 00 00 00 00 00 00 00 00 00,,00 0e 00 00 00 00 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/ef22fafdd3041dc08043fe2bb908e96dffa34ff5: -------------------------------------------------------------------------------- 1 | ,37 00 0b 00 00 00 00 02 00 00,,00 0e 01 18 00 00 00 12 00 00 07 75 00 00 00 12 00 00 00 c1 00 00 00 12 00 00 07 4f 00 00 00 12 00 00 01 3d 00 00 00 12 00 00 05 eb 00 00 00 12 00 00 05 bd 00 00 00 12 00 00 07 33 00 00 00 12 00 00 05 23 00 00 00 12 00 00 04 35 00 00 00 12 00 00 06 ed 00 00 00 12 00 00 01 97 00 00 00 12 00 00 02 07 00 00 00 12 00 00 02 2b 00 00 00 12 00 00 03 f5 00 00 00 12 00 00 04 f7 00 00 00 12 00 00 06 cf 00 00 00 12 00 00 04 17 00 00 00 12 00 00 01 0b 00 00 00 12 00 00 02 73 00 00 00 12 00 00 02 35 00 00 00 12 00 00 02 3d 00 00 00 12 00 00 01 31 00 00 00 12 00 00 03 37 00 00 00 12 00 00 06 07 00 00 00 12 00 00 00 5d 00 00 00 12 00 00 06 af 00 00 00 12 00 00 03 dd 00 00 00 12 00 00 00 6f 00 00 00 12 00 00 06 0d 00 00 00 12 00 00 05 9d 00 00 00 12 00 00 04 49 00 00 00 12 00 00 01 f5 00 00 00 12 00 00 06 a1 00 00 00 12 00 00 03 f3 00 00 00 12 00 00 03 55 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/f007593acbf7f63773efa1b65ef61da7fcefbb34: -------------------------------------------------------------------------------- 1 | ,25 00 00 00 00 00 00 00 00 00,70 00 06 00 00 00 00 0a 00 00 00 00 29 00 00 00 00 00, 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/f3492a44323a0bf7bea4e59b536feaf7620b8e8b: -------------------------------------------------------------------------------- 1 | ,5a 00 3f ff 00 00 00 10 00 00,,00 52 00 00 00 00 00 00 02 0e 00 00 00 00 00 00 00 00 00 09 00 00 00 00 0a 0a 00 00 00 00 00 00 00 00 00 00 18 06 06 00 00 00 00 00 19 06 16 00 00 0a 00 00 a0 0e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 21 0e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/f40e3999c3fe73cd2e50083874537ec000697cb7: -------------------------------------------------------------------------------- 1 | ,25 00 00 00 00 00 00 00 00 00,71 00 04 00 00 00 00 18 00 00 00 00 44 a2 00 00 00 00 00 00 f6 22 00 00 00 00 00 00 00 00 00 00, 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/f5272bcea41574f9cd663f33334c530abcca01d7: -------------------------------------------------------------------------------- 1 | ,1c 01 01 40 00 00,,01 00 00 d8 00 00 00 00 22 00 06 58 50 01 63 60 01 b6 34 3e 51 55 41 4e 54 41 00 00 4a 42 45 20 49 53 49 4d 37 20 20 20 00 00 00 00 30 31 30 34 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 17 12 00 10 04 12 00 10 07 01 00 10 0e 01 00 10 18 01 00 10 19 12 00 10 41 72 72 61 79 20 44 65 76 69 63 65 20 20 20 20 54 65 6d 70 65 72 61 74 75 72 65 20 20 20 20 20 45 4d 4d 20 20 20 20 20 20 20 20 20 20 20 20 20 45 6e 63 6c 6f 73 75 72 65 20 20 20 20 20 20 20 45 78 70 61 6e 64 65 72 20 20 20 20 20 20 20 20 43 6f 6e 6e 65 63 74 6f 72 20 20 20 20 20 20 20 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/f7db47bebdfb5888fae0fbe826b37df33a450292: -------------------------------------------------------------------------------- 1 | ,37 00 08 00 00 00 00 00 08 00,,00 0e 00 00 00 00 00 00 00 00 00 0c 00 00 00 70 00 00 00 0c 00 00 00 8e 00 00 00 0c 00 00 01 06 00 00 00 00 00 00 02 02 00 00 00 00 00 00 02 03 00 00 00 01 00 00 02 02 00 00 00 01 00 00 02 03 00 00 00 02 00 00 02 02 00 00 00 02 00 00 02 03 00 00 00 03 00 00 02 02 00 00 00 03 00 00 02 03 00 00 00 04 00 00 02 02 00 00 00 04 00 00 02 03 00 00 00 05 00 00 02 02 00 00 00 05 00 00 02 03 00 00 00 06 00 00 02 02 00 00 00 06 00 00 02 03 00 00 00 07 00 00 02 02 00 00 00 07 00 00 02 03 00 00 00 08 00 00 02 02 00 00 00 08 00 00 02 03 00 00 00 09 00 00 02 02 00 00 00 09 00 00 02 03 00 00 00 0a 00 00 02 02 00 00 00 0a 00 00 02 03 00 00 00 0b 00 00 02 02 00 00 00 0b 00 00 02 03 00 00 00 0c 00 00 02 02 00 00 00 0c 00 00 02 03 00 00 00 0d 00 00 02 02 00 00 00 0d 00 00 02 03 00 00 00 0e 00 00 02 02 00 00 00 0e 00 00 02 03 00 00 00 0f 00 00 02 02 00 00 00 0f 00 00 02 03 00 00 00 10 00 00 02 02 00 00 00 10 00 00 02 03 00 00 00 11 00 00 02 02 00 00 00 11 00 00 02 03 00 00 00 12 00 00 02 02 00 00 00 12 00 00 02 03 00 00 00 13 00 00 02 02 00 00 00 13 00 00 02 03 00 00 00 14 00 00 02 02 00 00 00 14 00 00 02 03 00 00 00 15 00 00 02 02 00 00 00 15 00 00 02 03 00 00 00 16 00 00 02 02 00 00 00 16 00 00 02 03 00 00 00 17 00 00 02 02 00 00 00 17 00 00 02 03 00 00 00 18 00 00 02 02 00 00 00 18 00 00 02 03 00 00 00 19 00 00 02 02 00 00 00 19 00 00 02 03 00 00 00 1a 00 00 02 02 00 00 00 1a 00 00 02 03 00 00 00 1b 00 00 02 02 00 00 00 1b 00 00 02 03 00 00 00 1c 00 00 02 02 00 00 00 1c 00 00 02 03 00 00 00 1d 00 00 02 02 00 00 00 1d 00 00 02 03 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/f7faaa230cdb97e1aec1e5ca75f89b7ea8b78726: -------------------------------------------------------------------------------- 1 | ,25 00 00 00 00 00 00 00 00 00,70 00 03 00 00 00 00 18 00 00 00 00 31 00 03 00 00 00 00 00 03 31 00 03 ff ff ff ff ff ff 00 00,00 83 00 48 01 03 00 08 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/fb0082d5df4c4f237f65ac2c2717ae46408c17b8.csv: -------------------------------------------------------------------------------- 1 | ,1c 01 00 40 00 00,,00 00 00 04 00 3f 40 82 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/fbc7b5cc87f1afa84d70c82f152761258a3b0ca6: -------------------------------------------------------------------------------- 1 | ,b7 0d 00 00 00 00 00 00 00 08 00 00,,00 0e 00 00 00 00 00 00 00 00 00 00 00 00 00 5a 00 00 00 01 00 00 00 5a 00 00 00 02 00 00 00 5a 00 00 00 03 00 00 00 5a 00 00 00 04 00 00 00 5a 00 00 00 06 00 00 00 5a 00 00 00 07 00 00 00 5a 00 00 00 08 00 00 00 5a 00 00 00 09 00 00 00 5a 00 00 00 0a 00 00 00 5a 00 00 00 0b 00 00 00 5a 00 00 00 12 00 00 00 5a 00 00 00 0c 00 00 00 5a 00 00 00 0d 00 00 00 5a 00 00 00 0e 00 00 00 5a 00 00 00 0f 00 00 00 5a 00 00 00 10 00 00 00 5a 00 00 00 05 00 00 00 5a 00 00 00 11 00 00 00 5a 00 00 00 13 00 00 00 5a 00 00 00 1e 00 00 00 5a 00 00 00 14 00 00 00 5a 00 00 00 15 00 00 00 5a 00 00 00 16 00 00 00 5a 00 00 00 17 00 00 00 5a 00 00 00 1f 00 00 00 5a 00 00 00 20 00 00 00 5a 00 00 00 21 00 00 00 5a 00 00 00 22 00 00 00 5a 00 00 00 23 00 00 00 5a 00 00 00 18 00 00 00 5a 00 00 00 19 00 00 00 5a 00 00 00 1a 00 00 00 5a 00 00 00 1b 00 00 00 5a 00 00 00 1c 00 00 00 5a 00 00 00 1d 00 00 00 5a 00 00 00 24 00 00 00 5a 00 00 00 25 00 00 00 5a 00 00 00 26 00 00 00 5a 00 00 00 27 00 00 00 5a 00 00 00 28 00 00 00 5a 00 00 00 29 00 00 00 5a 00 00 00 2a 00 00 00 5a 00 00 00 2d 00 00 00 5a 00 00 00 2e 00 00 00 5a 00 00 00 2f 00 00 00 5a 00 00 00 30 00 00 00 5a 00 00 00 31 00 00 00 5a 00 00 00 32 00 00 00 5a 00 00 00 33 00 00 00 5a 00 00 00 34 00 00 00 5a 00 00 00 35 00 00 00 5a 00 00 00 2b 00 00 00 5a 00 00 00 2c 00 00 00 5a 00 00 00 06 00 00 00 5b 00 00 00 00 00 00 00 5b 00 00 00 01 00 00 00 5b 00 00 00 04 00 00 00 5b 00 00 00 02 00 00 00 5b 00 00 00 03 00 00 00 5b 00 00 00 05 00 00 00 5b 00 00 00 07 00 00 00 5b 00 00 00 38 00 00 00 5a 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/fc52fecd84a8f8a478b99b4965333a7f9dfa002c: -------------------------------------------------------------------------------- 1 | ,37 00 11 00 00 00 00 00 08 00,70 00 01 00 00 00 00 18 00 00 00 00 1c 01 00 c0 00 02 00 00 17 47 00 00 00 00 00 00 00 00 00 00,00 16 04 50 00 00 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/fcc19a8cc98ada27c4b6a605adca5bb497ad618e: -------------------------------------------------------------------------------- 1 | ,4d 00 4d 00 00 00 00 40 00 00,,0d 00 00 0c 00 00 43 02 00 17 00 01 43 02 00 46 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/fcd8ce757f7d3f54ab0ee3d01007e0a6d70fa288: -------------------------------------------------------------------------------- 1 | ,1a 08 bf ff ff 00,70 00 05 00 00 00 00 18 00 00 00 00 24 00 00 c0 00 04 00 00 05 24 00 00 ff ff ff ff ff ff 00 00,01 aa 00 10 01 00 00 10 00 00 00 00 68 cb 9e 30 00 00 00 00 00 00 02 00 81 0a c4 14 ff 00 00 00 05 00 0c 00 82 0e 00 00 00 00 00 00 00 00 01 3a 00 00 00 00 83 16 bb d0 00 00 00 00 03 80 04 c4 02 00 00 01 00 a0 00 18 40 00 00 00 84 16 02 d3 c1 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 27 31 00 00 87 0a 04 14 ff 00 00 00 00 00 0c 00 88 12 14 00 ff ff 00 00 ff ff ff ff 80 03 00 00 00 00 00 00 8a 0a 00 10 00 80 00 00 00 00 00 06 18 06 06 00 00 00 00 00 99 0e 06 00 23 28 1b 58 00 00 00 00 00 00 00 00 59 01 00 64 00 06 00 02 00 00 00 00 10 49 0e 00 50 00 c5 00 54 97 b0 31 50 01 e6 75 96 b7 10 00 01 00 00 00 00 00 00 00 88 aa 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 50 00 c5 00 54 97 b0 32 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/febd83d39f830202ca6081514960b4242e536df7: -------------------------------------------------------------------------------- 1 | ,5a 08 ff ff 00 00 00 10 00 00,,01 f6 00 00 00 00 00 00 81 0a c8 ff ff 00 00 00 ff 00 13 88 82 0e 00 00 00 0a 00 00 00 00 01 00 00 00 00 00 83 16 00 80 00 00 00 00 00 00 00 80 02 00 00 01 00 00 00 00 40 00 00 00 84 16 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 87 0a 08 ff ff 00 00 00 00 00 13 88 88 12 14 00 ff ff 00 00 00 00 ff ff 00 08 00 00 00 00 00 00 8a 0a 00 00 00 00 00 00 00 00 07 08 ca 01 00 1c 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 98 06 06 00 00 00 00 00 99 0e 06 00 23 28 1b 58 00 00 00 00 00 00 00 00 d9 01 00 64 00 06 01 02 00 00 00 00 21 1a 02 02 50 00 03 96 9c 89 bf e2 50 06 04 80 78 0f c3 3f 0e 00 00 00 00 00 00 00 88 bb 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 21 1a 02 02 50 00 03 96 9c 89 bf e3 50 06 04 80 78 0e dc bf 20 00 00 00 00 00 00 00 88 bb 00 00 00 00 00 00 00 00 00 00 00 00 00 00 d9 02 00 0c 00 06 00 00 00 00 00 00 00 00 00 00 59 03 00 2c 00 06 01 02 00 00 00 10 80 ab 00 00 80 af 00 01 c0 a8 00 01 00 00 0a 00 00 01 00 10 80 ab 00 00 80 af 00 01 c0 a8 00 01 00 00 0a 00 9a 26 00 02 00 00 00 14 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 da 01 00 0c 00 00 00 00 00 00 00 00 00 00 00 00 9c 0a 08 00 00 00 00 00 00 00 00 01 a4 0e 00 00 40 37 0f 13 00 00 00 00 00 00 00 00 e4 01 00 0c 00 00 00 00 00 00 00 00 00 00 00 00 c0 01 00 30 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/fec38c54692c2fcff269370fc1bbb9e598b821a7: -------------------------------------------------------------------------------- 1 | ,1a 00 7f ff ff 00,70 00 02 00 00 00 00 18 00 00 00 00 04 04 00 80 30 9e 00 00 f5 04 00 00 00 00 00 00 00 00 00 00, 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/fec50c6c3f5486958b33beada06857deeff177dd.csv: -------------------------------------------------------------------------------- 1 | ,12 00 00 02 00 00,,0d 00 06 12 83 00 d0 02 45 4d 43 20 20 20 20 20 45 53 45 53 20 45 6e 63 6c 6f 73 75 72 65 20 20 30 30 30 31 50 4d 43 53 49 45 52 41 80 05 02 00 00 00 00 00 00 00 00 00 00 00 00 75 0c 00 03 01 03 e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 03 00 00 00 01 41 50 4d 30 30 31 34 30 37 32 34 32 36 38 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/fedb716d47c930bafffff38b6c274ce9202187ac: -------------------------------------------------------------------------------- 1 | ,1a 08 bf ff ff 00,,00 0e 00 00 00 00 00 00 00 00 00 03 00 00 00 2c 00 00 00 00 00 00 00 5a 00 00 00 01 00 00 00 5a 00 00 00 02 00 00 00 5a 00 00 00 03 00 00 00 5a 00 00 00 04 00 00 00 5a 00 00 00 06 00 00 00 5a 00 00 00 07 00 00 00 5a 00 00 00 08 00 00 00 5a 00 00 00 09 00 00 00 5a 00 00 00 0a 00 00 00 5a 00 00 00 0b 00 00 00 5a 00 00 00 12 00 00 00 5a 00 00 00 0c 00 00 00 5a 00 00 00 0d 00 00 00 5a 00 00 00 0e 00 00 00 5a 00 00 00 0f 00 00 00 5a 00 00 00 10 00 00 00 5a 00 00 00 05 00 00 00 5a 00 00 00 11 00 00 00 5a 00 00 00 13 00 00 00 5a 00 00 00 1e 00 00 00 5a 00 00 00 14 00 00 00 5a 00 00 00 15 00 00 00 5a 00 00 00 16 00 00 00 5a 00 00 00 17 00 00 00 5a 00 00 00 1f 00 00 00 5a 00 00 00 20 00 00 00 5a 00 00 00 21 00 00 00 5a 00 00 00 22 00 00 00 5a 00 00 00 23 00 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/ff0232f5144d65579feeccb6b65687c5056501a7: -------------------------------------------------------------------------------- 1 | ,4d 00 77 00 00 00 00 40 00 00,,37 00 00 28 00 00 02 04 4a 92 79 ba 00 01 02 04 71 dd 1f cd 00 02 02 04 6d 2c da 32 00 03 02 04 01 87 03 91 00 04 02 04 00 00 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/ff3242c96b948a6ded16dd8ae51b1e61c40c5a66: -------------------------------------------------------------------------------- 1 | ,1a 00 bf ff ff 00,70 00 05 00 00 00 00 28 00 00 00 00 24 00 00 c0 00 04 00 1a 13 01 01 00 00 00 00 00 00 00 78 00 00 1d 31 1a 18 00 00 00 00 00 14 00 00 00 00 00, 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/ff5a0c3111af229b7f4ec8c4a38d82ccf7e553a2: -------------------------------------------------------------------------------- 1 | ,1a 08 3f ff ff 00,70 00 05 00 00 00 00 18 00 00 00 00 24 00 00 c0 00 04 00 00 05 24 00 00 ff ff ff ff ff ff 00 00,01 aa 00 10 01 00 00 10 00 00 00 00 68 cb 9e 30 00 00 00 00 00 00 02 00 81 0a 04 14 ff 00 00 00 05 00 0c 00 82 0e 00 00 00 00 00 00 00 00 01 3a 00 00 00 00 83 16 bb d0 00 00 00 00 03 80 04 c4 02 00 00 01 00 a0 00 18 40 00 00 00 84 16 02 d3 c1 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 27 31 00 00 87 0a 04 14 ff 00 00 00 00 00 0c 00 88 12 14 00 ff ff 00 00 ff ff ff ff 80 03 00 00 00 00 00 00 8a 0a 00 10 00 80 00 00 00 00 00 06 18 06 06 00 00 00 00 00 99 0e 06 00 23 28 1b 58 00 00 00 00 00 00 00 00 59 01 00 64 00 06 00 02 00 00 00 00 10 49 0e 00 50 00 c5 00 70 c8 b6 d5 50 01 e6 78 ea fa c0 00 01 00 00 00 00 00 00 00 88 aa 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 50 00 c5 00 70 c8 b6 d6 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/ff5f50f7b5d36b765da768ef583a8b289be09a7e.csv: -------------------------------------------------------------------------------- 1 | ,1a 08 3f ff ff 00,,23 00 10 00 08 12 10 00 ff ff 00 00 ff ff ff ff 00 ff 00 00 00 00 00 00 1c 0a 00 00 00 00 00 00 00 00 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/ff82315f17a9d582afd6aba974c222e00d14af15: -------------------------------------------------------------------------------- 1 | ,4d 00 5f d2 00 00 00 40 00 00,70 00 05 00 00 00 00 18 00 00 00 00 24 00 00 cd 00 02 00 00 f8 23 00 00 00 00 00 00 00 00 00 00, 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/ff980b7b6e39f929b8ddb08e419a2904abd44b33: -------------------------------------------------------------------------------- 1 | ,1c 01 04 40 00 00,,04 00 01 4d 32 34 3a 31 35 3a 31 31 3a 31 37 3a 30 30 30 20 74 6e 6c 2f 74 75 6e 6e 65 6c 5f 73 74 65 5f 72 65 63 76 5f 64 69 61 67 5f 6d 73 67 5f 68 61 6e 64 6c 65 72 3a 20 74 75 6e 6e 65 6c 69 6e 67 20 52 45 43 56 20 44 49 41 47 4e 4f 53 54 49 43 20 72 65 63 65 69 76 65 64 20 66 72 6f 6d 20 53 54 45 2e 0a 32 34 3a 31 35 3a 31 31 3a 31 37 3a 32 30 33 20 45 53 45 53 3a 20 66 77 64 6c 20 70 72 74 74 6e 20 63 6e 74 72 6c 20 73 74 61 74 75 73 20 72 65 63 65 69 76 65 64 3a 20 61 63 74 69 76 65 3a 20 31 20 64 61 74 61 3a 20 30 20 69 6d 67 30 63 72 63 3a 20 30 78 62 64 20 69 6d 67 31 63 72 63 3a 20 30 78 61 34 0a 32 34 3a 31 35 3a 31 31 3a 32 35 3a 31 38 30 20 45 4d 43 20 53 54 45 3a 20 54 6f 74 61 6c 20 6e 75 6d 62 65 72 20 6f 66 20 56 50 44 20 70 61 67 65 73 20 77 61 73 20 31 30 2c 20 6e 6f 77 20 31 30 0a 32 34 3a 31 35 3a 31 31 3a 32 35 3a 31 38 38 20 45 4d 43 20 53 54 45 3a 20 54 6f 74 61 6c 20 6e 75 6d 62 65 72 20 6f 66 20 56 50 44 20 70 61 67 65 73 20 77 61 73 20 31 30 2c 20 6e 6f 77 20 31 30 0a 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/ffb313726fc6fa8b68381e5df22e960cb623b62c.csv: -------------------------------------------------------------------------------- 1 | ,9e 10 00 00 00 00 00 00 00 00 00 00 02 00 00 00,,00 00 00 00 00 e7 bf ff 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/ffe9cd6ca4dbbdd2b2429c8d8023183b84c2962f: -------------------------------------------------------------------------------- 1 | ,12 01 88 02 00 00,,00 88 00 30 00 00 00 01 00 00 00 00 00 00 00 0c 61 93 00 08 50 00 c5 00 67 b9 53 ad 00 00 00 02 00 00 00 00 00 00 00 0c 61 93 00 08 50 00 c5 00 67 b9 53 ae 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/ffefa3f6034cc5680792a8cae855bc7a2d9f9019: -------------------------------------------------------------------------------- 1 | ,12 01 c0 02 00 00,,0d c0 00 24 01 00 00 00 24 00 00 00 66 2f e0 06 0d 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 23 4a 88 75 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/fff9db19407d43fdb18735c075071a866a5f0795: -------------------------------------------------------------------------------- 1 | ,1c 01 82 40 00 00,,82 00 00 6e 48 49 54 41 43 48 49 20 43 32 36 30 00 01 00 00 00 00 00 00 0b 08 00 00 00 00 00 00 00 01 00 01 00 00 00 00 00 0e 00 01 00 01 00 00 00 5f 00 02 00 00 00 00 00 0b 00 02 00 01 00 00 00 11 00 03 00 00 00 00 00 00 00 03 00 01 00 00 00 00 00 04 00 00 00 00 00 00 00 04 00 01 00 00 00 00 00 05 00 00 00 00 00 0e 00 05 00 01 00 00 00 50 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/fffa5f13587a7e46023238c9e7db91fd61414105: -------------------------------------------------------------------------------- 1 | ,1a 00 bf ff ff 00,,bf 00 10 08 2e 90 ed d0 00 00 02 00 81 0a 04 01 00 00 00 00 00 00 0c 00 82 0e 00 00 00 00 00 00 01 f4 00 00 00 00 00 00 03 16 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 40 00 00 00 04 16 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 87 0a 04 01 00 00 00 00 00 00 0c 00 88 12 10 00 ff ff 00 00 ff ff ff ff 00 00 00 00 00 00 00 00 8a 0a 00 10 00 00 00 00 00 00 00 06 ca 01 00 1c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 98 06 06 00 00 00 00 00 99 0e 06 00 23 28 1b 58 00 00 00 00 00 00 00 00 d9 01 00 64 00 06 02 02 00 00 00 00 21 0a 02 02 50 00 cc a0 13 07 16 b1 50 06 04 80 d8 12 41 bf 18 00 00 00 00 00 00 00 88 aa 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 21 0a 02 02 50 00 cc 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/id:000001,sig:11,src:005156,op:ext_AO,pos:34: -------------------------------------------------------------------------------- 1 | ,1C 00 43 00 00 00 00 40 00 00,,01 aa 00 54 00 00 00 08 00 00 00 00 00 00 00 00 00 01 00 08 00 00 00 00 00 00 00 00 00 02 00 08 00 00 00 00 00 00B00030 00 03 00 08 00 00 00 00 00 00 00 00 00 04 00 08 00 00 00 00 00 00 00 00 00 05 00 08 00 00 73 e0 f6 d9 46 00 00 06 00 08 00 00 00 00 00 00 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/id:000001,src:000141,op:arith8,pos:118,val:-34: -------------------------------------------------------------------------------- 1 | ,5a 10 300,,00 2e 00 10 01 00 00 18 00 00 00 00 00 e7 bf ff 00 00 00 00 00 00 02 00 08 12 10 00 ff ff 00 00 ff ff ff fD 00 ff 00 00 00 00 00 00 1c 0a 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/id:000002,src:000200,op:ext_AO,pos:571: -------------------------------------------------------------------------------- 1 | ,5a 00 bf ff 00 00 00 10 00 00,,01 a2 00 10 00 00 00 08 68 cb 9e 30 00 00 02 00 81 0a 04 14 ff 00 00 00 05 00 0c 00 82 0e 00 00 00 00 00 00 00 00 01 3a 00 00 00 00 83 16 bb d0 00 00 00 00 03 80 04 c4 02 08 00 01 00 a0 00 18 40 00 00 00 84 16 02 d3 c1 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 27 31 00 00 87 0a 04 14 ff 00 00 00 00 00 0c 00 88 12 10 00 ff ff 00 00 ff ff ff ff 80 03 00 00 00 00 00 00 8a 0a 00 10 00 80 00 00 00 00 00 06 18 0B 06 00 00 00 00 00 99 0e 06 00 23 28 1b 58 00 00 00 00 00 00 00 00 59 01 00 64 00 06 00 02 00 00 00 00 10 49 0e 00 50 00 c5 00 ff fd f2 f1 50 01 e6 77 5a 4d b0 00 01 00 00 00 00 00 00 00 88 aa 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 50 00 c5 00 5f 0d f2 f2 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 88 aa 00 00 00 00 00 00 00 00 00 00 00 00 00 00 59 02 00 0c 00 06 03 e8 00 00 00 00 00 00 00 00 59 03 00 2c 00 06 00 02 00 00 00 10 80 ac 00 01 80 ac 00 01 00 00 00 00 00 00 09 00 00 01 00 10 80 ac 00 01 80 ac 00 01 00 00 00 00 00 00 00 00 9a 26 00 00 00 00 00 0a 00 00 8c a0 00 00 17 70 00 00 46 50 00 00 46 50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 9c 0a 00 04 00 00 00 00 00 00 00 01 dc 01 00 0c 01 00 00 48 00 18 01 f4 00 00 00 00 80 16 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0c 00 00 00 00 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/id:000003,src:000314,op:flip1,pos:19: -------------------------------------------------------------------------------- 1 | ,5a 10 3f ff00,,00 0e 40 10 01 00 00 10 00 00 00 00 00 e7 bf ff 00 00 00 00 00 00 d2 00 08 00 ff ff ff ff ff ffff 0000 ff 00 00 ff ff 00 ff 00 00 00 00 00 00 1 -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/id:000005,sig:11,src:005234,op:havoc,rep:2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baruch/diskscan/4773146060a1696c52c880ce65410dad2f861c08/libscsicmd/afl/testcase/id:000005,sig:11,src:005234,op:havoc,rep:2 -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/id:000005,src:000445,op:flip1,pos:132: -------------------------------------------------------------------------------- 1 | ,5a 10 3f ff00,,00 2e 00 10 01 00 00 10 00 00 00 00 00 e7 bd ff 00 00 00 00 00 00 08 12 10 09 ff ff 00 02 00 0810 00 ff ff ff ff fd 00 ff 00 00 0000 00 1c 0a -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/id:000007,sig:11,src:005483,op:flip2,pos:43: -------------------------------------------------------------------------------- 1 | ,12 01 43 00 00 00 00 40 00 00,,03 40 00 54,00 00 00 08 00 00 00 00 00 00 00 00 00 01 00 08 00 00 00 00 00 00 00 00 00 02 00 08 00 00 00 00 00 00B00030 00 03 00 08 00 00 00 00 00 00 00 00 00 04 00 08 00 00 00 00 00 00 00 00 00 05 00 08 00 00 73 e0 f6 d9 46 00 00 06 00 08 00 00 00 00 00 00 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/id:000008,src:001208,op:flip1,pos:89: -------------------------------------------------------------------------------- 1 | ,1a 08 300,,23 00 10 00 08 12 1F 00 ff ff 00 00 ff ff ff ff 00 ff 00 00 00 00 00fffffffffdffffffffffff00 00 -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/id:000013,sig:11,src:005882,op:havoc,rep:2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baruch/diskscan/4773146060a1696c52c880ce65410dad2f861c08/libscsicmd/afl/testcase/id:000013,sig:11,src:005882,op:havoc,rep:2 -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/id:000015,src:001216,op:flip1,pos:229: -------------------------------------------------------------------------------- 1 | ,5a 20 3f ff00 00 10 00 00,,00 52 00 00 00 00 00 00 02 0e 00 00 00 00 00 00 40 00 00 09 00 00 00 00 0a 0a 00 00 00 00 00 00 00 00 0ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffdfffffff0 00 18 06fffffffffffff -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/id:000018,src:001179,op:ext_AO,pos:826: -------------------------------------------------------------------------------- 1 | ,5a 00 bf ff 00 00 00 10 00 00,,01 a2 00 10 00 00 00 08 68 cb 9e 30 00 00 02 00 81 0a 04 14 ff 00 00 00 05 00 0c 00 82 0e 00 00 00 00 00 00 00 00 01 3a 00 00 00 00 83 16 bb d0 00 00 00 00 03 80 04 c4 02 08 00 01 00 a0 00 18 40 00 00 00 84 16 02 d3 c1 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 27 31 00 00 87 0a 04 14 ff 00 00 00 00 00 0c 00 88 12 10 00 ff ff 00 00 ff ff ff ff 80 03 00 00 00 00 00 00 8a 0a 00 10 00 80 00 00 00 00 00 06 18 06 06 00 00 00 00 00 99 0e 06 00 23 28 1b 58 00 00 00 00 00 00 00 00 59 01 00 65 00 06 00 02 00 00 00 00 10 49 0e 00 50 00 c5 00 5f 0d f2 f1 50 01 e6 77 5a 4d b0 00 01 00 00 00 00 00 00 00 88 aa 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 50 00 c5 00 5f 0d f2 f2 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 88 aa 00 00 00 00 00 00 00 00 00 00 00 00 00 00 59 ff ff fd 00 06 03 e8 00 00 00 00 00 00 00 00 59 03 00 2c 00 06 00 02 00 00 00 10 80 ac 00 01 80 ac 00 01 00 00 00 00 00 00 09 00 00 01 00 10 80 ac 00 01 80 ac 00 01 00 00 00 00 00 00 00 00 9a 26 00 00 00 00 00 0a 00 00 8c a0 00 00 17 70 00 00 46 50 00 00 46 50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 9c 0a 00 04 00 00 00 00 00 00 00 01 dc 01 00 0c 01 00 00 48 00 18 01 f4 00 00 00 00 80 16 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0c 00 00 00 00 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/id:000019,src:001231,op:flip1,pos:72: -------------------------------------------------------------------------------- 1 | ,5a 00,,00 59 00 00 00 00 00 0B 02 0e 00 00 00 00 00 00 00 00 00 FFFFFFFDFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/log_sense_9bd3419f85d952cf54a38196fc0775a2bfa4c6ff.csv: -------------------------------------------------------------------------------- 1 | ,4d 00 55 00 00 00 00 40 00 00,,95 00 00 88 00 00 03 0c 00 0f 17 2b 00 08 02 5d 00 00 02 5d 00 01 03 14 00 03 7f bf 51 18 01 50 5b 54 03 48 00 00 00 00 11 57 80 1b 00 02 03 14 00 0c 68 1c 13 11 00 20 44 4c 03 9d 00 00 00 00 0b 8f 13 7a 00 03 03 14 00 0c 6c da 51 17 01 20 9d ef 05 26 00 00 00 00 1a 25 64 00 00 04 03 14 00 0c f2 ec 51 17 01 21 f2 bd 04 4a 00 00 00 00 4a cf 77 f7 00 05 03 14 00 0d ab 1d 51 17 01 21 89 2a 03 75 00 00 00 00 3c f7 ac 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/log_sense_ac03383386fa3d77d3d460480a52e0b99a1c580e.csv: -------------------------------------------------------------------------------- 1 | ,4d 00 7e 00 00 00 00 40 00 00,,3e 00 00 24 00 00 02 04 00 10 c8 20 00 08 02 04 00 00 00 10 00 09 02 04 00 00 00 3c 00 0e 02 08 00 00 3c 04 24 09 8b 7d 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/log_sense_c52c16bd44de5cf72ba1a55c0b6258349a74e5d6.csv: -------------------------------------------------------------------------------- 1 | ,4d 00 40 00 00 00 00 40 00 00,,00 00 00 11 00 02 03 05 06 0d 0e 0f 10 11 15 18 1a 2f 30 31 37 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/log_sense_d192aef3ac66f84b8996edeb95ef1e7e9d6660cb.csv: -------------------------------------------------------------------------------- 1 | ,4d 00 40 00 00 00 00 40 00 00,,00 00 00 0f 00 02 03 05 06 0d 0e 0f 10 11 15 18 1a 2f 31 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/log_sense_dc08fbd86ddd3f34a56532faf9b46f0ae135e644.csv: -------------------------------------------------------------------------------- 1 | ,4d 00 6f 00 00 00 00 40 00 00,,2f 00 00 3c 00 00 03 08 00 00 19 55 21 00 00 00 00 01 03 04 5d 53 00 00 00 02 03 04 5d 54 00 00 00 03 03 04 5d 28 00 00 00 04 03 04 0b 06 00 00 00 05 03 04 5d 55 00 00 00 06 03 04 5d 56 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/log_sense_f2ca65053fcb0a0b0a479e181fa8b497beb40d9c.csv: -------------------------------------------------------------------------------- 1 | ,4d 00 4e 00 00 00 00 40 00 00,,0e 00 00 34 00 01 01 06 32 30 31 33 34 37 00 02 01 06 32 30 31 33 34 37 00 03 03 04 00 00 27 10 00 04 03 04 00 00 05 53 00 05 03 04 00 04 93 e0 00 06 03 04 00 00 05 53 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/log_sense_fb4080b69b8ca7d50d16f424305467a18d8eded9.csv: -------------------------------------------------------------------------------- 1 | ,4d 00 46 00 00 00 00 40 00 00,,06 00 00 08 00 00 02 04 00 00 02 44 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/log_sense_fc58600bcf8dc103f911bb2a6a867ab2c8e42fe2.csv: -------------------------------------------------------------------------------- 1 | ,4d 00 6f 00 00 00 00 40 00 00,,2f 00 00 4c 00 00 03 08 00 00 1c 46 26 00 00 00 00 01 03 04 5d 53 00 00 00 02 03 04 5d 54 00 00 00 03 03 04 5d 57 00 00 00 04 03 04 5d 28 00 00 00 05 03 04 0b 06 01 00 00 06 03 04 5d 56 38 00 00 07 03 04 5d 55 00 00 00 08 03 04 5d 20 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/log_sense_ffe62c433d9a885d2a5670ff890f5b00089739aa.csv: -------------------------------------------------------------------------------- 1 | ,4d 00 59 00 00 00 00 40 00 00,,19 00 00 5c 00 01 02 40 00 00 00 05 1d 74 16 f0 00 00 00 04 62 22 c5 8d 00 00 00 43 98 00 04 2c 00 00 00 53 be 7d 55 4d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 02 08 00 00 00 00 01 b4 c1 aa 00 03 03 08 00 00 00 02 00 00 00 05 2 | -------------------------------------------------------------------------------- /libscsicmd/afl/testcase/log_sense_ffee0af0b99b68b9d287e6f65ad08a4e11967daa.csv: -------------------------------------------------------------------------------- 1 | ,4d 00 43 00 00 00 00 40 00 00,,03 00 00 54 00 00 00 08 00 00 00 00 00 00 00 00 00 01 00 08 00 00 00 00 00 00 00 00 00 02 00 08 00 00 00 00 00 00 00 00 00 03 00 08 00 00 00 00 00 00 00 00 00 04 00 08 00 00 00 00 00 00 00 00 00 05 00 08 00 01 69 53 90 5e 44 00 00 06 00 08 00 00 00 00 00 00 00 00 2 | -------------------------------------------------------------------------------- /libscsicmd/include/ata_smart.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBSCSICMD_ATA_SMART_H 2 | #define LIBSCSICMD_ATA_SMART_H 3 | 4 | #include "smartdb.h" 5 | #include "ata.h" 6 | 7 | /* These functions are for common information that may show up differently in different drives (or unsupported) */ 8 | int ata_smart_get_temperature(const ata_smart_attr_t *attrs, int num_attrs, const smart_table_t *table, int *min_temp, int *max_temp); 9 | int ata_smart_get_power_on_hours(const ata_smart_attr_t *attrs, int num_attrs, const smart_table_t *table, int *pminutes); 10 | int ata_smart_get_num_reallocations(const ata_smart_attr_t *attrs, int num_attrs, const smart_table_t *table); 11 | int ata_smart_get_num_pending_reallocations(const ata_smart_attr_t *attrs, int num_attrs, const smart_table_t *table); 12 | int ata_smart_get_num_crc_errors(const ata_smart_attr_t *attrs, int num_attrs, const smart_table_t *table); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /libscsicmd/include/parse_extended_inquiry.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 Baruch Even 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #ifndef LIBSCSICMD_EXTENDED_INQUIRY_H 18 | #define LIBSCSICMD_EXTENDED_INQUIRY_H 19 | 20 | #include 21 | 22 | #define EVPD_MIN_LEN 4 23 | 24 | static inline uint8_t evpd_peripheral_qualifier(uint8_t *data) 25 | { 26 | return data[0] >> 5; 27 | } 28 | 29 | static inline uint8_t evpd_peripheral_device_type(uint8_t *data) 30 | { 31 | return data[0] & 0x1F; 32 | } 33 | 34 | static inline uint8_t evpd_page_code(uint8_t *data) 35 | { 36 | return data[1]; 37 | } 38 | 39 | static inline uint16_t evpd_page_len(uint8_t *data) 40 | { 41 | return (data[2] << 8) | data[3]; 42 | } 43 | 44 | static inline uint8_t *evpd_page_data(uint8_t *data) 45 | { 46 | return data + EVPD_MIN_LEN; 47 | } 48 | 49 | static inline bool evpd_is_ascii_page(uint8_t page_code) 50 | { 51 | return 0x01 <= page_code && page_code <= 0x7F; 52 | } 53 | 54 | /* This should be called with the body of the EVPD data and not the full (i.e. with the output of evpd_page_data()) */ 55 | static inline uint16_t evpd_ascii_len(uint8_t *evpd_body) 56 | { 57 | return (evpd_body[0] << 8) | evpd_body[1]; 58 | } 59 | 60 | static inline uint8_t *evpd_ascii_data(uint8_t *evpd_body) 61 | { 62 | return evpd_body + 2; 63 | } 64 | 65 | static inline uint8_t *evpd_ascii_post_data(uint8_t *evpd_body) 66 | { 67 | return evpd_body + 2 + evpd_ascii_len(evpd_body); 68 | } 69 | 70 | static inline unsigned evpd_ascii_post_data_len(uint8_t *evpd_body, unsigned full_data_len) 71 | { 72 | return full_data_len - EVPD_MIN_LEN - 2 - evpd_ascii_len(evpd_body); 73 | } 74 | 75 | static inline bool evpd_is_valid(uint8_t *data, unsigned data_len) 76 | { 77 | if (data_len < EVPD_MIN_LEN) 78 | return false; 79 | 80 | if (evpd_page_len(data) > data_len) 81 | return false; 82 | 83 | return true; 84 | } 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /libscsicmd/include/parse_receive_diagnostics.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 Baruch Even 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #ifndef LIBSCSICMD_RECEIVE_DIAGNOSTICS_H 18 | #define LIBSCSICMD_RECEIVE_DIAGNOSTICS_H 19 | 20 | #include "scsicmd_utils.h" 21 | #include 22 | #include 23 | 24 | #define RECV_DIAG_MIN_LEN 4 25 | 26 | static inline uint8_t recv_diag_get_page_code(uint8_t *data) 27 | { 28 | return data[0]; 29 | } 30 | 31 | static inline uint8_t recv_diag_get_page_code_specific(uint8_t *data) 32 | { 33 | return data[1]; 34 | } 35 | 36 | static inline uint16_t recv_diag_get_len(uint8_t *data) 37 | { 38 | return (data[2] << 8) | data[3]; 39 | } 40 | 41 | static inline uint8_t *recv_diag_data(uint8_t *data) 42 | { 43 | return data + RECV_DIAG_MIN_LEN; 44 | } 45 | 46 | static inline bool recv_diag_is_valid(uint8_t *data, unsigned data_len) 47 | { 48 | if (data_len < RECV_DIAG_MIN_LEN) 49 | return false; 50 | if ((unsigned)recv_diag_get_len(data) + RECV_DIAG_MIN_LEN > data_len) 51 | return false; 52 | return true; 53 | } 54 | 55 | /* SES Page 1 Configuration */ 56 | 57 | static inline bool ses_config_is_valid(uint8_t *data, unsigned data_len) 58 | { 59 | if (data_len < 8) 60 | return false; 61 | if (recv_diag_get_len(data) < 4) 62 | return false; 63 | return true; 64 | } 65 | 66 | static inline uint8_t ses_config_num_sub_enclosures(uint8_t *data) 67 | { 68 | return data[1] + 1; // +1 for primary 69 | } 70 | 71 | static inline uint32_t ses_config_generation(uint8_t *data) 72 | { 73 | return get_uint32(data, 4); 74 | } 75 | 76 | static inline uint8_t *ses_config_sub_enclosure(uint8_t *data) 77 | { 78 | return data + 8; 79 | } 80 | 81 | /* Enclosure Descriptor */ 82 | static inline uint8_t ses_config_enclosure_descriptor_process_identifier(uint8_t *data) 83 | { 84 | return (data[0] >> 4) & 0x7; 85 | } 86 | 87 | static inline uint8_t ses_config_enclosure_descriptor_num_processes(uint8_t *data) 88 | { 89 | return data[0] & 0x7; 90 | } 91 | 92 | static inline uint8_t ses_config_enclosure_descriptor_subenclosure_identifier(uint8_t *data) 93 | { 94 | return data[1]; 95 | } 96 | 97 | static inline uint8_t ses_config_enclosure_descriptor_num_type_descriptors(uint8_t *data) 98 | { 99 | return data[2]; 100 | } 101 | 102 | static inline uint8_t ses_config_enclosure_descriptor_len(uint8_t *data) 103 | { 104 | return data[3]; 105 | } 106 | 107 | static inline uint64_t ses_config_enclosure_descriptor_logical_identifier(uint8_t *data) 108 | { 109 | return get_uint64(data, 4); 110 | } 111 | 112 | static inline bool ses_config_enclosure_descriptor_is_valid(uint8_t *data, unsigned data_len) 113 | { 114 | if (data_len < 12) 115 | return false; 116 | if (ses_config_enclosure_descriptor_len(data) < 36 || 117 | ses_config_enclosure_descriptor_len(data) > 252 || 118 | ses_config_enclosure_descriptor_len(data) > data_len) 119 | { 120 | return false; 121 | } 122 | return true; 123 | } 124 | 125 | static inline void _ses_str_cpy(uint8_t *src, unsigned src_len, char *s, unsigned slen) 126 | { 127 | if (slen > src_len) 128 | slen = src_len; 129 | else 130 | slen--; 131 | 132 | memcpy(s, src, slen); 133 | s[slen] = 0; 134 | } 135 | 136 | static inline void ses_config_enclosure_descriptor_vendor_identifier(uint8_t *data, char *s, unsigned slen) 137 | { 138 | _ses_str_cpy(data+12, 8, s, slen); 139 | } 140 | 141 | static inline void ses_config_enclosure_descriptor_product_identifier(uint8_t *data, char *s, unsigned slen) 142 | { 143 | _ses_str_cpy(data+20, 16, s, slen); 144 | } 145 | 146 | static inline void ses_config_enclosure_descriptor_revision_level(uint8_t *data, char *s, unsigned slen) 147 | { 148 | _ses_str_cpy(data+36, 4, s, slen); 149 | } 150 | 151 | static inline uint8_t *ses_config_enclosure_descriptor_vendor_info(uint8_t *data) 152 | { 153 | return data + 40; 154 | } 155 | 156 | static inline uint8_t ses_config_enclosure_descriptor_vendor_len(uint8_t *data) 157 | { 158 | return ses_config_enclosure_descriptor_len(data) + 4 - 40; 159 | } 160 | 161 | #endif 162 | -------------------------------------------------------------------------------- /libscsicmd/include/scsicmd_utils.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2015 Baruch Even 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #ifndef LIBSCSICMD_UTILS_H 18 | #define LIBSCSICMD_UTILS_H 19 | 20 | #include 21 | 22 | static inline uint16_t get_uint16(unsigned char *buf, int start) 23 | { 24 | return (uint16_t)buf[start] << 8 | 25 | (uint16_t)buf[start+1]; 26 | } 27 | 28 | static inline uint32_t get_uint24(unsigned char *buf, int start) 29 | { 30 | return (uint32_t)buf[start] << 16 | 31 | (uint32_t)buf[start+1] << 8 | 32 | (uint32_t)buf[start+2]; 33 | } 34 | 35 | static inline uint32_t get_uint32(unsigned char *buf, int start) 36 | { 37 | return (uint32_t)buf[start] << 24 | 38 | (uint32_t)buf[start+1] << 16 | 39 | (uint32_t)buf[start+2] << 8 | 40 | (uint32_t)buf[start+3]; 41 | } 42 | 43 | static inline uint64_t get_uint64(unsigned char *buf, int start) 44 | { 45 | return (uint64_t)buf[start] << 56 | 46 | (uint64_t)buf[start+1] << 48 | 47 | (uint64_t)buf[start+2] << 40 | 48 | (uint64_t)buf[start+3] << 32 | 49 | (uint64_t)buf[start+4] << 24 | 50 | (uint64_t)buf[start+5] << 16 | 51 | (uint64_t)buf[start+6] << 8 | 52 | (uint64_t)buf[start+7]; 53 | } 54 | 55 | static inline unsigned safe_len(uint8_t *start, unsigned len, uint8_t *subbuf, unsigned subbuf_len) 56 | { 57 | const int start_offset = subbuf - start; 58 | 59 | if (start_offset < 0 || (unsigned)start_offset > len) 60 | return 0; 61 | 62 | if (subbuf_len + start_offset > len) 63 | return len - start_offset; 64 | else 65 | return subbuf_len; 66 | } 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /libscsicmd/include/sense_key_list.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2013 Baruch Even 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #ifndef LIBSCSICMD_SENSE_KEY_LIST_H 18 | #define LIBSCSICMD_SENSE_KEY_LIST_H 19 | 20 | #define SENSE_KEY_LIST \ 21 | SENSE_KEY_MAP(NO_SENSE, 0x0) \ 22 | SENSE_KEY_MAP(RECOVERED_ERROR, 0x1) \ 23 | SENSE_KEY_MAP(NOT_READY, 0x2) \ 24 | SENSE_KEY_MAP(MEDIUM_ERROR, 0x3) \ 25 | SENSE_KEY_MAP(HARDWARE_ERROR, 0x4) \ 26 | SENSE_KEY_MAP(ILLEGAL_REQUEST, 0x5) \ 27 | SENSE_KEY_MAP(UNIT_ATTENTION, 0x6) \ 28 | SENSE_KEY_MAP(DATA_PROTECT, 0x7) \ 29 | SENSE_KEY_MAP(BLANK_CHECK, 0x8) \ 30 | SENSE_KEY_MAP(VENDOR_SPECIFIC, 0x9) \ 31 | SENSE_KEY_MAP(COPY_ABORTED, 0xA) \ 32 | SENSE_KEY_MAP(ABORTED_COMMAND, 0xB) \ 33 | SENSE_KEY_MAP(RESERVED_C, 0xC) \ 34 | SENSE_KEY_MAP(VOLUME_OVERFLOW, 0xD) \ 35 | SENSE_KEY_MAP(MISCOMPARE, 0xE) \ 36 | SENSE_KEY_MAP(COMPLETED, 0xF) 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /libscsicmd/include/smartdb.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBSCSICMD_SMARTDB_H 2 | #define LIBSCSICMD_SMARTDB_H 3 | 4 | #include 5 | 6 | typedef struct smart_table smart_table_t; 7 | typedef struct smart_attr smart_attr_t; 8 | 9 | typedef enum smart_attr_type { 10 | SMART_ATTR_TYPE_NONE, 11 | SMART_ATTR_TYPE_POH, 12 | SMART_ATTR_TYPE_TEMP, 13 | SMART_ATTR_TYPE_REALLOC, 14 | SMART_ATTR_TYPE_REALLOC_PENDING, 15 | SMART_ATTR_TYPE_CRC_ERRORS, 16 | } smart_attr_type_e; 17 | 18 | typedef enum smart_attr_raw { 19 | SMART_ATTR_RAW_HEX48, 20 | SMART_ATTR_RAW_DEC48, 21 | } smart_attr_raw_e; 22 | 23 | struct smart_attr { 24 | uint8_t id; 25 | smart_attr_type_e type; 26 | smart_attr_raw_e raw; 27 | int offset; 28 | const char *name; 29 | }; 30 | 31 | struct smart_table { 32 | int num_attrs; 33 | smart_attr_t attrs[30]; 34 | }; 35 | 36 | const smart_table_t *smart_table_for_disk(const char *vendor, const char *model, const char *firmware); 37 | const smart_attr_t *smart_attr_for_id(const smart_table_t *table, uint8_t id); 38 | const smart_attr_t *smart_attr_for_type(const smart_table_t *table, smart_attr_type_e attr_type); 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /libscsicmd/regen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | echo "Regenerate generated files" 4 | 5 | src/smartdb/smartdb_gen_c.py src/smartdb/smartdb.xml > src/smartdb/smartdb_gen.c 6 | git add src/smartdb/smartdb_gen.c 7 | 8 | structs/ata_struct_2_h.py structs/ata_identify.yaml > include/ata_parse.h 9 | git add include/ata_parse.h 10 | -------------------------------------------------------------------------------- /libscsicmd/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(scsicmd STATIC ata.c ata_smart.c cdb.c parse_inquiry.c parse_read_cap.c parse_sense.c log_sense.c parse.c str_map.c smartdb/smartdb.c smartdb/smartdb_gen.c) 2 | -------------------------------------------------------------------------------- /libscsicmd/src/ata.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2013 Baruch Even 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "ata.h" 18 | #include 19 | #include 20 | 21 | 22 | bool ata_inquiry_checksum_verify(const unsigned char *buf, int buf_len) 23 | { 24 | if (buf_len != 512) 25 | return false; 26 | 27 | if (buf[511] != 0xA5) { 28 | // Checksum isn't claimed to be valid, nothing to check here 29 | return true; 30 | } 31 | 32 | return ata_checksum_verify(buf); 33 | } 34 | 35 | bool ata_status_from_scsi_sense(unsigned char *sense, int sense_len, ata_status_t *status) 36 | { 37 | sense_info_t sense_info; 38 | 39 | assert(status); 40 | 41 | bool parsed = scsi_parse_sense(sense, sense_len, &sense_info); 42 | 43 | if (parsed && sense_info.ata_status_valid) { 44 | *status = sense_info.ata_status; 45 | return true; 46 | } 47 | if (sense_info.is_fixed) { 48 | // Fixed format parsing for ATA passthrough can't be known automatically 49 | memset(status, 0, sizeof(*status)); 50 | status->error = sense_info.information & 0xFF; 51 | status->status = (sense_info.information >> 8) & 0xFF; 52 | status->device = (sense_info.information >> 16) & 0xFF; 53 | 54 | status->sector_count = (sense_info.information >> 24) & 0xFF; 55 | 56 | status->extend = sense_info.cmd_specific & 0x80; 57 | uint32_t lba_high = (sense_info.cmd_specific >> 8) & 0xFF; 58 | uint32_t lba_mid = (sense_info.cmd_specific >> 16) & 0xFF; 59 | uint32_t lba_low = (sense_info.cmd_specific >> 24) & 0xFF; 60 | status->lba = (lba_high << 16) | (lba_mid << 8) | lba_low; 61 | 62 | // TODO: sector_count_upper_non_zero: sense_info.cmd_specific & 0x40 63 | // TODO: lba upper non zero: sense_info.cmd_specific & 0x20 64 | // TODO: log index: sense_info.cmd_specific & 0x07 65 | } 66 | 67 | return false; 68 | } 69 | 70 | /* ATA SMART READ DATA */ 71 | 72 | uint16_t ata_get_ata_smart_read_data_version(const unsigned char *buf) 73 | { 74 | return ata_get_word(buf, 0); 75 | } 76 | 77 | int ata_parse_ata_smart_read_data(const unsigned char *buf, ata_smart_attr_t *attrs, int max_attrs) 78 | { 79 | if (!ata_check_ata_smart_read_data_checksum(buf)) 80 | return -1; 81 | 82 | /* // Some disks do not return this expected value (Ticket #55) 83 | if (ata_get_ata_smart_read_data_version(buf) != 0x0010) 84 | return -1; 85 | */ 86 | 87 | int i, j; 88 | 89 | for (i = 0, j = 0; i < MAX_SMART_ATTRS && i < max_attrs; i++) { 90 | const unsigned char *raw_attr = buf + 2 + 12*i; 91 | ata_smart_attr_t *attr = &attrs[j]; 92 | 93 | attr->id = raw_attr[0]; 94 | if (attr->id == 0) // Skip an invalid attribute 95 | continue; 96 | attr->status = raw_attr[1] | raw_attr[2]<<8; 97 | attr->value = raw_attr[3]; 98 | attr->min = raw_attr[4]; 99 | attr->raw = (raw_attr[5]) | 100 | (raw_attr[6] << 8) | 101 | (raw_attr[7] << 16) | 102 | (raw_attr[8] << 24) | 103 | ((uint64_t)raw_attr[9] << 32) | 104 | ((uint64_t)raw_attr[10] << 40); 105 | 106 | j++; 107 | } 108 | 109 | return j; 110 | } 111 | 112 | int ata_parse_ata_smart_read_thresh(const unsigned char *buf, ata_smart_thresh_t *attrs, int max_attrs) 113 | { 114 | if (!ata_check_ata_smart_read_data_checksum(buf)) 115 | return -1; 116 | 117 | /* // Some disks do not return this expected value (Ticket #55) 118 | if (ata_get_ata_smart_read_data_version(buf) != 0x0010) 119 | return -1; 120 | */ 121 | 122 | int i, j; 123 | 124 | for (i = 0, j = 0; i < MAX_SMART_ATTRS && i < max_attrs; i++) { 125 | const unsigned char *raw_attr = buf + 2 + 12*i; 126 | ata_smart_thresh_t *attr = &attrs[j]; 127 | 128 | attr->id = raw_attr[0]; 129 | if (attr->id == 0) // Skip an invalid attribute 130 | continue; 131 | attr->threshold = raw_attr[1]; 132 | 133 | j++; 134 | } 135 | 136 | return j; 137 | } 138 | -------------------------------------------------------------------------------- /libscsicmd/src/ata_smart.c: -------------------------------------------------------------------------------- 1 | #include "ata_smart.h" 2 | #include 3 | 4 | 5 | static const smart_attr_t *ata_smart_get(const ata_smart_attr_t *attrs, int num_attrs, const smart_table_t *table, const ata_smart_attr_t **pattr, smart_attr_type_e attr_type) 6 | { 7 | const smart_attr_t *attr_info; 8 | int i; 9 | 10 | attr_info = smart_attr_for_type(table, attr_type); 11 | if (attr_info == NULL) 12 | return NULL; 13 | 14 | for (i = 0; i < num_attrs; i++) { 15 | if (attrs[i].id == attr_info->id) { 16 | *pattr = &attrs[i]; 17 | return attr_info; 18 | } 19 | } 20 | 21 | // Attribute not found in disk smart data 22 | return NULL; 23 | } 24 | 25 | static int ata_smart_get_simple(const ata_smart_attr_t *attrs, int num_attrs, const smart_table_t *table, smart_attr_type_e attr_type) 26 | { 27 | const smart_attr_t *attr_info; 28 | const ata_smart_attr_t *smart_attr; 29 | 30 | attr_info = ata_smart_get(attrs, num_attrs, table, &smart_attr, attr_type); 31 | if (attr_info == NULL) 32 | return -1; 33 | 34 | return smart_attr->raw; 35 | } 36 | 37 | int ata_smart_get_temperature(const ata_smart_attr_t *attrs, int num_attrs, const smart_table_t *table, int *pmin_temp, int *pmax_temp) 38 | { 39 | const smart_attr_t *attr_info; 40 | const ata_smart_attr_t *smart_attr; 41 | 42 | attr_info = ata_smart_get(attrs, num_attrs, table, &smart_attr, SMART_ATTR_TYPE_TEMP); 43 | if (attr_info == NULL) 44 | return -1; 45 | 46 | // Temperature is some offset minus the current value, usually 47 | int temp = attr_info->offset - smart_attr->value; 48 | *pmin_temp = *pmax_temp = -1; 49 | 50 | if (smart_attr->raw) { 51 | int min_temp = (smart_attr->raw >> 16) & 0xFFFF; 52 | int max_temp = (smart_attr->raw >> 32) & 0xFFFF; 53 | 54 | temp = smart_attr->raw & 0xFFFF; 55 | 56 | if (max_temp >= temp && min_temp <= temp) { 57 | *pmin_temp = min_temp; 58 | *pmax_temp = max_temp; 59 | } 60 | } 61 | return temp; 62 | } 63 | 64 | int ata_smart_get_power_on_hours(const ata_smart_attr_t *attrs, int num_attrs, const smart_table_t *table, int *pminutes) 65 | { 66 | *pminutes = -1; 67 | return ata_smart_get_simple(attrs, num_attrs, table, SMART_ATTR_TYPE_POH); 68 | } 69 | 70 | int ata_smart_get_num_reallocations(const ata_smart_attr_t *attrs, int num_attrs, const smart_table_t *table) 71 | { 72 | return ata_smart_get_simple(attrs, num_attrs, table, SMART_ATTR_TYPE_REALLOC); 73 | } 74 | 75 | int ata_smart_get_num_pending_reallocations(const ata_smart_attr_t *attrs, int num_attrs, const smart_table_t *table) 76 | { 77 | return ata_smart_get_simple(attrs, num_attrs, table, SMART_ATTR_TYPE_REALLOC_PENDING); 78 | } 79 | 80 | int ata_smart_get_num_crc_errors(const ata_smart_attr_t *attrs, int num_attrs, const smart_table_t *table) 81 | { 82 | return ata_smart_get_simple(attrs, num_attrs, table, SMART_ATTR_TYPE_CRC_ERRORS); 83 | } 84 | -------------------------------------------------------------------------------- /libscsicmd/src/log_sense.c: -------------------------------------------------------------------------------- 1 | #include "parse_log_sense.h" 2 | 3 | bool log_sense_page_informational_exceptions(uint8_t *page, unsigned page_len, uint8_t *asc, uint8_t *ascq, uint8_t *temperature) 4 | { 5 | if (!log_sense_is_valid(page, page_len)) 6 | return false; 7 | if (log_sense_page_code(page) != 0x2F) 8 | return false; 9 | if (log_sense_subpage_format(page) && log_sense_subpage_code(page) != 0) 10 | return false; 11 | 12 | uint8_t *param; 13 | for_all_log_sense_params(page, page_len, param) { 14 | if (log_sense_param_code(param) == 0) { 15 | uint8_t *param_data = log_sense_param_data(param); 16 | *asc = param_data[0]; 17 | *ascq = param_data[1]; 18 | *temperature = param_data[2]; 19 | return true; 20 | } 21 | } 22 | 23 | return false; 24 | } 25 | 26 | 27 | -------------------------------------------------------------------------------- /libscsicmd/src/parse.c: -------------------------------------------------------------------------------- 1 | #include "parse_read_defect_data.h" 2 | 3 | static const char *defect_data_format_str[] = { 4 | "Short", 5 | "Reserved (1)", 6 | "Reserved (2)", 7 | "Long", 8 | "Index", 9 | "Physical", 10 | "Vendor", 11 | "Reserved (7)", 12 | }; 13 | 14 | const char *read_defect_data_format_to_str(uint8_t fmt) 15 | { 16 | if (fmt > 7) 17 | return "Unknown"; 18 | return defect_data_format_str[fmt]; 19 | } 20 | -------------------------------------------------------------------------------- /libscsicmd/src/parse_inquiry.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2013 Baruch Even 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "scsicmd.h" 18 | 19 | #include 20 | #include 21 | 22 | bool parse_inquiry(unsigned char *buf, unsigned buf_len, int *device_type, scsi_vendor_t vendor, scsi_model_t model, 23 | scsi_fw_revision_t revision, scsi_serial_t serial) 24 | { 25 | *device_type = -1; 26 | vendor[0] = 0; 27 | model[0] = 0; 28 | revision[0] = 0; 29 | serial[0] = 0; 30 | 31 | if (buf_len < 32) 32 | return false; 33 | 34 | unsigned char fmt = buf[3] & 0xf; 35 | 36 | int valid_len = buf[4] + 4; 37 | 38 | *device_type = buf[0] & 0x1f; 39 | 40 | if (valid_len >= 8 + SCSI_VENDOR_LEN) { 41 | strncpy(vendor, (char*)buf+8, SCSI_VENDOR_LEN); 42 | vendor[SCSI_VENDOR_LEN] = 0; 43 | } 44 | 45 | if (valid_len >= 16 + SCSI_MODEL_LEN) { 46 | strncpy(model, (char*)buf+16, SCSI_MODEL_LEN); 47 | model[SCSI_MODEL_LEN] = 0; 48 | } 49 | 50 | if (valid_len >= 32 + SCSI_FW_REVISION_LEN) { 51 | strncpy(revision, (char*)buf+32, SCSI_FW_REVISION_LEN); 52 | revision[SCSI_FW_REVISION_LEN] = 0; 53 | } 54 | 55 | if (valid_len >= 44 && fmt == 2) { 56 | strncpy(serial, (char*)buf+36, SCSI_SERIAL_LEN); 57 | serial[SCSI_SERIAL_LEN] = 0; 58 | } 59 | 60 | return true; 61 | } 62 | 63 | #define STRINGIFY(name) # name 64 | 65 | const char *scsi_device_type_name(scsi_device_type_e dev_type) 66 | { 67 | #define X(name) case SCSI_DEV_TYPE_##name: return STRINGIFY(name); 68 | switch (dev_type) { 69 | SCSI_DEVICE_TYPE_LIST 70 | #undef X 71 | } 72 | 73 | return "Unknown device type"; 74 | } 75 | -------------------------------------------------------------------------------- /libscsicmd/src/parse_read_cap.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2013 Baruch Even 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "scsicmd.h" 18 | #include "scsicmd_utils.h" 19 | 20 | #include 21 | #include 22 | 23 | bool parse_read_capacity_10(unsigned char *buf, unsigned buf_len, uint32_t *max_lba, uint32_t *block_size) 24 | { 25 | if (buf_len < 8) 26 | return false; 27 | 28 | if (max_lba) 29 | *max_lba = get_uint32(buf, 0); 30 | if (block_size) 31 | *block_size = get_uint32(buf, 4); 32 | return true; 33 | } 34 | 35 | bool parse_read_capacity_16(unsigned char *buf, unsigned buf_len, uint64_t *max_lba, uint32_t *block_size, bool *prot_enable, 36 | unsigned *p_type, unsigned *p_i_exponent, unsigned *logical_blocks_per_physical_block_exponent, 37 | bool *thin_provisioning_enabled, bool *thin_provisioning_zero, unsigned *lowest_aligned_lba) 38 | { 39 | if (buf_len < 16) 40 | return false; 41 | 42 | if (max_lba) 43 | *max_lba = get_uint64(buf, 0); 44 | if (block_size) 45 | *block_size = get_uint32(buf, 8); 46 | if (prot_enable) 47 | *prot_enable = buf[12] & 1; 48 | if (p_type) 49 | *p_type = (buf[12] & 0xe) >> 1; 50 | if (p_i_exponent) 51 | *p_i_exponent = (buf[13] & 0xf0) >> 4; 52 | if (logical_blocks_per_physical_block_exponent) 53 | *logical_blocks_per_physical_block_exponent = buf[13] & 0xf; 54 | if (thin_provisioning_enabled) 55 | *thin_provisioning_enabled = buf[14] & 0x80; 56 | if (thin_provisioning_zero) 57 | *thin_provisioning_zero = buf[14] & 0x40; 58 | if (lowest_aligned_lba) 59 | *lowest_aligned_lba = (buf[14] & 0x3f) << 8 | buf[15]; 60 | return true; 61 | } 62 | -------------------------------------------------------------------------------- /libscsicmd/src/smartdb/smartdb.c: -------------------------------------------------------------------------------- 1 | #include "smartdb.h" 2 | #include 3 | 4 | const smart_attr_t *smart_attr_for_id(const smart_table_t *table, uint8_t id) 5 | { 6 | int i; 7 | 8 | for (i = 0; i < table->num_attrs; i++) { 9 | if (table->attrs[i].id == id) 10 | return &table->attrs[i]; 11 | } 12 | 13 | return NULL; 14 | } 15 | 16 | const smart_attr_t *smart_attr_for_type(const smart_table_t *table, smart_attr_type_e attr_type) 17 | { 18 | int i; 19 | 20 | for (i = 0; i < table->num_attrs; i++) { 21 | if (table->attrs[i].type == attr_type) 22 | return &table->attrs[i]; 23 | } 24 | 25 | return NULL; 26 | } 27 | -------------------------------------------------------------------------------- /libscsicmd/src/smartdb/smartdb.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Raw Read Error Rate 4 | Throughput Performance 5 | Spin Up Time 6 | Start/Stop Count 7 | Reallocated Sectors Count 8 | Seek Error Rate 9 | Seek Time Performance 10 | Power On Hours 11 | Spin Retry Count 12 | Device Power Cycle Count 13 | G Sense Error Rate 14 | Power Off Retract Count 15 | Load/Unload Cycle Count 16 | Temperature 17 | Reallocation Event Count 18 | Pending Sector Reallocation Count 19 | Off-Line Scan Uncorrecable Sector Count 20 | CRC Error Count 21 | Total LBAs Written 22 | Multi-zone Error Rate 23 | Drive Calibration Retry Count 24 | Free Fall Sensor 25 | Total LBAs Read 26 | Head Flying Hours 27 | Hardware ECC Recovered 28 | Read Soft Error Rate 29 | 30 | 31 | 32 | 33 | 1 34 | Raw Read Error Rate 35 | dec48 36 | 37 | 38 | 2 39 | Throughput Performance 40 | 41 | 42 | 3 43 | Spin Up Time 44 | 45 | 46 | 4 47 | Start/Stop Count 48 | 49 | 50 | 5 51 | Reallocated Sectors Count 52 | 53 | 54 | 7 55 | Seek Error Rate 56 | 57 | 58 | 8 59 | Seek Time Performance 60 | 61 | 62 | 9 63 | Power On Hours 64 | 65 | 66 | 10 67 | Spin Retry Count 68 | 69 | 70 | 11 71 | Drive Calibration Retry Count 72 | 73 | 74 | 12 75 | Device Power Cycle Count 76 | 77 | 78 | 13 79 | Read Soft Error Rate 80 | 81 | 82 | 191 83 | G Sense Error Rate 84 | 85 | 86 | 192 87 | Power Off Retract Count 88 | 89 | 90 | 193 91 | Load/Unload Cycle Count 92 | 93 | 94 | 194 95 | Temperature 96 | 150 97 | 98 | 99 | 195 100 | Hardware ECC Recovered 101 | 102 | 103 | 196 104 | Reallocation Event Count 105 | 106 | 107 | 197 108 | Pending Sector Reallocation Count 109 | 110 | 111 | 198 112 | Off-Line Scan Uncorrecable Sector Count 113 | 114 | 115 | 199 116 | CRC Error Count 117 | 118 | 119 | 200 120 | Multi-zone Error Rate 121 | 122 | 123 | 240 124 | Head Flying Hours 125 | 126 | 127 | 241 128 | Total LBAs Written 129 | 130 | 131 | 242 132 | Total LBAs Read 133 | 134 | 135 | 254 136 | Free Fall Sensor 137 | 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /libscsicmd/src/smartdb/smartdb_gen.c: -------------------------------------------------------------------------------- 1 | #include "smartdb.h" 2 | static const smart_table_t defaults = { 3 | .num_attrs = 26, 4 | .attrs = { 5 | {.id=1, .type=SMART_ATTR_TYPE_NONE, .name="Raw Read Error Rate", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, 6 | {.id=2, .type=SMART_ATTR_TYPE_NONE, .name="Throughput Performance", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, 7 | {.id=3, .type=SMART_ATTR_TYPE_NONE, .name="Spin Up Time", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, 8 | {.id=4, .type=SMART_ATTR_TYPE_NONE, .name="Start/Stop Count", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, 9 | {.id=5, .type=SMART_ATTR_TYPE_REALLOC, .name="Reallocated Sectors Count", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, 10 | {.id=7, .type=SMART_ATTR_TYPE_NONE, .name="Seek Error Rate", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, 11 | {.id=8, .type=SMART_ATTR_TYPE_NONE, .name="Seek Time Performance", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, 12 | {.id=9, .type=SMART_ATTR_TYPE_POH, .name="Power On Hours", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, 13 | {.id=10, .type=SMART_ATTR_TYPE_NONE, .name="Spin Retry Count", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, 14 | {.id=11, .type=SMART_ATTR_TYPE_NONE, .name="Drive Calibration Retry Count", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, 15 | {.id=12, .type=SMART_ATTR_TYPE_NONE, .name="Device Power Cycle Count", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, 16 | {.id=13, .type=SMART_ATTR_TYPE_NONE, .name="Read Soft Error Rate", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, 17 | {.id=191, .type=SMART_ATTR_TYPE_NONE, .name="G Sense Error Rate", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, 18 | {.id=192, .type=SMART_ATTR_TYPE_NONE, .name="Power Off Retract Count", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, 19 | {.id=193, .type=SMART_ATTR_TYPE_NONE, .name="Load/Unload Cycle Count", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, 20 | {.id=194, .type=SMART_ATTR_TYPE_TEMP, .name="Temperature", .raw=SMART_ATTR_RAW_DEC48, .offset=150}, 21 | {.id=195, .type=SMART_ATTR_TYPE_NONE, .name="Hardware ECC Recovered", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, 22 | {.id=196, .type=SMART_ATTR_TYPE_NONE, .name="Reallocation Event Count", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, 23 | {.id=197, .type=SMART_ATTR_TYPE_REALLOC_PENDING, .name="Pending Sector Reallocation Count", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, 24 | {.id=198, .type=SMART_ATTR_TYPE_NONE, .name="Off-Line Scan Uncorrecable Sector Count", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, 25 | {.id=199, .type=SMART_ATTR_TYPE_CRC_ERRORS, .name="CRC Error Count", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, 26 | {.id=200, .type=SMART_ATTR_TYPE_NONE, .name="Multi-zone Error Rate", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, 27 | {.id=240, .type=SMART_ATTR_TYPE_NONE, .name="Head Flying Hours", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, 28 | {.id=241, .type=SMART_ATTR_TYPE_NONE, .name="Total LBAs Written", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, 29 | {.id=242, .type=SMART_ATTR_TYPE_NONE, .name="Total LBAs Read", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, 30 | {.id=254, .type=SMART_ATTR_TYPE_NONE, .name="Free Fall Sensor", .raw=SMART_ATTR_RAW_DEC48, .offset=-1}, 31 | } 32 | }; 33 | const smart_table_t * smart_table_for_disk(const char *vendor, const char *model, const char *firmware) 34 | { 35 | (void)vendor; 36 | (void)model; 37 | (void)firmware; 38 | return &defaults; 39 | } 40 | -------------------------------------------------------------------------------- /libscsicmd/src/smartdb/smartdb_gen_c.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import xml.etree.ElementTree as ET 4 | import sys 5 | 6 | tree = ET.parse(sys.argv[1]) 7 | root = tree.getroot() 8 | 9 | assert root.tag == 'smartdb' 10 | 11 | names = {} 12 | defaults = {} 13 | 14 | raw_types = { 15 | 'hex48': 'SMART_ATTR_RAW_HEX48', 16 | 'dec48': 'SMART_ATTR_RAW_DEC48', 17 | } 18 | raw_type_default = 'dec48' 19 | def raw_type_to_enum(raw): 20 | return raw_types.get(raw) 21 | 22 | attr_code = { 23 | 'none': 'SMART_ATTR_TYPE_NONE', 24 | 'poh': 'SMART_ATTR_TYPE_POH', 25 | 'temperature': 'SMART_ATTR_TYPE_TEMP', 26 | 'reallocations': 'SMART_ATTR_TYPE_REALLOC', 27 | 'pending_reallocations': 'SMART_ATTR_TYPE_REALLOC_PENDING', 28 | 'crc_count': 'SMART_ATTR_TYPE_CRC_ERRORS', 29 | } 30 | attr_code_default = 'none' 31 | def attr_code_to_enum(code): 32 | try: 33 | return attr_code[code] 34 | except KeyError: 35 | sys.stderr.write('Cannot find key "%s" in the known attribute code list: %s\n' % (code, attr_code.keys())) 36 | raise 37 | 38 | def validate_name(c, root): 39 | assert root.tag == 'name' 40 | name = root.text.strip() 41 | assert len(name) > 0 42 | for child in root: 43 | assert False, 'node cant have a child' 44 | assert name not in names 45 | names[name] = root.get('type', attr_code_default) 46 | 47 | def validate_attr(d, root): 48 | assert root.tag == 'attr' 49 | aid = None 50 | name = None 51 | tempoffset = -1 52 | raw = raw_type_default 53 | code = attr_code_default 54 | for child in root: 55 | assert child.tag in ('id', 'name', 'raw', 'tempoffset') 56 | if child.tag == 'id': 57 | val = int(child.text) 58 | assert val > 0 59 | assert val <= 255 60 | aid = val 61 | elif child.tag == 'name': 62 | val = child.text.strip() 63 | assert val in names 64 | name = val 65 | code = names.get(name) 66 | elif child.tag == 'raw': 67 | val = child.text.strip() 68 | assert val in list(raw_types.keys()) 69 | raw = val 70 | elif child.tag == 'tempoffset': 71 | val = int(child.text) 72 | assert val > 0 and val < 255 73 | tempoffset = val 74 | d[aid] = (aid, name, raw, code, tempoffset) 75 | 76 | nodes = { 77 | 'names': validate_name, 78 | 'default': validate_attr, 79 | } 80 | 81 | for child in root: 82 | if child.tag not in list(nodes.keys()): 83 | raise 'tag %s is unknown at smartdb level' % child.tag 84 | vfunc = nodes.get(child.tag) 85 | for subchild in child: 86 | vfunc(defaults, subchild) 87 | 88 | print('#include "smartdb.h"') 89 | 90 | print('static const smart_table_t defaults = {') 91 | print('.num_attrs = %d,' % len(defaults)) 92 | print('.attrs = {') 93 | keys = list(defaults.keys()) 94 | keys.sort() 95 | for aid in keys: 96 | attr = defaults[aid] 97 | name = attr[1] 98 | raw = raw_type_to_enum(attr[2]) 99 | atype = attr_code_to_enum(attr[3]) 100 | tempoffset = attr[4] 101 | print('{.id=%d, .type=%s, .name="%s", .raw=%s, .offset=%d},' % (aid, atype, name, raw, tempoffset)) 102 | print('}') 103 | print('};') 104 | 105 | print('const smart_table_t * smart_table_for_disk(const char *vendor, const char *model, const char *firmware)') 106 | print('{') 107 | print('(void)vendor;') 108 | print('(void)model;') 109 | print('(void)firmware;') 110 | print('return &defaults;') 111 | print('}') 112 | -------------------------------------------------------------------------------- /libscsicmd/src/str_map.c: -------------------------------------------------------------------------------- 1 | #include "scsicmd.h" 2 | 3 | #include 4 | 5 | const char *sense_key_to_name(enum sense_key_e sense_key) 6 | { 7 | #undef SENSE_KEY_MAP 8 | 9 | switch (sense_key) { 10 | #define SENSE_KEY_MAP(_name_, _val_) \ 11 | case _val_: return #_name_ ; 12 | SENSE_KEY_LIST 13 | } 14 | #undef SENSE_KEY_MAP 15 | 16 | return "Unknown sense key"; 17 | } 18 | 19 | const char *asc_num_to_name(uint8_t asc, uint8_t ascq) 20 | { 21 | static char msg[64]; 22 | 23 | uint16_t asc_full = asc<<8 | ascq; 24 | 25 | switch (asc_full) { 26 | #define SENSE_CODE_KEYED(_asc_, _fmt_) 27 | #define SENSE_CODE(_asc_, _ascq_, _msg_) case _asc_<<8 | _ascq_: return _msg_; 28 | ASC_NUM_LIST 29 | #undef SENSE_CODE 30 | #undef SENSE_CODE_KEYED 31 | } 32 | 33 | #define SENSE_CODE_KEYED(_asc_, _fmt_) if (asc == _asc_) { snprintf(msg, sizeof(msg), _fmt_, ascq); return msg; } 34 | #define SENSE_CODE(_asc_, _ascq_, _msg_) 35 | ASC_NUM_LIST 36 | #undef SENSE_CODE 37 | #undef SENSE_CODE_KEYED 38 | 39 | snprintf(msg, sizeof(msg), "UNKNOWN ASC/ASCQ (%02Xh/%02Xh)", asc, ascq); 40 | return msg; 41 | } 42 | -------------------------------------------------------------------------------- /libscsicmd/structs/asc-num-to-list: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | 5 | def nn_str(name): 6 | return name.replace('NN', '%u') 7 | 8 | # Skip the header 9 | for line in sys.stdin: 10 | if line[0] == '-': 11 | break 12 | 13 | # Read the raw data 14 | print('#ifndef LIBSCSICMD_ASC_NUM_LIST_H') 15 | print('#define LIBSCSICMD_ASC_NUM_LIST_H') 16 | print('#define ASC_NUM_LIST \\') 17 | for line in sys.stdin: 18 | line = line.strip() 19 | asc = int(line[0:2], 16) 20 | ascq_str = line[4:6] 21 | if ascq_str == 'NN': 22 | ascq = 'NN' 23 | else: 24 | ascq = int(ascq_str, 16) 25 | name = line[24:] 26 | if name == '': 27 | continue 28 | 29 | if ascq == 'NN': 30 | name_nn = nn_str(name) 31 | print('SENSE_CODE_KEYED(0x%x, "%s") \\' % (asc, name_nn)) 32 | else: 33 | print('SENSE_CODE(0x%x, 0x%x, "%s") \\' % (asc, ascq, name)) 34 | print() 35 | print('#endif') 36 | -------------------------------------------------------------------------------- /libscsicmd/structs/ata_struct_2_c_dump.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | import yaml 5 | 6 | def emit_func_bit(name, field, params): 7 | bit_params = dict(name=name, field=field, word=int(params[0]), bit=int(params[1])) 8 | print('printf("%%-40s: %%s\\n", "%(field)s", ata_get_%(name)s_%(field)s(buf) ? "true" : "false");' % bit_params) 9 | 10 | def emit_func_string(name, field, params): 11 | bit_params = dict(name=name, field=field, word_start=int(params[0]), word_end=int(params[1])) 12 | print('{') 13 | print('char outbuf[1024];') 14 | print('ata_get_%(name)s_%(field)s(buf, outbuf);' % bit_params) 15 | print('printf("%%-40s: %%s\\n", "%(field)s", outbuf);' % bit_params) 16 | print('}') 17 | 18 | def emit_func_bits(name, field, params): 19 | bit_params = dict(name=name, field=field, word_start=int(params[0])) 20 | print('printf("%%-40s: %%u\\n", "%(field)s", ata_get_%(name)s_%(field)s(buf));' % bit_params) 21 | 22 | def emit_func_longword(name, field, params): 23 | bit_params = dict(name=name, field=field, word_start=int(params)) 24 | print('printf("%%-40s: %%u\\n", "%(field)s", ata_get_%(name)s_%(field)s(buf));' % bit_params) 25 | 26 | def emit_func_qword(name, field, params): 27 | bit_params = dict(name=name, field=field, word_start=int(params)) 28 | print('printf("%%-40s: %%"PRIu64"\\n", "%(field)s", ata_get_%(name)s_%(field)s(buf));' % bit_params) 29 | 30 | kinds = { 31 | 'bit': emit_func_bit, 32 | 'bits': emit_func_bits, 33 | 'string': emit_func_string, 34 | 'longword': emit_func_longword, 35 | 'qword': emit_func_qword, 36 | } 37 | 38 | def emit_header_single(name, struct): 39 | field_names = list(struct.keys()) 40 | field_names.sort() 41 | 42 | for field in field_names: 43 | info = struct[field] 44 | keys = list(info.keys()) 45 | assert(len(keys) == 1) 46 | kind = keys[0] 47 | params = info[kind] 48 | 49 | kinds[kind](name, field, params) 50 | 51 | def emit_header(structs): 52 | for name, struct in list(structs.items()): 53 | print('void dump_%s(const unsigned char *buf)' % name) 54 | print('{') 55 | emit_header_single(name, struct) 56 | print('}') 57 | 58 | def emit_prefix(): 59 | print('#include "ata.h"') 60 | print('#include "ata_parse.h"') 61 | print('#include "ata_identify_dump.h"') 62 | print('#include ') 63 | print('#include ') 64 | 65 | def emit_suffix(): 66 | print('') 67 | 68 | def convert_def(filename): 69 | f = file(filename) 70 | structs = yaml.load(f) 71 | f.close() 72 | emit_header(structs) 73 | 74 | if __name__ == '__main__': 75 | emit_prefix() 76 | filenames = sys.argv[1:] 77 | for filename in filenames: 78 | convert_def(filename) 79 | emit_suffix() 80 | -------------------------------------------------------------------------------- /libscsicmd/structs/ata_struct_2_h.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | import yaml 5 | 6 | def emit_func_bit(name, field, params): 7 | bit_params = dict(name=name, field=field, word=int(params[0]), bit=int(params[1])) 8 | print("""static inline bool ata_get_%(name)s_%(field)s(const unsigned char *buf) { 9 | ata_word_t val = ata_get_word(buf, %(word)d); 10 | return val & (1 << %(bit)d); 11 | } 12 | """ % bit_params) 13 | 14 | def emit_func_bits(name, field, params): 15 | bit_params = dict(name=name, field=field, word=int(params[0]), start_bit=int(params[1]), end_bit=int(params[2])) 16 | print("""static inline unsigned ata_get_%(name)s_%(field)s(const unsigned char *buf) { 17 | ata_word_t val = ata_get_word(buf, %(word)d); 18 | return (val >> %(start_bit)d) & ((1<<(%(end_bit)d - %(start_bit)d + 1)) - 1); 19 | } 20 | """ % bit_params) 21 | 22 | def emit_func_string(name, field, params): 23 | bit_params = dict(name=name, field=field, word_start=int(params[0]), word_end=int(params[1])) 24 | print("""static inline void ata_get_%(name)s_%(field)s(const unsigned char *buf, char *out) { 25 | ata_get_string(buf, %(word_start)d, %(word_end)d, out); 26 | } 27 | """ % bit_params) 28 | 29 | def emit_func_longword(name, field, params): 30 | bit_params = dict(name=name, field=field, word_start=int(params)) 31 | print("""static inline ata_longword_t ata_get_%(name)s_%(field)s(const unsigned char *buf) { 32 | return ata_get_longword(buf, %(word_start)d); 33 | } 34 | """ % bit_params) 35 | 36 | def emit_func_qword(name, field, params): 37 | bit_params = dict(name=name, field=field, word_start=int(params)) 38 | print("""static inline ata_qword_t ata_get_%(name)s_%(field)s(const unsigned char *buf) { 39 | return ata_get_qword(buf, %(word_start)d); 40 | } 41 | """ % bit_params) 42 | 43 | kinds = { 44 | 'bit': emit_func_bit, 45 | 'bits': emit_func_bits, 46 | 'string': emit_func_string, 47 | 'longword': emit_func_longword, 48 | 'qword': emit_func_qword, 49 | } 50 | 51 | def emit_header_single(name, struct): 52 | for field, info in list(struct.items()): 53 | keys = list(info.keys()) 54 | assert(len(keys) == 1) 55 | kind = keys[0] 56 | params = info[kind] 57 | 58 | kinds[kind](name, field, params) 59 | 60 | def emit_header(structs): 61 | for name, struct in list(structs.items()): 62 | emit_header_single(name, struct) 63 | 64 | def emit_prefix(): 65 | print('/* Generated file, do not edit */') 66 | print('#ifndef ATA_PARSE_H') 67 | print('#define ATA_PARSE_H') 68 | print('#include "ata.h"') 69 | 70 | def emit_suffix(): 71 | print('#endif') 72 | 73 | def convert_def(filename): 74 | f = open(filename) 75 | structs = yaml.load(f) 76 | f.close() 77 | emit_header(structs) 78 | 79 | if __name__ == '__main__': 80 | emit_prefix() 81 | filenames = sys.argv[1:] 82 | for filename in filenames: 83 | convert_def(filename) 84 | emit_suffix() 85 | -------------------------------------------------------------------------------- /libscsicmd/structs/ata_struct_2_h_dump.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | import yaml 5 | 6 | def emit_header(structs): 7 | for name, struct in list(structs.items()): 8 | print('void dump_%s(const unsigned char *buf);' % name) 9 | 10 | def emit_prefix(): 11 | print('#ifndef _DUMP_H_') 12 | print('#define _DUMP_H_') 13 | 14 | def emit_suffix(): 15 | print('#endif') 16 | 17 | def convert_def(filename): 18 | f = file(filename) 19 | structs = yaml.load(f) 20 | f.close() 21 | emit_header(structs) 22 | 23 | if __name__ == '__main__': 24 | emit_prefix() 25 | filenames = sys.argv[1:] 26 | for filename in filenames: 27 | convert_def(filename) 28 | emit_suffix() 29 | -------------------------------------------------------------------------------- /libscsicmd/structs/update-asc-num: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | if [ -d structs ]; then 5 | cd structs 6 | fi 7 | curl 'http://www.t10.org/lists/asc-num.txt' > asc-num.txt.tmp 8 | mv asc-num.txt.tmp asc-num.txt 9 | dos2unix asc-num.txt 10 | ./asc-num-to-list < asc-num.txt > asc-num.h 11 | mv asc-num.h ../include/asc_num_list.h 12 | -------------------------------------------------------------------------------- /libscsicmd/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(testlib STATIC main.c sense_dump.c) 2 | 3 | add_executable(ata_check_power_mode ata_check_power_mode.c) 4 | target_link_libraries(ata_check_power_mode testlib scsicmd) 5 | 6 | add_custom_command(OUTPUT ata_identify_dump.h 7 | COMMAND ../structs/ata_struct_2_h_dump.py ../structs/ata_identify.yaml > ata_identify_dump.h 8 | DEPENDS ../structs/ata_struct_2_h_dump.py ../structs/ata_identify.yaml) 9 | add_custom_command(OUTPUT ata_identify_dump.c 10 | COMMAND ../structs/ata_struct_2_c_dump.py ../structs/ata_identify.yaml > ata_identify_dump.c 11 | DEPENDS ../structs/ata_struct_2_c_dump.py ../structs/ata_identify.yaml) 12 | add_executable(ata_identify ata_identify.c ata_identify_dump.c ata_identify_dump.h) 13 | target_link_libraries(ata_identify testlib scsicmd) 14 | 15 | add_executable(ata_smart_read_data ata_smart_read_data.c) 16 | target_link_libraries(ata_smart_read_data testlib scsicmd) 17 | 18 | add_executable(ata_smart_return_status ata_smart_return_status.c) 19 | target_link_libraries(ata_smart_return_status testlib scsicmd) 20 | 21 | add_executable(scsi_inquiry scsi_inquiry.c) 22 | target_link_libraries(scsi_inquiry testlib scsicmd) 23 | 24 | add_executable(scsi_log_sense scsi_log_sense.c) 25 | target_link_libraries(scsi_log_sense testlib scsicmd) 26 | 27 | add_executable(parse_scsi parse_scsi.c) 28 | target_link_libraries(parse_scsi testlib scsicmd) 29 | 30 | add_executable(scsi_mode_sense scsi_mode_sense.c) 31 | target_link_libraries(scsi_mode_sense testlib scsicmd) 32 | 33 | add_executable(scsi_receive_diagnostics scsi_receive_diagnostics.c) 34 | target_link_libraries(scsi_receive_diagnostics testlib scsicmd) 35 | 36 | add_executable(scsi_read_capacity_10 scsi_read_capacity_10.c) 37 | target_link_libraries(scsi_read_capacity_10 testlib scsicmd) 38 | 39 | add_executable(scsi_read_capacity_16 scsi_read_capacity_16.c) 40 | target_link_libraries(scsi_read_capacity_16 testlib scsicmd) 41 | 42 | add_executable(sense_decode sense_decode.c) 43 | target_link_libraries(sense_decode testlib scsicmd) 44 | 45 | add_executable(collect_raw_data collect_raw_data.c) 46 | target_link_libraries(collect_raw_data testlib scsicmd) 47 | -------------------------------------------------------------------------------- /libscsicmd/test/ata_check_power_mode.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2013 Baruch Even 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "ata.h" 18 | #include "ata_parse.h" 19 | #include "main.h" 20 | #include 21 | #include 22 | #include 23 | 24 | void do_command(int fd) 25 | { 26 | unsigned char cdb[12]; 27 | unsigned char buf[512] ; 28 | int cdb_len = cdb_ata_check_power_mode(cdb); 29 | 30 | bool ret = submit_cmd(fd, cdb, cdb_len, buf, sizeof(buf), SG_DXFER_FROM_DEV); 31 | if (!ret) { 32 | fprintf(stderr, "Failed to submit command\n"); 33 | return; 34 | } 35 | 36 | unsigned char *sense; 37 | unsigned sense_len; 38 | ret = read_response(fd, &sense, &sense_len); 39 | if (!ret) { 40 | fprintf(stderr, "Error reading scsi response\n"); 41 | return; 42 | } 43 | 44 | ata_status_t status; 45 | if (sense && ata_status_from_scsi_sense(sense, sense_len, &status)) { 46 | printf("extend: %d\n", status.extend); 47 | printf("error: %02x\n", status.error); 48 | printf("lba: %08"PRIx64"\n", status.lba); 49 | printf("device: %02x\n", status.device); 50 | printf("status: %02x\n", status.status); 51 | printf("count: %02x\n", status.sector_count); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /libscsicmd/test/ata_identify.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2013 Baruch Even 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "ata.h" 18 | #include "ata_parse.h" 19 | #include "ata_identify_dump.h" 20 | #include "main.h" 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | void do_command(int fd) 32 | { 33 | unsigned char cdb[32]; 34 | unsigned char buf[512] ; 35 | unsigned cdb_len = cdb_ata_identify(cdb); 36 | 37 | bool ret = submit_cmd(fd, cdb, cdb_len, buf, sizeof(buf), SG_DXFER_FROM_DEV); 38 | if (!ret) { 39 | fprintf(stderr, "Failed to submit command\n"); 40 | return; 41 | } 42 | 43 | unsigned char *sense = NULL; 44 | unsigned sense_len = 0; 45 | ret = read_response(fd, &sense, &sense_len); 46 | 47 | ata_status_t status; 48 | if (sense && ata_status_from_scsi_sense(sense, sense_len, &status)) { 49 | printf("extend: %d\n", status.extend); 50 | printf("error: %02x\n", status.error); 51 | printf("lba: %08"PRIx64"\n", status.lba); 52 | printf("device: %02x\n", status.device); 53 | printf("status: %02x\n", status.status); 54 | } 55 | 56 | if (!sense) 57 | dump_ata_identify(buf); 58 | else 59 | printf("error while reading ATA IDENTIFY, nothing to show\n"); 60 | } 61 | -------------------------------------------------------------------------------- /libscsicmd/test/ata_smart_return_status.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2013 Baruch Even 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "ata.h" 18 | #include "ata_parse.h" 19 | #include "main.h" 20 | #include 21 | #include 22 | #include 23 | 24 | void do_command(int fd) 25 | { 26 | unsigned char cdb[12]; 27 | unsigned char buf[512] ; 28 | int cdb_len = cdb_ata_smart_return_status(cdb); 29 | 30 | bool ret = submit_cmd(fd, cdb, cdb_len, buf, sizeof(buf), SG_DXFER_FROM_DEV); 31 | if (!ret) { 32 | fprintf(stderr, "Failed to submit command\n"); 33 | return; 34 | } 35 | 36 | unsigned char *sense; 37 | unsigned sense_len; 38 | ret = read_response(fd, &sense, &sense_len); 39 | if (!ret) { 40 | fprintf(stderr, "Error reading scsi response\n"); 41 | return; 42 | } 43 | printf("\n"); 44 | 45 | ata_status_t status; 46 | if (ata_status_from_scsi_sense(sense, sense_len, &status)) { 47 | printf("extend: %d\n", status.extend); 48 | printf("error: %02x\n", status.error); 49 | printf("lba: %08" PRIx64 "\n", status.lba); 50 | printf("device: %02x\n", status.device); 51 | printf("status: %02x\n", status.status); 52 | } 53 | printf("\n"); 54 | 55 | bool smart_ok; 56 | if (ata_smart_return_status_result(sense, sense_len, &smart_ok)) 57 | printf("smart result: %s\n", smart_ok ? "ok" : "failed"); 58 | else 59 | printf("smart parsing failed\n"); 60 | } 61 | -------------------------------------------------------------------------------- /libscsicmd/test/main.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2013 Baruch Even 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "ata.h" 18 | #include "ata_parse.h" 19 | #include "main.h" 20 | #include "sense_dump.h" 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | static unsigned char sense[128]; 31 | 32 | int debug = 1; 33 | 34 | bool submit_cmd(int fd, unsigned char *cdb, unsigned cdb_len, unsigned char *buf, unsigned buf_len, int dxfer_dir) 35 | { 36 | sg_io_hdr_t hdr; 37 | 38 | if (debug) 39 | cdb_dump(cdb, cdb_len); 40 | 41 | memset(&hdr, 0, sizeof(hdr)); 42 | 43 | hdr.interface_id = 'S'; 44 | hdr.dxfer_direction = dxfer_dir; 45 | hdr.cmd_len = cdb_len; 46 | hdr.mx_sb_len = sizeof(sense); 47 | hdr.dxfer_len = buf_len; 48 | hdr.dxferp = buf; 49 | hdr.cmdp = cdb; 50 | hdr.sbp = sense; 51 | hdr.timeout = 30*1000; 52 | hdr.flags = SG_FLAG_LUN_INHIBIT; 53 | hdr.pack_id = 0; 54 | hdr.usr_ptr = 0; 55 | 56 | ssize_t ret = write(fd, &hdr, sizeof(hdr)); 57 | return ret == sizeof(hdr); 58 | } 59 | 60 | bool read_response_buf(int fd, unsigned char **sensep, unsigned *sense_len, unsigned *buf_read) 61 | { 62 | *sensep = NULL; 63 | *sense_len = 0; 64 | 65 | sg_io_hdr_t hdr; 66 | int ret = read(fd, &hdr, sizeof(hdr)); 67 | if (ret != sizeof(hdr)) { 68 | fprintf(stderr, "Error reading scsi response, ret=%d, expected=%d, %m\n", ret, (int)sizeof(hdr)); 69 | return false; 70 | } 71 | 72 | printf("status: %d\n", hdr.status); 73 | printf("masked status: %d\n", hdr.masked_status); 74 | printf("driver status: %d\n", hdr.driver_status); 75 | printf("msg status: %d\n", hdr.msg_status); 76 | printf("host status: %d\n", hdr.host_status); 77 | printf("sense len: %d\n", hdr.sb_len_wr); 78 | 79 | if (hdr.sb_len_wr) { 80 | *sensep = sense; 81 | *sense_len = hdr.sb_len_wr; 82 | 83 | if (debug) { 84 | printf("sense data:\n"); 85 | sense_dump(sense, hdr.sb_len_wr); 86 | } 87 | } 88 | if (buf_read) 89 | *buf_read = hdr.dxfer_len - hdr.resid; 90 | return true; 91 | } 92 | 93 | static void test(const char *devname) 94 | { 95 | int fd = open(devname, O_RDWR); 96 | if (fd < 0) { 97 | fprintf(stderr, "Error opening device '%s': %m\n", devname); 98 | return; 99 | } 100 | 101 | do_command(fd); 102 | 103 | close(fd); 104 | } 105 | 106 | static int usage(char *name) 107 | { 108 | fprintf(stderr, "Usage:\n"); 109 | fprintf(stderr, "\t%s disk_device\n", name); 110 | return 1; 111 | } 112 | 113 | int main(int argc, char **argv) 114 | { 115 | if (argc != 2 || strstr(argv[1], "/sd") != NULL) 116 | return usage(argv[0]); 117 | 118 | test(argv[1]); 119 | return 0; 120 | } 121 | -------------------------------------------------------------------------------- /libscsicmd/test/main.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBSCSICMD_TEST_H 2 | #define LIBSCSICMD_TEST_H 3 | 4 | #include 5 | 6 | extern int debug; 7 | 8 | /** Do the command that we want to test on the open disk interface. */ 9 | void do_command(int fd); 10 | bool submit_cmd(int fd, unsigned char *cdb, unsigned cdb_len, unsigned char *buf, unsigned buf_len, int dxfer_dir); 11 | bool read_response_buf(int fd, unsigned char **sense, unsigned *sense_len, unsigned *buf_read); 12 | 13 | static inline bool read_response(int fd, unsigned char **sense, unsigned *sense_len) 14 | { 15 | return read_response_buf(fd, sense, sense_len, NULL); 16 | } 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /libscsicmd/test/samples/breakout.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | import subprocess 5 | 6 | files = { 7 | ',4d ' : 'log_sense', 8 | ',25 ' : 'read_cap_10', 9 | ',9e ' : 'read_cap_16', 10 | ',12 ' : 'inquiry', 11 | ',5a ' : 'mode_sense_10', 12 | ',1a ' : 'mode_sense_6', 13 | ',37 ' : 'read_defect_data_10', 14 | ',b7 ' : 'read_defect_data_12', 15 | ',1c ' : 'receive_diagnostics', 16 | } 17 | 18 | for key in files.keys(): 19 | filename = files[key] + '.csv.bz2' 20 | f = subprocess.Popen(['/bin/bzip2', '-z', '-c', '-9'], stdin=subprocess.PIPE, stdout=file(filename, 'w')) 21 | if f is None: 22 | print 'Failed to create process for', filename 23 | files[key] = f 24 | 25 | for line in sys.stdin: 26 | prefix = line[0:4] 27 | f = files.get(prefix, None) 28 | if f is None: 29 | print '"%s"' % prefix 30 | continue 31 | f.stdin.write(line) 32 | 33 | for key in files.keys(): 34 | print 'Closing', key 35 | files[key].stdin.close() 36 | files[key].wait() 37 | print 'Done' 38 | -------------------------------------------------------------------------------- /libscsicmd/test/samples/parse_file.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | import csv 5 | import os 6 | 7 | def parse_file(f): 8 | c = csv.reader(f) 9 | for line in c: 10 | msg = line[0] 11 | if msg != '': continue 12 | if len(line) != 4: continue 13 | 14 | cdb = line[1] 15 | sense = line[2] 16 | data = line[3] 17 | 18 | print('Parsing CDB: %s' % cdb) 19 | print('Parsing Sense: %s' % sense) 20 | print('Parsing Data: %s' % data) 21 | sys.stdout.flush() 22 | sys.stderr.flush() 23 | os.system('../parse_scsi "%s" "%s" "%s"' % (cdb, sense, data)) 24 | sys.stdout.flush() 25 | sys.stderr.flush() 26 | print('=========================================================================\n') 27 | 28 | if len(sys.argv) > 1: 29 | for filename in sys.argv[1:]: 30 | print('Parsing file %s' % filename) 31 | f = file(filename, 'r') 32 | parse_file(f) 33 | print('Done') 34 | print('') 35 | else: 36 | parse_file(sys.stdin) 37 | -------------------------------------------------------------------------------- /libscsicmd/test/scsi_log_sense.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2014 Baruch Even 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "scsicmd.h" 18 | #include "scsicmd_utils.h" 19 | 20 | #include "main.h" 21 | #include "sense_dump.h" 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | static void dump_page(int fd, uint8_t page, uint8_t subpage) 33 | { 34 | unsigned char cdb[32]; 35 | unsigned char buf[16*1024]; 36 | unsigned cdb_len = cdb_log_sense(cdb, page, subpage, sizeof(buf)); 37 | 38 | printf("List page %02X subpage %02X\n", page, subpage); 39 | bool ret = submit_cmd(fd, cdb, cdb_len, buf, sizeof(buf), SG_DXFER_FROM_DEV); 40 | if (!ret) { 41 | fprintf(stderr, "Failed to submit command\n"); 42 | return; 43 | } 44 | 45 | unsigned char *sense = NULL; 46 | unsigned sense_len = 0; 47 | unsigned buf_len = 0; 48 | ret = read_response_buf(fd, &sense, &sense_len, &buf_len); 49 | 50 | if (sense) { 51 | printf("error while reading response buffer, nothing to show\n"); 52 | return; 53 | } 54 | 55 | printf("Read %u bytes\n", buf_len); 56 | response_dump(buf, buf_len); 57 | printf("\n"); 58 | } 59 | 60 | void do_command(int fd) 61 | { 62 | unsigned char cdb[32]; 63 | unsigned char buf[16*1024]; 64 | unsigned cdb_len = cdb_log_sense(cdb, 0, 0, sizeof(buf)); 65 | 66 | printf("List all supported pages\n"); 67 | bool ret = submit_cmd(fd, cdb, cdb_len, buf, sizeof(buf), SG_DXFER_FROM_DEV); 68 | if (!ret) { 69 | fprintf(stderr, "Failed to submit command\n"); 70 | return; 71 | } 72 | 73 | unsigned char *sense = NULL; 74 | unsigned sense_len = 0; 75 | unsigned buf_len = 0; 76 | ret = read_response_buf(fd, &sense, &sense_len, &buf_len); 77 | 78 | if (sense) { 79 | printf("error while reading response buffer, nothing to show\n"); 80 | return; 81 | } 82 | 83 | printf("Read %u bytes\n", buf_len); 84 | response_dump(buf, buf_len); 85 | 86 | if (buf_len < 4) { 87 | printf("log sense list must have at least 4 bytes\n"); 88 | return; 89 | } 90 | 91 | if (buf[0] != 0 || buf[1] != 0) { 92 | printf("expected to receive log page 0 subpage 0\n"); 93 | return; 94 | } 95 | 96 | uint16_t num_pages = get_uint16(buf, 2); 97 | uint16_t i; 98 | for (i = 0; i < num_pages; i++) { 99 | dump_page(fd, buf[4 + i], 0); 100 | } 101 | 102 | printf("List all pages and subpages\n"); 103 | cdb_len = cdb_log_sense(cdb, 0, 0xff, sizeof(buf)); 104 | 105 | ret = submit_cmd(fd, cdb, cdb_len, buf, sizeof(buf), SG_DXFER_FROM_DEV); 106 | if (!ret) { 107 | fprintf(stderr, "Failed to submit command\n"); 108 | return; 109 | } 110 | 111 | sense = NULL; 112 | sense_len = 0; 113 | buf_len = 0; 114 | ret = read_response_buf(fd, &sense, &sense_len, &buf_len); 115 | 116 | if (sense) { 117 | printf("error while reading response buffer, nothing to show\n"); 118 | return; 119 | } 120 | 121 | printf("Read %u bytes\n", buf_len); 122 | 123 | response_dump(buf, buf_len); 124 | 125 | if (buf_len < 4) { 126 | printf("log sense list must have at least 4 bytes\n"); 127 | return; 128 | } 129 | 130 | if (buf[0] != 0x40 || buf[1] != 0xFF) { 131 | printf("expected to receive log page 0 (spf=1) subpage 0xFF\n"); 132 | return; 133 | } 134 | 135 | num_pages = get_uint16(buf, 2); 136 | for (i = 0; i < num_pages; i++) { 137 | uint8_t page = buf[4 + i*2] & 0x3F; 138 | uint8_t subpage = buf[4 + i*2 + 1]; 139 | if (subpage == 0) { 140 | printf("Skipping page %02X subpage %02X since subpage is 00 it was already retrieved above\n", page, subpage); 141 | continue; 142 | } 143 | dump_page(fd, page, subpage); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /libscsicmd/test/scsi_mode_sense.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2014 Baruch Even 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "scsicmd.h" 18 | #include "main.h" 19 | #include "sense_dump.h" 20 | #include "parse_mode_sense.h" 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | void do_command(int fd) 32 | { 33 | unsigned char cdb[32]; 34 | unsigned char buf[4096]; 35 | unsigned cdb_len = cdb_mode_sense_10(cdb, true, false, PAGE_CONTROL_CURRENT, 0x3F, 0xFF, sizeof(buf)); 36 | 37 | memset(buf, 0, sizeof(buf)); 38 | printf("List all supported pages\n"); 39 | bool ret = submit_cmd(fd, cdb, cdb_len, buf, sizeof(buf), SG_DXFER_FROM_DEV); 40 | if (!ret) { 41 | fprintf(stderr, "Failed to submit command\n"); 42 | return; 43 | } 44 | 45 | unsigned char *sense = NULL; 46 | unsigned sense_len = 0; 47 | unsigned buf_len = 0; 48 | ret = read_response_buf(fd, &sense, &sense_len, &buf_len); 49 | 50 | if (sense) { 51 | printf("error while reading response buffer, nothing to show\n"); 52 | return; 53 | } 54 | 55 | printf("Read %u bytes\n", buf_len); 56 | response_dump(buf, buf_len); 57 | 58 | if (buf_len < MODE_SENSE_10_MIN_LEN) { 59 | printf("Returned data is too short, expected a minimum of %u bytes and got only %u\n", MODE_SENSE_10_MIN_LEN, buf_len); 60 | return; 61 | } 62 | 63 | printf("Mode data len: %u\n", mode_sense_10_data_len(buf)); 64 | printf("Medium Type: %u\n", mode_sense_10_medium_type(buf)); 65 | printf("Device specific param: %u\n", mode_sense_10_device_specific_param(buf)); 66 | printf("Long LBA: %s\n", mode_sense_10_long_lba(buf) ? "yes" : "no"); 67 | printf("Block Descriptor length: %u\n", mode_sense_10_block_descriptor_length(buf)); 68 | 69 | if (buf_len < MODE_SENSE_10_MIN_LEN + mode_sense_10_block_descriptor_length(buf)) 70 | { 71 | printf("Not enough data for the block descriptor length\n"); 72 | return; 73 | } 74 | 75 | if (mode_sense_10_long_lba(buf)) { 76 | printf("Don't know how to parse the block descriptor for a long lba yet\n"); 77 | } else { 78 | uint8_t *bdb = mode_sense_10_block_descriptor_data(buf); 79 | 80 | putchar('\n'); 81 | printf("Density code: %u\n", block_descriptor_density_code(bdb)); 82 | printf("Num blocks: %u\n", block_descriptor_num_blocks(bdb)); 83 | printf("Block length: %u\n", block_descriptor_block_length(bdb)); 84 | } 85 | 86 | if (buf_len < MODE_SENSE_10_MIN_LEN + mode_sense_10_block_descriptor_length(buf) + mode_sense_10_data_len(buf)) 87 | { 88 | printf("Not enough data for the mode data length\n"); 89 | return; 90 | } 91 | 92 | putchar('\n'); 93 | //uint8_t *mode_data = mode_sense_10_mode_data(buf); 94 | 95 | } 96 | -------------------------------------------------------------------------------- /libscsicmd/test/scsi_read_capacity_10.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2013 Baruch Even 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "scsicmd.h" 18 | #include "main.h" 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | void do_command(int fd) 30 | { 31 | unsigned char cdb[32]; 32 | unsigned char buf[512] ; 33 | unsigned cdb_len = cdb_read_capacity_10(cdb); 34 | 35 | bool ret = submit_cmd(fd, cdb, cdb_len, buf, sizeof(buf), SG_DXFER_FROM_DEV); 36 | if (!ret) { 37 | fprintf(stderr, "Failed to submit command\n"); 38 | return; 39 | } 40 | 41 | unsigned char *sense = NULL; 42 | unsigned sense_len = 0; 43 | unsigned buf_len = 0; 44 | ret = read_response_buf(fd, &sense, &sense_len, &buf_len); 45 | 46 | if (sense) { 47 | printf("error while reading response buffer, nothing to show\n"); 48 | return; 49 | } 50 | 51 | printf("Read %u bytes\n", buf_len); 52 | 53 | uint32_t max_lba; 54 | uint32_t block_size; 55 | bool parsed = parse_read_capacity_10(buf, buf_len, &max_lba, &block_size); 56 | if (!parsed) { 57 | printf("Failed to parse read capacity buffer\n"); 58 | return; 59 | } 60 | 61 | printf("Max LBA: %u\nBlock size: %u\n", max_lba, block_size); 62 | return; 63 | } 64 | -------------------------------------------------------------------------------- /libscsicmd/test/scsi_read_capacity_16.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2013 Baruch Even 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "scsicmd.h" 18 | #include "main.h" 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | void do_command(int fd) 30 | { 31 | unsigned char cdb[32]; 32 | unsigned char buf[512] ; 33 | unsigned cdb_len = cdb_read_capacity_16(cdb, sizeof(buf)); 34 | 35 | bool ret = submit_cmd(fd, cdb, cdb_len, buf, sizeof(buf), SG_DXFER_FROM_DEV); 36 | if (!ret) { 37 | fprintf(stderr, "Failed to submit command\n"); 38 | return; 39 | } 40 | 41 | unsigned char *sense = NULL; 42 | unsigned sense_len = 0; 43 | unsigned buf_len = 0; 44 | ret = read_response_buf(fd, &sense, &sense_len, &buf_len); 45 | 46 | if (sense) { 47 | printf("error while reading response buffer, nothing to show\n"); 48 | return; 49 | } 50 | 51 | printf("Read %u bytes\n", buf_len); 52 | 53 | uint64_t max_lba; 54 | uint32_t block_size; 55 | bool prot_enable; 56 | unsigned p_type; 57 | unsigned p_i_exponent; 58 | unsigned logical_blocks_per_physical_block_exponent; 59 | bool thin_provisioning_enabled; 60 | bool thin_provisioning_zero; 61 | unsigned lowest_aligned_lba; 62 | bool parsed = parse_read_capacity_16(buf, buf_len, &max_lba, &block_size, &prot_enable, 63 | &p_type, &p_i_exponent, &logical_blocks_per_physical_block_exponent, 64 | &thin_provisioning_enabled, &thin_provisioning_zero, &lowest_aligned_lba); 65 | if (!parsed) { 66 | printf("Failed to parse read capacity buffer\n"); 67 | return; 68 | } 69 | 70 | printf("Max LBA: %"PRIu64"\nBlock size: %u\n", max_lba, block_size); 71 | printf("Protection enabled: %s\n", prot_enable ? "true" : "false"); 72 | printf("Protection type: %u\n", p_type); 73 | printf("Protection exponent: %u\n", p_i_exponent); 74 | printf("LBAs per block exponent: %u\n", logical_blocks_per_physical_block_exponent); 75 | printf("Thin provisioning enabled: %s\n", thin_provisioning_enabled ? "true" : "false"); 76 | printf("Thin provisoning zeroes: %s\n", thin_provisioning_zero ? "true" : "false"); 77 | printf("Lowest aligned LBA: %u\n", lowest_aligned_lba); 78 | return; 79 | } 80 | -------------------------------------------------------------------------------- /libscsicmd/test/scsi_receive_diagnostics.c: -------------------------------------------------------------------------------- 1 | /* Copyright 2014 Baruch Even 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | * 15 | */ 16 | 17 | #include "scsicmd.h" 18 | #include "parse_receive_diagnostics.h" 19 | #include "main.h" 20 | #include "sense_dump.h" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | static void dump_page(int fd, uint8_t page) 33 | { 34 | unsigned char cdb[32]; 35 | unsigned char buf[16*1024]; 36 | unsigned cdb_len = cdb_receive_diagnostics(cdb, true, page, sizeof(buf)); 37 | 38 | printf("List page %02X\n", page); 39 | bool ret = submit_cmd(fd, cdb, cdb_len, buf, sizeof(buf), SG_DXFER_FROM_DEV); 40 | if (!ret) { 41 | fprintf(stderr, "Failed to submit command\n"); 42 | return; 43 | } 44 | 45 | unsigned char *sense = NULL; 46 | unsigned sense_len = 0; 47 | unsigned buf_len = 0; 48 | ret = read_response_buf(fd, &sense, &sense_len, &buf_len); 49 | 50 | if (sense) { 51 | printf("error while reading response buffer, nothing to show\n"); 52 | return; 53 | } 54 | 55 | printf("Read %u bytes\n", buf_len); 56 | response_dump(buf, buf_len); 57 | printf("\n"); 58 | } 59 | 60 | void do_command(int fd) 61 | { 62 | unsigned char cdb[32]; 63 | unsigned char buf[16*1024]; 64 | unsigned cdb_len = cdb_receive_diagnostics(cdb, true, 0, sizeof(buf)); 65 | 66 | printf("List all supported pages\n"); 67 | bool ret = submit_cmd(fd, cdb, cdb_len, buf, sizeof(buf), SG_DXFER_FROM_DEV); 68 | if (!ret) { 69 | fprintf(stderr, "Failed to submit command\n"); 70 | return; 71 | } 72 | 73 | unsigned char *sense = NULL; 74 | unsigned sense_len = 0; 75 | unsigned buf_len = 0; 76 | ret = read_response_buf(fd, &sense, &sense_len, &buf_len); 77 | 78 | if (sense) { 79 | printf("error while reading response buffer, nothing to show\n"); 80 | return; 81 | } 82 | 83 | printf("Read %u bytes\n", buf_len); 84 | response_dump(buf, buf_len); 85 | 86 | if (buf_len < RECV_DIAG_MIN_LEN) { 87 | printf("receive diagnostics list must have at least 4 bytes\n"); 88 | return; 89 | } 90 | 91 | if (recv_diag_get_page_code(buf) != 0) { 92 | printf("expected to receive receive diagnostics page 0\n"); 93 | return; 94 | } 95 | 96 | uint16_t num_pages = recv_diag_get_len(buf); 97 | uint16_t i; 98 | for (i = 0; i < num_pages; i++) { 99 | dump_page(fd, buf[4 + i]); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /libscsicmd/test/sense_decode.c: -------------------------------------------------------------------------------- 1 | #include "sense_dump.h" 2 | #include 3 | #include 4 | 5 | int main(int argc, char **argv) 6 | { 7 | unsigned char sense[256]; 8 | int sense_len = 0; 9 | 10 | printf("Reading sense from args to buffer...\n"); 11 | int i; 12 | bool is_top_nibble = true; 13 | for (i = 1; i < argc; i++) { 14 | char *ch; 15 | 16 | for (ch = argv[i]; *ch != 0; ch++) { 17 | unsigned char val; 18 | if (*ch >= '0' && *ch <= '9') 19 | val = (*ch) - '0'; 20 | else if (*ch >= 'a' && *ch <= 'f') 21 | val = (*ch) - 'a' + 0xa; 22 | else if (*ch >= 'A' && *ch <= 'F') 23 | val = (*ch) - 'A' + 0xA; 24 | else if (*ch == ' ' || *ch == '+' || *ch == '\t') { 25 | continue; 26 | } else { 27 | fprintf(stderr, "\n\nInvalid character '%c' (%d) in sequence\n", *ch, *ch); 28 | return 1; 29 | } 30 | 31 | if (is_top_nibble) { 32 | sense[sense_len] = val<<4; 33 | is_top_nibble = false; 34 | } else { 35 | sense[sense_len] |= val; 36 | is_top_nibble = true; 37 | sense_len++; 38 | } 39 | } 40 | } 41 | 42 | if (!is_top_nibble) { 43 | fprintf(stderr, "Missing a nibble!\n"); 44 | return 2; 45 | } 46 | 47 | printf("Decoding sense...\n"); 48 | sense_dump(sense, sense_len); 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /libscsicmd/test/sense_dump.h: -------------------------------------------------------------------------------- 1 | #ifndef _SENSE_DUMP_H 2 | #define _SENSE_DUMP_H 3 | 4 | void sense_dump(unsigned char *sense, int sense_len); 5 | void response_dump(unsigned char *buf, int buf_len); 6 | void cdb_dump(unsigned char *cdb, int cdb_len); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /progressbar/.gitignore: -------------------------------------------------------------------------------- 1 | demo 2 | doc/ 3 | *~ 4 | *.o 5 | *.so 6 | *.a 7 | *.swp 8 | -------------------------------------------------------------------------------- /progressbar/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010, Trevor Fountain 2 | Copyright (c) 2014, Johannes Buchner 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | * Neither the name of software nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 10 | 11 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 12 | -------------------------------------------------------------------------------- /progressbar/Makefile: -------------------------------------------------------------------------------- 1 | EXECUTABLE = demo 2 | SHARED_LIB = libprogressbar.so 3 | STATIC_LIB = libprogressbar.a 4 | 5 | SRC=lib 6 | INCLUDE=include 7 | TEST=test 8 | CFLAGS += -std=c99 -I$(INCLUDE) -Wimplicit-function-declaration -Wall -Wextra -pedantic 9 | CFLAGS_DEBUG = -g -O0 10 | LDLIBS = -lncurses 11 | 12 | all: $(EXECUTABLE) $(SHARED_LIB) $(STATIC_LIB) 13 | 14 | debug: CFLAGS += $(CFLAGS_DEBUG) 15 | debug: $(EXECUTABLE) 16 | 17 | doc: include/progressbar.h include/statusbar.h 18 | mkdir -p doc 19 | doxygen 20 | 21 | $(EXECUTABLE): $(EXECUTABLE).o progressbar.o statusbar.o 22 | 23 | libprogressbar.so: $(INCLUDE)/progressbar.h $(SRC)/progressbar.c 24 | $(CC) -fPIC -shared -o $@ -c $(CFLAGS) $(CPPFLAGS) $(SRC)/progressbar.c 25 | 26 | libprogressbar.a: libprogressbar.a(progressbar.o) 27 | 28 | %.o: $(SRC)/%.c $(INCLUDE)/%.h 29 | $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@ 30 | 31 | demo.o: CFLAGS += -std=gnu99 # Demo uses usleep which requires POSIX or BSD source 32 | demo.o: $(TEST)/demo.c 33 | $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o demo.o 34 | 35 | .PHONY: clean 36 | clean: 37 | rm -f *.o $(EXECUTABLE) $(SHARED_LIB) $(STATIC_LIB) 38 | rm -rf doc 39 | -------------------------------------------------------------------------------- /progressbar/README.mdown: -------------------------------------------------------------------------------- 1 | ## What is this thing? 2 | 3 | progressbar is a C-class (it's a convention, dammit) for displaying attractive 4 | progress bars on the command line. It's heavily influenced by the ruby ProgressBar 5 | gem, whose api and behaviour it imitates. 6 | 7 | ## Ok, what the hell is a C-class, and how do I use one? 8 | 9 | progressbar is implemented in pure C99, but using a vaguely object-oriented convention. 10 | 11 | Example usage: 12 | 13 | progressbar *progress = progressbar_new("Loading",100); 14 | for(int i=0; i < 100; i++) 15 | { 16 | // Do some stuff 17 | progressbar_inc(progress); 18 | } 19 | progressbar_finish(progress); 20 | 21 | Example output (from `progressbar_demo.c`): 22 | 23 | ![demo output](example_output/demo.png) 24 | 25 | Additional examples can be found in `test/progressbar_demo.c` 26 | 27 | ## Why did you do this? 28 | 29 | One of the things I miss most when I'm writing C instead of Ruby is the 30 | how ridiculously easy it is to write user-friendly, informative CLI apps 31 | in Ruby. A big part of that, at least for me, is the ProgressBar gem -- 32 | and since most of the time when I'm writing C I'm doing so because I need 33 | a tool to handle some long-running, processor-intensive task, I'd really 34 | like to have a way of seeing at a glance how much time is remaining and 35 | how far along we've gotten. Enter progressbar! 36 | 37 | ## Can I use it? 38 | 39 | Of course, if you're so inclined. progressbar is licensed under a simplified BSD license, 40 | so feel free to take it and run with it. Details can be found in the `LICENSE` file. 41 | 42 | ## Why doesn't it compile? 43 | 44 | If progressbar fails to build because `termcap.h` isn't found, you're probably missing the ncurses dev libraries. 45 | 46 | gcc -c -std=c99 -Iinclude lib/progressbar.c 47 | lib/progressbar.c:13:45: fatal error: termcap.h: No such file or directory 48 | compilation terminated. 49 | -------------------------------------------------------------------------------- /progressbar/example_output/demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baruch/diskscan/4773146060a1696c52c880ce65410dad2f861c08/progressbar/example_output/demo.png -------------------------------------------------------------------------------- /progressbar/example_output/demo@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baruch/diskscan/4773146060a1696c52c880ce65410dad2f861c08/progressbar/example_output/demo@2x.png -------------------------------------------------------------------------------- /progressbar/include/progressbar.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \author Trevor Fountain 4 | * \author Johannes Buchner 5 | * \author Erik Garrison 6 | * \date 2010-2014 7 | * \copyright BSD 3-Clause 8 | * 9 | * progressbar -- a C class (by convention) for displaying progress 10 | * on the command line (to stderr). 11 | */ 12 | 13 | #ifndef PROGRESSBAR_H 14 | #define PROGRESSBAR_H 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | /** 22 | * Progressbar data structure (do not modify or create directly) 23 | */ 24 | typedef struct _progressbar_t 25 | { 26 | /// maximum value 27 | unsigned long max; 28 | /// current value 29 | unsigned long value; 30 | 31 | /// time progressbar was started 32 | time_t start; 33 | 34 | /// label 35 | const char *label; 36 | 37 | /// characters for the beginning, filling and end of the 38 | /// progressbar. E.g. |### | has |#| 39 | struct { 40 | char begin; 41 | char fill; 42 | char end; 43 | } format; 44 | } progressbar; 45 | 46 | /// Create a new progressbar with the specified label and number of steps. 47 | /// 48 | /// @param label The label that will prefix the progressbar. 49 | /// @param max The number of times the progressbar must be incremented before it is considered complete, 50 | /// or, in other words, the number of tasks that this progressbar is tracking. 51 | /// 52 | /// @return A progressbar configured with the provided arguments. Note that the user is responsible for disposing 53 | /// of the progressbar via progressbar_finish when finished with the object. 54 | progressbar *progressbar_new(const char *label, unsigned long max); 55 | 56 | /// Create a new progressbar with the specified label, number of steps, and format string. 57 | /// 58 | /// @param label The label that will prefix the progressbar. 59 | /// @param max The number of times the progressbar must be incremented before it is considered complete, 60 | /// or, in other words, the number of tasks that this progressbar is tracking. 61 | /// @param format The format of the progressbar. The string provided must be three characters, and it will 62 | /// be interpretted with the first character as the left border of the bar, the second 63 | /// character of the bar and the third character as the right border of the bar. For example, 64 | /// "<->" would result in a bar formatted like "<------ >". 65 | /// 66 | /// @return A progressbar configured with the provided arguments. Note that the user is responsible for disposing 67 | /// of the progressbar via progressbar_finish when finished with the object. 68 | progressbar *progressbar_new_with_format(const char *label, unsigned long max, const char *format); 69 | 70 | /// Free an existing progress bar. Don't call this directly; call *progressbar_finish* instead. 71 | void progressbar_free(progressbar *bar); 72 | 73 | /// Increment the given progressbar. Don't increment past the initialized # of steps, though. 74 | void progressbar_inc(progressbar *bar); 75 | 76 | /// Set the current status on the given progressbar. 77 | void progressbar_update(progressbar *bar, unsigned long value); 78 | 79 | /// Set the label of the progressbar. Note that no rendering is done. The label is simply set so that the next 80 | /// rendering will use the new label. To immediately see the new label, call progressbar_draw. 81 | /// Does not update display or copy the label 82 | void progressbar_update_label(progressbar *bar, const char *label); 83 | 84 | /// Finalize (and free!) a progressbar. Call this when you're done, or if you break out 85 | /// partway through. 86 | void progressbar_finish(progressbar *bar); 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /progressbar/include/statusbar.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \author Trevor Fountain 4 | * \author Johannes Buchner 5 | * \author Erik Garrison 6 | * \date 2010-2014 7 | * \copyright BSD 3-Clause 8 | * 9 | * statusbar -- a C class (by convention) for displaying indefinite progress 10 | * on the command line (to stderr). 11 | */ 12 | 13 | #ifndef STATUSBAR_H 14 | #define STATUSBAR_H 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | /** 22 | * Statusbar data structure (do not modify or create directly) 23 | */ 24 | typedef struct _statusbar_t 25 | { 26 | unsigned int start_time; 27 | const char *label; 28 | int format_index; 29 | int format_length; 30 | char *format; 31 | int last_printed; 32 | } statusbar; 33 | 34 | /// Create a new statusbar with the specified label and format string 35 | statusbar *statusbar_new_with_format(const char *label, const char *format); 36 | 37 | /// Create a new statusbar with the specified label 38 | statusbar *statusbar_new(const char *label); 39 | 40 | /// Free an existing progress bar. Don't call this directly; call *statusbar_finish* instead. 41 | void statusbar_free(statusbar *bar); 42 | 43 | /// Increment the given statusbar. 44 | void statusbar_inc(statusbar *bar); 45 | 46 | /// Finalize (and free!) a statusbar. Call this when you're done. 47 | void statusbar_finish(statusbar *bar); 48 | 49 | /// Draw a statusbar to the screen. Don't call this directly, 50 | /// as it's called internally by *statusbar_inc*. 51 | void statusbar_draw(statusbar *bar); 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /progressbar/lib/statusbar.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \author Trevor Fountain 4 | * \author Johannes Buchner 5 | * \author Erik Garrison 6 | * \date 2010-2014 7 | * \copyright BSD 3-Clause 8 | * 9 | * statusbar -- a C class (by convention) for displaying progress 10 | * on the command line (to stderr). 11 | */ 12 | #include "statusbar.h" 13 | 14 | statusbar *statusbar_new_with_format(const char *label, const char *format) 15 | { 16 | statusbar *new = malloc(sizeof(statusbar)); 17 | new->label = label; 18 | new->start_time = time(0); 19 | new->format_length = strlen(format); 20 | new->format = malloc( sizeof(char) * (new->format_length + 1) ); 21 | strncpy(new->format, format, new->format_length); 22 | new->format_index = 0; 23 | new->last_printed = 0; 24 | 25 | return new; 26 | } 27 | 28 | statusbar *statusbar_new(const char *label) 29 | { 30 | return statusbar_new_with_format(label, "-\\|/"); 31 | } 32 | 33 | void statusbar_free(statusbar *bar) 34 | { 35 | // We malloc'd a string, so let's be sure to free it... 36 | free(bar->format); 37 | // ...before we free the struct itself. 38 | free(bar); 39 | 40 | return; 41 | } 42 | 43 | void statusbar_inc(statusbar *bar) 44 | { 45 | bar->format_index++; 46 | if (bar->format_index >= bar->format_length) { 47 | bar->format_index = 0; 48 | } 49 | statusbar_draw(bar); 50 | 51 | return; 52 | } 53 | 54 | void statusbar_draw(statusbar *bar) 55 | { 56 | // Erase the last draw. If anything else has been printed to stderr, 57 | // things are going to look mighty interesting... 58 | for(int i=0; i < bar->last_printed; i++) { 59 | fprintf(stderr,"\b"); 60 | } 61 | 62 | fprintf( 63 | stderr, 64 | "%s: %c%n", 65 | bar->label, 66 | bar->format[bar->format_index], 67 | &(bar->last_printed) 68 | ); 69 | 70 | return; 71 | } 72 | 73 | void statusbar_finish(statusbar *bar) 74 | { 75 | // Draw one more time, with the actual time to completion. 76 | unsigned int offset = time(0) - (bar->start_time); 77 | 78 | // Convert the time to display into HHH:MM:SS 79 | unsigned int h = offset/3600; 80 | offset -= h*3600; 81 | unsigned int m = offset/60; 82 | offset -= m*60; 83 | unsigned int s = offset; 84 | 85 | // Erase the last draw 86 | for(int i=0; i < bar->last_printed; i++) { 87 | fprintf(stderr,"\b"); 88 | } 89 | 90 | // Calculate number of spaces for right-justified time to completion 91 | fprintf(stderr,"%s: %3d:%02d:%02d%n",bar->label,h,m,s,&(bar->last_printed)); 92 | for(int i=0; i < bar->last_printed; i++) { 93 | fprintf(stderr,"\b"); 94 | } 95 | 96 | // Print right-justified 97 | fprintf(stderr,"%s: ",bar->label); 98 | for(int i=0; i < (80 - (bar->last_printed)); i++) { 99 | fprintf(stderr," "); 100 | } 101 | fprintf(stderr,"%3d:%02d:%02d\n",h,m,s); 102 | 103 | // We've finished with this statusbar, so go ahead and free it. 104 | statusbar_free(bar); 105 | 106 | return; 107 | } 108 | -------------------------------------------------------------------------------- /progressbar/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "progressbar", 3 | "version": "0.1.0", 4 | "repo": "doches/progressbar", 5 | "description": "A C library for displaying command-line progress bars", 6 | "keywords": ["terminal", "tty", "progress", "progressbar", "statusbar", "console"], 7 | "license": "BSD", 8 | "src": ["include/progressbar.h", "include/progressbar.c", "include/statusbar.h", "include/statusbar.c"] 9 | } 10 | -------------------------------------------------------------------------------- /progressbar/test/demo.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file 3 | * \mainpage Progressbar and Statusbar -- Continuous console status updates 4 | * 5 | * \section Progressbar 6 | * Creating and starting the progress bar: \ref progressbar_new 7 | * 8 | * Updating the current progress: \ref progressbar_update, \ref progressbar_inc, \ref progressbar_update_label 9 | * 10 | * Finishing the progressbar (on success or failure): \ref progressbar_finish 11 | * 12 | * \section Statusbar 13 | * 14 | * Creating and starting the status bar: \ref statusbar_new 15 | * 16 | * Updating the current progress: \ref statusbar_inc 17 | * 18 | * Finishing the progressbar (on success or failure): \ref statusbar_finish 19 | * 20 | * \section Example Example Code 21 | * See \ref main in progressbar_demo.c 22 | * 23 | * Download the code from the repository at https://github.com/JohannesBuchner/progressbar 24 | * 25 | * \author Trevor Fountain 26 | * \author Johannes Buchner 27 | * \author Erik Garrison 28 | * \date 2010-2014 29 | * \copyright BSD 3-Clause 30 | * 31 | * 32 | **/ 33 | 34 | #include "progressbar.h" 35 | #include "statusbar.h" 36 | #include 37 | 38 | #define SLEEP_US 100000 39 | 40 | /** 41 | *Example for statusbar and progressbar usage 42 | **/ 43 | int main(void) 44 | { 45 | // Progress bar 46 | int max = 60; 47 | progressbar *smooth = progressbar_new("Smooth",max); 48 | for(int i=0; i < max; i++) { 49 | usleep(SLEEP_US); 50 | progressbar_inc(smooth); 51 | } 52 | progressbar_finish(smooth); 53 | 54 | progressbar *longlabel = progressbar_new("Three Second Task with a long label",3); 55 | for(int i=0; i < 3; i++) { 56 | progressbar_inc(longlabel); 57 | sleep(1); 58 | } 59 | progressbar_finish(longlabel); 60 | 61 | progressbar *fast = progressbar_new("Fast",20); 62 | for(int i=0; i < 20; i++) { 63 | usleep(SLEEP_US); 64 | progressbar_inc(fast); 65 | } 66 | progressbar_finish(fast); 67 | 68 | progressbar *custom = progressbar_new_with_format("Custom",max,"<.>"); 69 | for(int i=0; i < max; i++) { 70 | usleep(SLEEP_US); 71 | progressbar_inc(custom); 72 | } 73 | progressbar_finish(custom); 74 | 75 | // Status bar 76 | statusbar *status = statusbar_new("Indeterminate"); 77 | for(int i=0; i < 30; i++) { 78 | usleep(SLEEP_US); 79 | statusbar_inc(status); 80 | } 81 | statusbar_finish(status); 82 | 83 | statusbar *longStatus = statusbar_new("Status bar with a really long label"); 84 | for(int i=0; i < 10; i++) { 85 | usleep(SLEEP_US); 86 | statusbar_inc(longStatus); 87 | } 88 | statusbar_finish(longStatus); 89 | 90 | statusbar *customStatus = statusbar_new_with_format("Custom","(|)|"); 91 | for(int i=0; i < 30; i++) { 92 | usleep(SLEEP_US); 93 | statusbar_inc(customStatus); 94 | } 95 | statusbar_finish(customStatus); 96 | } 97 | --------------------------------------------------------------------------------