50 Commits

Author SHA1 Message Date
a1346054
0d3215a10b fix spelling 2021-08-25 13:23:06 +00:00
bendem
90ed489c2a Return the status of the device as error code
Closes #106
2019-03-04 16:57:36 +01:00
Michel Machado
742f4e613f f3probe: change default reset type to RT_NONE
Change default reset type from RT_USB to RT_NONE in order to
address the following issues:

https://github.com/AltraMayor/f3/issues/79
https://github.com/AltraMayor/f3/issues/81
2018-06-08 11:43:17 -04:00
Michel Machado
77d2ceb374 f3probe: avoid compiler warning
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
2016-01-04 13:49:05 -05:00
Michel Machado
d8694268a6 f3probe: warn about how much time probing takes
This patch addresses issue discussed here:
https://github.com/AltraMayor/f3/issues/33
2015-12-21 09:37:43 -05:00
Michel Machado
bac59102da f3probe: present time in a friendly format 2015-11-29 14:48:15 -05:00
Michel Machado
1a576cb6dc f3probe: speed up non-destructive mode
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.
2015-11-17 16:51:29 -05:00
Michel Machado
08dd0e9061 f3probe: avoid division by zero
Since some fake drives do not require resets,
the option --time-ops was triggering a division by zero for
those drives.
2015-11-16 13:09:44 -05:00
Michel Machado
e7769bb77d f3probe: relax cache size comparision in unit test 2015-11-16 12:49:18 -05:00
Michel Machado
3d04fc7b55 f3probe: change default reset to --reset-type=1 2015-11-14 09:33:19 -05:00
Michel Machado
70e07816af f3probe: support any reset type (even no reset!)
This patch allows f3probe to report an accurate usable size
with any type of reset.
It works even with --reset-type=2 that is no reset at all.
2015-11-14 09:26:01 -05:00
Michel Machado
8348bcd909 f3probe: fix unit test
The name of a variable as mistyped.
The bug was innocuous, though.
2015-11-14 08:53:11 -05:00
Michel Machado
591ad8a7bf f3probe: add a blank line when --destructive is used
When option --destructive was being used,
f3probe was not spacing the final diagnosis message.
2015-11-13 14:37:42 -05:00
Michel Machado
5d76cd84b6 f3probe: deal with permanent cache
This patch addresses issue discussed here:
https://github.com/AltraMayor/f3/issues/15

Given the structure of the solution implemented in this patch,
it's also expected to address the following issue:
https://github.com/AltraMayor/f3/issues/16
2015-11-12 09:55:39 -05:00
Michel Machado
3f0efeb12f f3probe/f3brew: add cache to the model
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.
2015-11-12 09:55:39 -05:00
Michel Machado
246011f053 f3brew: work at block level
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.
2015-11-04 16:41:04 -05:00
Michel Machado
cc24fdf5b2 f3probe: fix a memory leak
This memory leak is innocuous since it happens a little before
f3probe exits.
2015-11-04 11:03:13 -05:00
Michel Machado
277f61a403 f3probe: rename real size to usable size
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.
2015-10-27 09:00:12 -04:00
Michel Machado
4b7d35951f f3brew: accept parameters from prompt 2015-09-02 10:43:36 -04:00
Michel Machado
bce2b9899b f3probe: --debug-block-order and --debug-keep-file
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.
2015-09-02 10:43:36 -04:00
Michel Machado
4f13815dfc f3probe: use physical block size
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.
2015-02-14 09:56:04 -05:00
Michel Machado
172f19373a f3probe: drop `Last good sector:' from geometry
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.
2015-01-31 20:42:25 -05:00
Michel Machado
05eff6e76c f3probe: suggest f3fix when the drive is fake 2014-12-24 11:10:21 -03:00
Michel Machado
6fbe096089 f3probe: report if the device changes its filename
Due to the resets, the device might move its filename.
For example, from `/dev/sdb' to `/dev/sdc'.
2014-12-24 10:54:44 -03:00
Michel Machado
7f37ff5efb f3probe: rename block device to disk device
f3probe really cares about disk devices.
2014-12-24 09:55:53 -03:00
Michel Machado
da939f2d7d f3probe: fix parameter --block-order
Parameter --block-order was forcing debug mode.
This directive is expected to work for both modes: debug and test.
2014-12-18 08:38:57 -03:00
Michel Machado
919451abb9 f3probe: improve messages to users 2014-12-18 08:34:17 -03:00
Michel Machado
95c3f8110d f3probe: use unit blocks instead of sectors
f3proble is block aware, so there's no reason to use sectors.
Moreover, thanks to the last-good-sector field,
sector numbers are no longer useful.
2014-12-17 11:15:15 -05:00
Michel Machado
d603f2e90a f3probe: rebrand --debug-block-order to --block-order
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!
2014-12-17 11:15:15 -05:00
Michel Machado
490bf780a3 f3probe: report last good sector of the drive
This information is useful to fix fake drives using fdisk, or
another partition tool.
2014-12-17 09:13:56 -05:00
Michel Machado
662fbf3db7 f3probe: add a message after the last reset
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.
2014-12-17 09:00:22 -05:00
Michel Machado
fb8c784670 f3probe: make it more uniform to add reset methods 2014-12-16 12:01:52 -05:00
Michel Machado
f2ac688edd f3probe: issue friendly message when no access
This patch makes f3probe issue a friendly error message
when the user doesn't have access to the device to be tested.
2014-12-16 09:41:12 -05:00
Michel Machado
adb8aaec84 f3probe: add a friendly way to enter sizes
This patch allows any number passed as parameters to use a unit.
For example, the parameter --debug-real-size=1G sets
a real size of 1GB.
2014-12-16 08:52:42 -05:00
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
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
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
7f9f5972d0 f3probe: add unit test 2014-09-21 11:47:20 -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