openMSX
DiskPartition.cc
Go to the documentation of this file.
1#include "DiskPartition.hh"
2
3#include "DiskImageUtils.hh"
4#include "Filename.hh"
5
6#include "strCat.hh"
7
8#include <cassert>
9
10namespace openmsx {
11
12using namespace DiskImageUtils;
13
14[[nodiscard]] static DiskName getDiskName(SectorAccessibleDisk* disk, unsigned partition)
15{
16 if (const auto* dsk = dynamic_cast<Disk*>(disk)) {
17 return {dsk->getName().getFilename(),
18 strCat(':', partition)};
19 } else {
20 return DiskName(Filename("dummy"));
21 }
22}
23
25 std::shared_ptr<SectorAccessibleDisk> owned_)
26 : SectorBasedDisk(getDiskName(&disk, partition))
27 , parent(disk)
28 , owned(std::move(owned_))
29{
30 assert(!owned || (owned.get() == &disk));
31
32 if (partition == 0) {
33 start = 0;
35 } else {
36 SectorBuffer buf;
37 const Partition& p = getPartition(disk, partition, buf); // throws
38 start = p.start;
40 }
41}
42
44 size_t start_, size_t length)
45 : SectorBasedDisk(getDiskName(nullptr, 0))
46 , parent(parent_)
47 , start(start_)
48{
49 setNbSectors(length);
50}
51
52void DiskPartition::readSectorImpl(size_t sector, SectorBuffer& buf)
53{
54 parent.readSector(start + sector, buf);
55}
56
57void DiskPartition::writeSectorImpl(size_t sector, const SectorBuffer& buf)
58{
59 parent.writeSector(start + sector, buf);
60}
61
62bool DiskPartition::isWriteProtectedImpl() const
63{
64 return parent.isWriteProtected();
65}
66
67} // 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) const
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(const 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:11
STL namespace.
std::string strCat()
Definition strCat.hh:703
Endian::UA_L32 size
Endian::UA_L32 start