NetBSD-Bugs archive

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

Re: port-i386/43354: disklabel -i limits partition size to 2**31 on input from terminal



The following reply was made to PR port-i386/43354; it has been noted by GNATS.

From: David Holland <dholland-bugs%netbsd.org@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: 
Subject: Re: port-i386/43354: disklabel -i limits partition size to 2**31
        on input from terminal
Date: Thu, 27 May 2010 06:37:17 +0000

 On Tue, May 25, 2010 at 07:20:01PM +0000, rg%g-pb.de@localhost wrote:
  > Using disklabel -i for a disk with more than 1 TByte, a partition
  > cannot be set for more than 1 TByte interactively, i.e. the number
  > of sectors is limited to 2**31, whether given as sectors, cylinders
  > or Megabytes.
 
 Here's a candidate patch. I can't test it as I don't have a disk large
 enough, but it at least compiles. The first patch is for current, the
 second for 5.x.
 
 Index: interact.c
 ===================================================================
 RCS file: /cvsroot/src/sbin/disklabel/interact.c,v
 retrieving revision 1.33
 diff -u -p -r1.33 interact.c
 --- interact.c 28 Nov 2009 10:52:10 -0000      1.33
 +++ interact.c 27 May 2010 06:15:23 -0000
 @@ -67,7 +67,7 @@ static int   getinput(const char *, const 
  static int    alphacmp(const void *, const void *);
  static void   defnum(struct disklabel *, char *, uint32_t);
  static void   dumpnames(const char *, const char * const *, size_t);
 -static int    getnum(struct disklabel *, char *, int);
 +static intmax_t       getnum(struct disklabel *, char *, intmax_t);
  
  static int rounding = 0;      /* sector rounding */
  static int chaining = 0;      /* make partitions contiguous */
 @@ -444,6 +444,7 @@ static void
  cmd_part(struct disklabel *lp, char *s, int fd)
  {
        int     i;
 +      intmax_t im;
        char    line[BUFSIZ];
        char    def[BUFSIZ];
        int     part;
 @@ -503,14 +504,15 @@ cmd_part(struct disklabel *lp, char *s, 
                                    cp[line[0] - 'a'].p_size;
                        }
                } else {
 -                      if ((i = getnum(lp, line, 0)) == -1 || i < 0) {
 +                      if ((im = getnum(lp, line, 0)) == -1 || im < 0) {
                                printf("Bad offset `%s'\n", line);
                                continue;
 -                      } else if ((uint32_t)i > lp->d_secperunit) {
 +                      } else if (im > 0xffffffffLL ||
 +                                 (uint32_t)im > lp->d_secperunit) {
                                printf("Offset `%s' out of range\n", line);
                                continue;
                        }
 -                      p->p_offset = i;
 +                      p->p_offset = (uint32_t)im;
                }
                break;
        }
 @@ -522,16 +524,16 @@ cmd_part(struct disklabel *lp, char *s, 
                        return;
                else if (i == 0)
                        break;
 -              if ((i = getnum(lp, line, lp->d_secperunit - p->p_offset))
 +              if ((im = getnum(lp, line, lp->d_secperunit - p->p_offset))
                    == -1) {
                        printf("Bad size `%s'\n", line);
                        continue;
 -              } else if
 -                  ((i + p->p_offset) > lp->d_secperunit) {
 +              } else if (im > 0xffffffffLL ||
 +                         (im + p->p_offset) > lp->d_secperunit) {
                        printf("Size `%s' out of range\n", line);
                        continue;
                }
 -              p->p_size = i;
 +              p->p_size = im;
                break;
        }
  
 @@ -708,15 +710,15 @@ defnum(struct disklabel *lp, char *buf, 
  }
  
  
 -static int
 -getnum(struct disklabel *lp, char *buf, int max)
 +static intmax_t
 +getnum(struct disklabel *lp, char *buf, intmax_t defaultval)
  {
        char    *ep;
        double   d;
 -      int      rv;
 +      intmax_t rv;
  
 -      if (max && buf[0] == '$' && buf[1] == 0)
 -              return max;
 +      if (defaultval && buf[0] == '$' && buf[1] == 0)
 +              return defaultval;
  
        d = strtod(buf, &ep);
        if (buf == ep)
 @@ -729,32 +731,32 @@ getnum(struct disklabel *lp, char *buf, 
        case '\0':
        case 's':
        case 'S':
 -              rv = (int) d;
 +              rv = (intmax_t) d;
                break;
  
        case 'c':
        case 'C':
 -              rv = (int) (d * lp->d_secpercyl);
 +              rv = (intmax_t) (d * lp->d_secpercyl);
                break;
  
        case 'k':
        case 'K':
 -              rv =  (int) (d * 1024 / lp->d_secsize);
 +              rv =  (intmax_t) (d * 1024 / lp->d_secsize);
                break;
  
        case 'm':
        case 'M':
 -              rv =  (int) (d * 1024 * 1024 / lp->d_secsize);
 +              rv =  (intmax_t) (d * 1024 * 1024 / lp->d_secsize);
                break;
  
        case 'g':
        case 'G':
 -              rv =  (int) (d * 1024 * 1024 * 1024 / lp->d_secsize);
 +              rv =  (intmax_t) (d * 1024 * 1024 * 1024 / lp->d_secsize);
                break;
  
        case 't':
        case 'T':
 -              rv =  (int) (d * 1024 * 1024 * 1024 * 1024 / lp->d_secsize);
 +              rv =  (intmax_t) (d * 1024 * 1024 * 1024 * 1024 / 
lp->d_secsize);
                break;
  
        default:
 
 
 
 
    ------------
 
 
 Index: interact.c
 ===================================================================
 RCS file: /cvsroot/src/sbin/disklabel/interact.c,v
 retrieving revision 1.30
 diff -u -p -r1.30 interact.c
 --- interact.c 26 Nov 2006 16:16:31 -0000      1.30
 +++ interact.c 27 May 2010 06:35:17 -0000
 @@ -72,7 +72,7 @@ static int   getinput(const char *, const 
  static int    alphacmp(const void *, const void *);
  static void   defnum(struct disklabel *, char *, uint32_t);
  static void   dumpnames(const char *, const char * const *, size_t);
 -static int    getnum(struct disklabel *, char *, int);
 +static intmax_t       getnum(struct disklabel *, char *, intmax_t);
  
  static int rounding = 0;      /* sector rounding */
  static int chaining = 0;      /* make partitions contiguous */
 @@ -449,6 +449,7 @@ static void
  cmd_part(struct disklabel *lp, char *s, int fd)
  {
        int     i;
 +      intmax_t im;
        char    line[BUFSIZ];
        char    def[BUFSIZ];
        int     part;
 @@ -508,14 +509,15 @@ cmd_part(struct disklabel *lp, char *s, 
                                    cp[line[0] - 'a'].p_size;
                        }
                } else {
 -                      if ((i = getnum(lp, line, 0)) == -1) {
 +                      if ((im = getnum(lp, line, 0)) == -1 || im < 0) {
                                printf("Bad offset `%s'\n", line);
                                continue;
 -                      } else if (i > lp->d_secperunit) {
 +                      } else if (im > 0xffffffffLL ||
 +                                 (uint32_t)im > lp->d_secperunit) {
                                printf("Offset `%s' out of range\n", line);
                                continue;
                        }
 -                      p->p_offset = i;
 +                      p->p_offset = (uint32_t)im;
                }
                break;
        }
 @@ -527,16 +529,16 @@ cmd_part(struct disklabel *lp, char *s, 
                        return;
                else if (i == 0)
                        break;
 -              if ((i = getnum(lp, line, lp->d_secperunit - p->p_offset))
 +              if ((im = getnum(lp, line, lp->d_secperunit - p->p_offset))
                    == -1) {
                        printf("Bad size `%s'\n", line);
                        continue;
 -              } else if
 -                  ((i + p->p_offset) > lp->d_secperunit) {
 +              } else if (im > 0xffffffffLL ||
 +                         (im + p->p_offset) > lp->d_secperunit) {
                        printf("Size `%s' out of range\n", line);
                        continue;
                }
 -              p->p_size = i;
 +              p->p_size = im;
                break;
        }
  
 @@ -713,15 +715,15 @@ defnum(struct disklabel *lp, char *buf, 
  }
  
  
 -static int
 -getnum(struct disklabel *lp, char *buf, int max)
 +static intmax_t
 +getnum(struct disklabel *lp, char *buf, intmax_t defaultval)
  {
        char    *ep;
        double   d;
 -      int      rv;
 +      intmax_t rv;
  
 -      if (max && buf[0] == '$' && buf[1] == 0)
 -              return max;
 +      if (defaultval && buf[0] == '$' && buf[1] == 0)
 +              return defaultval;
  
        d = strtod(buf, &ep);
        if (buf == ep)
 @@ -734,32 +736,32 @@ getnum(struct disklabel *lp, char *buf, 
        case '\0':
        case 's':
        case 'S':
 -              rv = (int) d;
 +              rv = (intmax_t) d;
                break;
  
        case 'c':
        case 'C':
 -              rv = (int) (d * lp->d_secpercyl);
 +              rv = (intmax_t) (d * lp->d_secpercyl);
                break;
  
        case 'k':
        case 'K':
 -              rv =  (int) (d * 1024 / lp->d_secsize);
 +              rv =  (intmax_t) (d * 1024 / lp->d_secsize);
                break;
  
        case 'm':
        case 'M':
 -              rv =  (int) (d * 1024 * 1024 / lp->d_secsize);
 +              rv =  (intmax_t) (d * 1024 * 1024 / lp->d_secsize);
                break;
  
        case 'g':
        case 'G':
 -              rv =  (int) (d * 1024 * 1024 * 1024 / lp->d_secsize);
 +              rv =  (intmax_t) (d * 1024 * 1024 * 1024 / lp->d_secsize);
                break;
  
        case 't':
        case 'T':
 -              rv =  (int) (d * 1024 * 1024 * 1024 * 1024 / lp->d_secsize);
 +              rv =  (intmax_t) (d * 1024 * 1024 * 1024 * 1024 / 
lp->d_secsize);
                break;
  
        default:
 
 
 -- 
 David A. Holland
 dholland%netbsd.org@localhost
 


Home | Main Index | Thread Index | Old Index