From fbfc1768a878044720cd5f03dc6e308dbdc70595 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Wed, 20 Jul 2011 14:25:32 +0100 Subject: [PATCH] blkid: Detect when value not found and return empty string. If the blkid command returns 2, that means the value was not found. Note that this changes the output of the vfs-type API when the filesystem has no type (eg when it is empty). Previously this would return an error. Now it returns empty string "". We did not document this either way. Making it return empty string is consistent with vfs-label and vfs-uuid. This change broke list-filesystems, since that code was assuming that vfs-type could only return a filesystem type or an error. (cherry picked from commit 168fd4ad5d1e5da93e11388095d41aaa8f804ceb) --- daemon/blkid.c | 19 +++++++++++++++---- src/listfs.c | 4 ++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/daemon/blkid.c b/daemon/blkid.c index 2885a8f..f631061 100644 --- a/daemon/blkid.c +++ b/daemon/blkid.c @@ -41,10 +41,13 @@ get_blkid_tag (const char *device, const char *tag) unlink ("/etc/blkid/blkid.tab"); /* Red Hat, Fedora */ unlink ("/etc/blkid.tab"); /* Debian */ - r = command (&out, &err, - "blkid", "-o", "value", "-s", tag, device, NULL); - if (r == -1) { - reply_with_error ("%s: %s", device, err); + r = commandr (&out, &err, + "blkid", "-o", "value", "-s", tag, device, NULL); + if (r != 0 && r != 2) { + if (r >= 0) + reply_with_error ("%s: %s (blkid returned %d)", device, err, r); + else + reply_with_error ("%s: %s", device, err); free (out); free (err); return NULL; @@ -52,6 +55,14 @@ get_blkid_tag (const char *device, const char *tag) free (err); + if (r == 2) { /* means UUID etc not found */ + free (out); + out = strdup (""); + if (out == NULL) + reply_with_perror ("strdup"); + return out; + } + /* Trim trailing \n if present. */ size_t len = strlen (out); if (len > 0 && out[len-1] == '\n') diff --git a/src/listfs.c b/src/listfs.c index a89cd9b..42bbaef 100644 --- a/src/listfs.c +++ b/src/listfs.c @@ -139,6 +139,10 @@ check_with_vfs_type (guestfs_h *g, const char *device, if (!vfs_type) v = safe_strdup (g, "unknown"); + else if (STREQ (vfs_type, "")) { + free (vfs_type); + v = safe_strdup (g, "unknown"); + } else { /* Ignore all "*_member" strings. In libblkid these are returned * for things which are members of some RAID or LVM set, most -- 1.8.3.1