Chromium Code Reviews| Index: base/sys_info_win.cc |
| diff --git a/base/sys_info_win.cc b/base/sys_info_win.cc |
| index 9cc0cfa48a3637d48c36978de2c798383e9a194d..0a20b6c2e4b379b96328191d4a484fd6c5988e82 100644 |
| --- a/base/sys_info_win.cc |
| +++ b/base/sys_info_win.cc |
| @@ -5,12 +5,14 @@ |
| #include "base/sys_info.h" |
| #include <windows.h> |
| +#include <winioctl.h> |
| #include "base/files/file_path.h" |
| #include "base/logging.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/threading/thread_restrictions.h" |
| +#include "base/win/scoped_handle.h" |
| #include "base/win/windows_version.h" |
| namespace { |
| @@ -55,16 +57,56 @@ int64 SysInfo::AmountOfVirtualMemory() { |
| // static |
| int64 SysInfo::AmountOfFreeDiskSpace(const FilePath& path) { |
| - base::ThreadRestrictions::AssertIOAllowed(); |
| + ThreadRestrictions::AssertIOAllowed(); |
| ULARGE_INTEGER available, total, free; |
| - if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free)) { |
| + if (!GetDiskFreeSpaceExW(path.value().c_str(), &available, &total, &free)) |
| return -1; |
| - } |
| + |
| int64 rv = static_cast<int64>(available.QuadPart); |
| - if (rv < 0) |
| - rv = kint64max; |
| - return rv; |
| + return rv < 0 ? kint64max : rv; |
| +} |
| + |
| +bool SysInfo::HasSeekPenalty(const FilePath& path, bool* has_seek_penalty) { |
| + ThreadRestrictions::AssertIOAllowed(); |
| + |
| + if (!path.IsAbsolute() || !has_seek_penalty) |
|
rvargas (doing something else)
2015/03/12 22:01:12
I would probably also DCHECK the first condition g
Dan Beam
2015/03/13 19:31:32
Done.
|
| + return false; |
| + |
| + std::vector<FilePath::StringType> components; |
| + path.GetComponents(&components); |
| + |
| + FilePath::StringType drive = L"\\\\.\\" + components[0]; |
|
rvargas (doing something else)
2015/03/12 22:01:12
This syntax is not supported before win7
Dan Beam
2015/03/13 19:31:32
Acknowledged.
|
| + win::ScopedHandle handle(CreateFile( |
|
rvargas (doing something else)
2015/03/12 22:01:12
Looks like a job for base::File
Dan Beam
2015/03/13 19:31:32
Done.
|
| + drive.c_str(), |
| + 0, |
| + FILE_SHARE_READ | FILE_SHARE_WRITE, |
| + NULL, |
| + OPEN_EXISTING, |
| + 0, |
| + NULL)); |
| + |
| + if (!handle.IsValid()) |
| + return false; |
| + |
| + STORAGE_PROPERTY_QUERY query; |
| + query.QueryType = PropertyStandardQuery; |
| + query.PropertyId = StorageDeviceSeekPenaltyProperty; |
|
rvargas (doing something else)
2015/03/12 22:01:11
Not supported on XP
Dan Beam
2015/03/13 19:31:32
Acknowledged.
|
| + |
| + DEVICE_SEEK_PENALTY_DESCRIPTOR result; |
| + DWORD unused_bytes_returned; |
| + |
| + if (!DeviceIoControl(handle.Get(), |
| + IOCTL_STORAGE_QUERY_PROPERTY, |
| + &query, sizeof(query), |
| + &result, sizeof(result), |
| + &unused_bytes_returned, |
|
rvargas (doing something else)
2015/03/12 22:01:12
Verify that this is >= sizeof(result) before acces
Dan Beam
2015/03/13 19:31:32
Done.
|
| + NULL)) { |
| + return false; |
| + } |
| + |
| + *has_seek_penalty = !!result.IncursSeekPenalty; |
|
rvargas (doing something else)
2015/03/12 22:01:12
nit: != FALSE? (I hate using "!!" to do this).
Dan Beam
2015/03/13 19:31:32
why not == TRUE?
|
| + return true; |
| } |
| // static |