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 SectorBuffer buf;
34 Partition& p = getPartition(disk, partition, buf); // throws
35 start = p.start;
37 }
38}
39
41 size_t start_, size_t length)
42 : SectorBasedDisk(getDiskName(nullptr, 0))
43 , parent(parent_)
44 , start(start_)
45{
46 setNbSectors(length);
47}
48
49void DiskPartition::readSectorImpl(size_t sector, SectorBuffer& buf)
50{
51 parent.readSector(start + sector, buf);
52}
53
54void DiskPartition::writeSectorImpl(size_t sector, const SectorBuffer& buf)
55{
56 parent.writeSector(start + sector, buf);
57}
58
59bool DiskPartition::isWriteProtectedImpl() const
60{
61 return parent.isWriteProtected();
62}
63
64} // 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)
Partition & getPartition(SectorAccessibleDisk &disk, unsigned partition, SectorBuffer &buf)
Gets the requested partition.
unsigned partition(SectorAccessibleDisk &disk, std::span< const unsigned > sizes, MSXBootSectorType bootType)
Write a partition table to the given disk and format each partition.
This file implemented 3 utility functions:
Definition Autofire.cc:9
STL namespace.
std::string strCat()
Definition strCat.hh:703
Endian::UA_L32 size
Endian::UA_L32 start