From 588c2685f4d87b9a620c77bc7bc27fdaf8a915f9 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 30 Mar 2010 16:15:44 +0200 Subject: [PATCH] mount: support suffixes for offset= and sizelimit= Note that the offset= and sizelimit= values in /etc/mtab are always in the final format -- it means without suffix). Signed-off-by: Karel Zak --- mount/Makefile.am | 2 +- mount/mount.c | 46 +++++++++++++++++++++++----------------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/mount/Makefile.am b/mount/Makefile.am index b20fe1b3..8465d11e 100644 --- a/mount/Makefile.am +++ b/mount/Makefile.am @@ -26,7 +26,7 @@ ldadd_static = cflags_common = $(AM_CFLAGS) ldflags_static = -all-static -mount_SOURCES = mount.c $(srcs_mount) ../lib/setproctitle.c +mount_SOURCES = mount.c $(srcs_mount) ../lib/setproctitle.c ../lib/strtosize.c mount_CFLAGS = $(SUID_CFLAGS) $(cflags_common) mount_LDFLAGS = $(SUID_LDFLAGS) $(AM_LDFLAGS) mount_LDADD = $(ldadd_common) diff --git a/mount/mount.c b/mount/mount.c index f75a1fbd..7a5ea06d 100644 --- a/mount/mount.c +++ b/mount/mount.c @@ -41,6 +41,7 @@ #include "env.h" #include "nls.h" #include "blkdev.h" +#include "strtosize.h" #define DO_PS_FIDDLING @@ -1070,12 +1071,27 @@ is_mounted_same_loopfile(const char *node0, const char *loopfile, unsigned long return res; } +static int +parse_offset(const char **opt, uintmax_t *val) +{ + char *tmp; + + if (strtosize(*opt, val)) + return -1; + + tmp = xmalloc(32); + snprintf(tmp, 32, "%jd", *val); + my_free(*opt); + *opt = tmp; + return 0; +} + static int loop_check(const char **spec, const char **type, int *flags, int *loop, const char **loopdev, const char **loopfile, const char *node) { int looptype; - unsigned long long offset = 0, sizelimit = 0; + uintmax_t offset = 0, sizelimit = 0; /* * In the case of a loop mount, either type is of the form lo@/dev/loop5 @@ -1127,33 +1143,17 @@ loop_check(const char **spec, const char **type, int *flags, } else { int loop_opts = SETLOOP_AUTOCLEAR; /* always attempt autoclear */ int res; - char *endptr = NULL; - long long xnum; if (*flags & MS_RDONLY) loop_opts |= SETLOOP_RDONLY; - if (opt_offset) { - errno = 0; - xnum = strtoll(opt_offset, &endptr, 0); - if ((endptr && *endptr) || - (errno != 0 && (xnum == LLONG_MAX || xnum == 0)) || - xnum < 0) { - error(_("mount: invalid offset '%s' specified"), opt_offset); - return EX_FAIL; - } - offset = xnum; + if (opt_offset && parse_offset(&opt_offset, &offset)) { + error(_("mount: invalid offset '%s' specified"), opt_offset); + return EX_FAIL; } - if (opt_sizelimit) { - errno = 0; - xnum = strtoll(opt_sizelimit, &endptr, 0); - if ((endptr && *endptr) || - (errno != 0 && (xnum == LLONG_MAX || xnum == 0)) || - xnum < 0) { - error(_("mount: invalid sizelimit '%s' specified"), opt_sizelimit); - return EX_FAIL; - } - sizelimit = xnum; + if (opt_sizelimit && parse_offset(&opt_sizelimit, &sizelimit)) { + error(_("mount: invalid sizelimit '%s' specified"), opt_sizelimit); + return EX_FAIL; } if (is_mounted_same_loopfile(node, *loopfile, offset)) { -- 2.39.5