1 /* vi: set sw=4 ts=4: */
5 * Copyright (C) many different people.
6 * If you wrote this, please acknowledge your work.
8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
16 typedef struct ino_dev_hash_bucket_struct {
17 struct ino_dev_hash_bucket_struct *next;
21 } ino_dev_hashtable_bucket_t;
23 #define HASH_SIZE 311 /* Should be prime */
24 #define hash_inode(i) ((i) % HASH_SIZE)
26 /* array of [HASH_SIZE] elements */
27 static ino_dev_hashtable_bucket_t **ino_dev_hashtable;
30 * Return name if statbuf->st_ino && statbuf->st_dev are recorded in
31 * ino_dev_hashtable, else return NULL
33 char *is_in_ino_dev_hashtable(const struct stat *statbuf)
35 ino_dev_hashtable_bucket_t *bucket;
37 if (!ino_dev_hashtable)
40 bucket = ino_dev_hashtable[hash_inode(statbuf->st_ino)];
41 while (bucket != NULL) {
42 if ((bucket->ino == statbuf->st_ino)
43 && (bucket->dev == statbuf->st_dev)
47 bucket = bucket->next;
52 /* Add statbuf to statbuf hash table */
53 void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name)
56 ino_dev_hashtable_bucket_t *bucket;
58 i = hash_inode(statbuf->st_ino);
61 bucket = xmalloc(sizeof(ino_dev_hashtable_bucket_t) + strlen(name));
62 bucket->ino = statbuf->st_ino;
63 bucket->dev = statbuf->st_dev;
64 strcpy(bucket->name, name);
66 if (!ino_dev_hashtable)
67 ino_dev_hashtable = xzalloc(HASH_SIZE * sizeof(*ino_dev_hashtable));
69 bucket->next = ino_dev_hashtable[i];
70 ino_dev_hashtable[i] = bucket;
73 #if ENABLE_FEATURE_CLEAN_UP
74 /* Clear statbuf hash table */
75 void reset_ino_dev_hashtable(void)
78 ino_dev_hashtable_bucket_t *bucket;
80 for (i = 0; i < HASH_SIZE; i++) {
81 while (ino_dev_hashtable[i] != NULL) {
82 bucket = ino_dev_hashtable[i]->next;
83 free(ino_dev_hashtable[i]);
84 ino_dev_hashtable[i] = bucket;
87 free(ino_dev_hashtable);
88 ino_dev_hashtable = NULL;