46 Commits

Author SHA1 Message Date
Michel Machado
283f386448 Merge pull request #187 from Al2Klimov/hardening
Hardening f3write and f3read
2022-11-11 18:57:08 -05:00
Alexander A. Klimov
0acac543f1 f3read, f3write: chdir(2) to source/target dir
This makes the dir non-umount-able for the program's lifetime.
2022-11-11 20:20:46 +01:00
Michel Machado
f5ae6b537a Add dynamic buffers to f3write and f3read
The write and read buffers passed to the operating system have
previously been limited to MAX_BUFFER_SIZE.  This commit makes
them dynamically sized in order to reach maximum writing and
reading speeds.

See details on issue #188.
2022-11-10 08:57:46 -05:00
a1346054
0d3215a10b fix spelling 2021-08-25 13:23:06 +00:00
Michel Machado
5ac9551d87 libflow: avoid types size_t and ssize_t in libflow.h
Those types are not included in libflow.h and
including them is overwhelming.
2020-06-23 07:35:05 -04:00
Michel Machado
79cd2d66a2 libflow: rename fields and variables for generality
The original libflow was written for f3write only, and
this was reflected in the name of fields and variables
throughout the code. This patch renames these fields and
variables to reflect the fact that libflow will eventually
support f3write AND f3read.
2020-06-22 16:38:42 -04:00
Michel Machado
e2a59bc08d libflow: avoid fdatasync() and posix_fadvise()
This patch moves calls to fdatasync() and posix_fadvise() out of
libflow as one more step to generalize libflow.
2020-06-22 16:38:42 -04:00
Michel Machado
14b35b5bc6 f3write: avoid unnecessary calls to measure()
This patch is only meant to have a simpler calling pattern of
libflow since it'll be generalized down the line.
2020-06-22 16:38:42 -04:00
Michel Machado
b1ab05c280 f3write: move flow code to a new library (libflow)
This is the first step toward generalizing the flow code in order to
reuse it in f3read.
2020-06-22 16:38:42 -04:00
Michel Machado
c9eee71ee9 f3write: add a backup speed measurement
If the drive is too fast for the measument of the flow algorithm,
this patch uses a coarse approximation of the writing speed.
2019-05-16 10:57:18 -04:00
Michel Machado
62ef9921c0 f3write: keep up with extremely fast NVM drives
NVM drives are fast enough to overflow 32-bit measurement variables
in bytes and blocks. This patch upgrades these variables to 64 bits.

This patch addresses issue #117:
https://github.com/AltraMayor/f3/issues/117
2019-05-16 07:45:10 -04:00
Michel Machado
2766edd4be f3write: adopt write_all() from libdevs.c
The file system HFS (i.e. "OS X Extended (Journaled)") of
macOS 10.11 may return a number of partial write()'s before
the file system is full.

This POSIX-permited, but unusual behavior was frist reported here:
https://github.com/AltraMayor/f3/issues/111
2019-03-11 12:22:48 -04:00
Michel Machado
fead723be5 f3write: improve measurement of write speed
A second shot on solving issue #102.
2019-01-10 17:23:20 -05:00
Michel Machado
0b8c973c4c f3write: improve measurement of write speed
According to issue #102, calls to fdatasync() might take
a long time (.e.g. 3s or 4s) and distort the measurement of
the average write speed. This patch addresses it by only updating
the measurements when delays are within a tolerance.
2019-01-09 09:31:41 -05:00
Michel Machado
888cdf941b f3write: make maximum write rate precise
When parameter --max-write-rate is used,
this patch makes the rate algorithm precisely match that rate.

The error was around 3% for rates above 1MB/s.
2017-12-22 14:14:56 -05:00
Michel Machado
865c44f21c f3write: fix saved_error bug
When measure() fails at the very last end of a file,
@remaining is zero.
Since @saved_errno is not ENOSPC, but @remaining is zero,
the code was considering that the file was properly written.
2017-12-19 15:22:48 -05:00
Michel Machado
485b81ceb0 f3write: suggest --max-write-rate for error EIO 2017-12-19 11:46:32 -05:00
Michel Machado
2544c80ab0 f3write: add parameter --max-write-rate
This parameter is useful to test cards that overheat.

Daniel Otero (@danielotero) pointed out the overheat problem, and
suggested the parameter as a solution in the following issue:

https://github.com/AltraMayor/f3/issues/37
2017-12-19 10:50:40 -05:00
Michel Machado
7172cff4b9 f3write: gracefully handle failures of fdatasync(2)
This patch solves the following issue:

https://github.com/AltraMayor/f3/issues/37
2017-12-18 16:04:45 -05:00
Michel Machado
8c33abff6a f3write: reduce the number of write() system calls
This patch combines many calls to system call write() into
a single call.
This lower number of calls, and the combined buffer should enable
the kernel to speed up f3write to match H2testw' performance as
reported in the following issue:

https://github.com/AltraMayor/f3/issues/55
2016-11-15 16:57:11 -05:00
Michel Machado
abf811f04b General review of @zwpwjwtz's patch 2016-03-29 12:35:22 -04:00
zwpwjwtz
fb187b4c71 Replace parse_args() with argp_parse() from argp.h 2016-03-29 15:37:13 +08:00
Michel Machado
b8e825a331 f3write: polish fill_buffer()
This commit was inspired by the following commit:
52e252f5d6
f3read: avoid compiler warning
2016-01-05 10:06:08 -05: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
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
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
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
c24c098c3c Report version and copyright in help message
This was added mainly to help users to identify
the version they have installed.
2012-03-07 11:29:40 -05:00
Michel Machado
f7d57f76e0 Made f3write remove old F3 files in order
Messages like "Removing old file 0001.fff ..." were issued in
a file system dependent order.

This is a cosmetic change that takes advantage of
the function ls_my_files previously created for f3read.
2011-12-26 17:26:08 -02:00
Michel Machado
246f528e0a Refined flow control algorithm of f3write
The original algorithm had a slow reaction when there was
a large variation on the flow capacity.

The new algorithm even removed the need for the call to sync(2)
at beginning.
2011-12-26 17:25:47 -02:00
Michel Machado
d350745fc2 Verify that "all" F3 files are present
If an F3 file (i.e. *.fff) but the last one is missing,
f3read will report the missing file with a warning similar to this one:

Missing file 0001.fff

AND the following warning will be presented at the end of the report:

WARNING: Not all F3 files are available

Kenneth Arnold suggested this feature in an e-mail:
"I also noticed that if one of the files is completely missing, f3read
will still report no errors. The chance that this will happen on its
own without messing something else up is too small to worry about,
except possibly in the case that the device was actually read-only and
no files actually got created. In that case, f3read succeeds with 0
sectors OK and 0 sectors lost."

The last F3 file, if missing, is not reported because
it can be confusing.
The following example gives an idea of the problem:
a memory card wasn't empty when f3write was called and
the last F3 file created was 0010.fff with exactly 1GB;
here none F3 file is missing.
Then, some non-F3 files were removed, and f3read is called.
f3read would report a missing file even when non-F3 files were
removed!
The problem gets a little bit uglier if 0010.fff in the example
is less that 1GB, or the file system doesn't let f3write to
fill it up for a few bytes (this should be very rare, but
there's no guarantee that it cannot happen).

Finally, the implementation of this feature has a positive
side effect: f3read processes F3 files in ascending order,
that is, 0001.fff, 0002.fff, ..., NNNN.fff.
Before the order was file system dependent.

Magic numbers related to the number of digits in the F3 files'
names were eliminated.
2011-12-23 22:16:19 -02:00
Michel Machado
cbadb0c91c Reviewed code 2011-12-20 14:02:17 -05:00
Michel Machado
0510a6c08d Added support for Macs 2011-12-20 11:21:42 -05:00
Michel Machado
7c0be994e1 f3write now reports proper progress
In the previous version of f3write, fdatasync(2) was used to
show the progress printouts smoothly.
However, it slows down a lot the execution, and hurts
the writing speed measurement.

This new version finds out what is the writing speed of
the memory card being tested using an algorithm that reseables
TCP's congestion control algorithm, and keeps writing at that
speed; this allows smooth progress printouts.

f3write is even faster now!
2011-12-17 18:22:50 -05:00
Michel Machado
597aa0fb3c Added progress printout in f3read 2011-12-17 17:05:12 -05:00
Michel Machado
c03cbf4b4a Advising the kernel
* f3read
	As long as the kernel honors our advice, f3read doesn't
	ever read data from the system cache instead of reading
	from the memory card, and reading speed measurement  is
	improved.

* f3write
	Progress printout goes smoothly now.
2011-12-17 17:05:03 -05:00
Michel Machado
91083d787c Improved precision of speed measurements 2011-12-17 16:59:55 -05:00
Michel Machado
0135a9bfeb Improved user feedback
- Improved format of f3read's output, example:

$ ./f3read /media/F085-0201/
                     SECTORS      ok/corrupted/changed/overwritten
Validating file 0001.fff ... 2097152/        0/      0/      0
Validating file 0002.fff ... 1904000/        0/      0/      0

  Data OK: 1.91 GB (4001152 sectors)
Data LOST: 0.00 Byte (0 sectors)
	       Corrupted: 0.00 Byte (0 sectors)
	Slightly changed: 0.00 Byte (0 sectors)
	     Overwritten: 0.00 Byte (0 sectors)
Reading speed: 15.14 MB/s

- Added progress report per file to f3write.

Both suggestions were given by Michael D. Setzer II.
2011-12-17 15:52:17 -05:00
Michel Machado
d2a1a289fd Formated code following Linux's coding style
See file Documentation/CodingStyle in Linux's source code
for a reference of the style.

Used "indent -kr -i8" to help out.

Added a .gitignore to the repository.
2011-12-14 19:09:20 -05:00
Michel Machado
71cd829b9f Fixed block size bug
Nobody has reported this "bug", neither have I seen it coming out,
but I'm fixing it anyway.
It's based on Kenneth Arnold's fork of F3, which is available here:
https://github.com/kcarnold/f3

I also added a few lines in README.
2011-12-14 17:59:52 -05:00
Michel Machado
8bd4f358da Copied code from GNU Library C to improve portability
This version should compile and run on Apples, but since
I don't have one, I haven't tested it.
2011-12-14 15:48:15 -05:00
Michel Machado
899b3c6ca7 Version 1.1.1
Fixed some warnings issued by gcc when the parameter -Wall is
used to compile the source.
2011-12-14 15:32:33 -05:00
Michel Machado
45f50c10b2 Version 1.1
- Added a nice report at the end of the output of f3read.
- Fixed bug on large memory cards.
2011-12-14 15:28:46 -05:00
Michel Machado
48195690db The very first version of F3 (version 1.0)
It doesn't have a nice report, and due to a bug, only works properly on
2GB cards or less.
2011-12-14 15:24:43 -05:00