2 * tune2fs.c - Change the file system parameters on an ext2 file system
4 * Copyright (C) 1992, 1993, 1994 Remy Card <card@masi.ibp.fr>
5 * Laboratoire MASI, Institut Blaise Pascal
6 * Universite Pierre et Marie Curie (Paris VI)
8 * Copyright 1995, 1996, 1997, 1998, 1999, 2000 by Theodore Ts'o.
11 * This file may be redistributed under the terms of the GNU Public
19 * 93/10/31 - Added the -c option to change the maximal mount counts
20 * 93/12/14 - Added -l flag to list contents of superblock
21 * M.J.E. Mol (marcel@duteca.et.tudelft.nl)
22 * F.W. ten Wolde (franky@duteca.et.tudelft.nl)
23 * 93/12/29 - Added the -e option to change errors behavior
24 * 94/02/27 - Ported to use the ext2fs library
25 * 94/03/06 - Added the checks interval from Uwe Ohse (uwe@tirka.gun.de)
28 #define _XOPEN_SOURCE 600 /* for inclusion of strptime() */
29 #define _BSD_SOURCE /* for inclusion of strcasecmp() */
47 #include <sys/types.h>
51 #include "ext2fs/ext2_fs.h"
52 #include "ext2fs/ext2fs.h"
53 #include "et/com_err.h"
54 #include "uuid/uuid.h"
58 #include "blkid/blkid.h"
59 #include "quota/mkquota.h"
61 #include "../version.h"
62 #include "nls-enable.h"
64 #define QOPT_ENABLE (1)
65 #define QOPT_DISABLE (-1)
67 extern int ask_yn(const char *string, int def);
69 const char *program_name = "tune2fs";
71 char *new_label, *new_last_mounted, *new_UUID;
73 static int c_flag, C_flag, e_flag, f_flag, g_flag, i_flag, l_flag, L_flag;
74 static int m_flag, M_flag, Q_flag, r_flag, s_flag = -1, u_flag, U_flag, T_flag;
77 static time_t last_check_time;
78 static int print_label;
79 static int max_mount_count, mount_count, mount_flags;
80 static unsigned long interval;
81 static blk64_t reserved_blocks;
82 static double reserved_ratio;
83 static unsigned long resgid, resuid;
84 static unsigned short errors;
86 static char *features_cmd;
87 static char *mntopts_cmd;
88 static int stride, stripe_width;
89 static int stride_set, stripe_width_set;
90 static char *extended_cmd;
91 static unsigned long new_inode_size;
92 static char *ext_mount_opts;
93 static int usrquota, grpquota;
94 static int rewrite_checksums;
96 int journal_size, journal_flags;
99 static struct list_head blk_move_list;
102 struct list_head list;
108 static const char *please_fsck = N_("Please run e2fsck on the filesystem.\n");
109 static const char *please_dir_fsck =
110 N_("Please run e2fsck -D on the filesystem.\n");
112 #ifdef CONFIG_BUILD_FINDFS
113 void do_findfs(int argc, char **argv);
116 static void usage(void)
119 _("Usage: %s [-c max_mounts_count] [-e errors_behavior] "
121 "\t[-i interval[d|m|w]] [-j] [-J journal_options] [-l]\n"
122 "\t[-m reserved_blocks_percent] "
123 "[-o [^]mount_options[,...]] [-p mmp_update_interval]\n"
124 "\t[-r reserved_blocks_count] [-u user] [-C mount_count] "
125 "[-L volume_label]\n"
126 "\t[-M last_mounted_dir] [-O [^]feature[,...]]\n"
127 "\t[-E extended-option[,...]] [-T last_check_time] "
128 "[-U UUID]\n\t[ -I new_inode_size ] device\n"), program_name);
132 static __u32 ok_features[3] = {
134 EXT3_FEATURE_COMPAT_HAS_JOURNAL |
135 EXT2_FEATURE_COMPAT_DIR_INDEX,
137 EXT2_FEATURE_INCOMPAT_FILETYPE |
138 EXT3_FEATURE_INCOMPAT_EXTENTS |
139 EXT4_FEATURE_INCOMPAT_FLEX_BG |
140 EXT4_FEATURE_INCOMPAT_MMP,
142 EXT2_FEATURE_RO_COMPAT_LARGE_FILE |
143 EXT4_FEATURE_RO_COMPAT_HUGE_FILE|
144 EXT4_FEATURE_RO_COMPAT_DIR_NLINK|
145 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE|
146 EXT4_FEATURE_RO_COMPAT_GDT_CSUM |
147 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER |
149 EXT4_FEATURE_RO_COMPAT_QUOTA |
151 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM
154 static __u32 clear_ok_features[3] = {
156 EXT3_FEATURE_COMPAT_HAS_JOURNAL |
157 EXT2_FEATURE_COMPAT_RESIZE_INODE |
158 EXT2_FEATURE_COMPAT_DIR_INDEX,
160 EXT2_FEATURE_INCOMPAT_FILETYPE |
161 EXT4_FEATURE_INCOMPAT_FLEX_BG |
162 EXT4_FEATURE_INCOMPAT_MMP,
164 EXT2_FEATURE_RO_COMPAT_LARGE_FILE |
165 EXT4_FEATURE_RO_COMPAT_HUGE_FILE|
166 EXT4_FEATURE_RO_COMPAT_DIR_NLINK|
167 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE|
168 EXT4_FEATURE_RO_COMPAT_GDT_CSUM |
170 EXT4_FEATURE_RO_COMPAT_QUOTA |
172 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM
176 * Remove an external journal from the filesystem
178 static int remove_journal_device(ext2_filsys fs)
183 journal_superblock_t *jsb;
186 int commit_remove_journal = 0;
190 commit_remove_journal = 1; /* force removal even if error */
192 uuid_unparse(fs->super->s_journal_uuid, buf);
193 journal_path = blkid_get_devname(NULL, "UUID", buf);
197 ext2fs_find_block_device(fs->super->s_journal_dev);
199 goto no_valid_journal;
202 #ifdef CONFIG_TESTIO_DEBUG
203 if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) {
204 io_ptr = test_io_manager;
205 test_io_backing_manager = unix_io_manager;
208 io_ptr = unix_io_manager;
209 retval = ext2fs_open(journal_path, EXT2_FLAG_RW|
210 EXT2_FLAG_JOURNAL_DEV_OK, 0,
211 fs->blocksize, io_ptr, &jfs);
213 com_err(program_name, retval,
214 _("while trying to open external journal"));
215 goto no_valid_journal;
217 if (!(jfs->super->s_feature_incompat &
218 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)) {
219 fprintf(stderr, _("%s is not a journal device.\n"),
221 goto no_valid_journal;
224 /* Get the journal superblock */
225 if ((retval = io_channel_read_blk64(jfs->io, 1, -1024, buf))) {
226 com_err(program_name, retval,
227 _("while reading journal superblock"));
228 goto no_valid_journal;
231 jsb = (journal_superblock_t *) buf;
232 if ((jsb->s_header.h_magic != (unsigned)ntohl(JFS_MAGIC_NUMBER)) ||
233 (jsb->s_header.h_blocktype != (unsigned)ntohl(JFS_SUPERBLOCK_V2))) {
234 fputs(_("Journal superblock not found!\n"), stderr);
235 goto no_valid_journal;
238 /* Find the filesystem UUID */
239 nr_users = ntohl(jsb->s_nr_users);
240 for (i = 0; i < nr_users; i++) {
241 if (memcmp(fs->super->s_uuid, &jsb->s_users[i * 16], 16) == 0)
245 fputs(_("Filesystem's UUID not found on journal device.\n"),
247 commit_remove_journal = 1;
248 goto no_valid_journal;
251 for (i = 0; i < nr_users; i++)
252 memcpy(&jsb->s_users[i * 16], &jsb->s_users[(i + 1) * 16], 16);
253 jsb->s_nr_users = htonl(nr_users);
255 /* Write back the journal superblock */
256 if ((retval = io_channel_write_blk64(jfs->io, 1, -1024, buf))) {
257 com_err(program_name, retval,
258 "while writing journal superblock.");
259 goto no_valid_journal;
262 commit_remove_journal = 1;
265 if (commit_remove_journal == 0) {
266 fputs(_("Cannot locate journal device. It was NOT removed\n"
267 "Use -f option to remove missing journal device.\n"),
271 fs->super->s_journal_dev = 0;
272 uuid_clear(fs->super->s_journal_uuid);
273 ext2fs_mark_super_dirty(fs);
274 fputs(_("Journal removed\n"), stdout);
280 /* Helper function for remove_journal_inode */
281 static int release_blocks_proc(ext2_filsys fs, blk64_t *blocknr,
282 e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
283 blk64_t ref_block EXT2FS_ATTR((unused)),
284 int ref_offset EXT2FS_ATTR((unused)),
285 void *private EXT2FS_ATTR((unused)))
291 ext2fs_unmark_block_bitmap2(fs->block_map, block);
292 group = ext2fs_group_of_blk2(fs, block);
293 ext2fs_bg_free_blocks_count_set(fs, group, ext2fs_bg_free_blocks_count(fs, group) + 1);
294 ext2fs_group_desc_csum_set(fs, group);
295 ext2fs_free_blocks_count_add(fs->super, EXT2FS_CLUSTER_RATIO(fs));
300 * Remove the journal inode from the filesystem
302 static errcode_t remove_journal_inode(ext2_filsys fs)
304 struct ext2_inode inode;
306 ino_t ino = fs->super->s_journal_inum;
308 retval = ext2fs_read_inode(fs, ino, &inode);
310 com_err(program_name, retval,
311 _("while reading journal inode"));
314 if (ino == EXT2_JOURNAL_INO) {
315 retval = ext2fs_read_bitmaps(fs);
317 com_err(program_name, retval,
318 _("while reading bitmaps"));
321 retval = ext2fs_block_iterate3(fs, ino,
322 BLOCK_FLAG_READ_ONLY, NULL,
323 release_blocks_proc, NULL);
325 com_err(program_name, retval,
326 _("while clearing journal inode"));
329 memset(&inode, 0, sizeof(inode));
330 ext2fs_mark_bb_dirty(fs);
331 fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
333 inode.i_flags &= ~EXT2_IMMUTABLE_FL;
334 retval = ext2fs_write_inode(fs, ino, &inode);
336 com_err(program_name, retval,
337 _("while writing journal inode"));
340 fs->super->s_journal_inum = 0;
341 ext2fs_mark_super_dirty(fs);
347 * Update the default mount options
349 static int update_mntopts(ext2_filsys fs, char *mntopts)
351 struct ext2_super_block *sb = fs->super;
353 if (e2p_edit_mntopts(mntopts, &sb->s_default_mount_opts, ~0)) {
354 fprintf(stderr, _("Invalid mount option set: %s\n"),
358 ext2fs_mark_super_dirty(fs);
363 static int check_fsck_needed(ext2_filsys fs)
365 if (fs->super->s_state & EXT2_VALID_FS)
367 printf("\n%s\n", _(please_fsck));
368 if (mount_flags & EXT2_MF_READONLY)
369 printf(_("(and reboot afterwards!)\n"));
373 static void request_dir_fsck_afterwards(ext2_filsys fs)
375 static int requested;
379 fs->super->s_state &= ~EXT2_VALID_FS;
380 printf("\n%s\n", _(please_dir_fsck));
381 if (mount_flags & EXT2_MF_READONLY)
382 printf(_("(and reboot afterwards!)\n"));
385 static void request_fsck_afterwards(ext2_filsys fs)
387 static int requested = 0;
391 fs->super->s_state &= ~EXT2_VALID_FS;
392 printf("\n%s\n", _(please_fsck));
393 if (mount_flags & EXT2_MF_READONLY)
394 printf(_("(and reboot afterwards!)\n"));
397 /* Rewrite extents */
398 static errcode_t rewrite_extents(ext2_filsys fs, ext2_ino_t ino,
399 struct ext2_inode *inode)
401 ext2_extent_handle_t handle;
402 struct ext2fs_extent extent;
403 int op = EXT2_EXTENT_ROOT;
406 if (!(inode->i_flags & EXT4_EXTENTS_FL))
409 errcode = ext2fs_extent_open(fs, ino, &handle);
414 errcode = ext2fs_extent_get(handle, op, &extent);
418 /* Root node is in the separately checksummed inode */
419 if (op == EXT2_EXTENT_ROOT) {
420 op = EXT2_EXTENT_NEXT;
423 op = EXT2_EXTENT_NEXT;
425 /* Only visit the first extent in each extent block */
426 if (extent.e_flags & EXT2_EXTENT_FLAGS_SECOND_VISIT)
428 errcode = ext2fs_extent_replace(handle, 0, &extent);
433 /* Ok if we run off the end */
434 if (errcode == EXT2_ET_EXTENT_NO_NEXT)
440 * Rewrite directory blocks with checksums
442 struct rewrite_dir_context {
449 static int rewrite_dir_block(ext2_filsys fs,
451 e2_blkcnt_t blockcnt,
452 blk64_t ref_block EXT2FS_ATTR((unused)),
453 int ref_offset EXT2FS_ATTR((unused)),
456 struct ext2_dx_countlimit *dcl = NULL;
457 struct rewrite_dir_context *ctx = priv_data;
458 int dcl_offset, changed = 0;
460 ctx->errcode = ext2fs_read_dir_block4(fs, *blocknr, ctx->buf, 0,
465 /* if htree node... */
467 ext2fs_get_dx_countlimit(fs, (struct ext2_dir_entry *)ctx->buf,
470 if (!EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
471 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
472 /* Ensure limit is the max size */
473 int max_entries = (fs->blocksize - dcl_offset) /
474 sizeof(struct ext2_dx_entry);
475 if (ext2fs_le16_to_cpu(dcl->limit) != max_entries) {
477 dcl->limit = ext2fs_cpu_to_le16(max_entries);
480 /* If htree block is full then rebuild the dir */
481 if (ext2fs_le16_to_cpu(dcl->count) ==
482 ext2fs_le16_to_cpu(dcl->limit)) {
483 request_dir_fsck_afterwards(fs);
487 * Ensure dcl->limit is small enough to leave room for
490 int max_entries = (fs->blocksize - (dcl_offset +
491 sizeof(struct ext2_dx_tail))) /
492 sizeof(struct ext2_dx_entry);
493 if (ext2fs_le16_to_cpu(dcl->limit) != max_entries)
494 dcl->limit = ext2fs_cpu_to_le16(max_entries);
495 /* Always rewrite checksum */
499 unsigned int rec_len, name_size;
500 char *top = ctx->buf + fs->blocksize;
501 struct ext2_dir_entry *de = (struct ext2_dir_entry *)ctx->buf;
502 struct ext2_dir_entry *last_de = NULL, *penultimate_de = NULL;
504 /* Find last and penultimate dirent */
505 while ((char *)de < top) {
506 penultimate_de = last_de;
508 ctx->errcode = ext2fs_get_rec_len(fs, de, &rec_len);
509 if (!ctx->errcode && !rec_len)
510 ctx->errcode = EXT2_ET_DIR_CORRUPTED;
513 de = (struct ext2_dir_entry *)(((void *)de) + rec_len);
515 ctx->errcode = ext2fs_get_rec_len(fs, last_de, &rec_len);
518 name_size = last_de->name_len & 0xFF;
520 if (!EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
521 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
524 if (last_de->inode ||
526 rec_len != sizeof(struct ext2_dir_entry_tail))
529 * The last dirent is unused and the right length to
530 * have stored a checksum. Erase it.
532 ctx->errcode = ext2fs_get_rec_len(fs, penultimate_de,
535 ctx->errcode = EXT2_ET_DIR_CORRUPTED;
538 ext2fs_set_rec_len(fs, rec_len +
539 sizeof(struct ext2_dir_entry_tail),
543 int csum_size = sizeof(struct ext2_dir_entry_tail);
544 struct ext2_dir_entry_tail *t;
547 * If the last dirent looks like the tail, just update
550 if (!last_de->inode &&
551 rec_len == csum_size) {
552 t = (struct ext2_dir_entry_tail *)last_de;
553 t->det_reserved_name_len =
554 EXT2_DIR_NAME_LEN_CSUM;
559 name_size = (name_size & ~3) + 4;
560 /* If there's not enough space for the tail, e2fsck */
561 if (rec_len <= (8 + name_size + csum_size)) {
562 request_dir_fsck_afterwards(fs);
565 /* Shorten that last de and insert the tail */
566 ext2fs_set_rec_len(fs, rec_len - csum_size, last_de);
567 t = EXT2_DIRENT_TAIL(ctx->buf, fs->blocksize);
568 ext2fs_initialize_dirent_tail(fs, t);
570 /* Always update checksum */
579 ctx->errcode = ext2fs_write_dir_block4(fs, *blocknr, ctx->buf,
587 errcode_t rewrite_directory(ext2_filsys fs, ext2_ino_t dir,
588 struct ext2_inode *inode)
591 struct rewrite_dir_context ctx;
593 retval = ext2fs_get_mem(fs->blocksize, &ctx.buf);
597 ctx.is_htree = (inode->i_flags & EXT2_INDEX_FL);
600 retval = ext2fs_block_iterate3(fs, dir, BLOCK_FLAG_READ_ONLY |
601 BLOCK_FLAG_DATA_ONLY,
602 0, rewrite_dir_block, &ctx);
604 ext2fs_free_mem(&ctx.buf);
612 * Forcibly set checksums in all inodes.
614 static void rewrite_inodes(ext2_filsys fs)
616 int length = EXT2_INODE_SIZE(fs->super);
617 struct ext2_inode *inode;
619 ext2_inode_scan scan;
622 blk64_t file_acl_block;
624 if (fs->super->s_creator_os != EXT2_OS_LINUX)
627 retval = ext2fs_open_inode_scan(fs, 0, &scan);
629 com_err("set_csum", retval, "while opening inode scan");
633 retval = ext2fs_get_mem(length, &inode);
635 com_err("set_csum", retval, "while allocating memory");
639 retval = ext2fs_get_mem(fs->blocksize, &ea_buf);
641 com_err("set_csum", retval, "while allocating memory");
646 retval = ext2fs_get_next_inode_full(scan, &ino, inode, length);
648 com_err("set_csum", retval, "while getting next inode");
654 retval = ext2fs_write_inode_full(fs, ino, inode, length);
656 com_err("set_csum", retval, "while writing inode");
660 retval = rewrite_extents(fs, ino, inode);
662 com_err("rewrite_extents", retval,
663 "while rewriting extents");
667 if (LINUX_S_ISDIR(inode->i_mode)) {
668 retval = rewrite_directory(fs, ino, inode);
670 com_err("rewrite_directory", retval,
671 "while rewriting directories");
676 file_acl_block = ext2fs_file_acl_block(fs, inode);
679 retval = ext2fs_read_ext_attr3(fs, file_acl_block, ea_buf, ino);
681 com_err("rewrite_eablock", retval,
682 "while rewriting extended attribute");
685 retval = ext2fs_write_ext_attr3(fs, file_acl_block, ea_buf,
688 com_err("rewrite_eablock", retval,
689 "while rewriting extended attribute");
694 ext2fs_free_mem(&inode);
695 ext2fs_free_mem(&ea_buf);
696 ext2fs_close_inode_scan(scan);
699 static void rewrite_metadata_checksums(ext2_filsys fs)
703 fs->flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS;
704 ext2fs_init_csum_seed(fs);
705 for (i = 0; i < fs->group_desc_count; i++)
706 ext2fs_group_desc_csum_set(fs, i);
708 ext2fs_read_bitmaps(fs);
709 ext2fs_mark_ib_dirty(fs);
710 ext2fs_mark_bb_dirty(fs);
711 ext2fs_mmp_update2(fs, 1);
712 fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
713 fs->flags &= ~EXT2_FLAG_IGNORE_CSUM_ERRORS;
714 if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
715 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
716 fs->super->s_checksum_type = EXT2_CRC32C_CHKSUM;
718 fs->super->s_checksum_type = 0;
719 ext2fs_mark_super_dirty(fs);
722 static void enable_uninit_bg(ext2_filsys fs)
724 struct ext2_group_desc *gd;
727 for (i = 0; i < fs->group_desc_count; i++) {
728 gd = ext2fs_group_desc(fs, fs->group_desc, i);
729 gd->bg_itable_unused = 0;
730 gd->bg_flags = EXT2_BG_INODE_ZEROED;
731 ext2fs_group_desc_csum_set(fs, i);
733 fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
736 static void disable_uninit_bg(ext2_filsys fs, __u32 csum_feature_flag)
738 struct ext2_group_desc *gd;
741 /* Load bitmaps to ensure that the uninit ones get written out */
742 fs->super->s_feature_ro_compat |= csum_feature_flag;
743 ext2fs_read_bitmaps(fs);
744 ext2fs_mark_ib_dirty(fs);
745 ext2fs_mark_bb_dirty(fs);
746 fs->super->s_feature_ro_compat &= ~csum_feature_flag;
748 for (i = 0; i < fs->group_desc_count; i++) {
749 gd = ext2fs_group_desc(fs, fs->group_desc, i);
750 if ((gd->bg_flags & EXT2_BG_INODE_ZEROED) == 0) {
752 * XXX what we really should do is zap
753 * uninitialized inode tables instead.
755 request_fsck_afterwards(fs);
758 gd->bg_itable_unused = 0;
760 ext2fs_group_desc_csum_set(fs, i);
762 fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
766 * Update the feature set as provided by the user.
768 static int update_feature_set(ext2_filsys fs, char *features)
770 struct ext2_super_block *sb = fs->super;
771 __u32 old_features[3];
773 unsigned int mask_err;
775 #define FEATURE_ON(type, mask) (!(old_features[(type)] & (mask)) && \
776 ((&sb->s_feature_compat)[(type)] & (mask)))
777 #define FEATURE_OFF(type, mask) ((old_features[(type)] & (mask)) && \
778 !((&sb->s_feature_compat)[(type)] & (mask)))
779 #define FEATURE_CHANGED(type, mask) ((mask) & \
780 (old_features[(type)] ^ (&sb->s_feature_compat)[(type)]))
782 old_features[E2P_FEATURE_COMPAT] = sb->s_feature_compat;
783 old_features[E2P_FEATURE_INCOMPAT] = sb->s_feature_incompat;
784 old_features[E2P_FEATURE_RO_INCOMPAT] = sb->s_feature_ro_compat;
786 if (e2p_edit_feature2(features, &sb->s_feature_compat,
787 ok_features, clear_ok_features,
788 &type_err, &mask_err)) {
791 _("Invalid filesystem option set: %s\n"),
793 else if (type_err & E2P_FEATURE_NEGATE_FLAG)
794 fprintf(stderr, _("Clearing filesystem feature '%s' "
796 e2p_feature2string(type_err &
797 E2P_FEATURE_TYPE_MASK,
800 fprintf(stderr, _("Setting filesystem feature '%s' "
802 e2p_feature2string(type_err, mask_err));
806 if (FEATURE_OFF(E2P_FEATURE_COMPAT, EXT3_FEATURE_COMPAT_HAS_JOURNAL)) {
807 if ((mount_flags & EXT2_MF_MOUNTED) &&
808 !(mount_flags & EXT2_MF_READONLY)) {
809 fputs(_("The has_journal feature may only be "
810 "cleared when the filesystem is\n"
811 "unmounted or mounted "
812 "read-only.\n"), stderr);
815 if (sb->s_feature_incompat &
816 EXT3_FEATURE_INCOMPAT_RECOVER) {
817 fputs(_("The needs_recovery flag is set. "
818 "Please run e2fsck before clearing\n"
819 "the has_journal flag.\n"), stderr);
822 if (sb->s_journal_inum) {
823 if (remove_journal_inode(fs))
826 if (sb->s_journal_dev) {
827 if (remove_journal_device(fs))
831 if (FEATURE_ON(E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_MMP)) {
834 if ((mount_flags & EXT2_MF_MOUNTED) ||
835 (mount_flags & EXT2_MF_READONLY)) {
836 fputs(_("The multiple mount protection feature can't\n"
837 "be set if the filesystem is mounted or\n"
838 "read-only.\n"), stderr);
842 error = ext2fs_mmp_init(fs);
844 fputs(_("\nError while enabling multiple mount "
845 "protection feature."), stderr);
850 * We want to update group desc with the new free blocks count
852 fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
854 printf(_("Multiple mount protection has been enabled "
855 "with update interval %ds.\n"),
856 sb->s_mmp_update_interval);
859 if (FEATURE_OFF(E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_MMP)) {
862 if (mount_flags & EXT2_MF_READONLY) {
863 fputs(_("The multiple mount protection feature cannot\n"
864 "be disabled if the filesystem is readonly.\n"),
869 error = ext2fs_read_bitmaps(fs);
871 fputs(_("Error while reading bitmaps\n"), stderr);
875 error = ext2fs_mmp_read(fs, sb->s_mmp_block, NULL);
877 struct mmp_struct *mmp_cmp = fs->mmp_cmp;
879 if (error == EXT2_ET_MMP_MAGIC_INVALID)
880 printf(_("Magic number in MMP block does not "
881 "match. expected: %x, actual: %x\n"),
882 EXT4_MMP_MAGIC, mmp_cmp->mmp_magic);
884 com_err(program_name, error,
885 _("while reading MMP block."));
889 /* We need to force out the group descriptors as well */
890 fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
891 ext2fs_block_alloc_stats(fs, sb->s_mmp_block, -1);
894 sb->s_mmp_update_interval = 0;
897 if (FEATURE_ON(E2P_FEATURE_COMPAT, EXT3_FEATURE_COMPAT_HAS_JOURNAL)) {
899 * If adding a journal flag, let the create journal
900 * code below handle setting the flag and creating the
901 * journal. We supply a default size if necessary.
905 sb->s_feature_compat &= ~EXT3_FEATURE_COMPAT_HAS_JOURNAL;
908 if (FEATURE_ON(E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_DIR_INDEX)) {
909 if (!sb->s_def_hash_version)
910 sb->s_def_hash_version = EXT2_HASH_HALF_MD4;
911 if (uuid_is_null((unsigned char *) sb->s_hash_seed))
912 uuid_generate((unsigned char *) sb->s_hash_seed);
915 if (FEATURE_OFF(E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_FLEX_BG)) {
916 if (ext2fs_check_desc(fs)) {
917 fputs(_("Clearing the flex_bg flag would "
918 "cause the the filesystem to be\n"
919 "inconsistent.\n"), stderr);
924 if (FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT,
925 EXT4_FEATURE_RO_COMPAT_HUGE_FILE)) {
926 if ((mount_flags & EXT2_MF_MOUNTED) &&
927 !(mount_flags & EXT2_MF_READONLY)) {
928 fputs(_("The huge_file feature may only be "
929 "cleared when the filesystem is\n"
930 "unmounted or mounted "
931 "read-only.\n"), stderr);
936 if (FEATURE_ON(E2P_FEATURE_RO_INCOMPAT,
937 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
938 if (check_fsck_needed(fs))
940 rewrite_checksums = 1;
941 /* metadata_csum supersedes uninit_bg */
942 fs->super->s_feature_ro_compat &=
943 ~EXT4_FEATURE_RO_COMPAT_GDT_CSUM;
945 /* if uninit_bg was previously off, rewrite group desc */
946 if (!(old_features[E2P_FEATURE_RO_INCOMPAT] &
947 EXT4_FEATURE_RO_COMPAT_GDT_CSUM))
948 enable_uninit_bg(fs);
951 * Since metadata_csum supersedes uninit_bg, pretend like
952 * uninit_bg has been off all along.
954 old_features[E2P_FEATURE_RO_INCOMPAT] &=
955 ~EXT4_FEATURE_RO_COMPAT_GDT_CSUM;
958 if (FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT,
959 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
960 if (check_fsck_needed(fs))
962 rewrite_checksums = 1;
964 * If we're turning off metadata_csum and not turning on
965 * uninit_bg, rewrite group desc.
967 if (!(fs->super->s_feature_ro_compat &
968 EXT4_FEATURE_RO_COMPAT_GDT_CSUM))
969 disable_uninit_bg(fs,
970 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM);
973 * metadata_csum previously provided uninit_bg, so if
974 * we're also setting the uninit_bg feature bit,
975 * pretend like it was previously enabled. Checksums
976 * will be rewritten with crc16 later.
978 old_features[E2P_FEATURE_RO_INCOMPAT] |=
979 EXT4_FEATURE_RO_COMPAT_GDT_CSUM;
982 if (FEATURE_ON(E2P_FEATURE_RO_INCOMPAT,
983 EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
984 /* Do not enable uninit_bg when metadata_csum enabled */
985 if (fs->super->s_feature_ro_compat &
986 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)
987 fs->super->s_feature_ro_compat &=
988 ~EXT4_FEATURE_RO_COMPAT_GDT_CSUM;
990 enable_uninit_bg(fs);
993 if (FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT,
994 EXT4_FEATURE_RO_COMPAT_GDT_CSUM))
995 disable_uninit_bg(fs,
996 EXT4_FEATURE_RO_COMPAT_GDT_CSUM);
998 if (FEATURE_ON(E2P_FEATURE_RO_INCOMPAT,
999 EXT4_FEATURE_RO_COMPAT_QUOTA)) {
1001 * Set the Q_flag here and handle the quota options in the code
1006 /* Enable both user quota and group quota by default */
1007 usrquota = QOPT_ENABLE;
1008 grpquota = QOPT_ENABLE;
1010 sb->s_feature_ro_compat &= ~EXT4_FEATURE_RO_COMPAT_QUOTA;
1013 if (FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT,
1014 EXT4_FEATURE_RO_COMPAT_QUOTA)) {
1016 * Set the Q_flag here and handle the quota options in the code
1020 fputs(_("\nWarning: '^quota' option overrides '-Q'"
1021 "arguments.\n"), stderr);
1023 /* Disable both user quota and group quota by default */
1024 usrquota = QOPT_DISABLE;
1025 grpquota = QOPT_DISABLE;
1028 if (sb->s_rev_level == EXT2_GOOD_OLD_REV &&
1029 (sb->s_feature_compat || sb->s_feature_ro_compat ||
1030 sb->s_feature_incompat))
1031 ext2fs_update_dynamic_rev(fs);
1033 if (FEATURE_CHANGED(E2P_FEATURE_RO_INCOMPAT,
1034 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER) ||
1035 FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT,
1036 EXT4_FEATURE_RO_COMPAT_HUGE_FILE) ||
1037 FEATURE_CHANGED(E2P_FEATURE_INCOMPAT,
1038 EXT2_FEATURE_INCOMPAT_FILETYPE) ||
1039 FEATURE_CHANGED(E2P_FEATURE_COMPAT,
1040 EXT2_FEATURE_COMPAT_RESIZE_INODE) ||
1041 FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT,
1042 EXT2_FEATURE_RO_COMPAT_LARGE_FILE))
1043 request_fsck_afterwards(fs);
1045 if ((old_features[E2P_FEATURE_COMPAT] != sb->s_feature_compat) ||
1046 (old_features[E2P_FEATURE_INCOMPAT] != sb->s_feature_incompat) ||
1047 (old_features[E2P_FEATURE_RO_INCOMPAT] != sb->s_feature_ro_compat))
1048 ext2fs_mark_super_dirty(fs);
1054 * Add a journal to the filesystem.
1056 static int add_journal(ext2_filsys fs)
1058 unsigned long journal_blocks;
1063 if (fs->super->s_feature_compat &
1064 EXT3_FEATURE_COMPAT_HAS_JOURNAL) {
1065 fputs(_("The filesystem already has a journal.\n"), stderr);
1068 if (journal_device) {
1069 check_plausibility(journal_device);
1070 check_mount(journal_device, 0, _("journal"));
1071 #ifdef CONFIG_TESTIO_DEBUG
1072 if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) {
1073 io_ptr = test_io_manager;
1074 test_io_backing_manager = unix_io_manager;
1077 io_ptr = unix_io_manager;
1078 retval = ext2fs_open(journal_device, EXT2_FLAG_RW|
1079 EXT2_FLAG_JOURNAL_DEV_OK, 0,
1080 fs->blocksize, io_ptr, &jfs);
1082 com_err(program_name, retval,
1083 _("\n\twhile trying to open journal on %s\n"),
1087 printf(_("Creating journal on device %s: "),
1091 retval = ext2fs_add_journal_device(fs, jfs);
1094 com_err(program_name, retval,
1095 _("while adding filesystem to journal on %s"),
1099 fputs(_("done\n"), stdout);
1100 } else if (journal_size) {
1101 fputs(_("Creating journal inode: "), stdout);
1103 journal_blocks = figure_journal_size(journal_size, fs);
1105 retval = ext2fs_add_journal_inode(fs, journal_blocks,
1108 fprintf(stderr, "\n");
1109 com_err(program_name, retval,
1110 _("\n\twhile trying to create journal file"));
1113 fputs(_("done\n"), stdout);
1115 * If the filesystem wasn't mounted, we need to force
1116 * the block group descriptors out.
1118 if ((mount_flags & EXT2_MF_MOUNTED) == 0)
1119 fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
1121 print_check_message(fs->super->s_max_mnt_count,
1122 fs->super->s_checkinterval);
1126 free(journal_device);
1130 void handle_quota_options(ext2_filsys fs)
1135 if (!usrquota && !grpquota)
1136 /* Nothing to do. */
1139 quota_init_context(&qctx, fs, -1);
1141 if (usrquota == QOPT_ENABLE || grpquota == QOPT_ENABLE)
1142 quota_compute_usage(qctx);
1144 if (usrquota == QOPT_ENABLE && !fs->super->s_usr_quota_inum) {
1145 if ((qf_ino = quota_file_exists(fs, USRQUOTA,
1147 quota_update_limits(qctx, qf_ino, USRQUOTA);
1148 quota_write_inode(qctx, USRQUOTA);
1149 } else if (usrquota == QOPT_DISABLE) {
1150 quota_remove_inode(fs, USRQUOTA);
1153 if (grpquota == QOPT_ENABLE && !fs->super->s_grp_quota_inum) {
1154 if ((qf_ino = quota_file_exists(fs, GRPQUOTA,
1156 quota_update_limits(qctx, qf_ino, GRPQUOTA);
1157 quota_write_inode(qctx, GRPQUOTA);
1158 } else if (grpquota == QOPT_DISABLE) {
1159 quota_remove_inode(fs, GRPQUOTA);
1162 quota_release_context(&qctx);
1164 if ((usrquota == QOPT_ENABLE) || (grpquota == QOPT_ENABLE)) {
1165 fprintf(stderr, _("\nWarning: the quota feature is still "
1166 "under development\n"
1167 "See https://ext4.wiki.kernel.org/"
1168 "index.php/Quota for more information\n\n"));
1169 fs->super->s_feature_ro_compat |= EXT4_FEATURE_RO_COMPAT_QUOTA;
1170 ext2fs_mark_super_dirty(fs);
1171 } else if (!fs->super->s_usr_quota_inum &&
1172 !fs->super->s_grp_quota_inum) {
1173 fs->super->s_feature_ro_compat &= ~EXT4_FEATURE_RO_COMPAT_QUOTA;
1174 ext2fs_mark_super_dirty(fs);
1180 void parse_quota_opts(const char *opts)
1182 char *buf, *token, *next, *p;
1186 buf = malloc(len+1);
1188 fputs(_("Couldn't allocate memory to parse quota "
1189 "options!\n"), stderr);
1193 for (token = buf; token && *token; token = next) {
1194 p = strchr(token, ',');
1201 if (strcmp(token, "usrquota") == 0) {
1202 usrquota = QOPT_ENABLE;
1203 } else if (strcmp(token, "^usrquota") == 0) {
1204 usrquota = QOPT_DISABLE;
1205 } else if (strcmp(token, "grpquota") == 0) {
1206 grpquota = QOPT_ENABLE;
1207 } else if (strcmp(token, "^grpquota") == 0) {
1208 grpquota = QOPT_DISABLE;
1210 fputs(_("\nBad quota options specified.\n\n"
1211 "Following valid quota options are available "
1212 "(pass by separating with comma):\n"
1225 static void parse_e2label_options(int argc, char ** argv)
1227 if ((argc < 2) || (argc > 3)) {
1228 fputs(_("Usage: e2label device [newlabel]\n"), stderr);
1231 io_options = strchr(argv[1], '?');
1234 device_name = blkid_get_devname(NULL, argv[1], NULL);
1236 com_err("e2label", 0, _("Unable to resolve '%s'"),
1240 open_flag = EXT2_FLAG_JOURNAL_DEV_OK;
1242 open_flag |= EXT2_FLAG_RW;
1244 new_label = argv[2];
1249 static time_t parse_time(char *str)
1253 if (strcmp(str, "now") == 0) {
1256 memset(&ts, 0, sizeof(ts));
1257 #ifdef HAVE_STRPTIME
1258 strptime(str, "%Y%m%d%H%M%S", &ts);
1260 sscanf(str, "%4d%2d%2d%2d%2d%2d", &ts.tm_year, &ts.tm_mon,
1261 &ts.tm_mday, &ts.tm_hour, &ts.tm_min, &ts.tm_sec);
1264 if (ts.tm_year < 0 || ts.tm_mon < 0 || ts.tm_mon > 11 ||
1265 ts.tm_mday < 0 || ts.tm_mday > 31 || ts.tm_hour > 23 ||
1266 ts.tm_min > 59 || ts.tm_sec > 61)
1269 if (ts.tm_mday == 0) {
1270 com_err(program_name, 0,
1271 _("Couldn't parse date/time specifier: %s"),
1276 return (mktime(&ts));
1279 static void parse_tune2fs_options(int argc, char **argv)
1288 printf("tune2fs %s (%s)\n", E2FSPROGS_VERSION, E2FSPROGS_DATE);
1289 while ((c = getopt(argc, argv, "c:e:fg:i:jlm:o:r:s:u:C:E:I:J:L:M:O:Q:T:U:")) != EOF)
1292 max_mount_count = strtol(optarg, &tmp, 0);
1293 if (*tmp || max_mount_count > 16000) {
1294 com_err(program_name, 0,
1295 _("bad mounts count - %s"),
1299 if (max_mount_count == 0)
1300 max_mount_count = -1;
1302 open_flag = EXT2_FLAG_RW;
1305 mount_count = strtoul(optarg, &tmp, 0);
1306 if (*tmp || mount_count > 16000) {
1307 com_err(program_name, 0,
1308 _("bad mounts count - %s"),
1313 open_flag = EXT2_FLAG_RW;
1316 if (strcmp(optarg, "continue") == 0)
1317 errors = EXT2_ERRORS_CONTINUE;
1318 else if (strcmp(optarg, "remount-ro") == 0)
1319 errors = EXT2_ERRORS_RO;
1320 else if (strcmp(optarg, "panic") == 0)
1321 errors = EXT2_ERRORS_PANIC;
1323 com_err(program_name, 0,
1324 _("bad error behavior - %s"),
1329 open_flag = EXT2_FLAG_RW;
1332 extended_cmd = optarg;
1333 open_flag |= EXT2_FLAG_RW;
1335 case 'f': /* Force */
1339 resgid = strtoul(optarg, &tmp, 0);
1341 gr = getgrnam(optarg);
1345 resgid = gr->gr_gid;
1350 com_err(program_name, 0,
1351 _("bad gid/group name - %s"),
1356 open_flag = EXT2_FLAG_RW;
1359 interval = strtoul(optarg, &tmp, 0);
1366 case 'D': /* days */
1372 case 'M': /* months! */
1373 interval *= 86400 * 30;
1377 case 'W': /* weeks */
1378 interval *= 86400 * 7;
1383 com_err(program_name, 0,
1384 _("bad interval - %s"), optarg);
1388 open_flag = EXT2_FLAG_RW;
1393 open_flag = EXT2_FLAG_RW;
1396 parse_journal_opts(optarg);
1397 open_flag = EXT2_FLAG_RW;
1405 open_flag |= EXT2_FLAG_RW |
1406 EXT2_FLAG_JOURNAL_DEV_OK;
1409 reserved_ratio = strtod(optarg, &tmp);
1410 if (*tmp || reserved_ratio > 50 ||
1411 reserved_ratio < 0) {
1412 com_err(program_name, 0,
1413 _("bad reserved block ratio - %s"),
1418 open_flag = EXT2_FLAG_RW;
1421 new_last_mounted = optarg;
1423 open_flag = EXT2_FLAG_RW;
1427 com_err(program_name, 0,
1428 _("-o may only be specified once"));
1431 mntopts_cmd = optarg;
1432 open_flag = EXT2_FLAG_RW;
1436 com_err(program_name, 0,
1437 _("-O may only be specified once"));
1440 features_cmd = optarg;
1441 open_flag = EXT2_FLAG_RW;
1445 parse_quota_opts(optarg);
1446 open_flag = EXT2_FLAG_RW;
1449 reserved_blocks = strtoul(optarg, &tmp, 0);
1451 com_err(program_name, 0,
1452 _("bad reserved blocks count - %s"),
1457 open_flag = EXT2_FLAG_RW;
1459 case 's': /* Deprecated */
1460 s_flag = atoi(optarg);
1461 open_flag = EXT2_FLAG_RW;
1465 last_check_time = parse_time(optarg);
1466 open_flag = EXT2_FLAG_RW;
1469 resuid = strtoul(optarg, &tmp, 0);
1471 pw = getpwnam(optarg);
1475 resuid = pw->pw_uid;
1480 com_err(program_name, 0,
1481 _("bad uid/user name - %s"),
1486 open_flag = EXT2_FLAG_RW;
1491 open_flag = EXT2_FLAG_RW |
1492 EXT2_FLAG_JOURNAL_DEV_OK;
1495 new_inode_size = strtoul(optarg, &tmp, 0);
1497 com_err(program_name, 0,
1498 _("bad inode size - %s"),
1502 if (!((new_inode_size &
1503 (new_inode_size - 1)) == 0)) {
1504 com_err(program_name, 0,
1505 _("Inode size must be a "
1506 "power of two- %s"),
1510 open_flag = EXT2_FLAG_RW;
1516 if (optind < argc - 1 || optind == argc)
1518 if (!open_flag && !l_flag)
1520 io_options = strchr(argv[optind], '?');
1523 device_name = blkid_get_devname(NULL, argv[optind], NULL);
1525 com_err(program_name, 0, _("Unable to resolve '%s'"),
1531 #ifdef CONFIG_BUILD_FINDFS
1532 void do_findfs(int argc, char **argv)
1537 (strncmp(argv[1], "LABEL=", 6) && strncmp(argv[1], "UUID=", 5))) {
1538 fprintf(stderr, "Usage: findfs LABEL=<label>|UUID=<uuid>\n");
1541 dev = blkid_get_devname(NULL, argv[1], NULL);
1543 com_err("findfs", 0, _("Unable to resolve '%s'"),
1552 static int parse_extended_opts(ext2_filsys fs, const char *opts)
1554 char *buf, *token, *next, *p, *arg;
1559 buf = malloc(len+1);
1562 _("Couldn't allocate memory to parse options!\n"));
1566 for (token = buf; token && *token; token = next) {
1567 p = strchr(token, ',');
1573 arg = strchr(token, '=');
1578 if (strcmp(token, "clear-mmp") == 0 ||
1579 strcmp(token, "clear_mmp") == 0) {
1581 } else if (strcmp(token, "mmp_update_interval") == 0) {
1582 unsigned long interval;
1587 interval = strtoul(arg, &p, 0);
1590 _("Invalid mmp_update_interval: %s\n"),
1595 if (interval == 0) {
1596 interval = EXT4_MMP_UPDATE_INTERVAL;
1597 } else if (interval > EXT4_MMP_MAX_UPDATE_INTERVAL) {
1599 _("mmp_update_interval too big: %lu\n"),
1604 printf(P_("Setting multiple mount protection update "
1605 "interval to %lu second\n",
1606 "Setting multiple mount protection update "
1607 "interval to %lu seconds\n", interval),
1609 fs->super->s_mmp_update_interval = interval;
1610 ext2fs_mark_super_dirty(fs);
1611 } else if (!strcmp(token, "test_fs")) {
1612 fs->super->s_flags |= EXT2_FLAGS_TEST_FILESYS;
1613 printf("Setting test filesystem flag\n");
1614 ext2fs_mark_super_dirty(fs);
1615 } else if (!strcmp(token, "^test_fs")) {
1616 fs->super->s_flags &= ~EXT2_FLAGS_TEST_FILESYS;
1617 printf("Clearing test filesystem flag\n");
1618 ext2fs_mark_super_dirty(fs);
1619 } else if (strcmp(token, "stride") == 0) {
1624 stride = strtoul(arg, &p, 0);
1627 _("Invalid RAID stride: %s\n"),
1633 } else if (strcmp(token, "stripe-width") == 0 ||
1634 strcmp(token, "stripe_width") == 0) {
1639 stripe_width = strtoul(arg, &p, 0);
1642 _("Invalid RAID stripe-width: %s\n"),
1647 stripe_width_set = 1;
1648 } else if (strcmp(token, "hash_alg") == 0 ||
1649 strcmp(token, "hash-alg") == 0) {
1654 hash_alg = e2p_string2hash(arg);
1657 _("Invalid hash algorithm: %s\n"),
1662 fs->super->s_def_hash_version = hash_alg;
1663 printf(_("Setting default hash algorithm "
1666 ext2fs_mark_super_dirty(fs);
1667 } else if (!strcmp(token, "mount_opts")) {
1672 if (strlen(arg) >= sizeof(fs->super->s_mount_opts)) {
1674 "Extended mount options too long\n");
1677 ext_mount_opts = strdup(arg);
1682 fprintf(stderr, _("\nBad options specified.\n\n"
1683 "Extended options are separated by commas, "
1684 "and may take an argument which\n"
1685 "\tis set off by an equals ('=') sign.\n\n"
1686 "Valid extended options are:\n"
1688 "\thash_alg=<hash algorithm>\n"
1689 "\tmount_opts=<extended default mount options>\n"
1690 "\tstride=<RAID per-disk chunk size in blocks>\n"
1691 "\tstripe_width=<RAID stride*data disks in blocks>\n"
1703 * Fill in the block bitmap bmap with the information regarding the
1704 * blocks to be moved
1706 static int get_move_bitmaps(ext2_filsys fs, int new_ino_blks_per_grp,
1707 ext2fs_block_bitmap bmap)
1711 ext2_badblocks_list bb_list = 0;
1712 blk64_t j, needed_blocks = 0;
1713 blk64_t start_blk, end_blk;
1715 retval = ext2fs_read_bb_inode(fs, &bb_list);
1719 for (i = 0; i < fs->group_desc_count; i++) {
1720 start_blk = ext2fs_inode_table_loc(fs, i) +
1721 fs->inode_blocks_per_group;
1723 end_blk = ext2fs_inode_table_loc(fs, i) +
1724 new_ino_blks_per_grp;
1726 for (j = start_blk; j < end_blk; j++) {
1727 if (ext2fs_test_block_bitmap2(fs->block_map, j)) {
1729 * IF the block is a bad block we fail
1731 if (ext2fs_badblocks_list_test(bb_list, j)) {
1732 ext2fs_badblocks_list_free(bb_list);
1736 ext2fs_mark_block_bitmap2(bmap, j);
1739 * We are going to use this block for
1740 * inode table. So mark them used.
1742 ext2fs_mark_block_bitmap2(fs->block_map, j);
1745 needed_blocks += end_blk - start_blk;
1748 ext2fs_badblocks_list_free(bb_list);
1749 if (needed_blocks > ext2fs_free_blocks_count(fs->super))
1755 static int ext2fs_is_meta_block(ext2_filsys fs, blk_t blk)
1758 group = ext2fs_group_of_blk(fs, blk);
1759 if (ext2fs_block_bitmap_loc(fs, group) == blk)
1761 if (ext2fs_inode_bitmap_loc(fs, group) == blk)
1766 static int ext2fs_is_block_in_group(ext2_filsys fs, dgrp_t group, blk_t blk)
1768 blk_t start_blk, end_blk;
1769 start_blk = fs->super->s_first_data_block +
1770 EXT2_BLOCKS_PER_GROUP(fs->super) * group;
1772 * We cannot get new block beyond end_blk for for the last block group
1773 * so we can check with EXT2_BLOCKS_PER_GROUP even for last block group
1775 end_blk = start_blk + EXT2_BLOCKS_PER_GROUP(fs->super);
1776 if (blk >= start_blk && blk <= end_blk)
1781 static int move_block(ext2_filsys fs, ext2fs_block_bitmap bmap)
1788 blk64_t blk, new_blk, goal;
1789 struct blk_move *bmv;
1791 retval = ext2fs_get_mem(fs->blocksize, &buf);
1795 for (new_blk = blk = fs->super->s_first_data_block;
1796 blk < ext2fs_blocks_count(fs->super); blk++) {
1797 if (!ext2fs_test_block_bitmap2(bmap, blk))
1800 if (ext2fs_is_meta_block(fs, blk)) {
1802 * If the block is mapping a fs meta data block
1803 * like group desc/block bitmap/inode bitmap. We
1804 * should find a block in the same group and fix
1805 * the respective fs metadata pointers. Otherwise
1808 group = ext2fs_group_of_blk(fs, blk);
1809 goal = ext2fs_group_first_block2(fs, group);
1815 retval = ext2fs_new_block2(fs, goal, NULL, &new_blk);
1819 /* new fs meta data block should be in the same group */
1820 if (meta_data && !ext2fs_is_block_in_group(fs, group, new_blk)) {
1825 /* Mark this block as allocated */
1826 ext2fs_mark_block_bitmap2(fs->block_map, new_blk);
1828 /* Add it to block move list */
1829 retval = ext2fs_get_mem(sizeof(struct blk_move), &bmv);
1834 bmv->new_loc = new_blk;
1836 list_add(&(bmv->list), &blk_move_list);
1838 retval = io_channel_read_blk64(fs->io, blk, 1, buf);
1842 retval = io_channel_write_blk64(fs->io, new_blk, 1, buf);
1848 ext2fs_free_mem(&buf);
1852 static blk64_t translate_block(blk64_t blk)
1854 struct list_head *entry;
1855 struct blk_move *bmv;
1857 list_for_each(entry, &blk_move_list) {
1858 bmv = list_entry(entry, struct blk_move, list);
1859 if (bmv->old_loc == blk)
1860 return bmv->new_loc;
1866 static int process_block(ext2_filsys fs EXT2FS_ATTR((unused)),
1868 e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
1869 blk64_t ref_block EXT2FS_ATTR((unused)),
1870 int ref_offset EXT2FS_ATTR((unused)),
1875 ext2fs_block_bitmap bmap = (ext2fs_block_bitmap) priv_data;
1877 if (!ext2fs_test_block_bitmap2(bmap, *block_nr))
1879 new_blk = translate_block(*block_nr);
1881 *block_nr = new_blk;
1883 * This will force the ext2fs_write_inode in the iterator
1885 ret |= BLOCK_CHANGED;
1891 static int inode_scan_and_fix(ext2_filsys fs, ext2fs_block_bitmap bmap)
1893 errcode_t retval = 0;
1896 char *block_buf = 0;
1897 struct ext2_inode inode;
1898 ext2_inode_scan scan = NULL;
1900 retval = ext2fs_get_mem(fs->blocksize * 3, &block_buf);
1904 retval = ext2fs_open_inode_scan(fs, 0, &scan);
1909 retval = ext2fs_get_next_inode(scan, &ino, &inode);
1916 if (inode.i_links_count == 0)
1917 continue; /* inode not in use */
1920 * If we end up modifying the journal inode
1921 * the sb->s_jnl_blocks will differ. But a
1922 * subsequent e2fsck fixes that.
1923 * Do we need to fix this ??
1926 if (ext2fs_file_acl_block(fs, &inode) &&
1927 ext2fs_test_block_bitmap2(bmap,
1928 ext2fs_file_acl_block(fs, &inode))) {
1929 blk = translate_block(ext2fs_file_acl_block(fs,
1934 ext2fs_file_acl_block_set(fs, &inode, blk);
1937 * Write the inode to disk so that inode table
1940 retval = ext2fs_write_inode(fs, ino, &inode);
1945 if (!ext2fs_inode_has_valid_blocks2(fs, &inode))
1948 retval = ext2fs_block_iterate3(fs, ino, 0, block_buf,
1949 process_block, bmap);
1956 ext2fs_free_mem(&block_buf);
1962 * We need to scan for inode and block bitmaps that may need to be
1963 * moved. This can take place if the filesystem was formatted for
1964 * RAID arrays using the mke2fs's extended option "stride".
1966 static int group_desc_scan_and_fix(ext2_filsys fs, ext2fs_block_bitmap bmap)
1971 for (i = 0; i < fs->group_desc_count; i++) {
1972 blk = ext2fs_block_bitmap_loc(fs, i);
1973 if (ext2fs_test_block_bitmap2(bmap, blk)) {
1974 new_blk = translate_block(blk);
1977 ext2fs_block_bitmap_loc_set(fs, i, new_blk);
1980 blk = ext2fs_inode_bitmap_loc(fs, i);
1981 if (ext2fs_test_block_bitmap2(bmap, blk)) {
1982 new_blk = translate_block(blk);
1985 ext2fs_inode_bitmap_loc_set(fs, i, new_blk);
1991 static int expand_inode_table(ext2_filsys fs, unsigned long new_ino_size)
1996 int new_ino_blks_per_grp;
1998 char *old_itable = NULL, *new_itable = NULL;
1999 char *tmp_old_itable = NULL, *tmp_new_itable = NULL;
2000 unsigned long old_ino_size;
2001 int old_itable_size, new_itable_size;
2003 old_itable_size = fs->inode_blocks_per_group * fs->blocksize;
2004 old_ino_size = EXT2_INODE_SIZE(fs->super);
2006 new_ino_blks_per_grp = ext2fs_div_ceil(
2007 EXT2_INODES_PER_GROUP(fs->super) *
2011 new_itable_size = new_ino_blks_per_grp * fs->blocksize;
2013 retval = ext2fs_get_mem(old_itable_size, &old_itable);
2017 retval = ext2fs_get_mem(new_itable_size, &new_itable);
2021 tmp_old_itable = old_itable;
2022 tmp_new_itable = new_itable;
2024 for (i = 0; i < fs->group_desc_count; i++) {
2025 blk = ext2fs_inode_table_loc(fs, i);
2026 retval = io_channel_read_blk64(fs->io, blk,
2027 fs->inode_blocks_per_group, old_itable);
2031 for (j = 0; j < EXT2_INODES_PER_GROUP(fs->super); j++) {
2032 memcpy(new_itable, old_itable, old_ino_size);
2034 memset(new_itable+old_ino_size, 0,
2035 new_ino_size - old_ino_size);
2037 new_itable += new_ino_size;
2038 old_itable += old_ino_size;
2041 /* reset the pointer */
2042 old_itable = tmp_old_itable;
2043 new_itable = tmp_new_itable;
2045 retval = io_channel_write_blk64(fs->io, blk,
2046 new_ino_blks_per_grp, new_itable);
2051 /* Update the meta data */
2052 fs->inode_blocks_per_group = new_ino_blks_per_grp;
2053 fs->super->s_inode_size = new_ino_size;
2057 ext2fs_free_mem(&old_itable);
2060 ext2fs_free_mem(&new_itable);
2065 static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs)
2069 unsigned int group = 0;
2070 unsigned int count = 0;
2075 * First calculate the block statistics
2077 for (blk = fs->super->s_first_data_block;
2078 blk < ext2fs_blocks_count(fs->super); blk++) {
2079 if (!ext2fs_fast_test_block_bitmap2(fs->block_map, blk)) {
2084 if ((count == fs->super->s_blocks_per_group) ||
2085 (blk == ext2fs_blocks_count(fs->super)-1)) {
2086 ext2fs_bg_free_blocks_count_set(fs, group++,
2092 total_free = EXT2FS_C2B(fs, total_free);
2093 ext2fs_free_blocks_count_set(fs->super, total_free);
2096 * Next, calculate the inode statistics
2103 /* Protect loop from wrap-around if s_inodes_count maxed */
2104 for (ino = 1; ino <= fs->super->s_inodes_count && ino > 0; ino++) {
2105 if (!ext2fs_fast_test_inode_bitmap2(fs->inode_map, ino)) {
2110 if ((count == fs->super->s_inodes_per_group) ||
2111 (ino == fs->super->s_inodes_count)) {
2112 ext2fs_bg_free_inodes_count_set(fs, group++,
2118 fs->super->s_free_inodes_count = total_free;
2119 ext2fs_mark_super_dirty(fs);
2123 #define list_for_each_safe(pos, pnext, head) \
2124 for (pos = (head)->next, pnext = pos->next; pos != (head); \
2125 pos = pnext, pnext = pos->next)
2127 static void free_blk_move_list(void)
2129 struct list_head *entry, *tmp;
2130 struct blk_move *bmv;
2132 list_for_each_safe(entry, tmp, &blk_move_list) {
2133 bmv = list_entry(entry, struct blk_move, list);
2135 ext2fs_free_mem(&bmv);
2140 static int resize_inode(ext2_filsys fs, unsigned long new_size)
2143 int new_ino_blks_per_grp;
2144 ext2fs_block_bitmap bmap;
2146 retval = ext2fs_read_inode_bitmap(fs);
2148 fputs(_("Failed to read inode bitmap\n"), stderr);
2151 retval = ext2fs_read_block_bitmap(fs);
2153 fputs(_("Failed to read block bitmap\n"), stderr);
2156 INIT_LIST_HEAD(&blk_move_list);
2159 new_ino_blks_per_grp = ext2fs_div_ceil(
2160 EXT2_INODES_PER_GROUP(fs->super)*
2164 /* We may change the file system.
2165 * Mark the file system as invalid so that
2166 * the user is prompted to run fsck.
2168 fs->super->s_state &= ~EXT2_VALID_FS;
2170 retval = ext2fs_allocate_block_bitmap(fs, _("blocks to be moved"),
2173 fputs(_("Failed to allocate block bitmap when "
2174 "increasing inode size\n"), stderr);
2177 retval = get_move_bitmaps(fs, new_ino_blks_per_grp, bmap);
2179 fputs(_("Not enough space to increase inode size \n"), stderr);
2182 retval = move_block(fs, bmap);
2184 fputs(_("Failed to relocate blocks during inode resize \n"),
2188 retval = inode_scan_and_fix(fs, bmap);
2192 retval = group_desc_scan_and_fix(fs, bmap);
2196 retval = expand_inode_table(fs, new_size);
2200 ext2fs_calculate_summary_stats(fs);
2202 fs->super->s_state |= EXT2_VALID_FS;
2203 /* mark super block and block bitmap as dirty */
2204 ext2fs_mark_super_dirty(fs);
2205 ext2fs_mark_bb_dirty(fs);
2208 free_blk_move_list();
2209 ext2fs_free_block_bitmap(bmap);
2214 free_blk_move_list();
2215 ext2fs_free_block_bitmap(bmap);
2216 fputs(_("Error in resizing the inode size.\n"
2217 "Run e2undo to undo the "
2218 "file system changes. \n"), stderr);
2223 static int tune2fs_setup_tdb(const char *name, io_manager *io_ptr)
2225 errcode_t retval = 0;
2226 const char *tdb_dir;
2228 char *dev_name, *tmp_name;
2232 * Configuration via a conf file would be
2235 profile_get_string(profile, "scratch_files",
2239 tmp_name = strdup(name);
2242 com_err(program_name, ENOMEM,
2243 _("Couldn't allocate memory for tdb filename\n"));
2246 dev_name = basename(tmp_name);
2248 tdb_dir = getenv("E2FSPROGS_UNDO_DIR");
2250 tdb_dir = "/var/lib/e2fsprogs";
2252 if (!strcmp(tdb_dir, "none") || (tdb_dir[0] == 0) ||
2253 access(tdb_dir, W_OK))
2256 tdb_file = malloc(strlen(tdb_dir) + 9 + strlen(dev_name) + 7 + 1);
2259 sprintf(tdb_file, "%s/tune2fs-%s.e2undo", tdb_dir, dev_name);
2261 if (!access(tdb_file, F_OK)) {
2262 if (unlink(tdb_file) < 0) {
2264 com_err(program_name, retval,
2265 _("while trying to delete %s"),
2272 set_undo_io_backing_manager(*io_ptr);
2273 *io_ptr = undo_io_manager;
2274 set_undo_io_backup_file(tdb_file);
2275 printf(_("To undo the tune2fs operation please run "
2276 "the command\n e2undo %s %s\n\n"),
2283 int main(int argc, char **argv)
2287 struct ext2_super_block *sb;
2288 io_manager io_ptr, io_ptr_orig = NULL;
2292 setlocale(LC_MESSAGES, "");
2293 setlocale(LC_CTYPE, "");
2294 bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
2295 textdomain(NLS_CAT_NAME);
2296 set_com_err_gettext(gettext);
2299 program_name = *argv;
2300 add_error_table(&et_ext2_error_table);
2302 #ifdef CONFIG_BUILD_FINDFS
2303 if (strcmp(get_progname(argv[0]), "findfs") == 0)
2304 do_findfs(argc, argv);
2306 if (strcmp(get_progname(argv[0]), "e2label") == 0)
2307 parse_e2label_options(argc, argv);
2309 parse_tune2fs_options(argc, argv);
2311 #ifdef CONFIG_TESTIO_DEBUG
2312 if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_DEBUG")) {
2313 io_ptr = test_io_manager;
2314 test_io_backing_manager = unix_io_manager;
2317 io_ptr = unix_io_manager;
2320 if ((open_flag & EXT2_FLAG_RW) == 0 || f_flag)
2321 open_flag |= EXT2_FLAG_SKIP_MMP;
2323 open_flag |= EXT2_FLAG_64BITS;
2325 /* keep the filesystem struct around to dump MMP data */
2326 open_flag |= EXT2_FLAG_NOFREE_ON_ERROR;
2328 retval = ext2fs_open2(device_name, io_options, open_flag,
2331 com_err(program_name, retval,
2332 _("while trying to open %s"),
2334 if (retval == EXT2_ET_MMP_FSCK_ON ||
2335 retval == EXT2_ET_MMP_UNKNOWN_SEQ)
2336 dump_mmp_msg(fs->mmp_buf,
2337 _("If you are sure the filesystem "
2338 "is not in use on any node, run:\n"
2339 "'tune2fs -f -E clear_mmp {device}'\n"));
2340 else if (retval == EXT2_ET_MMP_FAILED)
2341 dump_mmp_msg(fs->mmp_buf, NULL);
2342 else if (retval == EXT2_ET_MMP_MAGIC_INVALID)
2344 _("MMP block magic is bad. Try to fix it by "
2345 "running:\n'e2fsck -f %s'\n"), device_name);
2346 else if (retval != EXT2_ET_MMP_FAILED)
2348 _("Couldn't find valid filesystem superblock.\n"));
2353 fs->default_bitmap_type = EXT2FS_BMAP64_RBTREE;
2355 if (I_flag && !io_ptr_orig) {
2357 * Check the inode size is right so we can issue an
2358 * error message and bail before setting up the tdb
2361 if (new_inode_size == EXT2_INODE_SIZE(fs->super)) {
2362 fprintf(stderr, _("The inode size is already %lu\n"),
2367 if (new_inode_size < EXT2_INODE_SIZE(fs->super)) {
2368 fprintf(stderr, _("Shrinking the inode size is "
2369 "not supported\n"));
2373 if (new_inode_size > fs->blocksize) {
2374 fprintf(stderr, _("Invalid inode size %lu (max %d)\n"),
2375 new_inode_size, fs->blocksize);
2381 * If inode resize is requested use the
2384 io_ptr_orig = io_ptr;
2385 retval = tune2fs_setup_tdb(device_name, &io_ptr);
2390 if (io_ptr != io_ptr_orig) {
2397 fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
2400 /* For e2label emulation */
2401 printf("%.*s\n", (int) sizeof(sb->s_volume_name),
2403 remove_error_table(&et_ext2_error_table);
2407 retval = ext2fs_check_if_mounted(device_name, &mount_flags);
2409 com_err("ext2fs_check_if_mount", retval,
2410 _("while determining whether %s is mounted."),
2415 /* Normally we only need to write out the superblock */
2416 fs->flags |= EXT2_FLAG_SUPER_ONLY;
2419 sb->s_max_mnt_count = max_mount_count;
2420 ext2fs_mark_super_dirty(fs);
2421 printf(_("Setting maximal mount count to %d\n"),
2425 sb->s_mnt_count = mount_count;
2426 ext2fs_mark_super_dirty(fs);
2427 printf(_("Setting current mount count to %d\n"), mount_count);
2430 sb->s_errors = errors;
2431 ext2fs_mark_super_dirty(fs);
2432 printf(_("Setting error behavior to %d\n"), errors);
2435 sb->s_def_resgid = resgid;
2436 ext2fs_mark_super_dirty(fs);
2437 printf(_("Setting reserved blocks gid to %lu\n"), resgid);
2440 if (interval >= (1ULL << 32)) {
2441 com_err(program_name, 0,
2442 _("interval between checks is too big (%lu)"),
2447 sb->s_checkinterval = interval;
2448 ext2fs_mark_super_dirty(fs);
2449 printf(_("Setting interval between checks to %lu seconds\n"),
2453 ext2fs_r_blocks_count_set(sb, reserved_ratio *
2454 ext2fs_blocks_count(sb) / 100.0);
2455 ext2fs_mark_super_dirty(fs);
2456 printf (_("Setting reserved blocks percentage to %g%% (%llu blocks)\n"),
2457 reserved_ratio, ext2fs_r_blocks_count(sb));
2460 if (reserved_blocks > ext2fs_blocks_count(sb)/2) {
2461 com_err(program_name, 0,
2462 _("reserved blocks count is too big (%llu)"),
2467 ext2fs_r_blocks_count_set(sb, reserved_blocks);
2468 ext2fs_mark_super_dirty(fs);
2469 printf(_("Setting reserved blocks count to %llu\n"),
2473 if (sb->s_feature_ro_compat &
2474 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)
2475 fputs(_("\nThe filesystem already has sparse "
2476 "superblocks.\n"), stderr);
2478 sb->s_feature_ro_compat |=
2479 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
2480 sb->s_state &= ~EXT2_VALID_FS;
2481 ext2fs_mark_super_dirty(fs);
2482 printf(_("\nSparse superblock flag set. %s"),
2487 fputs(_("\nClearing the sparse superflag not supported.\n"),
2493 sb->s_lastcheck = last_check_time;
2494 ext2fs_mark_super_dirty(fs);
2495 printf(_("Setting time filesystem last checked to %s\n"),
2496 ctime(&last_check_time));
2499 sb->s_def_resuid = resuid;
2500 ext2fs_mark_super_dirty(fs);
2501 printf(_("Setting reserved blocks uid to %lu\n"), resuid);
2504 if (strlen(new_label) > sizeof(sb->s_volume_name))
2505 fputs(_("Warning: label too long, truncating.\n"),
2507 memset(sb->s_volume_name, 0, sizeof(sb->s_volume_name));
2508 strncpy(sb->s_volume_name, new_label,
2509 sizeof(sb->s_volume_name));
2510 ext2fs_mark_super_dirty(fs);
2513 memset(sb->s_last_mounted, 0, sizeof(sb->s_last_mounted));
2514 strncpy(sb->s_last_mounted, new_last_mounted,
2515 sizeof(sb->s_last_mounted));
2516 ext2fs_mark_super_dirty(fs);
2519 rc = update_mntopts(fs, mntopts_cmd);
2524 rc = update_feature_set(fs, features_cmd);
2529 rc = parse_extended_opts(fs, extended_cmd);
2532 if (clear_mmp && !f_flag) {
2533 fputs(_("Error in using clear_mmp. "
2534 "It must be used with -f\n"),
2540 rc = ext2fs_mmp_clear(fs);
2543 if (journal_size || journal_device) {
2544 rc = add_journal(fs);
2550 if (mount_flags & EXT2_MF_MOUNTED) {
2551 fputs(_("The quota feature may only be changed when "
2552 "the filesystem is unmounted.\n"), stderr);
2556 handle_quota_options(fs);
2563 if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
2564 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
2566 * Changing the UUID requires rewriting all metadata,
2567 * which can race with a mounted fs. Don't allow that.
2569 if (mount_flags & EXT2_MF_MOUNTED) {
2570 fputs(_("The UUID may only be "
2571 "changed when the filesystem is "
2572 "unmounted.\n"), stderr);
2576 if (check_fsck_needed(fs))
2580 if (ext2fs_has_group_desc_csum(fs)) {
2582 * Determine if the block group checksums are
2583 * correct so we know whether or not to set
2586 for (i = 0; i < fs->group_desc_count; i++)
2587 if (!ext2fs_group_desc_csum_verify(fs, i))
2589 if (i >= fs->group_desc_count)
2592 if ((strcasecmp(new_UUID, "null") == 0) ||
2593 (strcasecmp(new_UUID, "clear") == 0)) {
2594 uuid_clear(sb->s_uuid);
2595 } else if (strcasecmp(new_UUID, "time") == 0) {
2596 uuid_generate_time(sb->s_uuid);
2597 } else if (strcasecmp(new_UUID, "random") == 0) {
2598 uuid_generate(sb->s_uuid);
2599 } else if (uuid_parse(new_UUID, sb->s_uuid)) {
2600 com_err(program_name, 0, _("Invalid UUID format\n"));
2604 ext2fs_init_csum_seed(fs);
2606 for (i = 0; i < fs->group_desc_count; i++)
2607 ext2fs_group_desc_csum_set(fs, i);
2608 fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
2610 ext2fs_mark_super_dirty(fs);
2611 if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
2612 EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
2613 rewrite_checksums = 1;
2615 if (rewrite_checksums)
2616 rewrite_metadata_checksums(fs);
2618 if (mount_flags & EXT2_MF_MOUNTED) {
2619 fputs(_("The inode size may only be "
2620 "changed when the filesystem is "
2621 "unmounted.\n"), stderr);
2625 if (fs->super->s_feature_incompat &
2626 EXT4_FEATURE_INCOMPAT_FLEX_BG) {
2627 fputs(_("Changing the inode size not supported for "
2628 "filesystems with the flex_bg\n"
2629 "feature enabled.\n"),
2635 * We want to update group descriptor also
2636 * with the new free inode count
2638 fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
2639 if (resize_inode(fs, new_inode_size) == 0) {
2640 printf(_("Setting inode size %lu\n"),
2643 printf(_("Failed to change inode size\n"));
2652 sb->s_raid_stride = stride;
2653 ext2fs_mark_super_dirty(fs);
2654 printf(_("Setting stride size to %d\n"), stride);
2656 if (stripe_width_set) {
2657 sb->s_raid_stripe_width = stripe_width;
2658 ext2fs_mark_super_dirty(fs);
2659 printf(_("Setting stripe width to %d\n"), stripe_width);
2661 if (ext_mount_opts) {
2662 strncpy((char *)(fs->super->s_mount_opts), ext_mount_opts,
2663 sizeof(fs->super->s_mount_opts));
2664 fs->super->s_mount_opts[sizeof(fs->super->s_mount_opts)-1] = 0;
2665 ext2fs_mark_super_dirty(fs);
2666 printf(_("Setting extended default mount options to '%s'\n"),
2668 free(ext_mount_opts);
2671 remove_error_table(&et_ext2_error_table);
2675 ext2fs_mmp_stop(fs);
2679 return (ext2fs_close(fs) ? 1 : 0);