Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/sysinst Fix some "partition index" (as used in the ...



details:   https://anonhg.NetBSD.org/src/rev/0f33637982e3
branches:  trunk
changeset: 964733:0f33637982e3
user:      martin <martin%NetBSD.org@localhost>
date:      Wed Aug 14 13:58:00 2019 +0000

description:
Fix some "partition index" (as used in the abstract interface)
versus disklabel "partition letter" confusion.

diffstat:

 usr.sbin/sysinst/disklabel.c |  36 ++++++++++++++++++++++++++++--------
 1 files changed, 28 insertions(+), 8 deletions(-)

diffs (81 lines):

diff -r 1710cede75c5 -r 0f33637982e3 usr.sbin/sysinst/disklabel.c
--- a/usr.sbin/sysinst/disklabel.c      Wed Aug 14 13:02:23 2019 +0000
+++ b/usr.sbin/sysinst/disklabel.c      Wed Aug 14 13:58:00 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disklabel.c,v 1.12 2019/08/14 13:02:23 martin Exp $    */
+/*     $NetBSD: disklabel.c,v 1.13 2019/08/14 13:58:00 martin Exp $    */
 
 /*
  * Copyright 2018 The NetBSD Foundation, Inc.
@@ -814,9 +814,25 @@
     part_id ptn, char *devname, size_t max_devname_len, int *part,
     enum dev_name_usage which_name, bool with_path)
 {
+       const struct disklabel_disk_partitions *parts =
+           (const struct disklabel_disk_partitions*)arg;
+       part_id id;
+       int part_index;
+       char pname;
+
+       if (ptn >= parts->l.d_npartitions)
+               return false;
+
+       for (id = part_index = 0; id < ptn &&
+           part_index < parts->l.d_npartitions; part_index++)
+               if (parts->l.d_partitions[part_index].p_fstype != FS_UNUSED ||
+                   parts->l.d_partitions[part_index].p_size != 0)
+                       id++;
 
        if (part != 0)
-               *part = ptn;
+               *part = part_index;
+
+       pname = 'a'+ part_index;
 
        switch (which_name) {
        case parent_device_only:
@@ -826,18 +842,18 @@
        case plain_name:
                if (with_path)
                        snprintf(devname, max_devname_len, _PATH_DEV "%s%c",
-                           arg->disk, (char)ptn + 'a');
+                           arg->disk, pname);
                else
                        snprintf(devname, max_devname_len, "%s%c",
-                           arg->disk, (char)ptn + 'a');
+                           arg->disk, pname);
                return true;
        case raw_dev_name:
                if (with_path)
                        snprintf(devname, max_devname_len, _PATH_DEV "r%s%c",
-                           arg->disk, (char)ptn + 'a');
+                           arg->disk, pname);
                else
                        snprintf(devname, max_devname_len, "r%s%c",
-                           arg->disk, (char)ptn + 'a');
+                           arg->disk, pname);
                return true;
        }
 
@@ -1024,7 +1040,7 @@
            (const struct disklabel_disk_partitions*)arg;
        char *sl, part;
        ptrdiff_t n;
-       part_id pno;
+       part_id pno, id, i;
 
        sl = strrchr(name, '/');
        if (sl == NULL)
@@ -1040,7 +1056,11 @@
                return NO_PART;
        if (parts->l.d_partitions[pno].p_fstype == FS_UNUSED)
                return NO_PART;
-       return pno;
+       for (id = 0, i = 0; i < pno; i++)
+               if (parts->l.d_partitions[i].p_fstype != FS_UNUSED ||
+                   parts->l.d_partitions[i].p_size != 0)
+                       id++;
+       return id;
 }
 
 static void



Home | Main Index | Thread Index | Old Index