mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-27 01:31:42 +00:00
Allow VolumeProviders to opt out of drivers completely.
This commit is contained in:
parent
22a3f4de2c
commit
91e9248ecc
@ -120,11 +120,9 @@ template <typename VolumeProvider> class PartitionMap {
|
||||
return driver_description;
|
||||
}
|
||||
|
||||
const bool has_driver = volume_provider_.driver_size() > 0;
|
||||
|
||||
// Blocks 1 and 2 contain entries of the partition map; there's also possibly an entry
|
||||
// for the driver.
|
||||
if(source_address < 3 + has_driver) {
|
||||
if(source_address < 3 + volume_provider_.HasDriver) {
|
||||
struct Partition {
|
||||
const char *name, *type;
|
||||
uint32_t start_block, size;
|
||||
@ -179,39 +177,43 @@ template <typename VolumeProvider> class PartitionMap {
|
||||
|
||||
// The third entry in this constructed partition map is the driver;
|
||||
// add some additional details.
|
||||
if(source_address == 3) {
|
||||
const auto driver_size = uint16_t(volume_provider_.driver_size());
|
||||
const auto driver_checksum = uint16_t(volume_provider_.driver_checksum());
|
||||
if constexpr (VolumeProvider::HasDriver) {
|
||||
if(source_address == 3) {
|
||||
const auto driver_size = uint16_t(volume_provider_.driver_size());
|
||||
const auto driver_checksum = uint16_t(volume_provider_.driver_checksum());
|
||||
|
||||
/* Driver size in bytes. */
|
||||
partition[98] = uint8_t(driver_size >> 8);
|
||||
partition[99] = uint8_t(driver_size);
|
||||
/* Driver size in bytes. */
|
||||
partition[98] = uint8_t(driver_size >> 8);
|
||||
partition[99] = uint8_t(driver_size);
|
||||
|
||||
/* Driver checksum. */
|
||||
partition[118] = uint8_t(driver_checksum >> 8);
|
||||
partition[119] = uint8_t(driver_checksum);
|
||||
/* Driver checksum. */
|
||||
partition[118] = uint8_t(driver_checksum >> 8);
|
||||
partition[119] = uint8_t(driver_checksum);
|
||||
|
||||
/* Driver target processor. */
|
||||
const char *driver_target = volume_provider_.driver_target();
|
||||
memcpy(&partition[120], driver_target, strlen(driver_target));
|
||||
/* Driver target processor. */
|
||||
const char *driver_target = volume_provider_.driver_target();
|
||||
memcpy(&partition[120], driver_target, strlen(driver_target));
|
||||
|
||||
// Various non-zero values that Apple HD SC Tool wrote are below; they are
|
||||
// documented as reserved officially, so I don't know their meaning.
|
||||
partition[137] = 0x01;
|
||||
partition[138] = 0x06;
|
||||
partition[143] = 0x01;
|
||||
partition[147] = 0x02;
|
||||
partition[149] = 0x07;
|
||||
// Various non-zero values that Apple HD SC Tool wrote are below; they are
|
||||
// documented as reserved officially, so I don't know their meaning.
|
||||
partition[137] = 0x01;
|
||||
partition[138] = 0x06;
|
||||
partition[143] = 0x01;
|
||||
partition[147] = 0x02;
|
||||
partition[149] = 0x07;
|
||||
}
|
||||
}
|
||||
|
||||
return partition;
|
||||
}
|
||||
|
||||
// The remainder of the non-volume area is the driver.
|
||||
if(source_address >= predriver_blocks() && source_address < non_volume_blocks()) {
|
||||
const uint8_t *driver = volume_provider_.driver();
|
||||
const auto offset = (source_address - predriver_blocks()) * 512;
|
||||
return std::vector<uint8_t>(&driver[offset], &driver[offset + 512]);
|
||||
if constexpr (VolumeProvider::HasDriver) {
|
||||
// The remainder of the non-volume area is the driver.
|
||||
if(source_address >= predriver_blocks() && source_address < non_volume_blocks()) {
|
||||
const uint8_t *driver = volume_provider_.driver();
|
||||
const auto offset = (source_address - predriver_blocks()) * 512;
|
||||
return std::vector<uint8_t>(&driver[offset], &driver[offset + 512]);
|
||||
}
|
||||
}
|
||||
|
||||
// Default: return an empty block.
|
||||
@ -239,7 +241,11 @@ template <typename VolumeProvider> class PartitionMap {
|
||||
}
|
||||
|
||||
size_t driver_block_size() const {
|
||||
return (volume_provider_.driver_size() + 511) >> 9;
|
||||
if constexpr (VolumeProvider::HasDriver) {
|
||||
return (volume_provider_.driver_size() + 511) >> 9;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -40,6 +40,7 @@ class Volume {
|
||||
};
|
||||
|
||||
struct VolumeProvider {
|
||||
static constexpr bool HasDriver = true;
|
||||
size_t driver_size() const;
|
||||
uint16_t driver_checksum() const;
|
||||
const uint8_t *driver() const;
|
||||
@ -56,43 +57,6 @@ struct VolumeProvider {
|
||||
*/
|
||||
using Mapper = Storage::MassStorage::Encodings::Apple::PartitionMap<VolumeProvider>;
|
||||
|
||||
//class Mapper {
|
||||
// public:
|
||||
// /*!
|
||||
// Sets the drive type to map to and the number of blocks in the underlying partition.
|
||||
// */
|
||||
// void set_drive_type(DriveType, size_t number_of_blocks);
|
||||
//
|
||||
// /*!
|
||||
// Maps from a mass-storage device address to an address
|
||||
// in the underlying HFS partition.
|
||||
// */
|
||||
// ssize_t to_source_address(size_t address);
|
||||
//
|
||||
// /*!
|
||||
// Converts from a source data block to one properly encoded for the drive type.
|
||||
//
|
||||
// Expected usage:
|
||||
//
|
||||
// const size_t source_address = mapper.to_source_address(unit_address);
|
||||
// if(is_in_range_for_partition(source_address)) {
|
||||
// return mapper.convert_source_block(source_address, get_block_contents(source_address));
|
||||
// } else {
|
||||
// return mapper.convert_source_block(source_address);
|
||||
// }
|
||||
// */
|
||||
// std::vector<uint8_t> convert_source_block(ssize_t source_address, std::vector<uint8_t> source_data = {});
|
||||
//
|
||||
// /*!
|
||||
// @returns The total number of blocks on the entire volume.
|
||||
// */
|
||||
// size_t get_number_of_blocks();
|
||||
//
|
||||
// private:
|
||||
// DriveType drive_type_;
|
||||
// size_t number_of_blocks_;
|
||||
//};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user