dcache: add initial dcache

Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
Michael Shaw 2026-07-23 02:14:28 -04:00
commit 5ae890b3b0
3 changed files with 123 additions and 2 deletions

32
include/fs/dcache.h Normal file
View file

@ -0,0 +1,32 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef _DCACHE_H_
#define _DCACHE_H_
#include <kernel/spinlock.h>
#include <fs/vfs.h>
#include <lib/list.h>
#define DCACHE_SHIFT 10
#define DCACHE_SIZE (1 << DCACHE_SHIFT)
#define DCACHE_LOCK_SHIFT 4
#define DCACHE_NLOCKS (1 << DCACHE_LOCK_SHIFT)
struct dc_entry {
struct dc_entry *parent;
struct mount *mount;
spinlock_t lock;
list_t children;
dirent_t *dirent;
char d_name[FILE_NAME_MAX_LEN + 1];
};
extern struct dc_entry dcache[DCACHE_SIZE];
void dcache_init(void);
void dcache_insert(struct dc_entry *parent, dirent_t *dirent, const char *name);
void dcache_remove(struct dc_entry *d);
struct dc_entry *dcache_lookup(struct dc_entry *parent, const char *name);
#endif /* _DCACHE_H_ */