FreeBSD available disk space

Adam Jacob Muller freebsd-hackers at adam.gs
Mon Feb 26 20:49:53 UTC 2007


Hello,
I've been going back and forth for a bit trying to figure out this  
situation, and I am hoping that someone on this list will have some  
insight :)

When using php's disk_free_space() function to determine the amount  
of free space on a partition that has a negative amount of free  
space, PHP returns an unreasonably large number, for example:

>> [root at cube]# php -r 'var_dump(disk_free_space("/some/partition/ 
>> with/negative/free/space"));'
>> float(3.7778931863E+22)

this is the comment from one of the PHP developers who has been  
helping me to debug this issue:

> Well, this is actually quite interesting.
> The problem is that according to POSIX statvfs struct's field  
> f_bavail must be <unsigned long>.
> But FreeBSD stores negative values in this field and I don't see  
> any hint on how to detect if this is a negative value or just a  
> huge positive one.
> I can of course cast it to signed long, but that would effectively  
> break it on other platforms, which do conform POSIX standard and do  
> not store negative values in unsigned variables.
>
> I guess FreeBSD developers might help here, since that should be a  
> known problem for them.

as well as:

> I can see that libstatgrab uses #ifdef's for all *BSD flavours and  
> casts f_bavail to (long long).
> Not sure if this is the correct solution, my previous suspicions  
> that it may not work with really big filesystems still aply.

Thanks in advance for any insight you may have!

-Adam


More information about the freebsd-hackers mailing list