Date: Tue, 3 Apr 2007 13:04:26 +0200 From: Pawel Jakub Dawidek <pjd@FreeBSD.org> To: Eric Anderson <anderson@freebsd.org> Cc: freebsd-current@freebsd.org Subject: Re: geom_journal panic: wrong offset 500107860990 for sectorsize 512 - RESOLVED Message-ID: <20070403110426.GD40062@garage.freebsd.pl> In-Reply-To: <4611DE78.7050405@freebsd.org> References: <460FDEF2.2060203@centtech.com> <20070401180125.GE25661@garage.freebsd.pl> <46119C4B.3020200@centtech.com> <4611DE78.7050405@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070403110426.GD40062>