• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "components/metrics/drive_metrics_provider.h"
6 
7 #include <windows.h>
8 #include <winioctl.h>
9 #include <vector>
10 
11 #include "base/files/file.h"
12 #include "base/files/file_path.h"
13 
14 namespace metrics {
15 
16 // static
HasSeekPenalty(const base::FilePath & path,bool * has_seek_penalty)17 bool DriveMetricsProvider::HasSeekPenalty(const base::FilePath& path,
18                                           bool* has_seek_penalty) {
19   std::vector<base::FilePath::StringType> components = path.GetComponents();
20 
21   base::File volume(base::FilePath(L"\\\\.\\" + components[0]),
22                     base::File::FLAG_OPEN);
23   if (!volume.IsValid())
24     return false;
25 
26   STORAGE_PROPERTY_QUERY query = {};
27   query.QueryType = PropertyStandardQuery;
28   query.PropertyId = StorageDeviceSeekPenaltyProperty;
29 
30   DEVICE_SEEK_PENALTY_DESCRIPTOR result;
31   DWORD bytes_returned;
32 
33   BOOL success = DeviceIoControl(
34       volume.GetPlatformFile(), IOCTL_STORAGE_QUERY_PROPERTY, &query,
35       sizeof(query), &result, sizeof(result), &bytes_returned, nullptr);
36 
37   if (success == FALSE || bytes_returned < sizeof(result))
38     return false;
39 
40   *has_seek_penalty = result.IncursSeekPenalty != FALSE;
41   return true;
42 }
43 
44 }  // namespace metrics
45