Skip to content

Commit 51019e4

Browse files
committed
Use MetaImgFile to allow ATA-based machines to mount multiple disks
Uses the same approach as we do for SCSI (split the hdd_image property on colons - 45a9d45) to mount multiple images. Switches reading of the apm_all_drivers.bin template file to using direct filesystem operations (since we don't want to go to the JS side in the Emscripten build).
1 parent b220d7b commit 51019e4

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

devices/common/ata/atahd.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
3131
#include <bitset>
3232
#include <cstring>
3333
#include <fstream>
34+
#include <sstream>
3435
#include <string>
3536

3637
using namespace ata_interface;
@@ -57,7 +58,11 @@ int AtaHardDisk::device_postinit() {
5758
auto bus_obj = dynamic_cast<IdeChannel*>(gMachineObj->get_comp_by_name(bus_id));
5859
bus_obj->register_device(dev_num, this);
5960

60-
this->insert_image(hdd_image_path);
61+
std::string single_image_path;
62+
std::istringstream hdd_image_stream(hdd_image_path);
63+
while (std::getline(hdd_image_stream, single_image_path, ':')) {
64+
this->insert_image(single_image_path);
65+
}
6166

6267
return 0;
6368
}

devices/common/ata/atahd.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
2525
#define ATA_HARD_DISK_H
2626

2727
#include <devices/common/ata/atabasedevice.h>
28-
#include <utils/imgfile.h>
28+
#include <utils/metaimgfile.h>
2929

3030
#include <string>
3131

@@ -60,7 +60,7 @@ class AtaHardDisk : public AtaBaseDevice
6060
void calc_chs_params();
6161

6262
private:
63-
ImgFile hdd_img;
63+
MetaImgFile hdd_img;
6464
uint64_t img_size = 0;
6565
uint32_t total_sectors = 0;
6666
uint64_t cur_fpos = 0;

utils/metaimgfile.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
2323
#include <memaccess.h>
2424
#include <loguru.hpp>
2525

26+
#include <fstream>
2627
#include <limits>
2728

2829
// ================================================================================================
@@ -562,14 +563,17 @@ void MetaImgFile::append_chunk(std::unique_ptr<FileMetaChunk> file)
562563
void MetaImgFile::reserve_partitions(int partitions_to_reserve)
563564
{
564565
if (this->max_partitions == 0) {
565-
ImgFile partitions;
566-
if (!partitions.open("apm_all_drivers.bin")) {
566+
std::ifstream partitions;
567+
partitions.open("apm_all_drivers.bin", std::ios::in | std::ios::binary);
568+
if (partitions.fail()) {
567569
ABORT_F("MetaImgFile: Missing file \"apm_all_drivers.bin\"");
568570
return;
569571
}
570-
uint64_t partitions_size = partitions.size();
572+
partitions.seekg(0, std::ios::end);
573+
size_t partitions_size = partitions.tellg();
571574
auto data = std::unique_ptr<uint8_t[]>(new uint8_t[partitions_size]);
572-
partitions.read(&data[0], 0, partitions_size);
575+
partitions.seekg(0, std::ios::beg);
576+
partitions.read((char*)data.get(), partitions_size);
573577
partitions.close();
574578

575579
Partition part = *(Partition*)&data[this->block_size];

0 commit comments

Comments
 (0)