72 Commits

Author SHA1 Message Date
Michel Machado
efdb48c79b f3probe: balance the number of writes and resets
One can write more blocks per pass in order to reduce
the total number of passes.
Trading resets for writes is effective when writing blocks is
cheaper than reseting the device being probed.

This patch dynamically balances the number of writes and
resets while probing.
The effectiveness of this balance is shown below:

A good 256MB drive produced the following measurements:
Probe time: 2.89 seconds
Probe read op: count=64, total time=0.13s, avg op time=2.06ms
Probe write op: count=48, total time=1.41s, avg op time=29.47ms
Probe reset op: count=8, total time=1.35s, avg op time=168.48ms

The results from previous commit (see git log):
Probe time: 47.57 seconds
Probe read op: count=2014, total time=1.72s, avg op time=0.85ms
Probe write op: count=2003, total time=45.32s, avg op time=22.62ms
Probe reset op: count=3, total time=0.53s, avg op time=175.66ms

Moreover, this patch spaces more uniformly
the blocks write_test_blocks() writes to improve
the effectiveness of each pass.
2014-10-09 17:54:30 -04:00
Michel Machado
46a7f24638 f3probe: add option --time-ops
In order to reduce probing time, one needs to time
reads, writes, and resets to evaluate how to change
the probing algorithm.
This patch adds these measurements.

A good 256MB drive produced the following measurements:
Probe time: 47.57 seconds
Probe read op: count=2014, total time=1.72s, avg op time=0.85ms
Probe write op: count=2003, total time=45.32s, avg op time=22.62ms
Probe reset op: count=3, total time=0.53s, avg op time=175.66ms
2014-09-25 14:33:02 -04:00
Michel Machado
a952fb7244 f3probe: probe with less resets
Of all three operations called on the flash drive being probed
(i.e. reading blocks, writing blocks, and resetting the drive),
the most time-consuming operation is reliably resetting the drive.

This patch reduces the number of resets writing and reading
more blocks.
2014-09-21 18:48:55 -04:00
Michel Machado
312c9170e7 f3probe: add option --min-memory
This option instructs f3probe to trade speed for less memory usage,
that is, f3probe minimizes use of memory.

Currently, this option only drops the use of the bitmap of
the safe device.
Nevertheless, this is not negligible memory.
For example, a 1TB drive whose block size is 512 Bytes requires
256MB of RAM for this bitmap:

  1TB / 512Byte/Block = 2^31Block
  2^31Block / 1Block/bit = 2^31bit
  2^31bit / 8bit/Byte = 2^28Byte = 256MB

To put it in context, 256MB of RAM was all that
Raspberry Pi Model A had.
2014-09-21 17:11:37 -04:00
Michel Machado
35a351ff39 f3probe: add option --manual-reset
The current reset method isn't supported for all USB drives,
what leads to wrong conclusions about some fake drives.

The option --manual-reset allows users to unplug and plug back
the USB drive being tested to manually reset the drive.
2014-09-21 17:09:01 -04:00
Michel Machado
73a657deec f3probe: protect block device
This patch makes f3probe read and save in memory
the content of all written blocks before writting them
during the probe, and restore the original content of those blocks
after probing the device.
In order words, f3probe behaves likes the probed device were
read only.

All the necessary memory to protect the probed device is
preallocated, so an on-going probe does not fail due to
lack of memory.

Although this feature adds an important protection layer,
users should be conscious that things can go wrong, and
the data will be lost.

This patch also adds option --debug-keep-file to help debugging
the new code this patch adds, and option --destructive to disable
the protection.
2014-09-21 13:02:03 -04:00
Michel Machado
294fd81798 f3probe: add block size to the drive model
Using the correct block size of the block device can improve
communication speed with the device.
2014-09-21 11:56:38 -04:00
Michel Machado
71370b7d89 f3probe: verify block number
This patch makes dev_read_block() and dev_write_block() verify
that their parameter @block is in the valid range of the device.
2014-09-21 11:56:38 -04:00
Michel Machado
02a3b25fcb f3probe: fix bug at search_wrap()
search_wrap() was considering @high_bit to be in blocks,
but it was in bytes.

This patch also improves the unit test to catch the fixed bug, and
to use real geometries.
2014-09-21 11:56:38 -04:00
Michel Machado
ea938f2ff2 f3probe: rewrite file device
This patch makes file devices use the same geometry model that
probe_device() probes for.

This change helps one to test whatever probe_device() finds in
the field.
2014-09-21 11:56:38 -04:00
Michel Machado
185145f5a1 f3probe: more than 45% speed-up with limbo drives
Skip the second test of a block if the first time test reads
something really different from what was written.
2014-09-21 11:56:38 -04:00
Michel Machado
6a63a5fff4 f3probe: improve report
- Show copyright header.
- Use friendly and precise units.
- Measure and show time to probe device.
2014-09-21 11:56:38 -04:00
Michel Machado
d940ecd19a f3probe: improve probe_device()
- It works with drives of any size.
- It precisely identifies the real size of drives.
- It identify the geometry of the drive.
2014-09-21 11:56:38 -04:00
Michel Machado
ceb79aae4e f3probe: improve debugging facility 2014-09-21 11:56:38 -04:00
Michel Machado
c1c7a95f0b f3probe: map block device to underlying USB device
The code is based on udev_example.c available on the following page:

libudev and Sysfs Tutorial
http://www.signal11.us/oss/udev/

f3probe nows requires library libudev.

This patch also updates the following files to reflect
the dependency of f3probe on libudev, and
the experimental status of f3probe: Makefile and README.
2014-09-21 11:56:38 -04:00
Michel Machado
c7beb92aba f3probe: reset USB drive to flush its cache
The internal cache of the USB drive was keeping all recent writes,
so subsequents reads were correct even when the underlying
storage was faulty.

The code is based on usbreset.c available on the following page:

How do you reset a USB device from the command line?
http://askubuntu.com/questions/645/how-do-you-reset-a-usb-device-from-the-command-line
2014-09-21 11:50:25 -04:00
Michel Machado
1e6ec3b83e Improve Makefile for debugging code
- Addopt -ggdb to add debugging information to binary.
- Add cscope target to help navigating the code.
- Add cscope.out to .gitignore.
- Add *.swp to .gitignore.
2014-09-21 11:50:25 -04:00
Michel Machado
b1fbd48675 f3probe: implement probe_device() 2014-09-21 11:47:20 -04:00
Michel Machado
96f9995d50 f3probe: implement block device support 2014-09-21 11:47:20 -04:00
Michel Machado
fadd9c805e f3probe: finish implemention of file device 2014-09-21 11:47:20 -04:00
Michel Machado
7f9f5972d0 f3probe: add unit test 2014-09-21 11:47:20 -04:00
Michel Machado
366e2d94bf f3probe: implement file device
NOT FINISHED
2014-09-21 11:47:19 -04:00
Michel Machado
28808f31b5 f3probe: move (missing) action to libprobe.c 2014-09-21 11:47:19 -04:00
Michel Machado
99dab5ca08 Make all applications share the same version 2014-09-21 11:47:19 -04:00
Michel Machado
b7790256f0 Skeleton of F3 probe 2014-09-21 11:43:59 -04:00
Michel Machado
2f10f2c068 Add experimental target to Makefile
f3probe, and any other future f3 application that isn't marked
as stable, will only compile with target experimental.
2014-09-21 11:43:59 -04:00
Michel Machado
55d201792c Bump next version to 4.0
Given that support for FreeBSD was added,
the next release will no longer be 3.1, but 4.0.
v4.0
2014-09-09 10:12:40 -04:00
Michel Machado
71433d3b78 Improve Makefile
- Change compiling flag -Wpedantic to -pedantic.
  Flag -Wpedantic is not available in older versions of gcc,
  what makes the life of some users unnecessarily harder.
  Not to mention that both flags work fine for F3.

- Allow make variable CC to be set externally.
  Some platforms favor other C compilers.
  For example, FreeBSD defaults to clang.

- Allow make variable CFLAGS to be extended externally.
  This helps packaging.

- Target clean to also remove *.d files.

The three first improvements were suggested by
Thomas Fischer and Uffe Jakobsen.
The discussion is available here:

https://github.com/AltraMayor/f3/issues/4
2014-09-05 07:58:08 -04:00
Uffe Jakobsen
b4e8e6c9da Fixes for FreeBSD 2014-09-02 10:30:43 -04:00
Michel Machado
397648282d f3write: account for option --end-at
This patch improves the progress percentage and estimate of
time to finish when option --end-at requires f3write to write
less than the amount of free space available.
2014-08-28 15:35:46 -04:00
Michel Machado
3263201548 Add script log-f3wr
This script runs f3write and f3read, echos their output to
the terminal, and records their output into a log file.
2014-08-28 15:11:31 -04:00
Michel Machado
9604f8b3df f3write.h2w: add support to all f3write's commands
The previous version of f3write.h2w didn't recognize
parameters --start-at= and --end-at=.

The new code of f3write.h2w also avoids overwritting
the environment variable PATH.
2014-08-22 10:26:12 -04:00
Michel Machado
1792cf1509 Prepare code for release of version 3.1 2014-08-15 17:30:38 -04:00
Michel Machado
d742672fa1 Add optional parameter --end-at=NUM to F3
This parameter allows users to execute F3 concurrently.

Moreover, users Mark and Wolfi have asked for similar parameters to
help analyzing very large flash drives.
2014-08-15 17:30:38 -04:00
Michel Machado
c98e580b94 General code review
- Comply with C99 standard.
- Adopt compiling flag -Wextra.
- Adopt compiling flag -Wpedantic.
- Drop use of PATH_MAX constant.
2014-08-12 13:56:01 -04:00
Michel Machado
01e8140ece Rewrite Makefile
This rewrite of the Makefile takes advantage of the fact that
the Makefile has been unified for all supported operating systems
to properly express source-file dependencies.
2014-08-12 13:56:01 -04:00
Michel Machado
66be2fddb9 Unify Makefile
The source now identifies the operating system with the help of
macros defined by GCC.

The macros are documented here:
http://sourceforge.net/p/predef/wiki/OperatingSystems/

This patch was inspired by a suggestion from Max Justicz.
2014-08-12 07:57:40 -04:00
Michel Machado
ba4d0a3fd8 Touch up README file 2014-08-12 07:55:52 -04:00
Michel Machado
11e2d2a3fa Add script f3write.h2w
This script calls truncate(1) after f3write runs successfully.
2014-07-15 15:58:34 -04:00
Michel Machado
b5dba24312 changelog: remove an undesirable header 2014-06-09 17:35:53 -04:00
Michel Machado
44ec7ce70e f3read: fix for Windows/Cygwin
Windows requires that the file descriptor passed to fdatasync(2)
to be writable.

Tom Hall reported the issue and proposed the solution.
v3.0
2014-06-03 11:31:35 -04:00
Michel Machado
7bd73cc434 Increment version to 3.0 2014-05-14 13:16:43 -04:00
Michel Machado
be1f587142 Adopt h2testw's file format
Now F3 and h2testw share the same file format.
Guenter Knauf has suggested this feature and
got the random-number generator used in h2testw from
Harald Bogeholz, the author of h2testw.

This change also addresses the issue that
the original random-number generator only fills
the first 32 bits of the 64 bits of the random numbers on
64-bit machines.
Besides the lower entropy on 64-bit machines, this issue was
making files generated on 32-bit and 64-bit machines incompatible.
Anselm Distelrath was the first to report this issue.
2014-05-14 11:44:13 -04:00
Michel Machado
1c50c85a4d Add a change log and a man page
Joao Eriberto Mota Filho contributed the change log and man page.
2014-05-14 10:34:44 -04:00
Michel Machado
a41f4a0c08 Add support for Windows/Cygwin
This commit is based on Tom Hall's patch.
2014-05-14 09:44:36 -04:00
Michel Machado
05eceb342d Fix report when .fff files are not fully read
Two things could go wrong when .fff files are not fully read:

1. The constraint "assert(*read_all || errno == EIO);"
   could fail because, according to the manual,
   feof(3) does not set errno(3), but gettimeofday(2),
   which is called after fread(3), does.

2. The tail message "NOT fully read" was never issued because
   the test was "read_all", and variable read_all was a pointer.
   Thus, the test was always true.

The not-fully-read error message now adds the output of
strerror(3) to guide the diagnose of the failure.

These bugs must be rare because they have been lurking around for
more than two years according to git's log.
They were only found due to a bug report by John Lussmyer on
September 21st, 2013.
2013-09-23 11:24:59 -04:00
Michel Machado
532bad04d6 Increment version to 2.2 v2.2 2013-02-08 15:14:28 -05:00
Michel Machado
f2a27db58c Add option parameter --start-at=NUM to F3
This parameter became important because F3 now can be used on
very large storages and one may want to resume the test process
from a failure or interruption.
2013-02-08 15:14:28 -05:00
Michel Machado
90b0bfbfcd Remove arbitrary limit on filenames
The filenames were from 0001.fff to 9999.fff.
This limit hasn't been a problem, but Anselm Distelrath reported
on February 8th, 2013 that isn't enough to test his system:
a RAID 6 with 18 hard drives of 3TB each.

Now filenames are from 1.fff to <INT_MAX>.fff.
2013-02-08 15:13:29 -05:00
Michel Machado
a642c2f3c8 Fix bug first reported by Martin Theiss
f3read finishes with following error message:

f3read: utils.c:39: number_from_filename: Assertion `is_my_file(filename)' failed.
2012-09-30 17:38:49 -04:00