+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
extern int optind;
#endif
#include <fcntl.h>
+#include <sys/stat.h>
#include "resize2fs.h"
blk_t max_size = 0;
io_manager io_ptr;
char *tmp;
+ struct stat st_buf;
initialize_ext2_error_table();
}
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"
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) {
/*
* 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))
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;
/* 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));