1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-27 02:29:12 +00:00
CLK/Storage/MassStorage/Formats/HFV.cpp

40 lines
1.0 KiB
C++
Raw Normal View History

//
// 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<uint8_t> 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());
}
2019-08-25 19:16:35 +00:00
void HFV::set_block(size_t address, const std::vector<uint8_t> &contents) {
const long file_offset = long(get_block_size() * address);
file_.seek(file_offset, SEEK_SET);
file_.write(contents);
}