X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=src%2Flistfs.c;h=0aef4f99c9886af887af20c4cb4dbdbfa132239e;hb=a7740cb19a6991d21dc9395dffb87d69ee5986b5;hp=a89cd9bd350b905a52bb40b194df1f482e0ff031;hpb=a0b4caa0821b759de01361b7019c9c9c9607027d;p=libguestfs.git diff --git a/src/listfs.c b/src/listfs.c index a89cd9b..0aef4f9 100644 --- a/src/listfs.c +++ b/src/listfs.c @@ -45,12 +45,13 @@ char ** guestfs__list_filesystems (guestfs_h *g) { size_t i; - char **ret; - size_t ret_size; + char **ret = NULL; + size_t ret_size = 0; - ret = safe_malloc (g, sizeof (char *)); - ret[0] = NULL; - ret_size = 0; + char **devices = NULL; + char **partitions = NULL; + char **mds = NULL; + char **lvs = NULL; /* Look to see if any devices directly contain filesystems * (RHBZ#590167). However vfs-type will fail to tell us anything @@ -58,19 +59,12 @@ guestfs__list_filesystems (guestfs_h *g) * get the list of partitions and exclude the corresponding devices * by using part-to-dev. */ - char **devices; devices = guestfs_list_devices (g); - if (devices == NULL) { - guestfs___free_string_list (ret); - return NULL; - } - char **partitions; + if (devices == NULL) goto error; partitions = guestfs_list_partitions (g); - if (partitions == NULL) { - guestfs___free_string_list (devices); - guestfs___free_string_list (ret); - return NULL; - } + if (partitions == NULL) goto error; + mds = guestfs_list_md_devices (g); + if (mds == NULL) goto error; for (i = 0; partitions[i] != NULL; ++i) { char *dev = guestfs_part_to_dev (g, partitions[i]); @@ -82,28 +76,37 @@ guestfs__list_filesystems (guestfs_h *g) /* Use vfs-type to check for filesystems on devices. */ for (i = 0; devices[i] != NULL; ++i) check_with_vfs_type (g, devices[i], &ret, &ret_size); - guestfs___free_string_list (devices); /* Use vfs-type to check for filesystems on partitions. */ for (i = 0; partitions[i] != NULL; ++i) check_with_vfs_type (g, partitions[i], &ret, &ret_size); - guestfs___free_string_list (partitions); + + /* Use vfs-type to check for filesystems on md devices. */ + for (i = 0; mds[i] != NULL; ++i) + check_with_vfs_type (g, mds[i], &ret, &ret_size); if (guestfs___feature_available (g, "lvm2")) { /* Use vfs-type to check for filesystems on LVs. */ - char **lvs; lvs = guestfs_lvs (g); - if (lvs == NULL) { - guestfs___free_string_list (ret); - return NULL; - } + if (lvs == NULL) goto error; for (i = 0; lvs[i] != NULL; ++i) check_with_vfs_type (g, lvs[i], &ret, &ret_size); - guestfs___free_string_list (lvs); } + guestfs___free_string_list (devices); + guestfs___free_string_list (partitions); + guestfs___free_string_list (mds); + if (lvs) guestfs___free_string_list (lvs); return ret; + + error: + if (devices) guestfs___free_string_list (devices); + if (partitions) guestfs___free_string_list (partitions); + if (mds) guestfs___free_string_list (mds); + if (lvs) guestfs___free_string_list (lvs); + if (ret) guestfs___free_string_list (ret); + return NULL; } /* If 'item' occurs in 'list', remove and free it. */ @@ -139,6 +142,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