Get eraseMaxGeometry and eraseMinGeometry from dbus
Also, make findDevice return output parameters based on RVO.
With the change like in EntityManager JSON:
```
{
"Name": "example_emmc",
"Type": "EmmcDevice",
"LocationCode": "location"
"EraseMaxGeometry": 10000000000,
"EraseMinGeometry": 5000000000,
}
```
and geometry values will be set to estoraged.
Tested:
- unit test pass:
```
5/7 util_test OK 0.05s
```
Change-Id: Ia8499af2168c7e740558978273fc80456eb29282
Signed-off-by: Tom Tung <shes050117@gmail.com>
diff --git a/include/estoraged.hpp b/include/estoraged.hpp
index 871fdca..ec8f467 100644
--- a/include/estoraged.hpp
+++ b/include/estoraged.hpp
@@ -44,6 +44,8 @@
* @param[in] partNumber - part number for the storage device
* @param[in] serialNumber - serial number for the storage device
* @param[in] locationCode - location code for the storage device
+ * @param[in] eraseMaxGeometry - max geometry to erase if it's specified
+ * @param[in] eraseMinGeometry - min geometry to erase if it's specified
* @param[in] cryptInterface - (optional) pointer to CryptsetupInterface
* object
* @param[in] fsInterface - (optional) pointer to FilesystemInterface
@@ -53,7 +55,8 @@
const std::string& configPath, const std::string& devPath,
const std::string& luksName, uint64_t size, uint8_t lifeTime,
const std::string& partNumber, const std::string& serialNumber,
- const std::string& locationCode,
+ const std::string& locationCode, uint64_t eraseMaxGeometry,
+ uint64_t eraseMinGeometry,
std::unique_ptr<CryptsetupInterface> cryptInterface =
std::make_unique<Cryptsetup>(),
std::unique_ptr<FilesystemInterface> fsInterface =
@@ -118,6 +121,12 @@
/** @brief Mount point for the filesystem. */
std::string mountPoint;
+ /** @brief Max geometry to erase. */
+ uint64_t eraseMaxGeometry;
+
+ /** @brief Min geometry to erase. */
+ uint64_t eraseMinGeometry;
+
/** @brief Indicates whether the LUKS device is currently locked. */
bool lockedProperty{false};
diff --git a/include/util.hpp b/include/util.hpp
index ff38cdd..8f5a0ff 100644
--- a/include/util.hpp
+++ b/include/util.hpp
@@ -2,6 +2,7 @@
#include "getConfig.hpp"
#include <filesystem>
+#include <optional>
#include <string>
namespace estoraged
@@ -9,6 +10,25 @@
namespace util
{
+struct DeviceInfo
+{
+ std::filesystem::path deviceFile;
+ std::filesystem::path sysfsDir;
+ std::string luksName;
+ std::string locationCode;
+ uint64_t eraseMaxGeometry;
+ uint64_t eraseMinGeometry;
+
+ DeviceInfo(std::filesystem::path& deviceFile,
+ std::filesystem::path& sysfsDir, std::string& luksName,
+ std::string& locationCode, uint64_t eraseMaxGeometry,
+ uint64_t eraseMinGeometry) :
+ deviceFile(deviceFile),
+ sysfsDir(sysfsDir), luksName(luksName), locationCode(locationCode),
+ eraseMaxGeometry(eraseMaxGeometry), eraseMinGeometry(eraseMinGeometry)
+ {}
+};
+
/** @brief finds the size of the linux block device in bytes
* @param[in] devpath - the name of the linux block device
* @return size of a block device using the devPath
@@ -43,17 +63,11 @@
* @param[in] data - map of properties from the config object.
* @param[in] searchDir - directory to search for devices in sysfs, e.g.
* /sys/block
- * @param[out] deviceFile - device file that was found, e.g. /dev/mmcblk0.
- * @param[out] sysfsDir - directory containing the sysfs entries for this
- * device.
- * @param[out] luksName - name of the encrypted LUKS device.
- *
- * @return True if the device was found. False otherwise.
+ * @return DeviceInfo - metadata for the device if device is found. Null
+ * otherwise.
*/
-bool findDevice(const StorageData& data, const std::filesystem::path& searchDir,
- std::filesystem::path& deviceFile,
- std::filesystem::path& sysfsDir, std::string& luksName,
- std::string& locationCode);
+std::optional<DeviceInfo> findDevice(const StorageData& data,
+ const std::filesystem::path& searchDir);
} // namespace util
diff --git a/include/verifyDriveGeometry.hpp b/include/verifyDriveGeometry.hpp
index 5d17957..144dd8d 100644
--- a/include/verifyDriveGeometry.hpp
+++ b/include/verifyDriveGeometry.hpp
@@ -20,13 +20,17 @@
/** @brief Test if input is in between the max and min expected sizes,
* and throws errors accordingly.
*
- * @param[in] bytes - Size of the block device
+ * @param[in] eraseMaxGeometry - the max expected size to erase.
+ * @param[in] eraseMinGeometry - the min expected size to erase.
+ * @param[in] bytes - Size of the block device.
*/
- void geometryOkay()
+ void geometryOkay(uint64_t eraseMaxGeometry, uint64_t eraseMinGemoetry)
{
- geometryOkay(util::findSizeOfBlockDevice(devPath));
+ geometryOkay(eraseMaxGeometry, eraseMinGemoetry,
+ util::findSizeOfBlockDevice(devPath));
}
- void geometryOkay(uint64_t bytes);
+ void geometryOkay(uint64_t eraseMaxGeometry, uint64_t eraseMinGemoetry,
+ uint64_t bytes);
};
} // namespace estoraged