summaryrefslogtreecommitdiffstats
path: root/net/disk_cache/cache_util_posix.cc
diff options
context:
space:
mode:
authormark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-10 19:57:23 +0000
committermark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-10 19:57:23 +0000
commit233665dce6fc0061fa821ed8438884a0582348e5 (patch)
treea5ba2935d2f2a5fc50e8e735419e3d76330a8022 /net/disk_cache/cache_util_posix.cc
parentbf5e7dbe6389d8e9a2b0d582c4b84b867599f962 (diff)
downloadchromium_src-233665dce6fc0061fa821ed8438884a0582348e5.zip
chromium_src-233665dce6fc0061fa821ed8438884a0582348e5.tar.gz
chromium_src-233665dce6fc0061fa821ed8438884a0582348e5.tar.bz2
Implement GetFreeDiskSpace for POSIX and GetSystemMemory for Linux.
Patch by Paweł Hajdan jr <phajdan.jr@gmail.com> http://codereview.chromium.org/1891 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2007 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/cache_util_posix.cc')
-rw-r--r--net/disk_cache/cache_util_posix.cc30
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) {