Date: Sat, 9 Nov 2013 22:52:02 -0500 From: Eitan Adler <lists@eitanadler.com> To: scsi@freebsd.org Subject: mptutil, mfitil, expand_number Message-ID: <CAF6rxgkCkpS_iu8VXcUnqk0TG%2BMrbzvt55-QJ-ebTUrqJv8UHQ@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
Any thoughts? commit 20ad9d0a2bd9aea4aaf7c5ae925397 8ae0aed75c Author: Eitan Adler <lists@eitanadler.com> Date: Sat Nov 9 22:19:41 2013 -0500 Indicate that expand_number is case-insensitive. diff --git a/lib/libutil/expand_number.3 b/lib/libutil/expand_number.3 index f78223b..2f5871f 100644 --- a/lib/libutil/expand_number.3 +++ b/lib/libutil/expand_number.3 @@ -51,12 +51,13 @@ argument. The .Fn expand_number function +is case-insensitive and follows the SI power of two convention. .Pp The prefixes are: .Bl -column "Prefix" "Description" "1000000000000000000" -offset indent .It Sy "Prefix" Ta Sy "Description" Ta Sy "Multiplier" -.It Li k Ta No kilo Ta 1024 +.It Li K Ta No kilo Ta 1024 .It Li M Ta No mega Ta 1048576 .It Li G Ta No giga Ta 1073741824 .It Li T Ta No tera Ta 1099511627776 commit e5d0f01bcea9115bd27394ae27a295717597cf7b Author: Eitan Adler <lists@eitanadler.com> Date: Sat Nov 9 22:09:17 2013 -0500 Convert from a hand-rolled function to expand_number. diff --git a/usr.sbin/mptutil/mpt_config.c b/usr.sbin/mptutil/mpt_config.c index 17b9945..ae66258 100644 --- a/usr.sbin/mptutil/mpt_config.c +++ b/usr.sbin/mptutil/mpt_config.c @@ -43,6 +43,7 @@ __RCSID("$FreeBSD$"); #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sysexits.h> #include <unistd.h> #include "mptutil.h" @@ -50,35 +51,6 @@ __RCSID("$FreeBSD$"); static void dump_config(CONFIG_PAGE_RAID_VOL_0 *vol); #endif -static long -dehumanize(const char *value) -{ - char *vtp; - long iv; - - if (value == NULL) - return (0); - iv = strtoq(value, &vtp, 0); - if (vtp == value || (vtp[0] != '\0' && vtp[1] != '\0')) { - return (0); - } - switch (vtp[0]) { - case 't': case 'T': - iv *= 1024; - case 'g': case 'G': - iv *= 1024; - case 'm': case 'M': - iv *= 1024; - case 'k': case 'K': - iv *= 1024; - case '\0': - break; - default: - return (0); - } - return (iv); -} - /* * Lock the volume by opening its /dev device read/write. This will * only work if nothing else has it opened (including mounts). We @@ -666,7 +638,9 @@ create_volume(int ac, char **av) quick = 1; break; case 's': - stripe_size = dehumanize(optarg); + error = expand_number(optarg, &stripe_size); + if (error == -1) + errx(EX_USAGE, "%s: stripe size incorrect", optarg); if ((stripe_size < 512) || (!powerof2(stripe_size))) { warnx("Invalid stripe size %s", optarg); return (EINVAL); commit 903b59a53bf479a5aa68ea523e5d0c1a2da7a8d9 Author: Eitan Adler <lists@eitanadler.com> Date: Sat Nov 9 22:09:17 2013 -0500 Convert from a hand-rolled function to expand_number. Reviewed by: sbruno diff --git a/usr.sbin/mfiutil/mfi_config.c b/usr.sbin/mfiutil/mfi_config.c index a919214..9f64cbc 100644 --- a/usr.sbin/mfiutil/mfi_config.c +++ b/usr.sbin/mfiutil/mfi_config.c @@ -41,41 +41,13 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sysexits.h> #include <unistd.h> #include "mfiutil.h" static int add_spare(int ac, char **av); static int remove_spare(int ac, char **av); -static long -dehumanize(const char *value) -{ - char *vtp; - long iv; - - if (value == NULL) - return (0); - iv = strtoq(value, &vtp, 0); - if (vtp == value || (vtp[0] != '\0' && vtp[1] != '\0')) { - return (0); - } - switch (vtp[0]) { - case 't': case 'T': - iv *= 1024; - case 'g': case 'G': - iv *= 1024; - case 'm': case 'M': - iv *= 1024; - case 'k': case 'K': - iv *= 1024; - case '\0': - break; - default: - return (0); - } - return (iv); -} - int mfi_config_read(int fd, struct mfi_config_data **configp) { @@ -629,7 +601,9 @@ create_volume(int ac, char **av) break; #endif case 's': - stripe_size = dehumanize(optarg); + error = expand_number(optarg, &stripe_size); + if (error == -1) + errx(EX_USAGE, "%s: stripe size incorrect", optarg); if ((stripe_size < 512) || (!powerof2(stripe_size))) stripe_size = 64 * 1024; break; -- Eitan Adler
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAF6rxgkCkpS_iu8VXcUnqk0TG%2BMrbzvt55-QJ-ebTUrqJv8UHQ>