+2003-05-13 root <tytso@mit.edu>
+
+ * main.c (main): Add the ability to specify units to the size
+ parameter, and make the error and information messages
+ display explicitly the blocksize used by the filesystem,
+ to avoid confusion. (Addresses Debian bug: #189814)
+
2003-05-03 Theodore Ts'o <tytso@mit.edu>
* main.c (main): Add calls to setup functions for NLS support.
exit(1);
}
+static int get_units(const char *s)
+{
+ if (strlen(s) != 1)
+ return -1;
+ switch(s[0]) {
+ case 's':
+ return 512;
+ case 'K':
+ return 1024;
+ case 'M':
+ return 1024*1024;
+ case 'G':
+ return 1024*1024*1024;
+ }
+ return -1;
+}
int main (int argc, char ** argv)
{
int fd;
blk_t new_size = 0;
blk_t max_size = 0;
+ int units = 0;
io_manager io_ptr;
char *tmp;
struct stat st_buf;
if (optind < argc) {
new_size = strtoul(argv[optind++], &tmp, 0);
if (*tmp) {
- com_err(program_name, 0, _("bad filesystem size - %s"),
- argv[optind - 1]);
- exit(1);
+ units = get_units(tmp);
+ if (units < 0) {
+ com_err(program_name, 0,
+ _("bad filesystem size - %s"),
+ argv[optind - 1]);
+ exit(1);
+ }
}
}
if (optind < argc)
_("while trying to determine filesystem size"));
exit(1);
}
+ if (units) {
+ if (units < fs->blocksize)
+ new_size = (new_size * units) / fs->blocksize;
+ else if (units > fs->blocksize)
+ new_size = new_size * (units / fs->blocksize);
+ }
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
}
if (!force && (new_size > max_size)) {
fprintf(stderr, _("The containing partition (or device)"
- " is only %d blocks.\nYou requested a new size"
+ " is only %d (%dk) blocks.\nYou requested a new size"
" of %d blocks.\n\n"), max_size,
- new_size);
+ fs->blocksize / 1024, new_size);
exit(1);
}
if (new_size == fs->super->s_blocks_count) {
device_name);
exit(1);
}
+ printf("Resizing the filesystem on %s to %d (%dk) blocks.\n",
+ device_name, new_size, fs->blocksize / 1024);
retval = resize_fs(fs, &new_size, flags,
((flags & RESIZE_PERCENT_COMPLETE) ?
resize_progress_func : 0));
The
.B resize2fs
program will resize ext2 file systems. It can be used to enlarge or
-shrink an ext2 file system located on
-.I device
-so that it will have
-.I size
-blocks.
-If the
+shrink an ext2 file system located on
+.IR device .
+The
.I size
-parameter is not specified, it will default to the size of the partition.
+parameter specifies the requested new size of the filesystem.
+If no units are specified, the units of the
+.I size
+parameter shall be the filesystem blocksize of the filesystem.
+Optionally, the
+.I size
+parameter may be suffixed by one of the following the units
+designators: 's', 'K', 'M', or 'G',
+for 512 byte sectors, kilobytes, megabytes, or gigabytes, respectively.
The
.I size
-parameter may never be larger than the size of the partition.
+of the filesystem may never be larger than the size of the partition.
+If
+.I size
+parameter is not specified, it will default to the size of the partition.
.PP
The
.B resize2fs