Update V8 to version 4.6.62.
[chromium-blink-merge.git] / components / metrics / drive_metrics_provider_linux.cc
blob4655bf92e4381c495fec1b528e5d1ad91d8302c5
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/metrics/drive_metrics_provider.h"
7 #include <linux/kdev_t.h> // For MAJOR()/MINOR().
8 #include <sys/stat.h>
9 #include <string>
11 #include "base/files/file.h"
12 #include "base/files/file_path.h"
13 #include "base/files/file_util.h"
14 #include "base/strings/stringprintf.h"
16 #if defined(OS_CHROMEOS)
17 #include "base/sys_info.h"
18 #endif
20 namespace metrics {
22 namespace {
24 // See http://www.kernel.org/doc/Documentation/devices.txt for more info.
25 const int kFirstScsiMajorNumber = 8;
26 const int kPartitionsPerScsiDevice = 16;
27 const char kRotationalFormat[] = "/sys/block/sd%c/queue/rotational";
29 } // namespace
31 // static
32 bool DriveMetricsProvider::HasSeekPenalty(const base::FilePath& path,
33 bool* has_seek_penalty) {
34 #if defined(OS_CHROMEOS)
35 std::string board = base::SysInfo::GetLsbReleaseBoard();
36 if (board != "unknown" && board != "parrot") {
37 // All ChromeOS devices have SSDs. Except some parrots.
38 *has_seek_penalty = false;
39 return true;
41 #endif
43 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ);
44 if (!file.IsValid())
45 return false;
47 struct stat path_stat;
48 int error = fstat(file.GetPlatformFile(), &path_stat);
49 if (error < 0 || MAJOR(path_stat.st_dev) != kFirstScsiMajorNumber) {
50 // TODO(dbeam): support more SCSI major numbers (e.g. /dev/sdq+) and LVM?
51 return false;
54 char sdX = 'a' + MINOR(path_stat.st_dev) / kPartitionsPerScsiDevice;
55 std::string rotational_path = base::StringPrintf(kRotationalFormat, sdX);
56 std::string rotates;
57 if (!base::ReadFileToString(base::FilePath(rotational_path), &rotates))
58 return false;
60 *has_seek_penalty = rotates.substr(0, 1) == "1";
61 return true;
64 } // namespace metrics