diff options
Diffstat (limited to 'net')
-rw-r--r-- | net/disk_cache/cache_util.h | 7 | ||||
-rw-r--r-- | net/disk_cache/cache_util_posix.cc | 30 |
2 files changed, 31 insertions, 6 deletions
diff --git a/net/disk_cache/cache_util.h b/net/disk_cache/cache_util.h index 8ddb8a7..0977472 100644 --- a/net/disk_cache/cache_util.h +++ b/net/disk_cache/cache_util.h @@ -11,11 +11,12 @@ namespace disk_cache { -// Returns the available disk space on the volume that contains |path|, or -1 -// on failure. +// Returns the available disk space on the volume that contains |path| +// (in bytes), or -1 on failure. int64 GetFreeDiskSpace(const std::wstring& path); -// Returns the total physical memory on the system, or -1 on failure. +// Returns the total physical memory on the system (in bytes), +// or -1 on failure. int64 GetSystemMemory(); // Moves the cache files from the given path to another location. 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) { |