314 Commits

Author SHA1 Message Date
Michel Machado
ac2d89a0b9 f3probe: improve manual reset
This patch handles the edge case in wich
the drive changes its size after a reset.
2015-02-02 13:31:00 -05:00
Michel Machado
ca59ef530d f3probe: deal with USB devices that support multilple drives
During manual resets, the drive was being identified by
idVendor, idProduct, and serial, what is NOT enough when
the USB device combines two or more drives.
For example the card reader Kingston MobileLite G3
supports two memory cards at the same time.

Discussion on the fixed issue is available here:
https://github.com/AltraMayor/f3/issues/10

User @derekchal was the first to report this problem.
2015-02-01 16:59:02 -05:00
Michel Machado
85d15520d4 f3probe: fix manual reset when card is removed
When the memory card in a card reader is removed,
the device is kept, not removed like in the case
the reader itself is unplugged.

This patch handles the `change' events that are generated in
the card-removal case.
2015-02-01 15:56:43 -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
b70b9ce914 f3probe: improve I/O error handling 2015-01-31 20:35:26 -05:00
Michel Machado
7c0306ca6f f3probe: avoid hanging before the second reset
f3probe was writing too many blocks between
the first and the second reset due to
a poor estimate of the writing and reseting times.
v5.0
2014-12-24 12:10:47 -03:00
Michel Machado
755fdc29ff Update folder where drives are mounted in README
At least Ubuntu has added the username after /media/.
2014-12-24 12:00:02 -03:00
Michel Machado
79f7e7a339 f3fix: report success to user 2014-12-24 11:52:10 -03:00
Michel Machado
21e26faa0f Add f3fix to this release 2014-12-24 11:11:26 -03: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
3f02ab9ac6 f3fix: add proper support to parameters 2014-12-24 09:54:01 -03:00
Michel Machado
5df999a767 f3fix: improve error handling 2014-12-24 08:06:11 -03:00
Michel Machado
423777ee6b f3fix: functional but not polished version 2014-12-23 13:25:16 -03:00
Michel Machado
8e25afa42b Add stub version of f3fix 2014-12-23 11:15:33 -03:00
Michel Machado
f8797d8b7c Minor fixes 2014-12-23 11:12:37 -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
263ea4f68e f3probe: reduce code of the manual reset
One doesn't have to wait for the remove event,
only for the add event.
2014-12-18 08:30:55 -03:00
Michel Machado
1caeff3205 Bump version to 5.0 2014-12-17 11:35:22 -05:00
Michel Machado
506730b83f f3probe: ignore return of udev_device_unref()
It is not predictable how udev library handles
its reference counters.
2014-12-17 11:15:15 -05: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
f7ff381eaf f3probe: make error message friendlier
when the user can't run f3probe as root, direct her to
f3write/f3read.
2014-12-17 08:46:19 -05:00
Michel Machado
dd6ebe6b99 f3probe: make sure that the block device is a disk
This patch makes f3probe test that the block device passed is
a disk, not a partition or something else.
If the block device is a partition,
the correct disk device is reported.

Example of this new protection in action:
$ sudo f3probe /dev/sdb1
[sudo] password for michel:
F3 probe 4.0
Copyright (C) 2010 Digirati Internet LTDA.
This is free software; see the source for copying conditions.

Device `/dev/sdb1' is a partition of disk device `/dev/sdb'.
You can run this program as follows:
f3probe /dev/sdb

Application cannot continue, finishing...
2014-12-17 08:37:18 -05:00
Michel Machado
783ef37213 f3probe: drop old manual reset
The code of the old manual reset couldn't handle the case of
the drive changing its filename, i.e. "/dev/sdb" becomes
"/dev/sdc" after the drive is unplugged and plugged back.

Not only this is a bug, in the rare case the user is
testing multiple drives at the same time, this would lead
to bad behavior.
2014-12-17 06:41:37 -05:00
Michel Machado
12b44e1068 f3probe: add semiautomatic reset method
This new reset method monitors the USB subsytem to know
when the drive was unplugged and when it was plugged back
to continue instead of waiting for a key to be pressed after
those actions.

The following URLs were very useful to implement this patch:

http://www.signal11.us/oss/udev/
http://www.freedesktop.org/software/systemd/libudev/
2014-12-17 06:32:30 -05:00
Michel Machado
3853dbc998 f3probe: map_block_to_usb_dev() avoids enumeration
Function map_block_to_usb_dev() was enumerating all USB devices and
comparing their properties to find the one we need.
The new code directly resolves the device from major and minor
number of the block device.
2014-12-16 13:30:45 -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
1db68aa268 Fix yet another building error on Macs
The error was inserted on the following commit:
e8509a05e970bf770db838bd00490f413bb1f432

Sebastian Busch was the first to report this error here:

https://github.com/AltraMayor/f3/issues/6#issuecomment-67152791
2014-12-16 07:35:32 -05:00
Michel Machado
f8050f4721 Address unused-parameter warning on Macs
Function posix_fadvise(), only implemented on Macs, was issuing
warnings because the code doesn't use parameters 'offset' and 'len'.
2014-12-16 07:10:02 -05:00
Michel Machado
e8509a05e9 Another take on fixing building issue on Macs
This patch is based on artosx's feedback on GitHub:

https://github.com/AltraMayor/f3/issues/6#issuecomment-67075953
2014-12-16 07:05:48 -05:00
Michel Machado
62f3c1d861 Fix building issue on Macs
This patch is based on artosx's suggestion on GitHub:

https://github.com/AltraMayor/f3/issues/6#issuecomment-66874674
2014-12-15 09:18:05 -05:00
Michel Machado
a61d96a33a experimental: require version 1 of libudev
libudev0 uses different function signatures.

This issue was first reported by Mark Knibbs.
2014-11-15 16:06:40 -05:00
Michel Machado
5e3ad28613 f3probe: improve handling of write errors 2014-10-10 14:24:39 -04:00
Michel Machado
91a291374c make f3brew (barely) work 2014-10-10 14:24:38 -04:00
Michel Machado
751b5a609f add f3brew (experimental)
f3brew, f3 block read write, tests block devices
writing and reading blocks directly to devices.

This is a not-functional version of f3brew.
The main contribution of this patch is to reorganize libprobe.{h,c},
so f3brew, and any future application, can reuse the library.
2014-10-10 09:54:39 -04: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
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