Don't use the kern.disks sysctl to find a list of md devices, use the
MDIOCLIST ioctl instead. Spotted by: keramida
This commit is contained in:
parent
16bcbe8cf7
commit
e39eff98a0
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=109930
@ -204,50 +204,16 @@ SLIST_HEAD(, dl) dlist = SLIST_HEAD_INITIALIZER(&dlist);
|
|||||||
int
|
int
|
||||||
list(const int fd)
|
list(const int fd)
|
||||||
{
|
{
|
||||||
char *disklist, *p, *p2, *p3;
|
|
||||||
int unit;
|
int unit;
|
||||||
size_t dll;
|
|
||||||
struct dl *dp, *di, *dn;
|
|
||||||
|
|
||||||
if (sysctlbyname("kern.disks", NULL, &dll, NULL, 0) == -1)
|
if (ioctl(fd, MDIOCLIST, &mdio) < 0)
|
||||||
err(1, "sysctlbyname: kern.disks");
|
err(1, "ioctl(/dev/%s)", MDCTL_NAME);
|
||||||
if ( (disklist = malloc(dll + 1)) == NULL)
|
for (unit = 0; unit < mdio.md_pad[0] && unit < MDNPAD - 1; unit++) {
|
||||||
err(1, "malloc");
|
printf("%smd%d", unit > 0 ? " " : "", mdio.md_pad[unit + 1]);
|
||||||
bzero(disklist, dll + 1);
|
|
||||||
if (sysctlbyname("kern.disks", disklist, &dll, NULL, 0) == -1)
|
|
||||||
err(1, "sysctlbyname: kern.disks");
|
|
||||||
|
|
||||||
for (p = disklist;
|
|
||||||
(p2 = strsep(&p, " ")) != NULL;) {
|
|
||||||
if (strncmp(p2, MD_NAME, sizeof(MD_NAME) - 1) != 0)
|
|
||||||
continue;
|
|
||||||
p2 += sizeof(MD_NAME) - 1;
|
|
||||||
unit = strtoul(p2, &p3, 10);
|
|
||||||
if (p2 == p3)
|
|
||||||
continue;
|
|
||||||
dp = calloc(sizeof *dp, 1);
|
|
||||||
dp->unit = unit;
|
|
||||||
dn = SLIST_FIRST(&dlist);
|
|
||||||
if (dn == NULL || dn->unit > unit) {
|
|
||||||
SLIST_INSERT_HEAD(&dlist, dp, slist);
|
|
||||||
} else {
|
|
||||||
SLIST_FOREACH(di, &dlist, slist) {
|
|
||||||
dn = SLIST_NEXT(di, slist);
|
|
||||||
if (dn == NULL || dn->unit > unit) {
|
|
||||||
SLIST_INSERT_AFTER(di, dp, slist);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
SLIST_FOREACH(di, &dlist, slist)
|
if (mdio.md_pad[0] - unit > 0)
|
||||||
query(fd, di->unit);
|
printf(" ... %d more", mdio.md_pad[0] - unit);
|
||||||
while (!SLIST_EMPTY(&dlist)) {
|
printf("\n");
|
||||||
di = SLIST_FIRST(&dlist);
|
|
||||||
SLIST_REMOVE_HEAD(&dlist, slist);
|
|
||||||
free(di);
|
|
||||||
}
|
|
||||||
free(disklist);
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user