minix/minix/lib/libvtreefs/extra.c
Cristiano Giuffrida 5a7def9a94 libvtreefs: fix naming bug
Change-Id: Ib8767cfef4206ed491855bace6dd8bd58b45b8ce
2015-06-29 10:56:59 +00:00

57 lines
1.1 KiB
C

/* VTreeFS - extra.c - per-inode storage of arbitrary extra data */
#include "inc.h"
/*
* Right now, we maintain the extra data (if requested) as a separate buffer,
* so that we don't have to make the inode structure variable in size. Later,
* if for example the maximum node name length becomes a runtime setting, we
* could reconsider this.
*/
static char *extra_ptr = NULL;
static size_t extra_size = 0; /* per inode */
/*
* Initialize memory to store extra data.
*/
int
init_extra(unsigned int nr_inodes, size_t inode_extra)
{
if (inode_extra == 0)
return OK;
if ((extra_ptr = calloc(nr_inodes, inode_extra)) == NULL)
return ENOMEM;
extra_size = inode_extra;
return OK;
}
/*
* Initialize the extra data for the given inode to zero.
*/
void
clear_inode_extra(struct inode * node)
{
if (extra_size == 0)
return;
memset(&extra_ptr[node->i_num * extra_size], 0, extra_size);
}
/*
* Retrieve a pointer to the extra data for the given inode.
*/
void *
get_inode_extra(const struct inode * node)
{
if (extra_size == 0)
return NULL;
return (void *)&extra_ptr[node->i_num * extra_size];
}