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..7db6fd15d3a3787530bc93b64c963a6a45c5fa00 100644 |
| --- a/base/sys_info_posix.cc |
| +++ b/base/sys_info_posix.cc |
| @@ -28,6 +28,10 @@ |
| #include <sys/statvfs.h> |
| #endif |
| +#if defined(OS_LINUX) |
| +#include <linux/magic.h> |
| +#endif |
| + |
| namespace { |
| #if !defined(OS_OPENBSD) |
| @@ -73,6 +77,15 @@ 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 fsid) { |
| + // 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 fsid == TMPFS_MAGIC || fsid == HUGETLBFS_MAGIC || fsid == RAMFS_MAGIC; |
| +} |
| +#endif |
| + |
| bool GetDiskSpaceInfo(const base::FilePath& path, |
| int64_t* available_bytes, |
| int64_t* total_bytes) { |
| @@ -80,10 +93,26 @@ bool GetDiskSpaceInfo(const base::FilePath& path, |
| if (HANDLE_EINTR(statvfs(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_fsid); |
|
Lei Zhang
2016/08/01 21:30:55
Are you sure f_fsid is the right field to check? L
Sriram
2016/08/02 00:03:24
You are right - I misunderstood the man page and f
|
| +#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; |
| } |