/*
* Calculate number of blocks to reserve
*/
- fs_param.s_r_blocks_count = e2p_percent(reserved_ratio,
- fs_param.s_blocks_count);
+ fs_param.s_r_blocks_count = (unsigned int) (reserved_ratio *
+ fs_param.s_blocks_count / 100.0);
}
+static int should_do_undo(const char *name)
+{
+ errcode_t retval;
+ io_channel channel;
+ __u16 s_magic;
+ struct ext2_super_block super;
+ io_manager manager = unix_io_manager;
+ int csum_flag, force_undo;
+
+ csum_flag = EXT2_HAS_RO_COMPAT_FEATURE(&fs_param,
+ EXT4_FEATURE_RO_COMPAT_GDT_CSUM);
+ force_undo = get_int_from_profile(fs_types, "force_undo", 0);
+ if (!force_undo && (!csum_flag || !lazy_itable_init))
+ return 0;
+
+ retval = manager->open(name, IO_FLAG_EXCLUSIVE, &channel);
+ if (retval) {
+ /*
+ * We don't handle error cases instead we
+ * declare that the file system doesn't exist
+ * and let the rest of mke2fs take care of
+ * error
+ */
+ retval = 0;
+ goto open_err_out;
+ }
+
+ io_channel_set_blksize(channel, SUPERBLOCK_OFFSET);
+ retval = io_channel_read_blk(channel, 1, -SUPERBLOCK_SIZE, &super);
+ if (retval) {
+ retval = 0;
+ goto err_out;
+ }
+
+#if defined(WORDS_BIGENDIAN)
+ s_magic = ext2fs_swab16(super.s_magic);
+#else
+ s_magic = super.s_magic;
+#endif
+
+ if (s_magic == EXT2_SUPER_MAGIC)
+ retval = 1;
+
+err_out:
+ io_channel_close(channel);
+
+open_err_out:
+
+ return retval;
+}
+
+static int mke2fs_setup_tdb(const char *name, io_manager *io_ptr)
+{
+ errcode_t retval = 0;
+ char *tdb_dir, tdb_file[PATH_MAX];
+ char *device_name, *tmp_name;
+
+ /*
+ * Configuration via a conf file would be
+ * nice
+ */
+ tdb_dir = getenv("E2FSPROGS_UNDO_DIR");
+ if (!tdb_dir)
+ profile_get_string(profile, "defaults",
+ "undo_dir", 0, "/var/lib/e2fsprogs",
+ &tdb_dir);
+
+ if (!strcmp(tdb_dir, "none") || (tdb_dir[0] == 0) ||
+ access(tdb_dir, W_OK))
+ return 0;
+
+ tmp_name = strdup(name);
+ device_name = basename(tmp_name);
+ sprintf(tdb_file, "%s/mke2fs-%s.e2undo", tdb_dir, device_name);
+
+ if (!access(tdb_file, F_OK)) {
+ if (unlink(tdb_file) < 0) {
+ retval = errno;
+ com_err(program_name, retval,
+ _("while trying to delete %s"),
+ tdb_file);
+ return retval;
+ }
+ }
+
+ set_undo_io_backing_manager(*io_ptr);
+ *io_ptr = undo_io_manager;
+ set_undo_io_backup_file(tdb_file);
+ printf(_("Overwriting existing filesystem; this can be undone "
+ "using the command:\n"
+ " e2undo %s %s\n\n"), tdb_file, name);
+err_out:
+ free(tmp_name);
+ return retval;
+}
+
int main (int argc, char *argv[])
{
errcode_t retval = 0;