[email protected]
[Top] [All Lists]

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

Subject: Re: port-i386/43354: disklabel -i limits partition size to 2**31 on input from terminal
From: Rainer Glaschick
Date: Fri, 28 May 2010 07:00:07 +0000 UTC
The following reply was made to PR bin/43354; it has been noted by GNATS.

From: Rainer Glaschick <[email protected]>
To: [email protected]
Cc: 
Subject: Re: port-i386/43354: disklabel -i limits partition size to 2**31
 on input from terminal
Date: Fri, 28 May 2010 06:58:52 +0200

 The binary compiled by David for me now does it right;
 tried it interactively with sectors, cylinders and megabyte,
 and re-wrote the disklabel successfully.
 
 Bug can be closed from my point of view.
 
 David Holland wrote:
 > The following reply was made to PR port-i386/43354; it has been noted b=
 y GNATS.
 >=20
 > From: David Holland <[email protected]>
 > To: [email protected]
 > Cc:=20
 > 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
 >=20
 >  On Tue, May 25, 2010 at 07:20:01PM +0000, [email protected] 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.
 > =20
 >  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.
 > =20
 >  Index: interact.c
 >  =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
 >  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=20
 >   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);
 >  =20
 >   static int rounding =3D 0; /* sector rounding */
 >   static int chaining =3D 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,=20
 >                                  cp[line[0] - 'a'].p_size;
 >                      }
 >              } else {
 >  -                   if ((i =3D getnum(lp, line, 0)) =3D=3D -1 || i < 0) {
 >  +                   if ((im =3D getnum(lp, line, 0)) =3D=3D -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 =3D i;
 >  +                   p->p_offset =3D (uint32_t)im;
 >              }
 >              break;
 >      }
 >  @@ -522,16 +524,16 @@ cmd_part(struct disklabel *lp, char *s,=20
 >                      return;
 >              else if (i =3D=3D 0)
 >                      break;
 >  -           if ((i =3D getnum(lp, line, lp->d_secperunit - p->p_offset))
 >  +           if ((im =3D getnum(lp, line, lp->d_secperunit - p->p_offset))
 >                  =3D=3D -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 =3D i;
 >  +           p->p_size =3D im;
 >              break;
 >      }
 >  =20
 >  @@ -708,15 +710,15 @@ defnum(struct disklabel *lp, char *buf,=20
 >   }
 >  =20
 >  =20
 >  -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;
 >  =20
 >  -   if (max && buf[0] =3D=3D '$' && buf[1] =3D=3D 0)
 >  -           return max;
 >  +   if (defaultval && buf[0] =3D=3D '$' && buf[1] =3D=3D 0)
 >  +           return defaultval;
 >  =20
 >      d =3D strtod(buf, &ep);
 >      if (buf =3D=3D ep)
 >  @@ -729,32 +731,32 @@ getnum(struct disklabel *lp, char *buf,=20
 >      case '\0':
 >      case 's':
 >      case 'S':
 >  -           rv =3D (int) d;
 >  +           rv =3D (intmax_t) d;
 >              break;
 >  =20
 >      case 'c':
 >      case 'C':
 >  -           rv =3D (int) (d * lp->d_secpercyl);
 >  +           rv =3D (intmax_t) (d * lp->d_secpercyl);
 >              break;
 >  =20
 >      case 'k':
 >      case 'K':
 >  -           rv =3D  (int) (d * 1024 / lp->d_secsize);
 >  +           rv =3D  (intmax_t) (d * 1024 / lp->d_secsize);
 >              break;
 >  =20
 >      case 'm':
 >      case 'M':
 >  -           rv =3D  (int) (d * 1024 * 1024 / lp->d_secsize);
 >  +           rv =3D  (intmax_t) (d * 1024 * 1024 / lp->d_secsize);
 >              break;
 >  =20
 >      case 'g':
 >      case 'G':
 >  -           rv =3D  (int) (d * 1024 * 1024 * 1024 / lp->d_secsize);
 >  +           rv =3D  (intmax_t) (d * 1024 * 1024 * 1024 / lp->d_secsize);
 >              break;
 >  =20
 >      case 't':
 >      case 'T':
 >  -           rv =3D  (int) (d * 1024 * 1024 * 1024 * 1024 / lp->d_secsize);
 >  +           rv =3D  (intmax_t) (d * 1024 * 1024 * 1024 * 1024 / 
 > lp->d_secsize);
 >              break;
 >  =20
 >      default:
 > =20
 > =20
 > =20
 > =20
 >     ------------
 > =20
 > =20
 >  Index: interact.c
 >  =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
 >  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=20
 >   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);
 >  =20
 >   static int rounding =3D 0; /* sector rounding */
 >   static int chaining =3D 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,=20
 >                                  cp[line[0] - 'a'].p_size;
 >                      }
 >              } else {
 >  -                   if ((i =3D getnum(lp, line, 0)) =3D=3D -1) {
 >  +                   if ((im =3D getnum(lp, line, 0)) =3D=3D -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 =3D i;
 >  +                   p->p_offset =3D (uint32_t)im;
 >              }
 >              break;
 >      }
 >  @@ -527,16 +529,16 @@ cmd_part(struct disklabel *lp, char *s,=20
 >                      return;
 >              else if (i =3D=3D 0)
 >                      break;
 >  -           if ((i =3D getnum(lp, line, lp->d_secperunit - p->p_offset))
 >  +           if ((im =3D getnum(lp, line, lp->d_secperunit - p->p_offset))
 >                  =3D=3D -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 =3D i;
 >  +           p->p_size =3D im;
 >              break;
 >      }
 >  =20
 >  @@ -713,15 +715,15 @@ defnum(struct disklabel *lp, char *buf,=20
 >   }
 >  =20
 >  =20
 >  -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;
 >  =20
 >  -   if (max && buf[0] =3D=3D '$' && buf[1] =3D=3D 0)
 >  -           return max;
 >  +   if (defaultval && buf[0] =3D=3D '$' && buf[1] =3D=3D 0)
 >  +           return defaultval;
 >  =20
 >      d =3D strtod(buf, &ep);
 >      if (buf =3D=3D ep)
 >  @@ -734,32 +736,32 @@ getnum(struct disklabel *lp, char *buf,=20
 >      case '\0':
 >      case 's':
 >      case 'S':
 >  -           rv =3D (int) d;
 >  +           rv =3D (intmax_t) d;
 >              break;
 >  =20
 >      case 'c':
 >      case 'C':
 >  -           rv =3D (int) (d * lp->d_secpercyl);
 >  +           rv =3D (intmax_t) (d * lp->d_secpercyl);
 >              break;
 >  =20
 >      case 'k':
 >      case 'K':
 >  -           rv =3D  (int) (d * 1024 / lp->d_secsize);
 >  +           rv =3D  (intmax_t) (d * 1024 / lp->d_secsize);
 >              break;
 >  =20
 >      case 'm':
 >      case 'M':
 >  -           rv =3D  (int) (d * 1024 * 1024 / lp->d_secsize);
 >  +           rv =3D  (intmax_t) (d * 1024 * 1024 / lp->d_secsize);
 >              break;
 >  =20
 >      case 'g':
 >      case 'G':
 >  -           rv =3D  (int) (d * 1024 * 1024 * 1024 / lp->d_secsize);
 >  +           rv =3D  (intmax_t) (d * 1024 * 1024 * 1024 / lp->d_secsize);
 >              break;
 >  =20
 >      case 't':
 >      case 'T':
 >  -           rv =3D  (int) (d * 1024 * 1024 * 1024 * 1024 / lp->d_secsize);
 >  +           rv =3D  (intmax_t) (d * 1024 * 1024 * 1024 * 1024 / 
 > lp->d_secsize);
 >              break;
 >  =20
 >      default:
 > =20
 > =20
 >  --=20
 >  David A. Holland
 >  [email protected]
 > =20
 
 --=20
 Rainer Glaschick
 email: [email protected]
 Paderborn, Germany
 Pers=F6nliche nicht=F6ffentliche Nachricht / personal private message
 

<Prev in Thread] Current Thread [Next in Thread>