blob: 7d604306ac8e04bf79d682b7156d3359b4cdf82a (
plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
/* VTreeFS - path.c - name resolution */
#include "inc.h"
/*
* Resolve a path string to an inode.
*/
int
fs_lookup(ino_t dir_nr, char * name, struct fsdriver_node * node_details,
int * is_mountpt)
{
struct inode *node, *child;
int r;
if ((node = find_inode(dir_nr)) == NULL)
return EINVAL;
if (!S_ISDIR(node->i_stat.mode))
return ENOTDIR;
if (strlen(name) > NAME_MAX)
return ENAMETOOLONG;
if (!strcmp(name, ".")) {
/* Stay in the given directory. */
child = node;
} else if (!strcmp(name, "..")) {
/* Progress into the parent directory. */
if ((child = get_parent_inode(node)) == NULL)
return ENOENT; /* deleted? should not be possible */
} else {
/* Progress into a directory entry. Call the lookup hook, if
* present, before doing the actual lookup.
*/
if (!is_inode_deleted(node) &&
vtreefs_hooks->lookup_hook != NULL) {
r = vtreefs_hooks->lookup_hook(node, name,
get_inode_cbdata(node));
if (r != OK) return r;
}
if ((child = get_inode_by_name(node, name)) == NULL)
return ENOENT;
}
/* On success, open the resulting file and return its details. */
ref_inode(child);
node_details->fn_ino_nr = get_inode_number(child);
node_details->fn_mode = child->i_stat.mode;
node_details->fn_size = child->i_stat.size;
node_details->fn_uid = child->i_stat.uid;
node_details->fn_gid = child->i_stat.gid;
node_details->fn_dev = child->i_stat.dev;
*is_mountpt = FALSE;
return OK;
}
|