From: Karel Zak Date: Tue, 30 Mar 2010 11:58:16 +0000 (+0200) Subject: blkid: support suffixes for -O and -S X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ab912cfa68bb5b3680516a230b694cf0305a955;p=util-linux blkid: support suffixes for -O and -S for example: blkid -p -O 17816085KiB /dev/sda Signed-off-by: Karel Zak --- diff --git a/misc-utils/Makefile.am b/misc-utils/Makefile.am index 8e1ea4fa..c4194786 100644 --- a/misc-utils/Makefile.am +++ b/misc-utils/Makefile.am @@ -35,7 +35,7 @@ endif if BUILD_LIBBLKID sbin_PROGRAMS += blkid findfs wipefs dist_man_MANS += blkid.8 findfs.8 wipefs.8 -blkid_SOURCES = blkid.c $(top_srcdir)/lib/ismounted.c +blkid_SOURCES = blkid.c $(top_srcdir)/lib/ismounted.c ../lib/strtosize.c blkid_LDADD = $(ul_libblkid_la) blkid_CFLAGS = $(AM_CFLAGS) -I$(ul_libblkid_incdir) findfs_LDADD = $(ul_libblkid_la) diff --git a/misc-utils/blkid.8 b/misc-utils/blkid.8 index 6990ad8f..a46b9f47 100644 --- a/misc-utils/blkid.8 +++ b/misc-utils/blkid.8 @@ -63,6 +63,9 @@ has two main forms of operation: either searching for a device with a specific NAME=value pair, or displaying NAME=value pairs for one or more devices. .SH OPTIONS +The \fIsize\fR and \fIoffset\fR arguments 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. .TP .BI \-c " cachefile" Read from @@ -146,7 +149,7 @@ and \fB-U\fR options vol_id compatible mode; usable in udev rules .RE .TP -.BI \-O " bytes" +.BI \-O " offset" Probe at the given offset (only useful with \fB-p\fR). .TP .BI \-p @@ -163,7 +166,7 @@ In order to just refresh the cache without showing any tokens, use .B "-s none" with no other options. .TP -.BI \-S " bytes" +.BI \-S " size" Overwrite device/file size (only useful with \fB-p\fR). .TP .BI \-t " NAME" = "value" diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c index 653af035..651deb3d 100644 --- a/misc-utils/blkid.c +++ b/misc-utils/blkid.c @@ -37,6 +37,7 @@ extern int optind; #include #include "ismounted.h" +#include "strtosize.h" const char *progname = "blkid"; @@ -73,8 +74,8 @@ static void usage(int error) " specify device(s) to probe (default: all devices)\n\n" "Low-level probing options:\n" " -p switch to low-level mode (bypass cache)\n" - " -S overwrite device size\n" - " -O probe at the given offset\n" + " -S overwrite device size\n" + " -O probe at the given offset\n" " -u filter by \"usage\" (e.g. -u filesystem,raid)\n" " -n filter by filesystem type (e.g. -n vfat,ext3)\n" "\n", @@ -630,7 +631,7 @@ int main(int argc, char **argv) int output_format = 0; int lookup = 0, gc = 0, lowprobe = 0, eval = 0; int c; - blkid_loff_t offset = 0, size = 0; + uintmax_t offset = 0, size = 0; show[0] = NULL; @@ -693,7 +694,10 @@ int main(int argc, char **argv) } break; case 'O': - offset = strtoll(optarg, NULL, 10); + if (strtosize(optarg, &offset)) + fprintf(stderr, + "Invalid offset '%s' specified\n", + optarg); break; case 'p': lowprobe++; @@ -707,7 +711,10 @@ int main(int argc, char **argv) show[numtag] = NULL; break; case 'S': - size = strtoll(optarg, NULL, 10); + if (strtosize(optarg, &size)) + fprintf(stderr, + "Invalid size '%s' specified\n", + optarg); break; case 't': if (search_type) { @@ -800,7 +807,9 @@ int main(int argc, char **argv) for (i = 0; i < numdev; i++) err = lowprobe_device(pr, devices[i], show, - output_format, offset, size); + output_format, + (blkid_loff_t) offset, + (blkid_loff_t) size); blkid_free_probe(pr); } else if (eval) { /*