Commit Graph

95 Commits (ebb8b1aa045a0a43344c4ae581e1c342a9724d23)

Author SHA1 Message Date
Theodore Ts'o 99ceb8ec1a Move the check_plausibility() function from misc to lib/support
The check_plausibility() function is now used all over the place, so
we should move the plausible.c file to lib/support and remove the
special case handling for that file that had been in the build system.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-07-12 22:01:17 -04:00
Jan Kara fcc19b4aa3 badblocks: Limit maximum number of bad blocks
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>
2014-12-14 20:55:44 -05:00
Theodore Ts'o 56087556e1 badblocks: print warning if set_o_direct() fails
Addresses-Coverity-Id: #1049148

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2014-01-08 19:46:05 -05:00
Theodore Ts'o f404167dda Clean up sparse warnings
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>
2013-12-16 18:56:36 -05:00
Andreas Dilger 45ff69ffeb build: quiet LLVM non-literal string format warning
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>
2013-12-15 22:12:16 -05:00
Darrick J. Wong d87f198ca3 libext2fs: reject 64bit badblocks numbers
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>
2013-10-23 19:56:21 -04:00
Theodore Ts'o 577c773a60 misc: fix gcc -Wall warnings
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2013-05-19 20:03:48 -04:00
Andreas Dilger 1d6fd6d0c3 misc: cleanup unused variables on MacOS
Clean up unused variables found by GCC on MacOS.

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-12-29 17:28:37 -05:00
Theodore Ts'o 4a4a44d7b1 badblocks: honor the -s option when in read-only -t mode
Addresses-Debian-Bug: #646629

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2012-02-17 15:28:21 -05:00
Theodore Ts'o 9d4507c5b6 Pass the gettext() function to libcom_err
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>
2011-10-05 01:00:30 -04:00
Theodore Ts'o d1154eb460 Shorten compile commands run by the build system
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>
2011-09-18 17:34:37 -04:00
Andreas Dilger cf5301d7f2 misc: clean up compiler warnings
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>
2011-06-11 10:58:25 -04:00
Theodore Ts'o 214580a339 Merge branch 'maint' into next
Conflicts:
	misc/mke2fs.conf.5.in
2011-02-20 21:54:43 -05:00
Theodore Ts'o 89d4597510 badblocks: Add accounting for different types of errors
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>
2011-02-20 15:29:51 -05:00
Theodore Ts'o 39791dc0bd badblocks: Fix up recover_block handling in badblocks
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>
2011-02-20 15:19:47 -05:00
Theodore Ts'o 175d43bead Merge branch 'maint' into next 2011-02-18 01:19:05 -05:00
Theodore Ts'o 468d82f430 badblocks: Only report errors when reading/writing one block at a time
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>
2011-02-18 01:16:03 -05:00
Theodore Ts'o e53e8fb009 badblocks: Add the -B option which forces the use of buffered I/O
If for some reason direct I/O does not work correctly, force the use
of buffered I/O.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-02-18 01:16:02 -05:00
Theodore Ts'o 7d6840354a badblocks: Fix bug so that O_DIRECT mode is correctly entered
The check to see if the block number is properly aligned was not done
correctly.  Fix this.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-02-18 01:09:39 -05:00
Theodore Ts'o 9d92a201de Merge branch 'maint' into next
Conflicts:
	configure
	configure.in
	lib/ext2fs/ext2fs.h
	misc/mke2fs.c
2010-09-24 22:40:21 -04:00
Theodore Ts'o 61ef2474c2 badblocks: Deal with UTF-8 characters in progress message
Addresses-Gentoo-Bug: #309909
Addresses-Debian-Bug: #583782
Addresses-Debian-Bug: #587834

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-08-01 22:30:33 -04:00
Valerie Aurora Henson 5648c35ab1 badblocks: Use ext2fs_get_device_size2()
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-06-13 12:00:00 -04:00
Theodore Ts'o c510d6f268 badblocks: Make sure the list of bad blocks found is flushed on interrupt
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-06-29 01:04:02 -04:00
Theodore Ts'o 83bfa27d32 badblocks: Print the currently tested block number when interrupted with ^C
This can be useful for the user who wishes to restart the badblocks
program after interrupting it.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-06-29 00:52:27 -04:00
Theodore Ts'o 3b5126de44 badblocks: Remove 4096 blocksize limit
There is no need to prohibit the use of block sizes larger than 4k in
the badblocks program.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-06-02 09:31:24 -04:00
Jim Meyering 45e338f533 remove useless if-before-free tests
In case you're wondering about whether this change is safe from a
portability standpoint, fear not.  This has been beaten to death
in other forums.  Here are a few threads:

  http://thread.gmane.org/gmane.comp.version-control.git/74187
  http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/12712
  http://thread.gmane.org/gmane.emacs.devel/98144
  http://thread.gmane.org/gmane.comp.lib.glibc.alpha/13092

There has been debate about whether it's a good idea from a
performance standpoint, too, but imho you'll have a hard time
finding an instance where this sort of change induces a
measurable performance penalty.  If you do, please let me know.

Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2009-03-08 20:37:12 -04:00
Theodore Ts'o 42e572b5b6 badblocks: Fix progress output for "badblocks -sw /dev/XXX"
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>
2008-10-01 20:00:54 -04:00
Manish Katiyar 504f7a2981 badblocks: Display time and percentage complete in verbose mode.
Addresses-Debian-Bug: #429739.

Signed-off-by: "Manish Katiyar" <mkatiyar@gmail.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-09-05 07:51:33 -04:00
Theodore Ts'o 22301afb01 badblocks: Open the device with O_LARGEFILE
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>
2008-09-02 08:29:20 -04:00
Theodore Ts'o efc6f628e1 Remove trailing whitespace for the entire source tree
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-08-27 23:07:54 -04:00
Benno Schulenberg ad39bcd9e3 badblocks: Insert a missing "\n" in the usage string.
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>
2008-07-18 21:14:21 -04:00
Theodore Ts'o c13ab4fa7a badblocks: If nanosleep() does not exist, try using usleep() instead
For portability on systems that don't have nanosleep().

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-07-13 16:38:56 -04:00
Theodore Ts'o f56f32b0a5 badblocks: Use standard terminology for first/last block
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>
2008-07-10 10:11:23 -04:00
Theodore Ts'o 69d813520c badblocks: Fix crash when lots of -t patterns given
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>
2008-07-06 18:56:31 -04:00
Eric Sandeen 79e62409b3 Clean up some trivial build warnings
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-07-06 18:36:56 -04:00
Iustin Pop edf261f6f8 badblocks: fix a bug in the read throttling
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>
2008-06-21 14:43:25 -04:00
Iustin Pop 264f64a5a8 badblocks: implement read throttling
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>
2008-06-17 07:47:25 -04:00
Iustin Pop eb594251b6 badblocks: fix a possible bug in parse_uint
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>
2008-06-17 07:33:44 -04:00
Iustin Pop 931b0289ee badblocks: add a max bad blocks count option
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>
2008-06-17 07:33:29 -04:00
Theodore Ts'o d4be9fad6e badblocks: Factor out calls to strtoul to a helper function
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>
2007-10-22 18:05:32 -04:00
Theodore Ts'o acd77415a9 badblocks: Change unsigned long to blk_t and unsigned int, as appropriate
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>
2007-10-22 18:05:32 -04:00
Theodore Ts'o e9860ae966 badblocks: Use unsigned int instead of unsigned long for test patterns
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2007-10-22 18:05:32 -04:00
Theodore Ts'o d4e0b1c6f5 Fix gcc -Wall warnings
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2007-08-03 18:56:01 -04:00
Theodore Ts'o 5267a520bb Fix error checking of badblock's last-block and start-block arguments
Addresses Debian Bug: #416477

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2007-06-04 01:49:51 -04:00
Theodore Ts'o 017a76ee39 Adjust badblocks -n/-w exclusive usage message
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2006-11-17 23:00:19 -05:00
Theodore Ts'o d8b5f77743 Add explanatory message to badblocks that -n and -w are mutually exclusive
Addresses Debian Bug: #371869

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2006-11-12 23:09:03 -05:00
Theodore Ts'o 8938ce64dc Fix interpretation of the last_block command-line parameter to badblocks
Also update the display messages so they are accurate.

Addresses Debian Bug: #386475

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2006-10-03 23:35:57 -04:00
Theodore Ts'o f63978aff7 Fix read/write badblocks testing in mke2fs and e2fsck
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>
2006-05-13 09:25:47 -04:00
Theodore Ts'o 5f51d1c1eb Fix display bug in badblocks -w
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>
2005-09-24 18:28:00 -04:00
Theodore Ts'o bb145b01cf Fix e2fsprogs messages for grammar and consistency, based on suggestions
from Benno Schulenberg.

Add missing _() so all strings can be internationalized.
2005-06-20 08:35:27 -04:00