diff options
author | Karel Zak <kzak@redhat.com> | 2010-03-30 13:58:16 +0200 |
---|---|---|
committer | Karel Zak <kzak@redhat.com> | 2010-03-30 14:42:42 +0200 |
commit | 8ab912cfa68bb5b3680516a230b694cf0305a955 (patch) | |
tree | ab25941aabaa8cccbc3907e26fc630d348224400 /misc-utils | |
parent | cf8de26afe0db5c330f4c913d736dc1f840add88 (diff) | |
download | util-linux-old-8ab912cfa68bb5b3680516a230b694cf0305a955.tar.gz |
blkid: support suffixes for -O <offset> and -S <size>
for example: blkid -p -O 17816085KiB /dev/sda
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils')
-rw-r--r-- | misc-utils/Makefile.am | 2 | ||||
-rw-r--r-- | misc-utils/blkid.8 | 7 | ||||
-rw-r--r-- | misc-utils/blkid.c | 21 |
3 files changed, 21 insertions, 9 deletions
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 <blkid.h> #include "ismounted.h" +#include "strtosize.h" const char *progname = "blkid"; @@ -73,8 +74,8 @@ static void usage(int error) " <dev> 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 <bytes> overwrite device size\n" - " -O <bytes> probe at the given offset\n" + " -S <size> overwrite device size\n" + " -O <offset> probe at the given offset\n" " -u <list> filter by \"usage\" (e.g. -u filesystem,raid)\n" " -n <list> 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) { /* |