AquilaOS documentation
How it works, and its code
Toggle main menu visibility
Loading...
Searching...
No Matches
vcache.c
Go to the documentation of this file.
1
5
6
#include <
core/system.h
>
7
#include <
fs/vcache.h
>
8
9
MALLOC_DEFINE
(M_VCACHE,
"vcache"
,
"vnode cache structure"
);
10
12
static
int
vcache_eq
(
void
*_a,
void
*_b)
13
{
14
struct
vnode
*a = (
struct
vnode
*) _a;
15
ino_t
*b = (
ino_t
*) _b;
16
17
return
a->
ino
== *b;
18
}
19
25
void
vcache_init
(
struct
vcache
*
vcache
)
26
{
27
vcache
->
hashmap
= hashmap_new(0,
vcache_eq
);
28
}
29
37
int
vcache_insert
(
struct
vcache
*
vcache
,
struct
vnode
*
vnode
)
38
{
39
if
(!
vcache
)
40
return
-EINVAL;
41
42
if
(!
vcache
->
hashmap
)
43
vcache_init
(
vcache
);
44
45
hash_t
hash = hashmap_digest(&
vnode
->
ino
,
sizeof
(
vnode
->
ino
));
46
return
hashmap_insert(
vcache
->
hashmap
, hash,
vnode
);
47
}
48
56
int
vcache_remove
(
struct
vcache
*
vcache
,
struct
vnode
*
vnode
)
57
{
58
if
(!
vcache
|| !
vcache
->
hashmap
)
59
return
-1;
60
61
hash_t
hash = hashmap_digest(&
vnode
->
ino
,
sizeof
(
ino_t
));
62
63
struct
hashmap_node
*node = hashmap_lookup(
vcache
->
hashmap
,
hash
, &
vnode
->
ino
);
64
65
if
(node) {
66
hashmap_node_remove(
vcache
->
hashmap
, node);
67
return
0;
68
}
69
70
return
-1;
71
}
72
80
struct
vnode
*
vcache_find
(
struct
vcache
*
vcache
,
ino_t
ino
)
81
{
82
if
(!
vcache
|| !
vcache
->
hashmap
)
83
return
NULL
;
84
85
hash_t
hash = hashmap_digest(&
ino
,
sizeof
(
ino
));
86
87
struct
hashmap_node
*node = hashmap_lookup(
vcache
->
hashmap
,
hash
, &ino);
88
89
if
(node) {
90
return
(
struct
vnode
*) node->
entry
;
91
}
92
93
return
NULL
;
94
}
hash_t
uintptr_t hash_t
Definition
hashmap.h:22
system.h
MALLOC_DEFINE
#define MALLOC_DEFINE(type, _name, _desc)
Definition
kvmem.h:30
NULL
#define NULL
Definition
stddef.h:27
hashmap_node
A hash table's node: an entry, with its key's hash.
Definition
hashmap.h:43
hashmap_node::hash
hash_t hash
Definition
hashmap.h:44
hashmap_node::entry
void * entry
Definition
hashmap.h:45
vcache
A filesystem's vnode cache (fs/vcache.c): its vnodes in memory, by their inode number,...
Definition
vcache.h:10
vcache::hashmap
struct hashmap * hashmap
Definition
vcache.h:11
vnode
A file in memory (a vnode): what its inode says, and the kernel's own state.
Definition
vfs.h:113
vnode::ino
ino_t ino
Definition
vfs.h:114
ino_t
uintptr_t ino_t
Definition
types.h:23
vcache_init
void vcache_init(struct vcache *vcache)
Sets up an empty vnode cache.
Definition
vcache.c:25
vcache_find
struct vnode * vcache_find(struct vcache *vcache, ino_t ino)
Finds the cached vnode of an inode.
Definition
vcache.c:80
vcache_insert
int vcache_insert(struct vcache *vcache, struct vnode *vnode)
Adds a vnode to a cache.
Definition
vcache.c:37
vcache_remove
int vcache_remove(struct vcache *vcache, struct vnode *vnode)
Takes a vnode out of a cache.
Definition
vcache.c:56
vcache_eq
static int vcache_eq(void *_a, void *_b)
Says whether a cached vnode has the inode number _b points to.
Definition
vcache.c:12
vcache.h
kernel
fs
vcache.c
Generated by
1.18.0