kv2: initialize memory manager, early pci devices
Signed-off-by: Michael Shaw <spencershawiscool@gmail.com>
This commit is contained in:
parent
e5b55a6ba5
commit
a252a3f8e9
58 changed files with 1270 additions and 505 deletions
75
fs/vfs/inode.c
Normal file
75
fs/vfs/inode.c
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#include <kernel/mem.h>
|
||||
#include <kernel/slab.h>
|
||||
|
||||
#include <fs/vfs.h>
|
||||
|
||||
#include <lib/string.h>
|
||||
|
||||
static mem_cache_t *inode_slab = NULL;
|
||||
static mem_cache_t *dirent_slab = NULL;
|
||||
|
||||
dirent_t *inode_find_dirent(inode_t *inode, char *name)
|
||||
{
|
||||
list_item_t *p = inode->dentries.head;
|
||||
|
||||
while (p) {
|
||||
dirent_t *dirent = (void *)p->ptr;
|
||||
if (!strncmp(name, dirent->name, dirent->name_len)) {
|
||||
return dirent;
|
||||
}
|
||||
p = p->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dirent_t *dirent_create(const char *name, inode_t *inode, u64 flags)
|
||||
{
|
||||
dirent_t *ret = slab_alloc(dirent_slab);
|
||||
|
||||
if (ret) {
|
||||
ret->inode = inode;
|
||||
|
||||
ret->flags = flags;
|
||||
ret->rec_len = sizeof(dirent_t);
|
||||
|
||||
ret->name_len = strlen(name);
|
||||
ret->name = kalloc(ret->name_len + 1, ALLOC_KERN);
|
||||
ret->name[ret->name_len] = 0;
|
||||
memcpy(ret->name, name, ret->name_len);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void dirent_free(dirent_t *dirent)
|
||||
{
|
||||
kfree(dirent->name);
|
||||
slab_free(dirent_slab, dirent);
|
||||
}
|
||||
|
||||
inode_t *inode_create()
|
||||
{
|
||||
inode_t *ret = slab_alloc(inode_slab);
|
||||
|
||||
if (ret)
|
||||
memset(ret, 0, sizeof(*ret));
|
||||
|
||||
rwlock_init(&ret->rwlock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void inode_free(inode_t *inode)
|
||||
{
|
||||
slab_free(inode_slab, inode);
|
||||
}
|
||||
|
||||
void inode_init()
|
||||
{
|
||||
inode_slab = slab_create("inode_slab", sizeof(inode_t), 64 * KB, 0x8);
|
||||
if(!inode_slab)panic("failed to create inode_slab\n");
|
||||
dirent_slab = slab_create("dentry_slab", sizeof(dirent_t), 64 * KB, 0x8);
|
||||
if(!dirent_slab)panic("failed to create dirent_slab\n");
|
||||
}
|
||||
Loading…
Reference in a new issue