Skip to content

Commit

Permalink
Don't ResizeCache on sector change if no filename is defined (#1438)
Browse files Browse the repository at this point in the history
* Add tests for issue#1426

Signed-off-by: Klaus Kämpf <[email protected]>

* add test without medium

Signed-off-by: Klaus Kämpf <[email protected]>

* 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 <[email protected]>
  • Loading branch information
kkaempf authored and rdmark committed May 1, 2024
1 parent a248730 commit f0640af
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
6 changes: 5 additions & 1 deletion cpp/devices/scsicd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ void SCSICD::ModeSelect(scsi_command cmd, cdb_t cdb, span<const uint8_t> buf, in
ClearTrack();
CreateDataTrack();
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);
Expand Down
27 changes: 26 additions & 1 deletion cpp/test/scsicd_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,11 @@ TEST(ScsiCdTest, ReadToc)
TEST(ScsiCdTest, ModeSelect)
{
MockSCSICD cd(0);
MockSCSICD cd1(0);
vector<int> cmd(6);
vector<uint8_t> buf(255);

// dummy file for DiskCache resize after sector size change
path filename = CreateTempFile(2* 2048);
cd.SetFilename(string(filename));
cd.Open();
Expand All @@ -157,7 +159,30 @@ TEST(ScsiCdTest, ModeSelect)
buf[12] = 0x01;
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;
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";
}

0 comments on commit f0640af

Please sign in to comment.