pax_global_header 0000666 0000000 0000000 00000000064 13150074536 0014516 g ustar 00root root 0000000 0000000 52 comment=6984540eed21b6a2e03a46e67a61f67b583f2004
diskscan-0.20/ 0000775 0000000 0000000 00000000000 13150074536 0013236 5 ustar 00root root 0000000 0000000 diskscan-0.20/.gitignore 0000664 0000000 0000000 00000000225 13150074536 0015225 0 ustar 00root root 0000000 0000000 *.o
*.a
*.d
diskscan
arch/arch.c
include/arch-internal.h
arch/arch.id
*~
CMakeCache.txt
CMakeFiles
cmake_install.cmake
install_manifest.txt
Makefile
diskscan-0.20/.travis.yml 0000664 0000000 0000000 00000001407 13150074536 0015351 0 ustar 00root root 0000000 0000000 language: c
install:
- wget https://s3.amazonaws.com/biibinaries/thirdparty/cmake-3.0.2-Linux-64.tar.gz
- tar -xzf cmake-3.0.2-Linux-64.tar.gz
- sudo cp -fR cmake-3.0.2-Linux-64/* /usr
- rm -rf cmake-3.0.2-Linux-64
- rm cmake-3.0.2-Linux-64.tar.gz
script:
- cmake --version
- mkdir build
- cd build
- cmake ..
- make VERBOSE=1
sudo: true
addons:
apt:
packages:
- python-yaml
- libtinfo-dev
compiler:
- gcc
#- clang
notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/fccf07549cf55d00de5d
on_success: change # options: [always|never|change] default: always
on_failure: always # options: [always|never|change] default: always
on_start: never # options: [always|never|change] default: always
diskscan-0.20/CMakeLists.txt 0000664 0000000 0000000 00000005432 13150074536 0016002 0 ustar 00root root 0000000 0000000 cmake_minimum_required(VERSION 3.0.2)
project(diskscan
VERSION 0.19)
export(PACKAGE diskscan)
set(PACKAGE_VERSION ${PROJECT_VERSION})
# Default to a debug build
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif(NOT CMAKE_BUILD_TYPE)
# Pull in zlib
find_package(ZLIB REQUIRED)
# Ensure clock_gettime can build with or without -lrt as needed
include(CheckLibraryExists)
CHECK_LIBRARY_EXISTS(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME)
if (NOT HAVE_CLOCK_GETTIME)
set(CMAKE_EXTRA_INCLUDE_FILES time.h)
CHECK_FUNCTION_EXISTS(clock_gettime HAVE_CLOCK_GETTIME)
SET(CMAKE_EXTRA_INCLUDE_FILES)
else()
list(APPEND LIBS rt)
endif()
# Find tinfo for termcap functions
INCLUDE (CheckIncludeFiles)
CHECK_INCLUDE_FILES(termcap.h HAVE_TERMCAP_H)
find_library(tinfo_LIBRARY NAMES tinfo curses)
# Architecture files
message("SYSTEM NAME: ${CMAKE_SYSTEM_NAME}")
if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(ARCH_SRC "arch/arch-linux.c")
set(ARCH_INCLUDE "arch/arch-linux.h")
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "kFreeBSD")
set(ARCH_SRC "arch/arch-freebsd.c")
set(ARCH_INCLUDE "arch/arch-posix.h")
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
set(ARCH_SRC "arch/arch-freebsd.c")
set(ARCH_INCLUDE "arch/arch-posix.h")
else()
set(ARCH_SRC "arch/arch-generic.c")
set(ARCH_INCLUDE "arch/arch-posix.h")
endif()
add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/include/arch-internal.h
COMMAND ln -fs ${CMAKE_CURRENT_SOURCE_DIR}/${ARCH_INCLUDE} ${CMAKE_CURRENT_SOURCE_DIR}/include/arch-internal.h
)
# Build diskscan
include_directories("include")
add_compile_options(-Wall -Wextra -Wshadow -Wmissing-prototypes -Winit-self)
add_definitions(-D_GNU_SOURCE -D_FORTIFY_SOURCE=2)
add_definitions(-DVERSION="${PROJECT_VERSION}")
include_directories(.)
include_directories(progressbar/include)
# Build libscsicmd for diskscan
include_directories(libscsicmd/include)
add_subdirectory(libscsicmd/src)
# Build diskscan library
add_library(diskscanlib STATIC lib/data.c lib/diskscan.c lib/sha1.c lib/system_id.c lib/verbose.c lib/disk.c
hdrhistogram/src/hdr_histogram.c hdrhistogram/src/hdr_histogram_log.c
hdrhistogram/src/hdr_encoding.c ${ARCH_SRC} ${CMAKE_CURRENT_SOURCE_DIR}/include/arch-internal.h)
add_dependencies(diskscanlib scsicmd)
# Build diskscan cli command
add_executable(diskscan diskscan.c cli/cli.c cli/verbose.c progressbar/lib/progressbar.c)
target_link_libraries(diskscan diskscanlib scsicmd m ${tinfo_LIBRARY} ${ZLIB_LIBRARIES} ${LIBS})
install(TARGETS diskscan
RUNTIME DESTINATION bin)
configure_file(Documentation/diskscan.1.in Documentation/diskscan.1)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/Documentation/diskscan.1
DESTINATION share/man/man1 COMPONENT doc)
diskscan-0.20/COPYING 0000664 0000000 0000000 00000104513 13150074536 0014275 0 ustar 00root root 0000000 0000000 GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
diskscan-0.20/DEVELOP.md 0000664 0000000 0000000 00000000764 13150074536 0014665 0 ustar 00root root 0000000 0000000 # Developing
## Debug build
To create a debug build you can tell cmake:
cmake -DCMAKE_BUILD_TYPE=DEBUG .
## Updating Libraries
Update libscsicmd:
git subtree pull --squash --prefix libscsicmd https://github.com/baruch/libscsicmd master
Update libprogressbar:
git subtree pull --squash --prefix progressbar https://github.com/doches/progressbar master
Update HdrHistogram:
git subtree pull --squash --prefix hdrhistogram https://github.com/HdrHistogram/HdrHistogram_c master
diskscan-0.20/Documentation/ 0000775 0000000 0000000 00000000000 13150074536 0016047 5 ustar 00root root 0000000 0000000 diskscan-0.20/Documentation/.gitignore 0000664 0000000 0000000 00000000005 13150074536 0020032 0 ustar 00root root 0000000 0000000 /*.1
diskscan-0.20/Documentation/diskscan.1.in 0000664 0000000 0000000 00000005427 13150074536 0020345 0 ustar 00root root 0000000 0000000 .TH DISKSCAN 1 2013-10-25 "DiskScan @PACKAGE_VERSION@" "User Commands"
.ad l
.nh
.SH NAME
diskscan - scan a disk for failed and near failure sectors
.SH SYNOPSIS
\fBdiskscan\fR [options...] \fIblock_device\fR
.SH DESCRIPTION
\fBdiskscan\fR is intended to check a disk and find any bad sectors already present
and assess it for any possible sectors that are in the process of going bad.
The operation is all read-only and can cause no direct damage to the data on
the disk.
.PP
diskscan reads the entire block device and notes the time it took to read a
block. When there is an error it is immediately noted and also when there is a
higher latency to read a block. A histogram of the block latency times is also
given to assess the health of the disk.
.PP
The output of diskscan will show any serious errors or very high latency and
will also emit an histogram at the end of the run in the form:
.RS +4n
.nf
.PP
I: Validating path /dev/sdg
I: Opened disk /dev/sdg
I: Scanning disk /dev/sdg
Access time histogram:
1: 0
10: 0
100: 0
500: 120
1000: 0
2000: 1
3000: 0
4000: 0
5000: 0
6000: 0
7000: 0
8000: 0
9000: 0
10000: 0
15000: 0
20000: 0
25000: 0
30000: 0
above that: 0
I: Closed disk /dev/sdg
.fi
.RE
.PP
This means that all I/Os in this case were between 100 and 600 msec and there
were 120 chunks being read. Current these chunks are 1MB in size.
.SH OPTIONS
\fB-v\fR, \fB--verbose\fR
display verbose information from the workings of the scan
use multiple times for increased verbosity.
.PP
\fB-f\fR, \fB--fix\fR
Attempt to fix areas that are nearing failure. This should only be
attempted on an unmounted block device and never on an inuse filesystem or
corruption is likely.
.PP
\fB-s \fR, \fB--scan \fR
Scan mode can be either \fBseq\fR or \fBrandom\fR, random reduces the chance that the
disk will be able spend time to recover data before we try to access a sector
but the seeks add noise to the latency measurement. Sequential test is the
default and random test is still experimental with regard to its usefulness.
.PP
\fB-e \fR, \fB--size \fR
Set the size in which the scan will be done, this must be a multiple of the sector size
which is normally 512 bytes.
.PP
\fB-o \fR, \fB--output \fR
Set the output file that the scan will generate. This is a JSON file with the
summary and details about the exceptional events found during the scan.
.PP
\fB-r \fR, \fB--raw-log \fR
Set the output file for the raw log which logs everything done and seen during
the scan. This is a rather large file but it can help get the finer details of
the scan progress and the disk behavior during the scan. This is too a JSON file.
.SH "SEE ALSO"
\fBbadblocks\fR(1), \fBfsck\fR(1)
.SH AUTHOR
Baruch Even \\
diskscan-0.20/README.md 0000664 0000000 0000000 00000004175 13150074536 0014524 0 ustar 00root root 0000000 0000000 # DiskScan -- Scan HDD/SSD for failed and near failed sectors
[](https://travis-ci.org/baruch/diskscan)
[](https://gitter.im/baruch/diskscan?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
DiskScan is a Unix/Linux tool to scan a block device and check if there are
unreadable sectors, in addition it uses read latency times as an assessment for
a near failure as sectors that are problematic to read usually entail many
retries. This can be used to assess the state of the disk and maybe decide on a
replacement in advance to its imminent failure. The disk self test may or may
not pick up on such clues depending on the disk vendor decision making logic.
## diskscan vs. badblocks
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.
In essence badblocks looks for fatal issues already happening and diskscan is for upcoming issues that can be fixed.
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.
## Build
This project is using CMake, on Debian/Ubuntu it is as simple as:
apt-get install cmake make libtinfo-dev libncurses5-dev zlib1g-dev python-yaml
For RedHat/SuSe based distros you need to install ninja-build first and then:
yum install compat-libtermcap libtermcap-devel cmake python-yaml zlib-devel
A Makefile is provided to avoid learning the ninja commands and do the non-build stuff (install, etc.)
To do the build:
cmake . && make
## Install
make install
You can control the DESTDIR when building packages and PREFIX if /usr is not right.
## License
diskscan is licensed under the GPL version 3 or later.
diskscan-0.20/arch/ 0000775 0000000 0000000 00000000000 13150074536 0014153 5 ustar 00root root 0000000 0000000 diskscan-0.20/arch/arch-freebsd.c 0000664 0000000 0000000 00000004521 13150074536 0016646 0 ustar 00root root 0000000 0000000 #include "arch.h"
#include
#include
#include
#include
#include
#include
#include "arch-posix.c"
#include
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)
{
(void)dev;
strcpy(vendor, "UNKNOWN");
strcpy(model, "UNKNOWN");
strcpy(fw_rev, "UNKN");
strcpy(serial, "UNKNOWN");
*is_ata = 0;
*ata_buf_len = 0;
*ata_buf = 0;
return 0;
}
int disk_dev_read_cap(disk_dev_t *dev, uint64_t *size_bytes, uint64_t *sector_size)
{
if (ioctl(dev->fd, DIOCGMEDIASIZE, size_bytes) < 0) {
return -1;
}
if (ioctl(dev->fd, DIOCGSECTORSIZE, sector_size) < 0) {
return -1;
}
return 0;
}
disk_mount_e disk_dev_mount_state(const char *path)
{
int num_mounts;
struct statfs *mntbuf;
disk_mount_e last_state;
int i;
num_mounts = getmntinfo(&mntbuf, MNT_WAIT);
if (num_mounts == 0) {
ERROR("Failed to get the mount information, errno=%d", errno);
return DISK_MOUNTED_RW;
}
last_state = DISK_NOT_MOUNTED;
for (i = 0; i < num_mounts; i++) {
struct statfs *mnt = &mntbuf[i];
if (strncmp(path, mnt->f_mntfromname, strlen(path)) == 0) {
disk_mount_e cur_state = DISK_NOT_MOUNTED;
if (mnt->f_flags == MNT_RDONLY)
cur_state = DISK_MOUNTED_RO;
else
cur_state = DISK_MOUNTED_RW;
if (cur_state > last_state)
last_state = cur_state;
}
}
return last_state;
}
void mac_read(unsigned char *buf, int len)
{
struct ifreq ifr;
struct ifconf ifc;
char data[1024];
int success = 0;
buf[0] = 0;
int sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock == -1) {
return;
};
ifc.ifc_len = sizeof(data);
ifc.ifc_buf = data;
if (ioctl(sock, SIOCGIFCONF, &ifc) == -1) {
/* handle error */
goto Exit;
}
struct ifreq* it = ifc.ifc_req;
const struct ifreq* const end = it + (ifc.ifc_len / sizeof(struct ifreq));
for (; it != end; ++it) {
strcpy(ifr.ifr_name, it->ifr_name);
if (ioctl(sock, SIOCGIFFLAGS, &ifr) == 0) {
if (! (ifr.ifr_flags & IFF_LOOPBACK)) { // don't count loopback
if (ioctl(sock, SIOCGIFMAC, &ifr) == 0) {
success = 1;
break;
}
}
}
else { /* handle error */ }
}
if (success) {
memcpy(buf, ifr.ifr_ifru.ifru_data, len >= 6 ? 6 : len);
} else {
memset(buf, 0, len);
}
Exit:
close(sock);
}
diskscan-0.20/arch/arch-generic.c 0000664 0000000 0000000 00000001317 13150074536 0016650 0 ustar 00root root 0000000 0000000 #include "arch.h"
#include
#include
#include "arch-posix.c"
int disk_dev_read_cap(disk_dev_t *dev, uint64_t *size_bytes, uint64_t *sector_size)
{
off_t end = lseek(dev->fd, 0, SEEK_END);
if (end == (off_t)-1)
return -1;
*size_bytes = end;
*sector_size = 512;
return 0;
}
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)
{
(void)dev;
strcpy(vendor, "UNKNOWN");
strcpy(model, "UNKNOWN");
strcpy(fw_rev, "UNKN");
strcpy(serial, "UNKNOWN");
*is_ata = 0;
*ata_buf_len = 0;
*ata_buf = 0;
return 0;
}
void mac_read(unsigned char *buf, int len)
{
(void)len;
*buf = 0;
}
diskscan-0.20/arch/arch-linux.c 0000664 0000000 0000000 00000035435 13150074536 0016403 0 ustar 00root root 0000000 0000000 #include "arch.h"
#include "libscsicmd/include/scsicmd.h"
#include "libscsicmd/include/ata.h"
#include "libscsicmd/include/ata_parse.h"
#include "verbose.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define LONG_TIMEOUT (60*1000) // 1 minutes
#define SHORT_TIMEOUT (5*1000) // 5 seconds
static void strtrim(char *s)
{
char *t;
// Skip initial spaces
for (t = s; *t && isspace(*t); t++)
;
if (t != s) {
// Copy content to start
while (*t && !isspace(*t)) {
*s++ = *t++;
}
*s = 0;
} else {
while (*t && !isspace(*t))
t++;
*t = 0;
}
}
static enum result_error_e sense_to_error(sense_info_t *info)
{
// TODO: May need a more granular decision based on asc/ascq
switch (info->sense_key) {
case SENSE_KEY_NO_SENSE:
return ERROR_NONE;
case SENSE_KEY_RECOVERED_ERROR:
return ERROR_CORRECTED;
case SENSE_KEY_MEDIUM_ERROR:
return ERROR_UNCORRECTED;
case SENSE_KEY_UNIT_ATTENTION:
case SENSE_KEY_NOT_READY:
case SENSE_KEY_ABORTED_COMMAND:
return ERROR_NEED_RETRY;
case SENSE_KEY_HARDWARE_ERROR:
case SENSE_KEY_ILLEGAL_REQUEST:
case SENSE_KEY_DATA_PROTECT:
case SENSE_KEY_BLANK_CHECK:
case SENSE_KEY_VENDOR_SPECIFIC:
case SENSE_KEY_COPY_ABORTED:
case SENSE_KEY_RESERVED_C:
case SENSE_KEY_VOLUME_OVERFLOW:
case SENSE_KEY_MISCOMPARE:
case SENSE_KEY_COMPLETED:
return ERROR_FATAL;
}
ERROR("BUG: Cannot translate sense 0x%02X to error code", info->sense_key);
return ERROR_UNKNOWN;
}
static const char *host_status_to_str(int host_status)
{
switch (host_status) {
case 0x00: return "DID_OK: No error";
case 0x01: return "DID_NO_CONNECT: Couldn't connect before timeout period";
case 0x02: return "DID_BUS_BUSY: BUS stayed busy through time out period";
case 0x03: return "DID_TIME_OUT: TIMED OUT for other reason";
case 0x04: return "DID_BAD_TARGET: BAD target";
case 0x05: return "DID_ABORT: Told to abort for some other reason";
case 0x06: return "DID_PARITY: Parity error";
case 0x07: return "DID_ERROR: internal error";
case 0x08: return "DID_RESET: Reset by somebody";
case 0x09: return "DID_BAD_INTR: Got an interrupt we weren't expecting";
default: return "Unknown host status";
}
}
static const char *driver_status_low_to_str(int driver_status)
{
switch (driver_status) {
case 0x00: return "DRIVER_OK: No error";
case 0x01: return "DRIVER_BUSY: not used";
case 0x02: return "DRIVER_SOFT: not used";
case 0x03: return "DRIVER_MEDIA: not used";
case 0x04: return "DRIVER_ERROR: internal driver error";
case 0x05: return "DRIVER_INVALID: finished (DID_BAD_TARGET or DID_ABORT)";
case 0x06: return "DRIVER_TIMEOUT: finished with timeout";
case 0x07: return "DRIVER_HARD: finished with fatal error";
case 0x08: return "DRIVER_SENSE: had sense information available";
default: return "Unknown driver status";
}
}
static const char *driver_status_high_to_str(int driver_status)
{
switch (driver_status) {
case 0: return "No suggestion";
case 0x10: return "SUGGEST_RETRY: retry the SCSI request";
case 0x20: return "SUGGEST_ABORT: abort the request";
case 0x30: return "SUGGEST_REMAP: remap the block (not yet implemented)";
case 0x40: return "SUGGEST_DIE: let the kernel panic";
case 0x80: return "SUGGEST_SENSE: get sense information from the device";
case 0xff: return "SUGGEST_IS_OK: nothing to be done";
default: return "Unknown suggestion";
}
}
static const char *status_code_to_str(int status)
{
switch (status) {
case 0x00: return "GOOD";
case 0x01: return "CHECK_CONDITION";
case 0x02: return "CONDITION_GOOD";
case 0x04: return "BUSY";
case 0x08: return "INTERMEDIATE_GOOD";
case 0x0a: return "INTERMEDIATE_C_GOOD";
case 0x0c: return "RESERVATION_CONFLICT";
default: return "Unknown status";
}
}
static const char *driver_status_to_str(int driver_status)
{
static char buf[256];
snprintf(buf, sizeof(buf), "%s %s",
driver_status_low_to_str(driver_status & 0x0F),
driver_status_high_to_str(driver_status & 0xF0));
return buf;
}
static int sg_ioctl(int fd, unsigned char *cdb, unsigned cdb_len,
unsigned char *buf, unsigned buf_len,
int dxfer_direction, unsigned timeout,
unsigned char *sense, unsigned sense_len,
unsigned *buf_read, unsigned *sense_read,
io_result_t *io_res)
{
sg_io_hdr_t hdr;
int ret;
memset(&hdr, 0, sizeof(hdr));
memset(io_res, 0, sizeof(*io_res));
*sense_read = 0;
*buf_read = 0;
hdr.interface_id = 'S';
hdr.dxfer_direction = dxfer_direction;
hdr.cmd_len = cdb_len;
hdr.mx_sb_len = sense_len;
hdr.dxfer_len = buf_len;
hdr.dxferp = buf;
hdr.cmdp = cdb;
hdr.sbp = sense;
hdr.timeout = timeout; /* timeout in milliseconds */
hdr.flags = SG_FLAG_LUN_INHIBIT;
hdr.pack_id = 0;
hdr.usr_ptr = 0;
ret = ioctl(fd, SG_IO, &hdr);
if (ret < 0) {
ERROR("Failed to issue ioctl to device errno=%d: %s", errno, strerror(errno));
io_res->error = ERROR_FATAL;
io_res->data = DATA_NONE;
return -1;
}
#if 0
if (hdr.status || hdr.driver_status || hdr.msg_status || hdr.host_status || hdr.sb_len_wr)
{
printf("status: %d %s\n", hdr.status, status_code_to_str(hdr.status));
printf("masked status: %d\n", hdr.masked_status);
printf("driver status: %d %s\n", hdr.driver_status, driver_status_to_str(hdr.driver_status));
printf("msg status: %d\n", hdr.msg_status);
printf("host status: %d = %s\n", hdr.host_status, host_status_to_str(hdr.host_status));
printf("sense len: %d\n", hdr.sb_len_wr);
}
#endif
*buf_read = hdr.dxfer_len - hdr.resid;
if (*buf_read == buf_len)
io_res->data = DATA_FULL;
else if (*buf_read == 0)
io_res->data = DATA_NONE;
else
io_res->data = DATA_PARTIAL;
if (hdr.sb_len_wr) {
memcpy(io_res->sense, sense, hdr.sb_len_wr);
io_res->sense_len = hdr.sb_len_wr;
*sense_read = hdr.sb_len_wr;
// Error with sense, parse the sense
if (scsi_parse_sense(sense, hdr.sb_len_wr, &io_res->info)) {
io_res->error = sense_to_error(&io_res->info);
} else {
// Parsing of the sense failed, assume the worst
io_res->error = ERROR_UNKNOWN;
}
return 0;
}
if (hdr.status != 0) {
// No sense but we have an error, consider it fatal if no data returned
ERROR("IO failed with no sense: status=%d (%s) mask=%d driver=%d (%s) msg=%d host=%d (%s)",
hdr.status, status_code_to_str(hdr.status),
hdr.masked_status,
hdr.driver_status, driver_status_to_str(hdr.driver_status),
hdr.msg_status,
hdr.host_status, host_status_to_str(hdr.host_status));
if (*buf_read == 0)
io_res->error = ERROR_UNKNOWN;
return 0;
}
io_res->error = ERROR_NONE;
return 0;
}
static disk_mount_e mount_point_check(struct mntent *mnt)
{
char *next = mnt->mnt_opts;
char *opt;
/* Device is mounted, check it */
while ((opt = strtok(next, ", \t\r\n")) != NULL) {
next = NULL; // continue scanning for this string
if (strcmp(opt, "rw") == 0)
return DISK_MOUNTED_RW;
}
return DISK_MOUNTED_RO;
}
disk_mount_e disk_dev_mount_state(const char *path)
{
struct stat dev_st_buf;
struct stat st_buf;
FILE *f = NULL;
struct mntent *mnt;
disk_mount_e state = DISK_MOUNTED_RW; // assume the worst
f = setmntent("/proc/mounts", "r");
if (f == NULL) {
ERROR("Failed to open /proc/mounts to know the state, errno=%d", errno);
goto Exit;
}
if (stat(path, &dev_st_buf) != 0) {
ERROR("Failed to stat the path %s, errno=%d", path, errno);
goto Exit;
}
if (!S_ISBLK(dev_st_buf.st_mode)) {
ERROR("Device %s is not a block device", path);
goto Exit; // We only want block devices
}
// From here we assume the disk is not mounted
state = DISK_NOT_MOUNTED;
while ((mnt = getmntent(f)) != NULL) {
disk_mount_e cur_state = DISK_NOT_MOUNTED;
/* Ignore non-full-path entries */
if (mnt->mnt_fsname[0] != '/')
continue;
/* Check for a name prefix match, we may check a full block device and a partition is mounted */
if (strncmp(path, mnt->mnt_fsname, strlen(path)) == 0) {
cur_state = mount_point_check(mnt);
if (cur_state > state)
state = cur_state;
continue;
}
/* Check for an underlying device match (name may have changed in between actions) */
if (stat(mnt->mnt_fsname, &st_buf) == 0) {
if (!S_ISBLK(st_buf.st_mode))
continue;
if (dev_st_buf.st_rdev == st_buf.st_rdev) {
cur_state = mount_point_check(mnt);
if (cur_state > state)
state = cur_state;
}
}
}
Exit:
if (f)
endmntent(f);
return state;
}
bool disk_dev_open(disk_dev_t *dev, const char *path)
{
dev->fd = open(path, O_RDWR|O_DIRECT);
return dev->fd >= 0;
}
void disk_dev_close(disk_dev_t *dev)
{
close(dev->fd);
dev->fd = -1;
}
void disk_dev_cdb_out(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)
{
sg_ioctl(dev->fd, cdb, cdb_len, buf, buf_size, SG_DXFER_TO_DEV, LONG_TIMEOUT, sense, sense_size, buf_read, sense_read, io_res);
}
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)
{
sg_ioctl(dev->fd, cdb, cdb_len, buf, buf_size, SG_DXFER_FROM_DEV, LONG_TIMEOUT, sense, sense_size, buf_read, sense_read, io_res);
}
ssize_t disk_dev_read(disk_dev_t *dev, uint64_t offset_bytes, uint32_t len_bytes, void *buf, io_result_t *io_res)
{
unsigned char cdb[32];
unsigned char sense[128];
int cdb_len;
unsigned buf_read = 0;
unsigned sense_read = 0;
int ret;
memset(buf, 0, len_bytes);
memset(io_res, 0, sizeof(*io_res));
cdb_len = cdb_read_10(cdb, false, offset_bytes / dev->sector_size, len_bytes / dev->sector_size);
ret = sg_ioctl(dev->fd, cdb, cdb_len, buf, len_bytes, SG_DXFER_FROM_DEV, LONG_TIMEOUT, sense, sizeof(sense), &buf_read, &sense_read, io_res);
if (ret < 0) {
return -1;
}
if (buf_read < len_bytes && sense_read > 0) {
VERBOSE("not all read: requested=%u read=%u sense=%u", len_bytes, buf_read, sense_read);
return -1;
}
return buf_read;
}
ssize_t disk_dev_write(disk_dev_t *dev, uint64_t offset_bytes, uint32_t len_bytes, void *buf, io_result_t *io_res)
{
unsigned char cdb[32];
unsigned char sense[128];
int cdb_len;
unsigned buf_read = 0;
unsigned sense_read = 0;
int ret;
memset(buf, 0, len_bytes);
memset(io_res, 0, sizeof(*io_res));
cdb_len = cdb_write_10(cdb, false, offset_bytes / dev->sector_size, len_bytes / dev->sector_size);
ret = sg_ioctl(dev->fd, cdb, cdb_len, buf, len_bytes, SG_DXFER_TO_DEV, LONG_TIMEOUT, sense, sizeof(sense), &buf_read, &sense_read, io_res);
if (ret < 0) {
return -1;
}
if (buf_read < len_bytes && sense_read > 0) {
VERBOSE("not all read: requested=%u read=%u sense=%u", len_bytes, buf_read, sense_read);
return -1;
}
return buf_read;
}
int disk_dev_read_cap(disk_dev_t *dev, uint64_t *size_bytes, uint64_t *sector_size)
{
unsigned char cdb[32];
unsigned char buf[512];
unsigned char sense[128];
int cdb_len;
unsigned buf_read = 0;
unsigned sense_read = 0;
int ret;
io_result_t io_res;
memset(buf, 0, sizeof(buf));
cdb_len = cdb_read_capacity_10(cdb);
ret = sg_ioctl(dev->fd, cdb, cdb_len, buf, sizeof(buf), SG_DXFER_FROM_DEV, SHORT_TIMEOUT, sense, sizeof(sense), &buf_read, &sense_read, &io_res);
if (ret < 0)
return -1;
uint32_t size_bytes_32;
uint32_t block_size;
if (!parse_read_capacity_10(buf, buf_read, &size_bytes_32, &block_size))
return -1;
if (sense_read > 0) // TODO: Parse to see if real error or something we can ignore
return -1;
if (size_bytes_32 < 0xFFFFFFFF) {
*size_bytes = (uint64_t)size_bytes_32 * 512;
dev->sector_size = *sector_size = block_size;
return 0;
}
// disk size is too large for READ CAPACITY 10, need to use READ CAPACITY 16
cdb_len = cdb_read_capacity_16(cdb, sizeof(buf));
ret = sg_ioctl(dev->fd, cdb, cdb_len, buf, sizeof(buf), SG_DXFER_FROM_DEV, SHORT_TIMEOUT, sense, sizeof(sense), &buf_read, &sense_read, &io_res);
if (ret < 0)
return -1;
if (sense_read > 0) // TODO: Parse to see if real error or something we can ignore
return -1;
if (!parse_read_capacity_16_simple(buf, buf_read, size_bytes, &block_size))
return -1;
*size_bytes *= 512;
dev->sector_size = *sector_size = block_size;
return 0;
}
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)
{
unsigned char cdb[32];
unsigned char buf[512];
unsigned char sense[128];
int cdb_len;
unsigned buf_read = 0;
unsigned sense_read = 0;
int ret;
io_result_t io_res;
*is_ata = false;
*ata_buf_len = 0;
memset(buf, 0, sizeof(buf));
cdb_len = cdb_inquiry_simple(cdb, 96);
ret = sg_ioctl(dev->fd, cdb, cdb_len, buf, sizeof(buf), SG_DXFER_FROM_DEV, SHORT_TIMEOUT, sense, sizeof(sense), &buf_read, &sense_read, &io_res);
if (ret < 0)
return -1;
int device_type;
if (!parse_inquiry(buf, buf_read, &device_type, vendor, model, fw_rev, serial))
{
INFO("Failed to parse the inquiry data");
return -1;
}
strtrim(vendor);
strtrim(model);
strtrim(fw_rev);
strtrim(serial);
// If the vendor doesn't start with ATA it is a proper SCSI interface
if (strncmp(vendor, "ATA", 3) != 0)
return 0;
*is_ata = true;
// For an ATA disk we need to get the proper ATA IDENTIFY response
memset(buf, 0, sizeof(buf));
cdb_len = cdb_ata_identify(cdb);
ret = sg_ioctl(dev->fd, cdb, cdb_len, buf, sizeof(buf), SG_DXFER_FROM_DEV, SHORT_TIMEOUT, sense, sizeof(sense), &buf_read, &sense_read, &io_res);
if (ret < 0)
return -1;
ata_get_ata_identify_model(buf, vendor);
strtrim(vendor);
strcpy(model, vendor + strlen(vendor) + 1);
strtrim(model);
ata_get_ata_identify_fw_rev(buf, fw_rev);
strtrim(fw_rev);
ata_get_ata_identify_serial_number(buf, serial);
strtrim(serial);
memcpy(ata_buf, buf, buf_read);
*ata_buf_len = buf_read;
return 0;
}
void mac_read(unsigned char *buf, int len)
{
struct ifreq ifr;
struct ifconf ifc;
char data[1024];
int success = 0;
buf[0] = 0;
int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
if (sock == -1) {
return;
};
ifc.ifc_len = sizeof(data);
ifc.ifc_buf = data;
if (ioctl(sock, SIOCGIFCONF, &ifc) == -1) {
/* handle error */
goto Exit;
}
struct ifreq* it = ifc.ifc_req;
const struct ifreq* const end = it + (ifc.ifc_len / sizeof(struct ifreq));
for (; it != end; ++it) {
strcpy(ifr.ifr_name, it->ifr_name);
if (ioctl(sock, SIOCGIFFLAGS, &ifr) == 0) {
if (! (ifr.ifr_flags & IFF_LOOPBACK)) { // don't count loopback
if (ioctl(sock, SIOCGIFHWADDR, &ifr) == 0) {
success = 1;
break;
}
}
}
else { /* handle error */ }
}
if (success) {
memcpy(buf, ifr.ifr_hwaddr.sa_data, len >= 6 ? 6 : len);
} else {
memset(buf, 0, len);
}
Exit:
close(sock);
}
diskscan-0.20/arch/arch-linux.h 0000664 0000000 0000000 00000000174 13150074536 0016400 0 ustar 00root root 0000000 0000000 #ifndef ARCH_INTERNAL_LINUX_H
#define ARCH_INTERNAL_LINUX_H
struct disk_dev_t {
int fd;
uint32_t sector_size;
};
#endif
diskscan-0.20/arch/arch-posix.c 0000664 0000000 0000000 00000004706 13150074536 0016403 0 ustar 00root root 0000000 0000000 #include
#include
#include
#include
#include
#include
#include
#include "verbose.h"
#include "arch.h"
bool disk_dev_open(disk_dev_t *dev, const char *path)
{
dev->fd = open(path, O_RDWR|O_DIRECT);
if (dev->fd < 0) {
INFO("Failed to open device %s with write permission, retrying without", path);
dev->fd = open(path, O_RDONLY|O_DIRECT);
}
return dev->fd >= 0;
}
void disk_dev_close(disk_dev_t *dev)
{
close(dev->fd);
dev->fd = -1;
}
ssize_t disk_dev_read(disk_dev_t *dev, uint64_t offset_bytes, uint32_t len_bytes, void *buf, io_result_t *io_res)
{
ssize_t ret = pread(dev->fd, buf, len_bytes, offset_bytes);
if (ret == len_bytes) {
io_res->data = DATA_FULL;
io_res->error = ERROR_NONE;
return ret;
} else if (ret > 0) {
io_res->data = DATA_PARTIAL;
io_res->error = ERROR_NONE;
return ret;
} else if (ret == 0) {
io_res->data = DATA_NONE;
io_res->error = ERROR_NONE;
return ret;
} else {
// ret < 0, i.e. error
INFO("Error reading from disk, offset=%lu len=%u errno=%d (%s)",
offset_bytes, len_bytes, errno, strerror(errno));
io_res->data = DATA_NONE;
io_res->error = ERROR_UNCORRECTED;
io_res->sense_len = 0;
memset(&io_res->info, 0, sizeof(io_res->info));
return -1;
}
//TODO: Handle EINTR with a retry
}
ssize_t disk_dev_write(disk_dev_t *dev, uint64_t offset_bytes, uint32_t len_bytes, void *buf, io_result_t *io_res)
{
ssize_t ret = pwrite(dev->fd, buf, len_bytes, offset_bytes);
if (ret == len_bytes) {
io_res->data = DATA_FULL;
io_res->error = ERROR_NONE;
return ret;
} else if (ret > 0) {
io_res->data = DATA_PARTIAL;
io_res->error = ERROR_NONE;
return ret;
} else if (ret == 0) {
io_res->data = DATA_NONE;
io_res->error = ERROR_NONE;
return ret;
} else {
// ret < 0, i.e. error
io_res->data = DATA_NONE;
io_res->error = ERROR_UNCORRECTED;
io_res->sense_len = 0;
memset(&io_res->info, 0, sizeof(io_res->info));
return -1;
}
//TODO: Handle EINTR with a retry
}
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)
{
(void)sense_size;
(void)sense;
(void)buf_size;
(void)buf;
(void)cdb_len;
(void)cdb;
(void)dev;
*sense_read = 0;
*buf_read = 0;
memset(&io_res, 0, sizeof(*io_res));
io_res->data = DATA_NONE;
io_res->error = ERROR_NONE;
}
diskscan-0.20/arch/arch-posix.h 0000664 0000000 0000000 00000000145 13150074536 0016401 0 ustar 00root root 0000000 0000000 #ifndef ARCH_INTERNAL_POSIX_H
#define ARCH_INTERNAL_POSIX_H
struct disk_dev_t {
int fd;
};
#endif
diskscan-0.20/cli/ 0000775 0000000 0000000 00000000000 13150074536 0014005 5 ustar 00root root 0000000 0000000 diskscan-0.20/cli/cli.c 0000664 0000000 0000000 00000020535 13150074536 0014725 0 ustar 00root root 0000000 0000000 /*
* Copyright 2013 Baruch Even
*
* This file is part of DiskScan.
*
* DiskScan is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DiskScan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DiskScan. If not, see .
*
*/
#include "verbose.h"
#include "diskscan.h"
#include "compiler.h"
#include "cli.h"
#include "progressbar/include/progressbar.h"
#include "hdrhistogram/src/hdr_histogram.h"
#include
#include
#include
#include
#include
#include
#include
#include
static disk_t disk;
static progressbar *bar;
typedef struct options_t options_t;
struct options_t {
char *disk_path;
int verbose;
int fix;
enum scan_mode mode;
unsigned scan_size;
char *data_log_name;
char *data_log_raw_name;
disk_mount_e allowed_mount;
};
static void print_header(void)
{
printf("diskscan version %s\n\n", VERSION);
VERBOSE("Verbosity set");
VVERBOSE("High verbosity set");
VVVERBOSE("Very high verbosity set");
}
static int usage(void) {
printf("diskscan version %s\n\n", VERSION);
printf("diskscan [options] /dev/sd\n");
printf("Options:\n");
printf(" -v, --verbose - Increase verbosity, multiple uses for higher levels\n");
printf(" -f, --fix - Attempt to fix near failures, nothing can be done for unreadable sectors\n");
printf(" -s, --scan - Scan in order (seq, random)\n");
printf(" -e, --size - Scan size (default to 64K, must be multiple of 512)\n");
printf(" -o, --output - Output file (json)\n");
printf(" -r, --raw-log - Raw log of all scan results (json)\n");
printf(" --force-mounted - Allow checking a read-only mounted disk\n");
printf(" --force-mounted-rw - Allow checking a read-write mounted disk\n");
printf("\n");
return 1;
}
void report_progress(disk_t * UNUSED(disk), int progress_part, int progress_full)
{
if (bar == NULL)
bar = progressbar_new("Disk scan", progress_full);
progressbar_update(bar, progress_part);
}
void report_scan_success(disk_t *UNUSED(disk), uint64_t UNUSED(offset_bytes), uint64_t UNUSED(data_size), uint64_t UNUSED(time))
{
}
void report_scan_error(disk_t *UNUSED(disk), uint64_t UNUSED(offset_bytes), uint64_t UNUSED(data_size), uint64_t UNUSED(time))
{
}
static void print_latency(latency_t *latency_graph, unsigned latency_graph_len)
{
unsigned i;
const uint32_t height = 30; // number of lines to fill
const uint32_t min_val = 0;
uint32_t max_val = 1;
for (i = 0; i < latency_graph_len; i++) {
if (max_val < latency_graph[i].latency_max_msec)
max_val = latency_graph[i].latency_max_msec;
}
uint32_t height_interval = (max_val - min_val + 1) / (height - 3);
if (height_interval == 0)
height_interval = 1;
else if (height_interval > 10000)
height_interval = 10000;
uint32_t j;
for (j = height; j > 0; j--) {
if (j % 5 == 0)
printf("%5u | ", j * height_interval);
else
printf(" | ");
for (i = 0; i < latency_graph_len; i++) {
uint32_t max_height = latency_graph[i].latency_max_msec / height_interval + 1;
uint32_t med_height = latency_graph[i].latency_median_msec / height_interval + 1;
uint32_t min_height = latency_graph[i].latency_min_msec / height_interval + 1;
if (max_height == med_height) {
max_height++;
}
if (med_height == min_height) {
med_height++;
if (max_height == med_height)
max_height++;
}
if (max_height != j && med_height != j && min_height != j) {
printf(" ");
continue;
}
if (max_height == j)
printf("^");
else if (med_height == j)
printf("*");
else
printf("_");
}
printf("\n");
}
printf(" +-");
for (i = 0; i < latency_graph_len; i++) {
printf("-");
}
printf("\n");
}
void report_scan_done(disk_t *pdisk)
{
progressbar_finish(bar);
printf("\nAccess time histogram:\n");
hdr_percentiles_print(pdisk->histogram, stdout, 5, 1000.0, CLASSIC); // Print msecs
printf("\nLatency graph:\n");
print_latency(pdisk->latency_graph, pdisk->latency_graph_len);
printf("\nConclusion: %s\n", conclusion_to_str(pdisk->conclusion));
}
static unsigned str_to_scan_size(const char *str)
{
char *endptr;
long int val;
errno = 0;
val = strtol(str, &endptr, 0);
if (errno != 0 || val <= 0) {
ERROR("Failed to parse the value (%s) to a number", str);
return 0;
}
if (*endptr != 0) {
unsigned factor = 1;
if (strcmp(endptr, "b") == 0 || strcmp(endptr, "B") == 0)
factor = 1;
else if (strcmp(endptr, "k") == 0 || strcmp(endptr, "K") == 0)
factor = 1024;
else if (strcmp(endptr, "m") == 0 || strcmp(endptr, "M") == 0)
factor = 1024*1024;
else {
ERROR("Unknown suffix '%s': B, K, and M are accepted", endptr);
return 0;
}
val *= factor;
}
unsigned retval = (unsigned)val;
if (retval > 32*1024*1024) {
ERROR("Maximum transfer size is 32MB, cannot handle more than that for now.");
return 0;
}
return (unsigned)val;
}
static int parse_args(int argc, char **argv, options_t *opts)
{
int c;
int unknown = 0;
static int allowed_mount = DISK_NOT_MOUNTED;
opts->scan_size = 64*1024;
while (1) {
int option_index = 0;
static struct option long_options[] = {
{"verbose", no_argument, 0, 'v'},
{"fix", no_argument, 0, 'f'},
{"scan", required_argument, 0, 's'},
{"size", required_argument, 0, 'e'},
{"raw-log", required_argument, 0, 'r'},
{"output", required_argument, 0, 'o'},
{"force-mounted", no_argument, &allowed_mount, DISK_MOUNTED_RO},
{"force-mounted-rw", no_argument, &allowed_mount, DISK_MOUNTED_RW},
{0, 0, 0, 0}
};
c = getopt_long(argc, argv, "vfs:e:o:r:", long_options, &option_index);
if (c == -1)
break;
switch (c) {
case 0:
break;
case 'v':
opts->verbose++;
break;
case 'f':
opts->fix = 1;
break;
case 's':
opts->mode = str_to_scan_mode(optarg);
if (opts->mode == SCAN_MODE_UNKNOWN) {
opts->mode = SCAN_MODE_SEQ;
printf("Unknown scan mode %s given, using sequential\n", optarg);
}
break;
case 'e':
opts->scan_size = str_to_scan_size(optarg);
break;
case 'o':
opts->data_log_name = optarg;
break;
case 'r':
opts->data_log_raw_name = optarg;
break;
default:
unknown = 1;
break;
}
}
if (optind == argc) {
printf("No disk path provided to scan!\n");
return usage();
}
if (optind < argc - 1) {
printf("Too many disk paths provided to scan, can only scan one disk!\n");
return usage();
}
if (unknown) {
printf("Unknown option provided\n");
return usage();
}
if (opts->scan_size == 0) {
printf("Scan size is invalid, must be a positive number\n");
return usage();
}
opts->disk_path = argv[optind];
opts->allowed_mount = allowed_mount;
return 0;
}
/*
static int print_disk_info(disk_t *UNUSED(disk))
{
return 0;
}
*/
static void diskscan_cli_signal(int UNUSED(signal))
{
disk_scan_stop(&disk);
}
static void setup_signals(void)
{
struct sigaction act = {
.sa_handler = diskscan_cli_signal,
.sa_flags = SA_RESTART,
};
sigaction(SIGINT, &act, NULL);
sigaction(SIGTERM, &act, NULL);
}
int diskscan_cli(int argc, char **argv)
{
int ret;
options_t opts;
memset(&opts, 0, sizeof(opts));
opts.mode = SCAN_MODE_SEQ;
opts.allowed_mount = DISK_NOT_MOUNTED;
if (parse_args(argc, argv, &opts))
return 1;
verbose = opts.verbose;
print_header();
setup_signals();
if (disk_open(&disk, opts.disk_path, opts.fix, 70, opts.allowed_mount))
return 1;
/*
if (print_disk_info(&disk))
return 1;
*/
if (opts.data_log_raw_name)
data_log_raw_start(&disk.data_raw, opts.data_log_raw_name, &disk);
if (opts.data_log_name)
data_log_start(&disk.data_log, opts.data_log_name, &disk);
ret = 0;
if (disk_scan(&disk, opts.mode, opts.scan_size))
ret = 1;
if (opts.data_log_raw_name)
data_log_raw_end(&disk.data_raw);
if (opts.data_log_name)
data_log_end(&disk.data_log, &disk);
disk_close(&disk);
return ret;
}
diskscan-0.20/cli/verbose.c 0000664 0000000 0000000 00000001754 13150074536 0015625 0 ustar 00root root 0000000 0000000 /*
* Copyright 2013 Baruch Even
*
* This file is part of DiskScan.
*
* DiskScan is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DiskScan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DiskScan. If not, see .
*
*/
#include "verbose.h"
#include
#include
int verbose_extra_newline;
void verbose_out(const char *fmt, ...)
{
va_list ap;
if (verbose_extra_newline)
printf("\n");
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
printf("\n");
}
diskscan-0.20/diskscan.c 0000664 0000000 0000000 00000001504 13150074536 0015201 0 ustar 00root root 0000000 0000000 /*
* Copyright 2013 Baruch Even
*
* This file is part of DiskScan.
*
* DiskScan is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DiskScan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DiskScan. If not, see .
*
*/
#include "cli.h"
int main(int argc, char **argv)
{
return diskscan_cli(argc, argv);
}
diskscan-0.20/distclean.sh 0000775 0000000 0000000 00000001521 13150074536 0015542 0 ustar 00root root 0000000 0000000 #!/bin/sh
# distclean.sh for diskscan
# Copyright 2015 Joao Eriberto Mota Filho
# v2015111402
# This file can used under GPL-3+ license or BSD-3-Clause.
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PREFIX="."
# Files and directories to remove
OBJS=" CMakeFiles/ \
Makefile \
CMakeCache.txt \
Documentation/diskscan.1 \
cmake_install.cmake \
install_manifest.txt \
libscsicmd/src/CMakeFiles/ \
libscsicmd/src/Makefile \
libscsicmd/src/cmake_install.cmake \
tags"
# Main procedures
remove_files () {
if [ -e "$PREFIX/$TARGET" ]; then
echo "Removing $PREFIX/$TARGET"
rm -rf "${PREFIX:?}/$TARGET"
else
echo "$PREFIX/$TARGET NOT FOUND."
fi
}
# Distclean
echo "DOING DISTCLEAN..."
for TARGET in $OBJS
do
remove_files
done
echo "DONE."
echo
diskscan-0.20/hdrhistogram/ 0000775 0000000 0000000 00000000000 13150074536 0015731 5 ustar 00root root 0000000 0000000 diskscan-0.20/hdrhistogram/.gitignore 0000664 0000000 0000000 00000001332 13150074536 0017720 0 ustar 00root root 0000000 0000000 target
.idea
out
gh-pages
HdrHistogram.iml
.classpath
.project
.settings
release.properties
/bin
alltests
format_example
*.a
*.iml
.sconsign.dblite
*.o
*.os
.DS_Store
build
CMakeCache.txt
CMakeFiles/
CPackConfig.cmake
CPackSourceConfig.cmake
CTestTestfile.cmake
Makefile
Testing/
cmake_install.cmake
examples/CMakeFiles/
examples/CTestTestfile.cmake
examples/Makefile
examples/cmake_install.cmake
examples/hdr_decoder
examples/hiccup
src/CMakeFiles/
src/CTestTestfile.cmake
src/Makefile
src/cmake_install.cmake
src/libhdr_histogram.so
test/CMakeFiles/
test/CTestTestfile.cmake
test/Makefile
test/cmake_install.cmake
test/hdr_dbl_histogram_test
test/hdr_histogram_log_test
test/hdr_histogram_test
test/perftest
.gdb_history
debug
diskscan-0.20/hdrhistogram/CMakeLists.txt 0000664 0000000 0000000 00000001205 13150074536 0020467 0 ustar 00root root 0000000 0000000 cmake_minimum_required(VERSION 2.8)
if("${CMAKE_VERSION}" VERSION_GREATER 3.0.0)
cmake_policy(SET CMP0042 NEW)
endif()
project("hdr_histogram")
ENABLE_TESTING()
if(UNIX)
set(CMAKE_C_FLAGS "-Wall -Wno-unknown-pragmas -Wextra -Wshadow -Winit-self -Wmissing-prototypes -D_GNU_SOURCE")
set(CMAKE_C_FLAGS_DEBUG "-O0 -g")
set(CMAKE_C_FLAGS_RELEASE "-O3 -g")
endif()
include_directories("${CMAKE_SOURCE_DIR}/src")
add_subdirectory("${CMAKE_SOURCE_DIR}/src")
add_subdirectory("${CMAKE_SOURCE_DIR}/test")
add_subdirectory("${CMAKE_SOURCE_DIR}/examples")
SET(CPACK_GENERATOR "TGZ")
SET(CPACK_PACKAGE_VERSION "0.9.1")
INCLUDE(CPack)
diskscan-0.20/hdrhistogram/COPYING.txt 0000664 0000000 0000000 00000015610 13150074536 0017605 0 ustar 00root root 0000000 0000000 Creative Commons Legal Code
CC0 1.0 Universal
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
HEREUNDER.
Statement of Purpose
The laws of most jurisdictions throughout the world automatically confer
exclusive Copyright and Related Rights (defined below) upon the creator
and subsequent owner(s) (each and all, an "owner") of an original work of
authorship and/or a database (each, a "Work").
Certain owners wish to permanently relinquish those rights to a Work for
the purpose of contributing to a commons of creative, cultural and
scientific works ("Commons") that the public can reliably and without fear
of later claims of infringement build upon, modify, incorporate in other
works, reuse and redistribute as freely as possible in any form whatsoever
and for any purposes, including without limitation commercial purposes.
These owners may contribute to the Commons to promote the ideal of a free
culture and the further production of creative, cultural and scientific
works, or to gain reputation or greater distribution for their Work in
part through the use and efforts of others.
For these and/or other purposes and motivations, and without any
expectation of additional consideration or compensation, the person
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
is an owner of Copyright and Related Rights in the Work, voluntarily
elects to apply CC0 to the Work and publicly distribute the Work under its
terms, with knowledge of his or her Copyright and Related Rights in the
Work and the meaning and intended legal effect of CC0 on those rights.
1. Copyright and Related Rights. A Work made available under CC0 may be
protected by copyright and related or neighboring rights ("Copyright and
Related Rights"). Copyright and Related Rights include, but are not
limited to, the following:
i. the right to reproduce, adapt, distribute, perform, display,
communicate, and translate a Work;
ii. moral rights retained by the original author(s) and/or performer(s);
iii. publicity and privacy rights pertaining to a person's image or
likeness depicted in a Work;
iv. rights protecting against unfair competition in regards to a Work,
subject to the limitations in paragraph 4(a), below;
v. rights protecting the extraction, dissemination, use and reuse of data
in a Work;
vi. database rights (such as those arising under Directive 96/9/EC of the
European Parliament and of the Council of 11 March 1996 on the legal
protection of databases, and under any national implementation
thereof, including any amended or successor version of such
directive); and
vii. other similar, equivalent or corresponding rights throughout the
world based on applicable law or treaty, and any national
implementations thereof.
2. Waiver. To the greatest extent permitted by, but not in contravention
of, applicable law, Affirmer hereby overtly, fully, permanently,
irrevocably and unconditionally waives, abandons, and surrenders all of
Affirmer's Copyright and Related Rights and associated claims and causes
of action, whether now known or unknown (including existing as well as
future claims and causes of action), in the Work (i) in all territories
worldwide, (ii) for the maximum duration provided by applicable law or
treaty (including future time extensions), (iii) in any current or future
medium and for any number of copies, and (iv) for any purpose whatsoever,
including without limitation commercial, advertising or promotional
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
member of the public at large and to the detriment of Affirmer's heirs and
successors, fully intending that such Waiver shall not be subject to
revocation, rescission, cancellation, termination, or any other legal or
equitable action to disrupt the quiet enjoyment of the Work by the public
as contemplated by Affirmer's express Statement of Purpose.
3. Public License Fallback. Should any part of the Waiver for any reason
be judged legally invalid or ineffective under applicable law, then the
Waiver shall be preserved to the maximum extent permitted taking into
account Affirmer's express Statement of Purpose. In addition, to the
extent the Waiver is so judged Affirmer hereby grants to each affected
person a royalty-free, non transferable, non sublicensable, non exclusive,
irrevocable and unconditional license to exercise Affirmer's Copyright and
Related Rights in the Work (i) in all territories worldwide, (ii) for the
maximum duration provided by applicable law or treaty (including future
time extensions), (iii) in any current or future medium and for any number
of copies, and (iv) for any purpose whatsoever, including without
limitation commercial, advertising or promotional purposes (the
"License"). The License shall be deemed effective as of the date CC0 was
applied by Affirmer to the Work. Should any part of the License for any
reason be judged legally invalid or ineffective under applicable law, such
partial invalidity or ineffectiveness shall not invalidate the remainder
of the License, and in such case Affirmer hereby affirms that he or she
will not (i) exercise any of his or her remaining Copyright and Related
Rights in the Work or (ii) assert any associated claims and causes of
action with respect to the Work, in either case contrary to Affirmer's
express Statement of Purpose.
4. Limitations and Disclaimers.
a. No trademark or patent rights held by Affirmer are waived, abandoned,
surrendered, licensed or otherwise affected by this document.
b. Affirmer offers the Work as-is and makes no representations or
warranties of any kind concerning the Work, express, implied,
statutory or otherwise, including without limitation warranties of
title, merchantability, fitness for a particular purpose, non
infringement, or the absence of latent or other defects, accuracy, or
the present or absence of errors, whether or not discoverable, all to
the greatest extent permissible under applicable law.
c. Affirmer disclaims responsibility for clearing rights of other persons
that may apply to the Work or any use thereof, including without
limitation any person's Copyright and Related Rights in the Work.
Further, Affirmer disclaims responsibility for obtaining any necessary
consents, permissions or other rights required for any use of the
Work.
d. Affirmer understands and acknowledges that Creative Commons is not a
party to this document and has no duty or obligation with respect to
this CC0 or use of the Work.
diskscan-0.20/hdrhistogram/LICENSE.txt 0000664 0000000 0000000 00000004161 13150074536 0017556 0 ustar 00root root 0000000 0000000 The code in this repository code was Written by Gil Tene, Michael Barker,
and Matt Warren, and released to the public domain, as explained at
http://creativecommons.org/publicdomain/zero/1.0/
For users of this code who wish to consume it under the "BSD" license
rather than under the public domain or CC0 contribution text mentioned
above, the code found under this directory is *also* provided under the
following license (commonly referred to as the BSD 2-Clause License). This
license does not detract from the above stated release of the code into
the public domain, and simply represents an additional license granted by
the Author.
-----------------------------------------------------------------------------
** Beginning of "BSD 2-Clause License" text. **
Copyright (c) 2012, 2013, 2014 Gil Tene
Copyright (c) 2014 Michael Barker
Copyright (c) 2014 Matt Warren
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. 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.
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.
diskscan-0.20/hdrhistogram/README.md 0000664 0000000 0000000 00000004177 13150074536 0017221 0 ustar 00root root 0000000 0000000 HdrHistogram_c: 'C' port of High Dynamic Range (HDR) Histogram
HdrHistogram
----------------------------------------------
[](https://gitter.im/HdrHistogram/HdrHistogram?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
This port contains a subset of the functionality supported by the Java
implementation. The current supported features are:
* Standard histogram with 64 bit counts (32/16 bit counts not supported)
* All iterator types (all values, recorded, percentiles, linear, logarithmic)
* Histogram serialisation (encoding version 1.2, decoding 1.0-1.2)
* Reader/writer phaser and interval recorder
Features not supported, but planned
* Auto-resizing of histograms
Features unlikely to be implemented
* Double histograms
* Atomic/Concurrent histograms
* 16/32 bit histograms
# Simple Tutorial
## Recording values
```C
#include
struct hdr_histogram* histogram;
// Initialise the histogram
hdr_init(
1, // Minimum value
INT64_C(3600000000), // Maximum value
3, // Number of significant figures
&histogram) // Pointer to initialise
// Record value
hdr_record_value(
histogram, // Histogram to record to
value) // Value to record
// Record value n times
hdr_record_value(
histogram, // Histogram to record to
value, // Value to record
10) // Record value 10 times
// Record value with correction for co-ordinated omission.
hdr_record_corrected_value(
histogram, // Histogram to record to
value, // Value to record
1000) // Record with expected interval of 1000.
// Print out the values of the histogram
hdr_percentiles_print(
histogram,
stdout, // File to write to
5, // Granularity of printed values
1.0, // Multiplier for results
CLASSIC); // Format CLASSIC/CSV supported.
```
## More examples
For more detailed examples of recording and logging results look at the
[hdr_decoder](examples/hdr_decoder.c)
and [hiccup](examples/hiccup.c)
examples. You can run hiccup and decoder
and pipe the results of one into the other.
```
$ ./examples/hiccup | ./examples/hdr_decoder
``` diskscan-0.20/hdrhistogram/examples/ 0000775 0000000 0000000 00000000000 13150074536 0017547 5 ustar 00root root 0000000 0000000 diskscan-0.20/hdrhistogram/examples/CMakeLists.txt 0000664 0000000 0000000 00000000562 13150074536 0022312 0 ustar 00root root 0000000 0000000 add_executable(hdr_decoder hdr_decoder.c)
target_link_libraries(hdr_decoder hdr_histogram m z)
install(TARGETS hdr_decoder DESTINATION bin)
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
add_executable(hiccup hiccup.c)
target_link_libraries(hiccup hdr_histogram m z pthread rt)
install(TARGETS hiccup DESTINATION bin)
endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
diskscan-0.20/hdrhistogram/examples/hdr_decoder.c 0000664 0000000 0000000 00000002704 13150074536 0022160 0 ustar 00root root 0000000 0000000 /**
* hdr_decoder.c
* Written by Michael Barker and released to the public domain,
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
*/
#include
#include
#include
#include
#include
#include
#include
#include
int main(int argc, char** argv)
{
int rc = 0;
FILE* f;
if (argc == 1)
{
f = stdin;
}
else
{
f = fopen(argv[1], "r");
}
if (!f)
{
fprintf(stderr, "Failed to open file(%s):%s\n", argv[1], strerror(errno));
return -1;
}
struct hdr_log_reader reader;
if (hdr_log_reader_init(&reader))
{
fprintf(stderr, "Failed to init reader\n");
return -1;
}
struct hdr_histogram* h = NULL;
struct timespec timestamp;
struct timespec interval;
rc = hdr_log_read_header(&reader, f);
if(rc)
{
fprintf(stderr, "Failed to read header: %s\n", hdr_strerror(rc));
return -1;
}
while (true)
{
rc = hdr_log_read(&reader, f, &h, ×tamp, &interval);
if (0 == rc)
{
hdr_percentiles_print(h, stdout, 5, 1.0, CLASSIC);
}
else if (EOF == rc)
{
break;
}
else
{
fprintf(stderr, "Failed to print histogram: %s\n", hdr_strerror(rc));
return -1;
}
}
return 0;
} diskscan-0.20/hdrhistogram/examples/hiccup.c 0000664 0000000 0000000 00000011614 13150074536 0021171 0 ustar 00root root 0000000 0000000 /**
* hiccup.c
* Written by Michael Barker and released to the public domain,
* as explained at http://creativecommons.org/publicdomain/zero/1.0/
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
static int64_t diff(struct timespec t0, struct timespec t1)
{
int64_t delta_us = 0;
delta_us = (t1.tv_sec - t0.tv_sec) * 1000000;
delta_us += (t1.tv_nsec - t0.tv_nsec) / 1000;
return delta_us;
}
static void update_histogram(void* data, void* arg)
{
struct hdr_histogram* h = data;
int64_t* values = arg;
hdr_record_value(h, values[0]);
}
static void* record_hiccups(void* thread_context)
{
struct pollfd fd;
struct timespec t0;
struct timespec t1;
struct itimerspec timeout;
struct hdr_interval_recorder* r = thread_context;
memset(&fd, 0, sizeof(struct pollfd));
memset(&timeout, 0, sizeof(struct itimerspec));
memset(&t0, 0, sizeof(struct timespec));
memset(&t1, 0, sizeof(struct timespec));
fd.fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC);
fd.events = POLLIN|POLLPRI|POLLRDHUP;
fd.revents = 0;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
while (true)
{
timeout.it_value.tv_sec = 0;
timeout.it_value.tv_nsec = 1000000;
timerfd_settime(fd.fd, 0, &timeout, NULL);
hdr_gettime(&t0);
poll(&fd, 1, -1);
hdr_gettime(&t1);
int64_t delta_us = diff(t0, t1) - 1000;
delta_us = delta_us < 0 ? 0 : delta_us;
hdr_interval_recorder_update(r, update_histogram, &delta_us);
}
#pragma clang diagnostic pop
pthread_exit(NULL);
}
struct config_t
{
int interval;
const char* filename;
};
const char* USAGE =
"hiccup [-i ] [-f ]\n"
" interval: Time in seconds between samples (default 1).\n"
" filename: Name of the file to log to (default stdout).\n";
static int handle_opts(int argc, char** argv, struct config_t* config)
{
int c;
int interval = 1;
while ((c = getopt(argc, argv, "i:f:")) != -1)
{
switch (c)
{
case 'h':
return 0;
case 'i':
interval = atoi(optarg);
if (interval < 1)
{
return 0;
}
break;
case 'f':
config->filename = optarg;
break;
default:
return 0;
}
}
config->interval = interval < 1 ? 1 : interval;
return 1;
}
int main(int argc, char** argv)
{
struct timespec timestamp;
struct timespec start_timestamp;
struct timespec end_timestamp;
struct hdr_interval_recorder recorder;
struct hdr_log_writer log_writer;
struct config_t config;
pthread_t recording_thread;
FILE* output = stdout;
memset(&config, 0, sizeof(struct config_t));
if (!handle_opts(argc, argv, &config))
{
printf("%s", USAGE);
return 0;
}
if (config.filename)
{
output = fopen(config.filename, "a+");
if (!output)
{
fprintf(
stderr, "Failed to open/create file: %s, %s",
config.filename, strerror(errno));
return -1;
}
}
if (0 != hdr_interval_recorder_init(&recorder))
{
fprintf(stderr, "%s\n", "Failed to init phaser");
return -1;
}
if (0 != hdr_init(
1, INT64_C(24) * 60 * 60 * 1000000, 3,
(struct hdr_histogram**) &recorder.active))
{
fprintf(stderr, "%s\n", "Failed to init hdr_histogram");
return -1;
}
if (0 != hdr_init(
1, INT64_C(24) * 60 * 60 * 1000000, 3,
(struct hdr_histogram**) &recorder.inactive))
{
fprintf(stderr, "%s\n", "Failed to init hdr_histogram");
return -1;
}
if (pthread_create(&recording_thread, NULL, record_hiccups, &recorder))
{
fprintf(stderr, "%s\n", "Failed to create thread");
return -1;
}
hdr_gettime(&start_timestamp);
hdr_log_writer_init(&log_writer);
hdr_log_write_header(&log_writer, output, "foobar", ×tamp);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
while (true)
{
sleep(config.interval);
hdr_reset(recorder.inactive);
struct hdr_histogram* h = hdr_interval_recorder_sample(&recorder);
hdr_gettime(&end_timestamp);
timestamp = start_timestamp;
hdr_gettime(&start_timestamp);
hdr_log_write(&log_writer, output, ×tamp, &end_timestamp, h);
fflush(output);
}
#pragma clang diagnostic pop
pthread_exit(NULL);
}
diskscan-0.20/hdrhistogram/ide/ 0000775 0000000 0000000 00000000000 13150074536 0016472 5 ustar 00root root 0000000 0000000 diskscan-0.20/hdrhistogram/ide/codestyle.jar 0000664 0000000 0000000 00000004267 13150074536 0021174 0 ustar 00root root 0000000 0000000 PK
S)G codestyles/ PK S)G codestyles/c_style.xmlVQo0~߯@7=J8Uc&q܆ S-;,$D;ߝQRJZ[\[[lRm},'Xje7}6`ޗ0X0c"qzi
mkly>p s$`'4p.F X@X#AKQL2?yдCc34!7Y1300cc W48 QLp-ΤaǂO 0O!_戒)-9I˥UE)dYRjJe)C-E^CX}|hxS~(+z=4Cld6x4_thi5u5n yK|6Y*f&Yb|mVr+6unqiy7ug|4/NwcIiUy]&tQJ˥.oqn}Ndwuvͧ}[̂rqL،Ac?FFpmLTVSZ4?_pۨg0=ne8|oCnJv_Yvt,'8 0'eQPp_{B/(v/S̙'('(x<'Owƽ
PKVB$ W PK G codestyles/Default _1_.xmlVQo0~߯@