From ca1e1363e773202b5739e264e83703da8600ab0b Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 30 Mar 2010 14:40:33 +0200 Subject: [PATCH] losetup: support suffixes and hex numbers for --offset and --sizelimit Reported-By: Liu Aleaxander Signed-off-by: Karel Zak --- mount/Makefile.am | 2 +- mount/lomount.c | 16 ++++++++++------ mount/losetup.8 | 10 +++++++--- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/mount/Makefile.am b/mount/Makefile.am index 8ae87129..b20fe1b3 100644 --- a/mount/Makefile.am +++ b/mount/Makefile.am @@ -42,7 +42,7 @@ swapon_SOURCES = swapon.c swap_constants.h ../lib/linux_version.c \ swapon_CFLAGS = $(cflags_common) swapon_LDADD = $(ldadd_common) -losetup_SOURCES = lomount.c $(srcs_common) loop.h lomount.h +losetup_SOURCES = lomount.c $(srcs_common) loop.h lomount.h ../lib/strtosize.c losetup_CPPFLAGS = -DMAIN $(AM_CPPFLAGS) mount_static_LDADD = diff --git a/mount/lomount.c b/mount/lomount.c index 67712c61..6130be1d 100644 --- a/mount/lomount.c +++ b/mount/lomount.c @@ -881,6 +881,8 @@ find_unused_loop_device (void) { #include #include +#include "strtosize.h" + static void usage(void) { fprintf(stderr, _("\nUsage:\n" @@ -913,7 +915,7 @@ main(int argc, char **argv) { int showdev = 0; int ro = 0; int pfd = -1; - unsigned long long off, slimit; + uintmax_t off = 0, slimit = 0; struct option longopts[] = { { "all", 0, 0, 'a' }, { "set-capacity", 0, 0, 'c' }, @@ -936,8 +938,6 @@ main(int argc, char **argv) { textdomain(PACKAGE); capacity = delete = find = all = 0; - off = 0; - slimit = 0; assoc = offset = sizelimit = encryption = passfd = NULL; progname = argv[0]; @@ -1015,11 +1015,15 @@ main(int argc, char **argv) { usage(); } - if (offset && sscanf(offset, "%llu", &off) != 1) + if (offset && strtosize(offset, &off)) { + error(_("%s: invalid offset '%s' specified"), progname, offset); usage(); - - if (sizelimit && sscanf(sizelimit, "%llu", &slimit) != 1) + } + if (sizelimit && strtosize(sizelimit, &slimit)) { + error(_("%s: invalid sizelimit '%s' specified"), + progname, sizelimit); usage(); + } if (all) return show_used_loop_devices(); diff --git a/mount/losetup.8 b/mount/losetup.8 index 8ccab6ce..fe8b8b83 100644 --- a/mount/losetup.8 +++ b/mount/losetup.8 @@ -39,7 +39,7 @@ Setup loop device: .RB [ \-o .IR offset ] .RB [ \-\-sizelimit -.IR limit ] +.IR size ] .in +8 .RB [ \-p .IR pfd ] @@ -78,6 +78,10 @@ When the cryptoloop module is loaded (or compiled in), it uses number 18. This cryptoloop module will take the name of an arbitrary encryption type and find the module that knows how to perform that encryption. .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. + .IP "\fB\-a, \-\-all\fP" show status of all loop devices .IP "\fB\-c, \-\-set-capacity\fP \fIloopdev\fP @@ -98,8 +102,8 @@ show status of all loop devices associated with given .IP "\fB\-o, \-\-offset \fIoffset\fP" the data start is moved \fIoffset\fP bytes into the specified file or device -.IP "\fB\-\-sizelimit \fIlimit\fP" -the data end is set to no more than \fIsizelimit\fP bytes after the data start +.IP "\fB\-\-sizelimit \fIsize\fP" +the data end is set to no more than \fIsize\fP bytes after the data start .IP "\fB\-p, \-\-pass-fd \fInum\fP" read the passphrase from file descriptor with number .I num -- 2.39.5