Skip to content

Commit

Permalink
list-filesystems: Ignore MBR type 0x42 (Windows dynamic disks) (RHBZ#…
Browse files Browse the repository at this point in the history
…887520).
  • Loading branch information
rwmjones committed Dec 17, 2012
1 parent 6f02e33 commit eab324b
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions src/listfs.c
Expand Up @@ -40,6 +40,7 @@

static void remove_from_list (char **list, const char *item);
static void check_with_vfs_type (guestfs_h *g, const char *dev, char ***ret, size_t *ret_size);
static int is_mbr_partition_type_42 (guestfs_h *g, const char *partition);

char **
guestfs__list_filesystems (guestfs_h *g)
Expand Down Expand Up @@ -80,8 +81,10 @@ guestfs__list_filesystems (guestfs_h *g)
check_with_vfs_type (g, devices[i], &ret, &ret_size);

/* 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);
for (i = 0; partitions[i] != NULL; ++i) {
if (! is_mbr_partition_type_42 (g, partitions[i]))
check_with_vfs_type (g, partitions[i], &ret, &ret_size);
}

/* Use vfs-type to check for filesystems on md devices. */
for (i = 0; mds[i] != NULL; ++i)
Expand Down Expand Up @@ -195,3 +198,37 @@ check_with_vfs_type (guestfs_h *g, const char *device,
(*ret)[i+1] = v;
(*ret)[i+2] = NULL;
}

/* We should ignore partitions that have MBR type byte 0x42, because
* these are members of a Windows dynamic disk group. Trying to read
* them will cause errors (RHBZ#887520). Assuming that libguestfs was
* compiled with ldm support, we'll get the filesystems on these later.
*/
static int
is_mbr_partition_type_42 (guestfs_h *g, const char *partition)
{
char *device = NULL;
int partnum;
int mbr_id;
int ret = 0;

guestfs_push_error_handler (g, NULL, NULL);

partnum = guestfs_part_to_partnum (g, partition);
if (partnum == -1)
goto out;

device = guestfs_part_to_dev (g, partition);
if (device == NULL)
goto out;

mbr_id = guestfs_part_get_mbr_id (g, device, partnum);

ret = mbr_id == 0x42;

out:
guestfs_pop_error_handler (g);
free (device);

return ret;
}

0 comments on commit eab324b

Please sign in to comment.