openMSX
DiskPartition.cc
Go to the documentation of this file.
1#include "DiskPartition.hh"
2#include "DiskImageUtils.hh"
3#include "Filename.hh"
4#include "strCat.hh"
5#include <cassert>
6
7namespace openmsx {
8
9using namespace DiskImageUtils;
10
11[[nodiscard]] static DiskName getDiskName(SectorAccessibleDisk* disk, unsigned partition)
12{
13 if (auto* dsk = dynamic_cast<Disk*>(disk)) {
14 return {dsk->getName().getFilename(),
15 strCat(':', partition)};
16 } else {
17 return {Filename("dummy")};
18 }
19}
20
22 std::shared_ptr<SectorAccessibleDisk> owned_)
23 : SectorBasedDisk(getDiskName(&disk, partition))
24 , parent(disk)
25 , owned(std::move(owned_))
26{
27 assert(!owned || (owned.get() == &disk));
28
29 if (partition == 0) {
30 start = 0;
32 } else {
33 checkValidPartition(disk, partition); // throws
34 SectorBuffer buf;
35 disk.readSector(0, buf);
36 auto& p = buf.pt.part[31 - partition];
37 start = p.start;
38 setNbSectors(p.size);
39 }
40}
41
43 size_t start_, size_t length)
44 : SectorBasedDisk(getDiskName(nullptr, 0))
45 , parent(parent_)
46 , start(start_)
47{
49}
50
51void DiskPartition::readSectorImpl(size_t sector, SectorBuffer& buf)
52{
53 parent.readSector(start + sector, buf);
54}
55
56void DiskPartition::writeSectorImpl(size_t sector, const SectorBuffer& buf)
57{
58 parent.writeSector(start + sector, buf);
59}
60
61bool DiskPartition::isWriteProtectedImpl() const
62{
63 return parent.isWriteProtected();
64}
65
66} // namespace openmsx
const Filename & getFilename() const
Definition: DiskName.hh:18
DiskPartition(SectorAccessibleDisk &disk, unsigned partition, std::shared_ptr< SectorAccessibleDisk > owned=nullptr)
Return a partition (as a SectorBasedDisk) from another Disk.
void readSector(size_t sector, SectorBuffer &buf)
void writeSector(size_t sector, const SectorBuffer &buf)
Abstract class for disk images that only represent the logical sector information (so not the raw tra...
void setNbSectors(size_t num)
T length(const vecN< N, T > &x)
Definition: gl_vec.hh:340
void partition(SectorAccessibleDisk &disk, std::span< const unsigned > sizes)
Write a partition table to the given disk and format each partition.
void checkValidPartition(SectorAccessibleDisk &disk, unsigned partition)
Checks whether the disk is partitioned the specified partition exists throws a CommandException if on...
This file implemented 3 utility functions:
Definition: Autofire.cc:9
STL namespace.
std::string strCat(Ts &&...ts)
Definition: strCat.hh:542
std::array< Partition, 31 > part