wavelength 1.0.0
Loading...
Searching...
No Matches
udftree.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <expected>
5#include <map>
6#include <optional>
7#include <vector>
8
9#include "isodate.h"
10#include "volume.h"
11
12namespace Tools::BuildImage {
13
14using Common::Error;
15using Common::Seconds;
16using Common::Volume;
17
26class UdfTree {
27public:
29 static constexpr std::uint32_t kAnchorSector = 256;
30
32 struct File {
33 std::uint32_t entry = 0;
36 std::vector<std::uint32_t> directories;
37 std::size_t extents = 0;
39 std::uint64_t size = 0;
40 };
41
49 static std::expected<std::optional<UdfTree>, Error> open(Volume &volume);
50
57 [[nodiscard]] std::expected<File, Error> find(std::uint32_t lba) const;
58
64 [[nodiscard]] std::uint32_t partitionStart() const;
65
71 [[nodiscard]] const std::vector<std::uint32_t> &partitionDescriptors() const;
72
78 [[nodiscard]] std::optional<std::uint32_t> integrityDescriptor() const;
79
91 static void
92 setFile(Volume::Sector &entry, std::uint32_t size, std::uint32_t block, Seconds modified);
93
100 static void raiseModified(Volume::Sector &entry, Seconds time);
101
110 static void
111 raiseIntegrity(Volume::Sector &descriptor, Seconds time, std::uint32_t partitionLength);
112
119 static std::uint32_t partitionLength(const Volume::Sector &descriptor);
120
127 static void setPartitionLength(Volume::Sector &descriptor, std::uint32_t length);
128
135 static void relocate(Volume::Sector &descriptor, std::uint32_t location);
136
137private:
138 UdfTree() = default;
139
140 std::expected<void, Error> walk(Volume &volume, std::uint32_t block);
141 std::expected<std::vector<std::uint8_t>, Error> directoryData(Volume &volume,
142 const Volume::Sector &entry);
143
144 std::uint32_t partitionStart_ = 0;
145 std::vector<std::uint32_t> partitionDescriptors_;
146 std::optional<std::uint32_t> integrityDescriptor_;
147 std::map<std::uint32_t, File> files_;
148};
149
150} // namespace Tools::BuildImage
static std::uint32_t partitionLength(const Volume::Sector &descriptor)
Read the length of a partition descriptor.
static void setFile(Volume::Sector &entry, std::uint32_t size, std::uint32_t block, Seconds modified)
Give a file entry a new single extent and date.
static void raiseModified(Volume::Sector &entry, Seconds time)
Raise the modification time of a file entry.
static void raiseIntegrity(Volume::Sector &descriptor, Seconds time, std::uint32_t partitionLength)
Raise the recording time of a logical volume integrity descriptor and set its partition size.
std::optional< std::uint32_t > integrityDescriptor() const
Report the sector of the logical volume integrity descriptor.
std::uint32_t partitionStart() const
Report the first sector of the partition.
std::expected< File, Error > find(std::uint32_t lba) const
Locate the file whose data starts at a sector.
const std::vector< std::uint32_t > & partitionDescriptors() const
List the sectors of the partition descriptors in both volume descriptor sequences.
static std::expected< std::optional< UdfTree >, Error > open(Volume &volume)
Read the UDF structures of a volume.
static void setPartitionLength(Volume::Sector &descriptor, std::uint32_t length)
Set the length of a partition descriptor.
static void relocate(Volume::Sector &descriptor, std::uint32_t location)
Move a descriptor to another sector by rewriting its tag location.
static constexpr std::uint32_t kAnchorSector
Sector of the first anchor volume descriptor pointer.
Definition udftree.h:29
std::array< std::uint8_t, kSectorData > Sector
The data bytes of one sector.
Definition volume.h:50
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 UDF tree.
Definition udftree.h:32
std::vector< std::uint32_t > directories
Sectors of the file entries of the containing directory, then each ancestor up to the root directory.
Definition udftree.h:36
std::uint32_t entry
Definition udftree.h:33
std::size_t extents
Definition udftree.h:37
std::uint64_t size
Definition udftree.h:39
Seconds modified
Definition udftree.h:38
Failure returned through std::expected.
Definition error.h:17