| 156 | } |
| 157 | |
| 158 | auto 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 | |
| 196 | auto MountTable::GetRootDentry(MountPoint* mp) -> Dentry* { |
| 197 | if (mp == nullptr || !mp->active) { |