Nucleus
Barry Ordered object lists 74ee43c (3 years, 2 months ago)
/*
* This file implements the Super Block object and associated functions. Most
* of the functions here are just wrappers for the Super Block Operations that
* get specified by the individual file systems, since most of them need to know
* driver-specific values. There usually isn't a generic way to handle these
* operations.
*/
#include <sys/types.h>
#include <nucleus/vfs.h>
static void super_block_new(Object *);
static void super_block_delete(Object *);
/* Super Block object type */
ObjectType superBlockType = {
.name = "SUPER BLOCK",
.size = sizeof(SuperBlock),
.new = super_block_new,
.delete = super_block_delete,
};
/* Create a new SuperBlock object */
static void
super_block_new(Object *obj)
{
SuperBlock *sb = (void *) obj;
sb->inodes = create_list(&inodeType, LIST_NORMAL);
}
/* Destroy SuperBlock object */
static void
super_block_delete(Object *obj)
{
SuperBlock *sb = (void *) obj;
destroy_list(sb->inodes);
}
/* Allocate an Inode */
Inode *
super_alloc_inode(SuperBlock *sb)
{
if (!sb->ops || !sb->ops->alloc_inode)
return NULL;
Inode *inode = sb->ops->alloc_inode(sb);
inode->super = get(sb);
add(sb->inodes, inode);
return inode;
}
/* Search for an Inode in a Super Block's Inode list */
Inode *
super_find_inode(SuperBlock *sb, ino_t ino)
{
Inode *inode;
foreach (sb->inodes, inode) {
if (inode->ino == ino)
break;
}
return inode;
}