wavelength 1.0.0
Loading...
Searching...
No Matches
imagebuilder.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <expected>
5#include <filesystem>
6#include <functional>
7#include <map>
8#include <span>
9#include <string>
10#include <utility>
11#include <vector>
12
13#include "isodate.h"
14#include "udftree.h"
15#include "volume.h"
16
18namespace Tools::BuildImage {
19
20using Common::DirectoryExtent;
21using Common::Error;
22using Common::LocatedFile;
23using Common::Seconds;
24using Common::Volume;
25
28 std::string target;
29 std::vector<std::uint8_t> payload;
32};
33
50class ImageBuilder {
51public:
60 static std::expected<ImageBuilder, Error> plan(Volume &source,
61 std::vector<Replacement> replacements);
62
71 std::expected<std::uint32_t, Error> write(const std::filesystem::path &output);
72
73private:
74 // The edit returns true once it has found its record.
75 using RecordEdit = std::function<bool(std::span<std::uint8_t>)>;
76
77 ImageBuilder(Volume &source, std::vector<Replacement> replacements);
78
79 std::expected<Volume::Sector *, Error> sector(std::uint32_t lba);
80 std::expected<bool, Error> editRecords(const DirectoryExtent &directory,
81 const RecordEdit &edit);
82 std::expected<void, Error> placePayloads();
83 std::expected<void, Error>
84 patchIso(const LocatedFile &found, const Replacement &replacement, std::uint32_t newLba);
85 std::expected<void, Error> patchUdf(const UdfTree &udf,
86 const LocatedFile &found,
87 const Replacement &replacement,
88 std::uint32_t newLba);
89 std::expected<std::uint32_t, Error>
90 patchUdfVolume(const UdfTree &udf, std::uint32_t appendLba, bool relocated, Seconds newest);
91 std::expected<void, Error> patchDescriptor(std::uint32_t volumeSectors);
92 [[nodiscard]] std::expected<void, Error> verify(const std::filesystem::path &image) const;
93
94 Volume *source_;
95 std::vector<Replacement> replacements_;
96 std::map<std::uint32_t, Volume::Sector> overlays_;
97 std::uint32_t volumeSectors_ = 0;
98 std::vector<std::pair<std::string, std::uint32_t>> written_;
99};
100
101} // namespace Tools::BuildImage
static std::expected< ImageBuilder, Error > plan(Volume &source, std::vector< Replacement > replacements)
Place each payload and collect the sectors that change.
std::expected< std::uint32_t, Error > write(const std::filesystem::path &output)
Write the ISO image and check the replaced extents.
The UDF bridge file system of a DVD image, beside its ISO9660 tree.
Definition udftree.h:26
The data sectors of an ISO9660 volume, from a disc image or built from a disc root.
Definition volume.h:34
Writer of an Amplitude disc image with the built executable and IOP modules in place.
Definition directoryvolume.h:20
std::chrono::sys_seconds Seconds
A UTC time with a resolution of one second.
Definition isodate.h:20
A file of the original disc and the payload that replaces it.
Definition imagebuilder.h:27
Seconds modified
Modification time of the payload's source file or archive member, in UTC.
Definition imagebuilder.h:31
std::vector< std::uint8_t > payload
Definition imagebuilder.h:29
std::string target
Definition imagebuilder.h:28
The extent of a directory in the ISO9660 tree.
Definition volume.h:19
A file found in the ISO9660 tree.
Definition volume.h:25