Ok I was able to replace the patch with an error message. I changed
the inodes per block to be more reasonable w/ large filesystems while
I was at it. I'll be sending the patch upstream as well.
--- disk-utils/mkfs.minix.c.orig	2015-06-20 13:50:45.509325736 -0700
+++ disk-utils/mkfs.minix.c	2015-06-20 20:27:11.732436640 -0700
@@ -49,6 +49,9 @@
  * 06.29.11  -  Overall cleanups for util-linux and v3 support
  *              Davidlohr Bueso <d...@gnu.org>
  *
+ * 06.20.15  -  Do not infinite loop or crash on large devices
+ *              Joshua Hudson <joshud...@gmail.com>
+ *
  * Usage:  mkfs [-c | -l filename ] [-12v3] [-nXX] [-iXX] device [size-in-blocks]
  *
  *	-c for readablility checking (SLOW!)
@@ -504,9 +507,16 @@
 	super_set_nzones();
 	zones = get_nzones();
 
-	/* some magic nrs: 1 inode / 3 blocks */
-	if ( req_nr_inodes == 0 ) 
-		inodes = BLOCKS/3;
+	/* some magic nrs: 1 inode / 3 blocks for smaller filesystems,
+	 * for one inode / 16 blocks for large ones. mkfs will eventually
+	 * crab about too far when getting close to the maximum size. */
+	if ( req_nr_inodes == 0 )
+		if (BLOCKS > 2048 * 1024) /* 2GB */
+			inodes = BLOCKS/16;
+		else if (BLOCKS > 512 * 1024) /* 0.5GB */
+			inodes = BLOCKS/8;
+		else
+			inodes = BLOCKS/3;
 	else
 		inodes = req_nr_inodes;
 	/* Round up inode count to fill block size */
@@ -526,6 +536,12 @@
 	}
 
 	super_set_map_blocks(inodes);
+	if (first_zone_data() >= 65536)
+		errx(MKFS_EX_ERROR, _("First data block at %jd, which is too far"
+			" (max 65535).\n"
+			"Try specifying fewer inodes by passing -i######.\n"),
+			first_zone_data());
+			
 	imaps = get_nimaps();
 	zmaps = get_nzmaps();
 
@@ -793,6 +809,8 @@
 	} else /* fs_version == 1 */
 		if (BLOCKS > MINIX_MAX_INODES)
 			BLOCKS = MINIX_MAX_INODES;
+	if (BLOCKS > 4 + 65531 * BITS_PER_BLOCK)
+		BLOCKS = 4 + 65531 * BITS_PER_BLOCK; /* Utter maximum: Clip. */
 	setup_tables();
 	if (check)
 		check_blocks();

Reply via email to