From 409b115da09744974144abc381dc4446096e7900 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 9 Sep 2008 00:49:01 +0200 Subject: [PATCH] blkid: optimize for string UUIDs Signed-off-by: Karel Zak --- libs/blkid/src/probe.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/libs/blkid/src/probe.c b/libs/blkid/src/probe.c index 247ce584..370ec4c6 100644 --- a/libs/blkid/src/probe.c +++ b/libs/blkid/src/probe.c @@ -484,6 +484,9 @@ int blkid_probe_set_label(blkid_probe pr, unsigned char *label, size_t len) struct blkid_prval *v; int i; + if (len > BLKID_PROBVAL_BUFSIZ) + len = BLKID_PROBVAL_BUFSIZ; + if ((pr->probreq & BLKID_PROBREQ_LABELRAW) && blkid_probe_set_value(pr, "LABEL_RAW", label, len) < 0) return -1; @@ -575,8 +578,11 @@ static int uuid_is_empty(const unsigned char *buf, size_t len) int blkid_probe_sprintf_uuid(blkid_probe pr, unsigned char *uuid, size_t len, const char *fmt, ...) { + int rc = -1; va_list ap; - int rc; + + if (len > BLKID_PROBVAL_BUFSIZ) + len = BLKID_PROBVAL_BUFSIZ; if (uuid_is_empty(uuid, len)) return 0; @@ -588,7 +594,22 @@ int blkid_probe_sprintf_uuid(blkid_probe pr, unsigned char *uuid, return 0; va_start(ap, fmt); - rc = blkid_probe_vsprintf_value(pr, "UUID", fmt, ap); + + if (!strcmp(fmt, "%s")) { + struct blkid_prval *v = NULL; + const char *str = va_arg(ap, char *); + + if (str && *str) + v = blkid_probe_assign_value(pr, "UUID"); + if (v) { + memcpy(v->data, str, len); + v->data[len] = '\0'; + v->len = len; + rc = 0; + } + } else + rc = blkid_probe_vsprintf_value(pr, "UUID", fmt, ap); + va_end(ap); /* convert to lower case (..be paranoid) */ -- 2.39.5