From owner-svn-src-stable@FreeBSD.ORG Sun Nov 23 00:16:10 2008 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 90CDD1065670; Sun, 23 Nov 2008 00:16:10 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 7B6228FC0C; Sun, 23 Nov 2008 00:16:10 +0000 (UTC) (envelope-from delphij@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 mAN0GAKX033235; Sun, 23 Nov 2008 00:16:10 GMT (envelope-from delphij@svn.freebsd.org) Received: (from delphij@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mAN0GA7x033233; Sun, 23 Nov 2008 00:16:10 GMT (envelope-from delphij@svn.freebsd.org) Message-Id: <200811230016.mAN0GA7x033233@svn.freebsd.org> From: Xin LI Date: Sun, 23 Nov 2008 00:16:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185192 - in stable/7/sbin/geom: . class/part misc X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Nov 2008 00:16:10 -0000 Author: delphij Date: Sun Nov 23 00:16:10 2008 New Revision: 185192 URL: http://svn.freebsd.org/changeset/base/185192 Log: MFC r185038,185044,185046: Automatically pad gptboot, style for include files, use humanize_number() for consistency and reduce code duplication. Approved by: re (kib) Modified: stable/7/sbin/geom/ (props changed) stable/7/sbin/geom/class/part/ (props changed) stable/7/sbin/geom/class/part/Makefile stable/7/sbin/geom/class/part/geom_part.c stable/7/sbin/geom/misc/ (props changed) Modified: stable/7/sbin/geom/class/part/Makefile ============================================================================== --- stable/7/sbin/geom/class/part/Makefile Sun Nov 23 00:13:25 2008 (r185191) +++ stable/7/sbin/geom/class/part/Makefile Sun Nov 23 00:16:10 2008 (r185192) @@ -4,6 +4,8 @@ CLASS= part +LDADD= -lutil + WARNS?= 4 .include Modified: stable/7/sbin/geom/class/part/geom_part.c ============================================================================== --- stable/7/sbin/geom/class/part/geom_part.c Sun Nov 23 00:13:25 2008 (r185191) +++ stable/7/sbin/geom/class/part/geom_part.c Sun Nov 23 00:16:10 2008 (r185192) @@ -27,19 +27,21 @@ #include __FBSDID("$FreeBSD$"); -#include -#include -#include -#include +#include + +#include #include +#include #include -#include -#include #include +#include #include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include "core/geom.h" #include "misc/subr.h" @@ -202,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; - - sfxidx = 0; - sz = (long double)rawsz; - while (sfxidx < 4 && sz > 1099.0) { - sz /= 1000; - sfxidx++; - } + static char buf[5]; - sprintf(buf, "%.1Lf%s", sz, sfx[sfxidx]); + humanize_number(buf, sizeof(buf), rawsz, "", HN_AUTOSCALE, + HN_B | HN_NOSPACE | HN_DECIMAL); return (buf); } @@ -386,6 +379,8 @@ gpart_write_partcode(struct gctl_req *re struct ggeom *gp; struct gprovider *pp; const char *s; + char *buf; + off_t bsize; int error, fd; s = gctl_get_ascii(req, "class"); @@ -421,8 +416,21 @@ gpart_write_partcode(struct gctl_req *re errx(EXIT_FAILURE, "%s: not enough space", dsf); if (lseek(fd, 0, SEEK_SET) != 0) err(EXIT_FAILURE, "%s", dsf); - if (write(fd, code, size) != size) + + /* + * When writing to a disk device, the write must be + * sector aligned and not write to any partial sectors, + * so round up the buffer size to the next sector and zero it. + */ + bsize = (size + pp->lg_sectorsize - 1) / + pp->lg_sectorsize * pp->lg_sectorsize; + buf = calloc(1, bsize); + if (buf == NULL) + err(EXIT_FAILURE, "%s", dsf); + bcopy(code, buf, size); + if (write(fd, buf, bsize) != bsize) err(EXIT_FAILURE, "%s", dsf); + free(buf); close(fd); } else errx(EXIT_FAILURE, "invalid partition index");