From owner-freebsd-net Wed Aug 14 9:56:27 2002 Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4F38A37B400 for ; Wed, 14 Aug 2002 09:56:22 -0700 (PDT) Received: from odin.ac.hmc.edu (Odin.AC.HMC.Edu [134.173.32.75]) by mx1.FreeBSD.org (Postfix) with ESMTP id AD31F43E75 for ; Wed, 14 Aug 2002 09:56:21 -0700 (PDT) (envelope-from brdavis@odin.ac.hmc.edu) Received: from odin.ac.hmc.edu (IDENT:brdavis@localhost.localdomain [127.0.0.1]) by odin.ac.hmc.edu (8.12.3/8.12.3) with ESMTP id g7EGu6wu003231; Wed, 14 Aug 2002 09:56:06 -0700 Received: (from brdavis@localhost) by odin.ac.hmc.edu (8.12.3/8.12.3/Submit) id g7EGu6U9003230; Wed, 14 Aug 2002 09:56:06 -0700 Date: Wed, 14 Aug 2002 09:56:06 -0700 From: Brooks Davis To: Bruce Evans Cc: Brooks Davis , "M. Warner Losh" , net@FreeBSD.ORG Subject: Re: switching to if_xname from if_name and if_unit Message-ID: <20020814095606.A32608@Odin.AC.HMC.Edu> References: <20020730101533.A29988@Odin.AC.HMC.Edu> <20020731041621.H56544-100000@gamplex.bde.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-md5; protocol="application/pgp-signature"; boundary="8t9RHnE3ZwKMSgU+" Content-Disposition: inline User-Agent: Mutt/1.2.5.1i In-Reply-To: <20020731041621.H56544-100000@gamplex.bde.org>; from bde@zeta.org.au on Wed, Jul 31, 2002 at 04:22:23AM +1000 X-Virus-Scanned: by amavisd-milter (http://amavis.org/) on odin.ac.hmc.edu Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org --8t9RHnE3ZwKMSgU+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jul 31, 2002 at 04:22:23AM +1000, Bruce Evans wrote: > On Tue, 30 Jul 2002, Brooks Davis wrote: >=20 > > On Mon, Jul 29, 2002 at 10:38:34PM -0600, M. Warner Losh wrote: > > > : @@ -280,8 +280,7 @@ ep_attach(sc) > > > : attached =3D (ifp->if_softc !=3D 0); > > > : > > > : ifp->if_softc =3D sc; > > > : - ifp->if_unit =3D sc->unit; > > > : - ifp->if_name =3D "ep"; > > > : + sprintf(ifp->if_xname, "ep%d", sc->unit); > > > > > > strcpy(ifp->if_xname, device_get_name(sc->dev)); > > > > > > might be better, don't you think? >=20 > I think this point has already been covered better by noticing that the > name is already stored in several other places (not just new-bus). >=20 > > Yes, that's probably better. At least it's one less place that needs to > > know the name of the device. >=20 > Except it gets the name wrong (it should use device_get_nameunit()), and > it is not so clear that the name fits in the buffer. I'm trying to figure out what the best idiom would be. While a >15 character name seems unlikely, we probably shouldn't trust device_get_nameunit(). In that case, I'm not sure what the best thing to use. The obvious thing is strlcpy, but I don't think we have that in the kernel. We could use strncpy with the usual tricks or snprintf. Another option would be something like in if.[ch]: void if_setxnamefromdev(struct ifnet *ifp, device_t dev) { KASSERT(strlen(device_get_nameunit(dev)) < sizeof(ifp->if_xname), ("%s: name too big for if_xname", device_get_nameunit(dev))); strncpy(ifp->if_xname, device_get_nameunit(dev), sizeof(ifp->if_xname) - 1); ifp->if_xname[sizeof(ifp->if_xname) - 1] =3D '\0'; } I kind of like that idea because it means we've got one function to hide the mess and we find out if someone does manage to make a name that's too long. -- Brooks --=20 Any statement of the form "X is the one, true Y" is FALSE. PGP fingerprint 655D 519C 26A7 82E7 2529 9BF0 5D8E 8BE9 F238 1AD4 --8t9RHnE3ZwKMSgU+ Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE9WoulXY6L6fI4GtQRAhBgAJ0SYXvqqNY/ywImSNBkv5FcYPGEIgCfXEag nGawHEIyrTdXHGaD5J53P+o= =PDKs -----END PGP SIGNATURE----- --8t9RHnE3ZwKMSgU+-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message