* 94/03/06 - Added the checks interval from Uwe Ohse (uwe@tirka.gun.de)
*/
-#define _XOPEN_SOURCE 500 /* for inclusion of strptime() */
+#define _XOPEN_SOURCE 600 /* for inclusion of strptime() */
#define _BSD_SOURCE /* for inclusion of strcasecmp() */
#include <fcntl.h>
#include <grp.h>
#endif
#include <pwd.h>
#include <stdio.h>
+#ifdef HAVE_STDLIB_H
#include <stdlib.h>
+#endif
#include <string.h>
#include <time.h>
#include <unistd.h>
}
#ifdef CONFIG_TESTIO_DEBUG
- io_ptr = test_io_manager;
- test_io_backing_manager = unix_io_manager;
-#else
- io_ptr = unix_io_manager;
+ if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) {
+ io_ptr = test_io_manager;
+ test_io_backing_manager = unix_io_manager;
+ } else
#endif
+ io_ptr = unix_io_manager;
retval = ext2fs_open(journal_path, EXT2_FLAG_RW|
EXT2_FLAG_JOURNAL_DEV_OK, 0,
fs->blocksize, io_ptr, &jfs);
break;
}
if (i >= nr_users) {
- fputs(_("Filesystem's UUID not found on journal device.\n"),
+ fputs(_("Filesystem's UUID not found on journal device.\n"),
stderr);
commit_remove_journal = 1;
goto no_valid_journal;
/* Helper function for remove_journal_inode */
static int release_blocks_proc(ext2_filsys fs, blk_t *blocknr,
- int blockcnt EXT2FS_ATTR((unused)),
+ int blockcnt EXT2FS_ATTR((unused)),
void *private EXT2FS_ATTR((unused)))
{
blk_t block;
struct ext2_inode inode;
errcode_t retval;
ino_t ino = fs->super->s_journal_inum;
-
+
retval = ext2fs_read_inode(fs, ino, &inode);
if (retval) {
com_err(program_name, retval,
if (FEATURE_ON(E2P_FEATURE_COMPAT, EXT3_FEATURE_COMPAT_HAS_JOURNAL)) {
/*
* If adding a journal flag, let the create journal
- * code below handle creating setting the flag and
- * creating the journal. We supply a default size if
- * necessary.
+ * code below handle setting the flag and creating the
+ * journal. We supply a default size if necessary.
*/
if (!journal_size)
journal_size = -1;
if (FEATURE_ON(E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_DIR_INDEX)) {
if (!sb->s_def_hash_version)
- sb->s_def_hash_version = EXT2_HASH_TEA;
+ sb->s_def_hash_version = EXT2_HASH_HALF_MD4;
if (uuid_is_null((unsigned char *) sb->s_hash_seed))
uuid_generate((unsigned char *) sb->s_hash_seed);
}
check_plausibility(journal_device);
check_mount(journal_device, 0, _("journal"));
#ifdef CONFIG_TESTIO_DEBUG
- io_ptr = test_io_manager;
- test_io_backing_manager = unix_io_manager;
-#else
- io_ptr = unix_io_manager;
+ if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) {
+ io_ptr = test_io_manager;
+ test_io_backing_manager = unix_io_manager;
+ } else
#endif
+ io_ptr = unix_io_manager;
retval = ext2fs_open(journal_device, EXT2_FLAG_RW|
EXT2_FLAG_JOURNAL_DEV_OK, 0,
fs->blocksize, io_ptr, &jfs);
*io_options++ = 0;
device_name = blkid_get_devname(NULL, argv[1], NULL);
if (!device_name) {
- com_err("e2label", 0, _("Unable to resolve '%s'"),
+ com_err("e2label", 0, _("Unable to resolve '%s'"),
argv[1]);
exit(1);
}
open_flag |= EXT2_FLAG_RW;
L_flag = 1;
new_label = argv[2];
- } else
+ } else
print_label++;
}
mntopts_cmd = optarg;
open_flag = EXT2_FLAG_RW;
break;
-
+
case 'O':
if (features_cmd) {
com_err (program_name, 0,
*io_options++ = 0;
device_name = blkid_get_devname(NULL, argv[optind], NULL);
if (!device_name) {
- com_err("tune2fs", 0, _("Unable to resolve '%s'"),
+ com_err("tune2fs", 0, _("Unable to resolve '%s'"),
argv[optind]);
exit(1);
}
}
dev = blkid_get_devname(NULL, argv[1], NULL);
if (!dev) {
- com_err("findfs", 0, _("Unable to resolve '%s'"),
+ com_err("findfs", 0, _("Unable to resolve '%s'"),
argv[1]);
exit(1);
}
static void parse_extended_opts(ext2_filsys fs, const char *opts)
{
char *buf, *token, *next, *p, *arg;
- int len;
+ int len, hash_alg;
int r_usage = 0;
len = strlen(opts);
continue;
}
stripe_width_set = 1;
- } else
+ } else if (strcmp(token, "hash_alg") == 0 ||
+ strcmp(token, "hash-alg") == 0) {
+ if (!arg) {
+ r_usage++;
+ continue;
+ }
+ hash_alg = e2p_string2hash(arg);
+ if (hash_alg < 0) {
+ fprintf(stderr,
+ _("Invalid hash algorithm: %s\n"),
+ arg);
+ r_usage++;
+ continue;
+ }
+ fs->super->s_def_hash_version = hash_alg;
+ printf(_("Setting default hash algorithm "
+ "to %s (%d)\n"),
+ arg, hash_alg);
+ ext2fs_mark_super_dirty(fs);
+ } else
r_usage++;
}
if (r_usage) {
"\tis set off by an equals ('=') sign.\n\n"
"Valid extended options are:\n"
"\tstride=<RAID per-disk chunk size in blocks>\n"
- "\tstripe-width=<RAID stride*data disks in blocks>\n"
+ "\tstripe_width=<RAID stride*data disks in blocks>\n"
+ "\thash_alg=<hash algorithm>\n"
"\ttest_fs\n"
"\t^test_fs\n"));
free(buf);
exit(1);
}
free(buf);
-}
+}
static int get_move_bitmap(ext2_filsys fs, int new_ino_blks_per_grp,
ext2fs_block_bitmap bmap)
if (retval)
return retval;
- for (blk = fs->super->s_first_data_block;
- blk < fs->super->s_blocks_count; blk++) {
+ for (new_blk = blk = fs->super->s_first_data_block;
+ blk < fs->super->s_blocks_count; blk++) {
if (!ext2fs_test_block_bitmap(bmap, blk))
continue;
- retval = ext2fs_new_block(fs, blk, NULL, &new_blk);
+ retval = ext2fs_new_block(fs, new_blk, NULL, &new_blk);
if (retval)
goto err_out;
e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
blk_t ref_block EXT2FS_ATTR((unused)),
int ref_offset EXT2FS_ATTR((unused)),
- void *priv_data EXT2FS_ATTR((unused)))
+ void *priv_data)
{
int ret = 0;
blk_t new_blk;
+ ext2fs_block_bitmap bmap = (ext2fs_block_bitmap) priv_data;
-
+ if (!ext2fs_test_block_bitmap(bmap, *block_nr))
+ return 0;
new_blk = transalate_block(*block_nr);
if (new_blk) {
*block_nr = new_blk;
return ret;
}
-static int inode_scan_and_fix(ext2_filsys fs)
+static int inode_scan_and_fix(ext2_filsys fs, ext2fs_block_bitmap bmap)
{
errcode_t retval = 0;
ext2_ino_t ino;
* Do we need to fix this ??
*/
- if (inode.i_file_acl) {
-
+ if (inode.i_file_acl &&
+ ext2fs_test_block_bitmap(bmap, inode.i_file_acl)) {
blk = transalate_block(inode.i_file_acl);
if (!blk)
continue;
if (!ext2fs_inode_has_valid_blocks(&inode))
continue;
- retval = ext2fs_block_iterate2(fs, ino, 0,
- block_buf, process_block,
- 0);
+ retval = ext2fs_block_iterate2(fs, ino, 0, block_buf,
+ process_block, bmap);
if (retval)
goto err_out;
int new_ino_blks_per_grp;
ext2fs_block_bitmap bmap;
- if (new_size <= EXT2_INODE_SIZE(fs->super)) {
- fprintf(stderr, _("New inode size too small\n"));
- return EXT2_ET_INVALID_ARGUMENT;
- }
-
ext2fs_read_inode_bitmap(fs);
ext2fs_read_block_bitmap(fs);
INIT_LIST_HEAD(&blk_move_list);
if (retval)
goto err_out;
- retval = inode_scan_and_fix(fs);
+ retval = inode_scan_and_fix(fs, bmap);
if (retval)
goto err_out;
set_undo_io_backing_manager(*io_ptr);
*io_ptr = undo_io_manager;
set_undo_io_backup_file(tdb_file);
- printf(_("To undo the tune2fs operations please run "
- "the command\n undoe2fs %s %s\n\n"),
+ printf(_("To undo the tune2fs operation please run "
+ "the command\n e2undo %s %s\n\n"),
tdb_file, name);
free(tmp_name);
return retval;
errcode_t retval;
ext2_filsys fs;
struct ext2_super_block *sb;
- io_manager io_ptr;
+ io_manager io_ptr, io_ptr_orig = NULL;
#ifdef ENABLE_NLS
setlocale(LC_MESSAGES, "");
parse_e2label_options(argc, argv);
else
parse_tune2fs_options(argc, argv);
-
+
#ifdef CONFIG_TESTIO_DEBUG
- io_ptr = test_io_manager;
- test_io_backing_manager = unix_io_manager;
-#else
- io_ptr = unix_io_manager;
+ if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_DEBUG")) {
+ io_ptr = test_io_manager;
+ test_io_backing_manager = unix_io_manager;
+ } else
#endif
+ io_ptr = unix_io_manager;
+
+retry_open:
+ retval = ext2fs_open2(device_name, io_options, open_flag,
+ 0, 0, io_ptr, &fs);
+ if (retval) {
+ com_err (program_name, retval, _("while trying to open %s"),
+ device_name);
+ fprintf(stderr,
+ _("Couldn't find valid filesystem superblock.\n"));
+ exit(1);
+ }
+
+ if (I_flag && !io_ptr_orig) {
+ /*
+ * Check the inode size is right so we can issue an
+ * error message and bail before setting up the tdb
+ * file.
+ */
+ if (new_inode_size == EXT2_INODE_SIZE(fs->super)) {
+ fprintf(stderr, _("The inode size is already %d\n"),
+ new_inode_size);
+ exit(1);
+ }
+ if (new_inode_size < EXT2_INODE_SIZE(fs->super)) {
+ fprintf(stderr, _("Shrinking the inode size is "
+ "not supported\n"));
+ exit(1);
+ }
- if (I_flag) {
/*
* If inode resize is requested use the
* Undo I/O manager
*/
+ io_ptr_orig = io_ptr;
retval = tune2fs_setup_tdb(device_name, &io_ptr);
if (retval)
exit(1);
+ if (io_ptr != io_ptr_orig) {
+ ext2fs_close(fs);
+ goto retry_open;
+ }
}
- retval = ext2fs_open2(device_name, io_options, open_flag,
- 0, 0, io_ptr, &fs);
- if (retval) {
- com_err (program_name, retval, _("while trying to open %s"),
- device_name);
- fprintf(stderr,
- _("Couldn't find valid filesystem superblock.\n"));
- exit(1);
- }
sb = fs->super;
fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
}
if (L_flag) {
if (strlen(new_label) > sizeof(sb->s_volume_name))
- fputs(_("Warning: label too long, truncating.\n"),
+ fputs(_("Warning: label too long, truncating.\n"),
stderr);
memset(sb->s_volume_name, 0, sizeof(sb->s_volume_name));
strncpy(sb->s_volume_name, new_label,
parse_extended_opts(fs, extended_cmd);
if (journal_size || journal_device)
add_journal(fs);
-
+
if (U_flag) {
+ int set_csum = 0;
+ dgrp_t i;
+
+ if (sb->s_feature_ro_compat &
+ EXT4_FEATURE_RO_COMPAT_GDT_CSUM) {
+ /*
+ * Determine if the block group checksums are
+ * correct so we know whether or not to set
+ * them later on.
+ */
+ for (i = 0; i < fs->group_desc_count; i++)
+ if (!ext2fs_group_desc_csum_verify(fs, i))
+ break;
+ if (i >= fs->group_desc_count)
+ set_csum = 1;
+ }
if ((strcasecmp(new_UUID, "null") == 0) ||
(strcasecmp(new_UUID, "clear") == 0)) {
uuid_clear(sb->s_uuid);
com_err(program_name, 0, _("Invalid UUID format\n"));
exit(1);
}
+ if (set_csum) {
+ for (i = 0; i < fs->group_desc_count; i++)
+ ext2fs_group_desc_csum_set(fs, i);
+ fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
+ }
ext2fs_mark_super_dirty(fs);
}
if (I_flag) {
"unmounted.\n"), stderr);
exit(1);
}
+ if (fs->super->s_feature_incompat &
+ EXT4_FEATURE_INCOMPAT_FLEX_BG) {
+ fputs(_("Changing the inode size not supported for filesystems "
+ "with the flex_bg\nfeature enabled.\n"),
+ stderr);
+ exit(1);
+ }
/*
* We want to update group descriptor also
* with the new free inode count
fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
if (resize_inode(fs, new_inode_size)) {
fputs(_("Error in resizing the inode size.\n"
- "Run undoe2fs to undo the "
+ "Run e2undo to undo the "
"file system changes. \n"), stderr);
} else {
printf (_("Setting inode size %lu\n"),