Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/sysinst PR 55381: try to deal with moved (but not y...



details:   https://anonhg.NetBSD.org/src/rev/2b70d97c6205
branches:  trunk
changeset: 955443:2b70d97c6205
user:      martin <martin%NetBSD.org@localhost>
date:      Tue Sep 29 14:29:56 2020 +0000

description:
PR 55381: try to deal with moved (but not yet saved) partitions when
calculating free space

diffstat:

 usr.sbin/sysinst/defs.h      |   6 +++---
 usr.sbin/sysinst/label.c     |  21 +++++++++++++++------
 usr.sbin/sysinst/part_edit.c |  13 +++++++++----
 3 files changed, 27 insertions(+), 13 deletions(-)

diffs (117 lines):

diff -r ade4a746513e -r 2b70d97c6205 usr.sbin/sysinst/defs.h
--- a/usr.sbin/sysinst/defs.h   Tue Sep 29 14:08:43 2020 +0000
+++ b/usr.sbin/sysinst/defs.h   Tue Sep 29 14:29:56 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.63 2020/09/22 16:18:54 martin Exp $ */
+/*     $NetBSD: defs.h,v 1.64 2020/09/29 14:29:56 martin Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -737,8 +737,8 @@
 int    edit_and_check_label(struct pm_devs *p, struct partition_usage_set *pset, bool install);
 int edit_ptn(menudesc *, void *);
 int checkoverlap(struct disk_partitions *parts);
-daddr_t getpartsize(struct disk_partitions *parts, daddr_t partstart,
-    daddr_t defpartsize);
+daddr_t getpartsize(struct disk_partitions *parts, daddr_t orig_start,
+    daddr_t partstart, daddr_t defpartsize);
 daddr_t getpartoff(struct disk_partitions *parts, daddr_t defpartstart);
 
 /* from install.c */
diff -r ade4a746513e -r 2b70d97c6205 usr.sbin/sysinst/label.c
--- a/usr.sbin/sysinst/label.c  Tue Sep 29 14:08:43 2020 +0000
+++ b/usr.sbin/sysinst/label.c  Tue Sep 29 14:29:56 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: label.c,v 1.24 2020/09/22 16:18:54 martin Exp $        */
+/*     $NetBSD: label.c,v 1.25 2020/09/29 14:29:56 martin Exp $        */
 
 /*
  * Copyright 1997 Jonathan Stone
@@ -36,7 +36,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: label.c,v 1.24 2020/09/22 16:18:54 martin Exp $");
+__RCSID("$NetBSD: label.c,v 1.25 2020/09/29 14:29:56 martin Exp $");
 #endif
 
 #include <sys/types.h>
@@ -291,10 +291,15 @@
 edit_fs_size(menudesc *m, void *arg)
 {
        struct single_part_fs_edit *edit = arg;
+       struct disk_part_info pinfo;
        daddr_t size;
 
-       size = getpartsize(edit->pset->parts, edit->info.start,
-           edit->info.size);
+       /* get original partition data, in case start moved already */
+       edit->pset->parts->pscheme->get_part_info(edit->pset->parts,
+           edit->id, &pinfo);
+       /* ask for new size with old start and current values */
+       size = getpartsize(edit->pset->parts, pinfo.start,
+           edit->info.start, edit->info.size);
        if (size < 0)
                return 0;
        if (size > edit->pset->parts->disk_size)
@@ -2040,7 +2045,8 @@
 
 /* Ask for a partition size, check bounds and do the needed roundups */
 daddr_t
-getpartsize(struct disk_partitions *parts, daddr_t partstart, daddr_t dflt)
+getpartsize(struct disk_partitions *parts, daddr_t orig_start,
+    daddr_t partstart, daddr_t dflt)
 {
        char dsize[24], isize[24], max_size[24], maxpartc, valid_parts[4],
            *label_msg, *prompt, *head, *hint, *tail;
@@ -2050,7 +2056,10 @@
        part_id partn;
 
        diskend = parts->disk_start + parts->disk_size;
-       max = parts->pscheme->max_free_space_at(parts, partstart);
+       max = parts->pscheme->max_free_space_at(parts, orig_start);
+       max += orig_start - partstart;
+       if (sizemult == 1)
+               max--;  /* with hugher scale proper rounding later will be ok */
 
        /* We need to keep both the unrounded and rounded (_r) max and dflt */
        dflt_r = (partstart + dflt) / sizemult - partstart / sizemult;
diff -r ade4a746513e -r 2b70d97c6205 usr.sbin/sysinst/part_edit.c
--- a/usr.sbin/sysinst/part_edit.c      Tue Sep 29 14:08:43 2020 +0000
+++ b/usr.sbin/sysinst/part_edit.c      Tue Sep 29 14:29:56 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: part_edit.c,v 1.16 2020/01/27 21:21:22 martin Exp $ */
+/*     $NetBSD: part_edit.c,v 1.17 2020/09/29 14:29:56 martin Exp $ */
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -211,11 +211,14 @@
 edit_part_start(menudesc *m, void *arg)
 {
        struct part_edit_info *marg = arg;
+       struct disk_part_info pinfo;
        daddr_t max_size;
 
+       marg->parts->pscheme->get_part_info(marg->parts, marg->cur_id, &pinfo);
        marg->cur.start = getpartoff(marg->parts, marg->cur.start);
        max_size = marg->parts->pscheme->max_free_space_at(marg->parts,
-           marg->cur.start);
+           pinfo.start);
+       max_size += pinfo.start - marg->cur.start;
        if (marg->cur.size > max_size)
                marg->cur.size = max_size;
 
@@ -226,9 +229,11 @@
 edit_part_size(menudesc *m, void *arg)
 {
        struct part_edit_info *marg = arg;
+       struct disk_part_info pinfo;
 
-       marg->cur.size = getpartsize(marg->parts, marg->cur.start,
-           marg->cur.size);
+       marg->parts->pscheme->get_part_info(marg->parts, marg->cur_id, &pinfo);
+       marg->cur.size = getpartsize(marg->parts, pinfo.start,
+           marg->cur.start, marg->cur.size);
 
        return 0;
 }



Home | Main Index | Thread Index | Old Index