mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
More API overhauling.
This commit is contained in:
@@ -23,15 +23,6 @@ public:
|
||||
locked = bytes0[7] & 0x80;
|
||||
length = ((bytes1[6] & 0x30) << 12) | (bytes1[5] << 8) | bytes1[4];
|
||||
file_type = TYPE_FILE;
|
||||
|
||||
attributes["filename"] = filename;
|
||||
attributes["length"] = fmt::format("{}", length);
|
||||
attributes["type"] = "file";
|
||||
attributes["acorndfs.inode"] = fmt::format("{}", inode);
|
||||
attributes["acorndfs.start_sector"] = fmt::format("{}", start_sector);
|
||||
attributes["acorndfs.load_address"] = fmt::format("0x{:x}", load_address);
|
||||
attributes["acorndfs.exec_address"] = fmt::format("0x{:x}", exec_address);
|
||||
attributes["acorndfs.locked"] = fmt::format("{}", locked);
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -65,6 +56,33 @@ public:
|
||||
throw FileNotFoundException();
|
||||
|
||||
std::vector<std::unique_ptr<Dirent>> result;
|
||||
for (auto& dirent : findAllFiles())
|
||||
result.push_back(std::move(dirent));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> getMetadata(const Path& path)
|
||||
{
|
||||
std::map<std::string, std::string> attributes;
|
||||
|
||||
auto dirent = findFile(path);
|
||||
attributes["filename"] = dirent->filename;
|
||||
attributes["length"] = fmt::format("{}", dirent->length);
|
||||
attributes["type"] = "file";
|
||||
attributes["acorndfs.inode"] = fmt::format("{}", dirent->inode);
|
||||
attributes["acorndfs.start_sector"] = fmt::format("{}", dirent->start_sector);
|
||||
attributes["acorndfs.load_address"] = fmt::format("0x{:x}", dirent->load_address);
|
||||
attributes["acorndfs.exec_address"] = fmt::format("0x{:x}", dirent->exec_address);
|
||||
attributes["acorndfs.locked"] = fmt::format("{}", dirent->locked);
|
||||
|
||||
return attributes;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<AcornDfsDirent>> findAllFiles()
|
||||
{
|
||||
std::vector<std::unique_ptr<AcornDfsDirent>> result;
|
||||
auto sector0 = getSector(0);
|
||||
auto sector1 = getSector(1);
|
||||
|
||||
@@ -77,26 +95,18 @@ public:
|
||||
auto bytes0 = sector0.slice(i * 8 + 8, 8);
|
||||
auto bytes1 = sector1.slice(i * 8 + 8, 8);
|
||||
|
||||
auto dirent = std::make_unique<AcornDfsDirent>(i, bytes0, bytes1);
|
||||
result.push_back(std::move(dirent));
|
||||
result.push_back(std::make_unique<AcornDfsDirent>(i, bytes0, bytes1));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::unique_ptr<Dirent> getMetadata(const Path& path)
|
||||
{
|
||||
return findFile(path);
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<Dirent> findFile(const Path& path)
|
||||
std::unique_ptr<AcornDfsDirent> findFile(const Path& path)
|
||||
{
|
||||
if (path.size() != 1)
|
||||
throw BadPathException();
|
||||
|
||||
auto files = list(Path());
|
||||
for (auto& dirent : files)
|
||||
for (auto& dirent : findAllFiles())
|
||||
{
|
||||
if (dirent->filename == path[0])
|
||||
return std::move(dirent);
|
||||
|
||||
@@ -34,13 +34,6 @@ public:
|
||||
start_sector = br.read_be16();
|
||||
length = br.read_8() * SECTOR_SIZE;
|
||||
file_type = TYPE_FILE;
|
||||
|
||||
attributes["filename"] = filename;
|
||||
attributes["length"] = fmt::format("{}", length);
|
||||
attributes["type"] = "file";
|
||||
attributes["brother120.inode"] = fmt::format("{}", inode);
|
||||
attributes["brother120.start_sector"] = fmt::format("{}", start_sector);
|
||||
attributes["brother120.type"] = fmt::format("{}", brother_type);
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -72,6 +65,31 @@ public:
|
||||
throw FileNotFoundException();
|
||||
|
||||
std::vector<std::unique_ptr<Dirent>> result;
|
||||
for (auto& dirent : findAllFiles())
|
||||
result.push_back(std::move(dirent));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> getMetadata(const Path& path)
|
||||
{
|
||||
std::map<std::string, std::string> attributes;
|
||||
|
||||
auto dirent = findFile(path);
|
||||
attributes["filename"] = dirent->filename;
|
||||
attributes["length"] = fmt::format("{}", dirent->length);
|
||||
attributes["type"] = "file";
|
||||
attributes["brother120.inode"] = fmt::format("{}", dirent->inode);
|
||||
attributes["brother120.start_sector"] = fmt::format("{}", dirent->start_sector);
|
||||
attributes["brother120.type"] = fmt::format("{}", dirent->brother_type);
|
||||
|
||||
return attributes;
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<Brother120Dirent>> findAllFiles()
|
||||
{
|
||||
std::vector<std::unique_ptr<Brother120Dirent>> result;
|
||||
int inode = 0;
|
||||
for (int block = 0; block < DIRECTORY_SECTORS; block++)
|
||||
{
|
||||
@@ -82,27 +100,21 @@ public:
|
||||
if (buffer[0] == 0xf0)
|
||||
continue;
|
||||
|
||||
auto dirent = std::make_unique<Brother120Dirent>(inode, buffer);
|
||||
result.push_back(std::move(dirent));
|
||||
result.push_back(
|
||||
std::make_unique<Brother120Dirent>(inode, buffer));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::unique_ptr<Dirent> getMetadata(const Path& path)
|
||||
{
|
||||
return findFile(path);
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<Dirent> findFile(const Path& path)
|
||||
std::unique_ptr<Brother120Dirent> findFile(const Path& path)
|
||||
{
|
||||
if (path.size() != 1)
|
||||
throw BadPathException();
|
||||
|
||||
auto files = list(Path());
|
||||
for (auto& dirent : files)
|
||||
for (auto& dirent : findAllFiles())
|
||||
{
|
||||
if (dirent->filename == path[0])
|
||||
return std::move(dirent);
|
||||
|
||||
@@ -10,12 +10,6 @@ class DfsProto;
|
||||
class FilesystemProto;
|
||||
class SectorInterface;
|
||||
|
||||
struct File
|
||||
{
|
||||
Bytes data;
|
||||
std::vector<std::shared_ptr<const Sector>> sectors;
|
||||
};
|
||||
|
||||
enum FileType
|
||||
{
|
||||
TYPE_FILE,
|
||||
@@ -24,7 +18,6 @@ enum FileType
|
||||
|
||||
struct Dirent
|
||||
{
|
||||
std::map<std::string, std::string> attributes;
|
||||
std::string filename;
|
||||
FileType file_type;
|
||||
uint64_t length;
|
||||
@@ -65,14 +58,13 @@ public:
|
||||
virtual std::vector<std::unique_ptr<Dirent>> list(const Path& path)
|
||||
{ throw UnimplementedFilesystemException(); }
|
||||
|
||||
virtual std::unique_ptr<File> read(const Path& path)
|
||||
virtual Bytes read(const Path& path)
|
||||
{ throw UnimplementedFilesystemException(); }
|
||||
|
||||
virtual std::vector<std::shared_ptr<const Sector>> write(
|
||||
const Path& path, const Bytes& data)
|
||||
virtual void write(const Path& path, const Bytes& data)
|
||||
{ throw UnimplementedFilesystemException(); }
|
||||
|
||||
virtual std::unique_ptr<Dirent> getMetadata(const Path& path)
|
||||
virtual std::map<std::string, std::string> getMetadata(const Path& path)
|
||||
{ throw UnimplementedFilesystemException(); }
|
||||
|
||||
virtual void setMetadata(const Path& path, const std::map<std::string, std::string>& metadata)
|
||||
|
||||
@@ -56,9 +56,9 @@ int mainGetFileInfo(int argc, const char* argv[])
|
||||
Filesystem::createFilesystem(config.filesystem(), sectorInterface);
|
||||
|
||||
Path path(directory);
|
||||
auto dirent = filesystem->getMetadata(path);
|
||||
auto attributes = filesystem->getMetadata(path);
|
||||
|
||||
for (const auto& e : dirent->attributes)
|
||||
for (const auto& e : attributes)
|
||||
fmt::print("{} = {}\n", e.first, e.second);
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user