OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [posix/] [mm0/] [fs/] [lookup.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * Inode lookup.
3
 *
4
 * Copyright (C) 2007, 2008 Bahadir Balban
5
 */
6
#include <fs.h>
7
#include <vfs.h>
8
#include <stat.h>
9
#include <l4/api/errno.h>
10
#include <lib/pathstr.h>
11
#include <path.h>
12
 
13
/*
14
 * Given a dentry that has been populated by readdir with children dentries
15
 * and their vnodes, this itself checks all those children on that level for
16
 * a match, but it also calls lookup, which recursively checks lower levels.
17
 */
18
struct vnode *lookup_dentry_children(struct dentry *parentdir,
19
                                     struct pathdata *pdata)
20
{
21
        struct dentry *childdir;
22
        struct vnode *v;
23
        const char *component = pathdata_next_component(pdata);
24
 
25
        list_foreach_struct(childdir, &parentdir->children, child)
26
                if (IS_ERR(v = childdir->vnode->ops.lookup(childdir->vnode,
27
                                                           pdata, component)))
28
                        /* Means not found, continue search */
29
                        if ((int)v == -ENOENT)
30
                                continue;
31
                        else    /* A real error */
32
                                return v;
33
                else    /* No error, so found it */
34
                        return v;
35
 
36
        /* Out of all children dentries, neither was a match */
37
        return PTR_ERR(-ENOENT);
38
}
39
 
40
/* Lookup, recursive, assuming single-mountpoint */
41
struct vnode *generic_vnode_lookup(struct vnode *thisnode,
42
                                   struct pathdata *pdata,
43
                                   const char *component)
44
{
45
        struct dentry *d;
46
        struct vnode *found;
47
        int err;
48
 
49
        /* Does this path component match with any of this vnode's dentries? */
50
        list_foreach_struct(d, &thisnode->dentries, vref) {
51
                if (d->ops.compare(d, component)) {
52
                        /* Is this a directory? */
53
                        if (vfs_isdir(thisnode)) {
54
                                /* Are there more path components? */
55
                                if (!list_empty(&pdata->list)) {
56
                                        /* Read directory contents */
57
                                        if ((err = d->vnode->ops.readdir(d->vnode)) < 0)
58
                                                return PTR_ERR(err);
59
 
60
                                        /* Search all children one level below. */
61
                                        if ((found = lookup_dentry_children(d, pdata)))
62
                                                /* Either found, or non-zero error */
63
                                                return found;
64
                                } else
65
                                        return thisnode;
66
                        } else { /* Its a file */
67
                                if (!list_empty(&pdata->list)) /* There's still path, but not directory */
68
                                        return PTR_ERR(-ENOTDIR);
69
                                else /* No path left, found it, so return file */
70
                                        return thisnode;
71
                        }
72
                }
73
        }
74
 
75
        /* Not found, return nothing */
76
        return PTR_ERR(-ENOENT);
77
}
78
 
79
int generic_dentry_compare(struct dentry *d, const char *name)
80
{
81
        if (!strcmp(d->name, name) || !strcmp(name, VFS_STR_CURDIR))
82
                return 1;
83
        else
84
                return 0;
85
}
86
 
87
struct dentry_ops generic_dentry_operations = {
88
        .compare = generic_dentry_compare,
89
};
90
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.