From 792a088162dcbd4e8f062e6cd42427e42c428ef7 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Tue, 13 May 2003 23:32:59 -0400 Subject: [PATCH] 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) --- resize/ChangeLog | 7 +++++++ resize/main.c | 40 +++++++++++++++++++++++++++++++++++----- resize/resize2fs.8.in | 24 ++++++++++++++++-------- 3 files changed, 58 insertions(+), 13 deletions(-) diff --git a/resize/ChangeLog b/resize/ChangeLog index 30c868b..ecf15f5 100644 --- a/resize/ChangeLog +++ b/resize/ChangeLog @@ -1,3 +1,10 @@ +2003-05-13 root + + * 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 * main.c (main): Add calls to setup functions for NLS support. diff --git a/resize/main.c b/resize/main.c index e35ac8e..7aade6d 100644 --- a/resize/main.c +++ b/resize/main.c @@ -106,6 +106,22 @@ static void check_mount(char *device) 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) { @@ -118,6 +134,7 @@ 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; @@ -164,9 +181,13 @@ int main (int argc, char ** argv) 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) @@ -229,8 +250,15 @@ int main (int argc, char ** argv) _("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 @@ -248,9 +276,9 @@ int main (int argc, char ** argv) } 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) { @@ -265,6 +293,8 @@ int main (int argc, char ** argv) 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)); diff --git a/resize/resize2fs.8.in b/resize/resize2fs.8.in index a3b7dee..8ea7b15 100644 --- a/resize/resize2fs.8.in +++ b/resize/resize2fs.8.in @@ -28,17 +28,25 @@ resize2fs \- ext2 file system resizer 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 -- 1.8.3.1