mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-05-27 15:04:33 +00:00
vfs: Fix GetRoot(), CacheRecursiveSearch() and root identifier
This commit is contained in:
parent
850b8ec490
commit
f48032658f
@ -37,7 +37,7 @@ static_assert(IFTODT(S_IFCHR) == DT_CHR);
|
|||||||
else \
|
else \
|
||||||
return fsi->Ops.op(this->Node, ##__VA_ARGS__)
|
return fsi->Ops.op(this->Node, ##__VA_ARGS__)
|
||||||
|
|
||||||
#define FSROOT(num) "\002root-" #num "\003"
|
#define FSROOT(num) "\x06root-" #num "\x06"
|
||||||
|
|
||||||
class FileNode
|
class FileNode
|
||||||
{
|
{
|
||||||
|
@ -32,7 +32,12 @@ namespace vfs
|
|||||||
|
|
||||||
struct cwk_segment segment;
|
struct cwk_segment segment;
|
||||||
if (!cwk_path_get_first_segment(*Path, &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");
|
ReturnLogError(nullptr, "Failed to get first segment of path");
|
||||||
|
}
|
||||||
|
|
||||||
size_t segments = 0;
|
size_t segments = 0;
|
||||||
while (cwk_path_get_next_segment(&segment))
|
while (cwk_path_get_next_segment(&segment))
|
||||||
@ -41,26 +46,26 @@ namespace vfs
|
|||||||
if (segments == 0)
|
if (segments == 0)
|
||||||
return Parent;
|
return Parent;
|
||||||
|
|
||||||
const char *path = *Path;
|
const char *tmpPath = *Path;
|
||||||
if (strncmp(path, "\002root-", 6) == 0) /* FIXME: deduce the index */
|
if (strncmp(tmpPath, "\x06root-", 6) == 0) /* FIXME: deduce the index */
|
||||||
{
|
{
|
||||||
path += 6;
|
tmpPath += 6;
|
||||||
while (*path != '\0' && *path != '\003')
|
while (*tmpPath != '\0' && *tmpPath != '\x06')
|
||||||
path++;
|
tmpPath++;
|
||||||
if (*path == '\003')
|
if (*tmpPath == '\x06')
|
||||||
path++;
|
tmpPath++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
path = *Path;
|
tmpPath = *Path;
|
||||||
|
|
||||||
FileNode *__Parent = Parent;
|
FileNode *__Parent = Parent;
|
||||||
if (this->PathIsAbsolute(path))
|
if (this->PathIsAbsolute(tmpPath))
|
||||||
{
|
{
|
||||||
while (__Parent->Parent)
|
while (__Parent->Parent)
|
||||||
__Parent = __Parent->Parent;
|
__Parent = __Parent->Parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
cwk_path_get_first_segment(path, &segment);
|
cwk_path_get_first_segment(tmpPath, &segment);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
std::string segmentName(segment.begin, segment.size);
|
std::string segmentName(segment.begin, segment.size);
|
||||||
@ -94,11 +99,18 @@ namespace vfs
|
|||||||
if (Root == nullptr)
|
if (Root == nullptr)
|
||||||
return 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;
|
struct cwk_segment segment;
|
||||||
if (!cwk_path_get_first_segment(NameOrPath, &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");
|
ReturnLogError(nullptr, "Failed to get first segment of path");
|
||||||
|
}
|
||||||
|
|
||||||
size_t segments = 0;
|
size_t segments = 0;
|
||||||
while (cwk_path_get_next_segment(&segment))
|
while (cwk_path_get_next_segment(&segment))
|
||||||
@ -116,12 +128,12 @@ namespace vfs
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *path = NameOrPath;
|
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;
|
path += 6;
|
||||||
while (*path != '\0' && *path != '\003')
|
while (*path != '\0' && *path != '\x06')
|
||||||
path++;
|
path++;
|
||||||
if (*path == '\003')
|
if (*path == '\x06')
|
||||||
path++;
|
path++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -39,19 +39,16 @@ namespace vfs
|
|||||||
|
|
||||||
FileNode *Virtual::GetRoot(size_t Index)
|
FileNode *Virtual::GetRoot(size_t Index)
|
||||||
{
|
{
|
||||||
if (Index >= FileSystemRoots->Children.size())
|
assert(Index < FileSystemRoots->Children.size());
|
||||||
return nullptr;
|
|
||||||
|
|
||||||
Inode *RootNode = FileSystemRoots->Children[Index];
|
|
||||||
|
|
||||||
char rootName[128]{};
|
|
||||||
snprintf(rootName, sizeof(rootName), "\002root-%ld\003", Index);
|
|
||||||
|
|
||||||
auto it = FileRoots.find(Index);
|
auto it = FileRoots.find(Index);
|
||||||
if (it != FileRoots.end())
|
if (it != FileRoots.end())
|
||||||
return it->second;
|
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});
|
FileRoots.insert({Index, ret});
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -116,7 +113,7 @@ namespace vfs
|
|||||||
FileNode *Virtual::GetByPath(const char *Path, FileNode *Parent)
|
FileNode *Virtual::GetByPath(const char *Path, FileNode *Parent)
|
||||||
{
|
{
|
||||||
debug("GetByPath: %s", Path);
|
debug("GetByPath: %s", Path);
|
||||||
if (Parent == nullptr)
|
if (Parent == nullptr || this->PathIsAbsolute(Path))
|
||||||
Parent = thisProcess ? thisProcess->Info.RootNode : this->GetRoot(0);
|
Parent = thisProcess ? thisProcess->Info.RootNode : this->GetRoot(0);
|
||||||
|
|
||||||
if (strcmp(Path, ".") == 0)
|
if (strcmp(Path, ".") == 0)
|
||||||
@ -129,12 +126,12 @@ namespace vfs
|
|||||||
if (fn)
|
if (fn)
|
||||||
return 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;
|
Path += 7;
|
||||||
while (*Path != '\0' && *Path != '\003')
|
while (*Path != '\0' && *Path != '\x06')
|
||||||
Path++;
|
Path++;
|
||||||
if (*Path == '\003')
|
if (*Path == '\x06')
|
||||||
Path++;
|
Path++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,10 +45,10 @@ namespace vfs
|
|||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
|
||||||
off_t offset = 0;
|
off_t offset = 0;
|
||||||
foreach (const auto &Root in Parent->Children)
|
for (const auto &Root : Parent->Children)
|
||||||
{
|
{
|
||||||
char rootName[128]{};
|
char rootName[128]{};
|
||||||
snprintf(rootName, sizeof(rootName), "\x02root-%ld\x03", offset);
|
snprintf(rootName, sizeof(rootName), "\x06root-%ld\x06", offset);
|
||||||
|
|
||||||
if (strcmp(rootName, Name) == 0)
|
if (strcmp(rootName, Name) == 0)
|
||||||
{
|
{
|
||||||
@ -159,8 +159,8 @@ namespace vfs
|
|||||||
S_IRWXO |
|
S_IRWXO |
|
||||||
S_IFDIR;
|
S_IFDIR;
|
||||||
FileNode *proc = this->ForceCreate(this->GetRoot(0), "proc", mode);
|
FileNode *proc = this->ForceCreate(this->GetRoot(0), "proc", mode);
|
||||||
FileNode *log = this->ForceCreate(this->GetRoot(0), "var", mode);
|
FileNode *var = this->ForceCreate(this->GetRoot(0), "var", mode);
|
||||||
log = this->ForceCreate(log, "log", mode);
|
FileNode *log = this->ForceCreate(var, "log", mode);
|
||||||
proc->Node->Flags = iFlags;
|
proc->Node->Flags = iFlags;
|
||||||
log->Node->Flags = iFlags;
|
log->Node->Flags = iFlags;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user