1997-04-26 21:21:57 +08:00
|
|
|
/*
|
2001-04-24 04:58:03 +08:00
|
|
|
* tune2fs.c - Change the file system parameters on an ext2 file system
|
1997-04-26 21:21:57 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 1992, 1993, 1994 Remy Card <card@masi.ibp.fr>
|
|
|
|
* Laboratoire MASI, Institut Blaise Pascal
|
|
|
|
* Universite Pierre et Marie Curie (Paris VI)
|
|
|
|
*
|
2001-04-24 04:58:03 +08:00
|
|
|
* Copyright 1995, 1996, 1997, 1998, 1999, 2000 by Theodore Ts'o.
|
1997-04-30 00:17:09 +08:00
|
|
|
*
|
|
|
|
* %Begin-Header%
|
|
|
|
* This file may be redistributed under the terms of the GNU Public
|
|
|
|
* License.
|
|
|
|
* %End-Header%
|
1997-04-26 21:21:57 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* History:
|
|
|
|
* 93/06/01 - Creation
|
|
|
|
* 93/10/31 - Added the -c option to change the maximal mount counts
|
|
|
|
* 93/12/14 - Added -l flag to list contents of superblock
|
|
|
|
* M.J.E. Mol (marcel@duteca.et.tudelft.nl)
|
|
|
|
* F.W. ten Wolde (franky@duteca.et.tudelft.nl)
|
|
|
|
* 93/12/29 - Added the -e option to change errors behavior
|
|
|
|
* 94/02/27 - Ported to use the ext2fs library
|
|
|
|
* 94/03/06 - Added the checks interval from Uwe Ohse (uwe@tirka.gun.de)
|
|
|
|
*/
|
|
|
|
|
2008-07-14 03:32:37 +08:00
|
|
|
#define _XOPEN_SOURCE 600 /* for inclusion of strptime() */
|
2011-09-19 05:34:37 +08:00
|
|
|
#include "config.h"
|
1997-04-26 21:21:57 +08:00
|
|
|
#include <fcntl.h>
|
1997-04-26 21:34:30 +08:00
|
|
|
#include <grp.h>
|
1997-04-26 22:00:26 +08:00
|
|
|
#ifdef HAVE_GETOPT_H
|
1997-04-26 21:21:57 +08:00
|
|
|
#include <getopt.h>
|
Many files:
badblocks.c, dumpe2fs.c, e2label.c, mke2fs.c, tune2fs.c, uuidgen.c:
For platforms that don't define optarg.h, manually define optarg and
optind.
ChangeLog, main.c:
main.c: For platforms that don't define optarg.h, manually define
optarg and optind.
ChangeLog, unix.c:
unix.c: For platforms that don't define optarg.h, manually define
optarg and optind.
2000-04-04 00:22:35 +08:00
|
|
|
#else
|
|
|
|
extern char *optarg;
|
|
|
|
extern int optind;
|
1997-04-26 22:00:26 +08:00
|
|
|
#endif
|
1997-04-26 21:34:30 +08:00
|
|
|
#include <pwd.h>
|
1997-04-26 21:21:57 +08:00
|
|
|
#include <stdio.h>
|
2008-09-01 23:17:29 +08:00
|
|
|
#ifdef HAVE_STDLIB_H
|
1997-04-26 21:21:57 +08:00
|
|
|
#include <stdlib.h>
|
2008-09-01 23:17:29 +08:00
|
|
|
#endif
|
2013-12-16 12:26:25 +08:00
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
#include <strings.h> /* for strcasecmp() */
|
|
|
|
#else
|
|
|
|
#define _BSD_SOURCE /* for inclusion of strcasecmp() via <string.h> */
|
2016-03-19 00:45:19 +08:00
|
|
|
#define _DEFAULT_SOURCE /* since glibc 2.20 _BSD_SOURCE is deprecated */
|
2013-12-16 12:26:25 +08:00
|
|
|
#endif
|
1997-04-26 21:21:57 +08:00
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
1997-04-26 21:34:30 +08:00
|
|
|
#include <sys/types.h>
|
2007-08-13 18:26:24 +08:00
|
|
|
#include <libgen.h>
|
2008-06-08 10:07:50 +08:00
|
|
|
#include <limits.h>
|
1997-04-26 21:21:57 +08:00
|
|
|
|
Many files:
badblocks.c, chattr.c, dumpe2fs.c, e2image.c, findsuper.c, lsattr.c,
mke2fs.c, mklost+found.c, tune2fs.c, util.c: Change location of
ext2_fs.h to be ext2fs/ext2_fs.h
ChangeLog, Makefile.in, resize2fs.h:
resize2fs.h: Change location of ext2_fs.h to be ext2fs/ext2_fs.h
ChangeLog, Makefile.in, debugfs.h:
debugfs.h: Change location of ext2_fs.h to be ext2fs/ext2_fs.h
ChangeLog, Makefile.in, e2fsck.h, scantest.c:
e2fsck.h, scantest.c: Change location of ext2_fs.h to be
ext2fs/ext2_fs.h
ChangeLog, Makefile.in, tst_uuid.c, uuid_time.c:
tst_uuid.c, uuid_time.c: Remove unneeded #include of ext2_fs.h
ChangeLog, Makefile.in, e2p.h:
e2p.h: Change location of ext2_fs.h to be ext2fs/ext2_fs.h
ChangeLog, Makefile.in, test_icount.c, test_rel.c:
test_icount.c, test_rel.c: Change location of ext2_fs.h to be
ext2fs/ext2_fs.h
2001-05-14 19:45:38 +08:00
|
|
|
#include "ext2fs/ext2_fs.h"
|
1997-04-26 21:21:57 +08:00
|
|
|
#include "ext2fs/ext2fs.h"
|
2015-05-26 07:29:34 +08:00
|
|
|
#include "ext2fs/kernel-jbd.h"
|
1997-04-26 21:21:57 +08:00
|
|
|
#include "et/com_err.h"
|
2015-07-13 09:55:32 +08:00
|
|
|
#include "support/plausible.h"
|
|
|
|
#include "support/quotaio.h"
|
1997-04-29 22:53:37 +08:00
|
|
|
#include "uuid/uuid.h"
|
1997-04-26 21:21:57 +08:00
|
|
|
#include "e2p/e2p.h"
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
#include "util.h"
|
2003-03-02 08:29:01 +08:00
|
|
|
#include "blkid/blkid.h"
|
1997-04-26 21:21:57 +08:00
|
|
|
|
|
|
|
#include "../version.h"
|
2015-07-13 09:55:32 +08:00
|
|
|
#include "support/nls-enable.h"
|
1997-04-26 21:21:57 +08:00
|
|
|
|
2011-07-21 02:40:05 +08:00
|
|
|
#define QOPT_ENABLE (1)
|
|
|
|
#define QOPT_DISABLE (-1)
|
|
|
|
|
|
|
|
extern int ask_yn(const char *string, int def);
|
|
|
|
|
2009-01-20 15:34:39 +08:00
|
|
|
const char *program_name = "tune2fs";
|
|
|
|
char *device_name;
|
|
|
|
char *new_label, *new_last_mounted, *new_UUID;
|
|
|
|
char *io_options;
|
2001-04-24 04:58:03 +08:00
|
|
|
static int c_flag, C_flag, e_flag, f_flag, g_flag, i_flag, l_flag, L_flag;
|
2011-07-21 02:40:05 +08:00
|
|
|
static int m_flag, M_flag, Q_flag, r_flag, s_flag = -1, u_flag, U_flag, T_flag;
|
2007-08-13 18:26:24 +08:00
|
|
|
static int I_flag;
|
2011-09-25 01:48:55 +08:00
|
|
|
static int clear_mmp;
|
2001-12-26 21:58:01 +08:00
|
|
|
static time_t last_check_time;
|
2001-01-09 08:16:26 +08:00
|
|
|
static int print_label;
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
static int max_mount_count, mount_count, mount_flags;
|
2009-09-08 08:46:34 +08:00
|
|
|
static unsigned long interval;
|
|
|
|
static blk64_t reserved_blocks;
|
2005-07-07 00:50:08 +08:00
|
|
|
static double reserved_ratio;
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
static unsigned long resgid, resuid;
|
|
|
|
static unsigned short errors;
|
2001-01-09 08:16:26 +08:00
|
|
|
static int open_flag;
|
|
|
|
static char *features_cmd;
|
2002-10-16 05:43:43 +08:00
|
|
|
static char *mntopts_cmd;
|
2008-02-19 11:56:25 +08:00
|
|
|
static int stride, stripe_width;
|
|
|
|
static int stride_set, stripe_width_set;
|
2008-01-27 08:06:35 +08:00
|
|
|
static char *extended_cmd;
|
2008-06-07 23:51:33 +08:00
|
|
|
static unsigned long new_inode_size;
|
2011-07-05 08:14:35 +08:00
|
|
|
static char *ext_mount_opts;
|
2016-01-12 16:56:44 +08:00
|
|
|
static int quota_enable[MAXQUOTAS];
|
2012-07-31 06:50:04 +08:00
|
|
|
static int rewrite_checksums;
|
2015-01-28 02:11:47 +08:00
|
|
|
static int feature_64bit;
|
|
|
|
static int fsck_requested;
|
2015-05-05 22:41:08 +08:00
|
|
|
static char *undo_file;
|
1997-04-26 21:21:57 +08:00
|
|
|
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
int journal_size, journal_flags;
|
|
|
|
char *journal_device;
|
2014-01-29 01:58:56 +08:00
|
|
|
static blk64_t journal_location = ~0LL;
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
|
2007-08-13 18:26:24 +08:00
|
|
|
static struct list_head blk_move_list;
|
|
|
|
|
|
|
|
struct blk_move {
|
|
|
|
struct list_head list;
|
2010-06-14 04:00:00 +08:00
|
|
|
blk64_t old_loc;
|
|
|
|
blk64_t new_loc;
|
2007-08-13 18:26:24 +08:00
|
|
|
};
|
|
|
|
|
2016-02-14 06:38:17 +08:00
|
|
|
errcode_t ext2fs_run_ext3_journal(ext2_filsys *fs);
|
2007-08-13 18:26:24 +08:00
|
|
|
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
static const char *please_fsck = N_("Please run e2fsck on the filesystem.\n");
|
2012-08-03 08:47:35 +08:00
|
|
|
static const char *please_dir_fsck =
|
|
|
|
N_("Please run e2fsck -D on the filesystem.\n");
|
1997-04-29 22:53:37 +08:00
|
|
|
|
2009-04-22 21:18:30 +08:00
|
|
|
#ifdef CONFIG_BUILD_FINDFS
|
2002-10-14 11:56:28 +08:00
|
|
|
void do_findfs(int argc, char **argv);
|
2009-04-22 21:18:30 +08:00
|
|
|
#endif
|
2002-10-14 11:56:28 +08:00
|
|
|
|
2016-04-16 07:01:38 +08:00
|
|
|
#ifdef CONFIG_JBD_DEBUG /* Enabled by configure --enable-jbd-debug */
|
|
|
|
int journal_enable_debug = -1;
|
|
|
|
#endif
|
|
|
|
|
ChangeLog, debugfs.8.in, debugfs.c:
Add a -V option which displays the current version.
ChangeLog, unix.c:
unix.c (e2fsck_update_progress): Remove unused variables.
ChangeLog, inode.c:
inode.c (get_next_blockgroup): Fix bug where if get_next_blockgroup()
is called early because of a missing inode table in a block group, the
current_inode counter wasn't incremented correctly.
ChangeLog, tst_uuid.c:
tst_uuid.c (main): Fixed bogus declaration of the main's argv parameter.
ChangeLog, test_icount.c:
test_icount.c (main): Fix main() declaration so that it returns int,
not void.
Many files:
fsck.c (ignore): Remove unused variable cp.
chattr.c (fatal_error):
tune2fs.c (usage):
lsattr.c (usage):
dumpe2fs.c (usage):
badblocks.c (usage): Remove volatile from declaration.
fsck.c: Change use of strdup to be string_copy, since we don't trust
what glibc is doing with strdup. (Whatever it is, it isn't pretty.)
1998-06-27 13:11:14 +08:00
|
|
|
static void usage(void)
|
1997-04-26 21:21:57 +08:00
|
|
|
{
|
2001-01-01 23:26:58 +08:00
|
|
|
fprintf(stderr,
|
2016-05-09 10:12:41 +08:00
|
|
|
_("Usage: %s [-c max_mounts_count] [-e errors_behavior] [-f] "
|
2001-01-01 23:26:58 +08:00
|
|
|
"[-g group]\n"
|
2008-02-29 10:26:01 +08:00
|
|
|
"\t[-i interval[d|m|w]] [-j] [-J journal_options] [-l]\n"
|
2015-07-04 10:02:30 +08:00
|
|
|
"\t[-m reserved_blocks_percent] [-o [^]mount_options[,...]]\n"
|
|
|
|
"\t[-p mmp_update_interval] [-r reserved_blocks_count] "
|
|
|
|
"[-u user]\n"
|
|
|
|
"\t[-C mount_count] [-L volume_label] [-M last_mounted_dir]\n"
|
|
|
|
"\t[-O [^]feature[,...]] [-Q quota_options]\n"
|
2008-01-27 08:06:35 +08:00
|
|
|
"\t[-E extended-option[,...]] [-T last_check_time] "
|
2015-05-05 22:41:08 +08:00
|
|
|
"[-U UUID]\n\t[-I new_inode_size] [-z undo_file] device\n"),
|
|
|
|
program_name);
|
2009-01-20 15:34:39 +08:00
|
|
|
exit(1);
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
|
|
|
|
1999-10-23 09:04:50 +08:00
|
|
|
static __u32 ok_features[3] = {
|
2008-02-28 04:01:19 +08:00
|
|
|
/* Compat */
|
2002-09-23 03:37:40 +08:00
|
|
|
EXT3_FEATURE_COMPAT_HAS_JOURNAL |
|
2008-02-28 04:01:19 +08:00
|
|
|
EXT2_FEATURE_COMPAT_DIR_INDEX,
|
|
|
|
/* Incompat */
|
2008-02-28 07:53:34 +08:00
|
|
|
EXT2_FEATURE_INCOMPAT_FILETYPE |
|
|
|
|
EXT3_FEATURE_INCOMPAT_EXTENTS |
|
2011-09-25 01:48:55 +08:00
|
|
|
EXT4_FEATURE_INCOMPAT_FLEX_BG |
|
2015-01-28 02:11:47 +08:00
|
|
|
EXT4_FEATURE_INCOMPAT_MMP |
|
2015-04-06 08:42:58 +08:00
|
|
|
EXT4_FEATURE_INCOMPAT_64BIT |
|
2016-03-06 01:38:52 +08:00
|
|
|
EXT4_FEATURE_INCOMPAT_ENCRYPT |
|
|
|
|
EXT4_FEATURE_INCOMPAT_CSUM_SEED,
|
2008-02-28 04:01:19 +08:00
|
|
|
/* R/O compat */
|
|
|
|
EXT2_FEATURE_RO_COMPAT_LARGE_FILE |
|
2008-07-10 22:49:59 +08:00
|
|
|
EXT4_FEATURE_RO_COMPAT_HUGE_FILE|
|
|
|
|
EXT4_FEATURE_RO_COMPAT_DIR_NLINK|
|
|
|
|
EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE|
|
2007-10-22 10:03:41 +08:00
|
|
|
EXT4_FEATURE_RO_COMPAT_GDT_CSUM |
|
2011-07-21 02:40:05 +08:00
|
|
|
EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER |
|
2012-07-31 06:50:04 +08:00
|
|
|
EXT4_FEATURE_RO_COMPAT_QUOTA |
|
2015-02-24 01:54:15 +08:00
|
|
|
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM |
|
2016-03-01 11:36:13 +08:00
|
|
|
EXT4_FEATURE_RO_COMPAT_READONLY |
|
|
|
|
EXT4_FEATURE_RO_COMPAT_PROJECT
|
1999-10-23 09:04:50 +08:00
|
|
|
};
|
|
|
|
|
2008-02-27 03:27:57 +08:00
|
|
|
static __u32 clear_ok_features[3] = {
|
2008-02-28 04:01:19 +08:00
|
|
|
/* Compat */
|
2008-02-27 03:27:57 +08:00
|
|
|
EXT3_FEATURE_COMPAT_HAS_JOURNAL |
|
2008-02-27 06:31:06 +08:00
|
|
|
EXT2_FEATURE_COMPAT_RESIZE_INODE |
|
2008-02-28 04:01:19 +08:00
|
|
|
EXT2_FEATURE_COMPAT_DIR_INDEX,
|
|
|
|
/* Incompat */
|
2008-02-28 07:53:34 +08:00
|
|
|
EXT2_FEATURE_INCOMPAT_FILETYPE |
|
2011-09-25 01:48:55 +08:00
|
|
|
EXT4_FEATURE_INCOMPAT_FLEX_BG |
|
2015-01-28 02:11:47 +08:00
|
|
|
EXT4_FEATURE_INCOMPAT_MMP |
|
2016-03-06 01:38:52 +08:00
|
|
|
EXT4_FEATURE_INCOMPAT_64BIT |
|
|
|
|
EXT4_FEATURE_INCOMPAT_CSUM_SEED,
|
2008-02-28 04:01:19 +08:00
|
|
|
/* R/O compat */
|
2007-10-22 10:03:41 +08:00
|
|
|
EXT2_FEATURE_RO_COMPAT_LARGE_FILE |
|
2008-07-10 22:49:59 +08:00
|
|
|
EXT4_FEATURE_RO_COMPAT_HUGE_FILE|
|
|
|
|
EXT4_FEATURE_RO_COMPAT_DIR_NLINK|
|
|
|
|
EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE|
|
2011-07-21 02:40:05 +08:00
|
|
|
EXT4_FEATURE_RO_COMPAT_GDT_CSUM |
|
2012-07-31 06:50:04 +08:00
|
|
|
EXT4_FEATURE_RO_COMPAT_QUOTA |
|
2015-02-24 01:54:15 +08:00
|
|
|
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM |
|
|
|
|
EXT4_FEATURE_RO_COMPAT_READONLY
|
1999-10-23 09:04:50 +08:00
|
|
|
};
|
|
|
|
|
2014-07-28 15:43:24 +08:00
|
|
|
/**
|
|
|
|
* Try to get journal super block if any
|
|
|
|
*/
|
|
|
|
static int get_journal_sb(ext2_filsys jfs, char buf[SUPERBLOCK_SIZE])
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
journal_superblock_t *jsb;
|
|
|
|
|
2015-10-24 13:23:01 +08:00
|
|
|
if (!ext2fs_has_feature_journal_dev(jfs->super)) {
|
2014-07-28 15:43:24 +08:00
|
|
|
return EXT2_ET_UNSUPP_FEATURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the journal superblock */
|
|
|
|
if ((retval = io_channel_read_blk64(jfs->io,
|
|
|
|
ext2fs_journal_sb_start(jfs->blocksize), -SUPERBLOCK_SIZE, buf))) {
|
|
|
|
com_err(program_name, retval, "%s",
|
|
|
|
_("while reading journal superblock"));
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
jsb = (journal_superblock_t *) buf;
|
|
|
|
if ((jsb->s_header.h_magic != (unsigned)ntohl(JFS_MAGIC_NUMBER)) ||
|
|
|
|
(jsb->s_header.h_blocktype != (unsigned)ntohl(JFS_SUPERBLOCK_V2))) {
|
|
|
|
fputs(_("Journal superblock not found!\n"), stderr);
|
|
|
|
return EXT2_ET_BAD_MAGIC;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-30 07:30:39 +08:00
|
|
|
static __u8 *journal_user(__u8 uuid[UUID_SIZE], __u8 s_users[JFS_USERS_SIZE],
|
|
|
|
int nr_users)
|
2014-07-28 15:43:25 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < nr_users; i++) {
|
|
|
|
if (memcmp(uuid, &s_users[i * UUID_SIZE], UUID_SIZE) == 0)
|
|
|
|
return &s_users[i * UUID_SIZE];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
ChangeLog, mke2fs.8.in, mke2fs.c, tune2fs.8.in, tune2fs.c:
tune2fs.c, mke2fs.c, tune2fs.8.in, mke2fs.8.in: Change user interface
so that -J is used to specify journal options, and -j is used to
request creation of a journal using default values. (This is a UI
change, but we haven't done a formal release, and it makes things much
more consistent with the rest of the options out there.)
tune2fs.c: Add support for removing a filesystem from an external
journal; we correctly remove the filesystem UUID from the external
journal's filesystem list.
2001-01-18 09:51:15 +08:00
|
|
|
/*
|
|
|
|
* Remove an external journal from the filesystem
|
|
|
|
*/
|
2011-09-25 01:48:55 +08:00
|
|
|
static int remove_journal_device(ext2_filsys fs)
|
ChangeLog, mke2fs.8.in, mke2fs.c, tune2fs.8.in, tune2fs.c:
tune2fs.c, mke2fs.c, tune2fs.8.in, mke2fs.8.in: Change user interface
so that -J is used to specify journal options, and -j is used to
request creation of a journal using default values. (This is a UI
change, but we haven't done a formal release, and it makes things much
more consistent with the rest of the options out there.)
tune2fs.c: Add support for removing a filesystem from an external
journal; we correctly remove the filesystem UUID from the external
journal's filesystem list.
2001-01-18 09:51:15 +08:00
|
|
|
{
|
2001-12-17 12:23:37 +08:00
|
|
|
char *journal_path;
|
ChangeLog, mke2fs.8.in, mke2fs.c, tune2fs.8.in, tune2fs.c:
tune2fs.c, mke2fs.c, tune2fs.8.in, mke2fs.8.in: Change user interface
so that -J is used to specify journal options, and -j is used to
request creation of a journal using default values. (This is a UI
change, but we haven't done a formal release, and it makes things much
more consistent with the rest of the options out there.)
tune2fs.c: Add support for removing a filesystem from an external
journal; we correctly remove the filesystem UUID from the external
journal's filesystem list.
2001-01-18 09:51:15 +08:00
|
|
|
ext2_filsys jfs;
|
2015-05-23 06:40:51 +08:00
|
|
|
char buf[SUPERBLOCK_SIZE] __attribute__ ((aligned(8)));
|
ChangeLog, mke2fs.8.in, mke2fs.c, tune2fs.8.in, tune2fs.c:
tune2fs.c, mke2fs.c, tune2fs.8.in, mke2fs.8.in: Change user interface
so that -J is used to specify journal options, and -j is used to
request creation of a journal using default values. (This is a UI
change, but we haven't done a formal release, and it makes things much
more consistent with the rest of the options out there.)
tune2fs.c: Add support for removing a filesystem from an external
journal; we correctly remove the filesystem UUID from the external
journal's filesystem list.
2001-01-18 09:51:15 +08:00
|
|
|
journal_superblock_t *jsb;
|
|
|
|
int i, nr_users;
|
|
|
|
errcode_t retval;
|
2001-04-24 04:58:03 +08:00
|
|
|
int commit_remove_journal = 0;
|
2003-05-06 00:08:47 +08:00
|
|
|
io_manager io_ptr;
|
2001-04-24 04:58:03 +08:00
|
|
|
|
|
|
|
if (f_flag)
|
|
|
|
commit_remove_journal = 1; /* force removal even if error */
|
ChangeLog, mke2fs.8.in, mke2fs.c, tune2fs.8.in, tune2fs.c:
tune2fs.c, mke2fs.c, tune2fs.8.in, mke2fs.8.in: Change user interface
so that -J is used to specify journal options, and -j is used to
request creation of a journal using default values. (This is a UI
change, but we haven't done a formal release, and it makes things much
more consistent with the rest of the options out there.)
tune2fs.c: Add support for removing a filesystem from an external
journal; we correctly remove the filesystem UUID from the external
journal's filesystem list.
2001-01-18 09:51:15 +08:00
|
|
|
|
2001-08-17 17:48:11 +08:00
|
|
|
uuid_unparse(fs->super->s_journal_uuid, buf);
|
2003-03-02 08:29:01 +08:00
|
|
|
journal_path = blkid_get_devname(NULL, "UUID", buf);
|
2001-08-17 17:48:11 +08:00
|
|
|
|
2001-12-17 12:23:37 +08:00
|
|
|
if (!journal_path) {
|
|
|
|
journal_path =
|
2001-08-17 17:48:11 +08:00
|
|
|
ext2fs_find_block_device(fs->super->s_journal_dev);
|
2001-12-17 12:23:37 +08:00
|
|
|
if (!journal_path)
|
2011-09-25 01:17:05 +08:00
|
|
|
goto no_valid_journal;
|
2001-08-17 17:48:11 +08:00
|
|
|
}
|
ChangeLog, mke2fs.8.in, mke2fs.c, tune2fs.8.in, tune2fs.c:
tune2fs.c, mke2fs.c, tune2fs.8.in, mke2fs.8.in: Change user interface
so that -J is used to specify journal options, and -j is used to
request creation of a journal using default values. (This is a UI
change, but we haven't done a formal release, and it makes things much
more consistent with the rest of the options out there.)
tune2fs.c: Add support for removing a filesystem from an external
journal; we correctly remove the filesystem UUID from the external
journal's filesystem list.
2001-01-18 09:51:15 +08:00
|
|
|
|
2003-05-06 00:08:47 +08:00
|
|
|
#ifdef CONFIG_TESTIO_DEBUG
|
2008-09-01 23:17:29 +08:00
|
|
|
if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) {
|
|
|
|
io_ptr = test_io_manager;
|
|
|
|
test_io_backing_manager = unix_io_manager;
|
|
|
|
} else
|
2003-05-06 00:08:47 +08:00
|
|
|
#endif
|
2008-09-01 23:17:29 +08:00
|
|
|
io_ptr = unix_io_manager;
|
2001-12-17 12:23:37 +08:00
|
|
|
retval = ext2fs_open(journal_path, EXT2_FLAG_RW|
|
ChangeLog, mke2fs.8.in, mke2fs.c, tune2fs.8.in, tune2fs.c:
tune2fs.c, mke2fs.c, tune2fs.8.in, mke2fs.8.in: Change user interface
so that -J is used to specify journal options, and -j is used to
request creation of a journal using default values. (This is a UI
change, but we haven't done a formal release, and it makes things much
more consistent with the rest of the options out there.)
tune2fs.c: Add support for removing a filesystem from an external
journal; we correctly remove the filesystem UUID from the external
journal's filesystem list.
2001-01-18 09:51:15 +08:00
|
|
|
EXT2_FLAG_JOURNAL_DEV_OK, 0,
|
2003-05-06 00:08:47 +08:00
|
|
|
fs->blocksize, io_ptr, &jfs);
|
ChangeLog, mke2fs.8.in, mke2fs.c, tune2fs.8.in, tune2fs.c:
tune2fs.c, mke2fs.c, tune2fs.8.in, mke2fs.8.in: Change user interface
so that -J is used to specify journal options, and -j is used to
request creation of a journal using default values. (This is a UI
change, but we haven't done a formal release, and it makes things much
more consistent with the rest of the options out there.)
tune2fs.c: Add support for removing a filesystem from an external
journal; we correctly remove the filesystem UUID from the external
journal's filesystem list.
2001-01-18 09:51:15 +08:00
|
|
|
if (retval) {
|
2013-12-16 11:11:40 +08:00
|
|
|
com_err(program_name, retval, "%s",
|
ChangeLog, mke2fs.8.in, mke2fs.c, tune2fs.8.in, tune2fs.c:
tune2fs.c, mke2fs.c, tune2fs.8.in, mke2fs.8.in: Change user interface
so that -J is used to specify journal options, and -j is used to
request creation of a journal using default values. (This is a UI
change, but we haven't done a formal release, and it makes things much
more consistent with the rest of the options out there.)
tune2fs.c: Add support for removing a filesystem from an external
journal; we correctly remove the filesystem UUID from the external
journal's filesystem list.
2001-01-18 09:51:15 +08:00
|
|
|
_("while trying to open external journal"));
|
2001-04-24 04:58:03 +08:00
|
|
|
goto no_valid_journal;
|
ChangeLog, mke2fs.8.in, mke2fs.c, tune2fs.8.in, tune2fs.c:
tune2fs.c, mke2fs.c, tune2fs.8.in, mke2fs.8.in: Change user interface
so that -J is used to specify journal options, and -j is used to
request creation of a journal using default values. (This is a UI
change, but we haven't done a formal release, and it makes things much
more consistent with the rest of the options out there.)
tune2fs.c: Add support for removing a filesystem from an external
journal; we correctly remove the filesystem UUID from the external
journal's filesystem list.
2001-01-18 09:51:15 +08:00
|
|
|
}
|
|
|
|
|
2014-07-28 15:43:24 +08:00
|
|
|
if ((retval = get_journal_sb(jfs, buf))) {
|
|
|
|
if (retval == EXT2_ET_UNSUPP_FEATURE)
|
|
|
|
fprintf(stderr, _("%s is not a journal device.\n"),
|
|
|
|
journal_path);
|
2001-04-24 04:58:03 +08:00
|
|
|
goto no_valid_journal;
|
ChangeLog, mke2fs.8.in, mke2fs.c, tune2fs.8.in, tune2fs.c:
tune2fs.c, mke2fs.c, tune2fs.8.in, mke2fs.8.in: Change user interface
so that -J is used to specify journal options, and -j is used to
request creation of a journal using default values. (This is a UI
change, but we haven't done a formal release, and it makes things much
more consistent with the rest of the options out there.)
tune2fs.c: Add support for removing a filesystem from an external
journal; we correctly remove the filesystem UUID from the external
journal's filesystem list.
2001-01-18 09:51:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
jsb = (journal_superblock_t *) buf;
|
|
|
|
/* Find the filesystem UUID */
|
|
|
|
nr_users = ntohl(jsb->s_nr_users);
|
2014-07-28 15:43:25 +08:00
|
|
|
|
|
|
|
if (!journal_user(fs->super->s_uuid, jsb->s_users, nr_users)) {
|
2008-08-28 11:07:54 +08:00
|
|
|
fputs(_("Filesystem's UUID not found on journal device.\n"),
|
2003-12-07 14:28:50 +08:00
|
|
|
stderr);
|
2001-04-24 04:58:03 +08:00
|
|
|
commit_remove_journal = 1;
|
|
|
|
goto no_valid_journal;
|
ChangeLog, mke2fs.8.in, mke2fs.c, tune2fs.8.in, tune2fs.c:
tune2fs.c, mke2fs.c, tune2fs.8.in, mke2fs.8.in: Change user interface
so that -J is used to specify journal options, and -j is used to
request creation of a journal using default values. (This is a UI
change, but we haven't done a formal release, and it makes things much
more consistent with the rest of the options out there.)
tune2fs.c: Add support for removing a filesystem from an external
journal; we correctly remove the filesystem UUID from the external
journal's filesystem list.
2001-01-18 09:51:15 +08:00
|
|
|
}
|
|
|
|
nr_users--;
|
2009-01-20 15:34:39 +08:00
|
|
|
for (i = 0; i < nr_users; i++)
|
2011-09-25 01:25:34 +08:00
|
|
|
memcpy(&jsb->s_users[i * 16], &jsb->s_users[(i + 1) * 16], 16);
|
ChangeLog, mke2fs.8.in, mke2fs.c, tune2fs.8.in, tune2fs.c:
tune2fs.c, mke2fs.c, tune2fs.8.in, mke2fs.8.in: Change user interface
so that -J is used to specify journal options, and -j is used to
request creation of a journal using default values. (This is a UI
change, but we haven't done a formal release, and it makes things much
more consistent with the rest of the options out there.)
tune2fs.c: Add support for removing a filesystem from an external
journal; we correctly remove the filesystem UUID from the external
journal's filesystem list.
2001-01-18 09:51:15 +08:00
|
|
|
jsb->s_nr_users = htonl(nr_users);
|
|
|
|
|
|
|
|
/* Write back the journal superblock */
|
2014-07-30 07:30:39 +08:00
|
|
|
retval = io_channel_write_blk64(jfs->io,
|
|
|
|
ext2fs_journal_sb_start(fs->blocksize),
|
|
|
|
-SUPERBLOCK_SIZE, buf);
|
|
|
|
if (retval) {
|
ChangeLog, mke2fs.8.in, mke2fs.c, tune2fs.8.in, tune2fs.c:
tune2fs.c, mke2fs.c, tune2fs.8.in, mke2fs.8.in: Change user interface
so that -J is used to specify journal options, and -j is used to
request creation of a journal using default values. (This is a UI
change, but we haven't done a formal release, and it makes things much
more consistent with the rest of the options out there.)
tune2fs.c: Add support for removing a filesystem from an external
journal; we correctly remove the filesystem UUID from the external
journal's filesystem list.
2001-01-18 09:51:15 +08:00
|
|
|
com_err(program_name, retval,
|
|
|
|
"while writing journal superblock.");
|
2001-04-24 04:58:03 +08:00
|
|
|
goto no_valid_journal;
|
ChangeLog, mke2fs.8.in, mke2fs.c, tune2fs.8.in, tune2fs.c:
tune2fs.c, mke2fs.c, tune2fs.8.in, mke2fs.8.in: Change user interface
so that -J is used to specify journal options, and -j is used to
request creation of a journal using default values. (This is a UI
change, but we haven't done a formal release, and it makes things much
more consistent with the rest of the options out there.)
tune2fs.c: Add support for removing a filesystem from an external
journal; we correctly remove the filesystem UUID from the external
journal's filesystem list.
2001-01-18 09:51:15 +08:00
|
|
|
}
|
|
|
|
|
2001-04-24 04:58:03 +08:00
|
|
|
commit_remove_journal = 1;
|
|
|
|
|
|
|
|
no_valid_journal:
|
|
|
|
if (commit_remove_journal == 0) {
|
2011-09-25 01:17:05 +08:00
|
|
|
fputs(_("Cannot locate journal device. It was NOT removed\n"
|
|
|
|
"Use -f option to remove missing journal device.\n"),
|
|
|
|
stderr);
|
2011-09-25 01:48:55 +08:00
|
|
|
return 1;
|
2001-04-24 04:58:03 +08:00
|
|
|
}
|
ChangeLog, mke2fs.8.in, mke2fs.c, tune2fs.8.in, tune2fs.c:
tune2fs.c, mke2fs.c, tune2fs.8.in, mke2fs.8.in: Change user interface
so that -J is used to specify journal options, and -j is used to
request creation of a journal using default values. (This is a UI
change, but we haven't done a formal release, and it makes things much
more consistent with the rest of the options out there.)
tune2fs.c: Add support for removing a filesystem from an external
journal; we correctly remove the filesystem UUID from the external
journal's filesystem list.
2001-01-18 09:51:15 +08:00
|
|
|
fs->super->s_journal_dev = 0;
|
2014-09-19 09:24:26 +08:00
|
|
|
memset(fs->super->s_jnl_blocks, 0, sizeof(fs->super->s_jnl_blocks));
|
2003-03-02 08:29:01 +08:00
|
|
|
uuid_clear(fs->super->s_journal_uuid);
|
ChangeLog, mke2fs.8.in, mke2fs.c, tune2fs.8.in, tune2fs.c:
tune2fs.c, mke2fs.c, tune2fs.8.in, mke2fs.8.in: Change user interface
so that -J is used to specify journal options, and -j is used to
request creation of a journal using default values. (This is a UI
change, but we haven't done a formal release, and it makes things much
more consistent with the rest of the options out there.)
tune2fs.c: Add support for removing a filesystem from an external
journal; we correctly remove the filesystem UUID from the external
journal's filesystem list.
2001-01-18 09:51:15 +08:00
|
|
|
ext2fs_mark_super_dirty(fs);
|
2003-12-07 14:28:50 +08:00
|
|
|
fputs(_("Journal removed\n"), stdout);
|
2001-12-17 12:23:37 +08:00
|
|
|
free(journal_path);
|
2011-09-25 01:48:55 +08:00
|
|
|
|
|
|
|
return 0;
|
ChangeLog, mke2fs.8.in, mke2fs.c, tune2fs.8.in, tune2fs.c:
tune2fs.c, mke2fs.c, tune2fs.8.in, mke2fs.8.in: Change user interface
so that -J is used to specify journal options, and -j is used to
request creation of a journal using default values. (This is a UI
change, but we haven't done a formal release, and it makes things much
more consistent with the rest of the options out there.)
tune2fs.c: Add support for removing a filesystem from an external
journal; we correctly remove the filesystem UUID from the external
journal's filesystem list.
2001-01-18 09:51:15 +08:00
|
|
|
}
|
|
|
|
|
2001-08-01 00:03:23 +08:00
|
|
|
/* Helper function for remove_journal_inode */
|
2010-06-14 04:00:00 +08:00
|
|
|
static int release_blocks_proc(ext2_filsys fs, blk64_t *blocknr,
|
|
|
|
e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
|
|
|
|
blk64_t ref_block EXT2FS_ATTR((unused)),
|
|
|
|
int ref_offset EXT2FS_ATTR((unused)),
|
2003-12-07 14:28:50 +08:00
|
|
|
void *private EXT2FS_ATTR((unused)))
|
2001-08-01 00:03:23 +08:00
|
|
|
{
|
2010-06-14 04:00:00 +08:00
|
|
|
blk64_t block;
|
2001-08-01 00:03:23 +08:00
|
|
|
int group;
|
|
|
|
|
|
|
|
block = *blocknr;
|
2009-08-23 09:15:30 +08:00
|
|
|
ext2fs_unmark_block_bitmap2(fs->block_map, block);
|
2009-10-26 08:50:15 +08:00
|
|
|
group = ext2fs_group_of_blk2(fs, block);
|
Convert to use block group accessor functions
Convert direct accesses to use the following block group accessor
functions: ext2fs_block_bitmap_loc(), ext2fs_inode_bitmap_loc(),
ext2fs_inode_table_loc(), ext2fs_bg_itable_unused(),
ext2fs_block_bitmap_loc_set(), ext2fs_inode_bitmap_loc_set(),
ext2fs_inode_table_loc_set(), ext2fs_bg_free_inodes_count(),
ext2fs_ext2fs_bg_used_dirs_count(), ext2fs_bg_free_inodes_count_set(),
ext2fs_bg_free_blocks_count_set(), ext2fs_bg_used_dirs_count_set()
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com>
Signed-off-by: Nick Dokos <nicholas.dokos@hp.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-26 09:43:47 +08:00
|
|
|
ext2fs_bg_free_blocks_count_set(fs, group, ext2fs_bg_free_blocks_count(fs, group) + 1);
|
2007-10-22 10:03:41 +08:00
|
|
|
ext2fs_group_desc_csum_set(fs, group);
|
2011-06-16 13:38:43 +08:00
|
|
|
ext2fs_free_blocks_count_add(fs->super, EXT2FS_CLUSTER_RATIO(fs));
|
2001-08-01 00:03:23 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove the journal inode from the filesystem
|
|
|
|
*/
|
2011-09-25 01:48:55 +08:00
|
|
|
static errcode_t remove_journal_inode(ext2_filsys fs)
|
2001-08-01 00:03:23 +08:00
|
|
|
{
|
|
|
|
struct ext2_inode inode;
|
|
|
|
errcode_t retval;
|
|
|
|
ino_t ino = fs->super->s_journal_inum;
|
2008-08-28 11:07:54 +08:00
|
|
|
|
2001-08-01 00:03:23 +08:00
|
|
|
retval = ext2fs_read_inode(fs, ino, &inode);
|
|
|
|
if (retval) {
|
2013-12-16 11:11:40 +08:00
|
|
|
com_err(program_name, retval, "%s",
|
2001-08-01 00:03:23 +08:00
|
|
|
_("while reading journal inode"));
|
2011-09-25 01:48:55 +08:00
|
|
|
return retval;
|
2001-08-01 00:03:23 +08:00
|
|
|
}
|
|
|
|
if (ino == EXT2_JOURNAL_INO) {
|
|
|
|
retval = ext2fs_read_bitmaps(fs);
|
|
|
|
if (retval) {
|
2013-12-16 11:11:40 +08:00
|
|
|
com_err(program_name, retval, "%s",
|
2001-08-01 00:03:23 +08:00
|
|
|
_("while reading bitmaps"));
|
2011-09-25 01:48:55 +08:00
|
|
|
return retval;
|
2001-08-01 00:03:23 +08:00
|
|
|
}
|
2010-06-14 04:00:00 +08:00
|
|
|
retval = ext2fs_block_iterate3(fs, ino,
|
|
|
|
BLOCK_FLAG_READ_ONLY, NULL,
|
|
|
|
release_blocks_proc, NULL);
|
2001-08-01 00:03:23 +08:00
|
|
|
if (retval) {
|
2013-12-16 11:11:40 +08:00
|
|
|
com_err(program_name, retval, "%s",
|
2001-08-01 00:03:23 +08:00
|
|
|
_("while clearing journal inode"));
|
2011-09-25 01:48:55 +08:00
|
|
|
return retval;
|
2001-08-01 00:03:23 +08:00
|
|
|
}
|
|
|
|
memset(&inode, 0, sizeof(inode));
|
|
|
|
ext2fs_mark_bb_dirty(fs);
|
|
|
|
fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
|
|
|
|
} else
|
|
|
|
inode.i_flags &= ~EXT2_IMMUTABLE_FL;
|
|
|
|
retval = ext2fs_write_inode(fs, ino, &inode);
|
|
|
|
if (retval) {
|
2013-12-16 11:11:40 +08:00
|
|
|
com_err(program_name, retval, "%s",
|
2001-08-01 00:03:23 +08:00
|
|
|
_("while writing journal inode"));
|
2011-09-25 01:48:55 +08:00
|
|
|
return retval;
|
2001-08-01 00:03:23 +08:00
|
|
|
}
|
|
|
|
fs->super->s_journal_inum = 0;
|
2014-09-09 07:12:35 +08:00
|
|
|
memset(fs->super->s_jnl_blocks, 0, sizeof(fs->super->s_jnl_blocks));
|
2001-08-01 00:03:23 +08:00
|
|
|
ext2fs_mark_super_dirty(fs);
|
2011-09-25 01:48:55 +08:00
|
|
|
|
|
|
|
return 0;
|
2001-08-01 00:03:23 +08:00
|
|
|
}
|
ChangeLog, mke2fs.8.in, mke2fs.c, tune2fs.8.in, tune2fs.c:
tune2fs.c, mke2fs.c, tune2fs.8.in, mke2fs.8.in: Change user interface
so that -J is used to specify journal options, and -j is used to
request creation of a journal using default values. (This is a UI
change, but we haven't done a formal release, and it makes things much
more consistent with the rest of the options out there.)
tune2fs.c: Add support for removing a filesystem from an external
journal; we correctly remove the filesystem UUID from the external
journal's filesystem list.
2001-01-18 09:51:15 +08:00
|
|
|
|
2002-10-16 05:43:43 +08:00
|
|
|
/*
|
|
|
|
* Update the default mount options
|
|
|
|
*/
|
2011-09-25 01:48:55 +08:00
|
|
|
static int update_mntopts(ext2_filsys fs, char *mntopts)
|
2002-10-16 05:43:43 +08:00
|
|
|
{
|
2009-01-20 15:34:39 +08:00
|
|
|
struct ext2_super_block *sb = fs->super;
|
2002-10-16 05:43:43 +08:00
|
|
|
|
|
|
|
if (e2p_edit_mntopts(mntopts, &sb->s_default_mount_opts, ~0)) {
|
|
|
|
fprintf(stderr, _("Invalid mount option set: %s\n"),
|
|
|
|
mntopts);
|
2011-09-25 01:48:55 +08:00
|
|
|
return 1;
|
2002-10-16 05:43:43 +08:00
|
|
|
}
|
|
|
|
ext2fs_mark_super_dirty(fs);
|
2011-09-25 01:48:55 +08:00
|
|
|
|
|
|
|
return 0;
|
2002-10-16 05:43:43 +08:00
|
|
|
}
|
|
|
|
|
2016-02-14 06:38:11 +08:00
|
|
|
static void check_fsck_needed(ext2_filsys fs, const char *prompt)
|
2012-07-31 06:50:04 +08:00
|
|
|
{
|
2016-02-14 06:38:11 +08:00
|
|
|
/* Refuse to modify anything but a freshly checked valid filesystem. */
|
|
|
|
if (!(fs->super->s_state & EXT2_VALID_FS) ||
|
|
|
|
(fs->super->s_state & EXT2_ERROR_FS) ||
|
|
|
|
(fs->super->s_lastcheck < fs->super->s_mtime)) {
|
|
|
|
printf("\n%s\n", _(please_fsck));
|
|
|
|
if (mount_flags & EXT2_MF_READONLY)
|
|
|
|
printf("%s", _("(and reboot afterwards!)\n"));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Give the admin a few seconds to bail out of a dangerous op. */
|
|
|
|
if (!getenv("TUNE2FS_FORCE_PROMPT") && (!isatty(0) || !isatty(1)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
puts(prompt);
|
|
|
|
proceed_question(5);
|
2012-07-31 06:50:04 +08:00
|
|
|
}
|
|
|
|
|
2012-08-03 08:47:35 +08:00
|
|
|
static void request_dir_fsck_afterwards(ext2_filsys fs)
|
|
|
|
{
|
|
|
|
static int requested;
|
|
|
|
|
|
|
|
if (requested++)
|
|
|
|
return;
|
2015-01-28 02:11:47 +08:00
|
|
|
fsck_requested++;
|
2012-08-03 08:47:35 +08:00
|
|
|
fs->super->s_state &= ~EXT2_VALID_FS;
|
|
|
|
printf("\n%s\n", _(please_dir_fsck));
|
|
|
|
if (mount_flags & EXT2_MF_READONLY)
|
2014-05-28 01:14:18 +08:00
|
|
|
printf("%s", _("(and reboot afterwards!)\n"));
|
2012-08-03 08:47:35 +08:00
|
|
|
}
|
|
|
|
|
2010-05-20 00:14:39 +08:00
|
|
|
static void request_fsck_afterwards(ext2_filsys fs)
|
|
|
|
{
|
|
|
|
static int requested = 0;
|
|
|
|
|
|
|
|
if (requested++)
|
|
|
|
return;
|
2015-01-28 02:11:47 +08:00
|
|
|
fsck_requested++;
|
2010-05-20 00:14:39 +08:00
|
|
|
fs->super->s_state &= ~EXT2_VALID_FS;
|
|
|
|
printf("\n%s\n", _(please_fsck));
|
|
|
|
if (mount_flags & EXT2_MF_READONLY)
|
2013-12-16 11:11:40 +08:00
|
|
|
printf("%s", _("(and reboot afterwards!)\n"));
|
2010-05-20 00:14:39 +08:00
|
|
|
}
|
|
|
|
|
2015-01-28 02:11:47 +08:00
|
|
|
static void convert_64bit(ext2_filsys fs, int direction)
|
|
|
|
{
|
|
|
|
if (!direction)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is resize2fs going to demand a fsck run? Might as well tell the
|
|
|
|
* user now.
|
|
|
|
*/
|
|
|
|
if (!fsck_requested &&
|
|
|
|
((fs->super->s_state & EXT2_ERROR_FS) ||
|
|
|
|
!(fs->super->s_state & EXT2_VALID_FS) ||
|
|
|
|
fs->super->s_lastcheck < fs->super->s_mtime))
|
|
|
|
request_fsck_afterwards(fs);
|
|
|
|
if (fsck_requested)
|
|
|
|
fprintf(stderr, _("After running e2fsck, please run `resize2fs %s %s"),
|
|
|
|
direction > 0 ? "-b" : "-s", fs->device_name);
|
|
|
|
else
|
|
|
|
fprintf(stderr, _("Please run `resize2fs %s %s"),
|
|
|
|
direction > 0 ? "-b" : "-s", fs->device_name);
|
|
|
|
|
2015-05-05 22:41:08 +08:00
|
|
|
if (undo_file)
|
|
|
|
fprintf(stderr, _(" -z \"%s\""), undo_file);
|
2015-01-28 02:11:47 +08:00
|
|
|
if (direction > 0)
|
|
|
|
fprintf(stderr, _("' to enable 64-bit mode.\n"));
|
|
|
|
else
|
|
|
|
fprintf(stderr, _("' to disable 64-bit mode.\n"));
|
|
|
|
}
|
|
|
|
|
2012-07-31 07:16:04 +08:00
|
|
|
/* Rewrite extents */
|
|
|
|
static errcode_t rewrite_extents(ext2_filsys fs, ext2_ino_t ino,
|
|
|
|
struct ext2_inode *inode)
|
|
|
|
{
|
|
|
|
ext2_extent_handle_t handle;
|
|
|
|
struct ext2fs_extent extent;
|
|
|
|
errcode_t errcode;
|
2014-11-05 00:52:03 +08:00
|
|
|
struct ext2_extent_info info;
|
2012-07-31 07:16:04 +08:00
|
|
|
|
2014-11-05 00:52:03 +08:00
|
|
|
if (!(inode->i_flags & EXT4_EXTENTS_FL) ||
|
2015-10-24 13:23:01 +08:00
|
|
|
!ext2fs_has_feature_metadata_csum(fs->super))
|
2012-07-31 07:16:04 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
errcode = ext2fs_extent_open(fs, ino, &handle);
|
|
|
|
if (errcode)
|
|
|
|
return errcode;
|
|
|
|
|
2014-11-05 00:52:03 +08:00
|
|
|
errcode = ext2fs_extent_get(handle, EXT2_EXTENT_ROOT, &extent);
|
|
|
|
if (errcode)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
do {
|
|
|
|
errcode = ext2fs_extent_get_info(handle, &info);
|
2012-07-31 07:16:04 +08:00
|
|
|
if (errcode)
|
|
|
|
break;
|
|
|
|
|
2014-11-05 00:52:03 +08:00
|
|
|
/*
|
|
|
|
* If this is the first extent in an extent block that we
|
|
|
|
* haven't visited, rewrite the extent to force the ETB
|
|
|
|
* checksum to be rewritten.
|
|
|
|
*/
|
|
|
|
if (info.curr_entry == 1 && info.curr_level != 0 &&
|
|
|
|
!(extent.e_flags & EXT2_EXTENT_FLAGS_SECOND_VISIT)) {
|
|
|
|
errcode = ext2fs_extent_replace(handle, 0, &extent);
|
|
|
|
if (errcode)
|
|
|
|
break;
|
2012-07-31 07:16:04 +08:00
|
|
|
}
|
|
|
|
|
2014-11-05 00:52:03 +08:00
|
|
|
/* Skip to the end of a block of leaf nodes */
|
|
|
|
if (extent.e_flags & EXT2_EXTENT_FLAGS_LEAF) {
|
|
|
|
errcode = ext2fs_extent_get(handle,
|
|
|
|
EXT2_EXTENT_LAST_SIB,
|
|
|
|
&extent);
|
|
|
|
if (errcode)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
errcode = ext2fs_extent_get(handle, EXT2_EXTENT_NEXT, &extent);
|
|
|
|
} while (errcode == 0);
|
2012-07-31 07:16:04 +08:00
|
|
|
|
2014-11-05 00:52:03 +08:00
|
|
|
out:
|
2012-07-31 07:16:04 +08:00
|
|
|
/* Ok if we run off the end */
|
|
|
|
if (errcode == EXT2_ET_EXTENT_NO_NEXT)
|
|
|
|
errcode = 0;
|
2014-11-05 00:52:03 +08:00
|
|
|
ext2fs_extent_free(handle);
|
2012-07-31 07:16:04 +08:00
|
|
|
return errcode;
|
|
|
|
}
|
|
|
|
|
2012-08-03 08:47:35 +08:00
|
|
|
/*
|
|
|
|
* Rewrite directory blocks with checksums
|
|
|
|
*/
|
|
|
|
struct rewrite_dir_context {
|
|
|
|
char *buf;
|
|
|
|
errcode_t errcode;
|
|
|
|
ext2_ino_t dir;
|
|
|
|
int is_htree;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int rewrite_dir_block(ext2_filsys fs,
|
|
|
|
blk64_t *blocknr,
|
2013-05-20 21:21:34 +08:00
|
|
|
e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
|
2012-08-03 08:47:35 +08:00
|
|
|
blk64_t ref_block EXT2FS_ATTR((unused)),
|
|
|
|
int ref_offset EXT2FS_ATTR((unused)),
|
|
|
|
void *priv_data)
|
|
|
|
{
|
|
|
|
struct ext2_dx_countlimit *dcl = NULL;
|
|
|
|
struct rewrite_dir_context *ctx = priv_data;
|
|
|
|
int dcl_offset, changed = 0;
|
|
|
|
|
|
|
|
ctx->errcode = ext2fs_read_dir_block4(fs, *blocknr, ctx->buf, 0,
|
|
|
|
ctx->dir);
|
|
|
|
if (ctx->errcode)
|
|
|
|
return BLOCK_ABORT;
|
|
|
|
|
|
|
|
/* if htree node... */
|
|
|
|
if (ctx->is_htree)
|
|
|
|
ext2fs_get_dx_countlimit(fs, (struct ext2_dir_entry *)ctx->buf,
|
|
|
|
&dcl, &dcl_offset);
|
|
|
|
if (dcl) {
|
2015-10-24 13:23:01 +08:00
|
|
|
if (!ext2fs_has_feature_metadata_csum(fs->super)) {
|
2012-08-03 08:47:35 +08:00
|
|
|
/* Ensure limit is the max size */
|
|
|
|
int max_entries = (fs->blocksize - dcl_offset) /
|
|
|
|
sizeof(struct ext2_dx_entry);
|
|
|
|
if (ext2fs_le16_to_cpu(dcl->limit) != max_entries) {
|
|
|
|
changed = 1;
|
|
|
|
dcl->limit = ext2fs_cpu_to_le16(max_entries);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* If htree block is full then rebuild the dir */
|
|
|
|
if (ext2fs_le16_to_cpu(dcl->count) ==
|
|
|
|
ext2fs_le16_to_cpu(dcl->limit)) {
|
|
|
|
request_dir_fsck_afterwards(fs);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Ensure dcl->limit is small enough to leave room for
|
|
|
|
* the checksum tail.
|
|
|
|
*/
|
|
|
|
int max_entries = (fs->blocksize - (dcl_offset +
|
|
|
|
sizeof(struct ext2_dx_tail))) /
|
|
|
|
sizeof(struct ext2_dx_entry);
|
|
|
|
if (ext2fs_le16_to_cpu(dcl->limit) != max_entries)
|
|
|
|
dcl->limit = ext2fs_cpu_to_le16(max_entries);
|
|
|
|
/* Always rewrite checksum */
|
|
|
|
changed = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
unsigned int rec_len, name_size;
|
|
|
|
char *top = ctx->buf + fs->blocksize;
|
|
|
|
struct ext2_dir_entry *de = (struct ext2_dir_entry *)ctx->buf;
|
|
|
|
struct ext2_dir_entry *last_de = NULL, *penultimate_de = NULL;
|
|
|
|
|
|
|
|
/* Find last and penultimate dirent */
|
|
|
|
while ((char *)de < top) {
|
|
|
|
penultimate_de = last_de;
|
|
|
|
last_de = de;
|
|
|
|
ctx->errcode = ext2fs_get_rec_len(fs, de, &rec_len);
|
|
|
|
if (!ctx->errcode && !rec_len)
|
|
|
|
ctx->errcode = EXT2_ET_DIR_CORRUPTED;
|
|
|
|
if (ctx->errcode)
|
|
|
|
return BLOCK_ABORT;
|
2013-05-20 21:21:34 +08:00
|
|
|
de = (struct ext2_dir_entry *)(((char *)de) + rec_len);
|
2012-08-03 08:47:35 +08:00
|
|
|
}
|
|
|
|
ctx->errcode = ext2fs_get_rec_len(fs, last_de, &rec_len);
|
|
|
|
if (ctx->errcode)
|
|
|
|
return BLOCK_ABORT;
|
2013-06-08 23:26:14 +08:00
|
|
|
name_size = ext2fs_dirent_name_len(last_de);
|
2012-08-03 08:47:35 +08:00
|
|
|
|
2015-10-24 13:23:01 +08:00
|
|
|
if (!ext2fs_has_feature_metadata_csum(fs->super)) {
|
2012-08-03 08:47:35 +08:00
|
|
|
if (!penultimate_de)
|
|
|
|
return 0;
|
|
|
|
if (last_de->inode ||
|
|
|
|
name_size ||
|
|
|
|
rec_len != sizeof(struct ext2_dir_entry_tail))
|
|
|
|
return 0;
|
|
|
|
/*
|
|
|
|
* The last dirent is unused and the right length to
|
|
|
|
* have stored a checksum. Erase it.
|
|
|
|
*/
|
|
|
|
ctx->errcode = ext2fs_get_rec_len(fs, penultimate_de,
|
|
|
|
&rec_len);
|
|
|
|
if (!rec_len)
|
|
|
|
ctx->errcode = EXT2_ET_DIR_CORRUPTED;
|
|
|
|
if (ctx->errcode)
|
|
|
|
return BLOCK_ABORT;
|
|
|
|
ext2fs_set_rec_len(fs, rec_len +
|
|
|
|
sizeof(struct ext2_dir_entry_tail),
|
|
|
|
penultimate_de);
|
|
|
|
changed = 1;
|
|
|
|
} else {
|
2013-05-20 21:21:34 +08:00
|
|
|
unsigned csum_size = sizeof(struct ext2_dir_entry_tail);
|
2012-08-03 08:47:35 +08:00
|
|
|
struct ext2_dir_entry_tail *t;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the last dirent looks like the tail, just update
|
|
|
|
* the checksum.
|
|
|
|
*/
|
|
|
|
if (!last_de->inode &&
|
|
|
|
rec_len == csum_size) {
|
|
|
|
t = (struct ext2_dir_entry_tail *)last_de;
|
|
|
|
t->det_reserved_name_len =
|
|
|
|
EXT2_DIR_NAME_LEN_CSUM;
|
|
|
|
changed = 1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (name_size & 3)
|
|
|
|
name_size = (name_size & ~3) + 4;
|
|
|
|
/* If there's not enough space for the tail, e2fsck */
|
|
|
|
if (rec_len <= (8 + name_size + csum_size)) {
|
|
|
|
request_dir_fsck_afterwards(fs);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* Shorten that last de and insert the tail */
|
|
|
|
ext2fs_set_rec_len(fs, rec_len - csum_size, last_de);
|
|
|
|
t = EXT2_DIRENT_TAIL(ctx->buf, fs->blocksize);
|
|
|
|
ext2fs_initialize_dirent_tail(fs, t);
|
|
|
|
|
|
|
|
/* Always update checksum */
|
|
|
|
changed = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (!changed)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ctx->errcode = ext2fs_write_dir_block4(fs, *blocknr, ctx->buf,
|
|
|
|
0, ctx->dir);
|
|
|
|
if (ctx->errcode)
|
|
|
|
return BLOCK_ABORT;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-05-20 21:21:34 +08:00
|
|
|
static errcode_t rewrite_directory(ext2_filsys fs, ext2_ino_t dir,
|
|
|
|
struct ext2_inode *inode)
|
2012-08-03 08:47:35 +08:00
|
|
|
{
|
|
|
|
errcode_t retval;
|
|
|
|
struct rewrite_dir_context ctx;
|
|
|
|
|
|
|
|
retval = ext2fs_get_mem(fs->blocksize, &ctx.buf);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
ctx.is_htree = (inode->i_flags & EXT2_INDEX_FL);
|
|
|
|
ctx.dir = dir;
|
|
|
|
ctx.errcode = 0;
|
|
|
|
retval = ext2fs_block_iterate3(fs, dir, BLOCK_FLAG_READ_ONLY |
|
|
|
|
BLOCK_FLAG_DATA_ONLY,
|
|
|
|
0, rewrite_dir_block, &ctx);
|
|
|
|
|
|
|
|
ext2fs_free_mem(&ctx.buf);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
return ctx.errcode;
|
|
|
|
}
|
|
|
|
|
2012-07-31 06:50:04 +08:00
|
|
|
/*
|
|
|
|
* Forcibly set checksums in all inodes.
|
|
|
|
*/
|
|
|
|
static void rewrite_inodes(ext2_filsys fs)
|
|
|
|
{
|
|
|
|
int length = EXT2_INODE_SIZE(fs->super);
|
2013-09-16 21:41:15 +08:00
|
|
|
struct ext2_inode *inode, *zero;
|
2012-08-03 08:47:44 +08:00
|
|
|
char *ea_buf;
|
2012-07-31 06:50:04 +08:00
|
|
|
ext2_inode_scan scan;
|
|
|
|
errcode_t retval;
|
|
|
|
ext2_ino_t ino;
|
2012-08-03 08:47:44 +08:00
|
|
|
blk64_t file_acl_block;
|
2013-09-16 21:41:15 +08:00
|
|
|
int inode_dirty;
|
2012-07-31 06:50:04 +08:00
|
|
|
|
|
|
|
if (fs->super->s_creator_os != EXT2_OS_LINUX)
|
|
|
|
return;
|
|
|
|
|
|
|
|
retval = ext2fs_open_inode_scan(fs, 0, &scan);
|
|
|
|
if (retval) {
|
|
|
|
com_err("set_csum", retval, "while opening inode scan");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = ext2fs_get_mem(length, &inode);
|
|
|
|
if (retval) {
|
|
|
|
com_err("set_csum", retval, "while allocating memory");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2013-09-16 21:41:15 +08:00
|
|
|
retval = ext2fs_get_memzero(length, &zero);
|
|
|
|
if (retval) {
|
|
|
|
com_err("set_csum", retval, "while allocating memory");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2012-08-03 08:47:44 +08:00
|
|
|
retval = ext2fs_get_mem(fs->blocksize, &ea_buf);
|
|
|
|
if (retval) {
|
|
|
|
com_err("set_csum", retval, "while allocating memory");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2012-07-31 06:50:04 +08:00
|
|
|
do {
|
|
|
|
retval = ext2fs_get_next_inode_full(scan, &ino, inode, length);
|
|
|
|
if (retval) {
|
|
|
|
com_err("set_csum", retval, "while getting next inode");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (!ino)
|
|
|
|
break;
|
2013-09-16 21:41:15 +08:00
|
|
|
if (ext2fs_test_inode_bitmap2(fs->inode_map, ino)) {
|
|
|
|
inode_dirty = 1;
|
|
|
|
} else {
|
|
|
|
if (memcmp(inode, zero, length) != 0) {
|
|
|
|
memset(inode, 0, length);
|
|
|
|
inode_dirty = 1;
|
|
|
|
} else {
|
|
|
|
inode_dirty = 0;
|
|
|
|
}
|
|
|
|
}
|
2012-07-31 06:50:04 +08:00
|
|
|
|
2013-09-16 21:41:15 +08:00
|
|
|
if (inode_dirty) {
|
|
|
|
retval = ext2fs_write_inode_full(fs, ino, inode,
|
|
|
|
length);
|
|
|
|
if (retval) {
|
|
|
|
com_err("set_csum", retval, "while writing "
|
|
|
|
"inode");
|
|
|
|
exit(1);
|
|
|
|
}
|
2012-07-31 06:50:04 +08:00
|
|
|
}
|
2012-07-31 07:16:04 +08:00
|
|
|
|
|
|
|
retval = rewrite_extents(fs, ino, inode);
|
|
|
|
if (retval) {
|
|
|
|
com_err("rewrite_extents", retval,
|
|
|
|
"while rewriting extents");
|
|
|
|
exit(1);
|
|
|
|
}
|
2012-08-03 08:47:35 +08:00
|
|
|
|
2014-03-03 13:27:48 +08:00
|
|
|
if (LINUX_S_ISDIR(inode->i_mode) &&
|
|
|
|
ext2fs_inode_has_valid_blocks2(fs, inode)) {
|
2012-08-03 08:47:35 +08:00
|
|
|
retval = rewrite_directory(fs, ino, inode);
|
|
|
|
if (retval) {
|
|
|
|
com_err("rewrite_directory", retval,
|
|
|
|
"while rewriting directories");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2012-08-03 08:47:44 +08:00
|
|
|
|
|
|
|
file_acl_block = ext2fs_file_acl_block(fs, inode);
|
|
|
|
if (!file_acl_block)
|
|
|
|
continue;
|
|
|
|
retval = ext2fs_read_ext_attr3(fs, file_acl_block, ea_buf, ino);
|
|
|
|
if (retval) {
|
|
|
|
com_err("rewrite_eablock", retval,
|
|
|
|
"while rewriting extended attribute");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
retval = ext2fs_write_ext_attr3(fs, file_acl_block, ea_buf,
|
|
|
|
ino);
|
|
|
|
if (retval) {
|
|
|
|
com_err("rewrite_eablock", retval,
|
|
|
|
"while rewriting extended attribute");
|
|
|
|
exit(1);
|
|
|
|
}
|
2012-07-31 06:50:04 +08:00
|
|
|
} while (ino);
|
|
|
|
|
2013-09-16 21:41:15 +08:00
|
|
|
ext2fs_free_mem(&zero);
|
2012-07-31 06:50:04 +08:00
|
|
|
ext2fs_free_mem(&inode);
|
2012-08-03 08:47:44 +08:00
|
|
|
ext2fs_free_mem(&ea_buf);
|
2012-07-31 06:50:04 +08:00
|
|
|
ext2fs_close_inode_scan(scan);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rewrite_metadata_checksums(ext2_filsys fs)
|
|
|
|
{
|
2014-01-11 12:04:57 +08:00
|
|
|
errcode_t retval;
|
2013-05-20 09:45:16 +08:00
|
|
|
dgrp_t i;
|
2012-08-03 08:47:45 +08:00
|
|
|
|
2012-07-31 06:50:04 +08:00
|
|
|
fs->flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS;
|
|
|
|
ext2fs_init_csum_seed(fs);
|
2012-08-03 08:47:45 +08:00
|
|
|
for (i = 0; i < fs->group_desc_count; i++)
|
|
|
|
ext2fs_group_desc_csum_set(fs, i);
|
2014-01-11 12:04:57 +08:00
|
|
|
retval = ext2fs_read_bitmaps(fs);
|
|
|
|
if (retval) {
|
|
|
|
com_err("rewrite_metadata_checksums", retval,
|
|
|
|
"while reading bitmaps");
|
|
|
|
exit(1);
|
|
|
|
}
|
2013-09-16 21:41:15 +08:00
|
|
|
rewrite_inodes(fs);
|
2012-07-31 06:58:04 +08:00
|
|
|
ext2fs_mark_ib_dirty(fs);
|
2012-07-31 07:12:04 +08:00
|
|
|
ext2fs_mark_bb_dirty(fs);
|
2012-08-03 08:47:45 +08:00
|
|
|
ext2fs_mmp_update2(fs, 1);
|
2012-07-31 06:58:04 +08:00
|
|
|
fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
|
2012-07-31 06:50:04 +08:00
|
|
|
fs->flags &= ~EXT2_FLAG_IGNORE_CSUM_ERRORS;
|
2015-10-24 13:23:01 +08:00
|
|
|
if (ext2fs_has_feature_metadata_csum(fs->super))
|
2012-08-03 08:47:44 +08:00
|
|
|
fs->super->s_checksum_type = EXT2_CRC32C_CHKSUM;
|
|
|
|
else
|
|
|
|
fs->super->s_checksum_type = 0;
|
|
|
|
ext2fs_mark_super_dirty(fs);
|
2012-07-31 06:50:04 +08:00
|
|
|
}
|
|
|
|
|
2012-08-03 08:47:45 +08:00
|
|
|
static void enable_uninit_bg(ext2_filsys fs)
|
|
|
|
{
|
|
|
|
struct ext2_group_desc *gd;
|
2013-05-20 09:45:16 +08:00
|
|
|
dgrp_t i;
|
2012-08-03 08:47:45 +08:00
|
|
|
|
|
|
|
for (i = 0; i < fs->group_desc_count; i++) {
|
|
|
|
gd = ext2fs_group_desc(fs, fs->group_desc, i);
|
|
|
|
gd->bg_itable_unused = 0;
|
|
|
|
gd->bg_flags = EXT2_BG_INODE_ZEROED;
|
|
|
|
ext2fs_group_desc_csum_set(fs, i);
|
|
|
|
}
|
|
|
|
fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
|
|
|
|
}
|
|
|
|
|
2013-09-16 21:41:15 +08:00
|
|
|
static errcode_t zero_empty_inodes(ext2_filsys fs)
|
|
|
|
{
|
|
|
|
int length = EXT2_INODE_SIZE(fs->super);
|
2014-08-25 00:16:23 +08:00
|
|
|
struct ext2_inode *inode = NULL;
|
2013-09-16 21:41:15 +08:00
|
|
|
ext2_inode_scan scan;
|
|
|
|
errcode_t retval;
|
|
|
|
ext2_ino_t ino;
|
|
|
|
|
|
|
|
retval = ext2fs_open_inode_scan(fs, 0, &scan);
|
|
|
|
if (retval)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
retval = ext2fs_get_mem(length, &inode);
|
|
|
|
if (retval)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
do {
|
|
|
|
retval = ext2fs_get_next_inode_full(scan, &ino, inode, length);
|
|
|
|
if (retval)
|
|
|
|
goto out;
|
|
|
|
if (!ino)
|
|
|
|
break;
|
|
|
|
if (!ext2fs_test_inode_bitmap2(fs->inode_map, ino)) {
|
|
|
|
memset(inode, 0, length);
|
|
|
|
retval = ext2fs_write_inode_full(fs, ino, inode,
|
|
|
|
length);
|
|
|
|
if (retval)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} while (1);
|
|
|
|
|
|
|
|
out:
|
|
|
|
ext2fs_free_mem(&inode);
|
|
|
|
ext2fs_close_inode_scan(scan);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2014-09-12 03:43:33 +08:00
|
|
|
static errcode_t disable_uninit_bg(ext2_filsys fs, __u32 csum_feature_flag)
|
2012-08-03 08:47:45 +08:00
|
|
|
{
|
|
|
|
struct ext2_group_desc *gd;
|
2013-05-20 09:45:16 +08:00
|
|
|
dgrp_t i;
|
2013-09-16 21:41:15 +08:00
|
|
|
errcode_t retval;
|
|
|
|
blk64_t b, c, d;
|
2012-08-03 08:47:45 +08:00
|
|
|
|
|
|
|
/* Load bitmaps to ensure that the uninit ones get written out */
|
|
|
|
fs->super->s_feature_ro_compat |= csum_feature_flag;
|
2014-01-11 12:04:57 +08:00
|
|
|
retval = ext2fs_read_bitmaps(fs);
|
2014-09-12 03:43:33 +08:00
|
|
|
fs->super->s_feature_ro_compat &= ~csum_feature_flag;
|
2014-01-11 12:04:57 +08:00
|
|
|
if (retval) {
|
|
|
|
com_err("disable_uninit_bg", retval,
|
|
|
|
"while reading bitmaps");
|
2014-09-12 03:43:33 +08:00
|
|
|
request_fsck_afterwards(fs);
|
|
|
|
return retval;
|
2014-01-11 12:04:57 +08:00
|
|
|
}
|
2012-08-03 08:47:45 +08:00
|
|
|
ext2fs_mark_ib_dirty(fs);
|
|
|
|
ext2fs_mark_bb_dirty(fs);
|
|
|
|
|
2013-09-16 21:41:15 +08:00
|
|
|
/* If we're only turning off uninit_bg, zero the inodes */
|
|
|
|
if (csum_feature_flag == EXT4_FEATURE_RO_COMPAT_GDT_CSUM) {
|
|
|
|
retval = zero_empty_inodes(fs);
|
|
|
|
if (retval) {
|
|
|
|
com_err("disable_uninit_bg", retval,
|
|
|
|
"while zeroing unused inodes");
|
|
|
|
request_fsck_afterwards(fs);
|
2014-09-12 03:43:33 +08:00
|
|
|
return retval;
|
2013-09-16 21:41:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The bbitmap is zeroed; we must mark group metadata blocks in use */
|
2012-08-03 08:47:45 +08:00
|
|
|
for (i = 0; i < fs->group_desc_count; i++) {
|
2013-09-16 21:41:15 +08:00
|
|
|
b = ext2fs_block_bitmap_loc(fs, i);
|
2013-10-13 10:31:20 +08:00
|
|
|
ext2fs_mark_block_bitmap2(fs->block_map, b);
|
2013-09-16 21:41:15 +08:00
|
|
|
b = ext2fs_inode_bitmap_loc(fs, i);
|
2013-10-13 10:31:20 +08:00
|
|
|
ext2fs_mark_block_bitmap2(fs->block_map, b);
|
2013-09-16 21:41:15 +08:00
|
|
|
|
|
|
|
retval = ext2fs_super_and_bgd_loc2(fs, i, &b, &c, &d, NULL);
|
|
|
|
if (retval == 0 && b)
|
2013-10-13 10:31:20 +08:00
|
|
|
ext2fs_mark_block_bitmap2(fs->block_map, b);
|
2013-09-16 21:41:15 +08:00
|
|
|
if (retval == 0 && c)
|
2013-10-13 10:31:20 +08:00
|
|
|
ext2fs_mark_block_bitmap2(fs->block_map, c);
|
2013-09-16 21:41:15 +08:00
|
|
|
if (retval == 0 && d)
|
2013-10-13 10:31:20 +08:00
|
|
|
ext2fs_mark_block_bitmap2(fs->block_map, d);
|
2013-09-16 21:41:15 +08:00
|
|
|
if (retval) {
|
|
|
|
com_err("disable_uninit_bg", retval,
|
|
|
|
"while initializing block bitmaps");
|
2012-08-03 08:47:45 +08:00
|
|
|
request_fsck_afterwards(fs);
|
|
|
|
}
|
2013-09-16 21:41:15 +08:00
|
|
|
|
|
|
|
gd = ext2fs_group_desc(fs, fs->group_desc, i);
|
2012-08-03 08:47:45 +08:00
|
|
|
gd->bg_itable_unused = 0;
|
|
|
|
gd->bg_flags = 0;
|
|
|
|
ext2fs_group_desc_csum_set(fs, i);
|
|
|
|
}
|
|
|
|
fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
|
2013-09-16 21:41:15 +08:00
|
|
|
ext2fs_mark_super_dirty(fs);
|
2014-09-12 03:43:33 +08:00
|
|
|
|
|
|
|
return 0;
|
2012-08-03 08:47:45 +08:00
|
|
|
}
|
|
|
|
|
2016-03-06 01:38:52 +08:00
|
|
|
static void
|
|
|
|
try_confirm_csum_seed_support(void)
|
|
|
|
{
|
|
|
|
if (access("/sys/fs/ext4/features/metadata_csum_seed", R_OK))
|
|
|
|
fputs(_("WARNING: Could not confirm kernel support for "
|
|
|
|
"metadata_csum_seed.\n This requires Linux >= "
|
|
|
|
"v4.4.\n"), stderr);
|
|
|
|
}
|
|
|
|
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
/*
|
|
|
|
* Update the feature set as provided by the user.
|
|
|
|
*/
|
2011-09-25 01:48:55 +08:00
|
|
|
static int update_feature_set(ext2_filsys fs, char *features)
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
{
|
2009-01-20 15:34:39 +08:00
|
|
|
struct ext2_super_block *sb = fs->super;
|
2008-02-27 04:08:14 +08:00
|
|
|
__u32 old_features[3];
|
2013-01-23 07:32:29 +08:00
|
|
|
int type_err;
|
2008-02-27 03:27:57 +08:00
|
|
|
unsigned int mask_err;
|
2014-09-12 03:43:33 +08:00
|
|
|
errcode_t err;
|
2016-01-12 16:56:44 +08:00
|
|
|
enum quota_type qtype;
|
2004-04-07 21:27:36 +08:00
|
|
|
|
2008-02-27 04:08:14 +08:00
|
|
|
#define FEATURE_ON(type, mask) (!(old_features[(type)] & (mask)) && \
|
|
|
|
((&sb->s_feature_compat)[(type)] & (mask)))
|
|
|
|
#define FEATURE_OFF(type, mask) ((old_features[(type)] & (mask)) && \
|
|
|
|
!((&sb->s_feature_compat)[(type)] & (mask)))
|
|
|
|
#define FEATURE_CHANGED(type, mask) ((mask) & \
|
|
|
|
(old_features[(type)] ^ (&sb->s_feature_compat)[(type)]))
|
|
|
|
|
|
|
|
old_features[E2P_FEATURE_COMPAT] = sb->s_feature_compat;
|
|
|
|
old_features[E2P_FEATURE_INCOMPAT] = sb->s_feature_incompat;
|
|
|
|
old_features[E2P_FEATURE_RO_INCOMPAT] = sb->s_feature_ro_compat;
|
|
|
|
|
2008-02-27 03:27:57 +08:00
|
|
|
if (e2p_edit_feature2(features, &sb->s_feature_compat,
|
|
|
|
ok_features, clear_ok_features,
|
|
|
|
&type_err, &mask_err)) {
|
|
|
|
if (!mask_err)
|
|
|
|
fprintf(stderr,
|
|
|
|
_("Invalid filesystem option set: %s\n"),
|
|
|
|
features);
|
|
|
|
else if (type_err & E2P_FEATURE_NEGATE_FLAG)
|
|
|
|
fprintf(stderr, _("Clearing filesystem feature '%s' "
|
|
|
|
"not supported.\n"),
|
|
|
|
e2p_feature2string(type_err &
|
|
|
|
E2P_FEATURE_TYPE_MASK,
|
|
|
|
mask_err));
|
|
|
|
else
|
|
|
|
fprintf(stderr, _("Setting filesystem feature '%s' "
|
|
|
|
"not supported.\n"),
|
|
|
|
e2p_feature2string(type_err, mask_err));
|
2011-09-25 01:48:55 +08:00
|
|
|
return 1;
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
}
|
2008-02-27 04:08:14 +08:00
|
|
|
|
|
|
|
if (FEATURE_OFF(E2P_FEATURE_COMPAT, EXT3_FEATURE_COMPAT_HAS_JOURNAL)) {
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
if ((mount_flags & EXT2_MF_MOUNTED) &&
|
|
|
|
!(mount_flags & EXT2_MF_READONLY)) {
|
2008-07-10 22:49:59 +08:00
|
|
|
fputs(_("The has_journal feature may only be "
|
2003-12-07 14:28:50 +08:00
|
|
|
"cleared when the filesystem is\n"
|
|
|
|
"unmounted or mounted "
|
|
|
|
"read-only.\n"), stderr);
|
2011-09-25 01:48:55 +08:00
|
|
|
return 1;
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
}
|
2015-10-24 13:23:01 +08:00
|
|
|
if (ext2fs_has_feature_journal_needs_recovery(sb) &&
|
2014-02-21 09:18:41 +08:00
|
|
|
f_flag < 2) {
|
2003-12-07 14:28:50 +08:00
|
|
|
fputs(_("The needs_recovery flag is set. "
|
|
|
|
"Please run e2fsck before clearing\n"
|
|
|
|
"the has_journal flag.\n"), stderr);
|
2011-09-25 01:48:55 +08:00
|
|
|
return 1;
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
}
|
|
|
|
if (sb->s_journal_inum) {
|
2011-09-25 01:48:55 +08:00
|
|
|
if (remove_journal_inode(fs))
|
|
|
|
return 1;
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
}
|
2001-07-31 04:31:30 +08:00
|
|
|
if (sb->s_journal_dev) {
|
2011-09-25 01:48:55 +08:00
|
|
|
if (remove_journal_device(fs))
|
|
|
|
return 1;
|
2001-07-31 04:31:30 +08:00
|
|
|
}
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
}
|
2014-02-07 04:11:52 +08:00
|
|
|
|
|
|
|
if (FEATURE_ON(E2P_FEATURE_RO_INCOMPAT,
|
|
|
|
EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)) {
|
2015-10-24 13:23:01 +08:00
|
|
|
if (ext2fs_has_feature_meta_bg(sb)) {
|
2014-02-07 04:11:52 +08:00
|
|
|
fputs(_("Setting filesystem feature 'sparse_super' "
|
|
|
|
"not supported\nfor filesystems with "
|
|
|
|
"the meta_bg feature enabled.\n"),
|
|
|
|
stderr);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-25 01:48:55 +08:00
|
|
|
if (FEATURE_ON(E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_MMP)) {
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if ((mount_flags & EXT2_MF_MOUNTED) ||
|
|
|
|
(mount_flags & EXT2_MF_READONLY)) {
|
|
|
|
fputs(_("The multiple mount protection feature can't\n"
|
|
|
|
"be set if the filesystem is mounted or\n"
|
|
|
|
"read-only.\n"), stderr);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = ext2fs_mmp_init(fs);
|
|
|
|
if (error) {
|
|
|
|
fputs(_("\nError while enabling multiple mount "
|
|
|
|
"protection feature."), stderr);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We want to update group desc with the new free blocks count
|
|
|
|
*/
|
|
|
|
fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
|
|
|
|
|
|
|
|
printf(_("Multiple mount protection has been enabled "
|
|
|
|
"with update interval %ds.\n"),
|
|
|
|
sb->s_mmp_update_interval);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FEATURE_OFF(E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_MMP)) {
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (mount_flags & EXT2_MF_READONLY) {
|
|
|
|
fputs(_("The multiple mount protection feature cannot\n"
|
|
|
|
"be disabled if the filesystem is readonly.\n"),
|
|
|
|
stderr);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = ext2fs_read_bitmaps(fs);
|
|
|
|
if (error) {
|
|
|
|
fputs(_("Error while reading bitmaps\n"), stderr);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = ext2fs_mmp_read(fs, sb->s_mmp_block, NULL);
|
|
|
|
if (error) {
|
|
|
|
struct mmp_struct *mmp_cmp = fs->mmp_cmp;
|
|
|
|
|
|
|
|
if (error == EXT2_ET_MMP_MAGIC_INVALID)
|
|
|
|
printf(_("Magic number in MMP block does not "
|
|
|
|
"match. expected: %x, actual: %x\n"),
|
|
|
|
EXT4_MMP_MAGIC, mmp_cmp->mmp_magic);
|
|
|
|
else
|
2013-12-16 11:11:40 +08:00
|
|
|
com_err(program_name, error, "%s",
|
2011-09-25 01:48:55 +08:00
|
|
|
_("while reading MMP block."));
|
|
|
|
goto mmp_error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We need to force out the group descriptors as well */
|
|
|
|
fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
|
2013-10-07 21:51:48 +08:00
|
|
|
ext2fs_block_alloc_stats2(fs, sb->s_mmp_block, -1);
|
2011-09-25 01:48:55 +08:00
|
|
|
mmp_error:
|
|
|
|
sb->s_mmp_block = 0;
|
|
|
|
sb->s_mmp_update_interval = 0;
|
|
|
|
}
|
2008-02-27 04:08:14 +08:00
|
|
|
|
|
|
|
if (FEATURE_ON(E2P_FEATURE_COMPAT, EXT3_FEATURE_COMPAT_HAS_JOURNAL)) {
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
/*
|
|
|
|
* If adding a journal flag, let the create journal
|
2008-07-18 05:58:35 +08:00
|
|
|
* code below handle setting the flag and creating the
|
|
|
|
* journal. We supply a default size if necessary.
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
*/
|
ChangeLog, mke2fs.8.in, mke2fs.c, tune2fs.8.in, tune2fs.c:
tune2fs.c, mke2fs.c, tune2fs.8.in, mke2fs.8.in: Change user interface
so that -J is used to specify journal options, and -j is used to
request creation of a journal using default values. (This is a UI
change, but we haven't done a formal release, and it makes things much
more consistent with the rest of the options out there.)
tune2fs.c: Add support for removing a filesystem from an external
journal; we correctly remove the filesystem UUID from the external
journal's filesystem list.
2001-01-18 09:51:15 +08:00
|
|
|
if (!journal_size)
|
|
|
|
journal_size = -1;
|
2015-10-24 13:23:01 +08:00
|
|
|
ext2fs_clear_feature_journal(sb);
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
}
|
2008-02-27 04:08:14 +08:00
|
|
|
|
|
|
|
if (FEATURE_ON(E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_DIR_INDEX)) {
|
2002-09-23 03:37:40 +08:00
|
|
|
if (!sb->s_def_hash_version)
|
2008-08-29 11:09:35 +08:00
|
|
|
sb->s_def_hash_version = EXT2_HASH_HALF_MD4;
|
2002-09-23 03:37:40 +08:00
|
|
|
if (uuid_is_null((unsigned char *) sb->s_hash_seed))
|
|
|
|
uuid_generate((unsigned char *) sb->s_hash_seed);
|
|
|
|
}
|
ChangeLog, mke2fs.8.in, mke2fs.c, tune2fs.8.in, tune2fs.c:
tune2fs.c, mke2fs.c, tune2fs.8.in, mke2fs.8.in: Change user interface
so that -J is used to specify journal options, and -j is used to
request creation of a journal using default values. (This is a UI
change, but we haven't done a formal release, and it makes things much
more consistent with the rest of the options out there.)
tune2fs.c: Add support for removing a filesystem from an external
journal; we correctly remove the filesystem UUID from the external
journal's filesystem list.
2001-01-18 09:51:15 +08:00
|
|
|
|
2008-02-28 07:53:34 +08:00
|
|
|
if (FEATURE_OFF(E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_FLEX_BG)) {
|
2007-08-14 12:32:57 +08:00
|
|
|
if (ext2fs_check_desc(fs)) {
|
|
|
|
fputs(_("Clearing the flex_bg flag would "
|
|
|
|
"cause the the filesystem to be\n"
|
|
|
|
"inconsistent.\n"), stderr);
|
2011-09-25 01:48:55 +08:00
|
|
|
return 1;
|
2007-08-14 12:32:57 +08:00
|
|
|
}
|
|
|
|
}
|
ChangeLog, mke2fs.8.in, mke2fs.c, tune2fs.8.in, tune2fs.c:
tune2fs.c, mke2fs.c, tune2fs.8.in, mke2fs.8.in: Change user interface
so that -J is used to specify journal options, and -j is used to
request creation of a journal using default values. (This is a UI
change, but we haven't done a formal release, and it makes things much
more consistent with the rest of the options out there.)
tune2fs.c: Add support for removing a filesystem from an external
journal; we correctly remove the filesystem UUID from the external
journal's filesystem list.
2001-01-18 09:51:15 +08:00
|
|
|
|
2008-07-10 22:49:59 +08:00
|
|
|
if (FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT,
|
|
|
|
EXT4_FEATURE_RO_COMPAT_HUGE_FILE)) {
|
|
|
|
if ((mount_flags & EXT2_MF_MOUNTED) &&
|
|
|
|
!(mount_flags & EXT2_MF_READONLY)) {
|
|
|
|
fputs(_("The huge_file feature may only be "
|
|
|
|
"cleared when the filesystem is\n"
|
|
|
|
"unmounted or mounted "
|
|
|
|
"read-only.\n"), stderr);
|
2011-09-25 01:48:55 +08:00
|
|
|
return 1;
|
2008-07-10 22:49:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-31 06:50:04 +08:00
|
|
|
if (FEATURE_ON(E2P_FEATURE_RO_INCOMPAT,
|
|
|
|
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
|
2016-02-14 06:38:11 +08:00
|
|
|
check_fsck_needed(fs,
|
|
|
|
_("Enabling checksums could take some time."));
|
2015-01-28 02:11:25 +08:00
|
|
|
if (mount_flags & EXT2_MF_MOUNTED) {
|
2014-11-05 00:52:26 +08:00
|
|
|
fputs(_("Cannot enable metadata_csum on a mounted "
|
|
|
|
"filesystem!\n"), stderr);
|
2015-01-28 02:11:25 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
2015-10-24 13:23:01 +08:00
|
|
|
if (!ext2fs_has_feature_extents(fs->super))
|
2014-12-14 10:57:20 +08:00
|
|
|
printf("%s",
|
|
|
|
_("Extents are not enabled. The file extent "
|
|
|
|
"tree can be checksummed, whereas block maps "
|
|
|
|
"cannot. Not enabling extents reduces the "
|
|
|
|
"coverage of metadata checksumming. "
|
|
|
|
"Re-run with -O extent to rectify.\n"));
|
2015-10-24 13:23:01 +08:00
|
|
|
if (!ext2fs_has_feature_64bit(fs->super))
|
2014-12-16 01:40:03 +08:00
|
|
|
printf("%s",
|
|
|
|
_("64-bit filesystem support is not enabled. "
|
|
|
|
"The larger fields afforded by this feature "
|
|
|
|
"enable full-strength checksumming. "
|
|
|
|
"Run resize2fs -b to rectify.\n"));
|
2012-07-31 06:50:04 +08:00
|
|
|
rewrite_checksums = 1;
|
2012-08-03 08:47:45 +08:00
|
|
|
/* metadata_csum supersedes uninit_bg */
|
2015-10-24 13:23:01 +08:00
|
|
|
ext2fs_clear_feature_gdt_csum(fs->super);
|
2012-08-03 08:47:45 +08:00
|
|
|
|
|
|
|
/* if uninit_bg was previously off, rewrite group desc */
|
|
|
|
if (!(old_features[E2P_FEATURE_RO_INCOMPAT] &
|
|
|
|
EXT4_FEATURE_RO_COMPAT_GDT_CSUM))
|
|
|
|
enable_uninit_bg(fs);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Since metadata_csum supersedes uninit_bg, pretend like
|
|
|
|
* uninit_bg has been off all along.
|
|
|
|
*/
|
|
|
|
old_features[E2P_FEATURE_RO_INCOMPAT] &=
|
|
|
|
~EXT4_FEATURE_RO_COMPAT_GDT_CSUM;
|
2012-07-31 06:50:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT,
|
|
|
|
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
|
2014-12-14 10:58:26 +08:00
|
|
|
__u32 test_features[3];
|
|
|
|
|
2016-02-14 06:38:11 +08:00
|
|
|
check_fsck_needed(fs,
|
|
|
|
_("Disabling checksums could take some time."));
|
2015-01-28 02:11:25 +08:00
|
|
|
if (mount_flags & EXT2_MF_MOUNTED) {
|
2014-11-05 00:52:26 +08:00
|
|
|
fputs(_("Cannot disable metadata_csum on a mounted "
|
|
|
|
"filesystem!\n"), stderr);
|
2015-01-28 02:11:25 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
2012-07-31 06:50:04 +08:00
|
|
|
rewrite_checksums = 1;
|
2014-12-14 10:58:26 +08:00
|
|
|
|
|
|
|
/* Enable uninit_bg unless the user expressly turned it off */
|
|
|
|
memcpy(test_features, old_features, sizeof(test_features));
|
|
|
|
test_features[E2P_FEATURE_RO_INCOMPAT] |=
|
|
|
|
EXT4_FEATURE_RO_COMPAT_GDT_CSUM;
|
|
|
|
e2p_edit_feature2(features, test_features, ok_features,
|
|
|
|
clear_ok_features, NULL, NULL);
|
|
|
|
if (test_features[E2P_FEATURE_RO_INCOMPAT] &
|
|
|
|
EXT4_FEATURE_RO_COMPAT_GDT_CSUM)
|
2015-10-24 13:23:01 +08:00
|
|
|
ext2fs_set_feature_gdt_csum(fs->super);
|
2014-12-14 10:58:26 +08:00
|
|
|
|
2012-08-03 08:47:45 +08:00
|
|
|
/*
|
|
|
|
* If we're turning off metadata_csum and not turning on
|
|
|
|
* uninit_bg, rewrite group desc.
|
|
|
|
*/
|
2015-10-24 13:23:01 +08:00
|
|
|
if (!ext2fs_has_feature_gdt_csum(fs->super)) {
|
2014-09-12 03:43:33 +08:00
|
|
|
err = disable_uninit_bg(fs,
|
|
|
|
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM);
|
|
|
|
if (err)
|
|
|
|
return 1;
|
|
|
|
} else
|
2012-08-03 08:47:45 +08:00
|
|
|
/*
|
|
|
|
* metadata_csum previously provided uninit_bg, so if
|
|
|
|
* we're also setting the uninit_bg feature bit,
|
|
|
|
* pretend like it was previously enabled. Checksums
|
|
|
|
* will be rewritten with crc16 later.
|
|
|
|
*/
|
|
|
|
old_features[E2P_FEATURE_RO_INCOMPAT] |=
|
|
|
|
EXT4_FEATURE_RO_COMPAT_GDT_CSUM;
|
2016-03-06 01:38:52 +08:00
|
|
|
fs->super->s_checksum_seed = 0;
|
|
|
|
ext2fs_clear_feature_csum_seed(fs->super);
|
2012-07-31 06:50:04 +08:00
|
|
|
}
|
|
|
|
|
2010-05-20 00:14:39 +08:00
|
|
|
if (FEATURE_ON(E2P_FEATURE_RO_INCOMPAT,
|
|
|
|
EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
|
2012-08-03 08:47:45 +08:00
|
|
|
/* Do not enable uninit_bg when metadata_csum enabled */
|
2015-10-24 13:23:01 +08:00
|
|
|
if (ext2fs_has_feature_metadata_csum(fs->super))
|
|
|
|
ext2fs_clear_feature_gdt_csum(fs->super);
|
2012-08-03 08:47:45 +08:00
|
|
|
else
|
|
|
|
enable_uninit_bg(fs);
|
2010-05-20 00:14:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT,
|
2014-09-12 03:43:33 +08:00
|
|
|
EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
|
|
|
|
err = disable_uninit_bg(fs,
|
2012-08-03 08:47:45 +08:00
|
|
|
EXT4_FEATURE_RO_COMPAT_GDT_CSUM);
|
2014-09-12 03:43:33 +08:00
|
|
|
if (err)
|
|
|
|
return 1;
|
|
|
|
}
|
2010-05-20 00:14:39 +08:00
|
|
|
|
2015-01-28 02:11:47 +08:00
|
|
|
/*
|
|
|
|
* We don't actually toggle 64bit; resize2fs does that. But this
|
|
|
|
* must come after the metadata_csum feature_on so that it won't
|
|
|
|
* complain about the lack of 64bit.
|
|
|
|
*/
|
|
|
|
if (FEATURE_ON(E2P_FEATURE_INCOMPAT,
|
|
|
|
EXT4_FEATURE_INCOMPAT_64BIT)) {
|
|
|
|
if (mount_flags & EXT2_MF_MOUNTED) {
|
|
|
|
fprintf(stderr, _("Cannot enable 64-bit mode "
|
|
|
|
"while mounted!\n"));
|
|
|
|
exit(1);
|
|
|
|
}
|
2015-10-24 13:23:01 +08:00
|
|
|
ext2fs_clear_feature_64bit(sb);
|
2015-01-28 02:11:47 +08:00
|
|
|
feature_64bit = 1;
|
|
|
|
}
|
|
|
|
if (FEATURE_OFF(E2P_FEATURE_INCOMPAT,
|
|
|
|
EXT4_FEATURE_INCOMPAT_64BIT)) {
|
|
|
|
if (mount_flags & EXT2_MF_MOUNTED) {
|
|
|
|
fprintf(stderr, _("Cannot disable 64-bit mode "
|
|
|
|
"while mounted!\n"));
|
|
|
|
exit(1);
|
|
|
|
}
|
2015-10-24 13:23:01 +08:00
|
|
|
ext2fs_set_feature_64bit(sb);
|
2015-01-28 02:11:47 +08:00
|
|
|
feature_64bit = -1;
|
|
|
|
}
|
|
|
|
|
2011-07-21 02:40:05 +08:00
|
|
|
if (FEATURE_ON(E2P_FEATURE_RO_INCOMPAT,
|
|
|
|
EXT4_FEATURE_RO_COMPAT_QUOTA)) {
|
|
|
|
/*
|
|
|
|
* Set the Q_flag here and handle the quota options in the code
|
|
|
|
* below.
|
|
|
|
*/
|
|
|
|
if (!Q_flag) {
|
|
|
|
Q_flag = 1;
|
2016-03-01 11:57:05 +08:00
|
|
|
/* Enable usr/grp quota by default */
|
|
|
|
for (qtype = 0; qtype < MAXQUOTAS; qtype++) {
|
|
|
|
if (qtype != PRJQUOTA)
|
|
|
|
quota_enable[qtype] = QOPT_ENABLE;
|
|
|
|
else
|
|
|
|
quota_enable[qtype] = QOPT_DISABLE;
|
|
|
|
}
|
2011-07-21 02:40:05 +08:00
|
|
|
}
|
2015-10-24 13:23:01 +08:00
|
|
|
ext2fs_clear_feature_quota(sb);
|
2011-07-21 02:40:05 +08:00
|
|
|
}
|
|
|
|
|
2016-03-01 11:57:05 +08:00
|
|
|
if (FEATURE_ON(E2P_FEATURE_RO_INCOMPAT,
|
|
|
|
EXT4_FEATURE_RO_COMPAT_PROJECT)) {
|
|
|
|
if (!Q_flag && !ext2fs_has_feature_quota(sb))
|
|
|
|
fputs(_("\nWarning: enabled project without quota together\n"),
|
|
|
|
stderr);
|
|
|
|
Q_flag = 1;
|
|
|
|
quota_enable[PRJQUOTA] = QOPT_ENABLE;
|
|
|
|
}
|
|
|
|
|
2011-07-21 02:40:05 +08:00
|
|
|
if (FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT,
|
|
|
|
EXT4_FEATURE_RO_COMPAT_QUOTA)) {
|
|
|
|
/*
|
|
|
|
* Set the Q_flag here and handle the quota options in the code
|
|
|
|
* below.
|
|
|
|
*/
|
|
|
|
if (Q_flag)
|
|
|
|
fputs(_("\nWarning: '^quota' option overrides '-Q'"
|
|
|
|
"arguments.\n"), stderr);
|
|
|
|
Q_flag = 1;
|
2016-01-12 16:56:44 +08:00
|
|
|
/* Disable all quota by default */
|
|
|
|
for (qtype = 0; qtype < MAXQUOTAS; qtype++)
|
|
|
|
quota_enable[qtype] = QOPT_DISABLE;
|
2011-07-21 02:40:05 +08:00
|
|
|
}
|
|
|
|
|
2015-04-06 08:42:58 +08:00
|
|
|
if (FEATURE_ON(E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_ENCRYPT)) {
|
|
|
|
fs->super->s_encrypt_algos[0] =
|
|
|
|
EXT4_ENCRYPTION_MODE_AES_256_XTS;
|
|
|
|
fs->super->s_encrypt_algos[1] =
|
|
|
|
EXT4_ENCRYPTION_MODE_AES_256_CTS;
|
|
|
|
}
|
|
|
|
|
2016-03-06 01:38:52 +08:00
|
|
|
if (FEATURE_ON(E2P_FEATURE_INCOMPAT,
|
|
|
|
EXT4_FEATURE_INCOMPAT_CSUM_SEED)) {
|
|
|
|
if (!ext2fs_has_feature_metadata_csum(sb)) {
|
|
|
|
fputs(_("Setting feature 'metadata_csum_seed' "
|
|
|
|
"is only supported\non filesystems with "
|
|
|
|
"the metadata_csum feature enabled.\n"),
|
|
|
|
stderr);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
try_confirm_csum_seed_support();
|
|
|
|
fs->super->s_checksum_seed = fs->csum_seed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FEATURE_OFF(E2P_FEATURE_INCOMPAT,
|
|
|
|
EXT4_FEATURE_INCOMPAT_CSUM_SEED)) {
|
|
|
|
__le32 uuid_seed;
|
|
|
|
|
|
|
|
uuid_seed = ext2fs_crc32c_le(~0, fs->super->s_uuid,
|
|
|
|
sizeof(fs->super->s_uuid));
|
|
|
|
if (fs->super->s_checksum_seed != uuid_seed &&
|
|
|
|
(mount_flags & EXT2_MF_MOUNTED)) {
|
|
|
|
fputs(_("UUID has changed since enabling "
|
|
|
|
"metadata_csum. Filesystem must be unmounted "
|
|
|
|
"\nto safely rewrite all metadata to "
|
|
|
|
"match the new UUID.\n"), stderr);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rewrite_checksums = 1;
|
|
|
|
}
|
|
|
|
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
if (sb->s_rev_level == EXT2_GOOD_OLD_REV &&
|
|
|
|
(sb->s_feature_compat || sb->s_feature_ro_compat ||
|
|
|
|
sb->s_feature_incompat))
|
|
|
|
ext2fs_update_dynamic_rev(fs);
|
2008-02-27 04:08:14 +08:00
|
|
|
|
|
|
|
if (FEATURE_CHANGED(E2P_FEATURE_RO_INCOMPAT,
|
|
|
|
EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER) ||
|
2008-07-10 22:49:59 +08:00
|
|
|
FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT,
|
|
|
|
EXT4_FEATURE_RO_COMPAT_HUGE_FILE) ||
|
2008-02-27 04:08:14 +08:00
|
|
|
FEATURE_CHANGED(E2P_FEATURE_INCOMPAT,
|
2008-02-27 06:31:06 +08:00
|
|
|
EXT2_FEATURE_INCOMPAT_FILETYPE) ||
|
|
|
|
FEATURE_CHANGED(E2P_FEATURE_COMPAT,
|
2008-02-28 04:01:19 +08:00
|
|
|
EXT2_FEATURE_COMPAT_RESIZE_INODE) ||
|
|
|
|
FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT,
|
2010-05-20 00:14:39 +08:00
|
|
|
EXT2_FEATURE_RO_COMPAT_LARGE_FILE))
|
|
|
|
request_fsck_afterwards(fs);
|
2008-02-27 04:08:14 +08:00
|
|
|
|
|
|
|
if ((old_features[E2P_FEATURE_COMPAT] != sb->s_feature_compat) ||
|
|
|
|
(old_features[E2P_FEATURE_INCOMPAT] != sb->s_feature_incompat) ||
|
|
|
|
(old_features[E2P_FEATURE_RO_INCOMPAT] != sb->s_feature_ro_compat))
|
2004-04-07 21:27:36 +08:00
|
|
|
ext2fs_mark_super_dirty(fs);
|
2011-09-25 01:48:55 +08:00
|
|
|
|
|
|
|
return 0;
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a journal to the filesystem.
|
|
|
|
*/
|
2011-09-25 01:48:55 +08:00
|
|
|
static int add_journal(ext2_filsys fs)
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
{
|
|
|
|
unsigned long journal_blocks;
|
|
|
|
errcode_t retval;
|
2001-01-16 15:47:31 +08:00
|
|
|
ext2_filsys jfs;
|
2003-05-06 00:08:47 +08:00
|
|
|
io_manager io_ptr;
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
|
2015-10-24 13:23:01 +08:00
|
|
|
if (ext2fs_has_feature_journal(fs->super)) {
|
2003-12-07 14:28:50 +08:00
|
|
|
fputs(_("The filesystem already has a journal.\n"), stderr);
|
2001-08-17 17:48:11 +08:00
|
|
|
goto err;
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
}
|
|
|
|
if (journal_device) {
|
2014-04-27 01:14:32 +08:00
|
|
|
if (!check_plausibility(journal_device, CHECK_BLOCK_DEV,
|
|
|
|
NULL))
|
2014-04-27 05:34:52 +08:00
|
|
|
proceed_question(-1);
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
check_mount(journal_device, 0, _("journal"));
|
2003-05-06 00:08:47 +08:00
|
|
|
#ifdef CONFIG_TESTIO_DEBUG
|
2008-09-01 23:17:29 +08:00
|
|
|
if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) {
|
|
|
|
io_ptr = test_io_manager;
|
|
|
|
test_io_backing_manager = unix_io_manager;
|
|
|
|
} else
|
2003-05-06 00:08:47 +08:00
|
|
|
#endif
|
2008-09-01 23:17:29 +08:00
|
|
|
io_ptr = unix_io_manager;
|
2001-01-16 15:47:31 +08:00
|
|
|
retval = ext2fs_open(journal_device, EXT2_FLAG_RW|
|
|
|
|
EXT2_FLAG_JOURNAL_DEV_OK, 0,
|
2003-05-06 00:08:47 +08:00
|
|
|
fs->blocksize, io_ptr, &jfs);
|
2001-01-16 15:47:31 +08:00
|
|
|
if (retval) {
|
|
|
|
com_err(program_name, retval,
|
2001-04-17 09:01:49 +08:00
|
|
|
_("\n\twhile trying to open journal on %s\n"),
|
2001-01-16 15:47:31 +08:00
|
|
|
journal_device);
|
2001-08-17 17:48:11 +08:00
|
|
|
goto err;
|
2001-01-16 15:47:31 +08:00
|
|
|
}
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
printf(_("Creating journal on device %s: "),
|
|
|
|
journal_device);
|
2001-01-15 00:11:14 +08:00
|
|
|
fflush(stdout);
|
2001-08-17 17:48:11 +08:00
|
|
|
|
2001-01-16 15:47:31 +08:00
|
|
|
retval = ext2fs_add_journal_device(fs, jfs);
|
2014-07-06 09:06:29 +08:00
|
|
|
ext2fs_close_free(&jfs);
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
if (retval) {
|
2009-01-20 15:34:39 +08:00
|
|
|
com_err(program_name, retval,
|
|
|
|
_("while adding filesystem to journal on %s"),
|
|
|
|
journal_device);
|
2001-08-17 17:48:11 +08:00
|
|
|
goto err;
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
}
|
2003-12-07 14:28:50 +08:00
|
|
|
fputs(_("done\n"), stdout);
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
} else if (journal_size) {
|
2003-12-07 14:28:50 +08:00
|
|
|
fputs(_("Creating journal inode: "), stdout);
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
fflush(stdout);
|
ChangeLog, mke2fs.8.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
ke2fs.8.in, tune2fs.8.in: Change man paegs to document that the
journal must be bewteen 1024 and 10,240 file system blocks.
mke2fs.c, tune2fs.c: Change to use figure_journal_size()
util.c, util.h (figure_journal_size): Change journal_default_size into
routine which also converts the requested journal size into filesystem
blocks and does bounds checking to make sure the journal is sized
reasonably. Renamed function to journal_default_size.
parse_journal_opts): Remove bounds check for the journal size, since
this is now done in figure_journal_size, and based on the number of
filesystem blocks, as opposed to using the absolute size of the
journal.
2001-03-27 04:07:13 +08:00
|
|
|
journal_blocks = figure_journal_size(journal_size, fs);
|
|
|
|
|
2014-01-29 01:58:56 +08:00
|
|
|
if (journal_location_string)
|
|
|
|
journal_location =
|
|
|
|
parse_num_blocks2(journal_location_string,
|
|
|
|
fs->super->s_log_block_size);
|
|
|
|
retval = ext2fs_add_journal_inode2(fs, journal_blocks,
|
|
|
|
journal_location,
|
|
|
|
journal_flags);
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
if (retval) {
|
2001-08-16 07:17:37 +08:00
|
|
|
fprintf(stderr, "\n");
|
2013-12-16 11:11:40 +08:00
|
|
|
com_err(program_name, retval, "%s",
|
2001-04-17 09:01:49 +08:00
|
|
|
_("\n\twhile trying to create journal file"));
|
2011-09-25 01:48:55 +08:00
|
|
|
return retval;
|
2001-04-17 09:01:49 +08:00
|
|
|
} else
|
2003-12-07 14:28:50 +08:00
|
|
|
fputs(_("done\n"), stdout);
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
/*
|
|
|
|
* If the filesystem wasn't mounted, we need to force
|
|
|
|
* the block group descriptors out.
|
|
|
|
*/
|
|
|
|
if ((mount_flags & EXT2_MF_MOUNTED) == 0)
|
|
|
|
fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
|
|
|
|
}
|
2011-09-14 10:24:11 +08:00
|
|
|
print_check_message(fs->super->s_max_mnt_count,
|
|
|
|
fs->super->s_checkinterval);
|
2011-09-25 01:48:55 +08:00
|
|
|
return 0;
|
2001-08-17 17:48:11 +08:00
|
|
|
|
|
|
|
err:
|
2009-02-24 01:07:50 +08:00
|
|
|
free(journal_device);
|
2011-09-25 01:48:55 +08:00
|
|
|
return 1;
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
}
|
|
|
|
|
2013-05-20 08:03:48 +08:00
|
|
|
static void handle_quota_options(ext2_filsys fs)
|
2011-07-21 02:40:05 +08:00
|
|
|
{
|
2016-05-30 05:36:43 +08:00
|
|
|
errcode_t retval;
|
2011-07-21 02:40:05 +08:00
|
|
|
quota_ctx_t qctx;
|
|
|
|
ext2_ino_t qf_ino;
|
2016-01-12 16:56:44 +08:00
|
|
|
enum quota_type qtype;
|
|
|
|
int enable = 0;
|
2011-07-21 02:40:05 +08:00
|
|
|
|
2016-01-12 16:56:44 +08:00
|
|
|
for (qtype = 0 ; qtype < MAXQUOTAS; qtype++)
|
|
|
|
if (quota_enable[qtype] != 0)
|
|
|
|
break;
|
|
|
|
if (qtype == MAXQUOTAS)
|
2011-07-21 02:40:05 +08:00
|
|
|
/* Nothing to do. */
|
|
|
|
return;
|
|
|
|
|
2016-05-30 05:36:43 +08:00
|
|
|
retval = quota_init_context(&qctx, fs, QUOTA_ALL_BIT);
|
|
|
|
if (retval) {
|
|
|
|
com_err(program_name, retval,
|
|
|
|
_("while initializing quota context in support library"));
|
|
|
|
exit(1);
|
|
|
|
}
|
2016-01-12 16:56:44 +08:00
|
|
|
for (qtype = 0 ; qtype < MAXQUOTAS; qtype++) {
|
|
|
|
if (quota_enable[qtype] == QOPT_ENABLE) {
|
|
|
|
enable = 1;
|
|
|
|
break;
|
|
|
|
}
|
2011-11-14 23:58:28 +08:00
|
|
|
}
|
2016-01-12 16:56:44 +08:00
|
|
|
if (enable)
|
|
|
|
quota_compute_usage(qctx);
|
2011-07-21 02:40:05 +08:00
|
|
|
|
2016-01-12 16:56:44 +08:00
|
|
|
for (qtype = 0 ; qtype < MAXQUOTAS; qtype++) {
|
|
|
|
if (quota_enable[qtype] == QOPT_ENABLE &&
|
|
|
|
*quota_sb_inump(fs->super, qtype) == 0) {
|
2016-05-30 05:36:43 +08:00
|
|
|
if ((qf_ino = quota_file_exists(fs, qtype)) > 0) {
|
|
|
|
retval = quota_update_limits(qctx, qf_ino,
|
|
|
|
qtype);
|
|
|
|
if (retval) {
|
|
|
|
com_err(program_name, retval,
|
|
|
|
_("while updating quota limits (%d)"),
|
|
|
|
qtype);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
retval = quota_write_inode(qctx, 1 << qtype);
|
|
|
|
if (retval) {
|
|
|
|
com_err(program_name, retval,
|
|
|
|
_("while writing quota file (%d)"),
|
|
|
|
qtype);
|
|
|
|
exit(1);
|
|
|
|
}
|
2016-01-12 16:56:44 +08:00
|
|
|
} else if (quota_enable[qtype] == QOPT_DISABLE) {
|
2016-05-30 05:36:43 +08:00
|
|
|
retval = quota_remove_inode(fs, qtype);
|
|
|
|
if (retval) {
|
|
|
|
com_err(program_name, retval,
|
|
|
|
_("while removing quota file (%d)"),
|
|
|
|
qtype);
|
|
|
|
exit(1);
|
|
|
|
}
|
2016-01-12 16:56:44 +08:00
|
|
|
}
|
2011-11-14 23:58:28 +08:00
|
|
|
}
|
2011-07-21 02:40:05 +08:00
|
|
|
|
2011-11-14 23:55:54 +08:00
|
|
|
quota_release_context(&qctx);
|
2011-07-21 02:40:05 +08:00
|
|
|
|
2016-01-12 16:56:44 +08:00
|
|
|
if (enable) {
|
2015-10-24 13:23:01 +08:00
|
|
|
ext2fs_set_feature_quota(fs->super);
|
2011-07-21 02:40:05 +08:00
|
|
|
ext2fs_mark_super_dirty(fs);
|
2016-01-12 16:56:44 +08:00
|
|
|
} else {
|
|
|
|
for (qtype = 0 ; qtype < MAXQUOTAS; qtype++)
|
|
|
|
if (*quota_sb_inump(fs->super, qtype) != 0)
|
|
|
|
break;
|
|
|
|
if (qtype == MAXQUOTAS) {
|
|
|
|
fs->super->s_feature_ro_compat &=
|
|
|
|
~EXT4_FEATURE_RO_COMPAT_QUOTA;
|
|
|
|
ext2fs_mark_super_dirty(fs);
|
|
|
|
}
|
2011-07-21 02:40:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-12 16:56:44 +08:00
|
|
|
static int option_handle_function(char *token, void *data)
|
2011-07-21 02:40:05 +08:00
|
|
|
{
|
2016-01-12 16:56:44 +08:00
|
|
|
if (strncmp(token, "usr", 3) == 0) {
|
|
|
|
quota_enable[USRQUOTA] = QOPT_ENABLE;
|
|
|
|
} else if (strncmp(token, "^usr", 4) == 0) {
|
|
|
|
quota_enable[USRQUOTA] = QOPT_DISABLE;
|
|
|
|
} else if (strncmp(token, "grp", 3) == 0) {
|
|
|
|
quota_enable[GRPQUOTA] = QOPT_ENABLE;
|
|
|
|
} else if (strncmp(token, "^grp", 4) == 0) {
|
|
|
|
quota_enable[GRPQUOTA] = QOPT_DISABLE;
|
2016-03-01 11:57:05 +08:00
|
|
|
} else if (strncmp(token, "prj", 3) == 0) {
|
|
|
|
quota_enable[PRJQUOTA] = QOPT_ENABLE;
|
|
|
|
} else if (strncmp(token, "^prj", 4) == 0) {
|
|
|
|
quota_enable[PRJQUOTA] = QOPT_DISABLE;
|
2016-01-12 16:56:44 +08:00
|
|
|
} else {
|
|
|
|
fputs(_("\nBad quota options specified.\n\n"
|
|
|
|
"Following valid quota options are available "
|
|
|
|
"(pass by separating with comma):\n"
|
|
|
|
"\t[^]usr[quota]\n"
|
|
|
|
"\t[^]grp[quota]\n"
|
2016-03-01 11:57:05 +08:00
|
|
|
"\t[^]prj[quota]\n"
|
2016-01-12 16:56:44 +08:00
|
|
|
"\n\n"), stderr);
|
|
|
|
return 1;
|
2011-07-21 02:40:05 +08:00
|
|
|
}
|
2016-01-12 16:56:44 +08:00
|
|
|
return 0;
|
2011-07-21 02:40:05 +08:00
|
|
|
}
|
2001-01-09 08:16:26 +08:00
|
|
|
|
ChangeLog, e2image.c, mke2fs.c, mklost+found.c, tune2fs.c, util.c, uuidgen.c:
e2image.c, mke2fs.c, mklost+found.c, tune2fs.c, util.c, uuidgen.c: Fix
gcc -Wall complaints, including one bug in tune2fs caused by a block
automatic shadowing version of the variable we really wanted to use,
which broke the logic testing to see if the filesystem was mounted.
ChangeLog, MCONFIG.in:
(gcc-wall-new): Added new target which forgoes the make clean so we
only check the newly modified .c files.
2001-01-12 00:08:23 +08:00
|
|
|
static void parse_e2label_options(int argc, char ** argv)
|
2001-01-09 08:16:26 +08:00
|
|
|
{
|
|
|
|
if ((argc < 2) || (argc > 3)) {
|
2003-12-07 14:28:50 +08:00
|
|
|
fputs(_("Usage: e2label device [newlabel]\n"), stderr);
|
2001-01-09 08:16:26 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
2004-12-01 03:07:11 +08:00
|
|
|
io_options = strchr(argv[1], '?');
|
|
|
|
if (io_options)
|
|
|
|
*io_options++ = 0;
|
2003-03-07 01:58:33 +08:00
|
|
|
device_name = blkid_get_devname(NULL, argv[1], NULL);
|
2003-11-21 22:10:29 +08:00
|
|
|
if (!device_name) {
|
2008-08-28 11:07:54 +08:00
|
|
|
com_err("e2label", 0, _("Unable to resolve '%s'"),
|
2003-11-21 22:10:29 +08:00
|
|
|
argv[1]);
|
|
|
|
exit(1);
|
|
|
|
}
|
2008-07-10 22:49:59 +08:00
|
|
|
open_flag = EXT2_FLAG_JOURNAL_DEV_OK;
|
2001-01-09 08:16:26 +08:00
|
|
|
if (argc == 3) {
|
2008-02-10 11:22:38 +08:00
|
|
|
open_flag |= EXT2_FLAG_RW;
|
2001-01-09 08:16:26 +08:00
|
|
|
L_flag = 1;
|
|
|
|
new_label = argv[2];
|
2008-08-28 11:07:54 +08:00
|
|
|
} else
|
2001-01-09 08:16:26 +08:00
|
|
|
print_label++;
|
|
|
|
}
|
|
|
|
|
2001-12-26 21:58:01 +08:00
|
|
|
static time_t parse_time(char *str)
|
|
|
|
{
|
|
|
|
struct tm ts;
|
|
|
|
|
|
|
|
if (strcmp(str, "now") == 0) {
|
|
|
|
return (time(0));
|
|
|
|
}
|
|
|
|
memset(&ts, 0, sizeof(ts));
|
2003-05-04 04:40:09 +08:00
|
|
|
#ifdef HAVE_STRPTIME
|
2004-12-22 09:40:08 +08:00
|
|
|
strptime(str, "%Y%m%d%H%M%S", &ts);
|
2003-05-04 04:40:09 +08:00
|
|
|
#else
|
2004-12-22 09:40:08 +08:00
|
|
|
sscanf(str, "%4d%2d%2d%2d%2d%2d", &ts.tm_year, &ts.tm_mon,
|
2003-05-04 04:40:09 +08:00
|
|
|
&ts.tm_mday, &ts.tm_hour, &ts.tm_min, &ts.tm_sec);
|
|
|
|
ts.tm_year -= 1900;
|
|
|
|
ts.tm_mon -= 1;
|
|
|
|
if (ts.tm_year < 0 || ts.tm_mon < 0 || ts.tm_mon > 11 ||
|
|
|
|
ts.tm_mday < 0 || ts.tm_mday > 31 || ts.tm_hour > 23 ||
|
|
|
|
ts.tm_min > 59 || ts.tm_sec > 61)
|
|
|
|
ts.tm_mday = 0;
|
|
|
|
#endif
|
2001-12-26 21:58:01 +08:00
|
|
|
if (ts.tm_mday == 0) {
|
|
|
|
com_err(program_name, 0,
|
|
|
|
_("Couldn't parse date/time specifier: %s"),
|
|
|
|
str);
|
|
|
|
usage();
|
|
|
|
}
|
2008-03-21 21:10:09 +08:00
|
|
|
ts.tm_isdst = -1;
|
2001-12-26 21:58:01 +08:00
|
|
|
return (mktime(&ts));
|
|
|
|
}
|
2001-01-09 08:16:26 +08:00
|
|
|
|
ChangeLog, e2image.c, mke2fs.c, mklost+found.c, tune2fs.c, util.c, uuidgen.c:
e2image.c, mke2fs.c, mklost+found.c, tune2fs.c, util.c, uuidgen.c: Fix
gcc -Wall complaints, including one bug in tune2fs caused by a block
automatic shadowing version of the variable we really wanted to use,
which broke the logic testing to see if the filesystem was mounted.
ChangeLog, MCONFIG.in:
(gcc-wall-new): Added new target which forgoes the make clean so we
only check the newly modified .c files.
2001-01-12 00:08:23 +08:00
|
|
|
static void parse_tune2fs_options(int argc, char **argv)
|
1997-04-26 21:21:57 +08:00
|
|
|
{
|
1997-10-25 11:49:49 +08:00
|
|
|
int c;
|
2009-01-20 15:34:39 +08:00
|
|
|
char *tmp;
|
|
|
|
struct group *gr;
|
|
|
|
struct passwd *pw;
|
2016-01-12 16:56:44 +08:00
|
|
|
int ret;
|
2015-07-04 10:02:30 +08:00
|
|
|
char optstring[100] = "c:e:fg:i:jlm:o:r:s:u:C:E:I:J:L:M:O:T:U:z:Q:";
|
1997-04-26 21:21:57 +08:00
|
|
|
|
2008-07-10 22:49:59 +08:00
|
|
|
open_flag = 0;
|
2001-08-28 00:44:23 +08:00
|
|
|
printf("tune2fs %s (%s)\n", E2FSPROGS_VERSION, E2FSPROGS_DATE);
|
2013-10-14 21:03:06 +08:00
|
|
|
while ((c = getopt(argc, argv, optstring)) != EOF)
|
2009-01-20 15:34:39 +08:00
|
|
|
switch (c) {
|
|
|
|
case 'c':
|
|
|
|
max_mount_count = strtol(optarg, &tmp, 0);
|
|
|
|
if (*tmp || max_mount_count > 16000) {
|
|
|
|
com_err(program_name, 0,
|
|
|
|
_("bad mounts count - %s"),
|
|
|
|
optarg);
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
if (max_mount_count == 0)
|
|
|
|
max_mount_count = -1;
|
|
|
|
c_flag = 1;
|
|
|
|
open_flag = EXT2_FLAG_RW;
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
mount_count = strtoul(optarg, &tmp, 0);
|
|
|
|
if (*tmp || mount_count > 16000) {
|
|
|
|
com_err(program_name, 0,
|
|
|
|
_("bad mounts count - %s"),
|
|
|
|
optarg);
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
C_flag = 1;
|
|
|
|
open_flag = EXT2_FLAG_RW;
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
if (strcmp(optarg, "continue") == 0)
|
|
|
|
errors = EXT2_ERRORS_CONTINUE;
|
|
|
|
else if (strcmp(optarg, "remount-ro") == 0)
|
|
|
|
errors = EXT2_ERRORS_RO;
|
|
|
|
else if (strcmp(optarg, "panic") == 0)
|
|
|
|
errors = EXT2_ERRORS_PANIC;
|
|
|
|
else {
|
|
|
|
com_err(program_name, 0,
|
|
|
|
_("bad error behavior - %s"),
|
|
|
|
optarg);
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
e_flag = 1;
|
|
|
|
open_flag = EXT2_FLAG_RW;
|
|
|
|
break;
|
|
|
|
case 'E':
|
|
|
|
extended_cmd = optarg;
|
|
|
|
open_flag |= EXT2_FLAG_RW;
|
|
|
|
break;
|
|
|
|
case 'f': /* Force */
|
2014-02-21 09:18:41 +08:00
|
|
|
f_flag++;
|
2009-01-20 15:34:39 +08:00
|
|
|
break;
|
|
|
|
case 'g':
|
|
|
|
resgid = strtoul(optarg, &tmp, 0);
|
|
|
|
if (*tmp) {
|
|
|
|
gr = getgrnam(optarg);
|
|
|
|
if (gr == NULL)
|
|
|
|
tmp = optarg;
|
ChangeLog, debugfs.8.in, debugfs.c:
Add a -V option which displays the current version.
ChangeLog, unix.c:
unix.c (e2fsck_update_progress): Remove unused variables.
ChangeLog, inode.c:
inode.c (get_next_blockgroup): Fix bug where if get_next_blockgroup()
is called early because of a missing inode table in a block group, the
current_inode counter wasn't incremented correctly.
ChangeLog, tst_uuid.c:
tst_uuid.c (main): Fixed bogus declaration of the main's argv parameter.
ChangeLog, test_icount.c:
test_icount.c (main): Fix main() declaration so that it returns int,
not void.
Many files:
fsck.c (ignore): Remove unused variable cp.
chattr.c (fatal_error):
tune2fs.c (usage):
lsattr.c (usage):
dumpe2fs.c (usage):
badblocks.c (usage): Remove volatile from declaration.
fsck.c: Change use of strdup to be string_copy, since we don't trust
what glibc is doing with strdup. (Whatever it is, it isn't pretty.)
1998-06-27 13:11:14 +08:00
|
|
|
else {
|
2009-01-20 15:34:39 +08:00
|
|
|
resgid = gr->gr_gid;
|
|
|
|
*tmp = 0;
|
1997-04-26 21:34:30 +08:00
|
|
|
}
|
2009-01-20 15:34:39 +08:00
|
|
|
}
|
|
|
|
if (*tmp) {
|
|
|
|
com_err(program_name, 0,
|
|
|
|
_("bad gid/group name - %s"),
|
|
|
|
optarg);
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
g_flag = 1;
|
|
|
|
open_flag = EXT2_FLAG_RW;
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
interval = strtoul(optarg, &tmp, 0);
|
|
|
|
switch (*tmp) {
|
|
|
|
case 's':
|
|
|
|
tmp++;
|
1997-04-26 21:34:30 +08:00
|
|
|
break;
|
2009-01-20 15:34:39 +08:00
|
|
|
case '\0':
|
|
|
|
case 'd':
|
|
|
|
case 'D': /* days */
|
|
|
|
interval *= 86400;
|
|
|
|
if (*tmp != '\0')
|
1997-04-29 22:53:37 +08:00
|
|
|
tmp++;
|
|
|
|
break;
|
1997-04-26 21:21:57 +08:00
|
|
|
case 'm':
|
2009-01-20 15:34:39 +08:00
|
|
|
case 'M': /* months! */
|
|
|
|
interval *= 86400 * 30;
|
|
|
|
tmp++;
|
1997-04-26 21:21:57 +08:00
|
|
|
break;
|
2009-01-20 15:34:39 +08:00
|
|
|
case 'w':
|
|
|
|
case 'W': /* weeks */
|
|
|
|
interval *= 86400 * 7;
|
|
|
|
tmp++;
|
2002-10-16 05:43:43 +08:00
|
|
|
break;
|
2009-01-20 15:34:39 +08:00
|
|
|
}
|
|
|
|
if (*tmp) {
|
|
|
|
com_err(program_name, 0,
|
|
|
|
_("bad interval - %s"), optarg);
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
i_flag = 1;
|
|
|
|
open_flag = EXT2_FLAG_RW;
|
|
|
|
break;
|
|
|
|
case 'j':
|
|
|
|
if (!journal_size)
|
|
|
|
journal_size = -1;
|
|
|
|
open_flag = EXT2_FLAG_RW;
|
|
|
|
break;
|
|
|
|
case 'J':
|
|
|
|
parse_journal_opts(optarg);
|
|
|
|
open_flag = EXT2_FLAG_RW;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
l_flag = 1;
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
new_label = optarg;
|
|
|
|
L_flag = 1;
|
|
|
|
open_flag |= EXT2_FLAG_RW |
|
|
|
|
EXT2_FLAG_JOURNAL_DEV_OK;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
reserved_ratio = strtod(optarg, &tmp);
|
2009-03-06 15:23:59 +08:00
|
|
|
if (*tmp || reserved_ratio > 50 ||
|
|
|
|
reserved_ratio < 0) {
|
2009-01-20 15:34:39 +08:00
|
|
|
com_err(program_name, 0,
|
|
|
|
_("bad reserved block ratio - %s"),
|
|
|
|
optarg);
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
m_flag = 1;
|
|
|
|
open_flag = EXT2_FLAG_RW;
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
new_last_mounted = optarg;
|
|
|
|
M_flag = 1;
|
|
|
|
open_flag = EXT2_FLAG_RW;
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
if (mntopts_cmd) {
|
2013-12-16 11:11:40 +08:00
|
|
|
com_err(program_name, 0, "%s",
|
2009-01-20 15:34:39 +08:00
|
|
|
_("-o may only be specified once"));
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
mntopts_cmd = optarg;
|
|
|
|
open_flag = EXT2_FLAG_RW;
|
|
|
|
break;
|
|
|
|
case 'O':
|
|
|
|
if (features_cmd) {
|
2013-12-16 11:11:40 +08:00
|
|
|
com_err(program_name, 0, "%s",
|
2009-01-20 15:34:39 +08:00
|
|
|
_("-O may only be specified once"));
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
features_cmd = optarg;
|
|
|
|
open_flag = EXT2_FLAG_RW;
|
|
|
|
break;
|
2011-07-21 02:40:05 +08:00
|
|
|
case 'Q':
|
|
|
|
Q_flag = 1;
|
2016-01-12 16:56:44 +08:00
|
|
|
ret = parse_quota_opts(optarg, option_handle_function,
|
|
|
|
NULL);
|
|
|
|
if (ret)
|
|
|
|
exit(1);
|
2011-07-21 02:40:05 +08:00
|
|
|
open_flag = EXT2_FLAG_RW;
|
|
|
|
break;
|
2009-01-20 15:34:39 +08:00
|
|
|
case 'r':
|
|
|
|
reserved_blocks = strtoul(optarg, &tmp, 0);
|
|
|
|
if (*tmp) {
|
|
|
|
com_err(program_name, 0,
|
|
|
|
_("bad reserved blocks count - %s"),
|
|
|
|
optarg);
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
r_flag = 1;
|
|
|
|
open_flag = EXT2_FLAG_RW;
|
|
|
|
break;
|
|
|
|
case 's': /* Deprecated */
|
|
|
|
s_flag = atoi(optarg);
|
|
|
|
open_flag = EXT2_FLAG_RW;
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
T_flag = 1;
|
|
|
|
last_check_time = parse_time(optarg);
|
|
|
|
open_flag = EXT2_FLAG_RW;
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
resuid = strtoul(optarg, &tmp, 0);
|
ChangeLog, debugfs.8.in, debugfs.c:
Add a -V option which displays the current version.
ChangeLog, unix.c:
unix.c (e2fsck_update_progress): Remove unused variables.
ChangeLog, inode.c:
inode.c (get_next_blockgroup): Fix bug where if get_next_blockgroup()
is called early because of a missing inode table in a block group, the
current_inode counter wasn't incremented correctly.
ChangeLog, tst_uuid.c:
tst_uuid.c (main): Fixed bogus declaration of the main's argv parameter.
ChangeLog, test_icount.c:
test_icount.c (main): Fix main() declaration so that it returns int,
not void.
Many files:
fsck.c (ignore): Remove unused variable cp.
chattr.c (fatal_error):
tune2fs.c (usage):
lsattr.c (usage):
dumpe2fs.c (usage):
badblocks.c (usage): Remove volatile from declaration.
fsck.c: Change use of strdup to be string_copy, since we don't trust
what glibc is doing with strdup. (Whatever it is, it isn't pretty.)
1998-06-27 13:11:14 +08:00
|
|
|
if (*tmp) {
|
2009-01-20 15:34:39 +08:00
|
|
|
pw = getpwnam(optarg);
|
1997-04-26 21:34:30 +08:00
|
|
|
if (pw == NULL)
|
|
|
|
tmp = optarg;
|
1997-04-26 22:00:26 +08:00
|
|
|
else {
|
1997-04-26 21:34:30 +08:00
|
|
|
resuid = pw->pw_uid;
|
1997-04-26 22:00:26 +08:00
|
|
|
*tmp = 0;
|
|
|
|
}
|
1997-04-26 21:34:30 +08:00
|
|
|
}
|
ChangeLog, debugfs.8.in, debugfs.c:
Add a -V option which displays the current version.
ChangeLog, unix.c:
unix.c (e2fsck_update_progress): Remove unused variables.
ChangeLog, inode.c:
inode.c (get_next_blockgroup): Fix bug where if get_next_blockgroup()
is called early because of a missing inode table in a block group, the
current_inode counter wasn't incremented correctly.
ChangeLog, tst_uuid.c:
tst_uuid.c (main): Fixed bogus declaration of the main's argv parameter.
ChangeLog, test_icount.c:
test_icount.c (main): Fix main() declaration so that it returns int,
not void.
Many files:
fsck.c (ignore): Remove unused variable cp.
chattr.c (fatal_error):
tune2fs.c (usage):
lsattr.c (usage):
dumpe2fs.c (usage):
badblocks.c (usage): Remove volatile from declaration.
fsck.c: Change use of strdup to be string_copy, since we don't trust
what glibc is doing with strdup. (Whatever it is, it isn't pretty.)
1998-06-27 13:11:14 +08:00
|
|
|
if (*tmp) {
|
2009-01-20 15:34:39 +08:00
|
|
|
com_err(program_name, 0,
|
|
|
|
_("bad uid/user name - %s"),
|
|
|
|
optarg);
|
ChangeLog, debugfs.8.in, debugfs.c:
Add a -V option which displays the current version.
ChangeLog, unix.c:
unix.c (e2fsck_update_progress): Remove unused variables.
ChangeLog, inode.c:
inode.c (get_next_blockgroup): Fix bug where if get_next_blockgroup()
is called early because of a missing inode table in a block group, the
current_inode counter wasn't incremented correctly.
ChangeLog, tst_uuid.c:
tst_uuid.c (main): Fixed bogus declaration of the main's argv parameter.
ChangeLog, test_icount.c:
test_icount.c (main): Fix main() declaration so that it returns int,
not void.
Many files:
fsck.c (ignore): Remove unused variable cp.
chattr.c (fatal_error):
tune2fs.c (usage):
lsattr.c (usage):
dumpe2fs.c (usage):
badblocks.c (usage): Remove volatile from declaration.
fsck.c: Change use of strdup to be string_copy, since we don't trust
what glibc is doing with strdup. (Whatever it is, it isn't pretty.)
1998-06-27 13:11:14 +08:00
|
|
|
usage();
|
1997-04-26 21:34:30 +08:00
|
|
|
}
|
|
|
|
u_flag = 1;
|
1997-04-29 22:53:37 +08:00
|
|
|
open_flag = EXT2_FLAG_RW;
|
|
|
|
break;
|
2009-01-20 15:34:39 +08:00
|
|
|
case 'U':
|
|
|
|
new_UUID = optarg;
|
|
|
|
U_flag = 1;
|
|
|
|
open_flag = EXT2_FLAG_RW |
|
|
|
|
EXT2_FLAG_JOURNAL_DEV_OK;
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
new_inode_size = strtoul(optarg, &tmp, 0);
|
|
|
|
if (*tmp) {
|
|
|
|
com_err(program_name, 0,
|
|
|
|
_("bad inode size - %s"),
|
|
|
|
optarg);
|
ChangeLog, debugfs.8.in, debugfs.c:
Add a -V option which displays the current version.
ChangeLog, unix.c:
unix.c (e2fsck_update_progress): Remove unused variables.
ChangeLog, inode.c:
inode.c (get_next_blockgroup): Fix bug where if get_next_blockgroup()
is called early because of a missing inode table in a block group, the
current_inode counter wasn't incremented correctly.
ChangeLog, tst_uuid.c:
tst_uuid.c (main): Fixed bogus declaration of the main's argv parameter.
ChangeLog, test_icount.c:
test_icount.c (main): Fix main() declaration so that it returns int,
not void.
Many files:
fsck.c (ignore): Remove unused variable cp.
chattr.c (fatal_error):
tune2fs.c (usage):
lsattr.c (usage):
dumpe2fs.c (usage):
badblocks.c (usage): Remove volatile from declaration.
fsck.c: Change use of strdup to be string_copy, since we don't trust
what glibc is doing with strdup. (Whatever it is, it isn't pretty.)
1998-06-27 13:11:14 +08:00
|
|
|
usage();
|
2009-01-20 15:34:39 +08:00
|
|
|
}
|
|
|
|
if (!((new_inode_size &
|
|
|
|
(new_inode_size - 1)) == 0)) {
|
|
|
|
com_err(program_name, 0,
|
|
|
|
_("Inode size must be a "
|
|
|
|
"power of two- %s"),
|
|
|
|
optarg);
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
open_flag = EXT2_FLAG_RW;
|
|
|
|
I_flag = 1;
|
|
|
|
break;
|
2015-05-05 22:41:08 +08:00
|
|
|
case 'z':
|
|
|
|
undo_file = optarg;
|
|
|
|
break;
|
2009-01-20 15:34:39 +08:00
|
|
|
default:
|
|
|
|
usage();
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
|
|
|
if (optind < argc - 1 || optind == argc)
|
ChangeLog, debugfs.8.in, debugfs.c:
Add a -V option which displays the current version.
ChangeLog, unix.c:
unix.c (e2fsck_update_progress): Remove unused variables.
ChangeLog, inode.c:
inode.c (get_next_blockgroup): Fix bug where if get_next_blockgroup()
is called early because of a missing inode table in a block group, the
current_inode counter wasn't incremented correctly.
ChangeLog, tst_uuid.c:
tst_uuid.c (main): Fixed bogus declaration of the main's argv parameter.
ChangeLog, test_icount.c:
test_icount.c (main): Fix main() declaration so that it returns int,
not void.
Many files:
fsck.c (ignore): Remove unused variable cp.
chattr.c (fatal_error):
tune2fs.c (usage):
lsattr.c (usage):
dumpe2fs.c (usage):
badblocks.c (usage): Remove volatile from declaration.
fsck.c: Change use of strdup to be string_copy, since we don't trust
what glibc is doing with strdup. (Whatever it is, it isn't pretty.)
1998-06-27 13:11:14 +08:00
|
|
|
usage();
|
1997-04-29 22:53:37 +08:00
|
|
|
if (!open_flag && !l_flag)
|
|
|
|
usage();
|
2004-12-01 03:07:11 +08:00
|
|
|
io_options = strchr(argv[optind], '?');
|
|
|
|
if (io_options)
|
|
|
|
*io_options++ = 0;
|
2003-03-07 01:58:33 +08:00
|
|
|
device_name = blkid_get_devname(NULL, argv[optind], NULL);
|
2003-11-21 22:10:29 +08:00
|
|
|
if (!device_name) {
|
2013-01-02 02:28:27 +08:00
|
|
|
com_err(program_name, 0, _("Unable to resolve '%s'"),
|
2003-11-21 22:10:29 +08:00
|
|
|
argv[optind]);
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-08-18 11:01:22 +08:00
|
|
|
}
|
|
|
|
|
2009-04-22 21:18:30 +08:00
|
|
|
#ifdef CONFIG_BUILD_FINDFS
|
2002-10-14 11:56:28 +08:00
|
|
|
void do_findfs(int argc, char **argv)
|
2002-08-18 11:01:22 +08:00
|
|
|
{
|
|
|
|
char *dev;
|
2001-01-09 08:16:26 +08:00
|
|
|
|
2002-08-18 11:01:22 +08:00
|
|
|
if ((argc != 2) ||
|
|
|
|
(strncmp(argv[1], "LABEL=", 6) && strncmp(argv[1], "UUID=", 5))) {
|
|
|
|
fprintf(stderr, "Usage: findfs LABEL=<label>|UUID=<uuid>\n");
|
|
|
|
exit(2);
|
|
|
|
}
|
2003-03-02 08:29:01 +08:00
|
|
|
dev = blkid_get_devname(NULL, argv[1], NULL);
|
2002-08-18 11:01:22 +08:00
|
|
|
if (!dev) {
|
2008-08-28 11:07:54 +08:00
|
|
|
com_err("findfs", 0, _("Unable to resolve '%s'"),
|
2002-08-18 11:01:22 +08:00
|
|
|
argv[1]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
puts(dev);
|
|
|
|
exit(0);
|
|
|
|
}
|
2009-04-22 21:18:30 +08:00
|
|
|
#endif
|
2001-01-09 08:16:26 +08:00
|
|
|
|
2011-09-25 01:48:55 +08:00
|
|
|
static int parse_extended_opts(ext2_filsys fs, const char *opts)
|
2008-01-27 08:06:35 +08:00
|
|
|
{
|
|
|
|
char *buf, *token, *next, *p, *arg;
|
2008-08-30 09:21:19 +08:00
|
|
|
int len, hash_alg;
|
2008-01-27 08:06:35 +08:00
|
|
|
int r_usage = 0;
|
|
|
|
|
|
|
|
len = strlen(opts);
|
|
|
|
buf = malloc(len+1);
|
|
|
|
if (!buf) {
|
2013-12-16 11:11:40 +08:00
|
|
|
fprintf(stderr, "%s",
|
2008-01-27 08:06:35 +08:00
|
|
|
_("Couldn't allocate memory to parse options!\n"));
|
2011-09-25 01:48:55 +08:00
|
|
|
return 1;
|
2008-01-27 08:06:35 +08:00
|
|
|
}
|
|
|
|
strcpy(buf, opts);
|
|
|
|
for (token = buf; token && *token; token = next) {
|
|
|
|
p = strchr(token, ',');
|
|
|
|
next = 0;
|
|
|
|
if (p) {
|
|
|
|
*p = 0;
|
|
|
|
next = p+1;
|
|
|
|
}
|
|
|
|
arg = strchr(token, '=');
|
|
|
|
if (arg) {
|
|
|
|
*arg = 0;
|
|
|
|
arg++;
|
|
|
|
}
|
2011-09-25 01:48:55 +08:00
|
|
|
if (strcmp(token, "clear-mmp") == 0 ||
|
|
|
|
strcmp(token, "clear_mmp") == 0) {
|
|
|
|
clear_mmp = 1;
|
|
|
|
} else if (strcmp(token, "mmp_update_interval") == 0) {
|
2013-05-20 08:03:48 +08:00
|
|
|
unsigned long intv;
|
2011-09-25 01:48:55 +08:00
|
|
|
if (!arg) {
|
|
|
|
r_usage++;
|
|
|
|
continue;
|
|
|
|
}
|
2013-05-20 08:03:48 +08:00
|
|
|
intv = strtoul(arg, &p, 0);
|
2011-09-25 01:48:55 +08:00
|
|
|
if (*p) {
|
|
|
|
fprintf(stderr,
|
|
|
|
_("Invalid mmp_update_interval: %s\n"),
|
|
|
|
arg);
|
|
|
|
r_usage++;
|
|
|
|
continue;
|
|
|
|
}
|
2013-05-20 08:03:48 +08:00
|
|
|
if (intv == 0) {
|
|
|
|
intv = EXT4_MMP_UPDATE_INTERVAL;
|
|
|
|
} else if (intv > EXT4_MMP_MAX_UPDATE_INTERVAL) {
|
2011-09-25 01:48:55 +08:00
|
|
|
fprintf(stderr,
|
|
|
|
_("mmp_update_interval too big: %lu\n"),
|
2013-05-20 08:03:48 +08:00
|
|
|
intv);
|
2011-09-25 01:48:55 +08:00
|
|
|
r_usage++;
|
|
|
|
continue;
|
|
|
|
}
|
2011-10-10 05:08:47 +08:00
|
|
|
printf(P_("Setting multiple mount protection update "
|
|
|
|
"interval to %lu second\n",
|
|
|
|
"Setting multiple mount protection update "
|
2013-05-20 08:03:48 +08:00
|
|
|
"interval to %lu seconds\n", intv),
|
|
|
|
intv);
|
|
|
|
fs->super->s_mmp_update_interval = intv;
|
2011-09-25 01:48:55 +08:00
|
|
|
ext2fs_mark_super_dirty(fs);
|
|
|
|
} else if (!strcmp(token, "test_fs")) {
|
2008-01-27 08:06:35 +08:00
|
|
|
fs->super->s_flags |= EXT2_FLAGS_TEST_FILESYS;
|
|
|
|
printf("Setting test filesystem flag\n");
|
|
|
|
ext2fs_mark_super_dirty(fs);
|
|
|
|
} else if (!strcmp(token, "^test_fs")) {
|
|
|
|
fs->super->s_flags &= ~EXT2_FLAGS_TEST_FILESYS;
|
|
|
|
printf("Clearing test filesystem flag\n");
|
|
|
|
ext2fs_mark_super_dirty(fs);
|
2008-02-19 11:56:25 +08:00
|
|
|
} else if (strcmp(token, "stride") == 0) {
|
|
|
|
if (!arg) {
|
|
|
|
r_usage++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
stride = strtoul(arg, &p, 0);
|
2011-07-05 07:37:11 +08:00
|
|
|
if (*p) {
|
2008-02-19 11:56:25 +08:00
|
|
|
fprintf(stderr,
|
2011-09-25 01:48:55 +08:00
|
|
|
_("Invalid RAID stride: %s\n"),
|
2008-02-19 11:56:25 +08:00
|
|
|
arg);
|
|
|
|
r_usage++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
stride_set = 1;
|
|
|
|
} else if (strcmp(token, "stripe-width") == 0 ||
|
|
|
|
strcmp(token, "stripe_width") == 0) {
|
|
|
|
if (!arg) {
|
|
|
|
r_usage++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
stripe_width = strtoul(arg, &p, 0);
|
2011-07-05 07:37:11 +08:00
|
|
|
if (*p) {
|
2008-02-19 11:56:25 +08:00
|
|
|
fprintf(stderr,
|
|
|
|
_("Invalid RAID stripe-width: %s\n"),
|
|
|
|
arg);
|
|
|
|
r_usage++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
stripe_width_set = 1;
|
2008-08-30 09:21:19 +08:00
|
|
|
} 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) {
|
2009-01-20 15:34:39 +08:00
|
|
|
fprintf(stderr,
|
2008-08-30 09:21:19 +08:00
|
|
|
_("Invalid hash algorithm: %s\n"),
|
|
|
|
arg);
|
|
|
|
r_usage++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
fs->super->s_def_hash_version = hash_alg;
|
|
|
|
printf(_("Setting default hash algorithm "
|
2009-01-20 15:34:39 +08:00
|
|
|
"to %s (%d)\n"),
|
2008-08-30 09:21:19 +08:00
|
|
|
arg, hash_alg);
|
|
|
|
ext2fs_mark_super_dirty(fs);
|
2011-07-05 08:14:35 +08:00
|
|
|
} else if (!strcmp(token, "mount_opts")) {
|
2010-09-19 07:38:22 +08:00
|
|
|
if (!arg) {
|
|
|
|
r_usage++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (strlen(arg) >= sizeof(fs->super->s_mount_opts)) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Extended mount options too long\n");
|
|
|
|
continue;
|
|
|
|
}
|
2011-07-05 08:14:35 +08:00
|
|
|
ext_mount_opts = strdup(arg);
|
2008-08-28 11:07:54 +08:00
|
|
|
} else
|
2008-01-27 08:06:35 +08:00
|
|
|
r_usage++;
|
|
|
|
}
|
|
|
|
if (r_usage) {
|
2013-12-16 11:11:40 +08:00
|
|
|
fprintf(stderr, "%s", _("\nBad options specified.\n\n"
|
2008-01-27 08:06:35 +08:00
|
|
|
"Extended options are separated by commas, "
|
|
|
|
"and may take an argument which\n"
|
|
|
|
"\tis set off by an equals ('=') sign.\n\n"
|
|
|
|
"Valid extended options are:\n"
|
2011-09-25 01:48:55 +08:00
|
|
|
"\tclear_mmp\n"
|
2011-07-05 08:14:35 +08:00
|
|
|
"\thash_alg=<hash algorithm>\n"
|
|
|
|
"\tmount_opts=<extended default mount options>\n"
|
2008-02-19 11:56:25 +08:00
|
|
|
"\tstride=<RAID per-disk chunk size in blocks>\n"
|
2008-08-30 09:21:19 +08:00
|
|
|
"\tstripe_width=<RAID stride*data disks in blocks>\n"
|
2008-01-27 08:06:35 +08:00
|
|
|
"\ttest_fs\n"
|
|
|
|
"\t^test_fs\n"));
|
|
|
|
free(buf);
|
2011-09-25 01:48:55 +08:00
|
|
|
return 1;
|
2008-01-27 08:06:35 +08:00
|
|
|
}
|
|
|
|
free(buf);
|
2011-09-25 01:48:55 +08:00
|
|
|
|
|
|
|
return 0;
|
2008-08-28 11:07:54 +08:00
|
|
|
}
|
2008-01-27 08:06:35 +08:00
|
|
|
|
2009-01-21 00:49:17 +08:00
|
|
|
/*
|
2009-08-06 14:12:29 +08:00
|
|
|
* Fill in the block bitmap bmap with the information regarding the
|
|
|
|
* blocks to be moved
|
2009-01-21 00:49:17 +08:00
|
|
|
*/
|
|
|
|
static int get_move_bitmaps(ext2_filsys fs, int new_ino_blks_per_grp,
|
2009-08-06 14:12:29 +08:00
|
|
|
ext2fs_block_bitmap bmap)
|
2007-08-13 18:26:24 +08:00
|
|
|
{
|
|
|
|
dgrp_t i;
|
2009-08-06 14:12:31 +08:00
|
|
|
int retval;
|
|
|
|
ext2_badblocks_list bb_list = 0;
|
2010-06-14 04:00:00 +08:00
|
|
|
blk64_t j, needed_blocks = 0;
|
|
|
|
blk64_t start_blk, end_blk;
|
2007-08-13 18:26:24 +08:00
|
|
|
|
2009-08-06 14:12:31 +08:00
|
|
|
retval = ext2fs_read_bb_inode(fs, &bb_list);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
2007-08-13 18:26:24 +08:00
|
|
|
for (i = 0; i < fs->group_desc_count; i++) {
|
Convert to use block group accessor functions
Convert direct accesses to use the following block group accessor
functions: ext2fs_block_bitmap_loc(), ext2fs_inode_bitmap_loc(),
ext2fs_inode_table_loc(), ext2fs_bg_itable_unused(),
ext2fs_block_bitmap_loc_set(), ext2fs_inode_bitmap_loc_set(),
ext2fs_inode_table_loc_set(), ext2fs_bg_free_inodes_count(),
ext2fs_ext2fs_bg_used_dirs_count(), ext2fs_bg_free_inodes_count_set(),
ext2fs_bg_free_blocks_count_set(), ext2fs_bg_used_dirs_count_set()
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com>
Signed-off-by: Nick Dokos <nicholas.dokos@hp.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-26 09:43:47 +08:00
|
|
|
start_blk = ext2fs_inode_table_loc(fs, i) +
|
2007-08-13 18:26:24 +08:00
|
|
|
fs->inode_blocks_per_group;
|
|
|
|
|
Convert to use block group accessor functions
Convert direct accesses to use the following block group accessor
functions: ext2fs_block_bitmap_loc(), ext2fs_inode_bitmap_loc(),
ext2fs_inode_table_loc(), ext2fs_bg_itable_unused(),
ext2fs_block_bitmap_loc_set(), ext2fs_inode_bitmap_loc_set(),
ext2fs_inode_table_loc_set(), ext2fs_bg_free_inodes_count(),
ext2fs_ext2fs_bg_used_dirs_count(), ext2fs_bg_free_inodes_count_set(),
ext2fs_bg_free_blocks_count_set(), ext2fs_bg_used_dirs_count_set()
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com>
Signed-off-by: Nick Dokos <nicholas.dokos@hp.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-26 09:43:47 +08:00
|
|
|
end_blk = ext2fs_inode_table_loc(fs, i) +
|
2007-08-13 18:26:24 +08:00
|
|
|
new_ino_blks_per_grp;
|
|
|
|
|
|
|
|
for (j = start_blk; j < end_blk; j++) {
|
2009-08-23 09:15:30 +08:00
|
|
|
if (ext2fs_test_block_bitmap2(fs->block_map, j)) {
|
2009-08-06 14:12:31 +08:00
|
|
|
/*
|
|
|
|
* IF the block is a bad block we fail
|
2007-08-13 18:26:24 +08:00
|
|
|
*/
|
2009-08-06 14:12:31 +08:00
|
|
|
if (ext2fs_badblocks_list_test(bb_list, j)) {
|
|
|
|
ext2fs_badblocks_list_free(bb_list);
|
|
|
|
return ENOSPC;
|
|
|
|
}
|
|
|
|
|
2009-08-23 09:15:30 +08:00
|
|
|
ext2fs_mark_block_bitmap2(bmap, j);
|
2007-08-13 18:26:24 +08:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We are going to use this block for
|
|
|
|
* inode table. So mark them used.
|
|
|
|
*/
|
2009-08-23 09:15:30 +08:00
|
|
|
ext2fs_mark_block_bitmap2(fs->block_map, j);
|
2007-08-13 18:26:24 +08:00
|
|
|
}
|
|
|
|
}
|
2009-08-06 14:12:29 +08:00
|
|
|
needed_blocks += end_blk - start_blk;
|
2007-08-13 18:26:24 +08:00
|
|
|
}
|
|
|
|
|
2009-08-06 14:12:31 +08:00
|
|
|
ext2fs_badblocks_list_free(bb_list);
|
2009-09-08 08:46:34 +08:00
|
|
|
if (needed_blocks > ext2fs_free_blocks_count(fs->super))
|
2007-08-13 18:26:24 +08:00
|
|
|
return ENOSPC;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-07 21:51:48 +08:00
|
|
|
static int ext2fs_is_meta_block(ext2_filsys fs, blk64_t blk)
|
2009-08-06 14:12:30 +08:00
|
|
|
{
|
|
|
|
dgrp_t group;
|
2013-10-07 21:51:48 +08:00
|
|
|
group = ext2fs_group_of_blk2(fs, blk);
|
Convert to use block group accessor functions
Convert direct accesses to use the following block group accessor
functions: ext2fs_block_bitmap_loc(), ext2fs_inode_bitmap_loc(),
ext2fs_inode_table_loc(), ext2fs_bg_itable_unused(),
ext2fs_block_bitmap_loc_set(), ext2fs_inode_bitmap_loc_set(),
ext2fs_inode_table_loc_set(), ext2fs_bg_free_inodes_count(),
ext2fs_ext2fs_bg_used_dirs_count(), ext2fs_bg_free_inodes_count_set(),
ext2fs_bg_free_blocks_count_set(), ext2fs_bg_used_dirs_count_set()
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com>
Signed-off-by: Nick Dokos <nicholas.dokos@hp.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-26 09:43:47 +08:00
|
|
|
if (ext2fs_block_bitmap_loc(fs, group) == blk)
|
2009-08-06 14:12:30 +08:00
|
|
|
return 1;
|
Convert to use block group accessor functions
Convert direct accesses to use the following block group accessor
functions: ext2fs_block_bitmap_loc(), ext2fs_inode_bitmap_loc(),
ext2fs_inode_table_loc(), ext2fs_bg_itable_unused(),
ext2fs_block_bitmap_loc_set(), ext2fs_inode_bitmap_loc_set(),
ext2fs_inode_table_loc_set(), ext2fs_bg_free_inodes_count(),
ext2fs_ext2fs_bg_used_dirs_count(), ext2fs_bg_free_inodes_count_set(),
ext2fs_bg_free_blocks_count_set(), ext2fs_bg_used_dirs_count_set()
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com>
Signed-off-by: Nick Dokos <nicholas.dokos@hp.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-26 09:43:47 +08:00
|
|
|
if (ext2fs_inode_bitmap_loc(fs, group) == blk)
|
2009-08-06 14:12:30 +08:00
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-07 21:51:48 +08:00
|
|
|
static int ext2fs_is_block_in_group(ext2_filsys fs, dgrp_t group, blk64_t blk)
|
2009-08-06 14:12:30 +08:00
|
|
|
{
|
2013-10-07 21:51:48 +08:00
|
|
|
blk64_t start_blk, end_blk;
|
2009-08-06 14:12:30 +08:00
|
|
|
start_blk = fs->super->s_first_data_block +
|
2014-07-26 19:40:36 +08:00
|
|
|
EXT2_GROUPS_TO_BLOCKS(fs->super, group);
|
2009-08-06 14:12:30 +08:00
|
|
|
/*
|
|
|
|
* We cannot get new block beyond end_blk for for the last block group
|
|
|
|
* so we can check with EXT2_BLOCKS_PER_GROUP even for last block group
|
|
|
|
*/
|
|
|
|
end_blk = start_blk + EXT2_BLOCKS_PER_GROUP(fs->super);
|
|
|
|
if (blk >= start_blk && blk <= end_blk)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-06 14:12:29 +08:00
|
|
|
static int move_block(ext2_filsys fs, ext2fs_block_bitmap bmap)
|
2007-08-13 18:26:24 +08:00
|
|
|
{
|
2009-08-06 14:12:30 +08:00
|
|
|
|
2007-08-13 18:26:24 +08:00
|
|
|
char *buf;
|
2011-06-11 22:58:25 +08:00
|
|
|
dgrp_t group = 0;
|
2007-08-13 18:26:24 +08:00
|
|
|
errcode_t retval;
|
2009-08-06 14:12:30 +08:00
|
|
|
int meta_data = 0;
|
2010-06-14 04:00:00 +08:00
|
|
|
blk64_t blk, new_blk, goal;
|
2007-08-13 18:26:24 +08:00
|
|
|
struct blk_move *bmv;
|
|
|
|
|
|
|
|
retval = ext2fs_get_mem(fs->blocksize, &buf);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
2008-11-15 13:32:39 +08:00
|
|
|
for (new_blk = blk = fs->super->s_first_data_block;
|
2009-09-08 08:46:34 +08:00
|
|
|
blk < ext2fs_blocks_count(fs->super); blk++) {
|
2009-08-23 09:15:30 +08:00
|
|
|
if (!ext2fs_test_block_bitmap2(bmap, blk))
|
2007-08-13 18:26:24 +08:00
|
|
|
continue;
|
|
|
|
|
2009-08-06 14:12:30 +08:00
|
|
|
if (ext2fs_is_meta_block(fs, blk)) {
|
|
|
|
/*
|
|
|
|
* If the block is mapping a fs meta data block
|
|
|
|
* like group desc/block bitmap/inode bitmap. We
|
|
|
|
* should find a block in the same group and fix
|
|
|
|
* the respective fs metadata pointers. Otherwise
|
|
|
|
* fail
|
|
|
|
*/
|
2013-10-07 21:51:48 +08:00
|
|
|
group = ext2fs_group_of_blk2(fs, blk);
|
2009-10-26 09:24:06 +08:00
|
|
|
goal = ext2fs_group_first_block2(fs, group);
|
2009-08-06 14:12:30 +08:00
|
|
|
meta_data = 1;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
goal = new_blk;
|
|
|
|
}
|
2010-06-14 04:00:00 +08:00
|
|
|
retval = ext2fs_new_block2(fs, goal, NULL, &new_blk);
|
2007-08-13 18:26:24 +08:00
|
|
|
if (retval)
|
|
|
|
goto err_out;
|
|
|
|
|
2009-08-06 14:12:30 +08:00
|
|
|
/* new fs meta data block should be in the same group */
|
|
|
|
if (meta_data && !ext2fs_is_block_in_group(fs, group, new_blk)) {
|
|
|
|
retval = ENOSPC;
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
2007-08-13 18:26:24 +08:00
|
|
|
/* Mark this block as allocated */
|
2009-08-23 09:15:30 +08:00
|
|
|
ext2fs_mark_block_bitmap2(fs->block_map, new_blk);
|
2007-08-13 18:26:24 +08:00
|
|
|
|
|
|
|
/* Add it to block move list */
|
|
|
|
retval = ext2fs_get_mem(sizeof(struct blk_move), &bmv);
|
|
|
|
if (retval)
|
|
|
|
goto err_out;
|
|
|
|
|
|
|
|
bmv->old_loc = blk;
|
|
|
|
bmv->new_loc = new_blk;
|
|
|
|
|
|
|
|
list_add(&(bmv->list), &blk_move_list);
|
|
|
|
|
2009-09-08 09:14:24 +08:00
|
|
|
retval = io_channel_read_blk64(fs->io, blk, 1, buf);
|
2007-08-13 18:26:24 +08:00
|
|
|
if (retval)
|
|
|
|
goto err_out;
|
|
|
|
|
2009-09-08 09:14:24 +08:00
|
|
|
retval = io_channel_write_blk64(fs->io, new_blk, 1, buf);
|
2007-08-13 18:26:24 +08:00
|
|
|
if (retval)
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
err_out:
|
|
|
|
ext2fs_free_mem(&buf);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-06-14 04:00:00 +08:00
|
|
|
static blk64_t translate_block(blk64_t blk)
|
2007-08-13 18:26:24 +08:00
|
|
|
{
|
|
|
|
struct list_head *entry;
|
|
|
|
struct blk_move *bmv;
|
|
|
|
|
|
|
|
list_for_each(entry, &blk_move_list) {
|
|
|
|
bmv = list_entry(entry, struct blk_move, list);
|
|
|
|
if (bmv->old_loc == blk)
|
|
|
|
return bmv->new_loc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-07 23:51:33 +08:00
|
|
|
static int process_block(ext2_filsys fs EXT2FS_ATTR((unused)),
|
2010-06-14 04:00:00 +08:00
|
|
|
blk64_t *block_nr,
|
2008-06-07 23:51:33 +08:00
|
|
|
e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
|
2010-06-14 04:00:00 +08:00
|
|
|
blk64_t ref_block EXT2FS_ATTR((unused)),
|
2007-08-13 18:26:24 +08:00
|
|
|
int ref_offset EXT2FS_ATTR((unused)),
|
2008-11-15 13:32:39 +08:00
|
|
|
void *priv_data)
|
2007-08-13 18:26:24 +08:00
|
|
|
{
|
|
|
|
int ret = 0;
|
2010-06-14 04:00:00 +08:00
|
|
|
blk64_t new_blk;
|
2008-11-15 13:32:39 +08:00
|
|
|
ext2fs_block_bitmap bmap = (ext2fs_block_bitmap) priv_data;
|
2007-08-13 18:26:24 +08:00
|
|
|
|
2009-08-23 09:15:30 +08:00
|
|
|
if (!ext2fs_test_block_bitmap2(bmap, *block_nr))
|
2008-11-15 13:32:39 +08:00
|
|
|
return 0;
|
2009-01-20 15:34:39 +08:00
|
|
|
new_blk = translate_block(*block_nr);
|
2007-08-13 18:26:24 +08:00
|
|
|
if (new_blk) {
|
|
|
|
*block_nr = new_blk;
|
|
|
|
/*
|
|
|
|
* This will force the ext2fs_write_inode in the iterator
|
|
|
|
*/
|
|
|
|
ret |= BLOCK_CHANGED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-11-15 13:32:39 +08:00
|
|
|
static int inode_scan_and_fix(ext2_filsys fs, ext2fs_block_bitmap bmap)
|
2007-08-13 18:26:24 +08:00
|
|
|
{
|
|
|
|
errcode_t retval = 0;
|
|
|
|
ext2_ino_t ino;
|
2010-06-14 04:00:00 +08:00
|
|
|
blk64_t blk;
|
2007-08-13 18:26:24 +08:00
|
|
|
char *block_buf = 0;
|
|
|
|
struct ext2_inode inode;
|
|
|
|
ext2_inode_scan scan = NULL;
|
|
|
|
|
|
|
|
retval = ext2fs_get_mem(fs->blocksize * 3, &block_buf);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
retval = ext2fs_open_inode_scan(fs, 0, &scan);
|
|
|
|
if (retval)
|
|
|
|
goto err_out;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
retval = ext2fs_get_next_inode(scan, &ino, &inode);
|
|
|
|
if (retval)
|
|
|
|
goto err_out;
|
|
|
|
|
|
|
|
if (!ino)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (inode.i_links_count == 0)
|
|
|
|
continue; /* inode not in use */
|
|
|
|
|
|
|
|
/* FIXME!!
|
|
|
|
* If we end up modifying the journal inode
|
|
|
|
* the sb->s_jnl_blocks will differ. But a
|
|
|
|
* subsequent e2fsck fixes that.
|
|
|
|
* Do we need to fix this ??
|
|
|
|
*/
|
|
|
|
|
2011-10-17 08:29:00 +08:00
|
|
|
if (ext2fs_file_acl_block(fs, &inode) &&
|
2009-09-08 10:29:45 +08:00
|
|
|
ext2fs_test_block_bitmap2(bmap,
|
2011-10-17 08:29:00 +08:00
|
|
|
ext2fs_file_acl_block(fs, &inode))) {
|
|
|
|
blk = translate_block(ext2fs_file_acl_block(fs,
|
|
|
|
&inode));
|
2007-08-13 18:26:24 +08:00
|
|
|
if (!blk)
|
|
|
|
continue;
|
|
|
|
|
2011-10-17 08:29:00 +08:00
|
|
|
ext2fs_file_acl_block_set(fs, &inode, blk);
|
2007-08-13 18:26:24 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Write the inode to disk so that inode table
|
|
|
|
* resizing can work
|
|
|
|
*/
|
|
|
|
retval = ext2fs_write_inode(fs, ino, &inode);
|
|
|
|
if (retval)
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
2011-10-17 08:29:00 +08:00
|
|
|
if (!ext2fs_inode_has_valid_blocks2(fs, &inode))
|
2007-08-13 18:26:24 +08:00
|
|
|
continue;
|
|
|
|
|
2010-06-14 04:00:00 +08:00
|
|
|
retval = ext2fs_block_iterate3(fs, ino, 0, block_buf,
|
2008-11-15 13:32:39 +08:00
|
|
|
process_block, bmap);
|
2007-08-13 18:26:24 +08:00
|
|
|
if (retval)
|
|
|
|
goto err_out;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
err_out:
|
|
|
|
ext2fs_free_mem(&block_buf);
|
2014-12-03 10:06:40 +08:00
|
|
|
ext2fs_close_inode_scan(scan);
|
2007-08-13 18:26:24 +08:00
|
|
|
|
|
|
|
return retval;
|
2009-01-21 00:49:17 +08:00
|
|
|
}
|
|
|
|
|
2009-08-06 14:12:30 +08:00
|
|
|
/*
|
|
|
|
* We need to scan for inode and block bitmaps that may need to be
|
|
|
|
* moved. This can take place if the filesystem was formatted for
|
|
|
|
* RAID arrays using the mke2fs's extended option "stride".
|
|
|
|
*/
|
|
|
|
static int group_desc_scan_and_fix(ext2_filsys fs, ext2fs_block_bitmap bmap)
|
|
|
|
{
|
|
|
|
dgrp_t i;
|
2013-10-07 21:51:48 +08:00
|
|
|
blk64_t blk, new_blk;
|
2009-08-06 14:12:30 +08:00
|
|
|
|
|
|
|
for (i = 0; i < fs->group_desc_count; i++) {
|
Convert to use block group accessor functions
Convert direct accesses to use the following block group accessor
functions: ext2fs_block_bitmap_loc(), ext2fs_inode_bitmap_loc(),
ext2fs_inode_table_loc(), ext2fs_bg_itable_unused(),
ext2fs_block_bitmap_loc_set(), ext2fs_inode_bitmap_loc_set(),
ext2fs_inode_table_loc_set(), ext2fs_bg_free_inodes_count(),
ext2fs_ext2fs_bg_used_dirs_count(), ext2fs_bg_free_inodes_count_set(),
ext2fs_bg_free_blocks_count_set(), ext2fs_bg_used_dirs_count_set()
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com>
Signed-off-by: Nick Dokos <nicholas.dokos@hp.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-26 09:43:47 +08:00
|
|
|
blk = ext2fs_block_bitmap_loc(fs, i);
|
2009-08-23 09:15:30 +08:00
|
|
|
if (ext2fs_test_block_bitmap2(bmap, blk)) {
|
2009-08-06 14:12:30 +08:00
|
|
|
new_blk = translate_block(blk);
|
|
|
|
if (!new_blk)
|
|
|
|
continue;
|
Convert to use block group accessor functions
Convert direct accesses to use the following block group accessor
functions: ext2fs_block_bitmap_loc(), ext2fs_inode_bitmap_loc(),
ext2fs_inode_table_loc(), ext2fs_bg_itable_unused(),
ext2fs_block_bitmap_loc_set(), ext2fs_inode_bitmap_loc_set(),
ext2fs_inode_table_loc_set(), ext2fs_bg_free_inodes_count(),
ext2fs_ext2fs_bg_used_dirs_count(), ext2fs_bg_free_inodes_count_set(),
ext2fs_bg_free_blocks_count_set(), ext2fs_bg_used_dirs_count_set()
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com>
Signed-off-by: Nick Dokos <nicholas.dokos@hp.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-26 09:43:47 +08:00
|
|
|
ext2fs_block_bitmap_loc_set(fs, i, new_blk);
|
2009-08-06 14:12:30 +08:00
|
|
|
}
|
|
|
|
|
Convert to use block group accessor functions
Convert direct accesses to use the following block group accessor
functions: ext2fs_block_bitmap_loc(), ext2fs_inode_bitmap_loc(),
ext2fs_inode_table_loc(), ext2fs_bg_itable_unused(),
ext2fs_block_bitmap_loc_set(), ext2fs_inode_bitmap_loc_set(),
ext2fs_inode_table_loc_set(), ext2fs_bg_free_inodes_count(),
ext2fs_ext2fs_bg_used_dirs_count(), ext2fs_bg_free_inodes_count_set(),
ext2fs_bg_free_blocks_count_set(), ext2fs_bg_used_dirs_count_set()
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com>
Signed-off-by: Nick Dokos <nicholas.dokos@hp.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-26 09:43:47 +08:00
|
|
|
blk = ext2fs_inode_bitmap_loc(fs, i);
|
2009-08-23 09:15:30 +08:00
|
|
|
if (ext2fs_test_block_bitmap2(bmap, blk)) {
|
2009-08-06 14:12:30 +08:00
|
|
|
new_blk = translate_block(blk);
|
|
|
|
if (!new_blk)
|
|
|
|
continue;
|
Convert to use block group accessor functions
Convert direct accesses to use the following block group accessor
functions: ext2fs_block_bitmap_loc(), ext2fs_inode_bitmap_loc(),
ext2fs_inode_table_loc(), ext2fs_bg_itable_unused(),
ext2fs_block_bitmap_loc_set(), ext2fs_inode_bitmap_loc_set(),
ext2fs_inode_table_loc_set(), ext2fs_bg_free_inodes_count(),
ext2fs_ext2fs_bg_used_dirs_count(), ext2fs_bg_free_inodes_count_set(),
ext2fs_bg_free_blocks_count_set(), ext2fs_bg_used_dirs_count_set()
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com>
Signed-off-by: Nick Dokos <nicholas.dokos@hp.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-26 09:43:47 +08:00
|
|
|
ext2fs_inode_bitmap_loc_set(fs, i, new_blk);
|
2009-08-06 14:12:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-07 23:51:33 +08:00
|
|
|
static int expand_inode_table(ext2_filsys fs, unsigned long new_ino_size)
|
2007-08-13 18:26:24 +08:00
|
|
|
{
|
|
|
|
dgrp_t i;
|
2010-06-14 04:00:00 +08:00
|
|
|
blk64_t blk;
|
2007-08-13 18:26:24 +08:00
|
|
|
errcode_t retval;
|
2008-06-07 23:51:33 +08:00
|
|
|
int new_ino_blks_per_grp;
|
|
|
|
unsigned int j;
|
2007-08-13 18:26:24 +08:00
|
|
|
char *old_itable = NULL, *new_itable = NULL;
|
|
|
|
char *tmp_old_itable = NULL, *tmp_new_itable = NULL;
|
2008-06-07 23:51:33 +08:00
|
|
|
unsigned long old_ino_size;
|
2007-08-13 18:26:24 +08:00
|
|
|
int old_itable_size, new_itable_size;
|
|
|
|
|
|
|
|
old_itable_size = fs->inode_blocks_per_group * fs->blocksize;
|
2008-06-07 23:51:33 +08:00
|
|
|
old_ino_size = EXT2_INODE_SIZE(fs->super);
|
2007-08-13 18:26:24 +08:00
|
|
|
|
|
|
|
new_ino_blks_per_grp = ext2fs_div_ceil(
|
|
|
|
EXT2_INODES_PER_GROUP(fs->super) *
|
2008-06-07 23:51:33 +08:00
|
|
|
new_ino_size,
|
2007-08-13 18:26:24 +08:00
|
|
|
fs->blocksize);
|
|
|
|
|
|
|
|
new_itable_size = new_ino_blks_per_grp * fs->blocksize;
|
|
|
|
|
|
|
|
retval = ext2fs_get_mem(old_itable_size, &old_itable);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
retval = ext2fs_get_mem(new_itable_size, &new_itable);
|
|
|
|
if (retval)
|
|
|
|
goto err_out;
|
|
|
|
|
|
|
|
tmp_old_itable = old_itable;
|
|
|
|
tmp_new_itable = new_itable;
|
|
|
|
|
|
|
|
for (i = 0; i < fs->group_desc_count; i++) {
|
Convert to use block group accessor functions
Convert direct accesses to use the following block group accessor
functions: ext2fs_block_bitmap_loc(), ext2fs_inode_bitmap_loc(),
ext2fs_inode_table_loc(), ext2fs_bg_itable_unused(),
ext2fs_block_bitmap_loc_set(), ext2fs_inode_bitmap_loc_set(),
ext2fs_inode_table_loc_set(), ext2fs_bg_free_inodes_count(),
ext2fs_ext2fs_bg_used_dirs_count(), ext2fs_bg_free_inodes_count_set(),
ext2fs_bg_free_blocks_count_set(), ext2fs_bg_used_dirs_count_set()
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com>
Signed-off-by: Nick Dokos <nicholas.dokos@hp.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-26 09:43:47 +08:00
|
|
|
blk = ext2fs_inode_table_loc(fs, i);
|
2009-09-08 09:14:24 +08:00
|
|
|
retval = io_channel_read_blk64(fs->io, blk,
|
2007-08-13 18:26:24 +08:00
|
|
|
fs->inode_blocks_per_group, old_itable);
|
|
|
|
if (retval)
|
|
|
|
goto err_out;
|
|
|
|
|
|
|
|
for (j = 0; j < EXT2_INODES_PER_GROUP(fs->super); j++) {
|
2008-06-07 23:51:33 +08:00
|
|
|
memcpy(new_itable, old_itable, old_ino_size);
|
2007-08-13 18:26:24 +08:00
|
|
|
|
2008-06-07 23:51:33 +08:00
|
|
|
memset(new_itable+old_ino_size, 0,
|
|
|
|
new_ino_size - old_ino_size);
|
2007-08-13 18:26:24 +08:00
|
|
|
|
2008-06-07 23:51:33 +08:00
|
|
|
new_itable += new_ino_size;
|
|
|
|
old_itable += old_ino_size;
|
2007-08-13 18:26:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* reset the pointer */
|
|
|
|
old_itable = tmp_old_itable;
|
|
|
|
new_itable = tmp_new_itable;
|
|
|
|
|
2009-09-08 09:14:24 +08:00
|
|
|
retval = io_channel_write_blk64(fs->io, blk,
|
2007-08-13 18:26:24 +08:00
|
|
|
new_ino_blks_per_grp, new_itable);
|
|
|
|
if (retval)
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update the meta data */
|
|
|
|
fs->inode_blocks_per_group = new_ino_blks_per_grp;
|
tune2fs: fix memory write overflow
If we apply this patch 'e2fsprogs/tune2fs: rewrite metadata checksums
when resizing inode size', we will trigger a segfault, this is because
of the inode cache issues.
Firstly we should notice that in expand_inode_table(), we have change
the super block's s_inode_size to new inode size(for example, 256).
Then we re-compute metadata checksums, see below code flow:
|-->rewrite_metadata_checksums
|----->rewrite_inodes
|-------->ext2fs_write_inode_full
In ext2fs_write_inode_full(), if an inode cache is hit, the below code will be executed:
/* Check to see if the inode cache needs to be updated */
if (fs->icache) {
for (i=0; i < fs->icache->cache_size; i++) {
if (fs->icache->cache[i].ino == ino) {
memcpy(fs->icache->cache[i].inode, inode,
(bufsize > length) ? length : bufsize);
break;
}
}
}
Before executing rewrite_inodes(), actually the inode in inode cache
is allocated by old inode size(for example, 128), but here the memcpy
will obviously write overflow, '(bufsize > length) ? length : bufsize'
here will return 256(new inode size), so this is wrong, we need to fix
this. I think we should call ext2fs_free_inode_cache() in
expand_inode_table(), to drop the inode cache, because inode size has
changed, if necessary, we will re-create this inode cache.
Steps to reproduce this bug (apply 'tune2fs: rewrite metadata checksums
when resizing inode size' first):
dd if=/dev/zero of=file.img bs=1M count=128
device_name=$(/sbin/losetup -f)
/sbin/losetup -f file.img
mkfs.ext4 -I 128 -O ^flex_bg $device_name
tune2fs -I 256 $device_name
Signed-off-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-12-03 11:31:11 +08:00
|
|
|
ext2fs_free_inode_cache(fs->icache);
|
|
|
|
fs->icache = 0;
|
2008-06-07 23:51:33 +08:00
|
|
|
fs->super->s_inode_size = new_ino_size;
|
2007-08-13 18:26:24 +08:00
|
|
|
|
|
|
|
err_out:
|
|
|
|
if (old_itable)
|
|
|
|
ext2fs_free_mem(&old_itable);
|
|
|
|
|
|
|
|
if (new_itable)
|
|
|
|
ext2fs_free_mem(&new_itable);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs)
|
|
|
|
{
|
2010-06-14 04:00:00 +08:00
|
|
|
blk64_t blk;
|
2007-08-13 18:26:24 +08:00
|
|
|
ext2_ino_t ino;
|
|
|
|
unsigned int group = 0;
|
|
|
|
unsigned int count = 0;
|
|
|
|
int total_free = 0;
|
|
|
|
int group_free = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First calculate the block statistics
|
|
|
|
*/
|
|
|
|
for (blk = fs->super->s_first_data_block;
|
2009-09-08 08:46:34 +08:00
|
|
|
blk < ext2fs_blocks_count(fs->super); blk++) {
|
2009-08-23 09:15:30 +08:00
|
|
|
if (!ext2fs_fast_test_block_bitmap2(fs->block_map, blk)) {
|
2007-08-13 18:26:24 +08:00
|
|
|
group_free++;
|
|
|
|
total_free++;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
if ((count == fs->super->s_blocks_per_group) ||
|
2009-09-08 08:46:34 +08:00
|
|
|
(blk == ext2fs_blocks_count(fs->super)-1)) {
|
Convert to use block group accessor functions
Convert direct accesses to use the following block group accessor
functions: ext2fs_block_bitmap_loc(), ext2fs_inode_bitmap_loc(),
ext2fs_inode_table_loc(), ext2fs_bg_itable_unused(),
ext2fs_block_bitmap_loc_set(), ext2fs_inode_bitmap_loc_set(),
ext2fs_inode_table_loc_set(), ext2fs_bg_free_inodes_count(),
ext2fs_ext2fs_bg_used_dirs_count(), ext2fs_bg_free_inodes_count_set(),
ext2fs_bg_free_blocks_count_set(), ext2fs_bg_used_dirs_count_set()
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com>
Signed-off-by: Nick Dokos <nicholas.dokos@hp.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-26 09:43:47 +08:00
|
|
|
ext2fs_bg_free_blocks_count_set(fs, group++,
|
|
|
|
group_free);
|
2007-08-13 18:26:24 +08:00
|
|
|
count = 0;
|
|
|
|
group_free = 0;
|
|
|
|
}
|
|
|
|
}
|
2011-06-16 13:38:43 +08:00
|
|
|
total_free = EXT2FS_C2B(fs, total_free);
|
2009-09-08 08:46:34 +08:00
|
|
|
ext2fs_free_blocks_count_set(fs->super, total_free);
|
2007-08-13 18:26:24 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Next, calculate the inode statistics
|
|
|
|
*/
|
|
|
|
group_free = 0;
|
|
|
|
total_free = 0;
|
|
|
|
count = 0;
|
|
|
|
group = 0;
|
|
|
|
|
|
|
|
/* Protect loop from wrap-around if s_inodes_count maxed */
|
|
|
|
for (ino = 1; ino <= fs->super->s_inodes_count && ino > 0; ino++) {
|
2009-08-23 09:15:30 +08:00
|
|
|
if (!ext2fs_fast_test_inode_bitmap2(fs->inode_map, ino)) {
|
2007-08-13 18:26:24 +08:00
|
|
|
group_free++;
|
|
|
|
total_free++;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
if ((count == fs->super->s_inodes_per_group) ||
|
|
|
|
(ino == fs->super->s_inodes_count)) {
|
Convert to use block group accessor functions
Convert direct accesses to use the following block group accessor
functions: ext2fs_block_bitmap_loc(), ext2fs_inode_bitmap_loc(),
ext2fs_inode_table_loc(), ext2fs_bg_itable_unused(),
ext2fs_block_bitmap_loc_set(), ext2fs_inode_bitmap_loc_set(),
ext2fs_inode_table_loc_set(), ext2fs_bg_free_inodes_count(),
ext2fs_ext2fs_bg_used_dirs_count(), ext2fs_bg_free_inodes_count_set(),
ext2fs_bg_free_blocks_count_set(), ext2fs_bg_used_dirs_count_set()
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com>
Signed-off-by: Nick Dokos <nicholas.dokos@hp.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-26 09:43:47 +08:00
|
|
|
ext2fs_bg_free_inodes_count_set(fs, group++,
|
|
|
|
group_free);
|
2007-08-13 18:26:24 +08:00
|
|
|
count = 0;
|
|
|
|
group_free = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fs->super->s_free_inodes_count = total_free;
|
|
|
|
ext2fs_mark_super_dirty(fs);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define list_for_each_safe(pos, pnext, head) \
|
|
|
|
for (pos = (head)->next, pnext = pos->next; pos != (head); \
|
|
|
|
pos = pnext, pnext = pos->next)
|
|
|
|
|
2008-06-07 23:51:33 +08:00
|
|
|
static void free_blk_move_list(void)
|
2007-08-13 18:26:24 +08:00
|
|
|
{
|
|
|
|
struct list_head *entry, *tmp;
|
|
|
|
struct blk_move *bmv;
|
|
|
|
|
|
|
|
list_for_each_safe(entry, tmp, &blk_move_list) {
|
|
|
|
bmv = list_entry(entry, struct blk_move, list);
|
|
|
|
list_del(entry);
|
|
|
|
ext2fs_free_mem(&bmv);
|
|
|
|
}
|
2009-01-21 00:49:17 +08:00
|
|
|
return;
|
2007-08-13 18:26:24 +08:00
|
|
|
}
|
2008-06-07 23:51:33 +08:00
|
|
|
|
|
|
|
static int resize_inode(ext2_filsys fs, unsigned long new_size)
|
2007-08-13 18:26:24 +08:00
|
|
|
{
|
|
|
|
errcode_t retval;
|
|
|
|
int new_ino_blks_per_grp;
|
2009-08-06 14:12:29 +08:00
|
|
|
ext2fs_block_bitmap bmap;
|
2007-08-13 18:26:24 +08:00
|
|
|
|
2011-09-17 04:49:37 +08:00
|
|
|
retval = ext2fs_read_inode_bitmap(fs);
|
|
|
|
if (retval) {
|
|
|
|
fputs(_("Failed to read inode bitmap\n"), stderr);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
retval = ext2fs_read_block_bitmap(fs);
|
|
|
|
if (retval) {
|
2011-10-10 05:08:47 +08:00
|
|
|
fputs(_("Failed to read block bitmap\n"), stderr);
|
2011-09-17 04:49:37 +08:00
|
|
|
return retval;
|
|
|
|
}
|
2007-08-13 18:26:24 +08:00
|
|
|
INIT_LIST_HEAD(&blk_move_list);
|
|
|
|
|
|
|
|
|
|
|
|
new_ino_blks_per_grp = ext2fs_div_ceil(
|
|
|
|
EXT2_INODES_PER_GROUP(fs->super)*
|
2008-06-07 23:51:33 +08:00
|
|
|
new_size,
|
2007-08-13 18:26:24 +08:00
|
|
|
fs->blocksize);
|
|
|
|
|
|
|
|
/* We may change the file system.
|
|
|
|
* Mark the file system as invalid so that
|
|
|
|
* the user is prompted to run fsck.
|
|
|
|
*/
|
|
|
|
fs->super->s_state &= ~EXT2_VALID_FS;
|
|
|
|
|
|
|
|
retval = ext2fs_allocate_block_bitmap(fs, _("blocks to be moved"),
|
|
|
|
&bmap);
|
2009-08-06 14:12:29 +08:00
|
|
|
if (retval) {
|
|
|
|
fputs(_("Failed to allocate block bitmap when "
|
|
|
|
"increasing inode size\n"), stderr);
|
2009-01-21 00:49:17 +08:00
|
|
|
return retval;
|
2009-08-06 14:12:29 +08:00
|
|
|
}
|
|
|
|
retval = get_move_bitmaps(fs, new_ino_blks_per_grp, bmap);
|
|
|
|
if (retval) {
|
|
|
|
fputs(_("Not enough space to increase inode size \n"), stderr);
|
2007-08-13 18:26:24 +08:00
|
|
|
goto err_out;
|
2009-08-06 14:12:29 +08:00
|
|
|
}
|
|
|
|
retval = move_block(fs, bmap);
|
|
|
|
if (retval) {
|
|
|
|
fputs(_("Failed to relocate blocks during inode resize \n"),
|
|
|
|
stderr);
|
2007-08-13 18:26:24 +08:00
|
|
|
goto err_out;
|
2009-08-06 14:12:29 +08:00
|
|
|
}
|
2008-11-15 13:32:39 +08:00
|
|
|
retval = inode_scan_and_fix(fs, bmap);
|
2007-08-13 18:26:24 +08:00
|
|
|
if (retval)
|
2009-08-06 14:12:29 +08:00
|
|
|
goto err_out_undo;
|
2009-01-21 00:49:17 +08:00
|
|
|
|
2009-08-06 14:12:30 +08:00
|
|
|
retval = group_desc_scan_and_fix(fs, bmap);
|
|
|
|
if (retval)
|
|
|
|
goto err_out_undo;
|
|
|
|
|
2008-06-07 23:51:33 +08:00
|
|
|
retval = expand_inode_table(fs, new_size);
|
2007-08-13 18:26:24 +08:00
|
|
|
if (retval)
|
2009-08-06 14:12:29 +08:00
|
|
|
goto err_out_undo;
|
2007-08-13 18:26:24 +08:00
|
|
|
|
|
|
|
ext2fs_calculate_summary_stats(fs);
|
|
|
|
|
|
|
|
fs->super->s_state |= EXT2_VALID_FS;
|
|
|
|
/* mark super block and block bitmap as dirty */
|
|
|
|
ext2fs_mark_super_dirty(fs);
|
|
|
|
ext2fs_mark_bb_dirty(fs);
|
|
|
|
|
|
|
|
err_out:
|
|
|
|
free_blk_move_list();
|
|
|
|
ext2fs_free_block_bitmap(bmap);
|
|
|
|
|
|
|
|
return retval;
|
2009-08-06 14:12:29 +08:00
|
|
|
|
|
|
|
err_out_undo:
|
|
|
|
free_blk_move_list();
|
|
|
|
ext2fs_free_block_bitmap(bmap);
|
|
|
|
fputs(_("Error in resizing the inode size.\n"
|
|
|
|
"Run e2undo to undo the "
|
|
|
|
"file system changes. \n"), stderr);
|
|
|
|
|
|
|
|
return retval;
|
2007-08-13 18:26:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int tune2fs_setup_tdb(const char *name, io_manager *io_ptr)
|
|
|
|
{
|
|
|
|
errcode_t retval = 0;
|
2008-06-07 23:51:33 +08:00
|
|
|
const char *tdb_dir;
|
2015-05-17 08:19:52 +08:00
|
|
|
char *tdb_file = NULL;
|
2008-06-07 23:51:33 +08:00
|
|
|
char *dev_name, *tmp_name;
|
2007-08-13 18:26:24 +08:00
|
|
|
|
2015-05-05 22:41:08 +08:00
|
|
|
/* (re)open a specific undo file */
|
|
|
|
if (undo_file && undo_file[0] != 0) {
|
2015-05-17 08:19:52 +08:00
|
|
|
retval = set_undo_io_backing_manager(*io_ptr);
|
|
|
|
if (retval)
|
|
|
|
goto err;
|
2015-05-05 22:41:08 +08:00
|
|
|
*io_ptr = undo_io_manager;
|
2015-05-17 08:19:52 +08:00
|
|
|
retval = set_undo_io_backup_file(undo_file);
|
|
|
|
if (retval)
|
|
|
|
goto err;
|
|
|
|
printf(_("Overwriting existing filesystem; this can be undone "
|
|
|
|
"using the command:\n"
|
|
|
|
" e2undo %s %s\n\n"),
|
2015-05-05 22:41:08 +08:00
|
|
|
undo_file, name);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2007-08-13 18:26:24 +08:00
|
|
|
/*
|
|
|
|
* Configuration via a conf file would be
|
|
|
|
* nice
|
|
|
|
*/
|
|
|
|
tdb_dir = getenv("E2FSPROGS_UNDO_DIR");
|
|
|
|
if (!tdb_dir)
|
2009-01-20 15:34:39 +08:00
|
|
|
tdb_dir = "/var/lib/e2fsprogs";
|
2007-08-13 18:26:24 +08:00
|
|
|
|
|
|
|
if (!strcmp(tdb_dir, "none") || (tdb_dir[0] == 0) ||
|
|
|
|
access(tdb_dir, W_OK))
|
|
|
|
return 0;
|
|
|
|
|
2015-05-17 08:19:52 +08:00
|
|
|
tmp_name = strdup(name);
|
|
|
|
if (!tmp_name)
|
|
|
|
goto errout;
|
|
|
|
dev_name = basename(tmp_name);
|
2009-04-18 22:53:32 +08:00
|
|
|
tdb_file = malloc(strlen(tdb_dir) + 9 + strlen(dev_name) + 7 + 1);
|
2015-05-17 08:19:52 +08:00
|
|
|
if (!tdb_file) {
|
|
|
|
free(tmp_name);
|
|
|
|
goto errout;
|
|
|
|
}
|
2008-06-07 23:51:33 +08:00
|
|
|
sprintf(tdb_file, "%s/tune2fs-%s.e2undo", tdb_dir, dev_name);
|
2015-05-17 08:19:52 +08:00
|
|
|
free(tmp_name);
|
2007-08-13 18:26:24 +08:00
|
|
|
|
2014-01-11 10:39:27 +08:00
|
|
|
if ((unlink(tdb_file) < 0) && (errno != ENOENT)) {
|
|
|
|
retval = errno;
|
|
|
|
com_err(program_name, retval,
|
|
|
|
_("while trying to delete %s"), tdb_file);
|
2015-05-17 08:19:52 +08:00
|
|
|
goto errout;
|
2007-08-13 18:26:24 +08:00
|
|
|
}
|
|
|
|
|
2015-05-17 08:19:52 +08:00
|
|
|
retval = set_undo_io_backing_manager(*io_ptr);
|
|
|
|
if (retval)
|
|
|
|
goto errout;
|
2007-08-13 18:26:24 +08:00
|
|
|
*io_ptr = undo_io_manager;
|
2015-05-17 08:19:52 +08:00
|
|
|
retval = set_undo_io_backup_file(tdb_file);
|
|
|
|
if (retval)
|
|
|
|
goto errout;
|
|
|
|
printf(_("Overwriting existing filesystem; this can be undone "
|
|
|
|
"using the command:\n"
|
|
|
|
" e2undo %s %s\n\n"),
|
2007-08-13 18:26:24 +08:00
|
|
|
tdb_file, name);
|
2015-05-17 08:19:52 +08:00
|
|
|
|
2009-04-18 22:53:32 +08:00
|
|
|
free(tdb_file);
|
2015-05-17 08:19:52 +08:00
|
|
|
return 0;
|
|
|
|
errout:
|
|
|
|
free(tdb_file);
|
|
|
|
err:
|
|
|
|
com_err("tune2fs", retval, "while trying to setup undo file\n");
|
2007-08-13 18:26:24 +08:00
|
|
|
return retval;
|
|
|
|
}
|
2001-01-09 08:16:26 +08:00
|
|
|
|
2015-07-14 01:23:28 +08:00
|
|
|
static int
|
2014-07-30 07:30:39 +08:00
|
|
|
fs_update_journal_user(struct ext2_super_block *sb, __u8 old_uuid[UUID_SIZE])
|
2014-07-28 15:43:25 +08:00
|
|
|
{
|
|
|
|
int retval, nr_users, start;
|
|
|
|
journal_superblock_t *jsb;
|
|
|
|
ext2_filsys jfs;
|
2014-07-30 07:30:39 +08:00
|
|
|
__u8 *j_uuid;
|
|
|
|
char *journal_path;
|
2014-07-28 15:43:25 +08:00
|
|
|
char uuid[UUID_STR_SIZE];
|
2015-05-23 06:40:51 +08:00
|
|
|
char buf[SUPERBLOCK_SIZE] __attribute__ ((aligned(8)));
|
2014-07-28 15:43:25 +08:00
|
|
|
|
2015-10-24 13:23:01 +08:00
|
|
|
if (!ext2fs_has_feature_journal(sb) || uuid_is_null(sb->s_journal_uuid))
|
2014-07-28 15:43:25 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
uuid_unparse(sb->s_journal_uuid, uuid);
|
|
|
|
journal_path = blkid_get_devname(NULL, "UUID", uuid);
|
|
|
|
if (!journal_path)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
retval = ext2fs_open2(journal_path, io_options,
|
|
|
|
EXT2_FLAG_JOURNAL_DEV_OK | EXT2_FLAG_RW,
|
|
|
|
0, 0, unix_io_manager, &jfs);
|
|
|
|
if (retval) {
|
|
|
|
com_err(program_name, retval,
|
|
|
|
_("while trying to open %s"),
|
|
|
|
journal_path);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2014-07-30 07:30:39 +08:00
|
|
|
retval = get_journal_sb(jfs, buf);
|
|
|
|
if (retval != 0) {
|
2014-07-28 15:43:25 +08:00
|
|
|
if (retval == EXT2_ET_UNSUPP_FEATURE)
|
|
|
|
fprintf(stderr, _("%s is not a journal device.\n"),
|
|
|
|
journal_path);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
jsb = (journal_superblock_t *) buf;
|
|
|
|
/* Find the filesystem UUID */
|
|
|
|
nr_users = ntohl(jsb->s_nr_users);
|
|
|
|
|
2014-07-30 07:30:39 +08:00
|
|
|
j_uuid = journal_user(old_uuid, jsb->s_users, nr_users);
|
|
|
|
if (j_uuid == NULL) {
|
2014-07-28 15:43:25 +08:00
|
|
|
fputs(_("Filesystem's UUID not found on journal device.\n"),
|
|
|
|
stderr);
|
|
|
|
return EXT2_ET_LOAD_EXT_JOURNAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(j_uuid, sb->s_uuid, UUID_SIZE);
|
|
|
|
|
|
|
|
start = ext2fs_journal_sb_start(jfs->blocksize);
|
|
|
|
/* Write back the journal superblock */
|
2014-07-30 07:30:39 +08:00
|
|
|
retval = io_channel_write_blk64(jfs->io, start, -SUPERBLOCK_SIZE, buf);
|
|
|
|
if (retval != 0) {
|
2014-07-28 15:43:25 +08:00
|
|
|
com_err(program_name, retval,
|
|
|
|
"while writing journal superblock.");
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
ext2fs_close(jfs);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-13 05:39:26 +08:00
|
|
|
#ifndef BUILD_AS_LIB
|
2009-01-20 15:34:39 +08:00
|
|
|
int main(int argc, char **argv)
|
2015-07-13 05:39:26 +08:00
|
|
|
#else
|
|
|
|
int tune2fs_main(int argc, char **argv)
|
|
|
|
#endif /* BUILD_AS_LIB */
|
2001-01-09 08:16:26 +08:00
|
|
|
{
|
|
|
|
errcode_t retval;
|
|
|
|
ext2_filsys fs;
|
|
|
|
struct ext2_super_block *sb;
|
2008-07-28 04:00:48 +08:00
|
|
|
io_manager io_ptr, io_ptr_orig = NULL;
|
2011-09-25 01:48:55 +08:00
|
|
|
int rc = 0;
|
2015-07-14 01:23:28 +08:00
|
|
|
char default_undo_file[1] = { 0 };
|
2001-01-09 08:16:26 +08:00
|
|
|
|
|
|
|
#ifdef ENABLE_NLS
|
|
|
|
setlocale(LC_MESSAGES, "");
|
2002-03-05 16:26:52 +08:00
|
|
|
setlocale(LC_CTYPE, "");
|
2001-01-09 08:16:26 +08:00
|
|
|
bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
|
|
|
|
textdomain(NLS_CAT_NAME);
|
2011-10-05 13:00:30 +08:00
|
|
|
set_com_err_gettext(gettext);
|
2001-01-09 08:16:26 +08:00
|
|
|
#endif
|
|
|
|
if (argc && *argv)
|
|
|
|
program_name = *argv;
|
2006-12-26 16:38:07 +08:00
|
|
|
add_error_table(&et_ext2_error_table);
|
2001-01-09 08:16:26 +08:00
|
|
|
|
2009-04-22 21:18:30 +08:00
|
|
|
#ifdef CONFIG_BUILD_FINDFS
|
2002-08-18 11:01:22 +08:00
|
|
|
if (strcmp(get_progname(argv[0]), "findfs") == 0)
|
|
|
|
do_findfs(argc, argv);
|
2009-04-22 21:18:30 +08:00
|
|
|
#endif
|
2001-01-09 08:16:26 +08:00
|
|
|
if (strcmp(get_progname(argv[0]), "e2label") == 0)
|
|
|
|
parse_e2label_options(argc, argv);
|
|
|
|
else
|
|
|
|
parse_tune2fs_options(argc, argv);
|
2008-08-28 11:07:54 +08:00
|
|
|
|
2003-05-06 00:08:47 +08:00
|
|
|
#ifdef CONFIG_TESTIO_DEBUG
|
2008-09-01 23:17:29 +08:00
|
|
|
if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_DEBUG")) {
|
|
|
|
io_ptr = test_io_manager;
|
|
|
|
test_io_backing_manager = unix_io_manager;
|
|
|
|
} else
|
2003-05-06 00:08:47 +08:00
|
|
|
#endif
|
2008-09-01 23:17:29 +08:00
|
|
|
io_ptr = unix_io_manager;
|
2007-08-13 18:26:24 +08:00
|
|
|
|
2008-07-28 04:00:48 +08:00
|
|
|
retry_open:
|
2011-09-25 01:48:55 +08:00
|
|
|
if ((open_flag & EXT2_FLAG_RW) == 0 || f_flag)
|
|
|
|
open_flag |= EXT2_FLAG_SKIP_MMP;
|
|
|
|
|
2014-09-09 07:12:21 +08:00
|
|
|
open_flag |= EXT2_FLAG_64BITS | EXT2_FLAG_JOURNAL_DEV_OK;
|
2011-09-25 01:48:55 +08:00
|
|
|
|
|
|
|
/* keep the filesystem struct around to dump MMP data */
|
|
|
|
open_flag |= EXT2_FLAG_NOFREE_ON_ERROR;
|
|
|
|
|
2008-08-28 11:07:54 +08:00
|
|
|
retval = ext2fs_open2(device_name, io_options, open_flag,
|
2004-12-01 03:07:11 +08:00
|
|
|
0, 0, io_ptr, &fs);
|
2009-01-20 15:34:39 +08:00
|
|
|
if (retval) {
|
2011-09-25 01:48:55 +08:00
|
|
|
com_err(program_name, retval,
|
|
|
|
_("while trying to open %s"),
|
2009-01-20 15:34:39 +08:00
|
|
|
device_name);
|
2011-09-25 01:48:55 +08:00
|
|
|
if (retval == EXT2_ET_MMP_FSCK_ON ||
|
|
|
|
retval == EXT2_ET_MMP_UNKNOWN_SEQ)
|
|
|
|
dump_mmp_msg(fs->mmp_buf,
|
|
|
|
_("If you are sure the filesystem "
|
|
|
|
"is not in use on any node, run:\n"
|
|
|
|
"'tune2fs -f -E clear_mmp {device}'\n"));
|
|
|
|
else if (retval == EXT2_ET_MMP_FAILED)
|
|
|
|
dump_mmp_msg(fs->mmp_buf, NULL);
|
|
|
|
else if (retval == EXT2_ET_MMP_MAGIC_INVALID)
|
|
|
|
fprintf(stderr,
|
|
|
|
_("MMP block magic is bad. Try to fix it by "
|
|
|
|
"running:\n'e2fsck -f %s'\n"), device_name);
|
2014-09-14 06:12:39 +08:00
|
|
|
else if (retval == EXT2_ET_BAD_MAGIC)
|
|
|
|
check_plausibility(device_name, CHECK_FS_EXIST, NULL);
|
2011-09-25 01:48:55 +08:00
|
|
|
else if (retval != EXT2_ET_MMP_FAILED)
|
2013-12-16 11:11:40 +08:00
|
|
|
fprintf(stderr, "%s",
|
2011-09-25 01:48:55 +08:00
|
|
|
_("Couldn't find valid filesystem superblock.\n"));
|
|
|
|
|
|
|
|
ext2fs_free(fs);
|
1997-04-26 21:21:57 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
2015-10-24 13:23:01 +08:00
|
|
|
if (ext2fs_has_feature_journal_dev(fs->super)) {
|
2014-09-09 07:12:21 +08:00
|
|
|
fprintf(stderr, "%s", _("Cannot modify a journal device.\n"));
|
|
|
|
ext2fs_free(fs);
|
|
|
|
exit(1);
|
|
|
|
}
|
2012-03-16 04:39:56 +08:00
|
|
|
fs->default_bitmap_type = EXT2FS_BMAP64_RBTREE;
|
2008-07-28 04:00:48 +08:00
|
|
|
|
2015-05-05 22:41:08 +08:00
|
|
|
if (I_flag) {
|
2008-07-28 04:00:48 +08:00
|
|
|
/*
|
|
|
|
* 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)) {
|
2009-04-23 03:13:37 +08:00
|
|
|
fprintf(stderr, _("The inode size is already %lu\n"),
|
2008-07-28 04:00:48 +08:00
|
|
|
new_inode_size);
|
2011-09-25 01:48:55 +08:00
|
|
|
rc = 1;
|
|
|
|
goto closefs;
|
2008-07-28 04:00:48 +08:00
|
|
|
}
|
|
|
|
if (new_inode_size < EXT2_INODE_SIZE(fs->super)) {
|
2013-12-16 11:11:40 +08:00
|
|
|
fprintf(stderr, "%s",
|
|
|
|
_("Shrinking inode size is not supported\n"));
|
2011-09-25 01:48:55 +08:00
|
|
|
rc = 1;
|
|
|
|
goto closefs;
|
2008-07-28 04:00:48 +08:00
|
|
|
}
|
2013-04-22 11:14:28 +08:00
|
|
|
if (new_inode_size > fs->blocksize) {
|
|
|
|
fprintf(stderr, _("Invalid inode size %lu (max %d)\n"),
|
|
|
|
new_inode_size, fs->blocksize);
|
|
|
|
rc = 1;
|
|
|
|
goto closefs;
|
2008-07-28 04:00:48 +08:00
|
|
|
}
|
2016-02-14 06:38:11 +08:00
|
|
|
check_fsck_needed(fs,
|
|
|
|
_("Resizing inodes could take some time."));
|
2008-07-28 04:00:48 +08:00
|
|
|
/*
|
|
|
|
* If inode resize is requested use the
|
|
|
|
* Undo I/O manager
|
|
|
|
*/
|
2015-07-14 01:23:28 +08:00
|
|
|
undo_file = default_undo_file;
|
2015-05-05 22:41:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up an undo file */
|
|
|
|
if (undo_file && io_ptr_orig == NULL) {
|
2008-07-28 04:00:48 +08:00
|
|
|
io_ptr_orig = io_ptr;
|
|
|
|
retval = tune2fs_setup_tdb(device_name, &io_ptr);
|
2011-09-25 01:48:55 +08:00
|
|
|
if (retval) {
|
|
|
|
rc = 1;
|
|
|
|
goto closefs;
|
|
|
|
}
|
2008-07-28 04:00:48 +08:00
|
|
|
if (io_ptr != io_ptr_orig) {
|
2014-07-06 09:06:29 +08:00
|
|
|
ext2fs_close_free(&fs);
|
2008-07-28 04:00:48 +08:00
|
|
|
goto retry_open;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-09 08:16:26 +08:00
|
|
|
sb = fs->super;
|
2007-06-19 06:26:50 +08:00
|
|
|
fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
|
2008-07-10 22:49:59 +08:00
|
|
|
|
2001-01-09 08:16:26 +08:00
|
|
|
if (print_label) {
|
|
|
|
/* For e2label emulation */
|
ChangeLog, e2image.c, mke2fs.c, mklost+found.c, tune2fs.c, util.c, uuidgen.c:
e2image.c, mke2fs.c, mklost+found.c, tune2fs.c, util.c, uuidgen.c: Fix
gcc -Wall complaints, including one bug in tune2fs caused by a block
automatic shadowing version of the variable we really wanted to use,
which broke the logic testing to see if the filesystem was mounted.
ChangeLog, MCONFIG.in:
(gcc-wall-new): Added new target which forgoes the make clean so we
only check the newly modified .c files.
2001-01-12 00:08:23 +08:00
|
|
|
printf("%.*s\n", (int) sizeof(sb->s_volume_name),
|
|
|
|
sb->s_volume_name);
|
2006-12-26 16:38:07 +08:00
|
|
|
remove_error_table(&et_ext2_error_table);
|
2011-09-25 01:48:55 +08:00
|
|
|
goto closefs;
|
2001-01-09 08:16:26 +08:00
|
|
|
}
|
2008-07-10 22:49:59 +08:00
|
|
|
|
2004-04-13 00:37:55 +08:00
|
|
|
retval = ext2fs_check_if_mounted(device_name, &mount_flags);
|
|
|
|
if (retval) {
|
|
|
|
com_err("ext2fs_check_if_mount", retval,
|
|
|
|
_("while determining whether %s is mounted."),
|
|
|
|
device_name);
|
2011-09-25 01:48:55 +08:00
|
|
|
rc = 1;
|
|
|
|
goto closefs;
|
2001-01-01 23:26:58 +08:00
|
|
|
}
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
/* Normally we only need to write out the superblock */
|
|
|
|
fs->flags |= EXT2_FLAG_SUPER_ONLY;
|
1997-04-26 21:21:57 +08:00
|
|
|
|
1997-04-29 22:53:37 +08:00
|
|
|
if (c_flag) {
|
2001-01-01 23:26:58 +08:00
|
|
|
sb->s_max_mnt_count = max_mount_count;
|
1997-04-26 21:21:57 +08:00
|
|
|
ext2fs_mark_super_dirty(fs);
|
2009-01-20 15:34:39 +08:00
|
|
|
printf(_("Setting maximal mount count to %d\n"),
|
|
|
|
max_mount_count);
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
1997-04-29 22:53:37 +08:00
|
|
|
if (C_flag) {
|
2001-01-01 23:26:58 +08:00
|
|
|
sb->s_mnt_count = mount_count;
|
1997-04-29 22:53:37 +08:00
|
|
|
ext2fs_mark_super_dirty(fs);
|
2009-01-20 15:34:39 +08:00
|
|
|
printf(_("Setting current mount count to %d\n"), mount_count);
|
1997-04-29 22:53:37 +08:00
|
|
|
}
|
|
|
|
if (e_flag) {
|
2001-01-01 23:26:58 +08:00
|
|
|
sb->s_errors = errors;
|
1997-04-26 21:21:57 +08:00
|
|
|
ext2fs_mark_super_dirty(fs);
|
2009-01-20 15:34:39 +08:00
|
|
|
printf(_("Setting error behavior to %d\n"), errors);
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
2001-01-01 23:26:58 +08:00
|
|
|
if (g_flag) {
|
|
|
|
sb->s_def_resgid = resgid;
|
1997-04-26 21:34:30 +08:00
|
|
|
ext2fs_mark_super_dirty(fs);
|
2009-01-20 15:34:39 +08:00
|
|
|
printf(_("Setting reserved blocks gid to %lu\n"), resgid);
|
1997-04-26 21:34:30 +08:00
|
|
|
}
|
ChangeLog, debugfs.8.in, debugfs.c:
Add a -V option which displays the current version.
ChangeLog, unix.c:
unix.c (e2fsck_update_progress): Remove unused variables.
ChangeLog, inode.c:
inode.c (get_next_blockgroup): Fix bug where if get_next_blockgroup()
is called early because of a missing inode table in a block group, the
current_inode counter wasn't incremented correctly.
ChangeLog, tst_uuid.c:
tst_uuid.c (main): Fixed bogus declaration of the main's argv parameter.
ChangeLog, test_icount.c:
test_icount.c (main): Fix main() declaration so that it returns int,
not void.
Many files:
fsck.c (ignore): Remove unused variable cp.
chattr.c (fatal_error):
tune2fs.c (usage):
lsattr.c (usage):
dumpe2fs.c (usage):
badblocks.c (usage): Remove volatile from declaration.
fsck.c: Change use of strdup to be string_copy, since we don't trust
what glibc is doing with strdup. (Whatever it is, it isn't pretty.)
1998-06-27 13:11:14 +08:00
|
|
|
if (i_flag) {
|
2014-04-15 00:20:25 +08:00
|
|
|
if ((unsigned long long)interval >= (1ULL << 32)) {
|
2011-04-19 04:11:39 +08:00
|
|
|
com_err(program_name, 0,
|
|
|
|
_("interval between checks is too big (%lu)"),
|
|
|
|
interval);
|
2011-09-25 01:48:55 +08:00
|
|
|
rc = 1;
|
|
|
|
goto closefs;
|
2011-04-19 04:11:39 +08:00
|
|
|
}
|
2001-01-01 23:26:58 +08:00
|
|
|
sb->s_checkinterval = interval;
|
1997-04-26 21:21:57 +08:00
|
|
|
ext2fs_mark_super_dirty(fs);
|
2009-01-20 15:34:39 +08:00
|
|
|
printf(_("Setting interval between checks to %lu seconds\n"),
|
|
|
|
interval);
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
ChangeLog, debugfs.8.in, debugfs.c:
Add a -V option which displays the current version.
ChangeLog, unix.c:
unix.c (e2fsck_update_progress): Remove unused variables.
ChangeLog, inode.c:
inode.c (get_next_blockgroup): Fix bug where if get_next_blockgroup()
is called early because of a missing inode table in a block group, the
current_inode counter wasn't incremented correctly.
ChangeLog, tst_uuid.c:
tst_uuid.c (main): Fixed bogus declaration of the main's argv parameter.
ChangeLog, test_icount.c:
test_icount.c (main): Fix main() declaration so that it returns int,
not void.
Many files:
fsck.c (ignore): Remove unused variable cp.
chattr.c (fatal_error):
tune2fs.c (usage):
lsattr.c (usage):
dumpe2fs.c (usage):
badblocks.c (usage): Remove volatile from declaration.
fsck.c: Change use of strdup to be string_copy, since we don't trust
what glibc is doing with strdup. (Whatever it is, it isn't pretty.)
1998-06-27 13:11:14 +08:00
|
|
|
if (m_flag) {
|
2009-09-08 08:46:34 +08:00
|
|
|
ext2fs_r_blocks_count_set(sb, reserved_ratio *
|
|
|
|
ext2fs_blocks_count(sb) / 100.0);
|
1997-04-26 21:21:57 +08:00
|
|
|
ext2fs_mark_super_dirty(fs);
|
2009-09-08 08:46:34 +08:00
|
|
|
printf (_("Setting reserved blocks percentage to %g%% (%llu blocks)\n"),
|
|
|
|
reserved_ratio, ext2fs_r_blocks_count(sb));
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|
ChangeLog, debugfs.8.in, debugfs.c:
Add a -V option which displays the current version.
ChangeLog, unix.c:
unix.c (e2fsck_update_progress): Remove unused variables.
ChangeLog, inode.c:
inode.c (get_next_blockgroup): Fix bug where if get_next_blockgroup()
is called early because of a missing inode table in a block group, the
current_inode counter wasn't incremented correctly.
ChangeLog, tst_uuid.c:
tst_uuid.c (main): Fixed bogus declaration of the main's argv parameter.
ChangeLog, test_icount.c:
test_icount.c (main): Fix main() declaration so that it returns int,
not void.
Many files:
fsck.c (ignore): Remove unused variable cp.
chattr.c (fatal_error):
tune2fs.c (usage):
lsattr.c (usage):
dumpe2fs.c (usage):
badblocks.c (usage): Remove volatile from declaration.
fsck.c: Change use of strdup to be string_copy, since we don't trust
what glibc is doing with strdup. (Whatever it is, it isn't pretty.)
1998-06-27 13:11:14 +08:00
|
|
|
if (r_flag) {
|
2011-06-01 08:08:58 +08:00
|
|
|
if (reserved_blocks > ext2fs_blocks_count(sb)/2) {
|
2009-01-20 15:34:39 +08:00
|
|
|
com_err(program_name, 0,
|
2009-09-08 08:46:34 +08:00
|
|
|
_("reserved blocks count is too big (%llu)"),
|
2009-01-20 15:34:39 +08:00
|
|
|
reserved_blocks);
|
2011-09-25 01:48:55 +08:00
|
|
|
rc = 1;
|
|
|
|
goto closefs;
|
1997-04-26 21:34:30 +08:00
|
|
|
}
|
2009-09-08 08:46:34 +08:00
|
|
|
ext2fs_r_blocks_count_set(sb, reserved_blocks);
|
1997-04-26 21:34:30 +08:00
|
|
|
ext2fs_mark_super_dirty(fs);
|
2009-09-08 08:46:34 +08:00
|
|
|
printf(_("Setting reserved blocks count to %llu\n"),
|
2009-01-20 15:34:39 +08:00
|
|
|
reserved_blocks);
|
1997-04-26 21:34:30 +08:00
|
|
|
}
|
1997-04-30 01:48:10 +08:00
|
|
|
if (s_flag == 1) {
|
2015-10-24 13:23:01 +08:00
|
|
|
if (ext2fs_has_feature_sparse_super(sb)) {
|
2003-12-07 14:28:50 +08:00
|
|
|
fputs(_("\nThe filesystem already has sparse "
|
|
|
|
"superblocks.\n"), stderr);
|
2015-10-24 13:23:01 +08:00
|
|
|
} else if (ext2fs_has_feature_meta_bg(sb)) {
|
2014-02-07 04:11:52 +08:00
|
|
|
fputs(_("\nSetting the sparse superblock flag not "
|
|
|
|
"supported\nfor filesystems with "
|
|
|
|
"the meta_bg feature enabled.\n"),
|
|
|
|
stderr);
|
|
|
|
rc = 1;
|
|
|
|
goto closefs;
|
|
|
|
} else {
|
2015-10-24 13:23:01 +08:00
|
|
|
ext2fs_set_feature_sparse_super(sb);
|
2001-01-01 23:26:58 +08:00
|
|
|
sb->s_state &= ~EXT2_VALID_FS;
|
1997-04-30 01:48:10 +08:00
|
|
|
ext2fs_mark_super_dirty(fs);
|
Many files:
badblocks.c, chattr.c, dumpe2fs.c, e2label.c, findsuper.c, fsck.c,
get_device_by_label.c, lsattr.c, mke2fs.c, mklost+found.c,
nls-enable.h, partinfo.c, tune2fs.c, uuidgen.c: Add
Internationalization support as suggested by Marco d'Itri
<md@linux.it>.
2000-02-08 08:47:55 +08:00
|
|
|
printf(_("\nSparse superblock flag set. %s"),
|
2000-02-09 05:35:41 +08:00
|
|
|
_(please_fsck));
|
1997-04-30 01:48:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (s_flag == 0) {
|
2014-02-07 04:11:52 +08:00
|
|
|
fputs(_("\nClearing the sparse superblock flag not supported.\n"),
|
2008-02-29 10:26:01 +08:00
|
|
|
stderr);
|
2011-09-25 01:48:55 +08:00
|
|
|
rc = 1;
|
|
|
|
goto closefs;
|
1997-04-30 01:48:10 +08:00
|
|
|
}
|
2001-12-26 21:58:01 +08:00
|
|
|
if (T_flag) {
|
|
|
|
sb->s_lastcheck = last_check_time;
|
|
|
|
ext2fs_mark_super_dirty(fs);
|
|
|
|
printf(_("Setting time filesystem last checked to %s\n"),
|
|
|
|
ctime(&last_check_time));
|
|
|
|
}
|
2001-01-01 23:26:58 +08:00
|
|
|
if (u_flag) {
|
|
|
|
sb->s_def_resuid = resuid;
|
1997-04-26 21:34:30 +08:00
|
|
|
ext2fs_mark_super_dirty(fs);
|
2009-01-20 15:34:39 +08:00
|
|
|
printf(_("Setting reserved blocks uid to %lu\n"), resuid);
|
1997-04-26 21:34:30 +08:00
|
|
|
}
|
1997-04-29 22:53:37 +08:00
|
|
|
if (L_flag) {
|
1998-03-30 09:20:55 +08:00
|
|
|
if (strlen(new_label) > sizeof(sb->s_volume_name))
|
2008-08-28 11:07:54 +08:00
|
|
|
fputs(_("Warning: label too long, truncating.\n"),
|
2003-12-07 14:28:50 +08:00
|
|
|
stderr);
|
1997-04-29 22:53:37 +08:00
|
|
|
memset(sb->s_volume_name, 0, sizeof(sb->s_volume_name));
|
|
|
|
strncpy(sb->s_volume_name, new_label,
|
|
|
|
sizeof(sb->s_volume_name));
|
|
|
|
ext2fs_mark_super_dirty(fs);
|
|
|
|
}
|
|
|
|
if (M_flag) {
|
|
|
|
memset(sb->s_last_mounted, 0, sizeof(sb->s_last_mounted));
|
|
|
|
strncpy(sb->s_last_mounted, new_last_mounted,
|
|
|
|
sizeof(sb->s_last_mounted));
|
|
|
|
ext2fs_mark_super_dirty(fs);
|
|
|
|
}
|
2011-09-25 01:48:55 +08:00
|
|
|
if (mntopts_cmd) {
|
|
|
|
rc = update_mntopts(fs, mntopts_cmd);
|
|
|
|
if (rc)
|
|
|
|
goto closefs;
|
|
|
|
}
|
|
|
|
if (features_cmd) {
|
|
|
|
rc = update_feature_set(fs, features_cmd);
|
|
|
|
if (rc)
|
|
|
|
goto closefs;
|
|
|
|
}
|
|
|
|
if (extended_cmd) {
|
|
|
|
rc = parse_extended_opts(fs, extended_cmd);
|
|
|
|
if (rc)
|
|
|
|
goto closefs;
|
|
|
|
if (clear_mmp && !f_flag) {
|
|
|
|
fputs(_("Error in using clear_mmp. "
|
|
|
|
"It must be used with -f\n"),
|
|
|
|
stderr);
|
|
|
|
goto closefs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (clear_mmp) {
|
|
|
|
rc = ext2fs_mmp_clear(fs);
|
|
|
|
goto closefs;
|
|
|
|
}
|
|
|
|
if (journal_size || journal_device) {
|
|
|
|
rc = add_journal(fs);
|
|
|
|
if (rc)
|
|
|
|
goto closefs;
|
|
|
|
}
|
2008-08-28 11:07:54 +08:00
|
|
|
|
2011-07-21 02:40:05 +08:00
|
|
|
if (Q_flag) {
|
|
|
|
if (mount_flags & EXT2_MF_MOUNTED) {
|
|
|
|
fputs(_("The quota feature may only be changed when "
|
|
|
|
"the filesystem is unmounted.\n"), stderr);
|
2011-09-25 01:48:55 +08:00
|
|
|
rc = 1;
|
|
|
|
goto closefs;
|
2011-07-21 02:40:05 +08:00
|
|
|
}
|
|
|
|
handle_quota_options(fs);
|
|
|
|
}
|
|
|
|
|
1997-04-29 22:53:37 +08:00
|
|
|
if (U_flag) {
|
2008-11-15 06:42:27 +08:00
|
|
|
int set_csum = 0;
|
|
|
|
dgrp_t i;
|
2015-05-23 06:40:51 +08:00
|
|
|
char buf[SUPERBLOCK_SIZE] __attribute__ ((aligned(8)));
|
2014-07-30 07:30:39 +08:00
|
|
|
__u8 old_uuid[UUID_SIZE];
|
2008-11-15 06:42:27 +08:00
|
|
|
|
2013-12-15 09:56:29 +08:00
|
|
|
if (ext2fs_has_group_desc_csum(fs)) {
|
2012-07-31 06:50:04 +08:00
|
|
|
/*
|
2016-03-06 01:38:52 +08:00
|
|
|
* Changing the UUID on a metadata_csum FS requires
|
|
|
|
* rewriting all metadata, which can race with a
|
|
|
|
* mounted fs. Don't allow that unless we're saving
|
|
|
|
* the checksum seed.
|
2012-07-31 06:50:04 +08:00
|
|
|
*/
|
2016-03-06 01:38:52 +08:00
|
|
|
if ((mount_flags & EXT2_MF_MOUNTED) &&
|
|
|
|
!ext2fs_has_feature_csum_seed(fs->super) &&
|
|
|
|
ext2fs_has_feature_metadata_csum(fs->super)) {
|
2012-07-31 06:50:04 +08:00
|
|
|
fputs(_("The UUID may only be "
|
|
|
|
"changed when the filesystem is "
|
|
|
|
"unmounted.\n"), stderr);
|
2016-03-06 01:38:52 +08:00
|
|
|
fputs(_("If you only use kernels newer than "
|
|
|
|
"v4.4, run 'tune2fs -O "
|
|
|
|
"metadata_csum_seed' and re-run this "
|
|
|
|
"command.\n"), stderr);
|
|
|
|
try_confirm_csum_seed_support();
|
2012-07-31 06:50:04 +08:00
|
|
|
exit(1);
|
|
|
|
}
|
2016-02-14 06:38:11 +08:00
|
|
|
if (!ext2fs_has_feature_csum_seed(fs->super))
|
|
|
|
check_fsck_needed(fs,
|
|
|
|
_("Setting UUID on a checksummed "
|
|
|
|
"filesystem could take some time."));
|
2012-07-31 06:50:04 +08:00
|
|
|
|
2009-01-20 15:34:39 +08:00
|
|
|
/*
|
2008-11-15 06:42:27 +08:00
|
|
|
* 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;
|
|
|
|
}
|
2014-07-28 15:43:25 +08:00
|
|
|
|
|
|
|
memcpy(old_uuid, sb->s_uuid, UUID_SIZE);
|
2001-04-24 04:58:03 +08:00
|
|
|
if ((strcasecmp(new_UUID, "null") == 0) ||
|
|
|
|
(strcasecmp(new_UUID, "clear") == 0)) {
|
1997-04-29 22:53:37 +08:00
|
|
|
uuid_clear(sb->s_uuid);
|
ChangeLog, Makefile.in, mke2fs.c, tune2fs.8.in, tune2fs.c, util.c, util.h:
tune2fs.c (update_feature_set, add_journal): Moved to separate
functions. Added ability to add and remove the journal while the
filesystem is live. Added support for setting a time-based UUID.
Removed zero-initialized static variables.
mke2fs.c, util.c, util.h (strcasecmp, proceed_question,
check_plausibility, parse_journal_opts, check_mount): Moved functions
to util.c so they can be used by tune2fs.
mke2fs.c (main): Change ext2fs_add_journal_fs() to
ext2fs_add_journal_inode() to reflect function renaming.
2001-01-04 01:02:13 +08:00
|
|
|
} else if (strcasecmp(new_UUID, "time") == 0) {
|
|
|
|
uuid_generate_time(sb->s_uuid);
|
1997-04-29 22:53:37 +08:00
|
|
|
} else if (strcasecmp(new_UUID, "random") == 0) {
|
|
|
|
uuid_generate(sb->s_uuid);
|
|
|
|
} else if (uuid_parse(new_UUID, sb->s_uuid)) {
|
2013-12-16 11:11:40 +08:00
|
|
|
com_err(program_name, 0, "%s",
|
|
|
|
_("Invalid UUID format\n"));
|
2011-09-25 01:48:55 +08:00
|
|
|
rc = 1;
|
|
|
|
goto closefs;
|
1997-04-29 22:53:37 +08:00
|
|
|
}
|
2012-07-31 06:50:04 +08:00
|
|
|
ext2fs_init_csum_seed(fs);
|
2008-11-15 06:42:27 +08:00
|
|
|
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;
|
|
|
|
}
|
2014-07-28 15:43:24 +08:00
|
|
|
|
|
|
|
/* If this is a journal dev, we need to copy UUID into jsb */
|
|
|
|
if (!(rc = get_journal_sb(fs, buf))) {
|
|
|
|
journal_superblock_t *jsb;
|
|
|
|
|
|
|
|
jsb = (journal_superblock_t *) buf;
|
|
|
|
fputs(_("Need to update journal superblock.\n"), stdout);
|
|
|
|
memcpy(jsb->s_uuid, sb->s_uuid, sizeof(sb->s_uuid));
|
|
|
|
|
|
|
|
/* Writeback the journal superblock */
|
|
|
|
if ((rc = io_channel_write_blk64(fs->io,
|
|
|
|
ext2fs_journal_sb_start(fs->blocksize),
|
|
|
|
-SUPERBLOCK_SIZE, buf)))
|
|
|
|
goto closefs;
|
|
|
|
} else if (rc != EXT2_ET_UNSUPP_FEATURE)
|
|
|
|
goto closefs;
|
2014-07-28 15:43:25 +08:00
|
|
|
else {
|
2014-07-28 15:43:24 +08:00
|
|
|
rc = 0; /** Reset rc to avoid ext2fs_mmp_stop() */
|
|
|
|
|
2014-07-28 15:43:25 +08:00
|
|
|
if ((rc = fs_update_journal_user(sb, old_uuid)))
|
|
|
|
goto closefs;
|
|
|
|
}
|
|
|
|
|
1997-04-29 22:53:37 +08:00
|
|
|
ext2fs_mark_super_dirty(fs);
|
2016-03-06 01:38:52 +08:00
|
|
|
if (ext2fs_has_feature_metadata_csum(fs->super) &&
|
|
|
|
!ext2fs_has_feature_csum_seed(fs->super))
|
2012-07-31 06:50:04 +08:00
|
|
|
rewrite_checksums = 1;
|
1997-04-29 22:53:37 +08:00
|
|
|
}
|
tune2fs: rewrite metadata checksums when resizing inode size
When we use tune2fs -I new_ino_size to change inode size, if
everything is OK, the corresponding ext4_group_desc.bg_free_blocks_count
will be decreased, so obviously, we need to re-compute the group
descriptor checksums, and the inode 's size has also changed, we also
need to recompute the checksums of inodes for metadata_csum
filesystem, so here we choose to call a rewrite_metadata_checksums(),
this will fix checksum issues.
Meanwhile, the patch will trigger an existing memory write overflow,
which will casue segfault, please see the next patch.
Signed-off-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-12-03 11:29:29 +08:00
|
|
|
|
2007-08-13 18:26:24 +08:00
|
|
|
if (I_flag) {
|
|
|
|
if (mount_flags & EXT2_MF_MOUNTED) {
|
|
|
|
fputs(_("The inode size may only be "
|
|
|
|
"changed when the filesystem is "
|
|
|
|
"unmounted.\n"), stderr);
|
2011-09-25 01:48:55 +08:00
|
|
|
rc = 1;
|
|
|
|
goto closefs;
|
2007-08-13 18:26:24 +08:00
|
|
|
}
|
2015-10-24 13:23:01 +08:00
|
|
|
if (ext2fs_has_feature_flex_bg(fs->super)) {
|
2009-01-20 15:34:39 +08:00
|
|
|
fputs(_("Changing the inode size not supported for "
|
|
|
|
"filesystems with the flex_bg\n"
|
|
|
|
"feature enabled.\n"),
|
2009-01-20 14:50:07 +08:00
|
|
|
stderr);
|
2011-09-25 01:48:55 +08:00
|
|
|
rc = 1;
|
|
|
|
goto closefs;
|
2009-01-20 14:50:07 +08:00
|
|
|
}
|
2007-08-13 18:26:24 +08:00
|
|
|
/*
|
|
|
|
* We want to update group descriptor also
|
|
|
|
* with the new free inode count
|
|
|
|
*/
|
2015-01-28 02:11:04 +08:00
|
|
|
if (rewrite_checksums)
|
|
|
|
fs->flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS;
|
2007-08-13 18:26:24 +08:00
|
|
|
fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
|
2015-01-28 02:11:04 +08:00
|
|
|
retval = resize_inode(fs, new_inode_size);
|
|
|
|
if (rewrite_checksums)
|
|
|
|
fs->flags &= ~EXT2_FLAG_IGNORE_CSUM_ERRORS;
|
|
|
|
if (retval == 0) {
|
2009-01-20 15:34:39 +08:00
|
|
|
printf(_("Setting inode size %lu\n"),
|
2007-08-13 18:26:24 +08:00
|
|
|
new_inode_size);
|
tune2fs: rewrite metadata checksums when resizing inode size
When we use tune2fs -I new_ino_size to change inode size, if
everything is OK, the corresponding ext4_group_desc.bg_free_blocks_count
will be decreased, so obviously, we need to re-compute the group
descriptor checksums, and the inode 's size has also changed, we also
need to recompute the checksums of inodes for metadata_csum
filesystem, so here we choose to call a rewrite_metadata_checksums(),
this will fix checksum issues.
Meanwhile, the patch will trigger an existing memory write overflow,
which will casue segfault, please see the next patch.
Signed-off-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-12-03 11:29:29 +08:00
|
|
|
rewrite_checksums = 1;
|
2011-09-17 04:49:37 +08:00
|
|
|
} else {
|
2013-12-16 11:11:40 +08:00
|
|
|
printf("%s", _("Failed to change inode size\n"));
|
2011-09-25 01:48:55 +08:00
|
|
|
rc = 1;
|
|
|
|
goto closefs;
|
2007-08-13 18:26:24 +08:00
|
|
|
}
|
|
|
|
}
|
1997-04-29 22:53:37 +08:00
|
|
|
|
tune2fs: rewrite metadata checksums when resizing inode size
When we use tune2fs -I new_ino_size to change inode size, if
everything is OK, the corresponding ext4_group_desc.bg_free_blocks_count
will be decreased, so obviously, we need to re-compute the group
descriptor checksums, and the inode 's size has also changed, we also
need to recompute the checksums of inodes for metadata_csum
filesystem, so here we choose to call a rewrite_metadata_checksums(),
this will fix checksum issues.
Meanwhile, the patch will trigger an existing memory write overflow,
which will casue segfault, please see the next patch.
Signed-off-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-12-03 11:29:29 +08:00
|
|
|
if (rewrite_checksums)
|
|
|
|
rewrite_metadata_checksums(fs);
|
|
|
|
|
1997-04-26 21:21:57 +08:00
|
|
|
if (l_flag)
|
2009-01-20 15:34:39 +08:00
|
|
|
list_super(sb);
|
2008-02-19 11:56:25 +08:00
|
|
|
if (stride_set) {
|
|
|
|
sb->s_raid_stride = stride;
|
|
|
|
ext2fs_mark_super_dirty(fs);
|
|
|
|
printf(_("Setting stride size to %d\n"), stride);
|
|
|
|
}
|
|
|
|
if (stripe_width_set) {
|
|
|
|
sb->s_raid_stripe_width = stripe_width;
|
|
|
|
ext2fs_mark_super_dirty(fs);
|
|
|
|
printf(_("Setting stripe width to %d\n"), stripe_width);
|
|
|
|
}
|
2011-07-05 08:14:35 +08:00
|
|
|
if (ext_mount_opts) {
|
2011-09-25 00:59:31 +08:00
|
|
|
strncpy((char *)(fs->super->s_mount_opts), ext_mount_opts,
|
2011-07-05 08:14:35 +08:00
|
|
|
sizeof(fs->super->s_mount_opts));
|
|
|
|
fs->super->s_mount_opts[sizeof(fs->super->s_mount_opts)-1] = 0;
|
|
|
|
ext2fs_mark_super_dirty(fs);
|
|
|
|
printf(_("Setting extended default mount options to '%s'\n"),
|
|
|
|
ext_mount_opts);
|
|
|
|
free(ext_mount_opts);
|
|
|
|
}
|
2015-12-01 01:13:39 +08:00
|
|
|
|
2016-03-19 04:07:34 +08:00
|
|
|
#ifdef NO_RECOVERY
|
|
|
|
/* Warn if file system needs recovery and it is opened for writing. */
|
|
|
|
if ((open_flag & EXT2_FLAG_RW) && !(mount_flags & EXT2_MF_MOUNTED) &&
|
|
|
|
(sb->s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL) &&
|
|
|
|
(sb->s_feature_incompat & EXT3_FEATURE_INCOMPAT_RECOVER)) {
|
|
|
|
fprintf(stderr,
|
|
|
|
_("Warning: The journal is dirty. You may wish to replay the journal like:\n\n"
|
|
|
|
"\te2fsck -E journal_only %s\n\n"
|
|
|
|
"then rerun this command. Otherwise, any changes made may be overwritten\n"
|
|
|
|
"by journal recovery.\n"), device_name);
|
|
|
|
}
|
|
|
|
#else
|
2016-02-14 06:38:17 +08:00
|
|
|
/* Recover the journal if possible. */
|
2015-12-01 01:13:39 +08:00
|
|
|
if ((open_flag & EXT2_FLAG_RW) && !(mount_flags & EXT2_MF_MOUNTED) &&
|
2016-02-14 06:38:17 +08:00
|
|
|
ext2fs_has_feature_journal_needs_recovery(fs->super)) {
|
|
|
|
errcode_t err;
|
|
|
|
|
|
|
|
printf(_("Recovering journal.\n"));
|
|
|
|
err = ext2fs_run_ext3_journal(&fs);
|
|
|
|
if (err) {
|
|
|
|
com_err("tune2fs", err, "while recovering journal.\n");
|
|
|
|
printf(_("Please run e2fsck -fy %s.\n"), argv[1]);
|
|
|
|
goto closefs;
|
|
|
|
}
|
|
|
|
ext2fs_clear_feature_journal_needs_recovery(fs->super);
|
|
|
|
ext2fs_mark_super_dirty(fs);
|
2015-12-01 01:13:39 +08:00
|
|
|
}
|
2016-03-19 04:07:34 +08:00
|
|
|
#endif
|
2015-12-01 01:13:39 +08:00
|
|
|
|
2009-06-15 15:53:04 +08:00
|
|
|
free(device_name);
|
2006-12-26 16:38:07 +08:00
|
|
|
remove_error_table(&et_ext2_error_table);
|
2011-09-25 01:48:55 +08:00
|
|
|
|
|
|
|
closefs:
|
|
|
|
if (rc) {
|
|
|
|
ext2fs_mmp_stop(fs);
|
2015-07-13 05:39:26 +08:00
|
|
|
#ifndef BUILD_AS_LIB
|
2011-09-25 01:48:55 +08:00
|
|
|
exit(1);
|
2015-07-13 05:39:26 +08:00
|
|
|
#endif
|
2011-09-25 01:48:55 +08:00
|
|
|
}
|
|
|
|
|
2015-01-28 02:11:47 +08:00
|
|
|
convert_64bit(fs, feature_64bit);
|
2014-07-06 09:06:29 +08:00
|
|
|
return (ext2fs_close_free(&fs) ? 1 : 0);
|
1997-04-26 21:21:57 +08:00
|
|
|
}
|