Skip to content

Commit

Permalink
Update count handling when hitting beginning-of-partition
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Dec 8, 2024
1 parent 87a5c14 commit b97aca4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
18 changes: 11 additions & 7 deletions cpp/devices/tape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ void Tape::WriteMetaData(Tape::object_type type, uint32_t size)
CheckForWriteError();
}

SimhMetaData Tape::FindNextObject(object_type type, int64_t requested_count, bool read)
SimhMetaData Tape::FindNextObject(object_type type, int32_t requested_count, bool read)
{
const bool reverse = requested_count < 0;

Expand All @@ -615,11 +615,11 @@ SimhMetaData Tape::FindNextObject(object_type type, int64_t requested_count, boo
requested_count = -requested_count;
}

int64_t actual_count = 0;
int32_t actual_count = 0;

while (true) {
SimhMetaData meta_data;
const auto [scsi_type, length] = ReadSimhMetaData(meta_data, actual_count, reverse);
const auto [scsi_type, length] = ReadSimhMetaData(meta_data, reverse);

// Bad data (not recovered) during READ(6)?
if (read && scsi_type == object_type::block && !length) {
Expand All @@ -641,13 +641,17 @@ SimhMetaData Tape::FindNextObject(object_type type, int64_t requested_count, boo
return meta_data;
}

if (scsi_type == object_type::beginning_of_partition) {
RaiseBeginningOfPartition(requested_count + 1);
}

if (scsi_type == object_type::end_of_partition) {
RaiseEndOfPartition(reverse ? -requested_count + actual_count - 1 : actual_count - 1);
RaiseEndOfPartition(actual_count);
}

// End-of-data while spacing over blocks or filemarks
if (scsi_type == object_type::end_of_data && type != object_type::end_of_data) {
RaiseEndOfData(type, reverse ? -requested_count + actual_count - 1 : actual_count - 1);
RaiseEndOfData(type, actual_count - 1);
}

// Terminate while spacing over blocks and a filemark is found
Expand Down Expand Up @@ -832,11 +836,11 @@ vector<PbStatistics> Tape::GetStatistics() const
return statistics;
}

pair<Tape::object_type, int> Tape::ReadSimhMetaData(SimhMetaData &meta_data, int64_t count, bool reverse)
pair<Tape::object_type, int> Tape::ReadSimhMetaData(SimhMetaData &meta_data, bool reverse)
{
while (true) {
if (!ReadNextMetaData(meta_data, reverse)) {
RaiseBeginningOfPartition(reverse ? -count : count);
return {object_type::beginning_of_partition, 0};
}

switch (meta_data.cls) {
Expand Down
7 changes: 4 additions & 3 deletions cpp/devices/tape.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class Tape : public StorageDevice, public ScsiStreamCommands
filemark = 0b001,
end_of_data = 0b011,
// SCSI2Pi-specific
end_of_partition = -1,
beginning_of_partition = -1,
end_of_partition = -2
};

// Commands covered by the SCSI specifications (see https://www.t10.org/drafts.htm)
Expand All @@ -85,7 +86,7 @@ class Tape : public StorageDevice, public ScsiStreamCommands
void Locate(bool);

void WriteMetaData(Tape::object_type, uint32_t = 0);
SimhMetaData FindNextObject(Tape::object_type, int64_t, bool);
SimhMetaData FindNextObject(Tape::object_type, int32_t, bool);
bool ReadNextMetaData(SimhMetaData&, bool);

[[noreturn]] void RaiseBeginningOfPartition(int64_t);
Expand All @@ -105,7 +106,7 @@ class Tape : public StorageDevice, public ScsiStreamCommands

void ResetPosition();

pair<Tape::object_type, int> ReadSimhMetaData(SimhMetaData&, int64_t, bool);
pair<Tape::object_type, int> ReadSimhMetaData(SimhMetaData&, bool);
int WriteSimhMetaData(simh_class, uint32_t);

void CheckBlockLength(int);
Expand Down
2 changes: 1 addition & 1 deletion cpp/test/tape_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ TEST(TapeTest, Space6_simh)
Dispatch(*tape, scsi_command::request_sense);
EXPECT_EQ(0b01000000, controller->GetBuffer()[2]) << "EOM must be set";
EXPECT_EQ(0x80, controller->GetBuffer()[0] & 0x80) << "VALID must be set";
EXPECT_EQ(0xffffffffU, GetInt32(controller->GetBuffer(), 3));
EXPECT_EQ(0xffU, GetInt32(controller->GetBuffer(), 3));


// Write 6 data records (bad and good) and different markers, 1 filemark
Expand Down

0 comments on commit b97aca4

Please sign in to comment.