vfs: Fix GetRoot(), CacheRecursiveSearch() and root identifier

This commit is contained in:
EnderIce2 2024-10-13 02:33:46 +03:00
parent 850b8ec490
commit f48032658f
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
4 changed files with 40 additions and 31 deletions

View File

@ -37,7 +37,7 @@ static_assert(IFTODT(S_IFCHR) == DT_CHR);
else \
return fsi->Ops.op(this->Node, ##__VA_ARGS__)
#define FSROOT(num) "\002root-" #num "\003"
#define FSROOT(num) "\x06root-" #num "\x06"
class FileNode
{

View File

@ -32,7 +32,12 @@ namespace vfs
struct cwk_segment segment;
if (!cwk_path_get_first_segment(*Path, &segment))
{
if (strcmp(*Path, Parent->fsi->RootName) == 0)
return Parent;
ReturnLogError(nullptr, "Failed to get first segment of path");
}
size_t segments = 0;
while (cwk_path_get_next_segment(&segment))
@ -41,26 +46,26 @@ namespace vfs
if (segments == 0)
return Parent;
const char *path = *Path;
if (strncmp(path, "\002root-", 6) == 0) /* FIXME: deduce the index */
const char *tmpPath = *Path;
if (strncmp(tmpPath, "\x06root-", 6) == 0) /* FIXME: deduce the index */
{
path += 6;
while (*path != '\0' && *path != '\003')
path++;
if (*path == '\003')
path++;
tmpPath += 6;
while (*tmpPath != '\0' && *tmpPath != '\x06')
tmpPath++;
if (*tmpPath == '\x06')
tmpPath++;
}
else
path = *Path;
tmpPath = *Path;
FileNode *__Parent = Parent;
if (this->PathIsAbsolute(path))
if (this->PathIsAbsolute(tmpPath))
{
while (__Parent->Parent)
__Parent = __Parent->Parent;
}
cwk_path_get_first_segment(path, &segment);
cwk_path_get_first_segment(tmpPath, &segment);
do
{
std::string segmentName(segment.begin, segment.size);
@ -94,11 +99,18 @@ namespace vfs
if (Root == nullptr)
return nullptr;
debug("%s cache search for \"%s\" in \"%s\"", IsName ? "Relative" : "Absolute", NameOrPath, Root->Path.c_str());
debug("%s cache search for \"%s\" in \"%s\"",
IsName ? "Relative" : "Absolute",
NameOrPath,
Root->Path.c_str());
struct cwk_segment segment;
if (!cwk_path_get_first_segment(NameOrPath, &segment))
{
if (strcmp(NameOrPath, Root->fsi->RootName) == 0)
return Root;
ReturnLogError(nullptr, "Failed to get first segment of path");
}
size_t segments = 0;
while (cwk_path_get_next_segment(&segment))
@ -116,12 +128,12 @@ namespace vfs
}
const char *path = NameOrPath;
if (strncmp(path, "\002root-", 6) == 0) /* FIXME: deduce the index */
if (strncmp(path, "\x06root-", 6) == 0) /* FIXME: deduce the index */
{
path += 6;
while (*path != '\0' && *path != '\003')
while (*path != '\0' && *path != '\x06')
path++;
if (*path == '\003')
if (*path == '\x06')
path++;
}
else

View File

@ -39,19 +39,16 @@ namespace vfs
FileNode *Virtual::GetRoot(size_t Index)
{
if (Index >= FileSystemRoots->Children.size())
return nullptr;
Inode *RootNode = FileSystemRoots->Children[Index];
char rootName[128]{};
snprintf(rootName, sizeof(rootName), "\002root-%ld\003", Index);
assert(Index < FileSystemRoots->Children.size());
auto it = FileRoots.find(Index);
if (it != FileRoots.end())
return it->second;
FileNode *ret = this->CreateCacheNode(nullptr, RootNode, rootName, 0);
Inode *rootNode = FileSystemRoots->Children[Index];
char rootName[128]{};
snprintf(rootName, sizeof(rootName), "\x06root-%ld\x06", Index);
FileNode *ret = this->CreateCacheNode(nullptr, rootNode, rootName, 0);
FileRoots.insert({Index, ret});
return ret;
}
@ -116,7 +113,7 @@ namespace vfs
FileNode *Virtual::GetByPath(const char *Path, FileNode *Parent)
{
debug("GetByPath: %s", Path);
if (Parent == nullptr)
if (Parent == nullptr || this->PathIsAbsolute(Path))
Parent = thisProcess ? thisProcess->Info.RootNode : this->GetRoot(0);
if (strcmp(Path, ".") == 0)
@ -129,12 +126,12 @@ namespace vfs
if (fn)
return fn;
if (strncmp(Path, "\002root-", 6) == 0) /* FIXME: deduce the index */
if (strncmp(Path, "\x06root-", 6) == 0) /* FIXME: deduce the index */
{
Path += 7;
while (*Path != '\0' && *Path != '\003')
while (*Path != '\0' && *Path != '\x06')
Path++;
if (*Path == '\003')
if (*Path == '\x06')
Path++;
}

View File

@ -45,10 +45,10 @@ namespace vfs
return -ENOENT;
off_t offset = 0;
foreach (const auto &Root in Parent->Children)
for (const auto &Root : Parent->Children)
{
char rootName[128]{};
snprintf(rootName, sizeof(rootName), "\x02root-%ld\x03", offset);
snprintf(rootName, sizeof(rootName), "\x06root-%ld\x06", offset);
if (strcmp(rootName, Name) == 0)
{
@ -159,8 +159,8 @@ namespace vfs
S_IRWXO |
S_IFDIR;
FileNode *proc = this->ForceCreate(this->GetRoot(0), "proc", mode);
FileNode *log = this->ForceCreate(this->GetRoot(0), "var", mode);
log = this->ForceCreate(log, "log", mode);
FileNode *var = this->ForceCreate(this->GetRoot(0), "var", mode);
FileNode *log = this->ForceCreate(var, "log", mode);
proc->Node->Flags = iFlags;
log->Node->Flags = iFlags;