From owner-freebsd-arch@FreeBSD.ORG Fri May 20 21:18:15 2005 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EB8AD16A4CF for ; Fri, 20 May 2005 21:18:14 +0000 (GMT) Received: from pd3mo1so.prod.shaw.ca (shawidc-mo1.cg.shawcable.net [24.71.223.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6399D43D3F for ; Fri, 20 May 2005 21:18:14 +0000 (GMT) (envelope-from cperciva@freebsd.org) Received: from pd3mr5so.prod.shaw.ca (pd3mr5so-qfe3.prod.shaw.ca [10.0.141.12])2004))freebsd-arch@freebsd.org; Fri, 20 May 2005 15:17:27 -0600 (MDT) Received: from pn2ml9so.prod.shaw.ca ([10.0.121.7]) by pd3mr5so.prod.shaw.ca (Sun ONE Messaging Server 6.0 HotFix 1.01 (built Mar 15 2004)) with ESMTP id <0IGT003SR4H3GB20@pd3mr5so.prod.shaw.ca> for freebsd-arch@freebsd.org; Fri, 20 May 2005 15:17:27 -0600 (MDT) Received: from [192.168.0.60] (S0106006067227a4a.vc.shawcable.net [24.87.209.6]) by l-daemon (iPlanet Messaging Server 5.2 HotFix 1.18 (built Jul 28 2003)) with ESMTP id <0IGT007984H2N5@l-daemon> for freebsd-arch@freebsd.org; Fri, 20 May 2005 15:17:27 -0600 (MDT) Date: Fri, 20 May 2005 14:17:25 -0700 From: Colin Percival In-reply-to: <20050520064929.GC959@funkthat.com> To: John-Mark Gurney Message-id: <428E53E5.7050509@freebsd.org> MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1 Content-transfer-encoding: 7bit X-Accept-Language: en-us, en X-Enigmail-Version: 0.91.0.0 References: <428D26C1.2020201@freebsd.org> <20050520064929.GC959@funkthat.com> User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050406) cc: freebsd-arch@freebsd.org Subject: Re: RFC: Using fixed-length strings for version[] and osrelease[] X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 May 2005 21:18:15 -0000 John-Mark Gurney wrote: > Colin Percival wrote this message on Thu, May 19, 2005 at 16:52 -0700: >>The lengths 512 and 64 are chosen as being considerably more than double the >>likely lengths of these strings; on my system, these two strings are 12 bytes >>and 134 bytes long respectively. > > Nope, but I would say make them just a bit larger than necessary right > now, and add the necessary CTASSERT lines to make sure we don't overflow.. > > I'd say no more than 256 bytes for the VERSION string, since CTASSERT will > prevent the overflow... > > Though you might want to make the fixed size dependent upon the release > kernel and not for custom compiled kernels... No point in penalizing > kernels that don't need this... I don't think there's much point worrying about saving a few hundred bytes, but I've put together a patch which allows the strings to be lengthened if necessary. The lengths are now 256 bytes and 32 bytes. I've also added a BRANCH_OVERRIDE variable which can bs set in the environment; this is probably not going to be useful to many people, but it will allow me to identify the osrelease[] string and avoid distributing a new kernel when the patch number is bumped due to a userland-only fix. Any objections to the following patch? @@ -33,6 +33,9 @@ TYPE="FreeBSD" REVISION="6.0" BRANCH="CURRENT" +if [ "X${BRANCH_OVERRIDE}" != "X" ]; then + BRANCH=${BRANCH_OVERRIDE} +fi RELEASE="${REVISION}-${BRANCH}" VERSION="${TYPE} ${RELEASE}" @@ -85,11 +88,14 @@ v=`cat version` u=${USER:-root} d=`pwd` i=`${MAKE:-make} -V KERN_IDENT` cat << EOF > vers.c $COPYRIGHT +#define VERSTR "${VERSION} #${v}: ${t}\\n ${u}@${h}:${d}\\n" +#define RELSTR "${RELEASE}" + char sccspad[32 - 4 /* sizeof(sccs) */] = { '\\0' }; char sccs[4] = { '@', '(', '#', ')' }; -char version[] = "${VERSION} #${v}: ${t}\\n ${u}@${h}:${d}\\n"; +char version[sizeof(VERSTR) > 256 ? sizeof(VERSTR) : 256] = VERSTR; char ostype[] = "${TYPE}"; -char osrelease[] = "${RELEASE}"; +char osrelease[sizeof(RELSTR) > 32 ? sizeof(RELSTR) : 32] = RELSTR; int osreldate = ${RELDATE}; char kern_ident[] = "${i}"; EOF Colin Percival