Gentoo Archives: gentoo-commits

From: Thomas Deutschmann <whissi@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: sys-block/f3/, sys-block/f3/files/
Date: Tue, 31 Jul 2018 17:13:52
Message-Id: 1533057193.d322d0827f05f64af1a70c1a85672476b0092e35.whissi@gentoo
1 commit: d322d0827f05f64af1a70c1a85672476b0092e35
2 Author: Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
3 AuthorDate: Tue Jul 31 17:12:43 2018 +0000
4 Commit: Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
5 CommitDate: Tue Jul 31 17:13:13 2018 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=d322d082
7
8 sys-block/f3: drop old
9
10 Package-Manager: Portage-2.3.44, Repoman-2.3.10
11
12 sys-block/f3/Manifest | 1 -
13 sys-block/f3/f3-6.0.ebuild | 74 ----
14 sys-block/f3/files/f3-6.0-extra-target.patch | 108 ------
15 .../f3-6.0-fix-compiler-warnings_f3probe.patch | 50 ---
16 .../f3-6.0-fix-compiler-warnings_f3read.patch | 88 -----
17 sys-block/f3/files/f3-6.0-respect-ldflags.patch | 40 --
18 sys-block/f3/files/f3-6.0-upstream-issue-44.patch | 25 --
19 sys-block/f3/files/f3-6.0-use-argp_parse.patch | 417 ---------------------
20 8 files changed, 803 deletions(-)
21
22 diff --git a/sys-block/f3/Manifest b/sys-block/f3/Manifest
23 index 54f97075311..43a76e35303 100644
24 --- a/sys-block/f3/Manifest
25 +++ b/sys-block/f3/Manifest
26 @@ -1,3 +1,2 @@
27 -DIST f3-6.0.tar.gz 45355 BLAKE2B c06f5ea3285f46197af05e7c4a75dc1e94b28acc14ec4f8da6b3fbeaec723cfaa420fa2542573a1cd5586ea50e27c3e8010ecd88ecfeb7b9ad28591f072c1377 SHA512 7960d01d7a2bd01a236006fcb4081cc7e2c0be674bc3e28137f00ea3f558a04eed47f10e7d3795c219943092ee43fb3189e19ff1925a7ed4ff5102130d65a470
28 DIST f3-7.0.tar.gz 67492 BLAKE2B 6b6882958ca831a26cd815635a563dd1bac9c93103fd6e9a2a4040b6ea3725395be96d0cbef9d7e01441402edf63a63110be41f5db559eb5fa85ac82a101751d SHA512 217348c3911995143e2d1f777ff6038ffd541f6868d58da9ca0a702610377f26eac7aafcd993d9b410b4d5a6d27d2c4fa8020b665beee7c2f760dc293a63c41f
29 DIST f3-7.1.tar.gz 67934 BLAKE2B 7d5e12d8af7abda6136dfa19127554b6e5c45fdec7f0cef10d792d77cd2cfae035a572cdf2f22faf54c61852b1660e70270a326bb4408ed64725114f1f9aff4f SHA512 d696bb96ebaefab13c50a4479be01c206365d8dcf7d3c3b1d906b68705b654fffabdbeee49ea208047383c117bcac2a85c2c5fb129cace82f8addc16f22d7514
30
31 diff --git a/sys-block/f3/f3-6.0.ebuild b/sys-block/f3/f3-6.0.ebuild
32 deleted file mode 100644
33 index ac8d4869cb4..00000000000
34 --- a/sys-block/f3/f3-6.0.ebuild
35 +++ /dev/null
36 @@ -1,74 +0,0 @@
37 -# Copyright 1999-2018 Gentoo Foundation
38 -# Distributed under the terms of the GNU General Public License v2
39 -
40 -EAPI=6
41 -
42 -inherit flag-o-matic toolchain-funcs
43 -
44 -DESCRIPTION="Utilities to detect broken or counterfeit flash storage"
45 -HOMEPAGE="http://oss.digirati.com.br/f3/ https://github.com/AltraMayor/f3"
46 -
47 -PATCHES=(
48 - "${FILESDIR}"/f3-6.0-fix-compiler-warnings_f3read.patch
49 - "${FILESDIR}"/f3-6.0-fix-compiler-warnings_f3probe.patch
50 - "${FILESDIR}"/f3-6.0-respect-ldflags.patch
51 - "${FILESDIR}"/f3-6.0-use-argp_parse.patch
52 - "${FILESDIR}"/f3-6.0-extra-target.patch
53 - "${FILESDIR}"/f3-6.0-upstream-issue-44.patch
54 -)
55 -
56 -if [[ ${PV} == "9999" ]]; then
57 - EGIT_REPO_URI="https://github.com/AltraMayor/${PN}.git"
58 -
59 - PATCHES=()
60 -
61 - inherit git-r3
62 -else
63 - SRC_URI="https://github.com/AltraMayor/${PN}/archive/v${PV}.tar.gz -> ${P}.tar.gz"
64 - KEYWORDS="amd64 ~arm64 x86"
65 -fi
66 -
67 -LICENSE="GPL-3+"
68 -SLOT="0"
69 -
70 -IUSE="extra"
71 -
72 -DEPEND="extra? (
73 - sys-block/parted
74 - virtual/udev
75 - )"
76 -
77 -RDEPEND=""
78 -
79 -DOCS=( changelog README.md )
80 -
81 -src_prepare() {
82 - default
83 -
84 - sed -i \
85 - -e 's:-ggdb::' \
86 - -e 's:^PREFIX =:PREFIX ?=:' \
87 - Makefile || die
88 -
89 - tc-export CC
90 -
91 - append-cflags -fgnu89-inline # https://github.com/AltraMayor/f3/issues/34
92 -}
93 -
94 -src_compile() {
95 - default
96 -
97 - if use extra; then
98 - emake V=1 extra
99 - fi
100 -}
101 -
102 -src_install() {
103 - emake PREFIX="${ED%/}/usr" install
104 -
105 - if use extra; then
106 - emake PREFIX="${ED%/}/usr" install-extra
107 - fi
108 -
109 - dodoc "${DOCS[@]}"
110 -}
111
112 diff --git a/sys-block/f3/files/f3-6.0-extra-target.patch b/sys-block/f3/files/f3-6.0-extra-target.patch
113 deleted file mode 100644
114 index 8523ca3f2b5..00000000000
115 --- a/sys-block/f3/files/f3-6.0-extra-target.patch
116 +++ /dev/null
117 @@ -1,108 +0,0 @@
118 -From 64d169e2486121eaece555c56040d6aff71e0b51 Mon Sep 17 00:00:00 2001
119 -From: Michel Machado <michel@××××××××××××.br>
120 -Date: Tue, 29 Mar 2016 12:56:43 -0400
121 -Subject: [PATCH] Mark experimental applications as stable
122 -
123 -The code of the applications f3probe, f3brew, and f3fix is now
124 -mature, and they have not received any significant bug report for
125 -about six months.
126 -
127 -From now on, one needs to compile these applications with
128 -```make extra```
129 ----
130 - Makefile | 10 +++++-----
131 - README.md | 29 ++++++++++++-----------------
132 - 2 files changed, 17 insertions(+), 22 deletions(-)
133 -
134 -diff --git a/Makefile b/Makefile
135 -index 46853f5..ce54842 100644
136 ---- a/Makefile
137 -+++ b/Makefile
138 -@@ -2,14 +2,14 @@ CC ?= gcc
139 - CFLAGS += -std=c99 -Wall -Wextra -pedantic -MMD -ggdb
140 -
141 - TARGETS = f3write f3read
142 --EXPERIMENTAL_TARGETS = f3probe f3brew f3fix
143 -+EXTRA_TARGETS = f3probe f3brew f3fix
144 -
145 - PREFIX = /usr/local
146 - INSTALL = install
147 - LN = ln
148 -
149 - all: $(TARGETS)
150 --experimental: $(EXPERIMENTAL_TARGETS)
151 -+extra: $(EXTRA_TARGETS)
152 -
153 - install: all
154 - $(INSTALL) -d $(PREFIX)/bin
155 -@@ -18,9 +18,9 @@ install: all
156 - $(INSTALL) -oroot -groot -m644 f3read.1 $(PREFIX)/share/man/man1
157 - $(LN) -sf f3read.1 $(PREFIX)/share/man/man1/f3write.1
158 -
159 --install-experimental: experimental
160 -+install-extra: extra
161 - $(INSTALL) -d $(PREFIX)/bin
162 -- $(INSTALL) -oroot -groot -m755 $(EXPERIMENTAL_TARGETS) $(PREFIX)/bin
163 -+ $(INSTALL) -oroot -groot -m755 $(EXTRA_TARGETS) $(PREFIX)/bin
164 -
165 - f3write: utils.o f3write.o
166 - $(CC) -o $@ $^ $(LDFLAGS) -lm
167 -@@ -45,4 +45,4 @@ cscope:
168 - cscope -b *.c *.h
169 -
170 - clean:
171 -- rm -f *.o *.d cscope.out $(TARGETS) $(EXPERIMENTAL_TARGETS)
172 -+ rm -f *.o *.d cscope.out $(TARGETS) $(EXTRA_TARGETS)
173 -diff --git a/README.md b/README.md
174 -index f0399b4..e2f7f79 100644
175 ---- a/README.md
176 -+++ b/README.md
177 -@@ -5,36 +5,31 @@ make
178 - ```
179 -
180 -
181 --## Compile experimental applications on Linux
182 -+## Compile the extra applications on Linux
183 -
184 - ### Install dependencies
185 -
186 -- - f3probe and f3brew require version 1 of the library libudev to compile.
187 -- On Ubuntu, you can install this library with the following command:
188 -+f3probe and f3brew require version 1 of the library libudev, and
189 -+f3fix requires version 0 of the library libparted to compile.
190 -+On Ubuntu, you can install these libraries with the following command:
191 - ```
192 --sudo apt-get install libudev1 libudev-dev
193 --```
194 -- - f3fix requires version 0 of the library libparted to compile.
195 -- On Ubuntu, you can install this library with the following command:
196 --```
197 --sudo apt-get install libparted0-dev
198 -+sudo apt-get install libudev1 libudev-dev libparted0-dev
199 - ```
200 -
201 --### Compile experimental applications
202 -+### Compile the extra applications
203 -
204 - ```
205 --make experimental
206 -+make extra
207 - ```
208 -
209 - NOTES:
210 -- - Experimental software might compile on non-Linux platforms, but
211 -- there is no guarantee given that they are only tested on Linux.
212 -- - Please do not e-mail me saying that you want an experimental software
213 -+ - The extra applications are only compiled and tested on Linux platform.
214 -+ - Please do not e-mail me saying that you want the extra applications
215 - to run on your platform; I already know that.
216 -- - If you want experimental software to run on your platform,
217 -+ - If you want the extra applications to run on your platform,
218 - help to port them, or find someone that can port them for you.
219 -- If you do port the software, please send me a patch to help others.
220 -- - Currently, f3probe, f3brew, and f3fix are experimental.
221 -+ If you do port any of them, please send me a patch to help others.
222 -+ - The extra applications are f3probe, f3brew, and f3fix.
223 -
224 -
225 - ## Use example of f3write/f3read
226
227 diff --git a/sys-block/f3/files/f3-6.0-fix-compiler-warnings_f3probe.patch b/sys-block/f3/files/f3-6.0-fix-compiler-warnings_f3probe.patch
228 deleted file mode 100644
229 index 739488b53f9..00000000000
230 --- a/sys-block/f3/files/f3-6.0-fix-compiler-warnings_f3probe.patch
231 +++ /dev/null
232 @@ -1,50 +0,0 @@
233 -From 77d2ceb374ff70b64e95a41f0e05486575147b53 Mon Sep 17 00:00:00 2001
234 -From: Michel Machado <michel@××××××××××××.br>
235 -Date: Mon, 4 Jan 2016 13:49:05 -0500
236 -Subject: [PATCH] f3probe: avoid compiler warning
237 -MIME-Version: 1.0
238 -Content-Type: text/plain; charset=UTF-8
239 -Content-Transfer-Encoding: 8bit
240 -
241 -When using -O2, GCC was issuing the following warning:
242 -
243 -cc -O2 -std=c99 -Wall -Wextra -pedantic -MMD -ggdb -c -o f3probe.o f3probe.c
244 -f3probe.c: In function ‘main’:
245 -f3probe.c:446:13: warning: ‘sdev’ may be used uninitialized in this function [-Wmaybe-uninitialized]
246 - sdev_flush(sdev);
247 - ^
248 -f3probe.c:369:30: note: ‘sdev’ was declared here
249 - struct device *dev, *pdev, *sdev;
250 - ^
251 -
252 -NOTE: The warning was wrong.
253 - GCC could not follow that @args->save being true implied
254 - @sdev to not be NULL.
255 -
256 -This patch addresses one of the issues discussed here:
257 -https://github.com/AltraMayor/f3/issues/34
258 ----
259 - f3probe.c | 3 ++-
260 - 1 file changed, 2 insertions(+), 1 deletion(-)
261 -
262 -diff --git a/f3probe.c b/f3probe.c
263 -index e647d7c..9f214ab 100644
264 ---- a/f3probe.c
265 -+++ b/f3probe.c
266 -@@ -393,6 +393,7 @@ static int test_device(struct args *args)
267 - pdev = NULL;
268 - }
269 -
270 -+ sdev = NULL;
271 - if (args->save) {
272 - sdev = create_safe_device(dev,
273 - probe_device_max_blocks(dev), args->min_mem);
274 -@@ -434,7 +435,7 @@ static int test_device(struct args *args)
275 - &read_count, &read_time_us,
276 - &write_count, &write_time_us,
277 - &reset_count, &reset_time_us);
278 -- if (args->save) {
279 -+ if (sdev) {
280 - uint64_t very_last_pos = real_size_byte >> block_order;
281 - printf("Probe finished, recovering blocks...");
282 - fflush(stdout);
283
284 diff --git a/sys-block/f3/files/f3-6.0-fix-compiler-warnings_f3read.patch b/sys-block/f3/files/f3-6.0-fix-compiler-warnings_f3read.patch
285 deleted file mode 100644
286 index 0e4f61fca81..00000000000
287 --- a/sys-block/f3/files/f3-6.0-fix-compiler-warnings_f3read.patch
288 +++ /dev/null
289 @@ -1,88 +0,0 @@
290 -From 52e252f5d6dc6d10fd85a45b0774bb0b29d5f989 Mon Sep 17 00:00:00 2001
291 -From: Michel Machado <michel@××××××××××××.br>
292 -Date: Mon, 4 Jan 2016 13:22:18 -0500
293 -Subject: [PATCH] f3read: avoid compiler warning
294 -MIME-Version: 1.0
295 -Content-Type: text/plain; charset=UTF-8
296 -Content-Transfer-Encoding: 8bit
297 -
298 -When using -O2, GCC was issuing the following warning:
299 -
300 -cc -O2 -std=c99 -Wall -Wextra -pedantic -MMD -ggdb -c -o f3read.o f3read.c
301 -f3read.c: In function ‘validate_file’:
302 -f3read.c:95:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
303 - offset = *((uint64_t *) sector);
304 - ^
305 ----
306 - f3read.c | 28 ++++++++++++----------------
307 - 1 file changed, 12 insertions(+), 16 deletions(-)
308 -
309 -diff --git a/f3read.c b/f3read.c
310 -index 1514365..2dc6942 100644
311 ---- a/f3read.c
312 -+++ b/f3read.c
313 -@@ -42,12 +42,12 @@ static void validate_file(const char *path, int number,
314 - {
315 - char *full_fn;
316 - const char *filename;
317 -- uint8_t sector[SECTOR_SIZE], *p, *ptr_end;
318 -+ const int num_int64 = SECTOR_SIZE >> 3;
319 -+ uint64_t sector[num_int64];
320 - FILE *f;
321 - int fd;
322 -- int offset_match, error_count;
323 - size_t sectors_read;
324 -- uint64_t offset, expected_offset;
325 -+ uint64_t expected_offset;
326 - int final_errno;
327 - struct timeval t1, t2;
328 - /* Progress time. */
329 -@@ -84,32 +84,24 @@ static void validate_file(const char *path, int number,
330 - /* Help the kernel to help us. */
331 - assert(!posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL));
332 -
333 -- ptr_end = sector + SECTOR_SIZE;
334 - sectors_read = fread(sector, SECTOR_SIZE, 1, f);
335 - final_errno = errno;
336 - expected_offset = (uint64_t)number * GIGABYTES;
337 - while (sectors_read > 0) {
338 - uint64_t rn;
339 -+ int error_count, i;
340 -
341 - assert(sectors_read == 1);
342 -- offset = *((uint64_t *) sector);
343 -- offset_match = offset == expected_offset;
344 -
345 -- rn = offset;
346 -- p = sector + sizeof(offset);
347 -+ rn = sector[0];
348 - error_count = 0;
349 -- for (; error_count <= TOLERANCE && p < ptr_end;
350 -- p += sizeof(rn)) {
351 -+ for (i = 1; error_count <= TOLERANCE && i < num_int64; i++) {
352 - rn = random_number(rn);
353 -- if (rn != *((__typeof__(rn) *) p))
354 -+ if (rn != sector[i])
355 - error_count++;
356 - }
357 -
358 -- sectors_read = fread(sector, SECTOR_SIZE, 1, f);
359 -- final_errno = errno;
360 -- expected_offset += SECTOR_SIZE;
361 --
362 -- if (offset_match) {
363 -+ if (expected_offset == sector[0]) {
364 - if (error_count == 0)
365 - (*ptr_ok)++;
366 - else if (error_count <= TOLERANCE)
367 -@@ -121,6 +113,10 @@ static void validate_file(const char *path, int number,
368 - else
369 - (*ptr_corrupted)++;
370 -
371 -+ sectors_read = fread(sector, SECTOR_SIZE, 1, f);
372 -+ final_errno = errno;
373 -+ expected_offset += SECTOR_SIZE;
374 -+
375 - if (progress) {
376 - struct timeval pt2;
377 - assert(!gettimeofday(&pt2, NULL));
378
379 diff --git a/sys-block/f3/files/f3-6.0-respect-ldflags.patch b/sys-block/f3/files/f3-6.0-respect-ldflags.patch
380 deleted file mode 100644
381 index 4d42ea8318d..00000000000
382 --- a/sys-block/f3/files/f3-6.0-respect-ldflags.patch
383 +++ /dev/null
384 @@ -1,40 +0,0 @@
385 -From 70962dcfaa41ca390f6f077cc64312fb879b7eb4 Mon Sep 17 00:00:00 2001
386 -From: Grazvydas Ignotas <notasas@×××××.com>
387 -Date: Sat, 12 Mar 2016 17:39:05 +0200
388 -Subject: [PATCH] allow users to specify linker flags
389 -
390 -Traditionally LDFLAGS is used for this, it's what I've tried first
391 -but it wasn't accepted.
392 ----
393 - Makefile | 10 +++++-----
394 - 1 file changed, 5 insertions(+), 5 deletions(-)
395 -
396 -diff --git a/Makefile b/Makefile
397 -index 404bc17..46853f5 100644
398 ---- a/Makefile
399 -+++ b/Makefile
400 -@@ -23,19 +23,19 @@ install-experimental: experimental
401 - $(INSTALL) -oroot -groot -m755 $(EXPERIMENTAL_TARGETS) $(PREFIX)/bin
402 -
403 - f3write: utils.o f3write.o
404 -- $(CC) -o $@ $^ -lm
405 -+ $(CC) -o $@ $^ $(LDFLAGS) -lm
406 -
407 - f3read: utils.o f3read.o
408 -- $(CC) -o $@ $^
409 -+ $(CC) -o $@ $^ $(LDFLAGS)
410 -
411 - f3probe: libutils.o libdevs.o libprobe.o f3probe.o
412 -- $(CC) -o $@ $^ -lm -ludev
413 -+ $(CC) -o $@ $^ $(LDFLAGS) -lm -ludev
414 -
415 - f3brew: libutils.o libdevs.o f3brew.o
416 -- $(CC) -o $@ $^ -lm -ludev
417 -+ $(CC) -o $@ $^ $(LDFLAGS) -lm -ludev
418 -
419 - f3fix: libutils.o f3fix.o
420 -- $(CC) -o $@ $^ -lparted
421 -+ $(CC) -o $@ $^ $(LDFLAGS) -lparted
422 -
423 - -include *.d
424 -
425
426 diff --git a/sys-block/f3/files/f3-6.0-upstream-issue-44.patch b/sys-block/f3/files/f3-6.0-upstream-issue-44.patch
427 deleted file mode 100644
428 index 605b6b3ea66..00000000000
429 --- a/sys-block/f3/files/f3-6.0-upstream-issue-44.patch
430 +++ /dev/null
431 @@ -1,25 +0,0 @@
432 -From a754e9cf29415d110c4fe6fb1fe0d060d765a73e Mon Sep 17 00:00:00 2001
433 -From: Michel Machado <michel@××××××××××××.br>
434 -Date: Thu, 19 May 2016 08:39:36 -0400
435 -Subject: [PATCH] f3read: add "#include <limits.h>" to f3read.c
436 -
437 -This addresses a compiling issue on Macs.
438 -
439 -@jksinton found and solved this problem:
440 -https://github.com/AltraMayor/f3/issues/44
441 ----
442 - f3read.c | 1 +
443 - 1 file changed, 1 insertion(+)
444 -
445 -diff --git a/f3read.c b/f3read.c
446 -index 0842071..c5c20d2 100644
447 ---- a/f3read.c
448 -+++ b/f3read.c
449 -@@ -5,6 +5,7 @@
450 - #include <stdint.h>
451 - #include <inttypes.h>
452 - #include <stdio.h>
453 -+#include <limits.h>
454 - #include <string.h>
455 - #include <stdlib.h>
456 - #include <errno.h>
457
458 diff --git a/sys-block/f3/files/f3-6.0-use-argp_parse.patch b/sys-block/f3/files/f3-6.0-use-argp_parse.patch
459 deleted file mode 100644
460 index b73fbff8c7a..00000000000
461 --- a/sys-block/f3/files/f3-6.0-use-argp_parse.patch
462 +++ /dev/null
463 @@ -1,417 +0,0 @@
464 -From fb187b4c710714a56d74af8a50adccd6118445e7 Mon Sep 17 00:00:00 2001
465 -From: zwpwjwtz <zwpwjwtz@×××.com>
466 -Date: Tue, 29 Mar 2016 15:36:04 +0800
467 -Subject: [PATCH] Replace parse_args() with argp_parse() from argp.h
468 -
469 ----
470 - f3read.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
471 - f3write.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
472 - utils.c | 92 ----------------------------------------------------
473 - utils.h | 5 ---
474 - 4 files changed, 200 insertions(+), 113 deletions(-)
475 -
476 -diff --git a/f3read.c b/f3read.c
477 -index 2dc6942..683232d 100644
478 ---- a/f3read.c
479 -+++ b/f3read.c
480 -@@ -12,8 +12,100 @@
481 - #include <unistd.h>
482 - #include <err.h>
483 - #include <sys/time.h>
484 -+#include <limits.h>
485 -+#include <argp.h>
486 -
487 - #include "utils.h"
488 -+#include "version.h"
489 -+
490 -+/* Argp's global variables. */
491 -+const char *argp_program_version = "F3 Read " F3_STR_VERSION;
492 -+
493 -+/* Arguments. */
494 -+static char adoc[] = "<PATH>";
495 -+
496 -+static char doc[] = "F3 Read -- test real flash memory capacity\n"
497 -+ "Copyright (C) 2010 Digirati Internet LTDA.\n"
498 -+ "This is free software; see the source for copying conditions.\n";
499 -+
500 -+static struct argp_option options[] = {
501 -+ {"start-at", 's', "NUM", 0,
502 -+ "Disk type of the partition table", 0},
503 -+ {"end-at", 'e', "NUM", 0,
504 -+ "Type of the file system of the partition", 0},
505 -+ {"progress", 'p', NULL, 0,
506 -+ "Show progress of the operation (default)", 0},
507 -+ { 0 }
508 -+};
509 -+
510 -+struct args {
511 -+ long start_at;
512 -+ long end_at;
513 -+ int show_progress;
514 -+ const char *dev_path;
515 -+};
516 -+
517 -+static error_t parse_opt(int key, char *arg, struct argp_state *state)
518 -+{
519 -+ struct args *args = state->input;
520 -+ char *endptr;
521 -+
522 -+ switch (key) {
523 -+ case 's':
524 -+ args->start_at = strtol(arg, &endptr, 10);
525 -+ if (*endptr != '\0')
526 -+ argp_error(state, "Option --start-at must be a number");
527 -+ break;
528 -+
529 -+ case 'e':
530 -+ args->end_at = strtol(arg, &endptr, 10);
531 -+ if (*endptr != '\0')
532 -+ argp_error(state, "Option --end-at must be a number");
533 -+ break;
534 -+
535 -+ case 'p':
536 -+ args->show_progress = 1;
537 -+ break;
538 -+
539 -+ case ARGP_KEY_INIT:
540 -+ args->dev_path = NULL;
541 -+ args->start_at = 0;
542 -+ args->end_at = LONG_MAX;
543 -+ args->show_progress = 0;
544 -+ break;
545 -+
546 -+ case ARGP_KEY_ARG:
547 -+ if (args->dev_path)
548 -+ argp_error(state,
549 -+ "Wrong number of arguments; only one is allowed");
550 -+ args->dev_path = arg;
551 -+ break;
552 -+
553 -+ case ARGP_KEY_END:
554 -+ if (!args->dev_path)
555 -+ argp_error(state,
556 -+ "The disk path was not specified");
557 -+
558 -+ if (args->start_at < 0)
559 -+ argp_error(state,
560 -+ "Option --start-at must be greater than 0");
561 -+
562 -+ if (args->end_at < 0)
563 -+ argp_error(state,
564 -+ "Option --end-at must be greater than 0");
565 -+
566 -+ if (args->start_at > args->end_at)
567 -+ argp_error(state,
568 -+ "Option --start-at must be less or equal to option --end-at");
569 -+ break;
570 -+
571 -+ default:
572 -+ return ARGP_ERR_UNKNOWN;
573 -+ }
574 -+ return 0;
575 -+}
576 -+
577 -+static struct argp argp = {options, parse_opt, adoc, doc, NULL, NULL, NULL};
578 -
579 - static inline void update_dt(struct timeval *dt, const struct timeval *t1,
580 - const struct timeval *t2)
581 -@@ -228,20 +320,21 @@ static void iterate_files(const char *path, const long *files,
582 -
583 - int main(int argc, char **argv)
584 - {
585 -- long start_at, end_at;
586 -- const char *path;
587 - const long *files;
588 -- int progress;
589 -+ struct args args;
590 - int rc;
591 --
592 -- rc = parse_args("read", argc, argv, &start_at, &end_at, &path);
593 -+ rc = argp_parse(&argp, argc, argv, 0, NULL, &args);
594 - if (rc)
595 - return rc;
596 -
597 -- files = ls_my_files(path, start_at, end_at);
598 - /* If stdout isn't a terminal, supress progress. */
599 -- progress = isatty(STDOUT_FILENO);
600 -- iterate_files(path, files, start_at, end_at, progress);
601 -+ if (!args.show_progress)
602 -+ args.show_progress = isatty(STDOUT_FILENO);
603 -+
604 -+ files = ls_my_files(args.dev_path, args.start_at, args.end_at);
605 -+ /* If stdout isn't a terminal, supress progress. */
606 -+
607 -+ iterate_files(args.dev_path, files, args.start_at, args.end_at, args.show_progress);
608 - free((void *)files);
609 - return 0;
610 - }
611 -diff --git a/f3write.c b/f3write.c
612 -index b964059..bfef27e 100644
613 ---- a/f3write.c
614 -+++ b/f3write.c
615 -@@ -15,8 +15,99 @@
616 - #include <unistd.h>
617 - #include <err.h>
618 - #include <math.h>
619 -+#include <argp.h>
620 -
621 - #include "utils.h"
622 -+#include "version.h"
623 -+
624 -+/* Argp's global variables. */
625 -+const char *argp_program_version = "F3 Write " F3_STR_VERSION;
626 -+
627 -+/* Arguments. */
628 -+static char adoc[] = "<PATH>";
629 -+
630 -+static char doc[] = "F3 Write -- test real flash memory capacity\n"
631 -+ "Copyright (C) 2010 Digirati Internet LTDA.\n"
632 -+ "This is free software; see the source for copying conditions.\n";
633 -+
634 -+static struct argp_option options[] = {
635 -+ {"start-at", 's', "NUM", 0,
636 -+ "Disk type of the partition table", 0},
637 -+ {"end-at", 'e', "NUM", 0,
638 -+ "Type of the file system of the partition", 0},
639 -+ {"progress", 'p', NULL, 0,
640 -+ "Show progress of the operation (default)", 0},
641 -+ { 0 }
642 -+};
643 -+
644 -+struct args {
645 -+ long start_at;
646 -+ long end_at;
647 -+ int show_progress;
648 -+ const char *dev_path;
649 -+};
650 -+
651 -+static error_t parse_opt(int key, char *arg, struct argp_state *state)
652 -+{
653 -+ struct args *args = state->input;
654 -+ char *endptr;
655 -+
656 -+ switch (key) {
657 -+ case 's':
658 -+ args->start_at = strtol(arg, &endptr, 10);
659 -+ if (*endptr != '\0')
660 -+ argp_error(state, "Option --start-at must be a number");
661 -+ break;
662 -+
663 -+ case 'e':
664 -+ args->end_at = strtol(arg, &endptr, 10);
665 -+ if (*endptr != '\0')
666 -+ argp_error(state, "Option --end-at must be a number");
667 -+ break;
668 -+
669 -+ case 'p':
670 -+ args->show_progress = 1;
671 -+ break;
672 -+
673 -+ case ARGP_KEY_INIT:
674 -+ args->dev_path = NULL;
675 -+ args->start_at = 0;
676 -+ args->end_at = LONG_MAX;
677 -+ args->show_progress = 0;
678 -+ break;
679 -+
680 -+ case ARGP_KEY_ARG:
681 -+ if (args->dev_path)
682 -+ argp_error(state,
683 -+ "Wrong number of arguments; only one is allowed");
684 -+ args->dev_path = arg;
685 -+ break;
686 -+
687 -+ case ARGP_KEY_END:
688 -+ if (!args->dev_path)
689 -+ argp_error(state,
690 -+ "The disk path was not specified");
691 -+
692 -+ if (args->start_at < 0)
693 -+ argp_error(state,
694 -+ "Option --start-at must be greater than 0");
695 -+
696 -+ if (args->end_at < 0)
697 -+ argp_error(state,
698 -+ "Option --end-at must be greater than 0");
699 -+
700 -+ if (args->start_at > args->end_at)
701 -+ argp_error(state,
702 -+ "Option --start-at must be less or equal to option --end-at");
703 -+ break;
704 -+
705 -+ default:
706 -+ return ARGP_ERR_UNKNOWN;
707 -+ }
708 -+ return 0;
709 -+}
710 -+
711 -+static struct argp argp = {options, parse_opt, adoc, doc, NULL, NULL, NULL};
712 -
713 - static uint64_t fill_buffer(void *buf, size_t size, uint64_t offset)
714 - {
715 -@@ -464,17 +555,17 @@ static void unlink_old_files(const char *path, long start_at, long end_at)
716 -
717 - int main(int argc, char **argv)
718 - {
719 -- long start_at, end_at;
720 -- const char *path;
721 -- int progress;
722 -+ struct args args;
723 - int rc;
724 --
725 -- rc = parse_args("write", argc, argv, &start_at, &end_at, &path);
726 -+ rc = argp_parse(&argp, argc, argv, 0, NULL, &args);
727 - if (rc)
728 - return rc;
729 -
730 -- unlink_old_files(path, start_at, end_at);
731 -+ unlink_old_files(args.dev_path, args.start_at, args.end_at);
732 -+
733 - /* If stdout isn't a terminal, supress progress. */
734 -- progress = isatty(STDOUT_FILENO);
735 -- return fill_fs(path, start_at, end_at, progress);
736 -+ if (!args.show_progress)
737 -+ args.show_progress = isatty(STDOUT_FILENO);
738 -+
739 -+ return fill_fs(args.dev_path, args.start_at, args.end_at, args.show_progress);
740 - }
741 -diff --git a/utils.c b/utils.c
742 -index a30ea3b..6aaceff 100644
743 ---- a/utils.c
744 -+++ b/utils.c
745 -@@ -13,13 +13,11 @@
746 - #include <string.h>
747 - #include <ctype.h>
748 - #include <assert.h>
749 --#include <limits.h>
750 - #include <sys/types.h>
751 - #include <dirent.h>
752 - #include <errno.h>
753 - #include <err.h>
754 -
755 --#include "version.h"
756 - #include "utils.h"
757 -
758 - const char *adjust_unit(double *ptr_bytes)
759 -@@ -60,87 +58,6 @@ char *full_fn_from_number(const char **filename, const char *path, long num)
760 - return str;
761 - }
762 -
763 --/* Parse @param and return the start-at parameter.
764 -- * The string must be of the format "--start-at=NUM"; otherwise it returns -1.
765 -- */
766 --#define START_AT_TEXT "--start-at="
767 --#define END_AT_TEXT "--end-at="
768 --
769 --static inline int is_param(const char *text, const char *param)
770 --{
771 -- return !strncmp(param, text, strlen(text));
772 --}
773 --
774 --static long parse_long_param(const char *param)
775 --{
776 -- char *endptr;
777 -- long value;
778 --
779 -- /* Skip text. */
780 -- while (*param != '=') {
781 -- if (*param == '\0')
782 -- return -1;
783 -- param++;
784 -- }
785 -- param++; /* Skip '='. */
786 --
787 -- value = strtol(param, &endptr, 10);
788 -- if (*endptr != '\0')
789 -- return -1;
790 --
791 -- return (value <= 0 || value == LONG_MAX) ? -1 : value - 1;
792 --}
793 --
794 --static int parse_param(const char *param, long *pstart_at, long *pend_at)
795 --{
796 -- if (is_param(START_AT_TEXT, param))
797 -- *pstart_at = parse_long_param(param);
798 -- else if (is_param(END_AT_TEXT, param))
799 -- *pend_at = parse_long_param(param);
800 -- else
801 -- return 1;
802 -- return 0;
803 --}
804 --
805 --int parse_args(const char *name, int argc, char **argv,
806 -- long *pstart_at, long *pend_at, const char **ppath)
807 --{
808 -- *pstart_at = 0;
809 -- *pend_at = LONG_MAX - 1;
810 --
811 -- switch (argc) {
812 -- case 2:
813 -- *ppath = argv[1];
814 -- break;
815 --
816 -- case 3:
817 -- if (parse_param(argv[1], pstart_at, pend_at))
818 -- goto error;
819 -- *ppath = argv[2];
820 -- break;
821 --
822 -- case 4:
823 -- if (parse_param(argv[1], pstart_at, pend_at))
824 -- goto error;
825 -- if (parse_param(argv[2], pstart_at, pend_at))
826 -- goto error;
827 -- *ppath = argv[3];
828 -- break;
829 --
830 -- default:
831 -- goto error;
832 -- }
833 --
834 -- if (*pstart_at >= 0 && *pend_at >= 0 && *pstart_at <= *pend_at)
835 -- return 0;
836 --
837 --error:
838 -- print_header(stderr, name);
839 -- fprintf(stderr, "Usage: f3%s [%sNUM] [%sNUM] <PATH>\n",
840 -- name, START_AT_TEXT, END_AT_TEXT);
841 -- return 1;
842 --}
843 --
844 - static long number_from_filename(const char *filename)
845 - {
846 - const char *p;
847 -@@ -218,15 +135,6 @@ const long *ls_my_files(const char *path, long start_at, long end_at)
848 - return ret;
849 - }
850 -
851 --void print_header(FILE *f, const char *name)
852 --{
853 -- fprintf(f,
854 -- "F3 %s " F3_STR_VERSION "\n"
855 -- "Copyright (C) 2010 Digirati Internet LTDA.\n"
856 -- "This is free software; see the source for copying conditions.\n"
857 -- "\n", name);
858 --}
859 --
860 - #if __APPLE__ && __MACH__
861 -
862 - /* This function is a _rough_ approximation of fdatasync(2). */
863 -diff --git a/utils.h b/utils.h
864 -index 6b7c92f..4fdbce2 100644
865 ---- a/utils.h
866 -+++ b/utils.h
867 -@@ -22,13 +22,8 @@ static inline long delay_ms(const struct timeval *t1, const struct timeval *t2)
868 - (t2->tv_usec - t1->tv_usec) / 1000;
869 - }
870 -
871 --int parse_args(const char *name, int argc, char **argv,
872 -- long *pstart_at, long *pend_at, const char **ppath);
873 --
874 - const long *ls_my_files(const char *path, long start_at, long end_at);
875 -
876 --void print_header(FILE *f, const char *name);
877 --
878 - static inline uint64_t random_number(uint64_t prv_number)
879 - {
880 - return prv_number * 4294967311ULL + 17;