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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/sys_info.h" 5 #include "base/sys_info.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 base::internal::LazySysInfoValue<int64_t, AmountOfVirtualMemory>>::Leaky 73 base::internal::LazySysInfoValue<int64_t, AmountOfVirtualMemory>>::Leaky
74 g_lazy_virtual_memory = LAZY_INSTANCE_INITIALIZER; 74 g_lazy_virtual_memory = LAZY_INSTANCE_INITIALIZER;
75 75
76 bool GetDiskSpaceInfo(const base::FilePath& path, 76 bool GetDiskSpaceInfo(const base::FilePath& path,
77 int64_t* available_bytes, 77 int64_t* available_bytes,
78 int64_t* total_bytes) { 78 int64_t* total_bytes) {
79 struct statvfs stats; 79 struct statvfs stats;
80 if (HANDLE_EINTR(statvfs(path.value().c_str(), &stats)) != 0) 80 if (HANDLE_EINTR(statvfs(path.value().c_str(), &stats)) != 0)
81 return false; 81 return false;
82 82
83 if (available_bytes) 83 // 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.
84 *available_bytes = static_cast<int64_t>(stats.f_bavail) * stats.f_frsize; 84 // to 0).
85 if (total_bytes) 85 if (available_bytes) {
86 *total_bytes = static_cast<int64_t>(stats.f_blocks) * stats.f_frsize; 86 *available_bytes = (stats.f_blocks == 0) ?
87 std::numeric_limits<int64_t>::max() :
88 static_cast<int64_t>(stats.f_bavail) * stats.f_frsize;
89 }
90
91 if (total_bytes) {
92 *total_bytes = (stats.f_blocks == 0) ?
93 std::numeric_limits<int64_t>::max() :
94 static_cast<int64_t>(stats.f_blocks) * stats.f_frsize;
95 }
87 return true; 96 return true;
88 } 97 }
89 98
90 } // namespace 99 } // namespace
91 100
92 namespace base { 101 namespace base {
Lei Zhang 2016/07/18 19:05:07 If you can move this up to wrap the anonymous name
Sriram 2016/07/19 23:41:32 Done.
93 102
94 #if !defined(OS_OPENBSD) 103 #if !defined(OS_OPENBSD)
95 int SysInfo::NumberOfProcessors() { 104 int SysInfo::NumberOfProcessors() {
96 return g_lazy_number_of_processors.Get().value(); 105 return g_lazy_number_of_processors.Get().value();
97 } 106 }
98 #endif 107 #endif
99 108
100 // static 109 // static
101 int64_t SysInfo::AmountOfVirtualMemory() { 110 int64_t SysInfo::AmountOfVirtualMemory() {
102 return g_lazy_virtual_memory.Get().value(); 111 return g_lazy_virtual_memory.Get().value();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 } 170 }
162 return arch; 171 return arch;
163 } 172 }
164 173
165 // static 174 // static
166 size_t SysInfo::VMAllocationGranularity() { 175 size_t SysInfo::VMAllocationGranularity() {
167 return getpagesize(); 176 return getpagesize();
168 } 177 }
169 178
170 } // namespace base 179 } // namespace base
OLDNEW
« 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