From owner-freebsd-current@FreeBSD.ORG Tue Apr 3 11:04:35 2007 Return-Path: X-Original-To: freebsd-current@freebsd.org Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 657BB16A407; Tue, 3 Apr 2007 11:04:35 +0000 (UTC) (envelope-from pjd@garage.freebsd.pl) Received: from mail.garage.freebsd.pl (arm132.internetdsl.tpnet.pl [83.17.198.132]) by mx1.freebsd.org (Postfix) with ESMTP id B6DD913C4B7; Tue, 3 Apr 2007 11:04:34 +0000 (UTC) (envelope-from pjd@garage.freebsd.pl) Received: by mail.garage.freebsd.pl (Postfix, from userid 65534) id D3AAE48804; Tue, 3 Apr 2007 13:04:33 +0200 (CEST) Received: from localhost (pjd.wheel.pl [10.0.1.1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.garage.freebsd.pl (Postfix) with ESMTP id 0AC0E45684; Tue, 3 Apr 2007 13:04:28 +0200 (CEST) Date: Tue, 3 Apr 2007 13:04:26 +0200 From: Pawel Jakub Dawidek To: Eric Anderson Message-ID: <20070403110426.GD40062@garage.freebsd.pl> References: <460FDEF2.2060203@centtech.com> <20070401180125.GE25661@garage.freebsd.pl> <46119C4B.3020200@centtech.com> <4611DE78.7050405@freebsd.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="AbQceqfdZEv+FvjW" Content-Disposition: inline In-Reply-To: <4611DE78.7050405@freebsd.org> X-PGP-Key-URL: http://people.freebsd.org/~pjd/pjd.asc X-OS: FreeBSD 7.0-CURRENT i386 User-Agent: mutt-ng/devel-r804 (FreeBSD) X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on mail.garage.freebsd.pl X-Spam-Level: X-Spam-Status: No, score=-5.9 required=3.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham version=3.0.4 Cc: freebsd-current@freebsd.org Subject: Re: geom_journal panic: wrong offset 500107860990 for sectorsize 512 - RESOLVED X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Apr 2007 11:04:35 -0000 --AbQceqfdZEv+FvjW Content-Type: text/plain; charset=iso-8859-2 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Apr 02, 2007 at 11:56:24PM -0500, Eric Anderson wrote: > Here is a patch that adds that functionality. Can be found here: >=20 > http://www.googlebit.com/freebsd/patches/gjournal_size_expression.patch >=20 > and attached. Thanks for the patch. I'd prefer to have such functionality as a part of libutil. Simlar to humanize_number(3), but the other way around. Some comments below. > + * Convert an expression of the following forms to a uintmax_t. > + * 1) A positive decimal number. > + * 2) A positive decimal number followed by a 'b' or 'B' (mult by 512). Why? If I give '-s 1024B' it means I want 1024 bytes, not 1024*512 bytes. I would multiply by 512 if I receive number of sectors or something. My suggestion is to accept 'b' and 'B', but ignore it (or multiply by 1). > + * 3) A positive decimal number followed by a 'k' or 'K' (mult by 1 << 1= 0). > + * 4) A positive decimal number followed by a 'm' or 'M' (mult by 1 << 2= 0). > + * 5) A positive decimal number followed by a 'g' or 'G' (mult by 1 << 3= 0). I'd add 't' and 'T' as well. > + * 5) A positive decimal number followed by a 'w' or 'W' (mult by sizeof= int). I suggest dropping it, I don't really see a use for it... > + */ > +intmax_t > +gctl_get_numexpr(struct gctl_req *req, const char *pfmt, ...) > +{ > + const char *val; > + va_list ap; > + uintmax_t num, mult, prevnum; > + char *expr; > + > + va_start(ap, pfmt); > + val =3D gctl_get_param(req, 0, pfmt, ap); > + > + num =3D strtouq(val, &expr, 0); > + > + if (expr =3D=3D val) /* No valid digits. */ > + printf("illegal numeric value\n"); > + > + mult =3D 0; > + switch (*expr) { > + case 'B': > + case 'b': > + mult =3D 512; > + break; > + case 'K': > + case 'k': > + mult =3D 1 << 10; > + break; > + case 'M': > + case 'm': > + mult =3D 1 << 20; > + break; > + case 'G': > + case 'g': > + mult =3D 1 << 30; > + break; > + case 'W': > + case 'w': > + mult =3D sizeof(int); > + break; > + default: > + ; > + } > + > + if (mult !=3D 0) { Maybe just set mult to 1 by default and drop this check? > + prevnum =3D num; > + num *=3D mult; > + /* Check for overflow. */ > + if (num / mult !=3D prevnum) > + printf("overflow in argument\n"); > + expr++; > + } --=20 Pawel Jakub Dawidek http://www.wheel.pl pjd@FreeBSD.org http://www.FreeBSD.org FreeBSD committer Am I Evil? Yes, I Am! --AbQceqfdZEv+FvjW Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (FreeBSD) iD8DBQFGEjS6ForvXbEpPzQRAv8PAJ9VE9tu7Ds5z+NXp4dpkDFiV9bfZQCfalRB AdS1WlNOR9oTO926z5mJtqo= =WMPQ -----END PGP SIGNATURE----- --AbQceqfdZEv+FvjW--