Fix resize2fs error msgs if the fs or kernel doesn't support on-line resize

Check to make sure the filesystem has a resize inode if it is needed to
grow the filesystem.  Print the correct error message if the kernel
returns an ENOTTY error to the group extend ioctl

Addresses Debian Bug: #380548

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
diff --git a/resize/ChangeLog b/resize/ChangeLog
index bc4dd92..ee61c72 100644
--- a/resize/ChangeLog
+++ b/resize/ChangeLog
@@ -1,3 +1,11 @@
+2006-10-01  Theodore Tso  <tytso@mit.edu>
+
+	* online.c (online_resize_fs): Check to make sure the filesystem
+		has a resize inode if it is needed to grow the filesystem.
+		Print the correct error message if the kernel returns an
+		ENOTTY error to the group extend ioctl.
+		(Addresses Debian bug #380548)
+
 2006-08-30  Eric Sandeen  <esandeen@redhat.com>
 
 	* online.c (online_resize_fs): use div_ceil for r_frac calculation.
diff --git a/resize/online.c b/resize/online.c
index a1c19c3..e3562e4 100644
--- a/resize/online.c
+++ b/resize/online.c
@@ -27,7 +27,7 @@
 	errcode_t 		retval;
 	dgrp_t			i;
 	blk_t			size;
-	int			fd, r_frac, overhead;
+	int			fd, r_frac, overhead, new_desc_blocks;
 
 	printf(_("Filesystem at %s is mounted on %s; "
 		 "on-line resizing required\n"), fs->device_name, mtpt);
@@ -38,6 +38,25 @@
 		exit(1);
 	}
 
+	/*
+	 * If the number of descriptor blocks is going to increase, 
+	 * the on-line resizing inode must be present.
+	 */
+	new_desc_blocks = ext2fs_div_ceil(
+		ext2fs_div_ceil(*new_size -
+				fs->super->s_first_data_block,
+				EXT2_BLOCKS_PER_GROUP(fs->super)),
+		EXT2_DESC_PER_BLOCK(fs->super));
+	printf("old desc_blocks = %d, new_desc_blocks = %d\n", fs->desc_blocks,
+	       new_desc_blocks);
+	if (!(fs->super->s_feature_compat & 
+	      EXT2_FEATURE_COMPAT_RESIZE_INODE) &&
+	    new_desc_blocks != fs->desc_blocks) {
+		com_err(program_name, 0, 
+			_("Filesystem does not support online resizing"));
+		exit(1);
+	}
+
 	fd = open(mtpt, O_RDONLY);
 	if (fd < 0) {
 		com_err(program_name, errno, 
@@ -52,7 +71,7 @@
 				_("Permission denied to resize filesystem"));
 		else if (errno == ENOTTY)
 			com_err(program_name, 0, 
-			_("Filesystem does not support online resizing"));
+			_("Kernel does not support online resizing"));
 		else 
 			com_err(program_name, errno, 
 			_("While checking for on-line resizing support"));