MCPcopy Create free account
hub / github.com/Simple-XX/SimpleKernel / Lookup

Method Lookup

src/filesystem/vfs/mount.cpp:158–194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

156}
157
158auto MountTable::Lookup(const char* path) -> MountPoint* {
159 if (path == nullptr || path[0] != '/') {
160 return nullptr;
161 }
162
163 MountPoint* best_match = nullptr;
164 size_t best_match_len = 0;
165
166 for (size_t i = 0; i < kMaxMounts; ++i) {
167 if (!mounts_[i].active) {
168 continue;
169 }
170
171 const char* mp_path = mounts_[i].mount_path;
172 if (mp_path == nullptr) {
173 continue;
174 }
175
176 size_t mp_len = strlen(mp_path);
177
178 // 检查路径是否以挂载路径开头
179 if (strncmp(path, mp_path, mp_len) == 0) {
180 // 确保是完整匹配或下一个字符是 /,或者是根目录挂载
181 char next_char = path[mp_len];
182 if (next_char == '\0' || next_char == '/' ||
183 (mp_len == 1 && mp_path[0] == '/')) {
184 // 选择最长的匹配
185 if (mp_len > best_match_len) {
186 best_match = &mounts_[i];
187 best_match_len = mp_len;
188 }
189 }
190 }
191 }
192
193 return best_match;
194}
195
196auto MountTable::GetRootDentry(MountPoint* mp) -> Dentry* {
197 if (mp == nullptr || !mp->active) {

Callers 3

LookupFunction · 0.45
TEST_FFunction · 0.45
TEST_FFunction · 0.45

Calls 2

strlenFunction · 0.85
strncmpFunction · 0.85

Tested by 2

TEST_FFunction · 0.36
TEST_FFunction · 0.36