Maintain list of supported block sizes

This commit is contained in:
Uwe Seimet 2021-08-25 08:21:19 +02:00
parent 2d364f16d8
commit bf5289d30e
6 changed files with 38 additions and 16 deletions

View File

@ -15,6 +15,7 @@
#include "scsi_host_bridge.h" #include "scsi_host_bridge.h"
#include "scsi_daynaport.h" #include "scsi_daynaport.h"
#include "device_factory.h" #include "device_factory.h"
#include <vector>
using namespace std; using namespace std;
using namespace rascsi_interface; using namespace rascsi_interface;
@ -44,8 +45,13 @@ Device *DeviceFactory::CreateDevice(PbDeviceType& type, const string& filename,
} }
} }
Device *device = NULL; vector<int> sector_sizes;
sector_sizes.push_back(512);
sector_sizes.push_back(1024);
sector_sizes.push_back(2048);
sector_sizes.push_back(4096);
Device *device = NULL;
switch (type) { switch (type) {
case SAHD: case SAHD:
device = new SASIHD(); device = new SASIHD();
@ -58,7 +64,7 @@ Device *DeviceFactory::CreateDevice(PbDeviceType& type, const string& filename,
} else { } else {
device = new SCSIHD(); device = new SCSIHD();
device->SetProtectable(true); device->SetProtectable(true);
((Disk *)device)->SetSectorSizeConfigurable(true); ((Disk *)device)->SetSectorSizes(sector_sizes);
} }
break; break;
@ -67,7 +73,8 @@ Device *DeviceFactory::CreateDevice(PbDeviceType& type, const string& filename,
device = new SCSIHD(true); device = new SCSIHD(true);
device->SetProtectable(true); device->SetProtectable(true);
device->SetLockable(true); device->SetLockable(true);
((Disk *)device)->SetSectorSizeConfigurable(true); device->SetProtectable(true);
((Disk *)device)->SetSectorSizes(sector_sizes);
break; break;
case SCMO: case SCMO:

View File

@ -424,7 +424,6 @@ void Disk::ReadDefectData10(SASIDEV *controller)
Disk::Disk(const std::string id) : Device(id), PrimaryDevice(), BlockDevice() Disk::Disk(const std::string id) : Device(id), PrimaryDevice(), BlockDevice()
{ {
// Work initialization // Work initialization
sector_size_configurable = false;
configured_sector_size = 0; configured_sector_size = 0;
disk.size = 0; disk.size = 0;
disk.blocks = 0; disk.blocks = 0;
@ -1765,12 +1764,12 @@ void Disk::SetSectorSize(int size)
bool Disk::IsSectorSizeConfigurable() const bool Disk::IsSectorSizeConfigurable() const
{ {
return sector_size_configurable; return !sector_sizes.empty();
} }
void Disk::SetSectorSizeConfigurable(bool sector_size_configurable) void Disk::SetSectorSizes(const vector<int>& sector_sizes)
{ {
this->sector_size_configurable = sector_size_configurable; this->sector_sizes = sector_sizes;
} }
int Disk::GetConfiguredSectorSize() const int Disk::GetConfiguredSectorSize() const

View File

@ -28,6 +28,7 @@
#include "file_support.h" #include "file_support.h"
#include "filepath.h" #include "filepath.h"
#include <string> #include <string>
#include <vector>
#include <map> #include <map>
class Disk : public Device, public PrimaryDevice, public BlockDevice class Disk : public Device, public PrimaryDevice, public BlockDevice
@ -35,7 +36,7 @@ class Disk : public Device, public PrimaryDevice, public BlockDevice
private: private:
enum access_mode { RW6, RW10, RW16 }; enum access_mode { RW6, RW10, RW16 };
bool sector_size_configurable; vector<int> sector_sizes;
int configured_sector_size; int configured_sector_size;
SASIDEV::ctrl_t *ctrl; SASIDEV::ctrl_t *ctrl;
@ -125,7 +126,8 @@ public:
int GetSectorSize() const; int GetSectorSize() const;
void SetSectorSize(int); void SetSectorSize(int);
bool IsSectorSizeConfigurable() const; bool IsSectorSizeConfigurable() const;
void SetSectorSizeConfigurable(bool); vector<int> GetSectorSizes() const;
void SetSectorSizes(const vector<int>&);
int GetConfiguredSectorSize() const; int GetConfiguredSectorSize() const;
void SetConfiguredSectorSize(int); void SetConfiguredSectorSize(int);
uint32_t GetBlockCount() const; uint32_t GetBlockCount() const;

View File

@ -552,20 +552,26 @@ void GetDeviceTypeFeatures(PbServerInfo& serverInfo)
features->set_supports_file(true); features->set_supports_file(true);
types_features = serverInfo.add_types_features(); types_features = serverInfo.add_types_features();
types_features->add_block_sizes(512);
types_features->add_block_sizes(1024);
types_features->add_block_sizes(2048);
types_features->add_block_sizes(4096);
features = types_features->add_features(); features = types_features->add_features();
types_features->set_type(SCHD); types_features->set_type(SCHD);
features->set_protectable(true); features->set_protectable(true);
features->set_supports_file(true); features->set_supports_file(true);
features->set_supports_block_size(true);
types_features = serverInfo.add_types_features(); types_features = serverInfo.add_types_features();
types_features->add_block_sizes(512);
types_features->add_block_sizes(1024);
types_features->add_block_sizes(2048);
types_features->add_block_sizes(4096);
features = types_features->add_features(); features = types_features->add_features();
types_features->set_type(SCRM); types_features->set_type(SCRM);
features->set_protectable(true); features->set_protectable(true);
features->set_removable(true); features->set_removable(true);
features->set_lockable(true); features->set_lockable(true);
features->set_supports_file(true); features->set_supports_file(true);
features->set_supports_block_size(true);
types_features = serverInfo.add_types_features(); types_features = serverInfo.add_types_features();
features = types_features->add_features(); features = types_features->add_features();

View File

@ -61,8 +61,6 @@ message PbDeviceFeatures {
bool lockable = 4; bool lockable = 4;
// Device supports image file // Device supports image file
bool supports_file = 5; bool supports_file = 5;
// Device supports configurable block size
bool supports_block_size = 6;
} }
// The status of a device // The status of a device
@ -79,6 +77,8 @@ message PbDeviceStatus {
message PbDeviceTypeFeatures { message PbDeviceTypeFeatures {
PbDeviceType type = 1; PbDeviceType type = 1;
repeated PbDeviceFeatures features = 2; repeated PbDeviceFeatures features = 2;
// List of supported block sizes
repeated uint32 block_sizes = 6;
} }
// The image file data // The image file data

View File

@ -236,15 +236,23 @@ void CommandServerInfo(const string& hostname, int port)
if (features.supports_file()) { if (features.supports_file()) {
cout << " Image file support"; cout << " Image file support";
} }
if (features.supports_block_size()) {
cout << " Block size configurable";
}
cout << endl; cout << endl;
} }
} }
else { else {
cout << endl; cout << endl;
} }
if (type_features.block_sizes_size()) {
cout << " Supported block sizes: ";
for (int j = 0; j < type_features.block_sizes_size(); j++) {
if (j) {
cout << ", ";
}
cout << type_features.block_sizes(j);
}
cout << endl;
}
} }
cout << "Available devices:" << endl; cout << "Available devices:" << endl;