Subject: Re: The demise of DEV_BSIZE
To: None <>
From: Wolfgang Solfrank <>
List: tech-kern
Date: 10/06/1999 19:24:00

> > >Both character and block devices have gained a new function call, d_bsize:
> > >void    (*d_bsize)      __P((dev_t dev, int * bshift, int * bsize));
> > >which fills in the bshift and bsize values for a device.
> > 
> > You do not need both (and as cgd noted, "unconfigured device" seems
> > like it should be an error-return).  The reason you only need one
> > is that all you need is the number of blocks.  The caller can
> > translate that into a shift if appropriate, e.g.:
> > 
> > 	ispow2 = (size & (size - 1)) == 0;
> > 	shift = ispow2 ? ffs(size) - 1 : 0;
> Ewww. ffs(). One of the things I'm adding is an intlog2() routine which
> tells you the power of 2 of the most significant bit set. It uses a binary
> search method, so for a u_int32_t, it takes 5 comparisons (well, 6 for
> either 0 or 1).
> My other concern is that I'd rather we not be recalculating the shift
> values over and over. Right now the shift gets calculated when a device
> driver notes the block size for a device. I'd like to keep caching that
> value everywhere we need to. :-)

Well, I think it wasn't Chris' suggestion to drop the two values from the
upper level code, just from your d_bsize routine.  I.e. the caller of
the d_bsize routine could evaluate the shift value on its own.  And since
you're calling it only once per device (or so), this shouldn't be a problem.

ws@TooLs.DE     (Wolfgang Solfrank, TooLs GmbH) 	+49-228-985800