Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/sysinst Get rid of hard coded disk names and use sy...
details: https://anonhg.NetBSD.org/src/rev/d9034786a97a
branches: trunk
changeset: 994397:d9034786a97a
user: martin <martin%NetBSD.org@localhost>
date: Mon Nov 05 19:45:56 2018 +0000
description:
Get rid of hard coded disk names and use sysctl hw.disknames
instead.
diffstat:
usr.sbin/sysinst/arch/amd64/md.h | 10 +--
usr.sbin/sysinst/arch/amiga/md.h | 10 +--
usr.sbin/sysinst/arch/emips/md.h | 8 +--
usr.sbin/sysinst/arch/hp300/md.h | 9 +--
usr.sbin/sysinst/arch/i386/md.h | 10 +--
usr.sbin/sysinst/arch/sparc/md.h | 7 +-
usr.sbin/sysinst/arch/vax/md.h | 7 +-
usr.sbin/sysinst/disks.c | 133 ++++++++++++++++++++------------------
8 files changed, 78 insertions(+), 116 deletions(-)
diffs (truncated from 331 to 300 lines):
diff -r 5091e9f54647 -r d9034786a97a usr.sbin/sysinst/arch/amd64/md.h
--- a/usr.sbin/sysinst/arch/amd64/md.h Mon Nov 05 18:37:18 2018 +0000
+++ b/usr.sbin/sysinst/arch/amd64/md.h Mon Nov 05 19:45:56 2018 +0000
@@ -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.
diff -r 5091e9f54647 -r d9034786a97a usr.sbin/sysinst/arch/amiga/md.h
--- a/usr.sbin/sysinst/arch/amiga/md.h Mon Nov 05 18:37:18 2018 +0000
+++ b/usr.sbin/sysinst/arch/amiga/md.h Mon Nov 05 19:45:56 2018 +0000
@@ -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.
diff -r 5091e9f54647 -r d9034786a97a usr.sbin/sysinst/arch/emips/md.h
--- a/usr.sbin/sysinst/arch/emips/md.h Mon Nov 05 18:37:18 2018 +0000
+++ b/usr.sbin/sysinst/arch/emips/md.h Mon Nov 05 19:45:56 2018 +0000
@@ -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
diff -r 5091e9f54647 -r d9034786a97a usr.sbin/sysinst/arch/hp300/md.h
--- a/usr.sbin/sysinst/arch/hp300/md.h Mon Nov 05 18:37:18 2018 +0000
+++ b/usr.sbin/sysinst/arch/hp300/md.h Mon Nov 05 19:45:56 2018 +0000
@@ -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.
diff -r 5091e9f54647 -r d9034786a97a usr.sbin/sysinst/arch/i386/md.h
--- a/usr.sbin/sysinst/arch/i386/md.h Mon Nov 05 18:37:18 2018 +0000
+++ b/usr.sbin/sysinst/arch/i386/md.h Mon Nov 05 19:45:56 2018 +0000
@@ -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.
diff -r 5091e9f54647 -r d9034786a97a usr.sbin/sysinst/arch/sparc/md.h
--- a/usr.sbin/sysinst/arch/sparc/md.h Mon Nov 05 18:37:18 2018 +0000
+++ b/usr.sbin/sysinst/arch/sparc/md.h Mon Nov 05 19:45:56 2018 +0000
@@ -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.
diff -r 5091e9f54647 -r d9034786a97a usr.sbin/sysinst/arch/vax/md.h
--- a/usr.sbin/sysinst/arch/vax/md.h Mon Nov 05 18:37:18 2018 +0000
+++ b/usr.sbin/sysinst/arch/vax/md.h Mon Nov 05 19:45:56 2018 +0000
@@ -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.
diff -r 5091e9f54647 -r d9034786a97a usr.sbin/sysinst/disks.c
--- a/usr.sbin/sysinst/disks.c Mon Nov 05 18:37:18 2018 +0000
+++ b/usr.sbin/sysinst/disks.c Mon Nov 05 19:45:56 2018 +0000
@@ -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 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 @@
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;
+
+ if (sysctl(mib, miblen, disk_names, &len, NULL, 0) == -1) {
+ free(disk_names);
+ return 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;
- 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 (!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;
+ }
- /*
- * 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;
+ /*
+ * 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;
Home |
Main Index |
Thread Index |
Old Index