@@ -235,13 +235,12 @@ void scsiInitiatorMainLoop()
235
235
g_initiator_state.sectorcount = g_initiator_state.sectorcount_all = 0 ;
236
236
}
237
237
238
- const char *filename_format = " HD00_imaged.hda " ;
238
+ char filename[ 18 ] = " " ;
239
239
if (inquiryok)
240
240
{
241
241
g_initiator_state.deviceType = inquiry_data[0 ] & 0x1F ;
242
242
if (g_initiator_state.deviceType == DEVICE_TYPE_CD)
243
243
{
244
- filename_format = " CD00_imaged.iso" ;
245
244
g_initiator_state.ejectWhenDone = true ;
246
245
}
247
246
else if (g_initiator_state.deviceType != DEVICE_TYPE_DIRECT_ACCESS)
@@ -252,11 +251,7 @@ void scsiInitiatorMainLoop()
252
251
253
252
if (g_initiator_state.sectorcount > 0 )
254
253
{
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 ;
260
255
261
256
uint64_t sd_card_free_bytes = (uint64_t )SD.vol ()->freeClusterCount () * SD.vol ()->bytesPerCluster ();
262
257
if (sd_card_free_bytes < total_bytes)
@@ -266,14 +261,14 @@ void scsiInitiatorMainLoop()
266
261
return ;
267
262
}
268
263
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, " . " );
277
272
g_initiator_state.target_file = SD.open (filename, O_WRONLY | O_CREAT | O_TRUNC);
278
273
if (!g_initiator_state.target_file .isOpen ())
279
274
{
0 commit comments