}
}
+static struct blkid_hint *get_hint(blkid_probe pr, const char *name)
+{
+ struct list_head *p;
+
+ if (list_empty(&pr->hints))
+ return NULL;
+
+ list_for_each(p, &pr->hints) {
+ struct blkid_hint *h = list_entry(p, struct blkid_hint, hints);
+
+ if (h->name && strcmp(name, h->name) == 0)
+ return h;
+ }
+ return NULL;
+}
+
/**
* blkid_probe_set_hint:
* @pr: probe
if (errno || v == end || (end && *end))
goto done;
+ }
+
+ hint = get_hint(pr, n ? n : name);
+ if (hint) {
+ /* alter old hint */
+ hint->value = value;
+ DBG(LOWPROBE,
+ ul_debug("updated hint '%s' to %"PRIu64"", hint->name, hint->value));
} else {
- n = strdup(name);
- if (!n)
+ /* add a new hint */
+ if (!n) {
+ n = strdup(name);
+ if (!n)
+ goto done;
+ }
+ hint = malloc(sizeof(*hint));
+ if (!hint)
goto done;
- }
- /* allocate info and space for data by one malloc call */
- hint = malloc(sizeof(*hint));
- if (!hint)
- goto done;
+ hint->name = n;
+ hint->value = value;
- INIT_LIST_HEAD(&hint->hints);
- hint->name = n;
- hint->value = value;
- n = NULL;
- list_add_tail(&hint->hints, &pr->hints);
+ INIT_LIST_HEAD(&hint->hints);
+ list_add_tail(&hint->hints, &pr->hints);
- DBG(LOWPROBE,
- ul_debug("new hint '%s' is %"PRIu64"", hint->name, hint->value));
+ DBG(LOWPROBE,
+ ul_debug("new hint '%s' is %"PRIu64"", hint->name, hint->value));
+ n = NULL;
+ }
done:
free(n);
free(v);
+
if (!hint)
return errno ? -errno : -EINVAL;
return 0;
int blkid_probe_get_hint(blkid_probe pr, const char *name, uint64_t *value)
{
- struct list_head *p;
+ struct blkid_hint *h = get_hint(pr, name);
- if (list_empty(&pr->hints))
+ if (!h)
return -EINVAL;
-
- list_for_each(p, &pr->hints) {
- struct blkid_hint *h = list_entry(p, struct blkid_hint, hints);
-
- if (h->name && strcmp(name, h->name) == 0) {
- if (value)
- *value = h->value;
- return 0;
- }
- }
- return -EINVAL;
+ if (value)
+ *value = h->value;
+ return 0;
}
/**