1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
| void traversal_recursive(struct dentry* node, const char* path, struct vnode** target_node, char* target_path) {
// find next /
int i = 0;
while (path[i]) {
if (path[i] == '/') break;
target_path[i] = path[i];
i++;
}
target_path[i++] = '\0';
*target_node = node->vnode;
// edge cases check
if (!strcmp(target_path, "")) {
return;
}
else if (!strcmp(target_path, ".")) {
traversal_recursive(node, path + i, target_node, target_path);
return;
}
else if (!strcmp(target_path, "..")) {
if (node->parent == NULL) { // root directory TODO: mountpoint
return;
}
traversal_recursive(node->parent, path + i, target_node, target_path);
return;
}
// find in node's child
struct list_head* p;
list_for_each(p, &node->childs) {
struct dentry* dent = list_entry(p, struct dentry, list);
if (!strcmp(dent->name, target_path)) {
if (dent->mountpoint != NULL) {
traversal_recursive(dent->mountpoint->root, path + i, target_node, target_path);
}
else if (dent->type == DIRECTORY) {
traversal_recursive(dent, path + i, target_node, target_path);
}
break;
}
}
}
|