Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 return g_lazy_virtual_memory.Get().value(); | 88 return g_lazy_virtual_memory.Get().value(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 // static | 91 // static |
| 92 int64_t SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { | 92 int64_t SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { |
| 93 base::ThreadRestrictions::AssertIOAllowed(); | 93 base::ThreadRestrictions::AssertIOAllowed(); |
| 94 | 94 |
| 95 struct statvfs stats; | 95 struct statvfs stats; |
| 96 if (HANDLE_EINTR(statvfs(path.value().c_str(), &stats)) != 0) | 96 if (HANDLE_EINTR(statvfs(path.value().c_str(), &stats)) != 0) |
| 97 return -1; | 97 return -1; |
| 98 return static_cast<int64_t>(stats.f_bavail) * stats.f_frsize; | 98 return static_cast<int64_t>(stats.f_bavail) * stats.f_frsize; |
|
Dan Beam
2016/06/09 17:20:13
nit: maybe use GetDiskSpaceInfo() to implement Amo
fukino
2016/06/10 01:33:36
Done.
I updated this to use GetDiskSpaceInfo() in
| |
| 99 } | 99 } |
| 100 | 100 |
| 101 // static | |
| 102 bool SysInfo::GetDiskSpaceInfo(const FilePath& path, | |
| 103 int64_t* available_bytes, | |
| 104 int64_t* total_bytes) { | |
| 105 ThreadRestrictions::AssertIOAllowed(); | |
| 106 | |
| 107 struct statvfs stats; | |
| 108 if (HANDLE_EINTR(statvfs(path.value().c_str(), &stats)) != 0) | |
| 109 return false; | |
| 110 | |
| 111 *available_bytes = static_cast<uint64_t>(stats.f_bavail) * stats.f_frsize; | |
| 112 *total_bytes = static_cast<uint64_t>(stats.f_blocks) * stats.f_frsize; | |
| 113 return true; | |
| 114 } | |
| 115 | |
| 101 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) | 116 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) |
| 102 // static | 117 // static |
| 103 std::string SysInfo::OperatingSystemName() { | 118 std::string SysInfo::OperatingSystemName() { |
| 104 struct utsname info; | 119 struct utsname info; |
| 105 if (uname(&info) < 0) { | 120 if (uname(&info) < 0) { |
| 106 NOTREACHED(); | 121 NOTREACHED(); |
| 107 return std::string(); | 122 return std::string(); |
| 108 } | 123 } |
| 109 return std::string(info.sysname); | 124 return std::string(info.sysname); |
| 110 } | 125 } |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 137 } | 152 } |
| 138 return arch; | 153 return arch; |
| 139 } | 154 } |
| 140 | 155 |
| 141 // static | 156 // static |
| 142 size_t SysInfo::VMAllocationGranularity() { | 157 size_t SysInfo::VMAllocationGranularity() { |
| 143 return getpagesize(); | 158 return getpagesize(); |
| 144 } | 159 } |
| 145 | 160 |
| 146 } // namespace base | 161 } // namespace base |
| OLD | NEW |