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 #define HASH_SIZE 311 /* Should be prime */
17 #define hash_inode(i) ((i) % HASH_SIZE)
19 typedef struct ino_dev_hash_bucket_struct {
20 struct ino_dev_hash_bucket_struct *next;
24 } ino_dev_hashtable_bucket_t;
26 static ino_dev_hashtable_bucket_t *ino_dev_hashtable[HASH_SIZE];
29 * Return 1 if statbuf->st_ino && statbuf->st_dev are recorded in
30 * `ino_dev_hashtable', else return 0
32 * If NAME is a non-NULL pointer to a character pointer, and there is
33 * a match, then set *NAME to the value of the name slot in that
36 int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name)
38 ino_dev_hashtable_bucket_t *bucket;
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))
45 if (name) *name = bucket->name;
48 bucket = bucket->next;
53 /* Add statbuf to statbuf hash table */
54 void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name)
58 ino_dev_hashtable_bucket_t *bucket;
60 i = hash_inode(statbuf->st_ino);
61 s = name ? strlen(name) : 0;
62 bucket = xmalloc(sizeof(ino_dev_hashtable_bucket_t) + s);
63 bucket->ino = statbuf->st_ino;
64 bucket->dev = statbuf->st_dev;
66 strcpy(bucket->name, name);
68 bucket->name[0] = '\0';
69 bucket->next = ino_dev_hashtable[i];
70 ino_dev_hashtable[i] = bucket;
73 #ifdef CONFIG_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;