Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
}
Loading