MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / ResolvePath

Function ResolvePath

Kernel/src/fs/filesystem.cpp:67–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65 }
66
67 FsNode* ResolvePath(const char* path, const char* workingDir, bool followSymlinks){
68 assert(path);
69
70 char* tempPath;
71 if(workingDir && path[0] != '/'){ // If the path starts with '/' then treat as an absolute path
72 tempPath = (char*)kmalloc(strlen(path) + strlen(workingDir) + 2);
73 strcpy(tempPath, workingDir);
74 strcpy(tempPath + strlen(tempPath), "/");
75 strcpy(tempPath + strlen(tempPath), path);
76 } else {
77 tempPath = (char*)kmalloc(strlen(path) + 1);
78 strcpy(tempPath, path);
79 }
80
81 FsNode* root = fs::GetRoot();
82 FsNode* currentNode = root;
83
84 char* file = strtok(tempPath,"/");
85
86 while(file != NULL){ // Iterate through the directories to find the file
87 FsNode* node = fs::FindDir(currentNode,file);
88 if(!node) {
89 Log::Warning("%s not found!", file);
90 kfree(tempPath);
91 return nullptr;
92 }
93
94 size_t amountOfSymlinks = 0;
95 while(((node->flags & FS_NODE_TYPE) == FS_NODE_SYMLINK)){ // Check for symlinks
96 if(amountOfSymlinks++ > MAXIMUM_SYMLINK_AMOUNT){
97 Log::Warning("ResolvePath: Reached maximum number of symlinks");
98 return nullptr;
99 }
100
101 node = FollowLink(node, currentNode);
102
103 if(!node){
104 Log::Warning("ResolvePath: Unresolved symlink!");
105 kfree(tempPath);
106 return node;
107 }
108 }
109
110 if((node->flags & FS_NODE_TYPE) == FS_NODE_DIRECTORY){
111 currentNode = node;
112 file = strtok(NULL, "/");
113 continue;
114 }
115
116 if((file = strtok(NULL, "/"))){
117 Log::Warning("%s is not a directory!", file);
118 kfree(tempPath);
119 return nullptr;
120 }
121
122 amountOfSymlinks = 0;
123 while(followSymlinks && ((currentNode->flags & FS_NODE_TYPE) == FS_NODE_SYMLINK)){ // Check for symlinks
124 if(amountOfSymlinks++ > MAXIMUM_SYMLINK_AMOUNT){

Callers 13

KernelProcessFunction · 0.85
CreateELFProcessFunction · 0.85
SysExecFunction · 0.85
SysOpenFunction · 0.85
SysLinkFunction · 0.85
SysChdirFunction · 0.85
SysStatFunction · 0.85
SysRmdirFunction · 0.85
SysReadLinkFunction · 0.85
FollowLinkFunction · 0.85
ResolveParentFunction · 0.85

Calls 9

kmallocFunction · 0.85
strlenFunction · 0.85
strcpyFunction · 0.85
GetRootFunction · 0.85
strtokFunction · 0.85
WarningFunction · 0.85
kfreeFunction · 0.85
FollowLinkFunction · 0.85
FindDirFunction · 0.70

Tested by

no test coverage detected