Currently maximum number of bad blocks is not limited in any way.
However our code can really handle at most INT_MAX/2 bad blocks (for
larger numbers binary search indexes start overflowing). So report
number of bad blocks is just too big instead of plain segfaulting.
It won't be too hard to raise the limit but I don't think there's any
real use for disks with over 1 billion of bad blocks...
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Mostly by adding static and removing excess extern qualifiers. Also
convert a few remaining non-ANSI function declarations to ANSI.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Compiling with LLVM generates a large number of warnings due
to the use of _() for wrapping strings for i18n:
warning: format string is not a string literal
(potentially insecure) [-Wformat-security]
./nls-enable.h:4:14: note: expanded from macro '_'
#define _(a) (gettext (a))
^~~~~~~~~~~~
These warnings are fixed by using "%s" as the format string,
and then _() is used as the string argument.
Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Don't accept block numbers larger than 2^32 for the badblocks list,
and don't run badblocks on them either.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
For those e2fsprogs programs which use libcom_err and are
internationalized, pass the gettext() function to libcom_err during
program initialization.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
The DEFS line in MCONFIG had gotten so long that it exceeded 4k, and
this was starting to cause some tools heartburn. It also made "make
V=1" almost useless, since trying to following the individual commands
run by make was lost in the noise of all of the defines.
So fix this by putting the configure-generated defines in lib/config.h
and the directory pathnames to lib/dirpaths.h.
In addition, clean up some vestigal defines in configure.in and in the
Makefiles to further shorten the cc command lines.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Fix several types of compiler warnings (unused variables/labels),
uninitialized variables, etc that are hit with gcc -Wall.
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
When using the -v option, report a breakdown of the number of read,
write, and comparison errors that were found by badblocks.
Thanks to Ragnar Kjørstad for providing this patch.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
If there was a bad block for block #0, badblocks would never switch
back testing blocks more efficiently. In addition, we were
double-incrementing the blocks to be tested in the read/write test due
to failure to remove code.
Thanks to Ragnar Kjørstad for pointing these problems out.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
With Direct I/O, the kernel can report 0 bytes read even though the
first block has no errors. So there are any errors, we need try to
read/write blocks one at a time and to get an accurate report.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Always initialize the starting time so that badblocks -sw works.
Thanks Jelle de Jong (jelledejong at powercraft.nl) for reporting this
bug.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Linux doesn't enforce the Large File Support API requirements on block
devices, but in case someone wants to run badblocks on a normal file,
open the device file with O_LARGEFILE.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Take the opportunity to wrap the string to be more readable,
and sort the options somewhat alphabetically.
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Use consistent and standard terminology for the starting and ending
blocks for the badblocks test in the man page and in the messages
printed by the program.
Addresses-Debian-Bug: #440983, #440981
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
With more than 8 -t patterns given, badblocks will overwrite the
t_patts array boundary due to realloc not taking into account the size
of an int. Oops.
Addresses-Debian-Bug: 487298
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
The previous patch was missing an #include and thus the compiler didn't
catch the (now obvious) error.
Signed-off-by: Iustin Pop <iustin@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Currently, badblocks will read as fast as it can from the drive. While
this is what one wants usually, if badblocks is run in read-only mode on
a drive that is in use, it will greatly degrade the other users of this
disk.
This patch adds a throttling mode for reads where each read will be
delayed by a percentage of the time the previous read took; i.e., an
invocation of '-d 100' will cause the sleep to be the same as the read
took, a value of 200 will cause the sleep to be twice as high, and a
value of 50 will cause it to be half. This will not be done if the
previous read had errors, since then the hardware will possibly have
timeouts and that would decrease the speed too much.
This algorithm helps when the disk is used by other processes as then,
due to the increased load, the time spent doing the reads will be
higher, and correspondingly badblocks will sleep even more and thus it
will use less of the drive's bandwidth. This is different from using
ionice, as it is a voluntary (and partial) throttling.
Signed-off-by: Iustin Pop <iustin@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Currently, the parse_uint() function checks errno after the strtoul()
call. But, according to the man page of strtoul():
Since strtoul() can legitimately return 0 or LONG_MAX (LLONG_MAX for
strtoull()) on both success and failure, the calling program
should set errno to 0 before the call, and then determine if an error
occurred by checking whether errno has a nonzero value after the call.
When using locales, it can happen that looking for the locale files is
not successful, and therefore errno will have a nonzero value from this.
And since the argument parsing is one of the first things done after
startup, parse_uint() will wrongly report errors.
The fix is to simply reset errno to zero before calling strtoul().
Signed-off-by: Iustin Pop <iustin@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Currently, badblocks will continue scanning the device until it reaches
last_block, even though it might be that the drive is not responding
at all anymore.
This patch introduces a new parameter ('-e') that allows one to specify
the maximum bad block count; if badblocks sees more than this number, it
will abort the test.
While this is not useful for testing a device that will need to be used
as a filesystem (because we don't get an exhaustive list of bad blocks),
it is useful for testing if a device has bad blocks at all: for example,
with a count of 1, it will finish after the first error thus not needing
to test the whole device if the only purpose of the test is to check for
any bad blocks.
Signed-off-by: Iustin Pop <iustin@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
The strtoul() function has a lot of messy error checking that needs to
be done; by factoring it out into one place we can make sure it's done
right in all of the places where it is called.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
This will make it easier for us to support 64-bit block numbers when
the time comes. Not that running badblocks on a > 4TB machine is
anything I want to contemplate!
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
The exlcusive device safety check that was added inadvertently broke
e2fsck -cc and mke2fs -cc since e2fsck and mke2fs hold the device
in exclusive access when badblocks is run. So we add a private option
to badblocks, -X, which is passed by e2fsck and mke2fs to badblocks
to indicate that it is OK to skip the EXT2_MF_BUSY checks.
Addresses Debian Bug: #366017
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Add extra spaces when printing the "done" message to clear out the
block number to fix a display corruption when the -s option is used to
display the progress of the test. (Addresses Debian Bug #322231)
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>