1 #pragma once 2 #include "getConfig.hpp" 3 4 #include <filesystem> 5 #include <optional> 6 #include <string> 7 8 namespace estoraged 9 { 10 namespace util 11 { 12 13 struct DeviceInfo 14 { 15 std::filesystem::path deviceFile; 16 std::filesystem::path sysfsDir; 17 std::string luksName; 18 std::string locationCode; 19 uint64_t eraseMaxGeometry; 20 uint64_t eraseMinGeometry; 21 22 DeviceInfo(std::filesystem::path& deviceFile, 23 std::filesystem::path& sysfsDir, std::string& luksName, 24 std::string& locationCode, uint64_t eraseMaxGeometry, 25 uint64_t eraseMinGeometry) : 26 deviceFile(deviceFile), 27 sysfsDir(sysfsDir), luksName(luksName), locationCode(locationCode), 28 eraseMaxGeometry(eraseMaxGeometry), eraseMinGeometry(eraseMinGeometry) 29 {} 30 }; 31 32 /** @brief finds the size of the linux block device in bytes 33 * @param[in] devpath - the name of the linux block device 34 * @return size of a block device using the devPath 35 */ 36 uint64_t findSizeOfBlockDevice(const std::string& devPath); 37 38 /** @brief finds the predicted life left for a eMMC device 39 * @param[in] sysfsPath - The path to the linux sysfs interface 40 * @return the life remaing for the emmc, as a percentage. 41 */ 42 uint8_t findPredictedMediaLifeLeftPercent(const std::string& sysfsPath); 43 44 /** @brief Get the part number (aka part name) for the storage device 45 * @param[in] sysfsPath - The path to the linux sysfs interface. 46 * @return part name as a string (or "unknown" if it couldn't be retrieved) 47 */ 48 std::string getPartNumber(const std::filesystem::path& sysfsPath); 49 50 /** @brief Get the serial number for the storage device 51 * @param[in] sysfsPath - The path to the linux sysfs interface. 52 * @return serial name as a string (or "unknown" if it couldn't be retrieved) 53 */ 54 std::string getSerialNumber(const std::filesystem::path& sysfsPath); 55 56 /** @brief Look for the device described by the provided StorageData. 57 * @details Currently, this function assumes that there's only one eMMC. 58 * When we need to support multiple eMMCs, we will put more information in 59 * the EntityManager config, to differentiate between them. Also, if we 60 * want to support other types of storage devices, this function will need 61 * to be updated. 62 * 63 * @param[in] data - map of properties from the config object. 64 * @param[in] searchDir - directory to search for devices in sysfs, e.g. 65 * /sys/block 66 * @return DeviceInfo - metadata for the device if device is found. Null 67 * otherwise. 68 */ 69 std::optional<DeviceInfo> findDevice(const StorageData& data, 70 const std::filesystem::path& searchDir); 71 72 } // namespace util 73 74 } // namespace estoraged 75