From c3a1f72b28b32b127e0e476f033d8492a40c92a3 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Thu, 7 Oct 1999 17:04:29 +0000 Subject: 1999-10-06 Roland McGrath * hyper.c (get_hypermetadata): Avoid overflow in calculation of disk size vs superblock-specified requirement. Add a warning for wasted disk blocks after last filesystem block. --- ext2fs/hyper.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ext2fs/hyper.c b/ext2fs/hyper.c index 9c76ec24..4012f9f7 100644 --- a/ext2fs/hyper.c +++ b/ext2fs/hyper.c @@ -96,9 +96,16 @@ get_hypermetadata (void) ext2_panic ("block size %d isn't a power-of-two multiple of 512!", block_size); - if (store->size < (sblock->s_blocks_count << log2_block_size)) - ext2_panic ("disk size (%ld bytes) too small; superblock says we need %d", - store->size, sblock->s_blocks_count << log2_block_size); + if ((store->size >> log2_block_size) < sblock->s_blocks_count) + ext2_panic ("disk size (%qd bytes) too small; superblock says we need %qd", + (long long int) store->size, + (long long int) sblock->s_blocks_count << log2_block_size); + if (log2_dev_blocks_per_fs_block != 0 + && (store->size & ((1 << log2_dev_blocks_per_fs_block) - 1)) != 0) + ext2_warning ("%ld (%d byte) device blocks " + " unused after last filesystem (%d byte) block", + (store->size & ((1 << log2_dev_blocks_per_fs_block) - 1)), + store->block_size, block_size); /* Set these handy variables. */ inodes_per_block = block_size / EXT2_INODE_SIZE (sblock); -- cgit v1.2.3