Use the same defaults for cluster sizes as Windows.

This commit is contained in:
mlelstv 2016-04-03 11:00:13 +00:00
parent b956532246
commit 4842a68f63
1 changed files with 22 additions and 12 deletions

View File

@ -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 *dtype, const struct msdos_options *op)
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;
}
}
}