wavelength 1.0.0
Loading...
Searching...
No Matches
directoryvolume.h
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#include <cstddef>
5#include <cstdint>
6#include <expected>
7#include <filesystem>
8#include <fstream>
9#include <map>
10#include <memory>
11#include <optional>
12#include <string>
13#include <string_view>
14#include <vector>
15
16#include "imagebuilder.h"
17#include "isodate.h"
18#include "volume.h"
19
21
22using Common::Error;
24using Common::Seconds;
25using Common::Volume;
26
39class DirectoryVolume final : public Volume {
40public:
53 static std::expected<std::unique_ptr<DirectoryVolume>, Error>
54 create(const std::filesystem::path &root,
55 std::optional<std::vector<std::uint8_t>> systemArea,
56 std::vector<Replacement> replacements);
57
65 static std::expected<std::string, Error> identify(const std::filesystem::path &root);
66
68 std::expected<LocatedFile, Error> find(const std::string &name) override;
70 std::expected<void, Error> readSector(std::uint32_t lba,
71 std::span<std::uint8_t, kSectorData> sector) override;
73 [[nodiscard]] std::uint32_t volumeSectors() const override;
74
75private:
76 struct Entry {
77 std::string isoName;
78 std::uint32_t lba = 0;
79 Seconds mtime;
80 std::filesystem::path path;
81 std::uint32_t size = 0;
82 const std::vector<std::uint8_t> *payload = nullptr;
83 };
84
85 struct ListingEntry {
86 bool isDirectory = false;
87 std::string isoName;
88 std::filesystem::path path;
89 std::size_t index = 0;
90 };
91
92 DirectoryVolume() = default;
93
94 std::expected<void, Error> build(const std::filesystem::path &root);
95 std::expected<void, Error> applyReplacements();
96 static std::expected<std::string, Error> isoName(const std::filesystem::path &entry);
97 static std::uint32_t extentSize(const std::vector<ListingEntry> &listing);
98 static std::vector<std::uint8_t>
99 record(std::string_view identifier, const Entry &entry, bool isDirectory);
100 void writeDescriptors(std::uint32_t pathTable, std::uint32_t tableSectors, Seconds newest);
101 void writePathTables(std::uint32_t tableSectors);
102 void writeDirectory(std::size_t directory);
103
104 std::vector<std::uint8_t> systemArea_;
105 std::vector<Replacement> replacements_;
106 std::vector<Entry> directories_;
107 std::vector<std::size_t> parents_;
108 std::vector<std::vector<ListingEntry>> listings_;
109 std::vector<Entry> files_;
110 std::map<std::string, std::size_t> parentOf_;
111 std::vector<std::uint32_t> fileStarts_;
112 std::map<std::uint32_t, Sector> metadata_;
113 std::map<std::filesystem::path, std::ifstream> handles_;
114 std::uint32_t volumeSectors_ = 0;
115};
116
117} // namespace Tools::BuildImage
std::expected< LocatedFile, Error > find(const std::string &name) override
Locate a file by name anywhere in the tree, ignoring case.
static std::expected< std::unique_ptr< DirectoryVolume >, Error > create(const std::filesystem::path &root, std::optional< std::vector< std::uint8_t > > systemArea, std::vector< Replacement > replacements)
Build the volume layout.
std::expected< void, Error > readSector(std::uint32_t lba, std::span< std::uint8_t, kSectorData > sector) override
Read the data bytes of one sector.
std::uint32_t volumeSectors() const override
Report the sector count of the volume.
static std::expected< std::string, Error > identify(const std::filesystem::path &root)
Read the name of the executable a disc root boots, without building the volume.
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
Failure returned through std::expected.
Definition error.h:17
A file found in the ISO9660 tree.
Definition volume.h:25