Source-Changes-HG archive

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

[src/netbsd-9]: src/usr.sbin/sysinst Pull up following revision(s) (requested...



details:   https://anonhg.NetBSD.org/src/rev/19e70e1c5172
branches:  netbsd-9
changeset: 458131:19e70e1c5172
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Mon Aug 05 04:37:44 2019 +0000

description:
Pull up following revision(s) (requested by martin in ticket #15):
        usr.sbin/sysinst/gpt.c: revision 1.8
When reading an existing gpt, match the wedges already existing
on the parent device, so we can use them directly if we should proceed
with an unmodified partition table.

diffstat:

 usr.sbin/sysinst/gpt.c |  45 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 44 insertions(+), 1 deletions(-)

diffs (71 lines):

diff -r 4f1ab9e159f9 -r 19e70e1c5172 usr.sbin/sysinst/gpt.c
--- a/usr.sbin/sysinst/gpt.c    Mon Aug 05 04:36:42 2019 +0000
+++ b/usr.sbin/sysinst/gpt.c    Mon Aug 05 04:37:44 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gpt.c,v 1.6.2.1 2019/08/05 04:34:54 msaitoh Exp $      */
+/*     $NetBSD: gpt.c,v 1.6.2.2 2019/08/05 04:37:44 msaitoh Exp $      */
 
 /*
  * Copyright 2018 The NetBSD Foundation, Inc.
@@ -228,11 +228,34 @@
        }
 }
 
+/*
+ * Find the partition matching this wedge info and record that we
+ * have a wedge already.
+ */
+static void
+update_part_from_wedge_info(struct gpt_disk_partitions *parts,
+    const struct dkwedge_info *dkw)
+{
+       for (struct gpt_part_entry *p = parts->partitions; p != NULL;
+           p = p->gp_next) {
+               if (p->gp_start != dkw->dkw_offset ||
+                   (uint64_t)p->gp_size != dkw->dkw_size)
+                       continue;
+               p->gp_flags |= GPEF_WEDGE;
+               strlcpy(p->gp_dev_name, dkw->dkw_devname,
+                   sizeof p->gp_dev_name);
+               return;
+       }
+}
+
 static struct disk_partitions *
 gpt_read_from_disk(const char *dev, daddr_t start, daddr_t len)
 {
        char diskpath[MAXPATHLEN];
        int fd;
+       struct dkwedge_info *dkw;
+       struct dkwedge_list dkwl;
+       size_t bufsize, dk;
 
        assert(start == 0);
        assert(have_gpt);
@@ -384,6 +407,26 @@
 
                parts->dp.free_space -= p->gp_size;
        }
+
+       /*
+        * Check if we have any (matching/auto-configured) wedges already
+        */
+       dkw = NULL;
+       dkwl.dkwl_buf = dkw;
+       dkwl.dkwl_bufsize = 0;
+       if (ioctl(fd, DIOCLWEDGES, &dkwl) == 0) {
+               /* do not even try to deal with any races at this point */
+               bufsize = dkwl.dkwl_nwedges * sizeof(*dkw);
+               dkw = malloc(bufsize);
+               dkwl.dkwl_buf = dkw;
+               dkwl.dkwl_bufsize = bufsize;
+               if (dkw != NULL && ioctl(fd, DIOCLWEDGES, &dkwl) == 0) {
+                       for (dk = 0; dk < dkwl.dkwl_ncopied; dk++)
+                               update_part_from_wedge_info(parts, &dkw[dk]);
+               }
+               free(dkw);
+       }
+
        close(fd);
 
        return &parts->dp;



Home | Main Index | Thread Index | Old Index