Module Name: src Committed By: dsl Date: Sat Jan 2 21:16:47 UTC 2010
Modified Files: src/distrib/utils/sysinst: Makefile.inc defs.h label.c mbr.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.48 -r1.49 src/distrib/utils/sysinst/Makefile.inc cvs rdiff -u -r1.146 -r1.147 src/distrib/utils/sysinst/defs.h cvs rdiff -u -r1.53 -r1.54 src/distrib/utils/sysinst/label.c cvs rdiff -u -r1.81 -r1.82 src/distrib/utils/sysinst/mbr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/utils/sysinst/Makefile.inc diff -u src/distrib/utils/sysinst/Makefile.inc:1.48 src/distrib/utils/sysinst/Makefile.inc:1.49 --- src/distrib/utils/sysinst/Makefile.inc:1.48 Sun Aug 23 20:58:05 2009 +++ src/distrib/utils/sysinst/Makefile.inc Sat Jan 2 21:16:46 2010 @@ -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 \ Index: src/distrib/utils/sysinst/defs.h diff -u src/distrib/utils/sysinst/defs.h:1.146 src/distrib/utils/sysinst/defs.h:1.147 --- src/distrib/utils/sysinst/defs.h:1.146 Sun Oct 18 12:09:48 2009 +++ src/distrib/utils/sysinst/defs.h Sat Jan 2 21:16:46 2010 @@ -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); Index: src/distrib/utils/sysinst/label.c diff -u src/distrib/utils/sysinst/label.c:1.53 src/distrib/utils/sysinst/label.c:1.54 --- src/distrib/utils/sysinst/label.c:1.53 Sun Feb 22 11:21:56 2009 +++ src/distrib/utils/sysinst/label.c Sat Jan 2 21:16:46 2010 @@ -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; } Index: src/distrib/utils/sysinst/mbr.c diff -u src/distrib/utils/sysinst/mbr.c:1.81 src/distrib/utils/sysinst/mbr.c:1.82 --- src/distrib/utils/sysinst/mbr.c:1.81 Sat Sep 19 14:57:27 2009 +++ src/distrib/utils/sysinst/mbr.c Sat Jan 2 21:16:46 2010 @@ -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) { partinfo *p; uint end; - /* Allow for size being -ve, get it right for very large partitions */ - end = start + size; - if (end < start) { + if (size > 0) { + end = start + size; + } else { end = start; - start = end + size; + start = end - size; } if (end == 0) @@ -275,9 +275,9 @@ } static int -find_mbr_space(struct mbr_sector *mbrs, uint *start, uint *size, int from, int ignore) +find_mbr_space(struct mbr_sector *mbrs, uint *start, uint *size, uint from, int ignore) { - int sz; + uint sz; int i; uint s, e; @@ -498,7 +498,7 @@ { static menu_ent type_opts[1 + nelem(part_ids)]; static int type_menu = -1; - int i; + unsigned int i; if (type_menu == -1) { for (i = 0; i < nelem(type_opts); i++) { @@ -527,7 +527,7 @@ int opt = mbri->opt; uint start, sz; uint new_r, new, limit, dflt_r; - int delta; + int64_t delta; const char *errmsg; char *cp; struct { @@ -535,10 +535,10 @@ uint start_r; uint limit; } freespace[MBR_PART_COUNT]; - int spaces; - int i; + unsigned int spaces; + unsigned int i; char prompt[MBR_PART_COUNT * 60]; - int len; + unsigned int len; char numbuf[12]; if (opt >= MBR_PART_COUNT) @@ -815,7 +815,7 @@ break; } - if (opt >= MBR_PART_COUNT && max - new <= bsec) + if (opt >= MBR_PART_COUNT && max - new <= (uint32_t)bsec) /* Round up if not enough space for a header for free area */ new = max; @@ -823,7 +823,7 @@ /* Kill information about old partition from label */ mbri->last_mounted[opt < MBR_PART_COUNT ? opt : 0] = NULL; remove_old_partitions(mbri->sector + mbrp->mbrp_start + - mbrp->mbrp_size, new - mbrp->mbrp_size); + mbrp->mbrp_size, (int64_t)new - mbrp->mbrp_size); } mbrp->mbrp_size = new; @@ -1340,7 +1340,7 @@ } /* Install in only netbsd partition if none tagged */ - if (ptstart == 0 && bsdstart != ~0) { + if (ptstart == 0 && bsdstart != ~0u) { ptstart = bsdstart; ptsize = bsdsize; } @@ -1425,7 +1425,7 @@ for (;;) { if (pread(fd, mbrs, sizeof *mbrs, - (ext_base + next_ext) * (off_t)MBR_SECSIZE) < sizeof *mbrs) + (ext_base + next_ext) * (off_t)MBR_SECSIZE) - sizeof *mbrs != 0) break; if (!valid_mbr(mbrs)) @@ -1706,7 +1706,7 @@ int xcylinders, xheads, i, j; daddr_t xsectors; int c1, h1, s1, c2, h2, s2; - unsigned long a1, a2; + daddr_t a1, a2; uint64_t num, denom; /* @@ -1791,7 +1791,7 @@ static int get_mapping(struct mbr_partition *parts, int i, - int *cylinder, int *head, int *sector, unsigned long *absolute) + int *cylinder, int *head, int *sector, daddr_t *absolute) { struct mbr_partition *apart = &parts[i / 2]; @@ -1810,7 +1810,7 @@ + le32toh(apart->mbrp_size) - 1; } /* Sanity check the data against max values */ - if ((((*cylinder * MAXHEAD) + *head) * MAXSECTOR + *sector) < *absolute) + if ((((*cylinder * MAXHEAD) + *head) * (uint32_t)MAXSECTOR + *sector) < *absolute) /* cannot be a CHS mapping */ return -1;