Skip to content

Commit

Permalink
Move code
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Jan 15, 2025
1 parent f29f479 commit 740c6b8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 28 deletions.
43 changes: 19 additions & 24 deletions cpp/devices/scsi_hd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,31 @@ ScsiHd::ScsiHd(int lun, bool removable, bool apple, bool scsi1, const set<uint32
SetRemovable(removable);
}

string ScsiHd::GetProductDataString() const
{
uint64_t capacity = GetBlockCount() * GetBlockSize();
string unit;

// 10,000 MiB and more
if (capacity >= 10'485'760'000) {
capacity /= 1'073'741'824;
unit = "GiB";
}
// 1 MiB and more
else if (capacity >= 1'048'576) {
capacity /= 1'048'576;
unit = "MiB";
}
else {
capacity /= 1024;
unit = "KiB";
}

return fmt::format("{0} {1} {2}", DEFAULT_PRODUCT, capacity, unit);
}

void ScsiHd::FinalizeSetup()
{
ValidateFile();

// For non-removable media drives set the default product name based on the drive capacity
if (!IsRemovable()) {
SetProductData( { "", GetProductDataString(), "" }, false);
uint64_t capacity = GetBlockCount() * GetBlockSize();
string unit;

// 10,000 MiB and more
if (capacity >= 10'485'760'000) {
capacity /= 1'073'741'824;
unit = "G";
}
// 1 MiB and more
else if (capacity >= 1'048'576) {
capacity /= 1'048'576;
unit = "M";
}
else {
capacity /= 1024;
unit = "K";
}

SetProductData( { "", fmt::format("SCSI HD {0} {1}iB", capacity, unit), "" }, false);
}
}

Expand Down
5 changes: 1 addition & 4 deletions cpp/devices/scsi_hd.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SCSI2Pi, SCSI device emulator and SCSI tools for the Raspberry Pi
//
// Copyright (C) 2023-2024 Uwe Seimet
// Copyright (C) 2023-2025 Uwe Seimet
//
//---------------------------------------------------------------------------

Expand All @@ -12,7 +12,6 @@

class ScsiHd : public Disk
{
inline static const string DEFAULT_PRODUCT = "SCSI HD";

public:

Expand All @@ -33,8 +32,6 @@ class ScsiHd : public Disk

private:

string GetProductDataString() const;

void AddFormatPage(map<int, vector<byte>>&, bool) const;
void AddDrivePage(map<int, vector<byte>>&, bool) const;
void AddNotchPage(map<int, vector<byte>>&, bool) const;
Expand Down

0 comments on commit 740c6b8

Please sign in to comment.