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

Unified Diff: base/sys_info_posix.cc

Issue 2152283003: 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: Created 4 years, 5 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..9f110c3cd6928477505232f304ce2ad216ac6d25 100644
--- a/base/sys_info_posix.cc
+++ b/base/sys_info_posix.cc
@@ -80,10 +80,19 @@ 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;
+ // f_blocks is 0 when tmpfs is mounted without any size limit (i.e. size set
Lei Zhang 2016/07/16 00:19:12 You need to check that the file system is tmpfs. T
Lei Zhang 2016/07/18 19:05:07 Basically something like the following, though it
Sriram 2016/07/19 23:41:32 Acknowledged.
Sriram 2016/07/19 23:41:32 Done.
+ // to 0).
+ if (available_bytes) {
+ *available_bytes = (stats.f_blocks == 0) ?
+ std::numeric_limits<int64_t>::max() :
+ static_cast<int64_t>(stats.f_bavail) * stats.f_frsize;
+ }
+
+ if (total_bytes) {
+ *total_bytes = (stats.f_blocks == 0) ?
+ 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