blob: a6af6ed84e80f518f9e9a9f975605bc30fbc729e [file] [log] [blame]
John Edward Broadbenta6e3b992022-03-17 14:33:15 -07001#pragma once
John Wedigd32b9662022-04-13 18:12:25 -07002#include "getConfig.hpp"
3
4#include <filesystem>
John Edward Broadbent5d799bb2022-03-22 16:14:24 -07005#include <string>
John Edward Broadbenta6e3b992022-03-17 14:33:15 -07006
7namespace estoraged
8{
9namespace util
10{
11
John Edward Broadbent5d799bb2022-03-22 16:14:24 -070012/** @brief finds the size of the linux block device in bytes
13 * @param[in] devpath - the name of the linux block device
14 * @return size of a block device using the devPath
15 */
16uint64_t findSizeOfBlockDevice(const std::string& devPath);
17
18/** @brief finds the predicted life left for a eMMC device
19 * @param[in] sysfsPath - The path to the linux sysfs interface
20 * @return the life remaing for the emmc, as a percentage.
21 */
22uint8_t findPredictedMediaLifeLeftPercent(const std::string& sysfsPath);
John Edward Broadbenta6e3b992022-03-17 14:33:15 -070023
John Wedigb4838302022-07-22 13:51:16 -070024/** @brief Get the part number (aka part name) for the storage device
25 * @param[in] sysfsPath - The path to the linux sysfs interface.
26 * @return part name as a string (or "unknown" if it couldn't be retrieved)
27 */
28std::string getPartNumber(const std::filesystem::path& sysfsPath);
29
30/** @brief Get the serial number for the storage device
31 * @param[in] sysfsPath - The path to the linux sysfs interface.
32 * @return serial name as a string (or "unknown" if it couldn't be retrieved)
33 */
34std::string getSerialNumber(const std::filesystem::path& sysfsPath);
35
John Wedigd32b9662022-04-13 18:12:25 -070036/** @brief Look for the device described by the provided StorageData.
37 * @details Currently, this function assumes that there's only one eMMC.
38 * When we need to support multiple eMMCs, we will put more information in
39 * the EntityManager config, to differentiate between them. Also, if we
40 * want to support other types of storage devices, this function will need
41 * to be updated.
42 *
43 * @param[in] data - map of properties from the config object.
44 * @param[in] searchDir - directory to search for devices in sysfs, e.g.
45 * /sys/block
46 * @param[out] deviceFile - device file that was found, e.g. /dev/mmcblk0.
47 * @param[out] sysfsDir - directory containing the sysfs entries for this
48 * device.
49 * @param[out] luksName - name of the encrypted LUKS device.
50 *
51 * @return True if the device was found. False otherwise.
52 */
53bool findDevice(const StorageData& data, const std::filesystem::path& searchDir,
54 std::filesystem::path& deviceFile,
55 std::filesystem::path& sysfsDir, std::string& luksName);
56
John Edward Broadbenta6e3b992022-03-17 14:33:15 -070057} // namespace util
58
59} // namespace estoraged