Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 10 Jan 2010 06:06:57 -0800 (PST)
From:      "Pedro F. Giffuni" <giffunip@tutopia.com>
To:        FreeBSD-gnats-submit@FreeBSD.org, freebsd-bugs@FreeBSD.org
Subject:   Re: bin/142526: Cleanups and updates to newfs_msdos
Message-ID:  <346723.73967.qm@web113505.mail.gq1.yahoo.com>

next in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
Update:
Some people (hi Bruce!) have used non-standard bytes/sector successfully
in the past so permit formatting of non-standard blocksizes but warn
about it.


      
[-- Attachment #2 --]
diff -ru newfs_msdos.orig/newfs_msdos.8 newfs_msdos/newfs_msdos.8
--- newfs_msdos.orig/newfs_msdos.8	2010-01-06 11:06:02.000000000 +0000
+++ newfs_msdos/newfs_msdos.8	2010-01-09 10:25:12.000000000 +0000
@@ -116,7 +116,7 @@
 .It Fl S Ar sector-size
 Number of bytes per sector.
 Acceptable values are powers of 2
-in the range 128 through 32768.
+in the range 512 through 4096.
 .It Fl a Ar FAT-size
 Number of sectors per FAT.
 .It Fl b Ar block-size
diff -ru newfs_msdos.orig/newfs_msdos.c newfs_msdos/newfs_msdos.c
--- newfs_msdos.orig/newfs_msdos.c	2010-01-06 11:06:02.000000000 +0000
+++ newfs_msdos/newfs_msdos.c	2010-01-10 08:54:15.000000000 +0000
@@ -55,6 +55,7 @@
 #define NPB	  2		/* nibbles per byte */
 
 #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 */
@@ -165,20 +166,23 @@
 
 #define BPBGAP 0, 0, 0, 0, 0, 0
 
+#define INIT(a, b, c, d, e, f, g, h, i, j) \
+    { .bps = a, .spc = b, .res = c, .nft = d, .rde = e, \
+      .sec = f, .mid = g, .spf = h, .spt = i, .hds = j, }
 static struct {
     const char *name;
     struct bpb bpb;
 } const stdfmt[] = {
-    {"160",  {512, 1, 1, 2,  64,  320, 0xfe, 1,  8, 1, BPBGAP}},
-    {"180",  {512, 1, 1, 2,  64,  360, 0xfc, 2,  9, 1, BPBGAP}},
-    {"320",  {512, 2, 1, 2, 112,  640, 0xff, 1,  8, 2, BPBGAP}},
-    {"360",  {512, 2, 1, 2, 112,  720, 0xfd, 2,  9, 2, BPBGAP}},
-    {"640",  {512, 2, 1, 2, 112, 1280, 0xfb, 2,  8, 2, BPBGAP}},    
-    {"720",  {512, 2, 1, 2, 112, 1440, 0xf9, 3,  9, 2, BPBGAP}},
-    {"1200", {512, 1, 1, 2, 224, 2400, 0xf9, 7, 15, 2, BPBGAP}},
-    {"1232", {1024,1, 1, 2, 192, 1232, 0xfe, 2,  8, 2, BPBGAP}},    
-    {"1440", {512, 1, 1, 2, 224, 2880, 0xf0, 9, 18, 2, BPBGAP}},
-    {"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)},    
+    {"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)},    
+    {"1440", INIT(512, 1, 1, 2, 224, 2880, 0xf0, 9, 18, 2)},
+    {"2880", INIT(512, 2, 1, 2, 240, 5760, 0xf0, 9, 36, 2)}
 };
 
 static const u_int8_t bootcode[] = {
@@ -421,7 +425,9 @@
     }
     if (!powerof2(bpb.bps))
 	errx(1, "bytes/sector (%u) is not a power of 2", bpb.bps);
-    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 = opt_F)) {
@@ -533,7 +539,7 @@
     if (!bpb.res)
 	bpb.res = fat == 32 ? MAX(x, MAX(16384 / bpb.bps, 4)) : x;
     else if (bpb.res < x)
-	errx(1, "too few reserved sectors");
+	errx(1, "too few reserved sectors (need %d have %d)", x, bpb.res);
     if (fat != 32 && !bpb.rde)
 	bpb.rde = DEFRDE;
     rds = 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);
-		mklabel(bsx->label, opt_L ? opt_L : "NO NAME");
-		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 += sizeof(struct bsx);
@@ -666,7 +672,7 @@
 		    mk1(bs->jmp[0], 0xeb);
 		    mk1(bs->jmp[1], x1 - 2);
 		    mk1(bs->jmp[2], 0x90);
-		    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);

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?346723.73967.qm>