Remove building with NOCRYPTO option
[minix3.git] / minix / lib / libvtreefs / extra.c
blob8855c75d772fd055a93c1903392a83ac16063d8c
1 /* VTreeFS - extra.c - per-inode storage of arbitrary extra data */
3 #include "inc.h"
5 /*
6 * Right now, we maintain the extra data (if requested) as a separate buffer,
7 * so that we don't have to make the inode structure variable in size. Later,
8 * if for example the maximum node name length becomes a runtime setting, we
9 * could reconsider this.
11 static char *extra_ptr = NULL;
12 static size_t extra_size = 0; /* per inode */
15 * Initialize memory to store extra data.
17 int
18 init_extra(unsigned int nr_inodes, size_t inode_extra)
21 if (inode_extra == 0)
22 return OK;
24 if ((extra_ptr = calloc(nr_inodes, inode_extra)) == NULL)
25 return ENOMEM;
27 extra_size = inode_extra;
29 return OK;
33 * Initialize the extra data for the given inode to zero.
35 void
36 clear_inode_extra(struct inode * node)
39 if (extra_size == 0)
40 return;
42 memset(&extra_ptr[node->i_num * extra_size], 0, extra_size);
46 * Retrieve a pointer to the extra data for the given inode.
48 void *
49 get_inode_extra(const struct inode * node)
52 if (extra_size == 0)
53 return NULL;
55 return (void *)&extra_ptr[node->i_num * extra_size];