resonance 1.0.1
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 "volume.h"
17
18namespace Tools::BuildImage {
19
29class DirectoryVolume final : public Volume {
30public:
39 static std::expected<std::unique_ptr<DirectoryVolume>, Error>
40 create(const std::filesystem::path &root, std::optional<std::vector<std::uint8_t>> systemArea);
41
49 static std::expected<std::string, Error> identify(const std::filesystem::path &root);
50
52 std::expected<LocatedFile, Error> find(const std::string &name) override;
54 std::expected<void, Error> readSector(std::uint32_t lba,
55 std::span<std::uint8_t, kSectorData> sector) override;
57 [[nodiscard]] std::uint32_t volumeSectors() const override;
58
59private:
60 struct Entry {
61 std::string isoName;
62 std::uint32_t lba = 0;
63 Seconds mtime;
64 std::filesystem::path path;
65 std::uint32_t size = 0;
66 };
67
68 struct ListingEntry {
69 bool isDirectory = false;
70 std::string isoName;
71 std::filesystem::path path;
72 std::size_t index = 0;
73 };
74
75 DirectoryVolume() = default;
76
77 std::expected<void, Error> build(const std::filesystem::path &root);
78 static std::expected<std::string, Error> isoName(const std::filesystem::path &entry);
79 static std::uint32_t extentSize(const std::vector<ListingEntry> &listing);
80 static std::vector<std::uint8_t>
81 record(std::string_view identifier, const Entry &entry, bool isDirectory);
82 void writeDescriptors(std::uint32_t pathTable, std::uint32_t tableSectors, Seconds newest);
83 void writePathTables(std::uint32_t tableSectors);
84 void writeDirectory(std::size_t directory);
85
86 std::vector<std::uint8_t> systemArea_;
87 std::vector<Entry> directories_;
88 std::vector<std::size_t> parents_;
89 std::vector<std::vector<ListingEntry>> listings_;
90 std::vector<Entry> files_;
91 std::map<std::string, std::size_t> parentOf_;
92 std::vector<std::uint32_t> fileStarts_;
93 std::map<std::uint32_t, Sector> metadata_;
94 std::map<std::filesystem::path, std::ifstream> handles_;
95 std::uint32_t volumeSectors_ = 0;
96};
97
98} // namespace Tools::BuildImage
static std::expected< std::unique_ptr< DirectoryVolume >, Error > create(const std::filesystem::path &root, std::optional< std::vector< std::uint8_t > > systemArea)
Build the volume layout.
std::expected< LocatedFile, Error > find(const std::string &name) override
Locate a file by name anywhere in the tree.
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 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