mirror of
https://github.com/akuker/RASCSI.git
synced 2025-01-27 07:30:16 +00:00
Sort block sizes
This commit is contained in:
parent
3db5d1dc4d
commit
4bdf6bad60
@ -15,20 +15,20 @@
|
||||
#include "scsi_host_bridge.h"
|
||||
#include "scsi_daynaport.h"
|
||||
#include "device_factory.h"
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
||||
using namespace std;
|
||||
using namespace rascsi_interface;
|
||||
|
||||
DeviceFactory::DeviceFactory()
|
||||
{
|
||||
sector_sizes_sasi.push_back(256);
|
||||
sector_sizes_sasi.push_back(1024);
|
||||
sector_sizes_sasi.insert(256);
|
||||
sector_sizes_sasi.insert(1024);
|
||||
|
||||
sector_sizes_scsi.push_back(512);
|
||||
sector_sizes_scsi.push_back(1024);
|
||||
sector_sizes_scsi.push_back(2048);
|
||||
sector_sizes_scsi.push_back(4096);
|
||||
sector_sizes_scsi.insert(512);
|
||||
sector_sizes_scsi.insert(1024);
|
||||
sector_sizes_scsi.insert(2048);
|
||||
sector_sizes_scsi.insert(4096);
|
||||
}
|
||||
|
||||
DeviceFactory::~DeviceFactory()
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include "rascsi_interface.pb.h"
|
||||
|
||||
@ -26,13 +26,13 @@ public:
|
||||
|
||||
static DeviceFactory& instance();
|
||||
|
||||
const std::vector<int>& GetSasiSectorSizes() const { return sector_sizes_sasi; };
|
||||
const std::vector<int>& GetScsiSectorSizes() const { return sector_sizes_scsi; };
|
||||
const std::set<int>& GetSasiSectorSizes() const { return sector_sizes_sasi; };
|
||||
const std::set<int>& GetScsiSectorSizes() const { return sector_sizes_scsi; };
|
||||
|
||||
Device *CreateDevice(rascsi_interface::PbDeviceType& type, const std::string& filename, const std::string& ext);
|
||||
|
||||
private:
|
||||
|
||||
std::vector<int> sector_sizes_sasi;
|
||||
std::vector<int> sector_sizes_scsi;
|
||||
std::set<int> sector_sizes_sasi;
|
||||
std::set<int> sector_sizes_scsi;
|
||||
};
|
||||
|
@ -1753,7 +1753,7 @@ int Disk::GetSectorSizeInBytes() const
|
||||
|
||||
void Disk::SetSectorSizeInBytes(int size, bool sasi)
|
||||
{
|
||||
vector<int> sector_sizes = sasi ? DeviceFactory::instance().GetSasiSectorSizes() : DeviceFactory::instance().GetScsiSectorSizes();
|
||||
set<int> sector_sizes = sasi ? DeviceFactory::instance().GetSasiSectorSizes() : DeviceFactory::instance().GetScsiSectorSizes();
|
||||
if (find(sector_sizes.begin(), sector_sizes.end(), size) == sector_sizes.end()) {
|
||||
stringstream error;
|
||||
error << "Invalid sector size of " << size << " bytes";
|
||||
@ -1798,7 +1798,7 @@ bool Disk::IsSectorSizeConfigurable() const
|
||||
return !sector_sizes.empty();
|
||||
}
|
||||
|
||||
void Disk::SetSectorSizes(const vector<int>& sector_sizes)
|
||||
void Disk::SetSectorSizes(const set<int>& sector_sizes)
|
||||
{
|
||||
this->sector_sizes = sector_sizes;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include "file_support.h"
|
||||
#include "filepath.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <map>
|
||||
|
||||
#include "../rascsi.h"
|
||||
@ -37,7 +37,7 @@ class Disk : public Device, public ScsiPrimaryCommands, public ScsiBlockCommands
|
||||
private:
|
||||
enum access_mode { RW6, RW10, RW16 };
|
||||
|
||||
vector<int> sector_sizes;
|
||||
set<int> sector_sizes;
|
||||
int configured_sector_size;
|
||||
|
||||
SASIDEV::ctrl_t *ctrl;
|
||||
@ -128,8 +128,8 @@ public:
|
||||
void SetSectorSizeInBytes(int, bool);
|
||||
int GetSectorSize() const;
|
||||
bool IsSectorSizeConfigurable() const;
|
||||
vector<int> GetSectorSizes() const;
|
||||
void SetSectorSizes(const vector<int>&);
|
||||
set<int> GetSectorSizes() const;
|
||||
void SetSectorSizes(const set<int>&);
|
||||
int GetConfiguredSectorSize() const;
|
||||
bool SetConfiguredSectorSize(int);
|
||||
uint32_t GetBlockCount() const;
|
||||
|
@ -531,7 +531,7 @@ void GetDeviceTypeFeatures(PbServerInfo& serverInfo)
|
||||
PbDeviceProperties *properties = types_properties->add_properties();
|
||||
types_properties->set_type(SAHD);
|
||||
properties->set_supports_file(true);
|
||||
vector<int> block_sizes = device_factory.GetSasiSectorSizes();
|
||||
set<int> block_sizes = device_factory.GetSasiSectorSizes();
|
||||
for (const auto& block_size : block_sizes) {
|
||||
properties->add_block_sizes(block_size);
|
||||
}
|
||||
|
@ -198,14 +198,14 @@ void CommandServerInfo(const string& hostname, int port)
|
||||
cout << " No image files available in the default folder" << endl;
|
||||
}
|
||||
else {
|
||||
list<PbImageFile> sorted_files;
|
||||
list<PbImageFile> files;
|
||||
for (int i = 0; i < serverInfo.image_files_size(); i++) {
|
||||
sorted_files.push_back(serverInfo.image_files(i));
|
||||
files.push_back(serverInfo.image_files(i));
|
||||
}
|
||||
sorted_files.sort([](const PbImageFile& a, const PbImageFile& b) { return a.name() < b.name(); });
|
||||
files.sort([](const PbImageFile& a, const PbImageFile& b) { return a.name() < b.name(); });
|
||||
|
||||
cout << "Image files available in the default folder:" << endl;
|
||||
for (const auto& file : sorted_files) {
|
||||
for (const auto& file : files) {
|
||||
cout << " " << file.name() << " (" << file.size() << " bytes)" << (file.read_only() ? ", read-only": "")
|
||||
<< endl;
|
||||
}
|
||||
@ -216,7 +216,7 @@ void CommandServerInfo(const string& hostname, int port)
|
||||
PbDeviceTypeProperties types_properties = serverInfo.types_properties(i);
|
||||
cout << " " << PbDeviceType_Name(types_properties.type());
|
||||
|
||||
vector<int> block_sizes;
|
||||
list<int> block_sizes;
|
||||
|
||||
cout << " Properties: ";
|
||||
if (types_properties.properties_size()) {
|
||||
@ -259,12 +259,18 @@ void CommandServerInfo(const string& hostname, int port)
|
||||
cout << " Block size is not configurable" << endl;
|
||||
}
|
||||
else {
|
||||
block_sizes.sort([](const int& a, const int& b) { return a < b; });
|
||||
|
||||
cout << " Configurable block sizes: ";
|
||||
for (size_t j = 0; j < block_sizes.size(); j++) {
|
||||
if (j) {
|
||||
|
||||
bool isFirst = true;
|
||||
for (const auto& block_size : block_sizes) {
|
||||
if (!isFirst) {
|
||||
cout << ", ";
|
||||
}
|
||||
cout << block_sizes.at(j);
|
||||
cout << block_size;
|
||||
|
||||
isFirst = false;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user