Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/newfs_msdos When we end up with too few clusters for th...



details:   https://anonhg.NetBSD.org/src/rev/0afa927aee08
branches:  trunk
changeset: 455259:0afa927aee08
user:      martin <martin%NetBSD.org@localhost>
date:      Sat Oct 12 09:42:38 2019 +0000

description:
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.

diffstat:

 sbin/newfs_msdos/mkfs_msdos.c |  13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diffs (49 lines):

diff -r bca858bb706d -r 0afa927aee08 sbin/newfs_msdos/mkfs_msdos.c
--- a/sbin/newfs_msdos/mkfs_msdos.c     Sat Oct 12 09:22:36 2019 +0000
+++ b/sbin/newfs_msdos/mkfs_msdos.c     Sat Oct 12 09:42:38 2019 +0000
@@ -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.15 2019/10/12 09:42:38 martin 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.15 2019/10/12 09:42:38 martin Exp $");
 #endif
 #endif /* not lint */
 
@@ -264,7 +264,10 @@
     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 @@
     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 @@
        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;



Home | Main Index | Thread Index | Old Index