Source-Changes-HG archive

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

[src/trunk]: src/distrib/utils/sysinst Change most of the variables that hold...



details:   https://anonhg.NetBSD.org/src/rev/6371ecf329be
branches:  trunk
changeset: 750487:6371ecf329be
user:      dsl <dsl%NetBSD.org@localhost>
date:      Sat Jan 02 21:16:46 2010 +0000

description:
Change most of the variables that hold disk sector number to be (at least)
uint32_t. Might make sysinst work on disks between 1TB and 2TB.
Not actually tested because I don't have a big disk.
Hopefully I haven't broken the small disk case!
Set WARNS= 4 so that comparisons of signed and unsigned block numbers
are trapped.

diffstat:

 distrib/utils/sysinst/Makefile.inc |   4 +-
 distrib/utils/sysinst/defs.h       |   6 +-
 distrib/utils/sysinst/label.c      |  94 +++++++++++++++++++-------------------
 distrib/utils/sysinst/mbr.c        |  42 ++++++++--------
 4 files changed, 72 insertions(+), 74 deletions(-)

diffs (truncated from 423 to 300 lines):

diff -r c42227309e66 -r 6371ecf329be distrib/utils/sysinst/Makefile.inc
--- a/distrib/utils/sysinst/Makefile.inc        Sat Jan 02 20:54:46 2010 +0000
+++ b/distrib/utils/sysinst/Makefile.inc        Sat Jan 02 21:16:46 2010 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.inc,v 1.48 2009/08/23 20:58:05 jmcneill Exp $
+#      $NetBSD: Makefile.inc,v 1.49 2010/01/02 21:16:46 dsl Exp $
 #
 # Makefile for sysinst
 
@@ -7,7 +7,7 @@
 PROG=          sysinst
 NOMAN=         # defined
 
-WARNS=         3
+WARNS=         4
 
 SRCS+= menu_defs.c msg_defs.c main.c install.c upgrade.c \
        txtwalk.c run.c factor.c net.c disks.c disks_lfs.c util.c geom.c \
diff -r c42227309e66 -r 6371ecf329be distrib/utils/sysinst/defs.h
--- a/distrib/utils/sysinst/defs.h      Sat Jan 02 20:54:46 2010 +0000
+++ b/distrib/utils/sysinst/defs.h      Sat Jan 02 21:16:46 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.146 2009/10/18 12:09:48 ahoka Exp $ */
+/*     $NetBSD: defs.h,v 1.147 2010/01/02 21:16:46 dsl Exp $   */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -153,7 +153,7 @@
 
 /* Round up to the next full cylinder size */
 #define NUMSEC(size, sizemult, cylsize) \
-       ((size) == -1 ? -1 : (sizemult) == 1 ? (size) : \
+       ((size) == ~0u ? ~0u : (sizemult) == 1 ? (size) : \
         roundup((size) * (sizemult), (cylsize)))
 
 /* What FS type? */
@@ -354,8 +354,6 @@
 int    savenewlabel(partinfo *, int);
 int    incorelabel(const char *, partinfo *);
 int    edit_and_check_label(partinfo *, int, int, int);
-int    getpartoff(int);
-int    getpartsize(int, int);
 void   set_bsize(partinfo *, int);
 void   set_fsize(partinfo *, int);
 void   set_ptype(partinfo *, int, int);
diff -r c42227309e66 -r 6371ecf329be distrib/utils/sysinst/label.c
--- a/distrib/utils/sysinst/label.c     Sat Jan 02 20:54:46 2010 +0000
+++ b/distrib/utils/sysinst/label.c     Sat Jan 02 21:16:46 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: label.c,v 1.53 2009/02/22 11:21:56 ad Exp $    */
+/*     $NetBSD: label.c,v 1.54 2010/01/02 21:16:46 dsl 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.53 2009/02/22 11:21:56 ad Exp $");
+__RCSID("$NetBSD: label.c,v 1.54 2010/01/02 21:16:46 dsl Exp $");
 #endif
 
 #include <sys/types.h>
@@ -63,9 +63,11 @@
  * local prototypes
  */
 static int boringpart(partinfo *, int, int, int);
+static uint32_t getpartoff(uint32_t);
+static uint32_t getpartsize(uint32_t, uint32_t);
 
 static int     checklabel(partinfo *, int, int, int, int *, int *);
-static void    atofsb(const char *, int *, int *);
+static int     atofsb(const char *, uint32_t *, uint32_t *);
 
 
 /*
@@ -102,7 +104,7 @@
 
        for (i = 0; i < nparts - 1; i ++ ) {
                partinfo *ip = &lp[i];
-               int istart, istop;
+               uint32_t istart, istop;
 
                /* skip unused or reserved partitions */
                if (boringpart(lp, i, rawpart, bsdpart))
@@ -117,7 +119,7 @@
 
                for (j = i+1; j < nparts; j++) {
                        partinfo *jp = &lp[j];
-                       int jstart, jstop;
+                       uint32_t jstart, jstop;
 
                        /* skip unused or reserved partitions */
                        if (boringpart(lp, j, rawpart, bsdpart))
@@ -168,16 +170,16 @@
 edit_fs_start(menudesc *m, void *arg)
 {
        partinfo *p = arg;
-       int start, size;
+       uint32_t start, end;
 
        start = getpartoff(p->pi_offset);
-       size = p->pi_size;
-       if (size != 0) {
+       if (p->pi_size != 0) {
                /* Try to keep end in the same place */
-               size += p->pi_offset - start;
-               if (size < 0)
-                       size = 0;
-               p->pi_size = size;
+               end = p->pi_offset + p->pi_size;
+               if (end < start)
+                       p->pi_size = 0;
+               else
+                       p->pi_size = end - start;
        }
        p->pi_offset = start;
        return 0;
@@ -187,10 +189,10 @@
 edit_fs_size(menudesc *m, void *arg)
 {
        partinfo *p = arg;
-       int size;
+       uint32_t size;
 
        size = getpartsize(p->pi_offset, p->pi_size);
-       if (size == -1)
+       if (size == ~0u)
                size = dlsize - p->pi_offset;
        p->pi_size = size;
        return 0;
@@ -369,7 +371,7 @@
        static int fspart_menu = -1;
        static menu_ent all_fstypes[FSMAXTYPES];
        partinfo *p, p_save;
-       int i;
+       unsigned int i;
 
        if (fspart_menu == -1) {
                fspart_menu = new_menu(NULL, fs_fields, nelem(fs_fields),
@@ -779,11 +781,13 @@
 }
 
 /* Ask for a partition offset, check bounds and do the needed roundups */
-int
-getpartoff(int defpartstart)
+static uint32_t
+getpartoff(uint32_t defpartstart)
 {
        char defsize[20], isize[20], maxpartc;
-       int i, localsizemult, partn;
+       uint32_t i;
+       uint32_t localsizemult;
+       int partn;
        const char *errmsg = "\n";
 
        maxpartc = 'a' + getmaxpartitions() - 1;
@@ -803,11 +807,11 @@
                } else if (atoi(isize) == -1) {
                        i = ptstart;
                        localsizemult = 1;
-               } else
-                       atofsb(isize, &i, &localsizemult);
-               if (i < 0) {
-                       errmsg = msg_string(MSG_invalid_sector_number);
-                       continue;
+               } else {
+                       if (atofsb(isize, &i, &localsizemult)) {
+                               errmsg = msg_string(MSG_invalid_sector_number);
+                               continue;
+                       }
                }
                /* round to cylinder size if localsizemult != 1 */
                i = NUMSEC(i/localsizemult, localsizemult, dlcylsize);
@@ -825,13 +829,13 @@
 
 
 /* Ask for a partition size, check bounds and do the needed roundups */
-int
-getpartsize(int partstart, int defpartsize)
+static uint32_t
+getpartsize(uint32_t partstart, uint32_t defpartsize)
 {
        char dsize[20], isize[20], maxpartc;
        const char *errmsg = "\n";
-       int i, partend, localsizemult;
-       int fsptend = ptstart + ptsize;
+       uint32_t i, partend, localsizemult;
+       uint32_t fsptend = ptstart + ptsize;
        int partn;
 
        maxpartc = 'a' + getmaxpartitions() - 1;
@@ -850,11 +854,11 @@
                } else if (atoi(isize) == -1) {
                        i = fsptend - partstart;
                        localsizemult = 1;
-               } else
-                       atofsb(isize, &i, &localsizemult);
-               if (i < 0) {
-                       errmsg = msg_string(MSG_invalid_sector_number);
-                       continue;
+               } else {
+                       if (atofsb(isize, &i, &localsizemult)) {
+                               errmsg = msg_string(MSG_invalid_sector_number);
+                               continue;
+                       }
                }
                /*
                 * partend is aligned to a cylinder if localsizemult
@@ -863,11 +867,11 @@
                partend = NUMSEC((partstart + i) / localsizemult,
                    localsizemult, dlcylsize);
                /* Align to end-of-disk or end-of-slice if close enough */
-               i = dlsize - partend;
-               if (i > -localsizemult && i < localsizemult)
+               if (partend > (dlsize - localsizemult)
+                   && partend < (dlsize + localsizemult))
                        partend = dlsize;
-               i = fsptend - partend;
-               if (i > -localsizemult && i < localsizemult)
+               if (partend > (fsptend - localsizemult)
+                   && partend < (fsptend + localsizemult))
                        partend = fsptend;
                /* sanity checks */
                if (partend > dlsize) {
@@ -876,7 +880,6 @@
                            NULL, isize, 1,
                            (partend - partstart) / sizemult, multname);
                }
-               /* return value */
                return (partend - partstart);
        }
        /* NOTREACHED */
@@ -891,16 +894,15 @@
  * returns the number of sectors, and the unit used (for roundups).
  */
 
-static void
-atofsb(const char *str, int *p_val, int *localsizemult)
+static int
+atofsb(const char *str, uint32_t *p_val, uint32_t *localsizemult)
 {
        int i;
-       int val;
+       uint32_t val;
 
        *localsizemult = sizemult;
        if (str[0] == '\0') {
-               *p_val = -1;
-               return;
+               return 1;
        }
        val = 0;
        for (i = 0; str[i] != '\0'; i++) {
@@ -910,8 +912,7 @@
                }
                if (str[i + 1] != '\0') {
                        /* A non-digit caracter, not at the end */
-                       *p_val = -1;
-                       return;
+                       return 1;
                }
                if (str[i] == 'G' || str[i] == 'g') {
                        val *= 1024;
@@ -931,9 +932,8 @@
                        break;
                }
                /* not a known unit */
-               *p_val = -1;
-               return;
+               return 1;
        }
        *p_val = val * (*localsizemult);
-       return;
+       return 0;
 }
diff -r c42227309e66 -r 6371ecf329be distrib/utils/sysinst/mbr.c
--- a/distrib/utils/sysinst/mbr.c       Sat Jan 02 20:54:46 2010 +0000
+++ b/distrib/utils/sysinst/mbr.c       Sat Jan 02 21:16:46 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mbr.c,v 1.81 2009/09/19 14:57:27 abs Exp $ */
+/*     $NetBSD: mbr.c,v 1.82 2010/01/02 21:16:46 dsl Exp $ */
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -114,7 +114,7 @@
 };
 
 static int get_mapping(struct mbr_partition *, int, int *, int *, int *,
-                           unsigned long *);
+                           daddr_t *);
 static void convert_mbr_chs(int, int, int, uint8_t *, uint8_t *,
                                 uint8_t *, uint32_t);
 
@@ -252,16 +252,16 @@
  * in the netbsd disklabel to the part we changed.
  */
 static void
-remove_old_partitions(uint start, int size)
+remove_old_partitions(uint start, int64_t size)



Home | Main Index | Thread Index | Old Index