]> err.no Git - util-linux/commitdiff
libblkid: don't return empty LABELs
authorKarel Zak <kzak@redhat.com>
Tue, 10 Nov 2009 13:00:13 +0000 (14:00 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 10 Nov 2009 13:00:13 +0000 (14:00 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
shlibs/blkid/src/blkidP.h
shlibs/blkid/src/probe.c
shlibs/blkid/src/superblocks/superblocks.c

index 6e9c21e8efd41f7a03fa9cd95141f2c68a3e49db..90900e27ef543d78fcf1dcf55a7df7a5432e24d6 100644 (file)
@@ -379,6 +379,7 @@ extern void blkid_probe_chain_reset_vals(blkid_probe pr, struct blkid_chain *chn
 extern int blkid_probe_chain_copy_vals(blkid_probe pr, struct blkid_chain *chn,
                                        struct blkid_prval *vals, int nvals);
 extern struct blkid_prval *blkid_probe_assign_value(blkid_probe pr, const char *name);
+extern int blkid_probe_reset_last_value(blkid_probe pr);
 extern void blkid_probe_append_vals(blkid_probe pr, struct blkid_prval *vals, int nvals);
 
 extern struct blkid_chain *blkid_probe_get_chain(blkid_probe pr);
index f8610cb61131878bd41eed16708024e56241eb1d..0324351ab9b30106846a8c3810860be7760aca79 100644 (file)
@@ -848,6 +848,25 @@ struct blkid_prval *blkid_probe_assign_value(
        return v;
 }
 
+int blkid_probe_reset_last_value(blkid_probe pr)
+{
+       struct blkid_prval *v;
+
+       if (pr == NULL || pr->nvals == 0)
+               return -1;
+
+       v = &pr->vals[pr->nvals - 1];
+
+       DBG(DEBUG_LOWPROBE,
+               printf("un-assigning %s [%s]\n", v->name, v->chain->driver->name));
+
+       memset(v, 0, sizeof(struct blkid_prval));
+       pr->nvals--;
+
+       return 0;
+
+}
+
 int blkid_probe_set_value(blkid_probe pr, const char *name,
                unsigned char *data, size_t len)
 {
@@ -878,7 +897,7 @@ int blkid_probe_vsprintf_value(blkid_probe pr, const char *name,
        len = vsnprintf((char *) v->data, sizeof(v->data), fmt, ap);
 
        if (len <= 0) {
-               pr->nvals--; /* reset the latest assigned value */
+               blkid_probe_reset_last_value(pr);
                return -1;
        }
        v->len = len + 1;
index 6fb2be3a705a18ab787c38f37fefc384d6216072..f625f271bcb6b74b2c306ba9fc59cdf45d91b791 100644 (file)
@@ -501,6 +501,8 @@ int blkid_probe_set_label(blkid_probe pr, unsigned char *label, size_t len)
        v->data[len] = '\0';
 
        v->len = blkid_rtrim_whitespace(v->data) + 1;
+       if (v->len == 1)
+               blkid_probe_reset_last_value(pr);
        return 0;
 }
 
@@ -521,6 +523,8 @@ int blkid_probe_set_utf8label(blkid_probe pr, unsigned char *label,
 
        blkid_encode_to_utf8(enc, v->data, sizeof(v->data), label, len);
        v->len = blkid_rtrim_whitespace(v->data) + 1;
+       if (v->len == 1)
+               blkid_probe_reset_last_value(pr);
        return 0;
 }