From owner-freebsd-hackers@FreeBSD.ORG Wed Mar 7 15:38:45 2007 Return-Path: X-Original-To: freebsd-hackers@FreeBSD.ORG Delivered-To: freebsd-hackers@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 3113016A402 for ; Wed, 7 Mar 2007 15:38:45 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (lurza.secnetix.de [83.120.8.8]) by mx1.freebsd.org (Postfix) with ESMTP id A2F4413C4AA for ; Wed, 7 Mar 2007 15:38:44 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (fgjajc@localhost [127.0.0.1]) by lurza.secnetix.de (8.13.4/8.13.4) with ESMTP id l27FcV2O036027; Wed, 7 Mar 2007 16:38:36 +0100 (CET) (envelope-from oliver.fromme@secnetix.de) Received: (from olli@localhost) by lurza.secnetix.de (8.13.4/8.13.1/Submit) id l27FcVBG036009; Wed, 7 Mar 2007 16:38:31 +0100 (CET) (envelope-from olli) Date: Wed, 7 Mar 2007 16:38:31 +0100 (CET) Message-Id: <200703071538.l27FcVBG036009@lurza.secnetix.de> From: Oliver Fromme To: freebsd-hackers@FreeBSD.ORG, freebsd-hackers@adam.gs In-Reply-To: <4D3F70BA-53C3-4A22-99F4-728592F2DB84@adam.gs> X-Newsgroups: list.freebsd-hackers User-Agent: tin/1.8.2-20060425 ("Shillay") (UNIX) (FreeBSD/4.11-STABLE (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.1.2 (lurza.secnetix.de [127.0.0.1]); Wed, 07 Mar 2007 16:38:36 +0100 (CET) Cc: Subject: Re: FreeBSD available disk space X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd-hackers@FreeBSD.ORG, freebsd-hackers@adam.gs List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Mar 2007 15:38:45 -0000 Adam Jacob Muller wrote: > 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@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 . > > 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. Well, POSIX doesn't specify at all how the values are to interpreted. It's up to the implementation to fill them with numbers that are useful, and the FreeBSD developers decided that the f_bavail value could be negative, so they reflect the numbers from the df(1) output correctly. Therefore, FreeBSD is in conformance with the strict letter of the POSIX standard. One possible solution would be to look at both the f_bfree and f_bavail numbers. If the former is less than the latter, then f_bavail obviously needs to be interpreted as a signed value. But even simply interpreting it as a signed value in every case won't break anything, even "with really big file- systems". A signed long long will handle as much as 2^63 (minus one, to be exact) which is 8 EB (exabyte), which is 8 million TB. Yeah, sure, I know "640 KB should be enough for everybody" and so on, but I honestly doubt that a file system of 8 million TB will exist in the near future. Best regards Oliver -- Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M. Handelsregister: Registergericht Muenchen, HRA 74606, Geschäftsfuehrung: secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün- chen, HRB 125758, Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart FreeBSD-Dienstleistungen, -Produkte und mehr: http://www.secnetix.de/bsd I suggested holding a "Python Object Oriented Programming Seminar", but the acronym was unpopular. -- Joseph Strout