From 404b088199840eeb69d5818d41f691bb5e981144 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 25 Aug 2019 15:09:27 -0400 Subject: [PATCH] Adds a trivial mass-storage device, for Macintosh HFV volumes. --- Storage/MassStorage/Formats/HFV.cpp | 33 +++++++++++++++++++++++++ Storage/MassStorage/Formats/HFV.hpp | 38 +++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 Storage/MassStorage/Formats/HFV.cpp create mode 100644 Storage/MassStorage/Formats/HFV.hpp diff --git a/Storage/MassStorage/Formats/HFV.cpp b/Storage/MassStorage/Formats/HFV.cpp new file mode 100644 index 000000000..85fa20847 --- /dev/null +++ b/Storage/MassStorage/Formats/HFV.cpp @@ -0,0 +1,33 @@ +// +// HFV.cpp +// Clock Signal +// +// Created by Thomas Harte on 25/08/2019. +// Copyright © 2019 Thomas Harte. All rights reserved. +// + +#include "HFV.hpp" + +using namespace Storage::MassStorage; + +HFV::HFV(const std::string &file_name) : file_(file_name) { + // Is the file a multiple of 512 bytes in size and larger than a floppy disk? + const auto file_size = file_.stats().st_size; + if(file_size & 511 || file_size <= 800*1024) throw std::exception(); + + // TODO: check filing system for MFS, HFS or HFS+. +} + +size_t HFV::get_block_size() { + return 512; +} + +size_t HFV::get_number_of_blocks() { + return size_t(file_.stats().st_size) / get_block_size(); +} + +std::vector HFV::get_block(size_t address) { + const long file_offset = long(get_block_size() * address); + file_.seek(file_offset, SEEK_SET); + return file_.read(get_block_size()); +} diff --git a/Storage/MassStorage/Formats/HFV.hpp b/Storage/MassStorage/Formats/HFV.hpp new file mode 100644 index 000000000..c3c556ee6 --- /dev/null +++ b/Storage/MassStorage/Formats/HFV.hpp @@ -0,0 +1,38 @@ +// +// HFV.hpp +// Clock Signal +// +// Created by Thomas Harte on 25/08/2019. +// Copyright © 2019 Thomas Harte. All rights reserved. +// + +#ifndef HFV_hpp +#define HFV_hpp + +#include "../MassStorageDevice.hpp" +#include "../../FileHolder.hpp" + +namespace Storage { +namespace MassStorage { + +/*! + Provides a @c MassStorageDevice containing an HFV image, which is a sector dump of + a Macintosh drive that is not the correct size to be a floppy disk. +*/ +class HFV: public MassStorageDevice { + public: + HFV(const std::string &file_name); + + private: + FileHolder file_; + + size_t get_block_size() final; + size_t get_number_of_blocks() final; + std::vector get_block(size_t address) final; + +}; + +} +} + +#endif /* HFV_hpp */