blob: b26b64a514632f0f9f165be643a1ca11d9d4f0dd [file] [log] [blame]
Gediminas Ramanauskas2f0b8852013-03-14 13:52:32 -07001// Copyright (c) 2012 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
Alex Vakulenko262be3f2014-07-30 15:25:50 -07005#ifndef DEBUGD_SRC_STORAGE_TOOL_H_
6#define DEBUGD_SRC_STORAGE_TOOL_H_
Gediminas Ramanauskas2f0b8852013-03-14 13:52:32 -07007
8#include <string>
Alexis Saverye39d3492017-11-07 18:10:08 -08009#include <vector>
Gediminas Ramanauskas2f0b8852013-03-14 13:52:32 -070010
Alexis Saverye39d3492017-11-07 18:10:08 -080011#include <base/files/file_path.h>
Eric Caruso0b241882018-04-04 13:43:46 -070012#include <base/files/scoped_file.h>
Ben Chan657bed82014-09-02 20:40:51 -070013#include <base/macros.h>
Gediminas Ramanauskas2f0b8852013-03-14 13:52:32 -070014
Alex Vakulenko262be3f2014-07-30 15:25:50 -070015#include "debugd/src/subprocess_tool.h"
Gediminas Ramanauskas2f0b8852013-03-14 13:52:32 -070016
17namespace debugd {
18
19class StorageTool : public SubprocessTool {
20 public:
Ben Chan78f89532014-08-29 09:35:09 -070021 StorageTool() = default;
Qijiang Fan6bc59e12020-11-11 02:51:06 +090022 StorageTool(const StorageTool&) = delete;
23 StorageTool& operator=(const StorageTool&) = delete;
24
Ben Chan78f89532014-08-29 09:35:09 -070025 ~StorageTool() override = default;
Gediminas Ramanauskas2f0b8852013-03-14 13:52:32 -070026
Eric Carusoc93a15c2017-04-24 16:15:12 -070027 std::string Smartctl(const std::string& option);
Eric Caruso0b241882018-04-04 13:43:46 -070028 std::string Start(const base::ScopedFD& outfd);
Alexis Saverye39d3492017-11-07 18:10:08 -080029 const base::FilePath GetDevice(const base::FilePath& filesystem,
30 const base::FilePath& mountsFile);
31 bool IsSupported(const base::FilePath typeFile,
32 const base::FilePath vendFile,
33 std::string* errorMsg);
Ting Shen92dd7832018-12-21 17:45:07 +080034 std::string Mmc(const std::string& option);
Oleh Lamzinfb868682019-09-03 19:23:28 +020035 std::string Nvme(const std::string& option);
Wayne Kung8a786fb2019-12-24 12:19:11 +080036 std::string NvmeLog(const uint32_t& page_id,
37 const uint32_t& length,
38 bool raw_binary);
Ben Chana0011d82014-05-13 00:19:29 -070039
Gediminas Ramanauskas2f0b8852013-03-14 13:52:32 -070040 private:
Alexis Saverye39d3492017-11-07 18:10:08 -080041 // Returns the partition of |dst| as a string. |dst| is expected
42 // to be a storage device path (e.g. "/dev/sda1").
43 const std::string GetPartition(const std::string& dst);
44
45 // Removes the partition from |dstPath| which is expected
46 // to be a storage device path (e.g. "/dev/mmcblk1p2").
47 void StripPartition(base::FilePath* dstPath);
Gediminas Ramanauskas2f0b8852013-03-14 13:52:32 -070048};
49
Ben Chana0011d82014-05-13 00:19:29 -070050} // namespace debugd
Gediminas Ramanauskas2f0b8852013-03-14 13:52:32 -070051
Alex Vakulenko262be3f2014-07-30 15:25:50 -070052#endif // DEBUGD_SRC_STORAGE_TOOL_H_