For HD Product name, use GiB unit from 10,000 Mib and higher. (#1147)

* For HD Product name, use GiB unit from 10,000 Mib and higher.

* Update unit test
This commit is contained in:
Daniel Markstedt 2023-04-20 06:38:31 -07:00 committed by GitHub
parent 8dd5071122
commit 3cceb515cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -36,9 +36,9 @@ string SCSIHD::GetProductData() const
uint64_t capacity = GetBlockCount() * GetSectorSizeInBytes();
string unit;
// 10 GiB and more
if (capacity >= 1'099'511'627'776) {
capacity /= 1'099'511'627'776;
// 10,000 MiB and more
if (capacity >= 10'485'760'000) {
capacity /= 1'073'741'824;
unit = "GiB";
}
// 1 MiB and more

View File

@ -69,10 +69,10 @@ TEST(ScsiHdTest, GetProductData)
hd_gb.SetFilename(string(filename));
hd_gb.SetSectorSizeInBytes(1024);
hd_gb.SetBlockCount(1'099'511'627'776 / 1024);
hd_gb.SetBlockCount(10'737'418'240 / 1024);
hd_gb.FinalizeSetup(0);
s = hd_gb.GetProduct();
EXPECT_NE(string::npos, s.find("1 GiB"));
EXPECT_NE(string::npos, s.find("10 GiB"));
remove(filename);
}