2003-01-24 00:45:16 +03:00
|
|
|
/*
|
|
|
|
* cache.c - allocation/initialization/free routines for cache
|
|
|
|
*
|
|
|
|
* Copyright (C) 2001 Andreas Dilger
|
|
|
|
*
|
|
|
|
* %Begin-Header%
|
|
|
|
* This file may be redistributed under the terms of the
|
|
|
|
* GNU Lesser General Public License.
|
|
|
|
* %End-Header%
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2003-01-26 09:54:39 +03:00
|
|
|
#include "blkidP.h"
|
2003-01-24 00:45:16 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG_CACHE
|
|
|
|
#include <stdio.h>
|
2003-01-25 08:26:48 +03:00
|
|
|
#define DBG(x) x
|
2003-01-24 00:45:16 +03:00
|
|
|
#else
|
2003-01-25 08:26:48 +03:00
|
|
|
#define DBG(x)
|
2003-01-24 00:45:16 +03:00
|
|
|
#endif
|
|
|
|
|
2003-01-26 09:54:39 +03:00
|
|
|
blkid_cache blkid_new_cache(void)
|
2003-01-24 00:45:16 +03:00
|
|
|
{
|
2003-01-26 09:54:39 +03:00
|
|
|
blkid_cache cache;
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2003-01-26 09:54:39 +03:00
|
|
|
if (!(cache = (blkid_cache) calloc(1, sizeof(struct blkid_struct_cache))))
|
2003-01-24 00:45:16 +03:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&cache->bic_devs);
|
|
|
|
INIT_LIST_HEAD(&cache->bic_tags);
|
|
|
|
|
|
|
|
return cache;
|
|
|
|
}
|
|
|
|
|
2003-01-26 09:54:39 +03:00
|
|
|
void blkid_free_cache(blkid_cache cache)
|
2003-01-24 00:45:16 +03:00
|
|
|
{
|
|
|
|
if (!cache)
|
|
|
|
return;
|
|
|
|
|
2003-01-25 08:26:48 +03:00
|
|
|
DBG(printf("freeing cache struct\n"));
|
2003-01-24 00:45:16 +03:00
|
|
|
/* DEB_DUMP_CACHE(cache); */
|
|
|
|
|
|
|
|
while (!list_empty(&cache->bic_devs)) {
|
2003-01-26 09:54:39 +03:00
|
|
|
blkid_dev dev = list_entry(cache->bic_devs.next,
|
|
|
|
struct blkid_struct_dev,
|
2003-01-24 00:45:16 +03:00
|
|
|
bid_devs);
|
|
|
|
blkid_free_dev(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!list_empty(&cache->bic_tags)) {
|
2003-01-26 09:54:39 +03:00
|
|
|
blkid_tag tag = list_entry(cache->bic_tags.next,
|
|
|
|
struct blkid_struct_tag,
|
|
|
|
bit_tags);
|
2003-01-24 00:45:16 +03:00
|
|
|
|
|
|
|
while (!list_empty(&tag->bit_names)) {
|
2003-01-26 09:54:39 +03:00
|
|
|
blkid_tag bad = list_entry(tag->bit_names.next,
|
|
|
|
struct blkid_struct_tag,
|
|
|
|
bit_names);
|
2003-01-24 00:45:16 +03:00
|
|
|
|
2003-01-25 08:26:48 +03:00
|
|
|
DBG(printf("warning: unfreed tag %s=%s\n",
|
|
|
|
bad->bit_name, bad->bit_val));
|
2003-01-24 00:45:16 +03:00
|
|
|
blkid_free_tag(bad);
|
|
|
|
}
|
|
|
|
blkid_free_tag(tag);
|
|
|
|
}
|
|
|
|
free(cache);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TEST_PROGRAM
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2003-01-26 09:54:39 +03:00
|
|
|
blkid_cache cache = NULL;
|
2003-01-24 00:45:16 +03:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if ((argc > 2)) {
|
|
|
|
fprintf(stderr, "Usage: %s [filename] \n", argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ret = blkid_read_cache(&cache, argv[1])) < 0)
|
|
|
|
fprintf(stderr, "error %d parsing cache file %s\n", ret,
|
|
|
|
argv[1] ? argv[1] : BLKID_CACHE_FILE);
|
|
|
|
else if ((ret = blkid_probe_all(&cache) < 0))
|
|
|
|
fprintf(stderr, "error probing devices\n");
|
|
|
|
else if ((ret = blkid_save_cache(cache, argv[1])) < 0)
|
|
|
|
fprintf(stderr, "error %d saving cache to %s\n", ret,
|
|
|
|
argv[1] ? argv[1] : BLKID_CACHE_FILE);
|
|
|
|
|
|
|
|
blkid_free_cache(cache);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|