Skip to content

Commit

Permalink
initiator: Eject CD devices and continue to look for media on them. A…
Browse files Browse the repository at this point in the history
…llows imaging of multiple CDs in one session.
  • Loading branch information
erichelgeson committed Feb 11, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent e1a1734 commit 5860b48
Showing 2 changed files with 23 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/BlueSCSI_initiator.cpp
Original file line number Diff line number Diff line change
@@ -65,6 +65,7 @@ static struct {
uint32_t badSectorCount;
uint8_t ansiVersion;
uint8_t maxRetryCount;
uint8_t deviceType;

// Retry information for sector reads.
// If a large read fails, retry is done sector-by-sector.
@@ -104,6 +105,7 @@ void scsiInitiatorInit()
g_initiator_state.max_sector_per_transfer = 512;
g_initiator_state.ansiVersion = 0;
g_initiator_state.badSectorCount = 0;
g_initiator_state.deviceType = DEVICE_TYPE_DIRECT_ACCESS;
}

// Update progress bar LED during transfers
@@ -227,10 +229,15 @@ void scsiInitiatorMainLoop()
const char *filename_format = "HD00_imaged.hda";
if (inquiryok)
{
if ((inquiry_data[0] & 0x1F) == 5)
g_initiator_state.deviceType = inquiry_data[0] & 0x1F;
if (g_initiator_state.deviceType == DEVICE_TYPE_CD)
{
filename_format = "CD00_imaged.iso";
}
else if(g_initiator_state.deviceType != DEVICE_TYPE_DIRECT_ACCESS)
{
log("Unhandled device type: ", g_initiator_state.deviceType, ". Handling it as Direct Access Device.");
}
}

if (g_initiator_state.sectorcount > 0)
@@ -297,7 +304,11 @@ void scsiInitiatorMainLoop()
log_f("NOTE: There were %d bad sectors that could not be read off this drive.", g_initiator_state.badSectorCount);
}

g_initiator_state.drives_imaged |= (1 << g_initiator_state.target_id);
if(g_initiator_state.deviceType != DEVICE_TYPE_CD)
{
log("Marking this ID as imaged, wont ask it again.");
g_initiator_state.drives_imaged |= (1 << g_initiator_state.target_id);
}
g_initiator_state.imaging = false;
g_initiator_state.target_file.close();
return;
@@ -515,6 +526,13 @@ bool scsiStartStopUnit(int target_id, bool start)
command[4] |= 1; // Start
command[1] = 0; // Immediate
}
else // stop
{
if(g_initiator_state.deviceType == DEVICE_TYPE_CD)
{
command[4] = 0b00000010; // eject(6), stop(7).
}
}

int status = scsiInitiatorRunCommand(target_id,
command, sizeof(command),
3 changes: 3 additions & 0 deletions src/BlueSCSI_initiator.h
Original file line number Diff line number Diff line change
@@ -5,6 +5,9 @@
#include <stdint.h>
#include <stdlib.h>

#define DEVICE_TYPE_CD 5
#define DEVICE_TYPE_DIRECT_ACCESS 0

void scsiInitiatorInit();

void scsiInitiatorMainLoop();

0 comments on commit 5860b48

Please sign in to comment.