vfs: allow subdirectory creation in /dev

This commit is contained in:
DH 2024-08-31 23:24:52 +03:00
parent ceb0172b1e
commit 797f70268f

View File

@ -8,14 +8,12 @@
#include <map>
#include <string_view>
static orbis::ErrorCode devfs_stat(orbis::File *file, orbis::Stat *sb,
orbis::Thread *thread) {
*sb = {}; // TODO
return {};
}
static orbis::FileOps devfs_ops = {
.stat = devfs_stat,
};
@ -39,22 +37,13 @@ struct DevFs : IoDevice {
result->ops = &devfs_ops;
*file = result;
return{};
return {};
}
std::string_view devPath = path;
if (auto pos = devPath.find('/'); pos != std::string_view::npos) {
auto deviceName = devPath.substr(0, pos);
devPath.remove_prefix(pos + 1);
if (auto it = devices.find(deviceName); it != devices.end()) {
return it->second->open(file, std::string(devPath).c_str(), flags, mode,
thread);
}
} else {
std::string_view devPath = path;
if (auto it = devices.find(devPath); it != devices.end()) {
return it->second->open(file, "", flags, mode, thread);
}
}
std::fprintf(stderr, "device %s not exists\n", path);
return orbis::ErrorCode::NOENT;
@ -115,7 +104,6 @@ rx::vfs::get(const std::filesystem::path &guestPath) {
std::string normalPath = std::filesystem::path(guestPath).lexically_normal();
std::string_view path = normalPath;
orbis::Ref<IoDevice> device;
std::string_view prefix;
std::lock_guard lock(gMountMtx);
@ -129,7 +117,7 @@ rx::vfs::get(const std::filesystem::path &guestPath) {
path = {};
}
return { gDevFs, std::string(path) };
return {gDevFs, std::string(path)};
}
}