fs: add ramfs
This commit is contained in:
parent
a7c526d2a6
commit
750ffa2e16
13 changed files with 355 additions and 55 deletions
|
|
@ -9,35 +9,35 @@
|
|||
static mem_cache_t *inode_slab = NULL;
|
||||
static mem_cache_t *dirent_slab = NULL;
|
||||
|
||||
dirent_t *inode_find_dirent(inode_t *inode, char *name)
|
||||
dirent_t *inode_find_dirent(inode_t *inode, const 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)) {
|
||||
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 *dirent_create(const char *name)
|
||||
{
|
||||
dirent_t *ret = slab_alloc(dirent_slab);
|
||||
|
||||
if (ret) {
|
||||
ret->inode = inode;
|
||||
if (!ret)
|
||||
return NULL;
|
||||
|
||||
ret->flags = flags;
|
||||
ret->rec_len = sizeof(dirent_t);
|
||||
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);
|
||||
ret->name_len = strlen(name);
|
||||
ret->name = strdup(name);
|
||||
|
||||
if (!ret->name) {
|
||||
slab_free(dirent_slab, ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
@ -69,7 +69,9 @@ void inode_free(inode_t *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");
|
||||
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");
|
||||
if (!dirent_slab)
|
||||
panic("failed to create dirent_slab\n");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue