resonance 1.0.1
Loading...
Searching...
No Matches
sourceimage.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <expected>
5#include <filesystem>
6#include <fstream>
7#include <memory>
8#include <string>
9#include <utility>
10#include <vector>
11
12#include "volume.h"
13
14namespace Tools::BuildImage {
15
17class SourceImage final : public Volume {
18public:
26 static std::expected<std::unique_ptr<SourceImage>, Error>
27 open(const std::filesystem::path &path);
28
30 std::expected<LocatedFile, Error> find(const std::string &name) override;
32 std::expected<void, Error> readSector(std::uint32_t lba,
33 std::span<std::uint8_t, kSectorData> sector) override;
35 std::expected<std::size_t, Error> readSectors(std::uint32_t lba,
36 std::span<std::uint8_t> sectors) override;
38 [[nodiscard]] std::uint32_t volumeSectors() const override;
39
40private:
41 struct Geometry {
42 std::size_t dataOffset = 0;
43 std::size_t sectorSize = 0;
44 std::uint32_t trackStart = 0;
45 };
46
47 struct Record {
48 bool isDirectory = false;
49 std::uint32_t lba = 0;
50 Seconds modified;
51 bool multiExtent = false;
52 std::string name;
53 std::uint32_t size = 0;
54 };
55
56 using Layout = std::pair<std::filesystem::path, Geometry>;
57
58 SourceImage(std::ifstream handle, Geometry geometry);
59
60 static std::expected<Layout, Error> detectGeometry(const std::filesystem::path &path);
61 static std::expected<Layout, Error> parseCue(const std::filesystem::path &path);
62 static std::expected<std::filesystem::path, Error>
63 resolveBinPath(const std::filesystem::path &directory, const std::string &binName);
64 std::expected<std::vector<Record>, Error> records(std::uint32_t lba, std::uint32_t size);
65
66 std::ifstream handle_;
67 Geometry geometry_;
68 std::uint32_t volumeSectors_ = 0;
69 std::vector<char> rawBuffer_;
70};
71
72} // namespace Tools::BuildImage
std::expected< void, Error > readSector(std::uint32_t lba, std::span< std::uint8_t, kSectorData > sector) override
Read the data bytes of one sector.
static std::expected< std::unique_ptr< SourceImage >, Error > open(const std::filesystem::path &path)
Open an image and verify its primary volume descriptor.
std::uint32_t volumeSectors() const override
Report the sector count of the volume.
std::expected< LocatedFile, Error > find(const std::string &name) override
Locate a file by name anywhere in the tree.
std::expected< std::size_t, Error > readSectors(std::uint32_t lba, std::span< std::uint8_t > sectors) override
Read the data bytes of consecutive sectors, stopping where the medium ends.
The data sectors of an ISO9660 volume, from a disc image or built from a disc root.
Definition volume.h:34
Writer of a FreQuency disc image with the built executable and module in place.
Definition byteorder.h:7
std::chrono::sys_seconds Seconds
A UTC time with a resolution of one second.
Definition isodate.h:20
Failure returned through std::expected.
Definition error.h:17