Index: base/sys_info_win.cc |
diff --git a/base/sys_info_win.cc b/base/sys_info_win.cc |
index 9cc0cfa48a3637d48c36978de2c798383e9a194d..7c12524f15cd813771d2f7bb53b22cb22d821481 100644 |
--- a/base/sys_info_win.cc |
+++ b/base/sys_info_win.cc |
@@ -5,7 +5,9 @@ |
#include "base/sys_info.h" |
#include <windows.h> |
+#include <winioctl.h> |
+#include "base/files/file.h" |
#include "base/files/file_path.h" |
#include "base/logging.h" |
#include "base/memory/scoped_ptr.h" |
@@ -24,9 +26,7 @@ int64 AmountOfMemory(DWORDLONG MEMORYSTATUSEX::* memory_field) { |
} |
int64 rv = static_cast<int64>(memory_info.*memory_field); |
- if (rv < 0) |
- rv = kint64max; |
- return rv; |
+ return rv < 0 ? kint64max : rv; |
} |
} // namespace |
@@ -55,16 +55,51 @@ 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(); |
+ |
+ DCHECK(path.IsAbsolute()); |
+ DCHECK(has_seek_penalty); |
+ |
+ // TODO(dbeam): Vista, XP support. |
+ if (win::GetVersion() < win::VERSION_WIN7) |
+ return false; |
+ |
+ std::vector<FilePath::StringType> components; |
+ path.GetComponents(&components); |
+ |
+ File drive(FilePath(L"\\\\.\\" + components[0]), File::FLAG_OPEN); |
+ if (!drive.IsValid()) |
+ return false; |
+ |
+ STORAGE_PROPERTY_QUERY query; |
+ query.QueryType = PropertyStandardQuery; |
+ query.PropertyId = StorageDeviceSeekPenaltyProperty; |
+ |
+ DEVICE_SEEK_PENALTY_DESCRIPTOR result; |
+ DWORD bytes_returned; |
+ |
+ BOOL success = DeviceIoControl(drive.GetPlatformFile(), |
+ IOCTL_STORAGE_QUERY_PROPERTY, |
+ &query, sizeof(query), |
+ &result, sizeof(result), |
+ &bytes_returned, |
+ NULL); |
+ if (success == FALSE || bytes_returned < sizeof(result)) |
+ return false; |
+ |
+ *has_seek_penalty = result.IncursSeekPenalty != FALSE; |
+ return true; |
} |
// static |