Improve partition detection on lesser used devices

The format strings in efi_get_info() are intended to extract both the
main device and partition number. However, this is only done correctly
for hd, sd and vd devices. The format strings for ram, dm-, md and loop
devices misparse the input. This causes the partition device to be
incorrectly labelled as the main device with the partition being
labelled 0.

Reported-by: ilovezfs <ilovezfs@icloud.com>
Signed-off-by: Richard Yao <ryao@gentoo.org>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Issue #2175
This commit is contained in:
Richard Yao 2014-01-09 12:52:10 -05:00 committed by Brian Behlendorf
parent b79e1f1f27
commit 787c455ed7
1 changed files with 12 additions and 8 deletions

View File

@ -194,8 +194,9 @@ efi_get_info(int fd, struct dk_cinfo *dki_info)
} else if ((strncmp(dev_path, "/dev/md", 7) == 0)) { } else if ((strncmp(dev_path, "/dev/md", 7) == 0)) {
strcpy(dki_info->dki_cname, "pseudo"); strcpy(dki_info->dki_cname, "pseudo");
dki_info->dki_ctype = DKC_MD; dki_info->dki_ctype = DKC_MD;
rval = sscanf(dev_path, "/dev/%[a-zA-Z0-9]p%hu", strcpy(dki_info->dki_dname, "md");
dki_info->dki_dname, rval = sscanf(dev_path, "/dev/md%[0-9]p%hu",
dki_info->dki_dname + 2,
&dki_info->dki_partition); &dki_info->dki_partition);
} else if ((strncmp(dev_path, "/dev/vd", 7) == 0)) { } else if ((strncmp(dev_path, "/dev/vd", 7) == 0)) {
strcpy(dki_info->dki_cname, "vd"); strcpy(dki_info->dki_cname, "vd");
@ -206,20 +207,23 @@ efi_get_info(int fd, struct dk_cinfo *dki_info)
} else if ((strncmp(dev_path, "/dev/dm-", 8) == 0)) { } else if ((strncmp(dev_path, "/dev/dm-", 8) == 0)) {
strcpy(dki_info->dki_cname, "pseudo"); strcpy(dki_info->dki_cname, "pseudo");
dki_info->dki_ctype = DKC_VBD; dki_info->dki_ctype = DKC_VBD;
rval = sscanf(dev_path, "/dev/%[a-zA-Z0-9-]p%hu", strcpy(dki_info->dki_dname, "dm-");
dki_info->dki_dname, rval = sscanf(dev_path, "/dev/dm-%[0-9]p%hu",
dki_info->dki_dname + 3,
&dki_info->dki_partition); &dki_info->dki_partition);
} else if ((strncmp(dev_path, "/dev/ram", 8) == 0)) { } else if ((strncmp(dev_path, "/dev/ram", 8) == 0)) {
strcpy(dki_info->dki_cname, "pseudo"); strcpy(dki_info->dki_cname, "pseudo");
dki_info->dki_ctype = DKC_PCMCIA_MEM; dki_info->dki_ctype = DKC_PCMCIA_MEM;
rval = sscanf(dev_path, "/dev/%[a-zA-Z0-9]p%hu", strcpy(dki_info->dki_dname, "ram");
dki_info->dki_dname, rval = sscanf(dev_path, "/dev/ram%[0-9]p%hu",
dki_info->dki_dname + 3,
&dki_info->dki_partition); &dki_info->dki_partition);
} else if ((strncmp(dev_path, "/dev/loop", 9) == 0)) { } else if ((strncmp(dev_path, "/dev/loop", 9) == 0)) {
strcpy(dki_info->dki_cname, "pseudo"); strcpy(dki_info->dki_cname, "pseudo");
dki_info->dki_ctype = DKC_VBD; dki_info->dki_ctype = DKC_VBD;
rval = sscanf(dev_path, "/dev/%[a-zA-Z0-9]p%hu", strcpy(dki_info->dki_dname, "loop");
dki_info->dki_dname, rval = sscanf(dev_path, "/dev/loop%[0-9]p%hu",
dki_info->dki_dname + 4,
&dki_info->dki_partition); &dki_info->dki_partition);
} else { } else {
strcpy(dki_info->dki_dname, "unknown"); strcpy(dki_info->dki_dname, "unknown");