fsautoproc
Basic file transformation automation management utility
|
File index mapping and serialization implementation. More...
#include "index.h"
#include <errno.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include "jemalloc/jemalloc.h"
#include "je.h"
#include "log.h"
Macros | |
#define | INDEXMAXFP 512 |
The maximum filepath length of a file in the index. | |
#define | indexbucket(hash) |
Maps and casts the hash value to a bucket index via the last N bits (where N is the number of buckets, INDEXBUCKETS). |
Functions | |
uint64_t | indexhash (const char *fp) |
Hashes the filepath string for use in the index map. | |
struct inode_s * | indexfind (const struct index_s *idx, const char *fp, const uint64_t fphash) |
Searches the index for a node with a matching filepath. | |
static int | indexnodecmp (const void *a, const void *b) |
Compares two file nodes for sorting in ascending order by filepath. | |
int | indexwrite (struct index_s *idx, FILE *s) |
Flattens the index map into a sorted array of nodes (by filepath). The list is then written to the file stream and freed. | |
int | indexread (struct index_s *idx, FILE *s) |
Reads a file stream and deserializes the contents into a map of individual file nodes. | |
static void | indexappend (struct ibucket_s *bucket, struct inode_s *node) |
Appends the node to the end of the bucket (linked list), potentially assigning a new head if the bucket is empty. | |
struct inode_s * | indexput (struct index_s *idx, const char *fp, const uint64_t fphash, const struct fsstat_s st) |
Copies the node and inserts it into the index mapping. | |
static void | indexfree_r (struct inode_s *idx) |
Recursively frees a linked list of nodes starting from a given head. | |
void | indexfree (struct index_s *idx) |
Frees all nodes in the index map. | |
struct inode_s ** | indexlist (const struct index_s *idx) |
Flattens the index map into an unsorted array of nodes. The list is dynamically allocated and must be freed by the caller. Array size is determined by the size field in the index struct. |
File index mapping and serialization implementation.
#define indexbucket | ( | hash | ) |
Maps and casts the hash value to a bucket index via the last N bits (where N is the number of buckets, INDEXBUCKETS).
#define INDEXMAXFP 512 |
The maximum filepath length of a file in the index.
Appends the node to the end of the bucket (linked list), potentially assigning a new head if the bucket is empty.
head | The head of the linked list |
node | The node pointer to insert |
Searches the index for a node with a matching filepath.
idx | The index to search |
fp | The search value (filepath) to compare |
fphash | The hash value of the filepath to compare |
void indexfree | ( | struct index_s * | idx | ) |
Frees all nodes in the index map.
idx | The index to free |
|
static |
Recursively frees a linked list of nodes starting from a given head.
idx | The head of the linked list |
uint64_t indexhash | ( | const char * | fp | ) |
Hashes the filepath string for use in the index map.
fp | The filepath string to hash |
Flattens the index map into an unsorted array of nodes. The list is dynamically allocated and must be freed by the caller. Array size is determined by the size field in the index struct.
idx | The index to flatten |
|
static |
Compares two file nodes for sorting in ascending order by filepath.
a | The first file node to compare |
b | The second file node to compare |
struct inode_s * indexput | ( | struct index_s * | idx, |
const char * | fp, | ||
uint64_t | fphash, | ||
struct fsstat_s | st ) |
Copies the node and inserts it into the index mapping.
idx | The index to insert into |
fp | The file path to use for the new node, duplicated internally |
fphash | The file path hash value to use for the new node |
st | The file stat info to use for the new node |
int indexread | ( | struct index_s * | idx, |
FILE * | s ) |
Reads a file stream and deserializes the contents into a map of individual file nodes.
idx | The index to populate |
s | The file stream to read from |
int indexwrite | ( | struct index_s * | idx, |
FILE * | s ) |
Flattens the index map into a sorted array of nodes (by filepath). The list is then written to the file stream and freed.
idx | The index to flatten |
s | The file stream to write to |