AquilaOS documentation
How it works, and its code
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
9MALLOC_DEFINE(M_VCACHE, "vcache", "vnode cache structure");
10
12static 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
26{
27 vcache->hashmap = hashmap_new(0, vcache_eq);
28}
29
37int vcache_insert(struct vcache *vcache, struct vnode *vnode)
38{
39 if (!vcache)
40 return -EINVAL;
41
42 if (!vcache->hashmap)
44
45 hash_t hash = hashmap_digest(&vnode->ino, sizeof(vnode->ino));
46 return hashmap_insert(vcache->hashmap, hash, vnode);
47}
48
56int 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
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}
uintptr_t hash_t
Definition hashmap.h:22
#define MALLOC_DEFINE(type, _name, _desc)
Definition kvmem.h:30
#define NULL
Definition stddef.h:27
A hash table's node: an entry, with its key's hash.
Definition hashmap.h:43
hash_t hash
Definition hashmap.h:44
void * entry
Definition hashmap.h:45
A filesystem's vnode cache (fs/vcache.c): its vnodes in memory, by their inode number,...
Definition vcache.h:10
struct hashmap * hashmap
Definition vcache.h:11
A file in memory (a vnode): what its inode says, and the kernel's own state.
Definition vfs.h:113
ino_t ino
Definition vfs.h:114
uintptr_t ino_t
Definition types.h:23
void vcache_init(struct vcache *vcache)
Sets up an empty vnode cache.
Definition vcache.c:25
struct vnode * vcache_find(struct vcache *vcache, ino_t ino)
Finds the cached vnode of an inode.
Definition vcache.c:80
int vcache_insert(struct vcache *vcache, struct vnode *vnode)
Adds a vnode to a cache.
Definition vcache.c:37
int vcache_remove(struct vcache *vcache, struct vnode *vnode)
Takes a vnode out of a cache.
Definition vcache.c:56
static int vcache_eq(void *_a, void *_b)
Says whether a cached vnode has the inode number _b points to.
Definition vcache.c:12