newnfs client and statfs

Jeremy Chadwick freebsd at jdc.parodius.com
Sun May 1 15:48:12 UTC 2011


[snip]
On Sun, May 01, 2011 at 10:37:18AM -0400, Rick Macklem wrote:
> > % + sbp->f_ffree = (sfp->sf_ffiles & OFF_MAX);
> > 
> > Any masking here is logically wrong, and in practice just destroys the
> > sign bit, as described above for the 0x7fffffff mask with old 32 bit
> > systems. Masking with OFF_MAX has additional logic errors. OFF_MAX
> > is the maximum value for an off_t, but none of the types here has
> > anything to do with off_t.
> > 
> 
> Ok, sf_ffiles is defined as uint64_t on the wire. Therefore there is
> no sign bit. The problem is that it could be a larger positive value
> than FreeBSD supports. All I wanted this code to do is make it the
> largest positive value that will fit in int64_t. (I used OFF_MAX
> because you suggested in a previous email that that was preferable
> to 0x7fffffffffffffffLLU for nm_maxfilesize. I don't see anything
> like INT64_MAX, UINT64_MAX in FreeBSD's limits.h)
> Would
> 
>    if (sfp->sf_ffiles > UINT64_MAX)
>        sbp->f_ffree = INT64_MAX;
>    else
>        sbp->f_ffree = sfp->sf_ffiles;
> 
> - except there isn't a UINT64_MAX, INT64_MAX defined in sys/*.h as
>   far as I can see. How do I express these constants? Do I have to
>   convert 0x7ffffffffffffff to decimal and use that?

Aren't these effectively defined in <sys/limits.h> as UQUAD_MAX and
QUAD_MAX?  These get translated/pulled in from <machine/_limits.h>,
which varies per architecture.  This looks like the translation based on
looking at the respective include files per arch:

i386: UQUAD_MAX == __UQUAD_MAX == __ULLONG_MAX == 0xffffffffffffffffULL
i386: QUAD_MAX  == __QUAD_MAX  == __LLONG_MAX  == 0x7fffffffffffffffLL

amd64: UQUAD_MAX == __UQUAD_MAX == __ULONG_MAX  == 0xffffffffffffffffUL
amd64: QUAD_MAX  == __QUAD_MAX  == __LONG_MAX   == 0x7fffffffffffffffL

There are some #ifdef's in <sys/limits.h> around some of these
declarations which I don't understand (like __BSD_VISIBLE), but I would
imagine the above declarations would do what you want.

-- 
| Jeremy Chadwick                                   jdc at parodius.com |
| Parodius Networking                       http://www.parodius.com/ |
| UNIX Systems Administrator                  Mountain View, CA, USA |
| Making life hard for others since 1977.               PGP 4BD6C0CB |



More information about the freebsd-fs mailing list