Module Name: src Committed By: bouyer Date: Sat Oct 12 15:11:43 UTC 2019
Modified Files: src/sbin/newfs_msdos [netbsd-9]: mkfs_msdos.c Log Message: Pull up following revision(s) (requested by martin in ticket #303): sbin/newfs_msdos/mkfs_msdos.c: revision 1.15 When we end up with too few clusters for the requested FAT type after configuring default values, retry with a smaller cluster size. This makes the typical invocation to create a spec conformant EFI boot partition work out of the box. To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.14.6.1 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.14 src/sbin/newfs_msdos/mkfs_msdos.c:1.14.6.1 --- src/sbin/newfs_msdos/mkfs_msdos.c:1.14 Sun Feb 4 09:03:23 2018 +++ src/sbin/newfs_msdos/mkfs_msdos.c Sat Oct 12 15:11:42 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: mkfs_msdos.c,v 1.14 2018/02/04 09:03:23 mrg Exp $ */ +/* $NetBSD: mkfs_msdos.c,v 1.14.6.1 2019/10/12 15:11:42 bouyer 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.14 2018/02/04 09:03:23 mrg Exp $"); +__RCSID("$NetBSD: mkfs_msdos.c,v 1.14.6.1 2019/10/12 15:11:42 bouyer Exp $"); #endif #endif /* not lint */ @@ -264,7 +264,10 @@ mkfs_msdos(const char *fname, const char int ch, fd, fd1; struct msdos_options o = *op; int oflags = O_RDWR | O_CREAT; + bool bspf_is_calculated; +again: + bspf_is_calculated = false; if (o.block_size && o.sectors_per_cluster) { warnx("Cannot specify both block size and sectors per cluster"); return -1; @@ -556,6 +559,7 @@ mkfs_msdos(const char *fname, const char x2 = howmany((RESFTE + MIN(x, maxcls(o.fat_type))) * (o.fat_type / BPN), bpb.bps * NPB); if (!bpb.bspf) { + bspf_is_calculated = true; bpb.bspf = x2; x1 += (bpb.bspf - 1) * bpb.nft; } @@ -569,6 +573,11 @@ mkfs_msdos(const char *fname, const char return -1; } if (cls < mincls(o.fat_type)) { + if (bspf_is_calculated && o.sectors_per_cluster == 0 && bpb.spc > 2) { + /* retry with smaller cluster size */ + o.sectors_per_cluster = 2; + goto again; + } warnx("%u clusters too few clusters for FAT%u, need %u", cls, o.fat_type, mincls(o.fat_type)); return -1;