Hotfixes for vitastor-disk prepare: max_other, get device size, older sfdisk

This commit is contained in:
Vitaliy Filippov
2022-09-05 12:48:27 +03:00
parent 8d9a5fde15
commit 150f369346
3 changed files with 43 additions and 10 deletions
+14 -3
View File
@@ -333,13 +333,24 @@ json11::Json read_parttable(std::string dev)
return pt;
}
uint64_t dev_size_from_parttable(json11::Json pt)
{
uint64_t free = pt["lastlba"].uint64_value() + 1 - pt["firstlba"].uint64_value();
if (!pt["sectorsize"].uint64_value())
free *= 512;
else
free *= pt["sectorsize"].uint64_value();
return free;
}
uint64_t free_from_parttable(json11::Json pt)
{
uint64_t free = pt["lastlba"].uint64_value() + 1 - pt["firstlba"].uint64_value();
for (const auto & part: pt["partitions"].array_items())
{
free -= part["size"].uint64_value();
}
free *= pt["sectorsize"].uint64_value();
if (!pt["sectorsize"].uint64_value())
free *= 512;
else
free *= pt["sectorsize"].uint64_value();
return free;
}