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

Subversion Repositories c0or1k

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * High-level vfs implementation.
3
 *
4
 * Copyright (C) 2008 Bahadir Balban
5
 */
6
#include <fs.h>
7
#include <vfs.h>
8
#include <task.h>
9
#include <path.h>
10
 
11
LINK_DECLARE(vnode_cache);
12
LINK_DECLARE(dentry_cache);
13
 
14
struct vfs_mountpoint vfs_root;
15
struct id_pool *vfs_fsidx_pool;
16
 
17
/*
18
 * Vnodes in the vnode cache have 2 keys. One is their dentry names, the other
19
 * is their vnum. This one checks the vnode cache by the given vnum first.
20
 * If nothing is found, it reads the vnode from disk into cache. This is called
21
 * by system calls since tasks keep an fd-to-vnum table.
22
 */
23
struct vnode *vfs_vnode_lookup_byvnum(struct superblock *sb, unsigned long vnum)
24
{
25
        struct vnode *v;
26
        int err;
27
 
28
        /* Check the vnode flat list by vnum */
29
        list_foreach_struct(v, &vnode_cache, cache_list)
30
                if (v->vnum == vnum)
31
                        return v;
32
 
33
        /* Check the actual filesystem for the vnode */
34
        v = vfs_alloc_vnode();
35
        v->vnum = vnum;
36
 
37
        /* Note this only checks given superblock */
38
        if ((err = sb->ops->read_vnode(sb, v)) < 0) {
39
                vfs_free_vnode(v);
40
                return PTR_ERR(err);
41
        }
42
 
43
        /* Add the vnode back to vnode flat list */
44
        list_insert(&v->cache_list, &vnode_cache);
45
 
46
        return v;
47
}
48
 
49
/*
50
 * Vnodes in the vnode cache have 2 keys. One is the set of dentry names they
51
 * have, the other is their vnum. This one checks the vnode cache by the path
52
 * first. If nothing is found, it reads the vnode from disk into the cache.
53
 */
54
struct vnode *vfs_vnode_lookup_bypath(struct pathdata *pdata)
55
{
56
        const char *firstcomp;
57
 
58
        /*
59
         * This does vfs cache + fs lookup.
60
         */
61
        BUG_ON(list_empty(&pdata->list));
62
        firstcomp = pathdata_next_component(pdata);
63
        return pdata->vstart->ops.lookup(pdata->vstart, pdata, firstcomp);
64
}
65
 
66
int vfs_mount_root(struct superblock *sb)
67
{
68
        /*
69
         * Lookup the root vnode of this superblock.
70
         * The root superblock has vnode number 0.
71
         */
72
        vfs_root.pivot = vfs_vnode_lookup_byvnum(sb, sb->fsidx | 0);
73
        vfs_root.sb = sb;
74
 
75
        return 0;
76
}
77
 

powered by: WebSVN 2.1.0

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