
Hello all, I was browsing boost to find some portable means for getting file system statistics such as file system (disk) size, free space, etc. I kind of expected to see this in the boost filesystem library, but they don't appear to be there. Doesn't even seem to be in the "Do-list". Am I missing something? Looking in the wrong place? Thanks, Steve

On 6/21/05, Steve Hartmann <steven_hartmann@yahoo.com> wrote:
Hello all,
I was browsing boost to find some portable means for getting file system statistics such as file system (disk) size, free space, etc. I kind of expected to see this in the boost filesystem library, but they don't appear to be there. Doesn't even seem to be in the "Do-list".
Am I missing something? Looking in the wrong place?
I've got an implementation (independent of FileSystem) that works on windows, hp and linux (others I'm sure, but I don't use them) if anyone's interested.

I am, thanks in advance ! If this implementation is not deemed to go with Boost, why not a new project on Sourceforge ? I may try to port it to Solaris, if you wish to. Thomas Matelich wrote:
On 6/21/05, Steve Hartmann <steven_hartmann@yahoo.com> wrote:
Hello all,
I was browsing boost to find some portable means for getting file system statistics such as file system (disk) size, free space, etc. I kind of expected to see this in the boost filesystem library, but they don't appear to be there. Doesn't even seem to be in the "Do-list".
Am I missing something? Looking in the wrong place?
I've got an implementation (independent of FileSystem) that works on windows, hp and linux (others I'm sure, but I don't use them) if anyone's interested.

On 6/21/05, remi.chateauneu@gmx.de <remi.chateauneu@gmx.de> wrote:
I am, thanks in advance ! If this implementation is not deemed to go with Boost, why not a new project on Sourceforge ? I may try to port it to Solaris, if you wish to.
Thomas Matelich wrote:
On 6/21/05, Steve Hartmann <steven_hartmann@yahoo.com> wrote:
Hello all,
I was browsing boost to find some portable means for getting file system statistics such as file system (disk) size, free space, etc. I kind of expected to see this in the boost filesystem library, but they don't appear to be there. Doesn't even seem to be in the "Do-list".
Am I missing something? Looking in the wrong place?
I've got an implementation (independent of FileSystem) that works on windows, hp and linux (others I'm sure, but I don't use them) if anyone's interested.
Its really not that complicated. just a wrapper around statfs on unix and GetDiskFreeSpaceEx on windows. Its not terribly long, I'll post it (copied from a longer .cpp file, sorry if I miss an include). #ifndef _WIN32 #include <sys/vfs.h> #else #include <winsock2.h> // I don't want winsock.h included ever #include <Windows.h> #endif #include <boost/cstdint.hpp> namespace { bool getDeviceStuff(std::string const& path, boost::intmax_t& num_bytes, boost::intmax_t& available_bytes) { if(path.empty()) { //ZLOG("diskspace") << "Cannot get device info for empty directory path" << std::endl; return false; } #ifndef _WIN32 struct statfs buf; if(statfs(path.c_str(), &buf) < 0) { //ZLOG("diskspace") << "statfs failed. " << strerror(errno) << std::endl; return false; } //ZLOG("diskspace") << " f_blocks=" << buf.f_blocks << " f_bsize=" << buf.f_bsize << " f_bavail=" << buf.f_bavail << std::endl; num_bytes = buf.f_blocks * buf.f_bsize; available_bytes = buf.f_bavail * buf.f_bsize; #else __int64 freebytestocaller, totalbytes, freebytes; if(!GetDiskFreeSpaceEx (path.c_str(), (PULARGE_INTEGER)&freebytestocaller, (PULARGE_INTEGER)&totalbytes, (PULARGE_INTEGER)&freebytes)) { LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language (LPTSTR) &lpMsgBuf, 0, NULL ); //ZLOG("diskspace") << "GetDiskFreeSpaceEx failed: " << GetLastError() << " - " << (LPCTSTR)lpMsgBuf << std::endl; LocalFree( lpMsgBuf ); return false; } num_bytes = totalbytes; available_bytes = freebytestocaller; #endif return true; } } double XPlat::getDeviceFreeSpace(std::string const& path) { boost::intmax_t num_bytes, available_bytes; if(!getDeviceStuff(path, num_bytes, available_bytes)) return -1.0; double retval = double(available_bytes) / (1 << 20); //ZLOG("diskspace") << retval << " meg free for " << path << std::endl; return retval; } double XPlat::getDeviceFreePercent(std::string const& path) { boost::intmax_t num_bytes, available_bytes; if(!getDeviceStuff(path, num_bytes, available_bytes)) return -1.0; double retval = (double(available_bytes) / num_bytes) * 100.0; //ZLOG("diskspace") << retval << " {(double(" << available_bytes << ") / " << num_bytes << ") * 100.0} percent free for " << path << std::endl; return retval; }

"Thomas Matelich" <matelich@gmail.com> wrote in message news:3944d45805062113231fa767ff@mail.gmail.com...
On 6/21/05, remi.chateauneu@gmx.de <remi.chateauneu@gmx.de> wrote:
I've got an implementation (independent of FileSystem) that works on windows, hp and linux (others I'm sure, but I don't use them) if anyone's interested.
Its really not that complicated. just a wrapper around statfs on unix and GetDiskFreeSpaceEx on windows.
Probably a dumb question, but why did you use <sys/vfs.h> and statfs() instead of the POSIX <sys/statvfs.h> and statvfs()? Were they not present on some of the target systems? I would like to include the functionality in Boost.Filesystem, but am concerned because POSIX lists it as optional. --Beman

On 6/22/05, Beman Dawes <bdawes@acm.org> wrote:
"Thomas Matelich" <matelich@gmail.com> wrote in message news:3944d45805062113231fa767ff@mail.gmail.com...
Probably a dumb question, but why did you use <sys/vfs.h> and statfs() instead of the POSIX <sys/statvfs.h> and statvfs()? Were they not present on some of the target systems?
I would like to include the functionality in Boost.Filesystem, but am concerned because POSIX lists it as optional.
I started with our legacy HP implementation as a reference and didn't need to change it for linux, so I didn't even notice that there was a different header. :-) I'd be fairly surprised if a platform supported by Filesystem didn't have a way to determine disk space. Well, I guess not all that surprised. Murphy's always waitin'.

"Thomas Matelich" <matelich@gmail.com> wrote in message news:3944d45805062213536c52a507@mail.gmail.com...
On 6/22/05, Beman Dawes <bdawes@acm.org> wrote:
"Thomas Matelich" <matelich@gmail.com> wrote in message news:3944d45805062113231fa767ff@mail.gmail.com...
Probably a dumb question, but why did you use <sys/vfs.h> and statfs() instead of the POSIX <sys/statvfs.h> and statvfs()? Were they not present on some of the target systems?
I would like to include the functionality in Boost.Filesystem, but am concerned because POSIX lists it as optional.
I started with our legacy HP implementation as a reference and didn't need to change it for linux, so I didn't even notice that there was a different header. :-)
I'd be fairly surprised if a platform supported by Filesystem didn't have a way to determine disk space. Well, I guess not all that surprised. Murphy's always waitin'.

"Thomas Matelich" <matelich@gmail.com> wrote in message news:3944d45805062213536c52a507@mail.gmail.com...
On 6/22/05, Beman Dawes <bdawes@acm.org> wrote:
"Thomas Matelich" <matelich@gmail.com> wrote in message news:3944d45805062113231fa767ff@mail.gmail.com...
Probably a dumb question, but why did you use <sys/vfs.h> and statfs() instead of the POSIX <sys/statvfs.h> and statvfs()? Were they not present on some of the target systems?
I would like to include the functionality in Boost.Filesystem, but am concerned because POSIX lists it as optional.
I started with our legacy HP implementation as a reference and didn't need to change it for linux, so I didn't even notice that there was a different header. :-)
Understood. Does the legacy HP implementation also supply <sys/statvfs.h> and statvfs()?
I'd be fairly surprised if a platform supported by Filesystem didn't have a way to determine disk space. Well, I guess not all that surprised. Murphy's always waitin'.
Yep. But that isn't necessarily a showstopper. 1.34 will add a function to create hard links, and just document the fact that it will always fail on some file systems. To me the key platforms are POSIX/Windows/Linux/Solaris/MacOS/HPux/AIX. If we get uniform behavior across those platforms, it is OK if a function can't succeed on more obscure platforms. --Beman

On 6/22/05, Beman Dawes <bdawes@acm.org> wrote:
"Thomas Matelich" <matelich@gmail.com> wrote in message news:3944d45805062213536c52a507@mail.gmail.com...
On 6/22/05, Beman Dawes <bdawes@acm.org> wrote:
"Thomas Matelich" <matelich@gmail.com> wrote in message news:3944d45805062113231fa767ff@mail.gmail.com...
Probably a dumb question, but why did you use <sys/vfs.h> and statfs() instead of the POSIX <sys/statvfs.h> and statvfs()? Were they not present on some of the target systems?
I would like to include the functionality in Boost.Filesystem, but am concerned because POSIX lists it as optional.
I started with our legacy HP implementation as a reference and didn't need to change it for linux, so I didn't even notice that there was a different header. :-)
Understood. Does the legacy HP implementation also supply <sys/statvfs.h> and statvfs()?
I slapped myself as soon as I saw the question, should have included that info in my first response. Yes, HP does have that.

On Wed, 2005-06-22 at 13:35 -0400, Beman Dawes wrote:
"Thomas Matelich" <matelich@gmail.com> wrote in message news:3944d45805062113231fa767ff@mail.gmail.com...
On 6/21/05, remi.chateauneu@gmx.de <remi.chateauneu@gmx.de> wrote:
I've got an implementation (independent of FileSystem) that works on windows, hp and linux (others I'm sure, but I don't use them) if anyone's interested.
Its really not that complicated. just a wrapper around statfs on unix and GetDiskFreeSpaceEx on windows.
Probably a dumb question, but why did you use <sys/vfs.h> and statfs() instead of the POSIX <sys/statvfs.h> and statvfs()? Were they not present on some of the target systems?
Note that some systems do not have statvfs. This is the case of, for example, NetBSD until 2.1, which only had statfs (sys/param.h and sys/mount.h required for it to work).
From statvfs' manpage:
HISTORY The statvfs(), statvfs1(), fstatvfs(), and fstatvfs1() functions first appeared in NetBSD 2.1 to replace the statfs() family of functions which first appeared in 4.4BSD. -- Julio M. Merino Vidal <jmmv84@gmail.com> http://www.livejournal.com/users/jmmv/ The NetBSD Project - http://www.NetBSD.org/

"Steve Hartmann" <steven_hartmann@yahoo.com> wrote in message news:pan.2005.06.21.16.44.52.431000@yahoo.com...
Hello all,
I was browsing boost to find some portable means for getting file system statistics such as file system (disk) size, free space, etc. I kind of expected to see this in the boost filesystem library, but they don't appear to be there. Doesn't even seem to be in the "Do-list".
I've added it to the "do-list":-) --Beman
participants (5)
-
Beman Dawes
-
Julio M. Merino Vidal
-
remi.chateauneu@gmx.de
-
Steve Hartmann
-
Thomas Matelich