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

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: Use GetFileSystemType to special case "f_block == 0" only for memory FS 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 NOTREACHED(); 66 NOTREACHED();
67 return 0; 67 return 0;
68 } 68 }
69 return limit.rlim_cur == RLIM_INFINITY ? 0 : limit.rlim_cur; 69 return limit.rlim_cur == RLIM_INFINITY ? 0 : limit.rlim_cur;
70 } 70 }
71 71
72 base::LazyInstance< 72 base::LazyInstance<
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 } // namespace
Lei Zhang 2016/07/19 23:45:10 No, that's not what I meant. namespace base { na
Sriram 2016/07/19 23:58:37 Done.
77
78 namespace base {
79
76 bool GetDiskSpaceInfo(const base::FilePath& path, 80 bool GetDiskSpaceInfo(const base::FilePath& path,
77 int64_t* available_bytes, 81 int64_t* available_bytes,
78 int64_t* total_bytes) { 82 int64_t* total_bytes) {
79 struct statvfs stats; 83 struct statvfs stats;
80 if (HANDLE_EINTR(statvfs(path.value().c_str(), &stats)) != 0) 84 if (HANDLE_EINTR(statvfs(path.value().c_str(), &stats)) != 0)
81 return false; 85 return false;
82 86
83 if (available_bytes) 87 #if defined(OS_LINUX)
84 *available_bytes = static_cast<int64_t>(stats.f_bavail) * stats.f_frsize; 88 // On Linux, stats.f_blocks is 0 when memory based file system like tmpfs,
85 if (total_bytes) 89 // ramfs, or hugetlbfs (all memory file systems). the is mounted without any
Lei Zhang 2016/07/19 23:45:10 So have you checked the ramfs / hugetlbfs behavior
Lei Zhang 2016/07/19 23:45:10 typo: "the is mounted"
Sriram 2016/07/19 23:58:37 Yes, See Linux code for: hugetlbfs - http://lxr.fr
Sriram 2016/07/19 23:58:37 Done.
86 *total_bytes = static_cast<int64_t>(stats.f_blocks) * stats.f_frsize; 90 // size limit (i.e. size set to 0).
91 FileSystemType fs_type;
92 const bool zero_size_means_unlimited = stats.f_blocks == 0 &&
93 GetFileSystemType(path, &fs_type) &&
94 fs_type == FILE_SYSTEM_MEMORY;
95 #else
96 const bool zero_size_means_unlimited = false;
97 #endif
98
99 if (available_bytes) {
100 *available_bytes = zero_size_means_unlimited ?
101 std::numeric_limits<int64_t>::max() :
102 static_cast<int64_t>(stats.f_bavail) * stats.f_frsize;
103 }
104
105 if (total_bytes) {
106 *total_bytes = zero_size_means_unlimited ?
107 std::numeric_limits<int64_t>::max() :
108 static_cast<int64_t>(stats.f_blocks) * stats.f_frsize;
109 }
87 return true; 110 return true;
88 } 111 }
89 112
90 } // namespace
91
92 namespace base {
93
94 #if !defined(OS_OPENBSD) 113 #if !defined(OS_OPENBSD)
95 int SysInfo::NumberOfProcessors() { 114 int SysInfo::NumberOfProcessors() {
96 return g_lazy_number_of_processors.Get().value(); 115 return g_lazy_number_of_processors.Get().value();
97 } 116 }
98 #endif 117 #endif
99 118
100 // static 119 // static
101 int64_t SysInfo::AmountOfVirtualMemory() { 120 int64_t SysInfo::AmountOfVirtualMemory() {
102 return g_lazy_virtual_memory.Get().value(); 121 return g_lazy_virtual_memory.Get().value();
103 } 122 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 } 180 }
162 return arch; 181 return arch;
163 } 182 }
164 183
165 // static 184 // static
166 size_t SysInfo::VMAllocationGranularity() { 185 size_t SysInfo::VMAllocationGranularity() {
167 return getpagesize(); 186 return getpagesize();
168 } 187 }
169 188
170 } // namespace base 189 } // 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