39 Commits

Author SHA1 Message Date
Michel Machado
5846f9dbb1 f3probe: report unexpected error codes in read_all()
No unexpected error code should happen in read_all(), but,
if it does, f3probe will report them before aborting.

This patch address the request of user @vi at the following comment:
https://github.com/AltraMayor/f3/issues/82#issuecomment-585829975
2020-02-18 10:27:07 -05:00
Michel Machado
3c19d21859 f3probe: allow errno == ENODATA when calling read(2)
The errno ENODATA is not documented in the manual, but according
to the comment the following comment, it behaves like EIO.

https://github.com/AltraMayor/f3/issues/82#issuecomment-584409275
2020-02-11 07:49:55 -05:00
Mariusz Wojtasik
3ab5bad85c libdevs: bring back missing ‘const’ specifier
Commit 7ff9fad37a32 ("libdevs: fix compiler warning") fixed the warning
by removing duplicate ‘const’ specifier.
The original intent of two ‘const’ specifiers, was most likely to make
non-mutable both: the ‘ftype_to_name‘ array itself and its elements,
so bring back the second ‘const’, but in the correct place this time,
i.e. after ‘*‘.
2018-12-30 21:31:07 +01:00
Michel Machado
7ff9fad37a libdevs: fix compiler warning
Warning:
libdevs.c:26:19: warning: duplicate ‘const’ declaration specifier [-Wduplicate-decl-specifier]
 static const char const *ftype_to_name[FKTY_MAX] = {
                   ^~~~~
2018-12-10 14:07:48 -05:00
Michel Machado
381d8603c2 f3probe: deal with an assertion failure
This patch may address the following issue:
https://github.com/AltraMayor/f3/issues/82
2018-12-10 14:04:29 -05:00
Michel Machado
83f6c0523a f3probe: add support to non-USB devices
This patch adds support to non-USB devices when reset is disabled
with parameter --reset-type=2
This patch address the following issue:

https://github.com/AltraMayor/f3/issues/62
2017-06-25 08:41:45 -04: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
83a9c1c87d f3probe/f3brew: add --reset-type=2
Reset type 2 does not reset, that is, it does nothing.
This parameter is only helpful to study the effects of cache on
the F3 algorithms.
2015-11-14 08:38:33 -05:00
Michel Machado
cedb3f17d2 f3probe: fix a (supposed) race condition
Although I (Michel) am not 100% sure, the kernel seemed to be
allowing reads to get data from an internal cache in the kernel;
the condition is tricky to reproduce, and trickier to be sure
since fake drives are not reliable or preditable.
The results seems more stable with this patch, though.
2015-11-13 20:18:12 -05:00
Michel Machado
e3fe7a006d f3probe: fix allocation error of safe device
probe_device_max_blocks() was returning an int that once multiplied
by block_size was out range.
This patch just enforces probe_device_max_blocks() to return
an uint64_t, and does the needed adjustments in the code.
2015-11-13 14:40:43 -05:00
Michel Machado
59ab4e9a8e f3brew: correct messages that refer to f3probe
libdevs.c had error messages that mentioned f3probe.
Given that f3brew also uses libdevs.c, this was causing nonsense
error messages such as the following:

==================================================================
$ ./f3brew /dev/sdc
F3 brew 5.0
Copyright (C) 2010 Digirati Internet LTDA.
This is free software; see the source for copying conditions.

Your username doesn't have access to device `/dev/sdc'.
Try to run this program as root:
sudo f3probe /dev/sdc
In case you don't have access to root, use f3write/f3read.

Application cannot continue, finishing...
==================================================================
2015-11-13 14:05:51 -05:00
Michel Machado
067802ca5a f3brew: speed up writing and reading
This patch changes the interface of struct device to allow
writes and reads of sequential blocks with a single call.
2015-11-13 09:09:33 -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
4d913c1442 f3probe: handle failures in usb_fd_from_block_dev()
Function usb_fd_from_block_dev() wasn't releasing resources
if any error happened.

Reported-by: Peter Skensved
2015-03-30 07:36:11 -04:00
Michel Machado
902db294ef f3probe: align buffers with devices' block sizes
This patch should address issue discussed here:
https://github.com/AltraMayor/f3/issues/13

Reported-by: Dingyuan Wang
2015-02-14 10:36:07 -05: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
ea4b33e275 f3probe: fix segmentation fault during manual reset 2015-02-04 16:48:20 -05:00
Michel Machado
d74ef39bdd f3probe: rename a variable for readability 2015-02-04 16:37:46 -05:00
Michel Machado
c3db1edd7c f3probe: improve error handling during resets 2015-02-02 14:41:17 -05:00
Michel Machado
8001dfdadd f3probe: make read_all() return negative errors
bdev_read_block(), who calls read_all(), is
expected to return negative errors.
2015-02-02 13:31:00 -05:00
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
b70b9ce914 f3probe: improve I/O error handling 2015-01-31 20:35:26 -05: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
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
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
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
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
5e3ad28613 f3probe: improve handling of write errors 2014-10-10 14:24:39 -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