Chromium Code Reviews| Index: base/sys_info_posix.cc |
| diff --git a/base/sys_info_posix.cc b/base/sys_info_posix.cc |
| index 5d1c450139a575705c3c5046ed32c565e4b5e404..a8e19dc13a9bef58a8fdc0717e8c965eee7dfd68 100644 |
| --- a/base/sys_info_posix.cc |
| +++ b/base/sys_info_posix.cc |
| @@ -21,12 +21,8 @@ |
| #include "base/threading/thread_restrictions.h" |
| #include "build/build_config.h" |
| -#if defined(OS_ANDROID) |
|
Lei Zhang
2016/08/02 00:11:48
Ok, hope this works.
Sriram
2016/08/02 20:51:56
Acknowledged.
|
| #include <sys/vfs.h> |
| -#define statvfs statfs // Android uses a statvfs-like statfs struct and call. |
| -#else |
| -#include <sys/statvfs.h> |
| -#endif |
| +#include <linux/magic.h> |
|
Lei Zhang
2016/08/02 00:11:48
Now that you have removed the #if, move these up t
|
| namespace { |
| @@ -73,17 +69,44 @@ base::LazyInstance< |
| base::internal::LazySysInfoValue<int64_t, AmountOfVirtualMemory>>::Leaky |
| g_lazy_virtual_memory = LAZY_INSTANCE_INITIALIZER; |
| +#if defined(OS_LINUX) |
| +bool IsStatsZeroIfUnlimited(unsigned long int fstype) { |
| + // On Linux, stats.f_blocks is 0 when memory based file system (like tmpfs, |
| + // ramfs, or hugetlbfs), is mounted without any size limit (i.e. size set to |
| + // 0). |
| + return fstype == TMPFS_MAGIC || fstype == HUGETLBFS_MAGIC || |
| + fstype == RAMFS_MAGIC; |
| +} |
| +#endif |
| + |
| bool GetDiskSpaceInfo(const base::FilePath& path, |
| int64_t* available_bytes, |
| int64_t* total_bytes) { |
| - struct statvfs stats; |
| - if (HANDLE_EINTR(statvfs(path.value().c_str(), &stats)) != 0) |
| + struct statfs stats; |
| + |
| + if (HANDLE_EINTR(statfs(path.value().c_str(), &stats)) != 0) |
| return false; |
| - if (available_bytes) |
| - *available_bytes = static_cast<int64_t>(stats.f_bavail) * stats.f_frsize; |
| - if (total_bytes) |
| - *total_bytes = static_cast<int64_t>(stats.f_blocks) * stats.f_frsize; |
| +#if defined(OS_LINUX) |
| + const bool zero_size_means_unlimited = |
| + stats.f_blocks == 0 && IsStatsZeroIfUnlimited(stats.f_type); |
| +#else |
| + const bool zero_size_means_unlimited = false; |
| +#endif |
| + |
| + if (available_bytes) { |
| + *available_bytes = |
| + zero_size_means_unlimited |
| + ? std::numeric_limits<int64_t>::max() |
| + : static_cast<int64_t>(stats.f_bavail) * stats.f_frsize; |
| + } |
| + |
| + if (total_bytes) { |
| + *total_bytes = zero_size_means_unlimited |
| + ? std::numeric_limits<int64_t>::max() |
| + : static_cast<int64_t>(stats.f_blocks) * stats.f_frsize; |
| + } |
| + |
| return true; |
| } |