Whamcloud - gitweb
tune2fs: Fix format string warnings
[tools/e2fsprogs.git] / misc / mke2fs.c
index c5f4da1..a9b01cb 100644 (file)
@@ -1024,8 +1024,7 @@ static char **parse_fs_type(const char *fs_type,
                }
        }
        free(parse_str);
-       if (profile_type)
-               free(profile_type);
+       free(profile_type);
        if (is_hurd)
                push_string(&list, "hurd");
        return (list.list);
@@ -1260,7 +1259,8 @@ static void PRS(int argc, char *argv[])
                        break;
                case 'm':
                        reserved_ratio = strtod(optarg, &tmp);
-                       if (reserved_ratio > 50 || *tmp) {
+                       if ( *tmp || reserved_ratio > 50 ||
+                            reserved_ratio < 0) {
                                com_err(program_name, 0,
                                        _("invalid reserved blocks percent - %s"),
                                        optarg);
@@ -1522,16 +1522,14 @@ got_size:
                                           "features", "", &tmp);
                        if (tmp && *tmp)
                                edit_feature(tmp, &fs_param.s_feature_compat);
-                       if (tmp)
-                               free(tmp);
+                       free(tmp);
                }
                tmp = get_string_from_profile(fs_types, "default_features",
                                              "");
        }
        edit_feature(fs_features ? fs_features : tmp,
                     &fs_param.s_feature_compat);
-       if (tmp)
-               free(tmp);
+       free(tmp);
 
        if (fs_param.s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) {
                fs_types[0] = strdup("journal");
@@ -1645,8 +1643,7 @@ got_size:
                profile_get_string(profile, "fs_types", *cpp, "options", "", &tmp);
                        if (tmp && *tmp)
                                parse_extended_opts(&fs_param, tmp);
-                       if (tmp)
-                               free(tmp);
+                       free(tmp);
        }
 
        if (extended_opts)
@@ -1800,7 +1797,7 @@ open_err_out:
 static int mke2fs_setup_tdb(const char *name, io_manager *io_ptr)
 {
        errcode_t retval = 0;
-       char *tdb_dir, tdb_file[PATH_MAX];
+       char *tdb_dir, *tdb_file;
        char *device_name, *tmp_name;
 
        /*
@@ -1818,7 +1815,16 @@ static int mke2fs_setup_tdb(const char *name, io_manager *io_ptr)
                return 0;
 
        tmp_name = strdup(name);
+       if (!tmp_name) {
+       alloc_fn_fail:
+               com_err(program_name, ENOMEM, 
+                       _("Couldn't allocate memory for tdb filename\n"));
+               return ENOMEM;
+       }
        device_name = basename(tmp_name);
+       tdb_file = malloc(strlen(tdb_dir) + 8 + strlen(device_name) + 7 + 1);
+       if (!tdb_file)
+               goto alloc_fn_fail;
        sprintf(tdb_file, "%s/mke2fs-%s.e2undo", tdb_dir, device_name);
 
        if (!access(tdb_file, F_OK)) {
@@ -1827,6 +1833,7 @@ static int mke2fs_setup_tdb(const char *name, io_manager *io_ptr)
                        com_err(program_name, retval,
                                _("while trying to delete %s"),
                                tdb_file);
+                       free(tdb_file);
                        return retval;
                }
        }
@@ -1838,6 +1845,7 @@ static int mke2fs_setup_tdb(const char *name, io_manager *io_ptr)
                 "using the command:\n"
                 "    e2undo %s %s\n\n"), tdb_file, name);
 
+       free(tdb_file);
        free(tmp_name);
        return retval;
 }
@@ -1892,6 +1900,14 @@ int main (int argc, char *argv[])
        if (fs_param.s_flags & EXT2_FLAGS_TEST_FILESYS)
                fs->super->s_flags |= EXT2_FLAGS_TEST_FILESYS;
 
+       if ((fs_param.s_feature_incompat &
+            (EXT3_FEATURE_INCOMPAT_EXTENTS|EXT4_FEATURE_INCOMPAT_FLEX_BG)) ||
+           (fs_param.s_feature_ro_compat &
+            (EXT4_FEATURE_RO_COMPAT_HUGE_FILE|EXT4_FEATURE_RO_COMPAT_GDT_CSUM|
+             EXT4_FEATURE_RO_COMPAT_DIR_NLINK|
+             EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE)))
+               fs->super->s_kbytes_written = 1;
+
        /*
         * Wipe out the old on-disk superblock
         */
@@ -2074,6 +2090,12 @@ int main (int argc, char *argv[])
                    EXT3_FEATURE_COMPAT_HAS_JOURNAL)) {
                journal_blocks = figure_journal_size(journal_size, fs);
 
+               if (super_only) {
+                       printf(_("Skipping journal creation in super-only mode\n"));
+                       fs->super->s_journal_inum = EXT2_JOURNAL_INO;
+                       goto no_journal;
+               }
+
                if (!journal_blocks) {
                        fs->super->s_feature_compat &=
                                ~EXT3_FEATURE_COMPAT_HAS_JOURNAL;