From owner-svn-src-head@FreeBSD.ORG Tue Nov 18 04:04:01 2008 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6E674106564A; Tue, 18 Nov 2008 04:04:01 +0000 (UTC) (envelope-from marcel@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 5B8458FC12; Tue, 18 Nov 2008 04:04:01 +0000 (UTC) (envelope-from marcel@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mAI441lf066916; Tue, 18 Nov 2008 04:04:01 GMT (envelope-from marcel@svn.freebsd.org) Received: (from marcel@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mAI441Kb066914; Tue, 18 Nov 2008 04:04:01 GMT (envelope-from marcel@svn.freebsd.org) Message-Id: <200811180404.mAI441Kb066914@svn.freebsd.org> From: Marcel Moolenaar Date: Tue, 18 Nov 2008 04:04:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185046 - head/sbin/geom/class/part X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Nov 2008 04:04:01 -0000 Author: marcel Date: Tue Nov 18 04:04:01 2008 New Revision: 185046 URL: http://svn.freebsd.org/changeset/base/185046 Log: Use humanize_number(), rather than a home-grown algorithm for formatting a number in a human-friendly way. Note that with this commit a megabyte changed from 1000000 to 1048576 and a 80G disk is now printed as being 75G in size. This is deliberate. It's consistent with the core of geom(8). However, the original choice for a megabyte being 1000000 was on purpose and matches what disk vendors put on the box. The consistency is considered more important. Submitted by: delphij Modified: head/sbin/geom/class/part/Makefile head/sbin/geom/class/part/geom_part.c Modified: head/sbin/geom/class/part/Makefile ============================================================================== --- head/sbin/geom/class/part/Makefile Tue Nov 18 03:55:55 2008 (r185045) +++ head/sbin/geom/class/part/Makefile Tue Nov 18 04:04:01 2008 (r185046) @@ -4,6 +4,8 @@ CLASS= part +LDADD= -lutil + WARNS?= 4 .include Modified: head/sbin/geom/class/part/geom_part.c ============================================================================== --- head/sbin/geom/class/part/geom_part.c Tue Nov 18 03:55:55 2008 (r185045) +++ head/sbin/geom/class/part/geom_part.c Tue Nov 18 04:04:01 2008 (r185046) @@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -203,21 +204,12 @@ find_provider(struct ggeom *gp, unsigned } static const char * -fmtsize(long double rawsz) +fmtsize(int64_t rawsz) { - static char buf[32]; - static const char *sfx[] = { "B", "KB", "MB", "GB", "TB" }; - long double sz; - int sfxidx; + static char buf[5]; - sfxidx = 0; - sz = (long double)rawsz; - while (sfxidx < 4 && sz > 1099.0) { - sz /= 1000; - sfxidx++; - } - - sprintf(buf, "%.1Lf%s", sz, sfx[sfxidx]); + humanize_number(buf, sizeof(buf), rawsz, "", HN_AUTOSCALE, + HN_B | HN_NOSPACE | HN_DECIMAL); return (buf); }