Don't ResizeCache on sector change if no filename is defined (#1438)

* Add tests for issue#1426

Signed-off-by: Klaus Kämpf <kkaempf@gmail.com>

* add test without medium

Signed-off-by: Klaus Kämpf <kkaempf@gmail.com>

* Don't resize DiskCache without a file

DiskCache computes its size from a file.
Skip ResizeCache Without file (i.e. 'empty' CD)

Fixes #1426

Signed-off-by: Klaus Kämpf <kkaempf@gmail.com>
This commit is contained in:
Klaus Kämpf 2024-02-27 03:20:22 +01:00 committed by GitHub
parent 24372ba939
commit dd9a3296d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 2 deletions

View File

@ -179,7 +179,11 @@ void SCSICD::ModeSelect(scsi_command cmd, cdb_t cdb, span<const uint8_t> buf, in
ClearTrack(); ClearTrack();
CreateDataTrack(); CreateDataTrack();
FlushCache(); FlushCache();
ResizeCache(GetFilename(), GetRawMode()); string filename;
if ((filename = GetFilename()) != "") {
// DiskCache fails without a file to compute the cache size
ResizeCache(filename, GetRawMode());
}
} }
if (const string result = scsi_command_util::ModeSelect(cmd, cdb, buf, length, sector_size); if (const string result = scsi_command_util::ModeSelect(cmd, cdb, buf, length, sector_size);

View File

@ -137,9 +137,11 @@ TEST(ScsiCdTest, ReadToc)
TEST(ScsiCdTest, ModeSelect) TEST(ScsiCdTest, ModeSelect)
{ {
MockSCSICD cd(0); MockSCSICD cd(0);
MockSCSICD cd1(0);
vector<int> cmd(6); vector<int> cmd(6);
vector<uint8_t> buf(255); vector<uint8_t> buf(255);
// dummy file for DiskCache resize after sector size change
path filename = CreateTempFile(2* 2048); path filename = CreateTempFile(2* 2048);
cd.SetFilename(string(filename)); cd.SetFilename(string(filename));
cd.Open(); cd.Open();
@ -157,7 +159,30 @@ TEST(ScsiCdTest, ModeSelect)
buf[12] = 0x01; buf[12] = 0x01;
EXPECT_NO_THROW(cd.ModeSelect(scsi_command::eCmdModeSelect6, cmd, buf, 255)) << "MODE SELECT(6) with sector size 2048 is supported"; EXPECT_NO_THROW(cd.ModeSelect(scsi_command::eCmdModeSelect6, cmd, buf, 255)) << "MODE SELECT(6) with sector size 2048 is supported";
// 512 bytes per sector // 512 bytes per sector - ModeSelect6
buf[10] = 0x02; buf[10] = 0x02;
EXPECT_NO_THROW(cd.ModeSelect(scsi_command::eCmdModeSelect6, cmd, buf, 255)) << "MODE SELECT(6) with sector size 512 is supported"; EXPECT_NO_THROW(cd.ModeSelect(scsi_command::eCmdModeSelect6, cmd, buf, 255)) << "MODE SELECT(6) with sector size 512 is supported";
// 2048 bytes per sector - ModeSelect6
buf[10] = 0x08;
EXPECT_NO_THROW(cd.ModeSelect(scsi_command::eCmdModeSelect6, cmd, buf, 255)) << "MODE SELECT(6) with sector size 2048 is supported";
// 512 bytes per sector - ModeSelect10
buf[10] = 0x02;
EXPECT_NO_THROW(cd.ModeSelect(scsi_command::eCmdModeSelect10, cmd, buf, 255)) << "MODE SELECT(10) with sector size 512 is supported";
// unsupported sector size - ModeSelect6
buf[10] = 0x04;
EXPECT_THROW(cd.ModeSelect(scsi_command::eCmdModeSelect6, cmd, buf, 255), io_exception) << "MODE SELECT(6) with sector size 1024 is unsupported";
// sector size not multiple of 512 - ModeSelect6
buf[10] = 0x03;
EXPECT_THROW(cd.ModeSelect(scsi_command::eCmdModeSelect6, cmd, buf, 255), io_exception) << "MODE SELECT(6) with sector size 768 is unsupported";
// cd1 has no dummy file attached, simulating an empty CD drive
cd1.SetSectorSizeInBytes(2048);
// 512 bytes per sector - ModeSelect6
buf[10] = 0x02;
EXPECT_NO_THROW(cd1.ModeSelect(scsi_command::eCmdModeSelect6, cmd, buf, 255)) << "MODE SELECT(6), emtpy drive, with sector size 512 is supported";
} }