|
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 | indexbucket(hash) ((int) (hash & INDEXBUCKETSMASK)) |
Maps and casts the hash value to a bucket index via the last N bits (where N is the number of buckets, INDEXBUCKETS). | |
| #define | INDEXWRITEFMT "%s,%" PRIu64 ",%" PRIu64 ",%" PRIu64 "\n" |
| Format string used for writing index entries to a file stream. | |
Typedefs | |
| typedef int(* | indexwriter_fn) (void *ctx, const char *buf, int len) |
| Function pointer type for writing a buffer to a stream. | |
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. | |
| static int | indexwriter_file (void *ctx, const char *buf, const int len) |
| static int | indexwriter_gz (void *ctx, const char *buf, const int len) |
| static int | indexwrite_impl (struct index_s *idx, void *ctx, indexwriter_fn wfn) |
| Flattens the index map into a sorted array of nodes (by filepath). The list is then written to the stream context and freed. | |
| 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 | indexwrite_gz (struct index_s *idx, gzFile gz) |
| Flattens the index map into a sorted array of nodes (by filepath). The list is then written to the gzip stream and freed. | |
| int | indexread (struct index_s *idx, gzFile gz) |
| Reads a gzip file stream and deserializes the contents into a map of individual file nodes. Transparently handles both compressed and uncompressed input. | |
| 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, const uint64_t xx) |
| 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. | |
Variables | |
| static char | indexfpbuf [1024] |
| Filepath buffer for index I/O operations. | |
File index mapping and serialization implementation.
| #define indexbucket | ( | hash | ) | ((int) (hash & INDEXBUCKETSMASK)) |
Maps and casts the hash value to a bucket index via the last N bits (where N is the number of buckets, INDEXBUCKETS).
| #define INDEXWRITEFMT "%s,%" PRIu64 ",%" PRIu64 ",%" PRIu64 "\n" |
Format string used for writing index entries to a file stream.
| typedef int(* indexwriter_fn) (void *ctx, const char *buf, int len) |
Function pointer type for writing a buffer to a stream.
| ctx | The stream context (FILE* or gzFile) |
| buf | The buffer to write |
| len | The length of the buffer |
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 |
idx->size is returned. Otherwise, NULL is returned and errno is set. 
|
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 |
strcmp(a->fp, b->fp). 
| struct inode_s * indexput | ( | struct index_s * | idx, |
| const char * | fp, | ||
| uint64_t | fphash, | ||
| const struct fsstat_s * | st, | ||
| uint64_t | xx | ||
| ) |
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 |
| xx | The xxHash64 hash value to use for the new node |
errno is set. 

| int indexread | ( | struct index_s * | idx, |
| gzFile | gz | ||
| ) |
Reads a gzip file stream and deserializes the contents into a map of individual file nodes. Transparently handles both compressed and uncompressed input.
| idx | The index to populate |
| gz | The gzip file stream to read from |
errno is set. 

| 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 |
errno is set. 

| int indexwrite_gz | ( | struct index_s * | idx, |
| gzFile | gz | ||
| ) |
Flattens the index map into a sorted array of nodes (by filepath). The list is then written to the gzip stream and freed.
| idx | The index to flatten |
| gz | The gzip file stream to write to |
errno is set. 

|
static |
Flattens the index map into a sorted array of nodes (by filepath). The list is then written to the stream context and freed.
| idx | The index to flatten |
| ctx | The stream context (FILE* or gzFile) |
| wfn | The writer function to use for output |


|
static |

|
static |

|
static |
Filepath buffer for index I/O operations.