Module Name:    src
Committed By:   mlelstv
Date:           Sun Apr  3 11:00:13 UTC 2016

Modified Files:
        src/sbin/newfs_msdos: mkfs_msdos.c

Log Message:
Use the same defaults for cluster sizes as Windows.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sbin/newfs_msdos/mkfs_msdos.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/newfs_msdos/mkfs_msdos.c
diff -u src/sbin/newfs_msdos/mkfs_msdos.c:1.9 src/sbin/newfs_msdos/mkfs_msdos.c:1.10
--- src/sbin/newfs_msdos/mkfs_msdos.c:1.9	Sun Jan  5 12:52:39 2014
+++ src/sbin/newfs_msdos/mkfs_msdos.c	Sun Apr  3 11:00:13 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: mkfs_msdos.c,v 1.9 2014/01/05 12:52:39 martin Exp $	*/
+/*	$NetBSD: mkfs_msdos.c,v 1.10 2016/04/03 11:00:13 mlelstv Exp $	*/
 
 /*
  * Copyright (c) 1998 Robert Nordier
@@ -37,7 +37,7 @@
 static const char rcsid[] =
   "$FreeBSD: src/sbin/newfs_msdos/newfs_msdos.c,v 1.15 2000/10/10 01:49:37 wollman Exp $";
 #else
-__RCSID("$NetBSD: mkfs_msdos.c,v 1.9 2014/01/05 12:52:39 martin Exp $");
+__RCSID("$NetBSD: mkfs_msdos.c,v 1.10 2016/04/03 11:00:13 mlelstv Exp $");
 #endif
 #endif /* not lint */
 
@@ -335,16 +335,26 @@ mkfs_msdos(const char *fname, const char
 	    return -1;
 	bpb.bsec -= (o.offset / bpb.bps);
 	if (bpb.spc == 0) {     /* set defaults */
-	    if (bpb.bsec <= 6000)       /* about 3MB -> 512 bytes */
-		bpb.spc = 1;
-	    else if (bpb.bsec <= (1<<17)) /* 64M -> 4k */
-		bpb.spc = 8;
-	    else if (bpb.bsec <= (1<<19)) /* 256M -> 8k */
-		bpb.spc = 16;
-	    else if (bpb.bsec <= (1<<21)) /* 1G -> 16k */
-		bpb.spc = 32;
-	    else
-		bpb.spc = 64;           /* otherwise 32k */
+	    /* minimum cluster size */
+	    switch (o.fat_type) {
+	    case 12:
+		bpb.spc = 1;            /* use 512 bytes */
+		x = 2;                  /* up to 2MB */
+		break;
+	    case 16:
+		bpb.spc = 1;            /* use 512 bytes */
+		x = 32;                 /* up to 32MB */
+		break;
+	    default:
+		bpb.spc = 8;            /* use 4k */
+		x = 8192;               /* up to 8GB */
+		break;
+	    }
+	    x1 = howmany(bpb.bsec, (1048576 / 512)); /* -> MB */
+	    while (bpb.spc < 128 && x < x1) {
+		x *= 2;
+		bpb.spc *= 2;
+	    }
 	}
     }
 

Reply via email to