Skip to content

Commit 69cc2ec

Browse files
committed
wipefs: support suffixes for --offset
Signed-off-by: Karel Zak <kzak@redhat.com>
1 parent 8ab912c commit 69cc2ec

3 files changed

Lines changed: 10 additions & 12 deletions

File tree

misc-utils/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ blkid_LDADD = $(ul_libblkid_la)
4040
blkid_CFLAGS = $(AM_CFLAGS) -I$(ul_libblkid_incdir)
4141
findfs_LDADD = $(ul_libblkid_la)
4242
findfs_CFLAGS = $(AM_CFLAGS) -I$(ul_libblkid_incdir)
43+
wipefs_SOURCES = wipefs.c ../lib/strtosize.c
4344
wipefs_LDADD = $(ul_libblkid_la)
4445
wipefs_CFLAGS = $(AM_CFLAGS) -I$(ul_libblkid_incdir)
4546
if HAVE_STATIC_BLKID

misc-utils/wipefs.8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ Causes everything to be done except for the write() call.
3131
Specifies location (in bytes) of the signature which should be erased from the
3232
device. The offset number may include a "0x" prefix, and then the number will be
3333
read as a hex value. It is possible to specify multiple -o options.
34+
35+
The \fIoffset\fR argument may be followed by binary (2^N) suffixes KiB, MiB,
36+
GiB, TiB, PiB and EiB (the "iB" is optional, e.g. "K" has the same meaning as
37+
"KiB") or decimal (10^N) suffixes KB, MB, GB, PB and EB.
3438
.IP "\fB\-p, \-\-parsable\fP"
3539
Print out in parsable instead of printable format. Encode all potentially unsafe
3640
characters of a string to the corresponding hex value prefixed by '\\x'.

misc-utils/wipefs.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <blkid.h>
3535

3636
#include "nls.h"
37+
#include "strtosize.h"
3738

3839
struct wipe_desc {
3940
loff_t offset; /* magic string offset */
@@ -305,22 +306,14 @@ do_wipe(struct wipe_desc *wp, const char *fname, int noact)
305306
static loff_t
306307
strtoll_offset(const char *str)
307308
{
308-
char *end = NULL;
309-
loff_t off;
309+
uintmax_t sz;
310310

311-
errno = 0;
312-
off = strtoll(str, &end, 0);
313-
314-
if ((errno == ERANGE && (off == LLONG_MAX || off == LONG_MIN)) ||
315-
(errno != 0 && off == 0))
316-
err(EXIT_FAILURE, _("invalid offset '%s' value specified"), str);
317-
318-
if (*end != '\0')
311+
if (strtosize(str, &sz))
319312
errx(EXIT_FAILURE, _("invalid offset '%s' value specified"), str);
320-
321-
return off;
313+
return sz;
322314
}
323315

316+
324317
static void __attribute__((__noreturn__))
325318
usage(FILE *out)
326319
{

0 commit comments

Comments
 (0)