From: Karel Zak Date: Tue, 30 Mar 2010 12:05:58 +0000 (+0200) Subject: wipefs: support suffixes for --offset X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=69cc2ec06158d7849e6ae8c95f944f044e7b380d;p=util-linux wipefs: support suffixes for --offset Signed-off-by: Karel Zak --- diff --git a/misc-utils/Makefile.am b/misc-utils/Makefile.am index c4194786..b5b7daa6 100644 --- a/misc-utils/Makefile.am +++ b/misc-utils/Makefile.am @@ -40,6 +40,7 @@ blkid_LDADD = $(ul_libblkid_la) blkid_CFLAGS = $(AM_CFLAGS) -I$(ul_libblkid_incdir) findfs_LDADD = $(ul_libblkid_la) findfs_CFLAGS = $(AM_CFLAGS) -I$(ul_libblkid_incdir) +wipefs_SOURCES = wipefs.c ../lib/strtosize.c wipefs_LDADD = $(ul_libblkid_la) wipefs_CFLAGS = $(AM_CFLAGS) -I$(ul_libblkid_incdir) if HAVE_STATIC_BLKID diff --git a/misc-utils/wipefs.8 b/misc-utils/wipefs.8 index 109c0a6b..973f2ef2 100644 --- a/misc-utils/wipefs.8 +++ b/misc-utils/wipefs.8 @@ -31,6 +31,10 @@ Causes everything to be done except for the write() call. Specifies location (in bytes) of the signature which should be erased from the device. The offset number may include a "0x" prefix, and then the number will be read as a hex value. It is possible to specify multiple -o options. + +The \fIoffset\fR argument may be followed by binary (2^N) suffixes KiB, MiB, +GiB, TiB, PiB and EiB (the "iB" is optional, e.g. "K" has the same meaning as +"KiB") or decimal (10^N) suffixes KB, MB, GB, PB and EB. .IP "\fB\-p, \-\-parsable\fP" Print out in parsable instead of printable format. Encode all potentially unsafe characters of a string to the corresponding hex value prefixed by '\\x'. diff --git a/misc-utils/wipefs.c b/misc-utils/wipefs.c index 489105e4..7cee1e51 100644 --- a/misc-utils/wipefs.c +++ b/misc-utils/wipefs.c @@ -34,6 +34,7 @@ #include #include "nls.h" +#include "strtosize.h" struct wipe_desc { loff_t offset; /* magic string offset */ @@ -305,22 +306,14 @@ do_wipe(struct wipe_desc *wp, const char *fname, int noact) static loff_t strtoll_offset(const char *str) { - char *end = NULL; - loff_t off; + uintmax_t sz; - errno = 0; - off = strtoll(str, &end, 0); - - if ((errno == ERANGE && (off == LLONG_MAX || off == LONG_MIN)) || - (errno != 0 && off == 0)) - err(EXIT_FAILURE, _("invalid offset '%s' value specified"), str); - - if (*end != '\0') + if (strtosize(str, &sz)) errx(EXIT_FAILURE, _("invalid offset '%s' value specified"), str); - - return off; + return sz; } + static void __attribute__((__noreturn__)) usage(FILE *out) {