Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2126)

Unified Diff: base/sys_info_posix.cc

Issue 2198283002: Return correct disk free/available size when FS is mounted with size = 0 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update based on CR comment and fix try bot failure. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/sys_info_posix.cc
diff --git a/base/sys_info_posix.cc b/base/sys_info_posix.cc
index 5d1c450139a575705c3c5046ed32c565e4b5e404..f480055cc4b472304b51e1c8f5c9d6246b81cbce 100644
--- a/base/sys_info_posix.cc
+++ b/base/sys_info_posix.cc
@@ -28,6 +28,11 @@
#include <sys/statvfs.h>
#endif
+#if defined(OS_LINUX)
+#include <linux/magic.h>
+#include <sys/vfs.h>
+#endif
+
namespace {
#if !defined(OS_OPENBSD)
@@ -73,6 +78,23 @@ base::LazyInstance<
base::internal::LazySysInfoValue<int64_t, AmountOfVirtualMemory>>::Leaky
g_lazy_virtual_memory = LAZY_INSTANCE_INITIALIZER;
+#if defined(OS_LINUX)
+bool IsStatsZeroIfUnlimited(const base::FilePath& path) {
+ struct statfs stats;
+
+ if (HANDLE_EINTR(statfs(path.value().c_str(), &stats)) != 0)
+ return false;
+
+ switch (stats.f_type) {
+ case TMPFS_MAGIC:
+ case HUGETLBFS_MAGIC:
+ case RAMFS_MAGIC:
+ return true;
+ }
+ return false;
+}
+#endif
+
bool GetDiskSpaceInfo(const base::FilePath& path,
int64_t* available_bytes,
int64_t* total_bytes) {
@@ -80,10 +102,25 @@ 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(path);
+#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;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698