Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set vendor / product id with image file name #290

Merged
merged 2 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/SCSI2SD/include/scsi2sd.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ typedef enum
S2S_CFG_QUIRKS_APPLE = 1,
S2S_CFG_QUIRKS_OMTI = 2,
S2S_CFG_QUIRKS_XEBEC = 4,
S2S_CFG_QUIRKS_VMS = 8
S2S_CFG_QUIRKS_VMS = 8,
S2S_CFG_QUIRKS_EMU = 9
PetteriAimonen marked this conversation as resolved.
Show resolved Hide resolved
} S2S_CFG_QUIRKS;

typedef enum
Expand Down
40 changes: 39 additions & 1 deletion src/ZuluSCSI_disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,37 @@ static void formatDriveInfoField(char *field, int fieldsize, bool align_right)
}
}

// remove path and extension from filename
void extractFileName(const char* path, char* output) {

const char *lastSlash, *lastDot;
int fileNameLength;

lastSlash = strrchr(path, '/');
if (!lastSlash) lastSlash = path;
else lastSlash++;

lastDot = strrchr(lastSlash, '.');
if (lastDot && (lastDot > lastSlash)) {
fileNameLength = lastDot - lastSlash;
strncpy(output, lastSlash, fileNameLength);
output[fileNameLength] = '\0';
} else {
strcpy(output, lastSlash);
}
}

void setNameFromImage(image_config_t &img, const char *filename) {

char image_name[MAX_FILE_PATH];

extractFileName(filename, image_name);
memset(img.vendor, 0, 8);
strncpy(img.vendor, image_name, 8);
memset(img.prodId, 0, 8);
strncpy(img.prodId, image_name+8, 8);
}

// Set default drive vendor / product info after the image file
// is loaded and the device type is known.
static void setDefaultDriveInfo(int target_idx)
Expand Down Expand Up @@ -398,6 +429,12 @@ bool scsiDiskOpenHDDImage(int target_idx, const char *filename, int scsi_id, int
PLATFORM_CONFIG_HOOK(&img);
#endif

if (img.name_from_image)
{
setNameFromImage(img, filename);
logmsg("Vendor / product id set from image file name");
}

setDefaultDriveInfo(target_idx);
PetteriAimonen marked this conversation as resolved.
Show resolved Hide resolved

if (img.prefetchbytes > 0)
Expand Down Expand Up @@ -528,8 +565,9 @@ static void scsiDiskLoadConfig(int target_idx, const char *section)
img.deviceTypeModifier = ini_getl(section, "TypeModifier", img.deviceTypeModifier, CONFIGFILE);
img.sectorsPerTrack = ini_getl(section, "SectorsPerTrack", img.sectorsPerTrack, CONFIGFILE);
img.headsPerCylinder = ini_getl(section, "HeadsPerCylinder", img.headsPerCylinder, CONFIGFILE);
img.quirks = ini_getl(section, "Quirks", img.quirks, CONFIGFILE);
img.quirks = ini_getl(section, "Quirks", img.quirks, CONFIGFILE);
img.rightAlignStrings = ini_getbool(section, "RightAlignStrings", 0, CONFIGFILE);
img.name_from_image = ini_getbool(section, "NameFromImage", 0, CONFIGFILE);
img.prefetchbytes = ini_getl(section, "PrefetchBytes", img.prefetchbytes, CONFIGFILE);
img.reinsert_on_inquiry = ini_getbool(section, "ReinsertCDOnInquiry", img.reinsert_on_inquiry, CONFIGFILE);
img.reinsert_after_eject = ini_getbool(section, "ReinsertAfterEject", img.reinsert_after_eject, CONFIGFILE);
Expand Down
3 changes: 3 additions & 0 deletions src/ZuluSCSI_disk.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ struct image_config_t: public S2S_TargetCfg
// This field uses -1 for default when field is not set in .ini
int rightAlignStrings;

// Set Vendor / Product Id from image file name
bool name_from_image;

// Maximum amount of bytes to prefetch
int prefetchbytes;

Expand Down