Added sector size validation

This commit is contained in:
Uwe Seimet 2021-08-25 12:45:56 +02:00
parent d0976f1ceb
commit 4a4cf12bca
6 changed files with 27 additions and 11 deletions

View File

@ -1747,11 +1747,15 @@ bool Disk::GetStartAndCount(SASIDEV *controller, uint64_t& start, uint32_t& coun
int Disk::GetSectorSizeInBytes() const
{
return 1 << disk.size;
return disk.size ? 1 << disk.size : 0;
}
void Disk::SetSectorSizeInBytes(int size)
bool Disk::SetSectorSizeInBytes(int size, bool sasi)
{
if (sasi && size != 256 && size != 1024) {
return false;
}
switch (size) {
case 256:
disk.size = 8;
@ -1778,6 +1782,8 @@ void Disk::SetSectorSizeInBytes(int size)
disk.size = 9;
break;
}
return true;
}
int Disk::GetSectorSize() const

View File

@ -124,7 +124,7 @@ public:
int SelectCheck10(const DWORD *cdb); // SELECT(10) check
int GetSectorSizeInBytes() const;
void SetSectorSizeInBytes(int);
bool SetSectorSizeInBytes(int, bool);
int GetSectorSize() const;
bool IsSectorSizeConfigurable() const;
vector<int> GetSectorSizes() const;

View File

@ -70,7 +70,12 @@ void SASIHD::Open(const Filepath& path)
fio.Close();
// Sector size (default 256 bytes) and number of blocks
SetSectorSizeInBytes(GetConfiguredSectorSize() ? GetConfiguredSectorSize() : 256);
if (!SetSectorSizeInBytes(GetConfiguredSectorSize() ? GetConfiguredSectorSize() : 256, true)) {
stringstream error;
error << "Invalid sector size " << GetConfiguredSectorSize();
throw io_exception(error.str());
}
SetBlockCount((DWORD)(size >> GetSectorSize()));
#if defined(REMOVE_FIXED_SASIHD_SIZE)
@ -110,8 +115,8 @@ void SASIHD::Open(const Filepath& path)
}
#endif // REMOVE_FIXED_SASIHD_SIZE
// Call the base class
Disk::Open(path);
FileSupport::SetPath(path);
}
//---------------------------------------------------------------------------

View File

@ -342,7 +342,7 @@ void SCSICD::Open(const Filepath& path)
ASSERT(GetBlockCount() > 0);
// Sector size 2048 bytes
SetSectorSizeInBytes(2048);
SetSectorSizeInBytes(2048, false);
Disk::Open(path);
FileSupport::SetPath(path);

View File

@ -71,7 +71,12 @@ void SCSIHD::Open(const Filepath& path)
fio.Close();
// Sector size (default 512 bytes) and number of blocks
SetSectorSizeInBytes(GetConfiguredSectorSize() ? GetConfiguredSectorSize() : 512);
if (!SetSectorSizeInBytes(GetConfiguredSectorSize() ? GetConfiguredSectorSize() : 512, false)) {
stringstream error;
error << "Invalid sector size " << GetConfiguredSectorSize();
throw io_exception(error.str());
}
SetBlockCount((DWORD)(size >> GetSectorSize()));
// File size must be a multiple of the sector size

View File

@ -57,28 +57,28 @@ void SCSIMO::Open(const Filepath& path)
// 128MB
case 0x797f400:
// 512 bytes per sector
SetSectorSizeInBytes(512);
SetSectorSizeInBytes(512, false);
SetBlockCount(248826);
break;
// 230MB
case 0xd9eea00:
// 512 bytes per sector
SetSectorSizeInBytes(512);
SetSectorSizeInBytes(512, false);
SetBlockCount(446325);
break;
// 540MB
case 0x1fc8b800:
// 512 bytes per sector
SetSectorSizeInBytes(512);
SetSectorSizeInBytes(512, false);
SetBlockCount(1041500);
break;
// 640MB
case 0x25e28000:
// 2048 bytes per sector
SetSectorSizeInBytes(2048);
SetSectorSizeInBytes(2048, false);
SetBlockCount(310352);
break;