]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
main.c (main): Add the ability to specify units to the size
authorTheodore Ts'o <tytso@mit.edu>
Wed, 14 May 2003 03:32:59 +0000 (23:32 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 14 May 2003 03:32:59 +0000 (23:32 -0400)
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
resize/main.c
resize/resize2fs.8.in

index 30c868b7910ac6cb38929e8cf8363179622cd3f6..ecf15f508966c1a4548308b1a51cdf25534a8005 100644 (file)
@@ -1,3 +1,10 @@
+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.
index e35ac8e2fbc204e88468b485284c8fa1596fa4e8..7aade6d2f6f6290c45680219d40d75ddb968feff 100644 (file)
@@ -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));
index a3b7dee039cf2e9c72932d7d3a54a5a98bf91a34..8ea7b15f2dff97fa7d7651571d89b2a626b510e9 100644 (file)
@@ -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