| // SPDX-License-Identifier: GPL-2.0-only |
| /* Manage a cache of file names' existence */ |
| static struct hlist_head fncache_hash[FNHSIZE]; |
| unsigned shash(const unsigned char *s) |
| static bool lookup_fncache(const char *name, bool *res) |
| int h = shash((const unsigned char *)name) % FNHSIZE; |
| hlist_for_each_entry(n, &fncache_hash[h], nd) { |
| if (!strcmp(n->name, name)) { |
| static void update_fncache(const char *name, bool res) |
| struct fncache *n = malloc(sizeof(struct fncache) + strlen(name) + 1); |
| int h = shash((const unsigned char *)name) % FNHSIZE; |
| hlist_add_head(&n->nd, &fncache_hash[h]); |
| /* No LRU, only use when bounded in some other way. */ |
| bool file_available(const char *name) |
| if (lookup_fncache(name, &res)) |
| res = access(name, R_OK) == 0; |
| update_fncache(name, res); |