blob: 07901f5c4f0eedd6ee394c56d1532c2a3db68061 [file] [log] [blame]
Alex Deymo42432912013-07-12 20:21:15 -07001// Copyright (c) 2013 The Chromium OS 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.
4
5#include "update_engine/hardware.h"
6
7#include <base/logging.h>
8#include <rootdev/rootdev.h>
9
10using std::string;
11
12namespace chromeos_update_engine {
13
14const string Hardware::BootDevice() {
15 char boot_path[PATH_MAX];
16 // Resolve the boot device path fully, including dereferencing
17 // through dm-verity.
18 int ret = rootdev(boot_path, sizeof(boot_path), true, false);
19
20 if (ret < 0) {
21 LOG(ERROR) << "rootdev failed to find the root device";
22 return "";
23 }
24 LOG_IF(WARNING, ret > 0) << "rootdev found a device name with no device node";
25
26 // This local variable is used to construct the return string and is not
27 // passed around after use.
28 return boot_path;
29}
30
31const string Hardware::KernelDeviceOfBootDevice(
32 const std::string& boot_device) {
33 // Currently this assumes the last digit of the boot device is
34 // 3, 5, or 7, and changes it to 2, 4, or 6, respectively, to
35 // get the kernel device.
36 string ret = boot_device;
37 if (ret.empty())
38 return ret;
39 char last_char = ret[ret.size() - 1];
40 if (last_char == '3' || last_char == '5' || last_char == '7') {
41 ret[ret.size() - 1] = last_char - 1;
42 return ret;
43 }
44 return "";
45}
46
47} // namespace chromeos_update_engine