mirror of
https://github.com/akuker/RASCSI.git
synced 2024-12-23 06:30:04 +00:00
Improved block size check
This commit is contained in:
parent
5ed6673429
commit
502b19bfb2
@ -32,20 +32,16 @@ DeviceFactory::DeviceFactory()
|
||||
sector_sizes_scsi.insert(2048);
|
||||
sector_sizes_scsi.insert(4096);
|
||||
|
||||
// 128 MB, 512 bytes per block, 248826 blocks
|
||||
// 128 MB, 512 bytes per sector, 248826 sectors
|
||||
geometries_mo[0x797f400] = make_pair(512, 248826);
|
||||
// 230 MB, 512 bytes per sector, 446325 blocks
|
||||
// 230 MB, 512 bytes per block, 446325 sectors
|
||||
geometries_mo[0xd9eea00] = make_pair(512, 446325);
|
||||
// 540 MB, 512 bytes per sector, 1041500 blocks
|
||||
// 540 MB, 512 bytes per sector, 1041500 sectors
|
||||
geometries_mo[0x1fc8b800] = make_pair(512, 1041500);
|
||||
// 640 MB, 20248 bytes per sector, 310352 blocks
|
||||
// 640 MB, 20248 bytes per sector, 310352 sectors
|
||||
geometries_mo[0x25e28000] = make_pair(2048, 310352);
|
||||
}
|
||||
|
||||
DeviceFactory::~DeviceFactory()
|
||||
{
|
||||
}
|
||||
|
||||
DeviceFactory& DeviceFactory::instance()
|
||||
{
|
||||
static DeviceFactory instance;
|
||||
@ -143,7 +139,7 @@ Device *DeviceFactory::CreateDevice(PbDeviceType& type, const string& filename,
|
||||
}
|
||||
}
|
||||
catch(const illegal_argument_exception& e) {
|
||||
// There was an internal problem with setting the INQUIRY DATA
|
||||
// There was an internal problem with setting up the device data
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -18,16 +18,16 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef pair<uint32_t, uint32_t> Geometry;
|
||||
|
||||
class Device;
|
||||
|
||||
class DeviceFactory
|
||||
{
|
||||
public:
|
||||
|
||||
typedef pair<uint32_t, uint32_t> Geometry;
|
||||
|
||||
DeviceFactory();
|
||||
~DeviceFactory();
|
||||
~DeviceFactory() {};
|
||||
|
||||
static DeviceFactory& instance();
|
||||
|
||||
|
@ -1756,7 +1756,7 @@ void Disk::SetSectorSizeInBytes(uint32_t size, bool sasi)
|
||||
set<uint32_t> sector_sizes = sasi ? DeviceFactory::instance().GetSasiSectorSizes() : DeviceFactory::instance().GetScsiSectorSizes();
|
||||
if (sector_sizes.find(size) == sector_sizes.end()) {
|
||||
stringstream error;
|
||||
error << "Invalid sector size of " << size << " bytes";
|
||||
error << "Invalid block size of " << size << " bytes";
|
||||
throw io_exception(error.str());
|
||||
}
|
||||
|
||||
@ -1809,8 +1809,10 @@ uint32_t Disk::GetConfiguredSectorSize() const
|
||||
|
||||
bool Disk::SetConfiguredSectorSize(uint32_t configured_sector_size)
|
||||
{
|
||||
if (configured_sector_size != 512 && configured_sector_size != 1024 &&
|
||||
configured_sector_size != 2048 && configured_sector_size != 4096) {
|
||||
const DeviceFactory& device_factory = DeviceFactory::instance();
|
||||
|
||||
set<uint32_t> sector_sizes = IsSCSI() ? device_factory.GetScsiSectorSizes() : device_factory.GetSasiSectorSizes();
|
||||
if (sector_sizes.find(configured_sector_size) == sector_sizes.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1819,15 +1821,13 @@ bool Disk::SetConfiguredSectorSize(uint32_t configured_sector_size)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Disk::SetGeometries(const map<uint64_t, DeviceFactory::Geometry>& geometries)
|
||||
void Disk::SetGeometries(const map<uint64_t, Geometry>& geometries)
|
||||
{
|
||||
if (!IsMo()) {
|
||||
return false;
|
||||
throw illegal_argument_exception("Can't set geometry for");
|
||||
}
|
||||
|
||||
this->geometries = geometries;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Disk::SetGeometryForCapacity(uint64_t capacity) {
|
||||
|
@ -43,7 +43,7 @@ private:
|
||||
uint32_t configured_sector_size;
|
||||
|
||||
// The mapping of supported capacities to block sizes and block counts, empty if there is no capacity restriction
|
||||
map<uint64_t, DeviceFactory::Geometry> geometries;
|
||||
map<uint64_t, Geometry> geometries;
|
||||
|
||||
SASIDEV::ctrl_t *ctrl;
|
||||
|
||||
@ -137,7 +137,7 @@ public:
|
||||
void SetSectorSizes(const set<uint32_t>&);
|
||||
uint32_t GetConfiguredSectorSize() const;
|
||||
bool SetConfiguredSectorSize(uint32_t);
|
||||
bool SetGeometries(const map<uint64_t, DeviceFactory::Geometry>&);
|
||||
void SetGeometries(const map<uint64_t, Geometry>&);
|
||||
void SetGeometryForCapacity(uint64_t);
|
||||
uint32_t GetBlockCount() const;
|
||||
void SetBlockCount(uint32_t);
|
||||
|
@ -727,7 +727,7 @@ bool ProcessCmd(int fd, const PbDeviceDefinition& pbDevice, const PbOperation op
|
||||
Disk *disk = dynamic_cast<Disk *>(device);
|
||||
if (disk && disk->IsSectorSizeConfigurable()) {
|
||||
if (!disk->SetConfiguredSectorSize(pbDevice.block_size())) {
|
||||
error << "Invalid block size " << pbDevice.block_size();
|
||||
error << "Invalid block size " << pbDevice.block_size() << " bytes";
|
||||
return ReturnStatus(fd, false, error);
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ string ListDevices(const PbDevices& devices)
|
||||
}
|
||||
|
||||
list<PbDevice> sorted_devices = { devices.devices().begin(), devices.devices().end() };
|
||||
sorted_devices.sort([](const PbDevice& a, const PbDevice& b) { return a.id() < b.id() && a.unit() < b.unit(); });
|
||||
sorted_devices.sort([](const auto& a, const auto& b) { return a.id() < b.id() && a.unit() < b.unit(); });
|
||||
|
||||
for (const auto& device : sorted_devices) {
|
||||
string filename;
|
||||
|
Loading…
Reference in New Issue
Block a user