When using -O2, GCC was issuing the following warning:
cc -O2 -std=c99 -Wall -Wextra -pedantic -MMD -ggdb -c -o f3probe.o f3probe.c
f3probe.c: In function ‘main’:
f3probe.c:446:13: warning: ‘sdev’ may be used uninitialized in this function [-Wmaybe-uninitialized]
sdev_flush(sdev);
^
f3probe.c:369:30: note: ‘sdev’ was declared here
struct device *dev, *pdev, *sdev;
^
NOTE: The warning was wrong.
GCC could not follow that @args->save being true implied
@sdev to not be NULL.
This patch addresses one of the issues discussed here:
https://github.com/AltraMayor/f3/issues/34
This patch makes f3probe issue single calls of
sequential reads and writes wherever is possible to speed up
the non-destructive (i.e. conservative) mode.
Notice that the non-destructive mode only recovers the usable
blocks of fake drives, and all blocks of legit drives.
F3 users have identified fake flashes that reserve a portion of
their good memory to use as a permanent cache.
This patch adds this feature to our model in order to allow us to
develop a new probe algorithm to deal with it.
f3brew were working at sector level because
it was borrowing code from f3write/f3read which work at that level.
This patch writes new functions to fill out, and validate blocks.
This change is important because
f3probe needs to validate blocks as well for its coming features.
A side effect of this patch is that all experimental applications
(i.e. f3probe, f3brew, and f3fix) no longer depend on
code from f3write and f3read.
f3probe does not try to find the real amount of memory that
a fake card has, but the usable about of memory, that is,
the memory from the first block (i.e. block zero) to
the block before the first failed block.
A fake card may have more memory, but it would be spread among
failed blocks, so it is not usable.
This patch just enables debugging mode when parameters
--debug-block-order and --debug-keep-file are used;
This is equivalent to automatically adding --debug.
It was an expected behavior that wasn't implemented.
f3probe was using a kernel-recommended logical block size.
This patch allows f3probe to always find
the last good physical block of devices.
This patch also renames option --block-order to --debug-block-order
since f3probe detects the physical block size of devices.
The field `Last good sector:' does not make sense
when the device is damaged, and
the geometry should be indepedent of the condition or
type of the drive.
The information is not lost because when the device "fixable",
f3fix is recommended with the correct parameter.
The new parameter allows users to test drives with
forced block sizes.
This parameter is only meant to help testing drives whose
*real* sizes are not multiples of their block sizes;
this should be rather rare!
This message is supposed to help the user to avoid
removing the drive after the last reset.
After a sequence of manual resets, it's almost automatic to unplug
the drive and lose all the save blocks; I've done it myself.
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.
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
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.
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.
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.
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.
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.
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.