From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org
Cc: Joshua Hudson <joshudson@gmail.com>
Subject: [PATCH 01/12] mkfs.minix: increase maximum minix v2 and v3 file system sizes
Date: Wed, 24 Jun 2015 09:15:08 +0100 [thread overview]
Message-ID: <1435133719-2971-2-git-send-email-kerolasa@iki.fi> (raw)
In-Reply-To: <1435133719-2971-1-git-send-email-kerolasa@iki.fi>
From: Joshua Hudson <joshudson@gmail.com>
mkfs.minix misbehaves when attempting to create a large v2 or v3
filesystem. I finally traced it down to attempting to create too many
inodes so that the first zone is past 65535 blocks in. This obviously
doesn't work as the on-disk superblock says this is a 16 bit integer.
I wrote a patch that catches this, clamps to the absolute v2/v3 limit
(like it already does for v1), and sets the blocks per inode to a more
reasonable ratio when exceeding half a gigabyte. Having a half-gig
filesystem with most files being smaller than 3k isn't really reasonable.
I suppose if you don't want to adjust inode sizes automatically you could
take that part out, and it will just crab sooner.
Given the non-attention in the code, I suspect nobody ever had cause to
try such a big minix filesystem. Well I have my reasons involving some
deeply embedded work where ext2 would place too much strain on the
hardware.
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Joshua Hudson <joshudson@gmail.com>
---
disk-utils/mkfs.minix.c | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/disk-utils/mkfs.minix.c b/disk-utils/mkfs.minix.c
index c84aed2..564f2b4 100644
--- a/disk-utils/mkfs.minix.c
+++ b/disk-utils/mkfs.minix.c
@@ -49,6 +49,9 @@
* 06.29.11 - Overall cleanups for util-linux and v3 support
* Davidlohr Bueso <dave@gnu.org>
*
+ * 06.20.15 - Do not infinite loop or crash on large devices
+ * Joshua Hudson <joshudson@gmail.com>
+ *
* Usage: mkfs [-c | -l filename ] [-12v3] [-nXX] [-iXX] device [size-in-blocks]
*
* -c for readablility checking (SLOW!)
@@ -504,9 +507,16 @@ static void setup_tables(void) {
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 (2048 * 1024 < BLOCKS) /* 2GB */
+ inodes = BLOCKS / 16;
+ else if (512 * 1024 < BLOCKS) /* 0.5GB */
+ inodes = BLOCKS / 8;
+ else
+ inodes = BLOCKS / 3;
else
inodes = req_nr_inodes;
/* Round up inode count to fill block size */
@@ -524,8 +534,13 @@ static void setup_tables(void) {
if (inodes > MINIX_MAX_INODES)
inodes = MINIX_MAX_INODES;
}
-
super_set_map_blocks(inodes);
+ if (MINIX_MAX_INODES < first_zone_data())
+ errx(MKFS_EX_ERROR,
+ _("First data block at %jd, which is too far (max %d).\n"
+ "Try specifying fewer inodes by passing -i <inodes>"),
+ first_zone_data(),
+ MINIX_MAX_INODES);
imaps = get_nimaps();
zmaps = get_nzmaps();
@@ -793,6 +808,8 @@ int main(int argc, char ** argv) {
} else /* fs_version == 1 */
if (BLOCKS > MINIX_MAX_INODES)
BLOCKS = MINIX_MAX_INODES;
+ if (BLOCKS > MINIX_MAX_INODES * BITS_PER_BLOCK)
+ BLOCKS = MINIX_MAX_INODES * BITS_PER_BLOCK; /* Utter maximum: Clip. */
setup_tables();
if (check)
check_blocks();
--
2.4.4
next prev parent reply other threads:[~2015-06-24 8:15 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-24 8:15 [PATCH 00/12] pull: minix updates Sami Kerola
2015-06-24 8:15 ` Sami Kerola [this message]
2015-06-24 8:15 ` [PATCH 02/12] mkfs.minix: introduce long options to the command Sami Kerola
2015-06-24 8:15 ` [PATCH 03/12] mkfs.minix: use is_mounted() from libcommon Sami Kerola
2015-06-24 8:15 ` [PATCH 04/12] mkfs.minix: remove unuseful code Sami Kerola
2015-06-24 8:15 ` [PATCH 05/12] mkfs.minix: add fs_control structure, and remove most global variables Sami Kerola
2015-06-24 8:15 ` [PATCH 06/12] mkfs.minix: check user input carefully Sami Kerola
2015-06-24 8:15 ` [PATCH 07/12] mkfs.minix: check requested blocks will not exceed available on device Sami Kerola
2015-06-24 8:15 ` [PATCH 08/12] mkfs.minix: refactor root block content creation Sami Kerola
2015-06-24 8:15 ` [PATCH 09/12] fsck.minix: rename device file descriptor variable Sami Kerola
2015-06-24 8:15 ` [PATCH 10/12] fsck.minix: add minix v3 support Sami Kerola
2015-06-24 8:15 ` [PATCH 11/12] fsck.minix: introduce long options to the command Sami Kerola
2015-06-24 8:15 ` [PATCH 12/12] docs: make fsck.minix(8) more pretty Sami Kerola
2015-07-30 9:55 ` [PATCH 00/12] pull: minix updates Karel Zak
2015-07-30 10:31 ` Sami Kerola
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1435133719-2971-2-git-send-email-kerolasa@iki.fi \
--to=kerolasa@iki.fi \
--cc=joshudson@gmail.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox