Index: stand/common/disk.c =================================================================== --- stand/common/disk.c +++ stand/common/disk.c @@ -131,17 +131,10 @@ dev.d_slice = part->index; dev.d_partition = -1; if (disk_open(&dev, partsize, sectsize) == 0) { - /* - * disk_open() for partition -1 on a bsd slice assumes - * you want the first bsd partition. Reset things so - * that we're looking at the start of the raw slice. - */ - dev.d_partition = -1; - dev.d_offset = part->start; table = ptable_open(&dev, partsize, sectsize, ptblread); if (table != NULL) { sprintf(line, " %s%s", pa->prefix, pname); - bsd.dev = pa->dev; + bsd.dev = &dev; bsd.prefix = line; bsd.verbose = pa->verbose; res = ptable_iterate(table, &bsd, ptable_print); @@ -229,7 +222,8 @@ int rc, slice, partition; rc = 0; - od = (struct open_disk *)malloc(sizeof(struct open_disk)); + table = NULL; + od = malloc(sizeof(*od)); if (od == NULL) { DEBUG("no memory"); return (ENOMEM); @@ -247,13 +241,11 @@ partdev.d_slice = -1; partdev.d_partition = -1; - dev->d_offset = 0; - table = NULL; slice = dev->d_slice; partition = dev->d_partition; - DEBUG("%s unit %d, slice %d, partition %d => %p", - disk_fmtdev(dev), dev->dd.d_unit, dev->d_slice, dev->d_partition, od); + DEBUG("%s unit %d, slice %d, partition %d => %p", disk_fmtdev(dev), + dev->dd.d_unit, dev->d_slice, dev->d_partition, od); /* Determine disk layout. */ od->table = ptable_open(&partdev, mediasize / sectorsize, sectorsize, @@ -289,6 +281,7 @@ rc = ptable_getpart(od->table, &part, slice); if (rc != 0) /* Partition doesn't exist */ goto out; + dev->d_offset = part.start; od->entrysize = part.end - part.start + 1; slice = part.index; @@ -303,15 +296,13 @@ */ partition = -1; } + /* - * If d_partition < 0 and we are looking at a BSD slice, - * then try to read BSD label, otherwise return the - * whole MBR slice. + * We do have slice, but no partition, return the slice. */ - if (partition == -1 && - part.type != PART_FREEBSD) + if (partition == -1) goto out; - /* Try to read BSD label */ + table = ptable_open(dev, part.end - part.start + 1, od->sectorsize, ptblread); if (table == NULL) { @@ -319,16 +310,6 @@ rc = ENXIO; goto out; } - /* - * If slice contains BSD label and d_partition < 0, then - * assume the 'a' partition. Otherwise just return the - * whole MBR slice, because it can contain ZFS. - */ - if (partition < 0) { - if (ptable_gettype(table) != PTABLE_BSD) - goto out; - partition = 0; - } rc = ptable_getpart(table, &part, partition); if (rc != 0) goto out; @@ -336,12 +317,9 @@ od->entrysize = part.end - part.start + 1; } out: - if (table != NULL) - ptable_close(table); - + ptable_close(table); if (rc != 0) { - if (od->table != NULL) - ptable_close(od->table); + ptable_close(od->table); free(od); DEBUG("%s could not open", disk_fmtdev(dev)); } else {