From owner-freebsd-scsi@FreeBSD.ORG Sun Nov 10 03:52:33 2013 Return-Path: Delivered-To: scsi@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id B928DD41 for ; Sun, 10 Nov 2013 03:52:33 +0000 (UTC) (envelope-from lists@eitanadler.com) Received: from mail-qe0-x233.google.com (mail-qe0-x233.google.com [IPv6:2607:f8b0:400d:c02::233]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 7C07F241D for ; Sun, 10 Nov 2013 03:52:33 +0000 (UTC) Received: by mail-qe0-f51.google.com with SMTP id t7so251845qeb.24 for ; Sat, 09 Nov 2013 19:52:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eitanadler.com; s=0xdeadbeef; h=mime-version:from:date:message-id:subject:to:content-type; bh=sI7uFgPDquWAFjD02twjVNDIMQr0HgAimT07GO0YRpk=; b=a6IFQp9o6CHzOTgLWRTZ2Qq5LIBtqbO2zkGkdUHNeI7PuwerS0aS52DpjMuN+ic10H 9m4igOhvke9TFEFRgU7WUW95doB84AJnE/9+hu81IVJYqxfsGeYgJg9mYLua3DyhLUbO Ye9Ef0mn3mnRYfLXLH4alqfFamhoi8F6b5kKk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to :content-type; bh=sI7uFgPDquWAFjD02twjVNDIMQr0HgAimT07GO0YRpk=; b=kpNICm/XpsU6nJ6bcCmA4/6yGXLbLpQ/O35W8ipW7NC/B6g9mn8vS2jFVIQpTKzDZw mscYMjwEYtQ9pdrEZVncIxKWcl58cyMBagsn2SdrueG6L3P4qHfs7V3f4nBu4ikqVJpX fSguB9ugjC65MK2406hw7CG0Kpe2qoM3aX8mjd5Yxco1ZjFlFHyzqX/gHF7kJpFl2x/p ktesoNjkkEWYxjysYuGG+anKhQfN/bklibE9aN+UQV2C4eBf2zrT/qDLL6U9/bpxG66U 2alMXiYLNPTSm2Iwgi8kDvvzGokShMYv7vW8MYhbUlocIQ+GNoPD756Y1oOHMFKj2QYu /KXg== X-Gm-Message-State: ALoCoQlBeXlPXkqGMoupjjDFRbYJvlzglFcAOOukEDdzQ2wgjzksqFfmH8+USR0PMcDCY1xiqAUx X-Received: by 10.224.69.132 with SMTP id z4mr37110179qai.78.1384055552692; Sat, 09 Nov 2013 19:52:32 -0800 (PST) MIME-Version: 1.0 Received: by 10.96.63.101 with HTTP; Sat, 9 Nov 2013 19:52:02 -0800 (PST) From: Eitan Adler Date: Sat, 9 Nov 2013 22:52:02 -0500 Message-ID: Subject: mptutil, mfitil, expand_number To: scsi@freebsd.org Content-Type: text/plain; charset=UTF-8 X-BeenThere: freebsd-scsi@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SCSI subsystem List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Nov 2013 03:52:33 -0000 Any thoughts? commit 20ad9d0a2bd9aea4aaf7c5ae925397 8ae0aed75c Author: Eitan Adler 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 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 #include #include +#include #include #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 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 #include #include +#include #include #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