Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/sysinst Slightly enhance previous: create two utili...
details: https://anonhg.NetBSD.org/src/rev/5ab2ba62adf9
branches: trunk
changeset: 994573:5ab2ba62adf9
user: martin <martin%NetBSD.org@localhost>
date: Wed Nov 14 02:30:00 2018 +0000
description:
Slightly enhance previous: create two utility functions checking for
partitionability and boot code requirements, use a generic match helper
function for both and fully check the device name.
diffstat:
usr.sbin/sysinst/defs.h | 4 ++-
usr.sbin/sysinst/disks.c | 68 ++++++++++++++++++++++++++++++++++++------------
2 files changed, 54 insertions(+), 18 deletions(-)
diffs (112 lines):
diff -r 76e627e4fdad -r 5ab2ba62adf9 usr.sbin/sysinst/defs.h
--- a/usr.sbin/sysinst/defs.h Tue Nov 13 22:25:28 2018 +0000
+++ b/usr.sbin/sysinst/defs.h Wed Nov 14 02:30:00 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: defs.h,v 1.24 2018/11/11 10:06:09 martin Exp $ */
+/* $NetBSD: defs.h,v 1.25 2018/11/14 02:30:00 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -483,6 +483,8 @@
int find_disks(const char *);
bool enumerate_disks(void *state,bool (*func)(void *state, const char *dev));
bool is_cdrom_device(const char *dev, bool as_target);
+bool is_bootable_device(const char *dev);
+bool is_partitionable_device(const char *dev);
struct menudesc;
void fmt_fspart(struct menudesc *, int, void *);
diff -r 76e627e4fdad -r 5ab2ba62adf9 usr.sbin/sysinst/disks.c
--- a/usr.sbin/sysinst/disks.c Tue Nov 13 22:25:28 2018 +0000
+++ b/usr.sbin/sysinst/disks.c Wed Nov 14 02:30:00 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: disks.c,v 1.26 2018/11/13 17:22:04 bouyer Exp $ */
+/* $NetBSD: disks.c,v 1.27 2018/11/14 02:30:00 martin Exp $ */
/*
* Copyright 1997 Piermont Information Systems Inc.
@@ -546,6 +546,53 @@
return false;
}
+/* does this device match any entry in the driver list? */
+static bool
+dev_in_list(const char *dev, const char **list)
+{
+
+ for ( ; *list; list++) {
+
+ size_t len = strlen(*list);
+
+ /* start of name matches? */
+ if (strncmp(dev, *list, len) == 0) {
+ char *endp;
+ int e;
+
+ /* remainder of name is a decimal number? */
+ strtou(dev+len, &endp, 10, 0, INT_MAX, &e);
+ if (endp && *endp == 0 && e == 0)
+ return true;
+ }
+ }
+
+ return false;
+}
+
+bool
+is_bootable_device(const char *dev)
+{
+ static const char *non_bootable_devs[] = {
+ "raid", /* bootcode lives outside of raid */
+ "xbd", /* xen virtual device, can not boot from that */
+ NULL
+ };
+
+ return !dev_in_list(dev, non_bootable_devs);
+}
+
+bool
+is_partitionable_device(const char *dev)
+{
+ static const char *non_partitionable_devs[] = {
+ "dk", /* this is alreay a partioned slice */
+ NULL
+ };
+
+ return !dev_in_list(dev, non_partitionable_devs);
+}
+
/*
* Multi-purpose helper function:
* iterate all known disks, invoke a callback for each.
@@ -604,27 +651,14 @@
if (is_cdrom_device(dev, true))
return true;
+ memset(state->dd, 0, sizeof(*state->dd));
strlcpy(state->dd->dd_name, dev, sizeof state->dd->dd_name - 2);
- state->dd->dd_no_mbr = false;
- state->dd->dd_no_part = false;
+ state->dd->dd_no_mbr = !is_bootable_device(dev);
+ state->dd->dd_no_part = !is_partitionable_device(dev);
- if (strncmp(dev, "dk", 2) == 0) {
- char *endp;
- int e;
-
- /* if this device is dkNNNN, no partitioning is possible */
- strtou(dev+2, &endp, 10, 0, INT_MAX, &e);
- if (endp && *endp == 0 && e == 0)
- state->dd->dd_no_part = true;
- }
if (state->dd->dd_no_part && !state->with_non_partitionable)
return true;
- if (strncmp(dev, "xbd", 3) == 0 || strncmp(dev, "raid", 4) == 0) {
- /* if this device is xbd or raid, don't set up an MBR */
- state->dd->dd_no_mbr = true;
- }
-
if (!get_geom(state->dd->dd_name, &l)) {
if (errno == ENOENT)
return true;
Home |
Main Index |
Thread Index |
Old Index