bin/142526: [patch] Cleanups and updates to newfs_msdos(8)

David Naylor naylor.b.david at gmail.com
Thu Jan 14 16:20:04 UTC 2010


The following reply was made to PR bin/142526; it has been noted by GNATS.

From: David Naylor <naylor.b.david at gmail.com>
To: bug-followup at freebsd.org,
 giffunip at tutopia.com
Cc:  
Subject: Re: bin/142526: [patch] Cleanups and updates to newfs_msdos(8)
Date: Thu, 14 Jan 2010 18:13:04 +0200

 --nextPart14527654.YHE7cjX8oQ
 Content-Type: multipart/mixed;
   boundary="Boundary-01=_RK0TLGZ7UiF974l"
 Content-Transfer-Encoding: 7bit
 
 
 --Boundary-01=_RK0TLGZ7UiF974l
 Content-Type: Text/Plain;
   charset="us-ascii"
 Content-Transfer-Encoding: quoted-printable
 Content-Disposition: inline
 
 Hi,
 
 There is an error in handling of sector size (-S):
 
 # newfs_msdos -S 512 /dev/`mdconfig -a -t swap -s 10m`
 =46loating exception (core dumped)
 
 The attached patch (should) fix this problem. =20
 
 Also clang doesn't like some of the comparisons (u_int vs int).  I've chang=
 ed=20
 some of the #define to fix that. =20
 
 Regards
 
 --Boundary-01=_RK0TLGZ7UiF974l
 Content-Type: text/x-patch;
   charset="ISO-8859-1";
   name="newfs_msdos.diff"
 Content-Transfer-Encoding: quoted-printable
 Content-Disposition: attachment;
 	filename="newfs_msdos.diff"
 
 diff -ur /usr/src/sbin/newfs_msdos/newfs_msdos.8 newfs_msdos/newfs_msdos.8
 =2D-- /usr/src/sbin/newfs_msdos/newfs_msdos.8	2009-09-03 08:43:57.000000000=
  +0200
 +++ newfs_msdos/newfs_msdos.8	2010-01-14 16:41:05.000000000 +0200
 @@ -116,7 +116,7 @@
  .It Fl S Ar sector-size
  Number of bytes per sector.
  Acceptable values are powers of 2
 =2Din the range 128 through 32768.
 +in the range 512 through 32768.
  .It Fl a Ar FAT-size
  Number of sectors per FAT.
  .It Fl b Ar block-size
 diff -ur /usr/src/sbin/newfs_msdos/newfs_msdos.c newfs_msdos/newfs_msdos.c
 =2D-- /usr/src/sbin/newfs_msdos/newfs_msdos.c	2009-09-03 08:43:57.000000000=
  +0200
 +++ newfs_msdos/newfs_msdos.c	2010-01-14 18:10:46.000000000 +0200
 @@ -55,6 +55,7 @@
  #define NPB	  2		/* nibbles per byte */
 =20
  #define DOSMAGIC  0xaa55	/* DOS magic number */
 +#define MAXBPS	  4096		/* maximum bytes per sector */
  #define MINBPS	  512		/* minimum bytes per sector */
  #define MAXSPC	  128		/* maximum sectors per cluster */
  #define MAXNFT	  16		/* maximum number of FATs */
 @@ -62,12 +63,12 @@
  #define DEFBLK16  2048		/* default block size FAT16 */
  #define DEFRDE	  512		/* default root directory entries */
  #define RESFTE	  2		/* reserved FAT entries */
 =2D#define MINCLS12  1		/* minimum FAT12 clusters */
 =2D#define MINCLS16  0x1000	/* minimum FAT16 clusters */
 =2D#define MINCLS32  2		/* minimum FAT32 clusters */
 =2D#define MAXCLS12  0xfed 	/* maximum FAT12 clusters */
 =2D#define MAXCLS16  0xfff5	/* maximum FAT16 clusters */
 =2D#define MAXCLS32  0xffffff5	/* maximum FAT32 clusters */
 +#define MINCLS12  1u		/* minimum FAT12 clusters */
 +#define MINCLS16  0x1000u	/* minimum FAT16 clusters */
 +#define MINCLS32  2u		/* minimum FAT32 clusters */
 +#define MAXCLS12  0xfedu 	/* maximum FAT12 clusters */
 +#define MAXCLS16  0xfff5u	/* maximum FAT16 clusters */
 +#define MAXCLS32  0xffffff5u	/* maximum FAT32 clusters */
 =20
  #define mincls(fat)  ((fat) =3D=3D 12 ? MINCLS12 :	\
  		      (fat) =3D=3D 16 ? MINCLS16 :	\
 @@ -165,20 +166,23 @@
 =20
  #define BPBGAP 0, 0, 0, 0, 0, 0
 =20
 +#define INIT(a, b, c, d, e, f, g, h, i, j) \
 +    { .bps =3D a, .spc =3D b, .res =3D c, .nft =3D d, .rde =3D e, \
 +      .sec =3D f, .mid =3D g, .spf =3D h, .spt =3D i, .hds =3D j, }
  static struct {
      const char *name;
      struct bpb bpb;
  } const stdfmt[] =3D {
 =2D    {"160",  {512, 1, 1, 2,  64,  320, 0xfe, 1,  8, 1, BPBGAP}},
 =2D    {"180",  {512, 1, 1, 2,  64,  360, 0xfc, 2,  9, 1, BPBGAP}},
 =2D    {"320",  {512, 2, 1, 2, 112,  640, 0xff, 1,  8, 2, BPBGAP}},
 =2D    {"360",  {512, 2, 1, 2, 112,  720, 0xfd, 2,  9, 2, BPBGAP}},
 =2D    {"640",  {512, 2, 1, 2, 112, 1280, 0xfb, 2,  8, 2, BPBGAP}},   =20
 =2D    {"720",  {512, 2, 1, 2, 112, 1440, 0xf9, 3,  9, 2, BPBGAP}},
 =2D    {"1200", {512, 1, 1, 2, 224, 2400, 0xf9, 7, 15, 2, BPBGAP}},
 =2D    {"1232", {1024,1, 1, 2, 192, 1232, 0xfe, 2,  8, 2, BPBGAP}},   =20
 =2D    {"1440", {512, 1, 1, 2, 224, 2880, 0xf0, 9, 18, 2, BPBGAP}},
 =2D    {"2880", {512, 2, 1, 2, 240, 5760, 0xf0, 9, 36, 2, BPBGAP}}
 +    {"160",  INIT(512, 1, 1, 2,  64,  320, 0xfe, 1,  8, 1)},
 +    {"180",  INIT(512, 1, 1, 2,  64,  360, 0xfc, 2,  9, 1)},
 +    {"320",  INIT(512, 2, 1, 2, 112,  640, 0xff, 1,  8, 2)},
 +    {"360",  INIT(512, 2, 1, 2, 112,  720, 0xfd, 2,  9, 2)},
 +    {"640",  INIT(512, 2, 1, 2, 112, 1280, 0xfb, 2,  8, 2)},   =20
 +    {"720",  INIT(512, 2, 1, 2, 112, 1440, 0xf9, 3,  9, 2)},
 +    {"1200", INIT(512, 1, 1, 2, 224, 2400, 0xf9, 7, 15, 2)},
 +    {"1232", INIT(1024,1, 1, 2, 192, 1232, 0xfe, 2,  8, 2)},   =20
 +    {"1440", INIT(512, 1, 1, 2, 224, 2880, 0xf0, 9, 18, 2)},
 +    {"2880", INIT(512, 2, 1, 2, 240, 5760, 0xf0, 9, 36, 2)}
  };
 =20
  static const u_int8_t bootcode[] =3D {
 @@ -421,7 +425,9 @@
      }
      if (!powerof2(bpb.bps))
  	errx(1, "bytes/sector (%u) is not a power of 2", bpb.bps);
 =2D    if (bpb.bps < MINBPS)
 +    if (bpb.bps > MAXBPS)
 +    	printf( "WARNING: bytes/sector (%u) is too big", bpb.bps);
 +    else if (bpb.bps < MINBPS)
  	errx(1, "bytes/sector (%u) is too small; minimum is %u",
  	     bpb.bps, MINBPS);
      if (!(fat =3D opt_F)) {
 @@ -533,7 +539,7 @@
      if (!bpb.res)
  	bpb.res =3D fat =3D=3D 32 ? MAX(x, MAX(16384 / bpb.bps, 4)) : x;
      else if (bpb.res < x)
 =2D	errx(1, "too few reserved sectors");
 +	errx(1, "too few reserved sectors (need %d have %d)", x, bpb.res);
      if (fat !=3D 32 && !bpb.rde)
  	bpb.rde =3D DEFRDE;
      rds =3D howmany(bpb.rde, bpb.bps / sizeof(struct de));
 @@ -657,8 +663,8 @@
  			 ((u_int)tm->tm_hour << 8 |
  			  (u_int)tm->tm_min));
  		mk4(bsx->volid, x);
 =2D		mklabel(bsx->label, opt_L ? opt_L : "NO NAME");
 =2D		sprintf(buf, "FAT%u", fat);
 +		mklabel(bsx->label, opt_L ? opt_L : "NO_NAME");
 +		snprintf(buf, sizeof(buf), "FAT%u", fat);
  		setstr(bsx->type, buf, sizeof(bsx->type));
  		if (!opt_B) {
  		    x1 +=3D sizeof(struct bsx);
 @@ -666,7 +672,7 @@
  		    mk1(bs->jmp[0], 0xeb);
  		    mk1(bs->jmp[1], x1 - 2);
  		    mk1(bs->jmp[2], 0x90);
 =2D		    setstr(bs->oem, opt_O ? opt_O : "BSD  4.4",
 +		    setstr(bs->oem, opt_O ? opt_O : "BSD4.4  ",
  			   sizeof(bs->oem));
  		    memcpy(img + x1, bootcode, sizeof(bootcode));
  		    mk2(img + MINBPS - 2, DOSMAGIC);
 @@ -794,11 +800,12 @@
 =20
      /* Maybe it's a fixed drive */
      if (lp =3D=3D NULL) {
 +	if (bpb->bps)
 +	    dlp.d_secsize =3D bpb->bps;
  	if (ioctl(fd, DIOCGDINFO, &dlp) =3D=3D -1) {
  	    if (bpb->bps =3D=3D 0 && ioctl(fd, DIOCGSECTORSIZE, &dlp.d_secsize) =
 =3D=3D -1)
  		errx(1, "Cannot get sector size, %s", strerror(errno));
 =20
 =2D	    /* XXX Should we use bpb->bps if it's set? */
  	    dlp.d_secperunit =3D ms / dlp.d_secsize;
 =20
  	    if (bpb->spt =3D=3D 0 && ioctl(fd, DIOCGFWSECTORS, &dlp.d_nsectors) =
 =3D=3D -1) {
 
 --Boundary-01=_RK0TLGZ7UiF974l--
 
 --nextPart14527654.YHE7cjX8oQ
 Content-Type: application/pgp-signature; name=signature.asc 
 Content-Description: This is a digitally signed message part.
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.13 (FreeBSD)
 
 iEYEABECAAYFAktPQpcACgkQUaaFgP9pFrJNXwCgi6v2hLTRMsysqcZZNbgX7XKP
 mdkAni7gdnLgqwXByisCda1Ib7Tf8Av+
 =wsF8
 -----END PGP SIGNATURE-----
 
 --nextPart14527654.YHE7cjX8oQ--


More information about the freebsd-bugs mailing list