]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blobdiff - resize/main.c
Merge branch 'maint' into next
[thirdparty/e2fsprogs.git] / resize / main.c
index 9da3a958cc01379c7ed204840518f73e070a1abb..a0c31c069f3c71ca9764cf7a9949fb0979bf1dae 100644 (file)
  * %End-Header%
  */
 
+#ifndef _LARGEFILE_SOURCE
 #define _LARGEFILE_SOURCE
+#endif
+#ifndef _LARGEFILE64_SOURCE
 #define _LARGEFILE64_SOURCE
+#endif
 
 #include "config.h"
 #ifdef HAVE_GETOPT_H
@@ -43,7 +47,8 @@ static char *device_name, *io_options;
 static void usage (char *prog)
 {
        fprintf (stderr, _("Usage: %s [-d debug_flags] [-f] [-F] [-M] [-P] "
-                          "[-p] device [-b|-s|new_size] [-z undo_file]\n\n"),
+                          "[-p] device [-b|-s|new_size] [-S RAID-stride] "
+                          "[-z undo_file]\n\n"),
                 prog);
 
        exit (1);
@@ -154,8 +159,7 @@ static void determine_fs_stride(ext2_filsys fs)
 
 static void bigalloc_check(ext2_filsys fs, int force)
 {
-       if (!force && EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
-                               EXT4_FEATURE_RO_COMPAT_BIGALLOC)) {
+       if (!force && ext2fs_has_feature_bigalloc(fs->super)) {
                fprintf(stderr, "%s", _("\nResizing bigalloc file systems has "
                                        "not been fully tested.  Proceed at\n"
                                        "your own risk!  Use the force option "
@@ -164,11 +168,12 @@ static void bigalloc_check(ext2_filsys fs, int force)
        }
 }
 
-static int resize2fs_setup_tdb(const char *device_name, char *undo_file,
+static int resize2fs_setup_tdb(const char *device, char *undo_file,
                               io_manager *io_ptr)
 {
        errcode_t retval = ENOMEM;
-       char *tdb_dir = NULL, *tdb_file = NULL;
+       const char *tdb_dir = NULL;
+       char *tdb_file = NULL;
        char *dev_name, *tmp_name;
 
        /* (re)open a specific undo file */
@@ -183,7 +188,7 @@ static int resize2fs_setup_tdb(const char *device_name, char *undo_file,
                printf(_("Overwriting existing filesystem; this can be undone "
                         "using the command:\n"
                         "    e2undo %s %s\n\n"),
-                       undo_file, device_name);
+                       undo_file, device);
                return retval;
        }
 
@@ -199,7 +204,7 @@ static int resize2fs_setup_tdb(const char *device_name, char *undo_file,
            access(tdb_dir, W_OK))
                return 0;
 
-       tmp_name = strdup(device_name);
+       tmp_name = strdup(device);
        if (!tmp_name)
                goto errout;
        dev_name = basename(tmp_name);
@@ -227,7 +232,7 @@ static int resize2fs_setup_tdb(const char *device_name, char *undo_file,
                goto errout;
        printf(_("Overwriting existing filesystem; this can be undone "
                 "using the command:\n"
-                "    e2undo %s %s\n\n"), tdb_file, device_name);
+                "    e2undo %s %s\n\n"), tdb_file, device);
 
        free(tdb_file);
        return 0;
@@ -418,7 +423,7 @@ int main (int argc, char ** argv)
         * unless the user is forcing it.
         *
         * We do ERROR and VALID checks even if we're only printing the
-        * minimimum size, because traversal of a badly damaged filesystem
+        * minimum size, because traversal of a badly damaged filesystem
         * can cause issues as well.  We don't require it to be fscked after
         * the last mount time in this case, though, as this is a bit less
         * risky.
@@ -436,6 +441,11 @@ int main (int argc, char ** argv)
                    !print_min_size)
                        checkit = 1;
 
+               if ((ext2fs_free_blocks_count(fs->super) >
+                    ext2fs_blocks_count(fs->super)) ||
+                   (fs->super->s_free_inodes_count > fs->super->s_inodes_count))
+                       checkit = 1;
+
                if (checkit) {
                        fprintf(stderr,
                                _("Please run 'e2fsck -f %s' first.\n\n"),
@@ -501,14 +511,13 @@ int main (int argc, char ** argv)
                new_size = max_size;
                /* Round down to an even multiple of a pagesize */
                if (sys_page_size > blocksize)
-                       new_size &= ~((sys_page_size / blocksize)-1);
+                       new_size &= ~((blk64_t)((sys_page_size / blocksize)-1));
        }
        /* If changing 64bit, don't change the filesystem size. */
        if (flags & (RESIZE_DISABLE_64BIT | RESIZE_ENABLE_64BIT)) {
                new_size = ext2fs_blocks_count(fs->super);
        }
-       if (!EXT2_HAS_INCOMPAT_FEATURE(fs->super,
-                                      EXT4_FEATURE_INCOMPAT_64BIT)) {
+       if (!ext2fs_has_feature_64bit(fs->super)) {
                /* Take 16T down to 2^32-1 blocks */
                if (new_size == (1ULL << 32))
                        new_size--;
@@ -574,8 +583,7 @@ int main (int argc, char ** argv)
                        exit(1);
                }
                if (flags & RESIZE_ENABLE_64BIT &&
-                   !EXT2_HAS_INCOMPAT_FEATURE(fs->super,
-                               EXT3_FEATURE_INCOMPAT_EXTENTS)) {
+                   !ext2fs_has_feature_extents(fs->super)) {
                        fprintf(stderr, _("Please enable the extents feature "
                                "with tune2fs before enabling the 64bit "
                                "feature.\n"));
@@ -588,17 +596,16 @@ int main (int argc, char ** argv)
                exit(0);
        }
        if ((flags & RESIZE_ENABLE_64BIT) &&
-           EXT2_HAS_INCOMPAT_FEATURE(fs->super, EXT4_FEATURE_INCOMPAT_64BIT)) {
+           ext2fs_has_feature_64bit(fs->super)) {
                fprintf(stderr, _("The filesystem is already 64-bit.\n"));
                exit(0);
        }
        if ((flags & RESIZE_DISABLE_64BIT) &&
-           !EXT2_HAS_INCOMPAT_FEATURE(fs->super, EXT4_FEATURE_INCOMPAT_64BIT)) {
+           !ext2fs_has_feature_64bit(fs->super)) {
                fprintf(stderr, _("The filesystem is already 32-bit.\n"));
                exit(0);
        }
        if (mount_flags & EXT2_MF_MOUNTED) {
-               bigalloc_check(fs, force);
                retval = online_resize_fs(fs, mtpt, &new_size, flags);
        } else {
                bigalloc_check(fs, force);