blkid_tag_iterate tag_iter;
blkid_dev dev;
blkid_cache cache = NULL;
- const char *type, *value;
+ const char *type, *value, *fstype = NULL;
int ret;
ret = blkid_get_cache(&cache, NULL);
dev = blkid_get_dev(cache, devname, 0);
if (!dev)
- return NULL;
+ goto err_put_cache;
dev = blkid_verify(cache, dev);
if (!dev)
- return NULL;
+ goto err_put_cache;
tag_iter = blkid_tag_iterate_begin(dev);
while (blkid_tag_next(tag_iter, &type, &value) == 0) {
if (!strncmp(type, "TYPE", 4)) {
- char *fstype = strdup(value);
-
+ fstype = strdup(value);
if (!fstype)
- return NULL;
+ fprintf(stderr, "failed to duplicate fs type string\n");
- blkid_tag_iterate_end(tag_iter);
- blkid_put_cache(cache);
- return fstype;
+ break;
}
}
+
blkid_tag_iterate_end(tag_iter);
+
+err_put_cache:
blkid_put_cache(cache);
- return NULL;
+ return fstype;
}
static int mount_dev(const char *dev)