|
|
@@ -1,7 +1,7 @@
|
|
|
/**
|
|
|
* This file is part of BlueSCSI
|
|
|
*
|
|
|
- * Copyright (C) 2023 Eric Helgeson
|
|
|
+ * Copyright (C) 2023-2025 Eric Helgeson
|
|
|
* Portions ZuluSCSI™ - Copyright (c) 2023-2025 Rabbit Hole Computing™
|
|
|
*
|
|
|
* This file is licensed under the GPL version 3 or any later version.
|
|
|
@@ -29,58 +29,56 @@
|
|
|
#include "BlueSCSI_settings.h"
|
|
|
#include "QuirksCheck.h"
|
|
|
#include <assert.h>
|
|
|
-#include <stdint.h>
|
|
|
|
|
|
|
|
|
static bool isValidMacintoshImage(image_config_t *img)
|
|
|
{
|
|
|
- bool result = true;
|
|
|
- const char apple_magic[2] = {0x45, 0x52};
|
|
|
- const char block_size[2] = {0x02, 0x00}; // 512 BE == 2
|
|
|
- const char lido_sig[4] = {'C', 'M', 'S', '_' };
|
|
|
- uint8_t tmp[SD_SECTOR_SIZE];
|
|
|
- // Check for Apple Magic
|
|
|
- img->file.seek(0);
|
|
|
- img->file.read(tmp, SD_SECTOR_SIZE);
|
|
|
- if (memcmp(apple_magic, tmp, 2) != 0)
|
|
|
- {
|
|
|
- dbgmsg("---- Apple magic not found.");
|
|
|
- result = false;
|
|
|
+ // Mac block sizes should be the same size SD sector sizes for raw seeks, and reads to work
|
|
|
+ assert(MACINTOSH_BLOCK_SIZE == SD_SECTOR_SIZE);
|
|
|
+
|
|
|
+ constexpr char LIDO_SIGNATURE[] = {'C', 'M', 'S', '_' };
|
|
|
+ // Apple Volume Magic
|
|
|
+ // constexpr uint8_t APPLE_VOLUME_MAGIC[] {0x45, 0x52};
|
|
|
+ // 512 BE == 2
|
|
|
+ // constexpr uint8_t HFS_BLOCK_SIZE_HEX[] = {0x02, 0x00};
|
|
|
+ // HFS partitions start with BD at offset 1024.
|
|
|
+ constexpr uint8_t HFS_VOLUME_MAGIC[] {0x42, 0x44};
|
|
|
+
|
|
|
+ // Check for Raw HFS Volume start magic
|
|
|
+ if (2 * MACINTOSH_BLOCK_SIZE > img->file.size()) {
|
|
|
+ return false;
|
|
|
}
|
|
|
- // Check HFS Block size is 512
|
|
|
- if (memcmp(block_size, &tmp[2], 2) != 0)
|
|
|
- {
|
|
|
- dbgmsg("---- Block size not 512", block_size);
|
|
|
- result = false;
|
|
|
+ img->file.seek(2 * MACINTOSH_BLOCK_SIZE);
|
|
|
+ img->file.read(scsiDev.data, SD_SECTOR_SIZE);
|
|
|
+
|
|
|
+ if (memcmp(HFS_VOLUME_MAGIC, scsiDev.data, sizeof(HFS_VOLUME_MAGIC)) == 0) {
|
|
|
+ logmsg("---- ERROR: This is a bare HFS Volume. Use DiskJockey to convert it to a Device image.");
|
|
|
+ return false;
|
|
|
}
|
|
|
- uint8_t *mac_driver = &tmp[MACINTOSH_SCSI_DRIVER_OFFSET];
|
|
|
- uint32_t driver_offset_blocks = mac_driver[0] << 24 |
|
|
|
- mac_driver[1] << 16 |
|
|
|
- mac_driver[2] << 8 |
|
|
|
- mac_driver[3];
|
|
|
- // Find size of SCSI Driver partition
|
|
|
- uint8_t *mac_driver_size = &tmp[MACINTOSH_SCSI_DRIVER_SIZE_OFFSET];
|
|
|
- uint32_t driver_size_blocks = mac_driver_size[0] << 8 | mac_driver_size[1];
|
|
|
+ const uint8_t *mac_driver = &scsiDev.data[MACINTOSH_SCSI_DRIVER_OFFSET];
|
|
|
+ const uint32_t driver_offset_blocks = mac_driver[0] << 24 |
|
|
|
+ mac_driver[1] << 16 |
|
|
|
+ mac_driver[2] << 8 |
|
|
|
+ mac_driver[3];
|
|
|
+ // Find the size of SCSI Driver partition
|
|
|
+ const uint8_t *mac_driver_size = &scsiDev.data[MACINTOSH_SCSI_DRIVER_SIZE_OFFSET];
|
|
|
+ const uint32_t driver_size_blocks = mac_driver_size[0] << 8 | mac_driver_size[1];
|
|
|
// SCSI Driver sanity checks
|
|
|
- if((driver_size_blocks * MACINTOSH_BLOCK_SIZE) > MACINTOSH_SCSI_DRIVER_MAX_SIZE ||
|
|
|
- (driver_offset_blocks * MACINTOSH_BLOCK_SIZE) > img->file.size())
|
|
|
- {
|
|
|
- dbgmsg("---- Invalid Macintosh SCSI Driver partition detected.");
|
|
|
- result = false;
|
|
|
- }
|
|
|
- // Contains Lido Driver - driver causes issues on a Mac Plus and is generally slower than the Apple 4.3 or FWB.
|
|
|
- // Also causes compatibility issues with other drivers.
|
|
|
- // Mac block sizes should be the same size SD sector sizes for raw seeks, and reads to work
|
|
|
- assert(MACINTOSH_BLOCK_SIZE == SD_SECTOR_SIZE);
|
|
|
- img->file.seek(driver_offset_blocks * MACINTOSH_BLOCK_SIZE);
|
|
|
- img->file.read(tmp, SD_SECTOR_SIZE);
|
|
|
- uint8_t* lido_driver = &tmp[LIDO_SIG_OFFSET];
|
|
|
- if(memcmp(lido_sig, lido_driver, 4) == 0)
|
|
|
+ if(!((driver_size_blocks * MACINTOSH_BLOCK_SIZE) > MACINTOSH_SCSI_DRIVER_MAX_SIZE ||
|
|
|
+ (driver_offset_blocks * MACINTOSH_BLOCK_SIZE) > img->file.size()))
|
|
|
{
|
|
|
- logmsg("---- WARNING: This drive contains the LIDO driver and may cause issues.");
|
|
|
+ // Check if Lido Driver - driver causes issues on a Mac Plus and is generally slower than the Apple 4.3 or FWB.
|
|
|
+ // Also causes compatibility issues with other drivers.
|
|
|
+ img->file.seek(driver_offset_blocks * MACINTOSH_BLOCK_SIZE);
|
|
|
+ img->file.read(scsiDev.data, SD_SECTOR_SIZE);
|
|
|
+ uint8_t* lido_driver = &scsiDev.data[LIDO_SIG_OFFSET];
|
|
|
+ if(memcmp(LIDO_SIGNATURE, lido_driver, sizeof(LIDO_SIGNATURE)) == 0)
|
|
|
+ {
|
|
|
+ logmsg("---- WARNING: This drive contains the LIDO driver and may cause issues. Use DiskJockey to replace it.");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- return result;
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
// Called from BlueSCSI_disk after image is initalized.
|
|
|
@@ -95,18 +93,11 @@ static void macQuirksSanityCheck(image_config_t *img)
|
|
|
|
|
|
if(img->deviceType == S2S_CFG_FIXED)
|
|
|
{
|
|
|
- if(!isValidMacintoshImage(img))
|
|
|
- {
|
|
|
- logmsg("---- WARNING: This image does not appear to be a valid Macintosh disk image.");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- dbgmsg("---- Valid Macintosh disk image detected.");
|
|
|
- }
|
|
|
+ isValidMacintoshImage(img);
|
|
|
}
|
|
|
|
|
|
- // Macintosh hosts reserve ID 7, so warn the user this configuration wont work
|
|
|
- if((img->scsiId & S2S_CFG_TARGET_ID_BITS) == 7)
|
|
|
+ // Macintosh hosts reserve ID 7, so warn the user this configuration won't work
|
|
|
+ if((img->scsiId & S2S_CFG_TARGET_ID_BITS) == S2S_CFG_TARGET_ID_BITS)
|
|
|
{
|
|
|
logmsg("---- WARNING: Quirks set to Apple so can not use SCSI ID 7!");
|
|
|
}
|