wavelength 1.0.0
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 <vector>
10
11#include "volume.h"
12
13namespace Tools::Common {
14
16class SourceImage final : public Volume {
17public:
25 static std::expected<std::unique_ptr<SourceImage>, Error>
26 open(const std::filesystem::path &path);
27
29 std::expected<LocatedFile, Error> find(const std::string &name) override;
40 std::expected<std::size_t, Error> extract(const std::filesystem::path &root);
42 std::expected<void, Error> readSector(std::uint32_t lba,
43 std::span<std::uint8_t, kSectorData> sector) override;
45 std::expected<std::size_t, Error> readSectors(std::uint32_t lba,
46 std::span<std::uint8_t> sectors) override;
48 [[nodiscard]] std::uint32_t volumeSectors() const override;
49
50private:
51 struct Record {
52 bool isDirectory = false;
53 std::uint32_t lba = 0;
54 Seconds modified;
55 bool multiExtent = false;
56 std::string name;
57 std::uint32_t size = 0;
58 };
59
60 explicit SourceImage(std::ifstream handle);
61
62 std::expected<std::vector<Record>, Error> records(std::uint32_t lba, std::uint32_t size);
63
64 std::ifstream handle_;
65 std::uint32_t volumeSectors_ = 0;
66};
67
68} // namespace Tools::Common
Random access to the sectors of an ISO disc image.
Definition sourceimage.h:16
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, ignoring case.
std::expected< std::size_t, Error > extract(const std::filesystem::path &root)
Copy every file of the ISO9660 tree into a directory.
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.
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 ISO image and verify its primary volume descriptor.
The data sectors of an ISO9660 volume, from a disc image or built from a disc root.
Definition volume.h:34
Code that the host tools share.
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