mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-26 08:49:37 +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;
|
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
|
// Blocks 1 and 2 contain entries of the partition map; there's also possibly an entry
|
||||||
// for the driver.
|
// for the driver.
|
||||||
if(source_address < 3 + has_driver) {
|
if(source_address < 3 + volume_provider_.HasDriver) {
|
||||||
struct Partition {
|
struct Partition {
|
||||||
const char *name, *type;
|
const char *name, *type;
|
||||||
uint32_t start_block, size;
|
uint32_t start_block, size;
|
||||||
@ -179,6 +177,7 @@ template <typename VolumeProvider> class PartitionMap {
|
|||||||
|
|
||||||
// The third entry in this constructed partition map is the driver;
|
// The third entry in this constructed partition map is the driver;
|
||||||
// add some additional details.
|
// add some additional details.
|
||||||
|
if constexpr (VolumeProvider::HasDriver) {
|
||||||
if(source_address == 3) {
|
if(source_address == 3) {
|
||||||
const auto driver_size = uint16_t(volume_provider_.driver_size());
|
const auto driver_size = uint16_t(volume_provider_.driver_size());
|
||||||
const auto driver_checksum = uint16_t(volume_provider_.driver_checksum());
|
const auto driver_checksum = uint16_t(volume_provider_.driver_checksum());
|
||||||
@ -203,16 +202,19 @@ template <typename VolumeProvider> class PartitionMap {
|
|||||||
partition[147] = 0x02;
|
partition[147] = 0x02;
|
||||||
partition[149] = 0x07;
|
partition[149] = 0x07;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return partition;
|
return partition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if constexpr (VolumeProvider::HasDriver) {
|
||||||
// The remainder of the non-volume area is the driver.
|
// The remainder of the non-volume area is the driver.
|
||||||
if(source_address >= predriver_blocks() && source_address < non_volume_blocks()) {
|
if(source_address >= predriver_blocks() && source_address < non_volume_blocks()) {
|
||||||
const uint8_t *driver = volume_provider_.driver();
|
const uint8_t *driver = volume_provider_.driver();
|
||||||
const auto offset = (source_address - predriver_blocks()) * 512;
|
const auto offset = (source_address - predriver_blocks()) * 512;
|
||||||
return std::vector<uint8_t>(&driver[offset], &driver[offset + 512]);
|
return std::vector<uint8_t>(&driver[offset], &driver[offset + 512]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Default: return an empty block.
|
// Default: return an empty block.
|
||||||
return std::vector<uint8_t>(512);
|
return std::vector<uint8_t>(512);
|
||||||
@ -239,7 +241,11 @@ template <typename VolumeProvider> class PartitionMap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t driver_block_size() const {
|
size_t driver_block_size() const {
|
||||||
|
if constexpr (VolumeProvider::HasDriver) {
|
||||||
return (volume_provider_.driver_size() + 511) >> 9;
|
return (volume_provider_.driver_size() + 511) >> 9;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ class Volume {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct VolumeProvider {
|
struct VolumeProvider {
|
||||||
|
static constexpr bool HasDriver = true;
|
||||||
size_t driver_size() const;
|
size_t driver_size() const;
|
||||||
uint16_t driver_checksum() const;
|
uint16_t driver_checksum() const;
|
||||||
const uint8_t *driver() const;
|
const uint8_t *driver() const;
|
||||||
@ -56,43 +57,6 @@ struct VolumeProvider {
|
|||||||
*/
|
*/
|
||||||
using Mapper = Storage::MassStorage::Encodings::Apple::PartitionMap<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