resonance 1.0.1
Loading...
Searching...
No Matches
volume.h
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <cstddef>
5#include <cstdint>
6#include <expected>
7#include <span>
8#include <string>
9#include <string_view>
10#include <vector>
11
12#include "error.h"
13#include "isodate.h"
14
16namespace Tools::BuildImage {
17
20 std::uint32_t lba = 0;
21 std::uint32_t size = 0;
22};
23
26 std::uint32_t lba = 0;
28 std::vector<DirectoryExtent> directories;
30 std::uint32_t size = 0;
31};
32
34class Volume {
35public:
37 static constexpr std::size_t kSectorData = 2048;
39 static constexpr std::uint32_t kPvdSector = 16;
41 static constexpr std::string_view kPvdMagic = "CD001";
43 static constexpr std::string_view kSystemCnf = "SYSTEM.CNF";
45 static constexpr std::string_view kPalExecutable = "SCES_507.91";
47 static constexpr std::string_view kNtscExecutable = "SCUS_971.25";
48
50 using Sector = std::array<std::uint8_t, kSectorData>;
51
53 virtual ~Volume() = default;
54
62 virtual std::expected<LocatedFile, Error> find(const std::string &name) = 0;
63
71 virtual std::expected<void, Error> readSector(std::uint32_t lba,
72 std::span<std::uint8_t, kSectorData> sector) = 0;
73
81 virtual std::expected<std::size_t, Error> readSectors(std::uint32_t lba,
82 std::span<std::uint8_t> sectors);
83
89 [[nodiscard]] virtual std::uint32_t volumeSectors() const = 0;
90
97 std::expected<std::string, Error> bootExecutable();
98
106 static std::expected<std::string, Error> parseBoot2(std::span<const std::uint8_t> data);
107
114 static std::uint32_t sectorsFor(std::uint64_t size);
115
122 static std::string upperAscii(std::string_view text);
123
130 static std::string lowerAscii(std::string_view text);
131
138 static std::unexpected<Error> pastEnd(std::uint32_t lba);
139};
140
141} // namespace Tools::BuildImage
The data sectors of an ISO9660 volume, from a disc image or built from a disc root.
Definition volume.h:34
virtual std::expected< void, Error > readSector(std::uint32_t lba, std::span< std::uint8_t, kSectorData > sector)=0
Read the data bytes of one sector.
virtual std::expected< std::size_t, Error > readSectors(std::uint32_t lba, std::span< std::uint8_t > sectors)
Read the data bytes of consecutive sectors, stopping where the medium ends.
static constexpr std::size_t kSectorData
Data bytes in one sector.
Definition volume.h:37
static std::unexpected< Error > pastEnd(std::uint32_t lba)
Report that a sector lies past the end of the medium.
static std::string lowerAscii(std::string_view text)
Convert the ASCII letters of a text to lower case.
static constexpr std::uint32_t kPvdSector
Sector of the primary volume descriptor.
Definition volume.h:39
static std::uint32_t sectorsFor(std::uint64_t size)
Count the sectors that a length in bytes occupies.
static constexpr std::string_view kNtscExecutable
Executable of the North American release.
Definition volume.h:47
virtual std::uint32_t volumeSectors() const =0
Report the sector count of the volume.
static constexpr std::string_view kPalExecutable
Executable of the European release.
Definition volume.h:45
static constexpr std::string_view kSystemCnf
Name of the boot configuration file.
Definition volume.h:43
std::expected< std::string, Error > bootExecutable()
Read the name of the executable the disc boots.
static constexpr std::string_view kPvdMagic
Identifier of an ISO9660 volume descriptor.
Definition volume.h:41
static std::expected< std::string, Error > parseBoot2(std::span< const std::uint8_t > data)
Read the executable name from the text of SYSTEM.CNF.
virtual ~Volume()=default
Release the medium.
virtual std::expected< LocatedFile, Error > find(const std::string &name)=0
Locate a file by name anywhere in the tree.
static std::string upperAscii(std::string_view text)
Convert the ASCII letters of a text to upper case.
std::array< std::uint8_t, kSectorData > Sector
The data bytes of one sector.
Definition volume.h:50
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
The extent of a directory in the ISO9660 tree.
Definition volume.h:19
std::uint32_t lba
Definition volume.h:20
std::uint32_t size
Definition volume.h:21
A file found in the ISO9660 tree.
Definition volume.h:25
std::uint32_t lba
Definition volume.h:26
std::vector< DirectoryExtent > directories
The containing directory, then each ancestor up to the root directory.
Definition volume.h:28
Seconds modified
Definition volume.h:29
std::uint32_t size
Definition volume.h:30