php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40633 disk_free_space returns a bad result on filesystems with negative free space
Submitted: 2007-02-26 00:55 UTC Modified: 2021-05-10 15:24 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: adam-phpbugs at adam dot gs Assigned: cmb (profile)
Status: Not a bug Package: Filesystem function related
PHP Version: 5.2.1 OS: FreeBSD
Private report: No CVE-ID: None
 [2007-02-26 00:55 UTC] adam-phpbugs at adam dot gs
Description:
------------
on a filesystem with a negative amount of free space (this 
can happen on at least FreeBSD) disk_free_space returns 
unreasonable results.

-=[/some/path]=- -=[Sun Feb 25]=- -=[19:51:55]=-
[root@cube]# php -r 'print disk_free_space(".")."\n";'
3.77789318629E+22
-=[/some/path]=- -=[Sun Feb 25]=- -=[19:51:57]=-
[root@cube]# df -h .
Filesystem    Size    Used   Avail Capacity  Mounted on
/dev/ad7      289G    289G    -23G   109%    /some/path
-=[/some/path]=- -=[Sun Feb 25]=- -=[19:51:58]=-
[root@cube]# df .
Filesystem 1K-blocks      Used     Avail Capacity  Mounted 
on
/dev/ad7   302732078 302699550 -24186038   109%    /some/
path


Reproduce code:
---------------
php -r 'print disk_free_space(".")."\n";'

Expected result:
----------------
-24186038

Actual result:
--------------
3.77789318629E+22

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-02-26 09:33 UTC] tony2001@php.net
What kind of BSD is that and don't you think that negative free space is a BSD bug?
 [2007-02-26 13:32 UTC] adam-phpbugs at adam dot gs
This was FreeBSD

if you look at the FreeBSD manpage for tunefs(8), this is 
the intended behaviour.

http://www.freebsd.org/cgi/man.cgi?
query=tunefs&apropos=0&sektion=0&manpath=FreeBSD+6.2-
RELEASE&format=html


Basically, in FreeBSD (under UFS2 at least) avaliable space 
is calculated as total minus used minus reserved. A small % 
(8 by default) is reserved.

So, this is not really a bug, but actually an intended 
feature.
 [2007-02-26 13:33 UTC] adam-phpbugs at adam dot gs
changing OS to FreeBSD
 [2007-02-26 15:44 UTC] tony2001@php.net
Please provide an SSH account on a machine where I can reproduce it.
 [2007-04-10 20:58 UTC] stas@php.net
Funny thing is that PHP doesn't use any unsigned numbers on the way - it translates it directly from system call int64 to double. I guess version of the system and header file defining struct statvfs would be useful.
 [2007-04-26 23:18 UTC] adam-phpbugs at adam dot gs
For some reason I didn't get any notification of stas's message.

this is FreeBSD 6.2-STABLE
<pre>
struct statvfs {
        fsblkcnt_t      f_bavail;       /* Number of blocks */
        fsblkcnt_t      f_bfree;
        fsblkcnt_t      f_blocks;
        fsfilcnt_t      f_favail;       /* Number of files (e.g., inodes) */
        fsfilcnt_t      f_ffree;
        fsfilcnt_t      f_files;
        unsigned long   f_bsize;        /* Size of blocks counted above */
        unsigned long   f_flag;
        unsigned long   f_frsize;       /* Size of fragments */
        unsigned long   f_fsid;         /* Not meaningful */
        unsigned long   f_namemax;      /* Same as pathconf(_PC_NAME_MAX) */
};</pre>

http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/sys/statvfs.h for cvs/changelog (make sure your looking at 6.2-RELEASE) branch, there may be differences.
 [2009-10-16 04:29 UTC] perryc at gmail dot com
Remarkably on a completely different machine, version of FreeBSD, available disk space, etc I get the same return value from disk_free_space() (albeit with slightly better precision):

  Oct 15 2009 21:21:51 disk_free_space(): 3.7778931862952E+22

The reporter's remarks about negative free space are correct.
 [2010-10-27 13:30 UTC] tony2001@php.net
-Status: Suspended +Status: Open -Assigned To: tony2001 +Assigned To:
 [2021-05-10 15:24 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-05-10 15:24 UTC] cmb@php.net
f_bfree and f_bavail are of type fsblkcnt_t, and according to
POSIX shall be defined as unsigned integer type[1], so this
doesn't look like a PHP bug.

[1] <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_types.h.html>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 06:01:30 2024 UTC