Module Name: src Committed By: martin Date: Mon Nov 5 19:45:57 UTC 2018
Modified Files: src/usr.sbin/sysinst: disks.c src/usr.sbin/sysinst/arch/amd64: md.h src/usr.sbin/sysinst/arch/amiga: md.h src/usr.sbin/sysinst/arch/emips: md.h src/usr.sbin/sysinst/arch/hp300: md.h src/usr.sbin/sysinst/arch/i386: md.h src/usr.sbin/sysinst/arch/sparc: md.h src/usr.sbin/sysinst/arch/vax: md.h Log Message: Get rid of hard coded disk names and use sysctl hw.disknames instead. To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/usr.sbin/sysinst/disks.c cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/sysinst/arch/amd64/md.h cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/sysinst/arch/amiga/md.h cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/sysinst/arch/emips/md.h cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/sysinst/arch/hp300/md.h cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/sysinst/arch/i386/md.h cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/sysinst/arch/sparc/md.h cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/sysinst/arch/vax/md.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.sbin/sysinst/disks.c diff -u src/usr.sbin/sysinst/disks.c:1.16 src/usr.sbin/sysinst/disks.c:1.17 --- src/usr.sbin/sysinst/disks.c:1.16 Sun Jun 3 13:18:06 2018 +++ src/usr.sbin/sysinst/disks.c Mon Nov 5 19:45:56 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: disks.c,v 1.16 2018/06/03 13:18:06 martin Exp $ */ +/* $NetBSD: disks.c,v 1.17 2018/11/05 19:45:56 martin Exp $ */ /* * Copyright 1997 Piermont Information Systems Inc. @@ -36,6 +36,7 @@ #include <errno.h> +#include <inttypes.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -109,12 +110,6 @@ static void fixsb(const char *, const ch static bool is_gpt(const char *); static int incoregpt(pm_devs_t *, partinfo *); -#ifndef DISK_NAMES -#define DISK_NAMES "wd", "sd", "ld", "raid" -#endif - -static const char *disk_names[] = { DISK_NAMES, - "vnd", "cgd", "dk:no_part", NULL }; static bool tmpfs_on_var_shm(void); @@ -510,72 +505,86 @@ is_ffs_wedge(const char *dev) static int get_disks(struct disk_desc *dd, bool with_non_partitionable) { - const char **xd; - char *cp; + static const int mib[] = { CTL_HW, HW_DISKNAMES }; + static const unsigned int miblen = __arraycount(mib); + const char *xd; struct disklabel l; - int i; int numdisks; + size_t len; + char *disk_names; /* initialize */ numdisks = 0; - for (xd = disk_names; *xd != NULL; xd++) { - for (i = 0; i < MAX_DISKS; i++) { - strlcpy(dd->dd_name, *xd, sizeof dd->dd_name - 2); - cp = strchr(dd->dd_name, ':'); - if (cp != NULL) { - dd->dd_no_mbr = !strcmp(cp, ":no_mbr"); - dd->dd_no_part = !strcmp(cp, ":no_part"); - } else { - dd->dd_no_mbr = false; - dd->dd_no_part = false; - cp = strchr(dd->dd_name, 0); - } - if (dd->dd_no_part && !with_non_partitionable) - continue; + if (sysctl(mib, miblen, NULL, &len, NULL, 0) == -1) + return 0; + disk_names = malloc(len); + if (disk_names == NULL) + return 0; - snprintf(cp, 2 + 1, "%d", i); - if (!get_geom(dd->dd_name, &l)) { - if (errno == ENOENT) - break; - if (errno != ENOTTY || !dd->dd_no_part) - /* - * Allow plain partitions, - * like already existing wedges - * (like dk0) if marked as - * non-partitioning device. - * For all other cases, continue - * with the next disk. - */ - continue; - if (!is_ffs_wedge(dd->dd_name)) - continue; - } + if (sysctl(mib, miblen, disk_names, &len, NULL, 0) == -1) { + free(disk_names); + return 0; + } - /* - * Exclude a disk mounted as root partition, - * in case of install-image on a USB memstick. - */ - if (is_active_rootpart(dd->dd_name, 0)) + for (xd = strtok(disk_names, " "); xd != NULL; xd = strtok(NULL, " ")) { + strlcpy(dd->dd_name, xd, sizeof dd->dd_name - 2); + dd->dd_no_mbr = false; + dd->dd_no_part = false; + + if (strncmp(xd, "dk", 2) == 0) { + char *endp; + int e; + + /* if this device is dkNNNN, no partitioning is possible */ + strtou(xd+2, &endp, 10, 0, INT_MAX, &e); + if (endp && *endp == 0 && e == 0) + dd->dd_no_part = true; + } + if (dd->dd_no_part && !with_non_partitionable) + continue; + + if (!get_geom(dd->dd_name, &l)) { + if (errno == ENOENT) + break; + if (errno != ENOTTY || !dd->dd_no_part) + /* + * Allow plain partitions, + * like already existing wedges + * (like dk0) if marked as + * non-partitioning device. + * For all other cases, continue + * with the next disk. + */ + continue; + if (!is_ffs_wedge(dd->dd_name)) continue; + } - if (!dd->dd_no_part) { - dd->dd_cyl = l.d_ncylinders; - dd->dd_head = l.d_ntracks; - dd->dd_sec = l.d_nsectors; - dd->dd_secsize = l.d_secsize; - dd->dd_totsec = l.d_secperunit; - } - if (dd->dd_no_part) - get_wedge_descr(dd); - else - get_descr(dd); - dd++; - numdisks++; - if (numdisks >= MAX_DISKS) - return numdisks; + /* + * Exclude a disk mounted as root partition, + * in case of install-image on a USB memstick. + */ + if (is_active_rootpart(dd->dd_name, 0)) + continue; + + if (!dd->dd_no_part) { + dd->dd_cyl = l.d_ncylinders; + dd->dd_head = l.d_ntracks; + dd->dd_sec = l.d_nsectors; + dd->dd_secsize = l.d_secsize; + dd->dd_totsec = l.d_secperunit; } + if (dd->dd_no_part) + get_wedge_descr(dd); + else + get_descr(dd); + dd++; + numdisks++; + if (numdisks == MAX_DISKS) + break; } + free(disk_names); return numdisks; } Index: src/usr.sbin/sysinst/arch/amd64/md.h diff -u src/usr.sbin/sysinst/arch/amd64/md.h:1.2 src/usr.sbin/sysinst/arch/amd64/md.h:1.3 --- src/usr.sbin/sysinst/arch/amd64/md.h:1.2 Sat Nov 14 23:00:17 2015 +++ src/usr.sbin/sysinst/arch/amd64/md.h Mon Nov 5 19:45:56 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: md.h,v 1.2 2015/11/14 23:00:17 pgoyette Exp $ */ +/* $NetBSD: md.h,v 1.3 2018/11/05 19:45:56 martin Exp $ */ /* * Copyright 1997 Piermont Information Systems Inc. @@ -85,14 +85,6 @@ #define SET_KERNEL_GENERIC SET_KERNEL_1 /* - * Disk names accepted as valid targets for a from-scratch installation. - * - * On amd64, we allow "wd" ST-506/IDE disks, "sd" scsi disks, "ld" logical - * disks and "raid" raidframe disks. - */ -#define DISK_NAMES "wd", "sd", "ld", "raid:no_mbr", "xbd:no_mbr" - -/* * Machine-specific command to write a new label to a disk. * For example, i386 uses "/sbin/disklabel -w -r", just like i386 * miniroot scripts, though this may leave a bogus incore label. Index: src/usr.sbin/sysinst/arch/amiga/md.h diff -u src/usr.sbin/sysinst/arch/amiga/md.h:1.1 src/usr.sbin/sysinst/arch/amiga/md.h:1.2 --- src/usr.sbin/sysinst/arch/amiga/md.h:1.1 Sat Jul 26 19:30:44 2014 +++ src/usr.sbin/sysinst/arch/amiga/md.h Mon Nov 5 19:45:56 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: md.h,v 1.1 2014/07/26 19:30:44 dholland Exp $ */ +/* $NetBSD: md.h,v 1.2 2018/11/05 19:45:56 martin Exp $ */ /* * Copyright 1997 Piermont Information Systems Inc. @@ -57,14 +57,6 @@ #define SET_KERNEL_1_NAME "kern-GENERIC" /* - * Disk names accepted as valid targets for a from-scratch installation. - * - * On amiga, disks are always named "sd", regardless they are attached - * to the IDE bus or to the SCSI bus. - */ -#define DISK_NAMES "sd" - -/* * Machine-specific command to write a new label to a disk. * For example, i386 uses "/sbin/disklabel -w -r", just like i386 * miniroot scripts, though this may leave a bogus incore label. Index: src/usr.sbin/sysinst/arch/emips/md.h diff -u src/usr.sbin/sysinst/arch/emips/md.h:1.1 src/usr.sbin/sysinst/arch/emips/md.h:1.2 --- src/usr.sbin/sysinst/arch/emips/md.h:1.1 Sat Jul 26 19:30:45 2014 +++ src/usr.sbin/sysinst/arch/emips/md.h Mon Nov 5 19:45:56 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: md.h,v 1.1 2014/07/26 19:30:45 dholland Exp $ */ +/* $NetBSD: md.h,v 1.2 2018/11/05 19:45:56 martin Exp $ */ /* * Copyright 1997 Piermont Information Systems Inc. @@ -51,12 +51,6 @@ #define DEFUSRSIZE 120 /* Default /usr size, if /home */ #define XNEEDMB 100 /* Extra megs for full X installation */ -/* - * Disk names accepted as valid targets for a from-scratch installation. - * - */ -#define DISK_NAMES "ace", "sd", "wd", "ld", "raid" - /* have support for booting from UFS2 */ #define HAVE_UFS2_BOOT Index: src/usr.sbin/sysinst/arch/hp300/md.h diff -u src/usr.sbin/sysinst/arch/hp300/md.h:1.1 src/usr.sbin/sysinst/arch/hp300/md.h:1.2 --- src/usr.sbin/sysinst/arch/hp300/md.h:1.1 Sat Jul 26 19:30:45 2014 +++ src/usr.sbin/sysinst/arch/hp300/md.h Mon Nov 5 19:45:56 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: md.h,v 1.1 2014/07/26 19:30:45 dholland Exp $ */ +/* $NetBSD: md.h,v 1.2 2018/11/05 19:45:56 martin Exp $ */ /* * Copyright 1997 Piermont Information Systems Inc. @@ -69,13 +69,6 @@ */ #define SET_KERNEL_1_NAME "kern-GENERIC" -/* - * Disk names accepted as valid targets for a from-scratch installation. - * - * On hp300, allow "rd" HP-IB and "sd" scsi disks. - */ -#define DISK_NAMES "rd", "sd" - /* * Machine-specific command to write a new label to a disk. Index: src/usr.sbin/sysinst/arch/i386/md.h diff -u src/usr.sbin/sysinst/arch/i386/md.h:1.1 src/usr.sbin/sysinst/arch/i386/md.h:1.2 --- src/usr.sbin/sysinst/arch/i386/md.h:1.1 Sat Jul 26 19:30:45 2014 +++ src/usr.sbin/sysinst/arch/i386/md.h Mon Nov 5 19:45:56 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: md.h,v 1.1 2014/07/26 19:30:45 dholland Exp $ */ +/* $NetBSD: md.h,v 1.2 2018/11/05 19:45:56 martin Exp $ */ /* * Copyright 1997 Piermont Information Systems Inc. @@ -79,14 +79,6 @@ #define SET_KERNEL_1_NAME "kern-GENERIC" /* - * Disk names accepted as valid targets for a from-scratch installation. - * - * On i386, we allow "wd" ST-506/IDE disks, "sd" scsi disks, "ld" logical - * disks, "ed" IBM ESDI disks, "raid" raidframe disks - */ -#define DISK_NAMES "wd", "sd", "ld", "ed", "raid:no_mbr", "xbd:no_mbr" - -/* * Machine-specific command to write a new label to a disk. * For example, i386 uses "/sbin/disklabel -w -r", just like i386 * miniroot scripts, though this may leave a bogus incore label. Index: src/usr.sbin/sysinst/arch/sparc/md.h diff -u src/usr.sbin/sysinst/arch/sparc/md.h:1.1 src/usr.sbin/sysinst/arch/sparc/md.h:1.2 --- src/usr.sbin/sysinst/arch/sparc/md.h:1.1 Sat Jul 26 19:30:47 2014 +++ src/usr.sbin/sysinst/arch/sparc/md.h Mon Nov 5 19:45:56 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: md.h,v 1.1 2014/07/26 19:30:47 dholland Exp $ */ +/* $NetBSD: md.h,v 1.2 2018/11/05 19:45:56 martin Exp $ */ /* * Copyright 1997 Piermont Information Systems Inc. @@ -65,11 +65,6 @@ #define SET_KERNEL_4_NAME "kern-GENERIC.MP" /* - * Disk names accepted as valid targets for a from-scratch installation. - */ -#define DISK_NAMES "sd", "xy", "xd" - -/* * Machine-specific command to write a new label to a disk. * If not defined, we assume the port does not support disklabels and * the hand-edited disklabel will NOT be written by MI code. Index: src/usr.sbin/sysinst/arch/vax/md.h diff -u src/usr.sbin/sysinst/arch/vax/md.h:1.1 src/usr.sbin/sysinst/arch/vax/md.h:1.2 --- src/usr.sbin/sysinst/arch/vax/md.h:1.1 Sat Jul 26 19:30:47 2014 +++ src/usr.sbin/sysinst/arch/vax/md.h Mon Nov 5 19:45:56 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: md.h,v 1.1 2014/07/26 19:30:47 dholland Exp $ */ +/* $NetBSD: md.h,v 1.2 2018/11/05 19:45:56 martin Exp $ */ /* * Copyright 1997 Piermont Information Systems Inc. @@ -59,11 +59,6 @@ #define SET_KERNEL_1_NAME "kern-GENERIC" /* - * Disk names accepted as valid targets for a from-scratch installation. - */ -#define DISK_NAMES "sd", "ra", "rd", "hp" - -/* * Machine-specific command to write a new label to a disk. * If not defined, we assume the port does not support disklabels and * the hand-edited disklabel will NOT be written by MI code.