Nucleus
Barry Super block object f9d8430 (3 years, 3 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>
/* Data for find callback */
struct FindData {
ino_t ino;
Inode *result;
};
ObjectType superBlockType = {
.size = sizeof(SuperBlock),
};
/* Find an Inode by ino value */
int
compare_inode_ino(void *addr, void *data)
{
Inode *inode = addr;
struct FindData *find = data;
if (find->ino == inode->ino){
find->result = get(inode);
return 1;
}
return 0;
}
/* Allocate an Inode */
Inode *
super_alloc_inode(SuperBlock *sb)
{
if (!sb->ops || !sb->ops->alloc_inode)
return NULL;
return sb->ops->alloc_inode(sb);
}
/* Search for an Inode in a Super Block's Inode list */
Inode *
super_find_inode(SuperBlock *sb, ino_t ino)
{
Inode *inode;
struct FindData find = {
.ino = ino,
.result = NULL,
};
iterate(sb->inodes, compare_inode_ino, &find);
return find.result;
}