Skip to content

Commit

Permalink
Add support for updating file metadata (only the SRA bits, really).
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgiven committed May 13, 2024
1 parent 7643457 commit 00e9c5a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
38 changes: 37 additions & 1 deletion lib/vfs/cpmfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class CpmFsFilesystem : public Filesystem, public HasBitmap, public HasMount
uint32_t capabilities() const override
{
return OP_GETFSDATA | OP_LIST | OP_GETFILE | OP_PUTFILE | OP_DELETE |
OP_GETDIRENT | OP_CREATE | OP_MOVE;
OP_GETDIRENT | OP_CREATE | OP_MOVE | OP_PUTATTRS;
}

std::map<std::string, std::string> getMetadata() override
Expand Down Expand Up @@ -294,6 +294,42 @@ class CpmFsFilesystem : public Filesystem, public HasBitmap, public HasMount
throw FileNotFoundException();
}

void putMetadata(const Path& path,
const std::map<std::string, std::string>& metadata) override
{
mount();
if (path.size() != 1)
throw BadPathException();

/* Only updating MODE is supported. */

if (metadata.empty())
return;
if ((metadata.size() != 1) || (metadata.begin()->first != MODE))
throw UnimplementedFilesystemException();
auto mode = metadata.begin()->second;

/* Update all dirents corresponding to this file. */

bool found = false;
for (int d = 0; d < _config.dir_entries(); d++)
{
std::unique_ptr<Entry> entry = getEntry(d);
if (entry->deleted)
continue;
if (path[0] == entry->combinedFilename())
{
entry->mode = mode;
putEntry(entry);
found = true;
}
}
if (!found)
throw FileNotFoundException();

unmount();
}

Bytes getFile(const Path& path) override
{
mount();
Expand Down
26 changes: 26 additions & 0 deletions tests/cpmfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,31 @@ static void testMove()
createDirent("FILE2", 0, 1, {19})));
}

static void testPutMetadata()
{
auto sectors = std::make_shared<TestSectorInterface>();
auto fs = Filesystem::createCpmFsFilesystem(
globalConfig()->filesystem(), sectors);
fs->create(true, "volume");

fs->putFile(Path("0:FILE1"), Bytes{0x55} * 0x9000);
fs->putFile(Path("0:FILE2"), Bytes{5, 6, 7, 8});

fs->putMetadata(Path("0:FILE1"),
std::map<std::string, std::string>{
{"mode", "SRA"}
});

auto directory = getBlock(sectors, 0, 256).slice(0, 32 * 3);
AssertThat(directory,
Equals(createDirent("FILE1 \xa0\xa0\xa0",
0,
0x80,
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}) +
createDirent("FILE1 \xa0\xa0\xa0", 2, 0x20, {17, 18}) +
createDirent("FILE2", 0, 1, {19})));
}

int main(void)
{
try
Expand Down Expand Up @@ -286,6 +311,7 @@ int main(void)
testPutBigFile();
testDelete();
testMove();
testPutMetadata();
}
catch (const ErrorException& e)
{
Expand Down

0 comments on commit 00e9c5a

Please sign in to comment.