From 42a350156a345d997092a0ef5bf9a4004e8312f6 Mon Sep 17 00:00:00 2001 From: David Given Date: Tue, 30 Aug 2022 23:13:59 +0200 Subject: [PATCH] Amiga FFS writes work. --- lib/vfs/amigaffs.cc | 28 +++++++++++++++++++++++- lib/vfs/fluxsectorinterface.cc | 40 +++++++++++++++++----------------- 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/lib/vfs/amigaffs.cc b/lib/vfs/amigaffs.cc index ac8297e8..1cf8fca8 100644 --- a/lib/vfs/amigaffs.cc +++ b/lib/vfs/amigaffs.cc @@ -147,6 +147,30 @@ public: return bytes; } + void putFile(const Path& path, const Bytes& data) + { + AdfMount m(this); + if (path.size() == 0) + throw BadPathException(); + + auto* vol = m.getVolume(); + changeDirButOne(vol, path); + + auto* file = adfOpenFile(vol, (char*)path.back().c_str(), (char*)"w"); + if (!file) + throw CannotWriteException(); + + unsigned pos = 0; + while (pos != data.size()) + { + long done = adfWriteFile( + file, data.size() - pos, (uint8_t*)data.cbegin() + pos); + pos += done; + } + + adfCloseFile(file); + } + private: class AdfEntry { @@ -270,7 +294,9 @@ public: RETCODE adfNativeWriteSector( struct Device* dev, int32_t sector, int size, uint8_t* buffer) { - return RC_OK; + Bytes bytes(buffer, size); + putLogicalSector(sector, bytes); + return RC_OK; } private: diff --git a/lib/vfs/fluxsectorinterface.cc b/lib/vfs/fluxsectorinterface.cc index 2a5e5553..880df2c5 100644 --- a/lib/vfs/fluxsectorinterface.cc +++ b/lib/vfs/fluxsectorinterface.cc @@ -75,30 +75,30 @@ public: &*_fluxSource); } else - { - /* Only a few sectors have changed. Do we need to populate the track? */ + { + /* Only a few sectors have changed. Do we need to populate the + * track? */ - if (_loadedtracks.find(trackid) == _loadedtracks.end()) - populateSectors(track, side); + if (_loadedtracks.find(trackid) == _loadedtracks.end()) + populateSectors(track, side); - /* Now merge the loaded track with the changed one, and write the result back. */ + /* Now merge the loaded track with the changed one, and write + * the result back. */ - Image image; - for (const unsigned sector : sectors) - { - auto s = image.put(track, side, sector); - if (_changedSectors.contains(track, side, sector)) - s->data = _changedSectors.get(track, side, sector)->data; - else - s->data = _readSectors.get(track, side, sector)->data; - } + Image image; + for (const unsigned sector : sectors) + { + auto s = image.put(track, side, sector); + if (_changedSectors.contains(track, side, sector)) + s->data = + _changedSectors.get(track, side, sector)->data; + else + s->data = _readSectors.get(track, side, sector)->data; + } - writeDiskCommand(image, - *_encoder, - *_fluxSink, - &*_decoder, - &*_fluxSource); - } + writeDiskCommand( + image, *_encoder, *_fluxSink, &*_decoder, &*_fluxSource); + } } }