diff options
Diffstat (limited to 'net/disk_cache/cache_util_posix.cc')
-rw-r--r-- | net/disk_cache/cache_util_posix.cc | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/net/disk_cache/cache_util_posix.cc b/net/disk_cache/cache_util_posix.cc index 708f378..041b2b5 100644 --- a/net/disk_cache/cache_util_posix.cc +++ b/net/disk_cache/cache_util_posix.cc @@ -4,19 +4,43 @@ #include "net/disk_cache/cache_util.h" +#include <errno.h> +#include <sys/statvfs.h> +#include <unistd.h> + #include "base/file_util.h" #include "base/logging.h" +#include "base/string_util.h" namespace disk_cache { int64 GetFreeDiskSpace(const std::wstring& path) { - DLOG(WARNING) << "Not Implemented"; - return -1; + struct statvfs stats; + if (statvfs(WideToUTF8(path).c_str(), &stats) != 0) { + return -1; + } + return static_cast<int64>(stats.f_bavail) * stats.f_frsize; } int64 GetSystemMemory() { - // TODO(pinkerton): figure this out for mac/linux +#if defined(OS_LINUX) + // _SC_PHYS_PAGES is not part of POSIX and not available on OS X + long pages = sysconf(_SC_PHYS_PAGES); + if (pages == -1) { + return -1; + } + long page_size = sysconf(_SC_PAGE_SIZE); + if (page_size == -1) { + return -1; + } + int64 result = static_cast<int64>(pages) * page_size; + DCHECK(result > 0); + return result; +#else + // TODO(pinkerton): figure this out for mac + NOTIMPLEMENTED(); return -1; +#endif } bool MoveCache(const std::wstring& from_path, const std::wstring& to_path) { |