summaryrefslogtreecommitdiff
path: root/minix/lib/libvtreefs/extra.c
blob: 8855c75d772fd055a93c1903392a83ac16063d8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* 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];
}