main.c (main): If we are resizing a plain file which is smaller
	than the requested size, then we will attempt to
	transparently extend the filesize in a sparse fashion by
	writing a block at the end of the requested part of the
	filesystem.

main.c (main), resize2fs.c (resize_fs), resize2fs.h: Change the
	function prototype of resize_fs() so that it can modify
	the new_size parameter with the actual new size of the
	filesystem after the resize operation.  (This can
	sometimes be less than the requested new size if there
	isn't enough space to create the necessary block group
	metadata for that last bit of disk space.)  Resize2fs now
	prints the actual new size of the filesystem when it finishes.

diff --git a/resize/ChangeLog b/resize/ChangeLog
index ac34105..29b4564 100644
--- a/resize/ChangeLog
+++ b/resize/ChangeLog
@@ -1,3 +1,20 @@
+2002-03-31    <tytso@mit.edu>
+
+	* main.c (main): If we are resizing a plain file which is smaller
+		than the requested size, then we will attempt to
+		transparently extend the filesize in a sparse fashion by
+		writing a block at the end of the requested part of the
+		filesystem.
+
+	* main.c (main), resize2fs.c (resize_fs), resize2fs.h: Change the
+		function prototype of resize_fs() so that it can modify
+		the new_size parameter with the actual new size of the
+		filesystem after the resize operation.  (This can
+		sometimes be less than the requested new size if there
+		isn't enough space to create the necessary block group
+		metadata for that last bit of disk space.)  Resize2fs now
+		prints the actual new size of the filesystem when it finishes.
+
 2002-03-08  Theodore Tso  <tytso@mit.edu>
 
 	* Release of E2fsprogs 1.27
diff --git a/resize/main.c b/resize/main.c
index cff2d0f..238e799 100644
--- a/resize/main.c
+++ b/resize/main.c
@@ -19,6 +19,7 @@
 extern int optind;
 #endif
 #include <fcntl.h>
+#include <sys/stat.h>
 
 #include "resize2fs.h"
 
@@ -119,6 +120,7 @@
 	blk_t		max_size = 0;
 	io_manager	io_ptr;
 	char		*tmp;
+	struct stat	st_buf;
 	
 	initialize_ext2_error_table();
 
@@ -223,6 +225,21 @@
 	}
 	if (!new_size)
 		new_size = max_size;
+	/*
+	 * If we are resizing a plain file, and it's not big enough,
+	 * automatically extend it in a sparse fashion by writing the
+	 * last requested block.
+	 */
+	if ((new_size > max_size) &&
+	    (stat(device_name, &st_buf) == 0) &&
+	    S_ISREG(st_buf.st_mode) &&
+	    ((tmp = malloc(fs->blocksize)) != 0)) {
+		memset(tmp, 0, fs->blocksize);
+		retval = io_channel_write_blk(fs->io, new_size-1, 1, tmp);
+		if (retval == 0)
+			max_size = new_size;
+		free(tmp);
+	}
 	if (!force && (new_size > max_size)) {
 		fprintf(stderr, _("The containing partition (or device)"
 			" is only %d blocks.\nYou requested a new size"
@@ -240,7 +257,7 @@
 			device_name);
 		exit(1);
 	}
-	retval = resize_fs(fs, new_size, flags,
+	retval = resize_fs(fs, &new_size, flags,
 			   ((flags & RESIZE_PERCENT_COMPLETE) ?
 			    resize_progress_func : 0));
 	if (retval) {
diff --git a/resize/resize2fs.c b/resize/resize2fs.c
index 830347c..42ba470 100644
--- a/resize/resize2fs.c
+++ b/resize/resize2fs.c
@@ -66,7 +66,7 @@
 /*
  * This is the top-level routine which does the dirty deed....
  */
-errcode_t resize_fs(ext2_filsys fs, blk_t new_size, int flags,
+errcode_t resize_fs(ext2_filsys fs, blk_t *new_size, int flags,
 		    errcode_t (*progress)(ext2_resize_t rfs, int pass,
 				     unsigned long cur,
 				     unsigned long max_val))
@@ -95,10 +95,12 @@
 	if (retval)
 		goto errout;
 
-	retval = adjust_superblock(rfs, new_size);
+	retval = adjust_superblock(rfs, *new_size);
 	if (retval)
 		goto errout;
 
+	*new_size = rfs->new_fs->super->s_blocks_count;
+
 	retval = blocks_to_move(rfs);
 	if (retval)
 		goto errout;
diff --git a/resize/resize2fs.h b/resize/resize2fs.h
index 61d4fe8..712475a 100644
--- a/resize/resize2fs.h
+++ b/resize/resize2fs.h
@@ -118,7 +118,7 @@
 
 
 /* prototypes */
-extern errcode_t resize_fs(ext2_filsys fs, blk_t new_size, int flags,
+extern errcode_t resize_fs(ext2_filsys fs, blk_t *new_size, int flags,
 			   errcode_t	(*progress)(ext2_resize_t rfs,
 					    int pass, unsigned long cur,
 					    unsigned long max));