Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/sysinst Add an option to install onto a pre-configu...



details:   https://anonhg.NetBSD.org/src/rev/fc50e367fe47
branches:  trunk
changeset: 832970:fc50e367fe47
user:      martin <martin%NetBSD.org@localhost>
date:      Sun Jun 03 13:16:30 2018 +0000

description:
Add an option to install onto a pre-configured wedge.
Greatly simmplifies (U)EFI setups (but does not fully automate them yet).

diffstat:

 usr.sbin/sysinst/arch/i386/md.c |   46 +++--
 usr.sbin/sysinst/bsddisklabel.c |    5 +-
 usr.sbin/sysinst/defs.h         |    3 +-
 usr.sbin/sysinst/disks.c        |  284 ++++++++++++++++++++++++++++++++++-----
 usr.sbin/sysinst/mbr.c          |    7 +-
 usr.sbin/sysinst/msg.mi.de      |   13 +-
 usr.sbin/sysinst/msg.mi.en      |   10 +-
 usr.sbin/sysinst/msg.mi.es      |   12 +-
 usr.sbin/sysinst/msg.mi.fr      |   12 +-
 usr.sbin/sysinst/msg.mi.pl      |   12 +-
 10 files changed, 333 insertions(+), 71 deletions(-)

diffs (truncated from 689 to 300 lines):

diff -r 0dda36895359 -r fc50e367fe47 usr.sbin/sysinst/arch/i386/md.c
--- a/usr.sbin/sysinst/arch/i386/md.c   Sun Jun 03 12:54:51 2018 +0000
+++ b/usr.sbin/sysinst/arch/i386/md.c   Sun Jun 03 13:16:30 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: md.c,v 1.8 2018/05/18 12:23:22 joerg Exp $ */
+/*     $NetBSD: md.c,v 1.9 2018/06/03 13:16:30 martin Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -317,32 +317,36 @@
        struct termios t;
        dev_t condev;
 
-       /*
-        * Get console device, should either be ttyE0 or tty0n.
-        * Too hard to double check, so just 'know' the device numbers.
-        */
-       len = sizeof condev;
-       if (sysctl(conmib, nelem(conmib), &condev, &len, NULL, 0) != -1
-           && (condev & ~3) == 0x800) {
-               /* Motherboard serial port */
-               boottype.bp_consdev = (condev & 3) + 1;
-               /* Defaulting the baud rate to that of stdin should suffice */
-               if (tcgetattr(0, &t) != -1)
-                       boottype.bp_conspeed = t.c_ispeed;
+       if (pm == NULL || !pm->no_part) {
+               /*
+                * Get console device, should either be ttyE0 or tty0n.
+                * Too hard to double check, so just 'know' the device numbers.
+                */
+               len = sizeof condev;
+               if (sysctl(conmib, nelem(conmib), &condev, &len, NULL, 0) != -1
+                   && (condev & ~3) == 0x800) {
+                       /* Motherboard serial port */
+                       boottype.bp_consdev = (condev & 3) + 1;
+                       /* Defaulting the baud rate to that of stdin should suffice */
+                       if (tcgetattr(0, &t) != -1)
+                               boottype.bp_conspeed = t.c_ispeed;
+               }
+
+               process_menu(MENU_getboottype, &boottype);
+               msg_display(MSG_dobootblks, pm->diskdev);
+               if (boottype.bp_consdev == ~0u)
+                       /* Use existing bootblocks */
+                       return 0;
        }
 
-       process_menu(MENU_getboottype, &boottype);
-       msg_display(MSG_dobootblks, pm->diskdev);
-       if (boottype.bp_consdev == ~0u)
-               /* Use existing bootblocks */
-               return 0;
-
        ret = cp_to_target("/usr/mdec/boot", "/boot");
        if (ret)
                return ret;
+       if (pm && pm->no_part)
+               return 0;
 
-        bootxx_filename = bootxx_name();                                                 
-        if (bootxx_filename != NULL) {                                                   
+        bootxx_filename = bootxx_name();
+        if (bootxx_filename != NULL) {
                snprintf(boot_options, sizeof boot_options,
                    "console=%s,speed=%u", consoles[boottype.bp_consdev],
                    boottype.bp_conspeed);
diff -r 0dda36895359 -r fc50e367fe47 usr.sbin/sysinst/bsddisklabel.c
--- a/usr.sbin/sysinst/bsddisklabel.c   Sun Jun 03 12:54:51 2018 +0000
+++ b/usr.sbin/sysinst/bsddisklabel.c   Sun Jun 03 13:16:30 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bsddisklabel.c,v 1.3 2018/05/18 12:23:22 joerg Exp $   */
+/*     $NetBSD: bsddisklabel.c,v 1.4 2018/06/03 13:16:30 martin Exp $  */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -566,6 +566,9 @@
        int no_swap = 0, valid_part = -1;
        partinfo *p, savedlabel[MAXPARTITIONS];
 
+       if (pm && pm->no_part)
+               return 1;
+
        memcpy(&savedlabel, &pm->bsdlabel, sizeof savedlabel);
 
        /*
diff -r 0dda36895359 -r fc50e367fe47 usr.sbin/sysinst/defs.h
--- a/usr.sbin/sysinst/defs.h   Sun Jun 03 12:54:51 2018 +0000
+++ b/usr.sbin/sysinst/defs.h   Sun Jun 03 13:16:30 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.10 2018/05/18 12:23:22 joerg Exp $  */
+/*     $NetBSD: defs.h,v 1.11 2018/06/03 13:16:30 martin Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -294,6 +294,7 @@
     partinfo bsdlabel[MAXPARTITIONS]; /* What we want it to look like */
     int gpt;
     int no_mbr; /* set for raid (etc) */
+    int no_part;       /* can not be partitioned, e.g. dk0 */
     int rootpart; /* partition we install into */
     const char *disktype; /* ST506, SCSI, ... */
     const char *doessf;
diff -r 0dda36895359 -r fc50e367fe47 usr.sbin/sysinst/disks.c
--- a/usr.sbin/sysinst/disks.c  Sun Jun 03 12:54:51 2018 +0000
+++ b/usr.sbin/sysinst/disks.c  Sun Jun 03 13:16:30 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disks.c,v 1.14 2018/05/01 09:01:45 martin Exp $ */
+/*     $NetBSD: disks.c,v 1.15 2018/06/03 13:16:30 martin Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -68,7 +68,7 @@
 struct disk_desc {
        char    dd_name[SSTRSIZE];
        char    dd_descr[70];
-       uint    dd_no_mbr;
+       bool    dd_no_mbr, dd_no_part;
        uint    dd_cyl;
        uint    dd_head;
        uint    dd_sec;
@@ -104,7 +104,7 @@
 #ifdef USE_SYSVBFS
 static int foundsysvbfs(struct data *, size_t);
 #endif
-static int fsck_preen(const char *, int, const char *);
+static int fsck_preen(const char *, int, const char *, bool silent);
 static void fixsb(const char *, const char *, char);
 static bool is_gpt(const char *);
 static int incoregpt(pm_devs_t *, partinfo *);
@@ -113,7 +113,8 @@
 #define DISK_NAMES "wd", "sd", "ld", "raid"
 #endif
 
-static const char *disk_names[] = { DISK_NAMES, "vnd", "cgd", NULL };
+static const char *disk_names[] = { DISK_NAMES,
+                                   "vnd", "cgd", "dk:no_part", NULL };
 
 static bool tmpfs_on_var_shm(void);
 
@@ -396,8 +397,118 @@
        return cdrom_devices[0];
 }
 
+static void
+get_wedge_descr(struct disk_desc *dd)
+{
+       struct dkwedge_info dkw;
+       char buf[MAXPATHLEN];
+       int fd;
+
+       fd = opendisk(dd->dd_name, O_RDONLY, buf, sizeof(buf), 0);
+       if (fd == -1)
+               return;
+
+       if (ioctl(fd, DIOCGWEDGEINFO, &dkw) == 0) {
+               fprintf(stderr, "device %s\n", dd->dd_name);
+               sprintf(dd->dd_descr, "%s (%s@%s)",
+                   dkw.dkw_wname, dkw.dkw_devname, dkw.dkw_parent);
+       }
+       close(fd);
+}
+
+static bool
+get_name_and_parent(const char *dev, char *name, char *parent)
+{
+       struct dkwedge_info dkw;
+       char buf[MAXPATHLEN];
+       int fd;
+       bool res = false;
+
+       fd = opendisk(dev, O_RDONLY, buf, sizeof(buf), 0);
+       if (fd == -1)
+               return false;
+
+       if (ioctl(fd, DIOCGWEDGEINFO, &dkw) == 0) {
+               strcpy(name, (const char *)dkw.dkw_wname);
+               strcpy(parent, dkw.dkw_parent);
+               res = true;
+       }
+       close(fd);
+       return res;
+}
+
+static bool
+find_swap_part_on(const char *dev, char *swap_name)
+{
+       struct dkwedge_info *dkw;
+       struct dkwedge_list dkwl;
+       char buf[MAXPATHLEN];
+       size_t bufsize;
+       int fd;
+       u_int i;
+       bool res = false;
+
+       dkw = NULL;
+       dkwl.dkwl_buf = dkw;
+       dkwl.dkwl_bufsize = 0;
+
+       fd = opendisk(dev, O_RDONLY, buf, sizeof(buf), 0);
+       if (fd == -1)
+               return false;
+
+       for (;;) {
+               if (ioctl(fd, DIOCLWEDGES, &dkwl) == -1) {
+                       dkwl.dkwl_ncopied = 0;
+                       break;
+               }
+               if (dkwl.dkwl_nwedges == dkwl.dkwl_ncopied)
+                       break;
+               bufsize = dkwl.dkwl_nwedges * sizeof(*dkw);
+               if (dkwl.dkwl_bufsize < bufsize) {
+                       dkw = realloc(dkwl.dkwl_buf, bufsize);
+                       if (dkw == NULL)
+                               break;
+                       dkwl.dkwl_buf = dkw;
+                       dkwl.dkwl_bufsize = bufsize;
+               }
+       }
+
+       for (i = 0; i < dkwl.dkwl_nwedges; i++) {
+               res = strcmp(dkw[i].dkw_ptype, DKW_PTYPE_SWAP) == 0;
+               if (res) {
+                       strcpy(swap_name, (const char*)dkw[i].dkw_wname);
+                       break;
+               }
+       }
+
+       close(fd);
+
+       return res;
+}
+
+static bool
+is_ffs_wedge(const char *dev)
+{
+       struct dkwedge_info dkw;
+       char buf[MAXPATHLEN];
+       int fd;
+       bool res;
+
+       fd = opendisk(dev, O_RDONLY, buf, sizeof(buf), 0);
+       if (fd == -1)
+               return false;
+
+       if (ioctl(fd, DIOCGWEDGEINFO, &dkw) == -1)
+               return false;
+
+       res = strcmp(dkw.dkw_ptype, DKW_PTYPE_FFS) == 0;
+       close(fd);
+
+       return res;
+}
+
 static int
-get_disks(struct disk_desc *dd)
+get_disks(struct disk_desc *dd, bool with_non_partitionable)
 {
        const char **xd;
        char *cp;
@@ -412,18 +523,33 @@
                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)
+                       if (cp != NULL) {
                                dd->dd_no_mbr = !strcmp(cp, ":no_mbr");
-                       else {
-                               dd->dd_no_mbr = 0;
+                               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;
 
                        snprintf(cp, 2 + 1, "%d", i);
                        if (!get_geom(dd->dd_name, &l)) {
                                if (errno == ENOENT)
                                        break;
-                               continue;
+                               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;
                        }
 
                        /*
@@ -433,12 +559,17 @@
                        if (is_active_rootpart(dd->dd_name, 0))
                                continue;



Home | Main Index | Thread Index | Old Index