Skip to content

Commit

Permalink
Merge pull request #301 from ZuluSCSI/default-dirs
Browse files Browse the repository at this point in the history
Adopt support for Implicit Image directories from downstream fork
  • Loading branch information
aperezbios authored Sep 19, 2023
2 parents f751d89 + 16be0e0 commit d88c95f
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/ZuluSCSI.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ZuluSCSI
* Copyright (c) 2022 Rabbit Hole Computing
* ZuluSCSI
* Copyright (c) 2022-2023 Rabbit Hole Computing
*
* This project is based on BlueSCSI:
*
Expand Down Expand Up @@ -295,7 +295,7 @@ bool findHDDImages()
ini_gets("SCSI", "Dir", "/", imgdir, sizeof(imgdir), CONFIGFILE);
int dirindex = 0;

logmsg("Finding HDD images in directory ", imgdir, ":");
logmsg("Finding images in directory ", imgdir, ":");

SdFile root;
root.open(imgdir);
Expand Down Expand Up @@ -326,7 +326,7 @@ bool findHDDImages()

if (imgdir[0] != '\0')
{
logmsg("Finding HDD images in additional directory Dir", (int)dirindex, " = \"", imgdir, "\":");
logmsg("Finding images in additional directory Dir", (int)dirindex, " = \"", imgdir, "\":");
root.open(imgdir);
if (!root.isOpen())
{
Expand Down
108 changes: 98 additions & 10 deletions src/ZuluSCSI_disk.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/**
* SCSI2SD V6 - Copyright (C) 2013 Michael McMaster <[email protected]>
* Copyright (C) 2014 Doug Brown <[email protected]
* ZuluSCSI™ - Copyright (c) 2022 Rabbit Hole Computing™
* Portions Copyright (C) 2014 Doug Brown <[email protected]>
* Portions Copyright (C) 2023 Eric Helgeson
* ZuluSCSI™ - Copyright (c) 2022-2023 Rabbit Hole Computing™
*
* This file is licensed under the GPL version 3 or any later version. 
* It is derived from disk.c in SCSI2SD V6
Expand Down Expand Up @@ -435,7 +436,7 @@ bool scsiDiskOpenHDDImage(int target_idx, const char *filename, int scsi_id, int
if (img.name_from_image)
{
setNameFromImage(img, filename);
logmsg("Vendor / product id set from image file name");
logmsg("---- Vendor / product id set from image file name");
}

setDefaultDriveInfo(target_idx);
Expand Down Expand Up @@ -532,6 +533,12 @@ bool scsiDiskFilenameValid(const char* name)
}
}
}
// Check first character
if (!isalnum(name[0]))
{
// ignore files that don't start with a letter or a number
return false;
}
return true;
}

Expand Down Expand Up @@ -559,6 +566,23 @@ static void scsiDiskConfigDefaults(int target_idx)
memset(img.serial, 0, sizeof(img.serial));
}

static void scsiDiskCheckDir(char * dir_name, int target_idx, image_config_t* img, S2S_CFG_TYPE type, const char* type_name)
{
if (SD.exists(dir_name))
{
if (img->image_directory)
{
logmsg("-- Already found an image directory, skipping '", dir_name, "'");
}
else
{
img->deviceType = type;
img->image_directory = true;
logmsg("SCSI", target_idx, " searching default ", type_name, " image directory '", dir_name, "'");
}
}
}

// Load values for target configuration from given section if they exist.
// Otherwise keep current settings.
static void scsiDiskLoadConfig(int target_idx, const char *section)
Expand Down Expand Up @@ -603,9 +627,35 @@ static void scsiDiskLoadConfig(int target_idx, const char *section)
ini_gets(section, "ImgDir", "", tmp, sizeof(tmp), CONFIGFILE);
if (tmp[0])
{
logmsg("-- SCSI", target_idx, " using image directory \'", tmp, "'");
logmsg("SCSI", target_idx, " using image directory '", tmp, "'");
img.image_directory = true;
}
else
{
strcpy(tmp, "HD0");
tmp[2] += target_idx;
scsiDiskCheckDir(tmp, target_idx, &img, S2S_CFG_FIXED, "disk");

strcpy(tmp, "CD0");
tmp[2] += target_idx;
scsiDiskCheckDir(tmp, target_idx, &img, S2S_CFG_OPTICAL, "optical");

strcpy(tmp, "RM0");
tmp[2] += target_idx;
scsiDiskCheckDir(tmp, target_idx, &img, S2S_CFG_REMOVEABLE, "removable");

strcpy(tmp, "MO0");
tmp[2] += target_idx;
scsiDiskCheckDir(tmp, target_idx, &img, S2S_CFG_MO, "magneto-optical");

strcpy(tmp, "TP0");
tmp[2] += target_idx;
scsiDiskCheckDir(tmp, target_idx, &img, S2S_CFG_SEQUENTIAL, "tape");

strcpy(tmp, "FP0");
tmp[2] += target_idx;
scsiDiskCheckDir(tmp, target_idx, &img, S2S_CFG_FLOPPY_14MB, "floppy");
}
}
}

Expand All @@ -625,13 +675,20 @@ static int findNextImageAfter(image_config_t &img,
if (!dir.open(dirname))
{
logmsg("Image directory '", dirname, "' couldn't be opened");
return 0;
}
if (!dir.isDir())
{
logmsg("Can't find images in '", dirname, "', not a directory");
dir.close();
return 0;
}
if (dir.isHidden())
{
logmsg("Image directory '", dirname, "' is hidden, skipping");
dir.close();
return 0;
}

char first_name[MAX_FILE_PATH] = {'\0'};
char candidate_name[MAX_FILE_PATH] = {'\0'};
Expand All @@ -641,10 +698,14 @@ static int findNextImageAfter(image_config_t &img,
if (file.isDir()) continue;
if (!file.getName(buf, MAX_FILE_PATH))
{
logmsg("Image directory '", dirname, "'had invalid file");
logmsg("Image directory '", dirname, "' had invalid file");
continue;
}
if (!scsiDiskFilenameValid(buf)) continue;
if (file.isHidden()) {
logmsg("Image '", dirname, "/", buf, "' is hidden, skipping file");
continue;
}

// keep track of the first item to allow wrapping
// without having to iterate again
Expand Down Expand Up @@ -681,6 +742,7 @@ static int findNextImageAfter(image_config_t &img,
else
{
logmsg("Image directory '", dirname, "' was empty");
img.image_directory = false;
return 0;
}
}
Expand All @@ -703,10 +765,36 @@ int scsiDiskGetNextImageName(image_config_t &img, char *buf, size_t buflen)
int dirlen = ini_gets(section, key, "", dirname, sizeof(dirname), CONFIGFILE);
if (!dirlen)
{
// If image_directory set but ImageDir is not, could be used to
// indicate an image directory configured via folder structure.
// Not implemented, so treat this as equivalent to missing ImageDir
return 0;
switch (img.deviceType)
{
case S2S_CFG_FIXED:
strcpy(dirname ,"HD0");
break;
case S2S_CFG_OPTICAL:
strcpy(dirname, "CD0");
break;
case S2S_CFG_REMOVEABLE:
strcpy(dirname, "RM0");
break;
case S2S_CFG_MO:
strcpy(dirname, "MO0");
break;
case S2S_CFG_SEQUENTIAL:
strcpy(dirname ,"TP0");
break;
case S2S_CFG_FLOPPY_14MB:
strcpy(dirname, "FP0");
break;
default:
dbgmsg("No matching device type for default directory found");
return 0;
}
dirname[2] += target_idx;
if (!SD.exists(dirname))
{
dbgmsg("Default image directory, ", dirname, " does not exist");
return 0;
}
}

// find the next filename
Expand Down Expand Up @@ -785,7 +873,7 @@ void scsiDiskLoadConfig(int target_idx)
if (scsiDiskGetNextImageName(img, filename, sizeof(filename)))
{
int blocksize = (img.deviceType == S2S_CFG_OPTICAL) ? 2048 : 512;
logmsg("-- Opening '", filename, "' for id:", target_idx, ", specified in " CONFIGFILE);
logmsg("-- Opening '", filename, "' for id: ", target_idx);
scsiDiskOpenHDDImage(target_idx, filename, target_idx, 0, blocksize);
}
}
Expand Down

0 comments on commit d88c95f

Please sign in to comment.