Skip to content

Commit 7f1a100

Browse files
committed
initiator: fixes #175 - Allow more than 10 image files with the same id when copying
1 parent 5727fcc commit 7f1a100

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

src/BlueSCSI_initiator.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,12 @@ void scsiInitiatorMainLoop()
235235
g_initiator_state.sectorcount = g_initiator_state.sectorcount_all = 0;
236236
}
237237

238-
const char *filename_format = "HD00_imaged.hda";
238+
char filename[18] = "";
239239
if (inquiryok)
240240
{
241241
g_initiator_state.deviceType = inquiry_data[0] & 0x1F;
242242
if (g_initiator_state.deviceType == DEVICE_TYPE_CD)
243243
{
244-
filename_format = "CD00_imaged.iso";
245244
g_initiator_state.ejectWhenDone = true;
246245
}
247246
else if(g_initiator_state.deviceType != DEVICE_TYPE_DIRECT_ACCESS)
@@ -252,11 +251,7 @@ void scsiInitiatorMainLoop()
252251

253252
if (g_initiator_state.sectorcount > 0)
254253
{
255-
char filename[32] = {0};
256-
int lun = 0;
257-
258-
strncpy(filename, filename_format, sizeof(filename) - 1);
259-
filename[2] += g_initiator_state.target_id;
254+
int image_num = 0;
260255

261256
uint64_t sd_card_free_bytes = (uint64_t)SD.vol()->freeClusterCount() * SD.vol()->bytesPerCluster();
262257
if(sd_card_free_bytes < total_bytes)
@@ -266,14 +261,14 @@ void scsiInitiatorMainLoop()
266261
return;
267262
}
268263

269-
while(SD.exists(filename))
270-
{
271-
filename[3] = lun++ + '0';
272-
}
273-
if(lun != 0)
274-
{
275-
log("Using filename: ", filename, " to avoid overwriting existing file.");
276-
}
264+
do {
265+
sprintf(filename, "%s%d_imaged-%03d.%s",
266+
(g_initiator_state.deviceType == DEVICE_TYPE_CD) ? "CD" : "HD",
267+
g_initiator_state.target_id,
268+
++image_num,
269+
(g_initiator_state.deviceType == DEVICE_TYPE_CD) ? "iso" : "hda");
270+
} while(SD.exists(filename));
271+
log("Imaging filename: ", filename, ".");
277272
g_initiator_state.target_file = SD.open(filename, O_WRONLY | O_CREAT | O_TRUNC);
278273
if (!g_initiator_state.target_file.isOpen())
279274
{

0 commit comments

Comments
 (0)