/* cache */
extern char *blkid_safe_getenv(const char *arg);
+extern char *blkid_get_cache_filename(struct blkid_config *conf);
/*
* Functions to create and find a specific tag type: tag.c
}
#endif
+/* returns allocated path to cache */
+char *blkid_get_cache_filename(struct blkid_config *conf)
+{
+ char *filename;
+
+ filename = blkid_safe_getenv("BLKID_FILE");
+ if (filename)
+ filename = blkid_strdup(filename);
+ else if (conf)
+ filename = blkid_strdup(conf->cachefile);
+ else {
+ struct blkid_config *c = blkid_read_config(NULL);
+ if (!c)
+ return -BLKID_ERR_PARAM;
+ filename = c->cachefile; /* already allocated */
+ c->cachefile = NULL;
+ blkid_free_config(c);
+ }
+ return filename;
+}
+
int blkid_get_cache(blkid_cache *ret_cache, const char *filename)
{
blkid_cache cache;
if (filename && !*filename)
filename = NULL;
- if (!filename)
- filename = blkid_safe_getenv("BLKID_FILE");
if (filename)
cache->bic_filename = blkid_strdup(filename);
- else {
- struct blkid_config *conf = blkid_read_config(NULL);
- if (!conf)
- return -BLKID_ERR_PARAM;
- cache->bic_filename = conf->cachefile;
- conf->cachefile = NULL;
- blkid_free_config(conf);
- }
+ else
+ cache->bic_filename = blkid_get_cache_filename(NULL);
blkid_read_cache(cache);
-
*ret_cache = cache;
return 0;
}
}
static char *evaluate_by_scan(const char *token, const char *value,
- blkid_cache *cache, const char *cachefile)
+ blkid_cache *cache, struct blkid_config *conf)
{
blkid_cache c = cache ? *cache : NULL;
char *res;
DBG(DEBUG_EVALUATE,
printf("evaluating by blkid scan %s=%s\n", token, value));
- if (!c)
+ if (!c) {
+ char *cachefile = blkid_get_cache_filename(conf);
blkid_get_cache(&c, cachefile);
+ free(cachefile);
+ }
if (!c)
return NULL;
if (conf->eval[i] == BLKID_EVAL_UDEV)
ret = evaluate_by_udev(token, value, conf->uevent);
else if (conf->eval[i] == BLKID_EVAL_SCAN)
- ret = evaluate_by_scan(token, value, cache, conf->cachefile);
+ ret = evaluate_by_scan(token, value, cache, conf);
if (ret)
break;
}