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;
76 static time_t last_check_time;
77 static int print_label;
78 static int max_mount_count, mount_count, mount_flags;
79 static unsigned long interval;
80 static blk64_t reserved_blocks;
81 static double reserved_ratio;
82 static unsigned long resgid, resuid;
83 static unsigned short errors;
85 static char *features_cmd;
86 static char *mntopts_cmd;
87 static int stride, stripe_width;
88 static int stride_set, stripe_width_set;
89 static char *extended_cmd;
90 static unsigned long new_inode_size;
91 static char *ext_mount_opts;
92 static int usrquota, grpquota;
94 int journal_size, journal_flags;
97 static struct list_head blk_move_list;
100 struct list_head list;
106 static const char *please_fsck = N_("Please run e2fsck on the filesystem.\n");
108 #ifdef CONFIG_BUILD_FINDFS
109 void do_findfs(int argc, char **argv);
112 static void usage(void)
115 _("Usage: %s [-c max_mounts_count] [-e errors_behavior] "
117 "\t[-i interval[d|m|w]] [-j] [-J journal_options] [-l]\n"
118 "\t[-m reserved_blocks_percent] "
119 "[-o [^]mount_options[,...]] \n"
120 "\t[-r reserved_blocks_count] [-u user] [-C mount_count] "
121 "[-L volume_label]\n"
122 "\t[-M last_mounted_dir] [-O [^]feature[,...]]\n"
123 "\t[-E extended-option[,...]] [-T last_check_time] "
124 "[-U UUID]\n\t[ -I new_inode_size ] device\n"), program_name);
128 static __u32 ok_features[3] = {
130 EXT3_FEATURE_COMPAT_HAS_JOURNAL |
131 EXT2_FEATURE_COMPAT_DIR_INDEX,
133 EXT2_FEATURE_INCOMPAT_FILETYPE |
134 EXT3_FEATURE_INCOMPAT_EXTENTS |
135 EXT4_FEATURE_INCOMPAT_FLEX_BG,
137 EXT2_FEATURE_RO_COMPAT_LARGE_FILE |
138 EXT4_FEATURE_RO_COMPAT_HUGE_FILE|
139 EXT4_FEATURE_RO_COMPAT_DIR_NLINK|
140 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE|
141 EXT4_FEATURE_RO_COMPAT_GDT_CSUM |
142 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER |
143 EXT4_FEATURE_RO_COMPAT_QUOTA
146 static __u32 clear_ok_features[3] = {
148 EXT3_FEATURE_COMPAT_HAS_JOURNAL |
149 EXT2_FEATURE_COMPAT_RESIZE_INODE |
150 EXT2_FEATURE_COMPAT_DIR_INDEX,
152 EXT2_FEATURE_INCOMPAT_FILETYPE |
153 EXT4_FEATURE_INCOMPAT_FLEX_BG,
155 EXT2_FEATURE_RO_COMPAT_LARGE_FILE |
156 EXT4_FEATURE_RO_COMPAT_HUGE_FILE|
157 EXT4_FEATURE_RO_COMPAT_DIR_NLINK|
158 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE|
159 EXT4_FEATURE_RO_COMPAT_GDT_CSUM |
160 EXT4_FEATURE_RO_COMPAT_QUOTA
164 * Remove an external journal from the filesystem
166 static void remove_journal_device(ext2_filsys fs)
171 journal_superblock_t *jsb;
174 int commit_remove_journal = 0;
178 commit_remove_journal = 1; /* force removal even if error */
180 uuid_unparse(fs->super->s_journal_uuid, buf);
181 journal_path = blkid_get_devname(NULL, "UUID", buf);
185 ext2fs_find_block_device(fs->super->s_journal_dev);
187 goto no_valid_journal;
190 #ifdef CONFIG_TESTIO_DEBUG
191 if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) {
192 io_ptr = test_io_manager;
193 test_io_backing_manager = unix_io_manager;
196 io_ptr = unix_io_manager;
197 retval = ext2fs_open(journal_path, EXT2_FLAG_RW|
198 EXT2_FLAG_JOURNAL_DEV_OK, 0,
199 fs->blocksize, io_ptr, &jfs);
201 com_err(program_name, retval,
202 _("while trying to open external journal"));
203 goto no_valid_journal;
205 if (!(jfs->super->s_feature_incompat &
206 EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)) {
207 fprintf(stderr, _("%s is not a journal device.\n"),
209 goto no_valid_journal;
212 /* Get the journal superblock */
213 if ((retval = io_channel_read_blk64(jfs->io, 1, -1024, buf))) {
214 com_err(program_name, retval,
215 _("while reading journal superblock"));
216 goto no_valid_journal;
219 jsb = (journal_superblock_t *) buf;
220 if ((jsb->s_header.h_magic != (unsigned)ntohl(JFS_MAGIC_NUMBER)) ||
221 (jsb->s_header.h_blocktype != (unsigned)ntohl(JFS_SUPERBLOCK_V2))) {
222 fputs(_("Journal superblock not found!\n"), stderr);
223 goto no_valid_journal;
226 /* Find the filesystem UUID */
227 nr_users = ntohl(jsb->s_nr_users);
228 for (i = 0; i < nr_users; i++) {
229 if (memcmp(fs->super->s_uuid, &jsb->s_users[i * 16], 16) == 0)
233 fputs(_("Filesystem's UUID not found on journal device.\n"),
235 commit_remove_journal = 1;
236 goto no_valid_journal;
239 for (i = 0; i < nr_users; i++)
240 memcpy(&jsb->s_users[i * 16], &jsb->s_users[(i + 1) * 16], 16);
241 jsb->s_nr_users = htonl(nr_users);
243 /* Write back the journal superblock */
244 if ((retval = io_channel_write_blk64(jfs->io, 1, -1024, buf))) {
245 com_err(program_name, retval,
246 "while writing journal superblock.");
247 goto no_valid_journal;
250 commit_remove_journal = 1;
253 if (commit_remove_journal == 0) {
254 fputs(_("Cannot locate journal device. It was NOT removed\n"
255 "Use -f option to remove missing journal device.\n"),
259 fs->super->s_journal_dev = 0;
260 uuid_clear(fs->super->s_journal_uuid);
261 ext2fs_mark_super_dirty(fs);
262 fputs(_("Journal removed\n"), stdout);
266 /* Helper function for remove_journal_inode */
267 static int release_blocks_proc(ext2_filsys fs, blk64_t *blocknr,
268 e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
269 blk64_t ref_block EXT2FS_ATTR((unused)),
270 int ref_offset EXT2FS_ATTR((unused)),
271 void *private EXT2FS_ATTR((unused)))
277 ext2fs_unmark_block_bitmap2(fs->block_map, block);
278 group = ext2fs_group_of_blk2(fs, block);
279 ext2fs_bg_free_blocks_count_set(fs, group, ext2fs_bg_free_blocks_count(fs, group) + 1);
280 ext2fs_group_desc_csum_set(fs, group);
281 ext2fs_free_blocks_count_add(fs->super, EXT2FS_CLUSTER_RATIO(fs));
286 * Remove the journal inode from the filesystem
288 static void remove_journal_inode(ext2_filsys fs)
290 struct ext2_inode inode;
292 ino_t ino = fs->super->s_journal_inum;
294 retval = ext2fs_read_inode(fs, ino, &inode);
296 com_err(program_name, retval,
297 _("while reading journal inode"));
300 if (ino == EXT2_JOURNAL_INO) {
301 retval = ext2fs_read_bitmaps(fs);
303 com_err(program_name, retval,
304 _("while reading bitmaps"));
307 retval = ext2fs_block_iterate3(fs, ino,
308 BLOCK_FLAG_READ_ONLY, NULL,
309 release_blocks_proc, NULL);
311 com_err(program_name, retval,
312 _("while clearing journal inode"));
315 memset(&inode, 0, sizeof(inode));
316 ext2fs_mark_bb_dirty(fs);
317 fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
319 inode.i_flags &= ~EXT2_IMMUTABLE_FL;
320 retval = ext2fs_write_inode(fs, ino, &inode);
322 com_err(program_name, retval,
323 _("while writing journal inode"));
326 fs->super->s_journal_inum = 0;
327 ext2fs_mark_super_dirty(fs);
331 * Update the default mount options
333 static void update_mntopts(ext2_filsys fs, char *mntopts)
335 struct ext2_super_block *sb = fs->super;
337 if (e2p_edit_mntopts(mntopts, &sb->s_default_mount_opts, ~0)) {
338 fprintf(stderr, _("Invalid mount option set: %s\n"),
342 ext2fs_mark_super_dirty(fs);
345 static void request_fsck_afterwards(ext2_filsys fs)
347 static int requested = 0;
351 fs->super->s_state &= ~EXT2_VALID_FS;
352 printf("\n%s\n", _(please_fsck));
353 if (mount_flags & EXT2_MF_READONLY)
354 printf(_("(and reboot afterwards!)\n"));
358 * Update the feature set as provided by the user.
360 static void update_feature_set(ext2_filsys fs, char *features)
362 struct ext2_super_block *sb = fs->super;
363 struct ext2_group_desc *gd;
364 __u32 old_features[3];
366 unsigned int mask_err;
368 #define FEATURE_ON(type, mask) (!(old_features[(type)] & (mask)) && \
369 ((&sb->s_feature_compat)[(type)] & (mask)))
370 #define FEATURE_OFF(type, mask) ((old_features[(type)] & (mask)) && \
371 !((&sb->s_feature_compat)[(type)] & (mask)))
372 #define FEATURE_CHANGED(type, mask) ((mask) & \
373 (old_features[(type)] ^ (&sb->s_feature_compat)[(type)]))
375 old_features[E2P_FEATURE_COMPAT] = sb->s_feature_compat;
376 old_features[E2P_FEATURE_INCOMPAT] = sb->s_feature_incompat;
377 old_features[E2P_FEATURE_RO_INCOMPAT] = sb->s_feature_ro_compat;
379 if (e2p_edit_feature2(features, &sb->s_feature_compat,
380 ok_features, clear_ok_features,
381 &type_err, &mask_err)) {
384 _("Invalid filesystem option set: %s\n"),
386 else if (type_err & E2P_FEATURE_NEGATE_FLAG)
387 fprintf(stderr, _("Clearing filesystem feature '%s' "
389 e2p_feature2string(type_err &
390 E2P_FEATURE_TYPE_MASK,
393 fprintf(stderr, _("Setting filesystem feature '%s' "
395 e2p_feature2string(type_err, mask_err));
399 if (FEATURE_OFF(E2P_FEATURE_COMPAT, EXT3_FEATURE_COMPAT_HAS_JOURNAL)) {
400 if ((mount_flags & EXT2_MF_MOUNTED) &&
401 !(mount_flags & EXT2_MF_READONLY)) {
402 fputs(_("The has_journal feature may only be "
403 "cleared when the filesystem is\n"
404 "unmounted or mounted "
405 "read-only.\n"), stderr);
408 if (sb->s_feature_incompat &
409 EXT3_FEATURE_INCOMPAT_RECOVER) {
410 fputs(_("The needs_recovery flag is set. "
411 "Please run e2fsck before clearing\n"
412 "the has_journal flag.\n"), stderr);
415 if (sb->s_journal_inum) {
416 remove_journal_inode(fs);
418 if (sb->s_journal_dev) {
419 remove_journal_device(fs);
423 if (FEATURE_ON(E2P_FEATURE_COMPAT, EXT3_FEATURE_COMPAT_HAS_JOURNAL)) {
425 * If adding a journal flag, let the create journal
426 * code below handle setting the flag and creating the
427 * journal. We supply a default size if necessary.
431 sb->s_feature_compat &= ~EXT3_FEATURE_COMPAT_HAS_JOURNAL;
434 if (FEATURE_ON(E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_DIR_INDEX)) {
435 if (!sb->s_def_hash_version)
436 sb->s_def_hash_version = EXT2_HASH_HALF_MD4;
437 if (uuid_is_null((unsigned char *) sb->s_hash_seed))
438 uuid_generate((unsigned char *) sb->s_hash_seed);
441 if (FEATURE_OFF(E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_FLEX_BG)) {
442 if (ext2fs_check_desc(fs)) {
443 fputs(_("Clearing the flex_bg flag would "
444 "cause the the filesystem to be\n"
445 "inconsistent.\n"), stderr);
450 if (FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT,
451 EXT4_FEATURE_RO_COMPAT_HUGE_FILE)) {
452 if ((mount_flags & EXT2_MF_MOUNTED) &&
453 !(mount_flags & EXT2_MF_READONLY)) {
454 fputs(_("The huge_file feature may only be "
455 "cleared when the filesystem is\n"
456 "unmounted or mounted "
457 "read-only.\n"), stderr);
462 if (FEATURE_ON(E2P_FEATURE_RO_INCOMPAT,
463 EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
464 for (i = 0; i < fs->group_desc_count; i++) {
465 gd = ext2fs_group_desc(fs, fs->group_desc, i);
466 gd->bg_itable_unused = 0;
467 gd->bg_flags = EXT2_BG_INODE_ZEROED;
468 ext2fs_group_desc_csum_set(fs, i);
470 fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
473 if (FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT,
474 EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
475 for (i = 0; i < fs->group_desc_count; i++) {
476 gd = ext2fs_group_desc(fs, fs->group_desc, i);
477 if ((gd->bg_flags & EXT2_BG_INODE_ZEROED) == 0) {
479 * XXX what we really should do is zap
480 * uninitialized inode tables instead.
482 request_fsck_afterwards(fs);
485 gd->bg_itable_unused = 0;
489 fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
492 if (FEATURE_ON(E2P_FEATURE_RO_INCOMPAT,
493 EXT4_FEATURE_RO_COMPAT_QUOTA)) {
495 * Set the Q_flag here and handle the quota options in the code
500 /* Enable both user quota and group quota by default */
501 usrquota = QOPT_ENABLE;
502 grpquota = QOPT_ENABLE;
504 sb->s_feature_ro_compat &= ~EXT4_FEATURE_RO_COMPAT_QUOTA;
507 if (FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT,
508 EXT4_FEATURE_RO_COMPAT_QUOTA)) {
510 * Set the Q_flag here and handle the quota options in the code
514 fputs(_("\nWarning: '^quota' option overrides '-Q'"
515 "arguments.\n"), stderr);
517 /* Disable both user quota and group quota by default */
518 usrquota = QOPT_DISABLE;
519 grpquota = QOPT_DISABLE;
522 if (sb->s_rev_level == EXT2_GOOD_OLD_REV &&
523 (sb->s_feature_compat || sb->s_feature_ro_compat ||
524 sb->s_feature_incompat))
525 ext2fs_update_dynamic_rev(fs);
527 if (FEATURE_CHANGED(E2P_FEATURE_RO_INCOMPAT,
528 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER) ||
529 FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT,
530 EXT4_FEATURE_RO_COMPAT_HUGE_FILE) ||
531 FEATURE_CHANGED(E2P_FEATURE_INCOMPAT,
532 EXT2_FEATURE_INCOMPAT_FILETYPE) ||
533 FEATURE_CHANGED(E2P_FEATURE_COMPAT,
534 EXT2_FEATURE_COMPAT_RESIZE_INODE) ||
535 FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT,
536 EXT2_FEATURE_RO_COMPAT_LARGE_FILE))
537 request_fsck_afterwards(fs);
539 if ((old_features[E2P_FEATURE_COMPAT] != sb->s_feature_compat) ||
540 (old_features[E2P_FEATURE_INCOMPAT] != sb->s_feature_incompat) ||
541 (old_features[E2P_FEATURE_RO_INCOMPAT] != sb->s_feature_ro_compat))
542 ext2fs_mark_super_dirty(fs);
546 * Add a journal to the filesystem.
548 static void add_journal(ext2_filsys fs)
550 unsigned long journal_blocks;
555 if (fs->super->s_feature_compat &
556 EXT3_FEATURE_COMPAT_HAS_JOURNAL) {
557 fputs(_("The filesystem already has a journal.\n"), stderr);
560 if (journal_device) {
561 check_plausibility(journal_device);
562 check_mount(journal_device, 0, _("journal"));
563 #ifdef CONFIG_TESTIO_DEBUG
564 if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) {
565 io_ptr = test_io_manager;
566 test_io_backing_manager = unix_io_manager;
569 io_ptr = unix_io_manager;
570 retval = ext2fs_open(journal_device, EXT2_FLAG_RW|
571 EXT2_FLAG_JOURNAL_DEV_OK, 0,
572 fs->blocksize, io_ptr, &jfs);
574 com_err(program_name, retval,
575 _("\n\twhile trying to open journal on %s\n"),
579 printf(_("Creating journal on device %s: "),
583 retval = ext2fs_add_journal_device(fs, jfs);
586 com_err(program_name, retval,
587 _("while adding filesystem to journal on %s"),
591 fputs(_("done\n"), stdout);
592 } else if (journal_size) {
593 fputs(_("Creating journal inode: "), stdout);
595 journal_blocks = figure_journal_size(journal_size, fs);
597 retval = ext2fs_add_journal_inode(fs, journal_blocks,
600 fprintf(stderr, "\n");
601 com_err(program_name, retval,
602 _("\n\twhile trying to create journal file"));
605 fputs(_("done\n"), stdout);
607 * If the filesystem wasn't mounted, we need to force
608 * the block group descriptors out.
610 if ((mount_flags & EXT2_MF_MOUNTED) == 0)
611 fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
613 print_check_message(fs->super->s_max_mnt_count,
614 fs->super->s_checkinterval);
618 free(journal_device);
622 void handle_quota_options(ext2_filsys fs)
628 if (!usrquota && !grpquota)
632 init_quota_context(&qctx, fs, -1);
634 if (usrquota == QOPT_ENABLE && !fs->super->s_usr_quota_inum) {
635 if ((qf_ino = quota_file_exists(fs, USRQUOTA, QFMT_VFS_V1)) > 0)
636 set_sb_quota_inum(fs, qf_ino, USRQUOTA);
638 write_quota_inode(qctx, USRQUOTA);
639 } else if (usrquota == QOPT_DISABLE) {
640 remove_quota_inode(fs, USRQUOTA);
643 if (grpquota == QOPT_ENABLE && !fs->super->s_grp_quota_inum) {
644 if ((qf_ino = quota_file_exists(fs, GRPQUOTA, QFMT_VFS_V1)) > 0)
645 set_sb_quota_inum(fs, qf_ino, GRPQUOTA);
647 write_quota_inode(qctx, GRPQUOTA);
648 } else if (grpquota == QOPT_DISABLE) {
649 remove_quota_inode(fs, GRPQUOTA);
652 release_quota_context(&qctx);
654 if ((usrquota == QOPT_ENABLE) || (grpquota == QOPT_ENABLE)) {
655 fs->super->s_feature_ro_compat |= EXT4_FEATURE_RO_COMPAT_QUOTA;
656 ext2fs_mark_super_dirty(fs);
657 } else if ((usrquota == QOPT_DISABLE) && (grpquota == QOPT_DISABLE)) {
658 fs->super->s_feature_ro_compat &= ~EXT4_FEATURE_RO_COMPAT_QUOTA;
659 ext2fs_mark_super_dirty(fs);
665 void parse_quota_opts(const char *opts)
667 char *buf, *token, *next, *p, *arg;
673 fputs(_("Couldn't allocate memory to parse quota "
674 "options!\n"), stderr);
678 for (token = buf; token && *token; token = next) {
679 p = strchr(token, ',');
686 if (strcmp(token, "usrquota") == 0) {
687 usrquota = QOPT_ENABLE;
688 } else if (strcmp(token, "^usrquota") == 0) {
689 usrquota = QOPT_DISABLE;
690 } else if (strcmp(token, "grpquota") == 0) {
691 grpquota = QOPT_ENABLE;
692 } else if (strcmp(token, "^grpquota") == 0) {
693 grpquota = QOPT_DISABLE;
695 fputs(_("\nBad quota options specified.\n\n"
696 "Following valid quota options are available "
697 "(pass by separating with comma):\n"
710 static void parse_e2label_options(int argc, char ** argv)
712 if ((argc < 2) || (argc > 3)) {
713 fputs(_("Usage: e2label device [newlabel]\n"), stderr);
716 io_options = strchr(argv[1], '?');
719 device_name = blkid_get_devname(NULL, argv[1], NULL);
721 com_err("e2label", 0, _("Unable to resolve '%s'"),
725 open_flag = EXT2_FLAG_JOURNAL_DEV_OK;
727 open_flag |= EXT2_FLAG_RW;
734 static time_t parse_time(char *str)
738 if (strcmp(str, "now") == 0) {
741 memset(&ts, 0, sizeof(ts));
743 strptime(str, "%Y%m%d%H%M%S", &ts);
745 sscanf(str, "%4d%2d%2d%2d%2d%2d", &ts.tm_year, &ts.tm_mon,
746 &ts.tm_mday, &ts.tm_hour, &ts.tm_min, &ts.tm_sec);
749 if (ts.tm_year < 0 || ts.tm_mon < 0 || ts.tm_mon > 11 ||
750 ts.tm_mday < 0 || ts.tm_mday > 31 || ts.tm_hour > 23 ||
751 ts.tm_min > 59 || ts.tm_sec > 61)
754 if (ts.tm_mday == 0) {
755 com_err(program_name, 0,
756 _("Couldn't parse date/time specifier: %s"),
761 return (mktime(&ts));
764 static void parse_tune2fs_options(int argc, char **argv)
773 printf("tune2fs %s (%s)\n", E2FSPROGS_VERSION, E2FSPROGS_DATE);
774 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)
777 max_mount_count = strtol(optarg, &tmp, 0);
778 if (*tmp || max_mount_count > 16000) {
779 com_err(program_name, 0,
780 _("bad mounts count - %s"),
784 if (max_mount_count == 0)
785 max_mount_count = -1;
787 open_flag = EXT2_FLAG_RW;
790 mount_count = strtoul(optarg, &tmp, 0);
791 if (*tmp || mount_count > 16000) {
792 com_err(program_name, 0,
793 _("bad mounts count - %s"),
798 open_flag = EXT2_FLAG_RW;
801 if (strcmp(optarg, "continue") == 0)
802 errors = EXT2_ERRORS_CONTINUE;
803 else if (strcmp(optarg, "remount-ro") == 0)
804 errors = EXT2_ERRORS_RO;
805 else if (strcmp(optarg, "panic") == 0)
806 errors = EXT2_ERRORS_PANIC;
808 com_err(program_name, 0,
809 _("bad error behavior - %s"),
814 open_flag = EXT2_FLAG_RW;
817 extended_cmd = optarg;
818 open_flag |= EXT2_FLAG_RW;
820 case 'f': /* Force */
824 resgid = strtoul(optarg, &tmp, 0);
826 gr = getgrnam(optarg);
835 com_err(program_name, 0,
836 _("bad gid/group name - %s"),
841 open_flag = EXT2_FLAG_RW;
844 interval = strtoul(optarg, &tmp, 0);
857 case 'M': /* months! */
858 interval *= 86400 * 30;
862 case 'W': /* weeks */
863 interval *= 86400 * 7;
868 com_err(program_name, 0,
869 _("bad interval - %s"), optarg);
873 open_flag = EXT2_FLAG_RW;
878 open_flag = EXT2_FLAG_RW;
881 parse_journal_opts(optarg);
882 open_flag = EXT2_FLAG_RW;
890 open_flag |= EXT2_FLAG_RW |
891 EXT2_FLAG_JOURNAL_DEV_OK;
894 reserved_ratio = strtod(optarg, &tmp);
895 if (*tmp || reserved_ratio > 50 ||
896 reserved_ratio < 0) {
897 com_err(program_name, 0,
898 _("bad reserved block ratio - %s"),
903 open_flag = EXT2_FLAG_RW;
906 new_last_mounted = optarg;
908 open_flag = EXT2_FLAG_RW;
912 com_err(program_name, 0,
913 _("-o may only be specified once"));
916 mntopts_cmd = optarg;
917 open_flag = EXT2_FLAG_RW;
922 com_err(program_name, 0,
923 _("-O may only be specified once"));
926 features_cmd = optarg;
927 open_flag = EXT2_FLAG_RW;
931 parse_quota_opts(optarg);
932 open_flag = EXT2_FLAG_RW;
935 reserved_blocks = strtoul(optarg, &tmp, 0);
937 com_err(program_name, 0,
938 _("bad reserved blocks count - %s"),
943 open_flag = EXT2_FLAG_RW;
945 case 's': /* Deprecated */
946 s_flag = atoi(optarg);
947 open_flag = EXT2_FLAG_RW;
951 last_check_time = parse_time(optarg);
952 open_flag = EXT2_FLAG_RW;
955 resuid = strtoul(optarg, &tmp, 0);
957 pw = getpwnam(optarg);
966 com_err(program_name, 0,
967 _("bad uid/user name - %s"),
972 open_flag = EXT2_FLAG_RW;
977 open_flag = EXT2_FLAG_RW |
978 EXT2_FLAG_JOURNAL_DEV_OK;
981 new_inode_size = strtoul(optarg, &tmp, 0);
983 com_err(program_name, 0,
984 _("bad inode size - %s"),
988 if (!((new_inode_size &
989 (new_inode_size - 1)) == 0)) {
990 com_err(program_name, 0,
991 _("Inode size must be a "
996 open_flag = EXT2_FLAG_RW;
1002 if (optind < argc - 1 || optind == argc)
1004 if (!open_flag && !l_flag)
1006 io_options = strchr(argv[optind], '?');
1009 device_name = blkid_get_devname(NULL, argv[optind], NULL);
1011 com_err("tune2fs", 0, _("Unable to resolve '%s'"),
1017 #ifdef CONFIG_BUILD_FINDFS
1018 void do_findfs(int argc, char **argv)
1023 (strncmp(argv[1], "LABEL=", 6) && strncmp(argv[1], "UUID=", 5))) {
1024 fprintf(stderr, "Usage: findfs LABEL=<label>|UUID=<uuid>\n");
1027 dev = blkid_get_devname(NULL, argv[1], NULL);
1029 com_err("findfs", 0, _("Unable to resolve '%s'"),
1038 static void parse_extended_opts(ext2_filsys fs, const char *opts)
1040 char *buf, *token, *next, *p, *arg;
1045 buf = malloc(len+1);
1048 _("Couldn't allocate memory to parse options!\n"));
1052 for (token = buf; token && *token; token = next) {
1053 p = strchr(token, ',');
1059 arg = strchr(token, '=');
1064 if (!strcmp(token, "test_fs")) {
1065 fs->super->s_flags |= EXT2_FLAGS_TEST_FILESYS;
1066 printf("Setting test filesystem flag\n");
1067 ext2fs_mark_super_dirty(fs);
1068 } else if (!strcmp(token, "^test_fs")) {
1069 fs->super->s_flags &= ~EXT2_FLAGS_TEST_FILESYS;
1070 printf("Clearing test filesystem flag\n");
1071 ext2fs_mark_super_dirty(fs);
1072 } else if (strcmp(token, "stride") == 0) {
1077 stride = strtoul(arg, &p, 0);
1080 _("Invalid RAID stride: %s\n"),
1086 } else if (strcmp(token, "stripe-width") == 0 ||
1087 strcmp(token, "stripe_width") == 0) {
1092 stripe_width = strtoul(arg, &p, 0);
1095 _("Invalid RAID stripe-width: %s\n"),
1100 stripe_width_set = 1;
1101 } else if (strcmp(token, "hash_alg") == 0 ||
1102 strcmp(token, "hash-alg") == 0) {
1107 hash_alg = e2p_string2hash(arg);
1110 _("Invalid hash algorithm: %s\n"),
1115 fs->super->s_def_hash_version = hash_alg;
1116 printf(_("Setting default hash algorithm "
1119 ext2fs_mark_super_dirty(fs);
1120 } else if (!strcmp(token, "mount_opts")) {
1125 if (strlen(arg) >= sizeof(fs->super->s_mount_opts)) {
1127 "Extended mount options too long\n");
1130 ext_mount_opts = strdup(arg);
1135 fprintf(stderr, _("\nBad options specified.\n\n"
1136 "Extended options are separated by commas, "
1137 "and may take an argument which\n"
1138 "\tis set off by an equals ('=') sign.\n\n"
1139 "Valid extended options are:\n"
1140 "\thash_alg=<hash algorithm>\n"
1141 "\tmount_opts=<extended default mount options>\n"
1142 "\tstride=<RAID per-disk chunk size in blocks>\n"
1143 "\tstripe_width=<RAID stride*data disks in blocks>\n"
1153 * Fill in the block bitmap bmap with the information regarding the
1154 * blocks to be moved
1156 static int get_move_bitmaps(ext2_filsys fs, int new_ino_blks_per_grp,
1157 ext2fs_block_bitmap bmap)
1161 ext2_badblocks_list bb_list = 0;
1162 blk64_t j, needed_blocks = 0;
1163 blk64_t start_blk, end_blk;
1165 retval = ext2fs_read_bb_inode(fs, &bb_list);
1169 for (i = 0; i < fs->group_desc_count; i++) {
1170 start_blk = ext2fs_inode_table_loc(fs, i) +
1171 fs->inode_blocks_per_group;
1173 end_blk = ext2fs_inode_table_loc(fs, i) +
1174 new_ino_blks_per_grp;
1176 for (j = start_blk; j < end_blk; j++) {
1177 if (ext2fs_test_block_bitmap2(fs->block_map, j)) {
1179 * IF the block is a bad block we fail
1181 if (ext2fs_badblocks_list_test(bb_list, j)) {
1182 ext2fs_badblocks_list_free(bb_list);
1186 ext2fs_mark_block_bitmap2(bmap, j);
1189 * We are going to use this block for
1190 * inode table. So mark them used.
1192 ext2fs_mark_block_bitmap2(fs->block_map, j);
1195 needed_blocks += end_blk - start_blk;
1198 ext2fs_badblocks_list_free(bb_list);
1199 if (needed_blocks > ext2fs_free_blocks_count(fs->super))
1205 static int ext2fs_is_meta_block(ext2_filsys fs, blk_t blk)
1208 group = ext2fs_group_of_blk(fs, blk);
1209 if (ext2fs_block_bitmap_loc(fs, group) == blk)
1211 if (ext2fs_inode_bitmap_loc(fs, group) == blk)
1216 static int ext2fs_is_block_in_group(ext2_filsys fs, dgrp_t group, blk_t blk)
1218 blk_t start_blk, end_blk;
1219 start_blk = fs->super->s_first_data_block +
1220 EXT2_BLOCKS_PER_GROUP(fs->super) * group;
1222 * We cannot get new block beyond end_blk for for the last block group
1223 * so we can check with EXT2_BLOCKS_PER_GROUP even for last block group
1225 end_blk = start_blk + EXT2_BLOCKS_PER_GROUP(fs->super);
1226 if (blk >= start_blk && blk <= end_blk)
1231 static int move_block(ext2_filsys fs, ext2fs_block_bitmap bmap)
1238 blk64_t blk, new_blk, goal;
1239 struct blk_move *bmv;
1241 retval = ext2fs_get_mem(fs->blocksize, &buf);
1245 for (new_blk = blk = fs->super->s_first_data_block;
1246 blk < ext2fs_blocks_count(fs->super); blk++) {
1247 if (!ext2fs_test_block_bitmap2(bmap, blk))
1250 if (ext2fs_is_meta_block(fs, blk)) {
1252 * If the block is mapping a fs meta data block
1253 * like group desc/block bitmap/inode bitmap. We
1254 * should find a block in the same group and fix
1255 * the respective fs metadata pointers. Otherwise
1258 group = ext2fs_group_of_blk(fs, blk);
1259 goal = ext2fs_group_first_block2(fs, group);
1265 retval = ext2fs_new_block2(fs, goal, NULL, &new_blk);
1269 /* new fs meta data block should be in the same group */
1270 if (meta_data && !ext2fs_is_block_in_group(fs, group, new_blk)) {
1275 /* Mark this block as allocated */
1276 ext2fs_mark_block_bitmap2(fs->block_map, new_blk);
1278 /* Add it to block move list */
1279 retval = ext2fs_get_mem(sizeof(struct blk_move), &bmv);
1284 bmv->new_loc = new_blk;
1286 list_add(&(bmv->list), &blk_move_list);
1288 retval = io_channel_read_blk64(fs->io, blk, 1, buf);
1292 retval = io_channel_write_blk64(fs->io, new_blk, 1, buf);
1298 ext2fs_free_mem(&buf);
1302 static blk64_t translate_block(blk64_t blk)
1304 struct list_head *entry;
1305 struct blk_move *bmv;
1307 list_for_each(entry, &blk_move_list) {
1308 bmv = list_entry(entry, struct blk_move, list);
1309 if (bmv->old_loc == blk)
1310 return bmv->new_loc;
1316 static int process_block(ext2_filsys fs EXT2FS_ATTR((unused)),
1318 e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
1319 blk64_t ref_block EXT2FS_ATTR((unused)),
1320 int ref_offset EXT2FS_ATTR((unused)),
1325 ext2fs_block_bitmap bmap = (ext2fs_block_bitmap) priv_data;
1327 if (!ext2fs_test_block_bitmap2(bmap, *block_nr))
1329 new_blk = translate_block(*block_nr);
1331 *block_nr = new_blk;
1333 * This will force the ext2fs_write_inode in the iterator
1335 ret |= BLOCK_CHANGED;
1341 static int inode_scan_and_fix(ext2_filsys fs, ext2fs_block_bitmap bmap)
1343 errcode_t retval = 0;
1346 char *block_buf = 0;
1347 struct ext2_inode inode;
1348 ext2_inode_scan scan = NULL;
1350 retval = ext2fs_get_mem(fs->blocksize * 3, &block_buf);
1354 retval = ext2fs_open_inode_scan(fs, 0, &scan);
1359 retval = ext2fs_get_next_inode(scan, &ino, &inode);
1366 if (inode.i_links_count == 0)
1367 continue; /* inode not in use */
1370 * If we end up modifying the journal inode
1371 * the sb->s_jnl_blocks will differ. But a
1372 * subsequent e2fsck fixes that.
1373 * Do we need to fix this ??
1376 if (ext2fs_file_acl_block(&inode) &&
1377 ext2fs_test_block_bitmap2(bmap,
1378 ext2fs_file_acl_block(&inode))) {
1379 blk = translate_block(ext2fs_file_acl_block(&inode));
1383 ext2fs_file_acl_block_set(&inode, blk);
1386 * Write the inode to disk so that inode table
1389 retval = ext2fs_write_inode(fs, ino, &inode);
1394 if (!ext2fs_inode_has_valid_blocks(&inode))
1397 retval = ext2fs_block_iterate3(fs, ino, 0, block_buf,
1398 process_block, bmap);
1405 ext2fs_free_mem(&block_buf);
1411 * We need to scan for inode and block bitmaps that may need to be
1412 * moved. This can take place if the filesystem was formatted for
1413 * RAID arrays using the mke2fs's extended option "stride".
1415 static int group_desc_scan_and_fix(ext2_filsys fs, ext2fs_block_bitmap bmap)
1420 for (i = 0; i < fs->group_desc_count; i++) {
1421 blk = ext2fs_block_bitmap_loc(fs, i);
1422 if (ext2fs_test_block_bitmap2(bmap, blk)) {
1423 new_blk = translate_block(blk);
1426 ext2fs_block_bitmap_loc_set(fs, i, new_blk);
1429 blk = ext2fs_inode_bitmap_loc(fs, i);
1430 if (ext2fs_test_block_bitmap2(bmap, blk)) {
1431 new_blk = translate_block(blk);
1434 ext2fs_inode_bitmap_loc_set(fs, i, new_blk);
1440 static int expand_inode_table(ext2_filsys fs, unsigned long new_ino_size)
1445 int new_ino_blks_per_grp;
1447 char *old_itable = NULL, *new_itable = NULL;
1448 char *tmp_old_itable = NULL, *tmp_new_itable = NULL;
1449 unsigned long old_ino_size;
1450 int old_itable_size, new_itable_size;
1452 old_itable_size = fs->inode_blocks_per_group * fs->blocksize;
1453 old_ino_size = EXT2_INODE_SIZE(fs->super);
1455 new_ino_blks_per_grp = ext2fs_div_ceil(
1456 EXT2_INODES_PER_GROUP(fs->super) *
1460 new_itable_size = new_ino_blks_per_grp * fs->blocksize;
1462 retval = ext2fs_get_mem(old_itable_size, &old_itable);
1466 retval = ext2fs_get_mem(new_itable_size, &new_itable);
1470 tmp_old_itable = old_itable;
1471 tmp_new_itable = new_itable;
1473 for (i = 0; i < fs->group_desc_count; i++) {
1474 blk = ext2fs_inode_table_loc(fs, i);
1475 retval = io_channel_read_blk64(fs->io, blk,
1476 fs->inode_blocks_per_group, old_itable);
1480 for (j = 0; j < EXT2_INODES_PER_GROUP(fs->super); j++) {
1481 memcpy(new_itable, old_itable, old_ino_size);
1483 memset(new_itable+old_ino_size, 0,
1484 new_ino_size - old_ino_size);
1486 new_itable += new_ino_size;
1487 old_itable += old_ino_size;
1490 /* reset the pointer */
1491 old_itable = tmp_old_itable;
1492 new_itable = tmp_new_itable;
1494 retval = io_channel_write_blk64(fs->io, blk,
1495 new_ino_blks_per_grp, new_itable);
1500 /* Update the meta data */
1501 fs->inode_blocks_per_group = new_ino_blks_per_grp;
1502 fs->super->s_inode_size = new_ino_size;
1506 ext2fs_free_mem(&old_itable);
1509 ext2fs_free_mem(&new_itable);
1514 static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs)
1518 unsigned int group = 0;
1519 unsigned int count = 0;
1524 * First calculate the block statistics
1526 for (blk = fs->super->s_first_data_block;
1527 blk < ext2fs_blocks_count(fs->super); blk++) {
1528 if (!ext2fs_fast_test_block_bitmap2(fs->block_map, blk)) {
1533 if ((count == fs->super->s_blocks_per_group) ||
1534 (blk == ext2fs_blocks_count(fs->super)-1)) {
1535 ext2fs_bg_free_blocks_count_set(fs, group++,
1541 total_free = EXT2FS_C2B(fs, total_free);
1542 ext2fs_free_blocks_count_set(fs->super, total_free);
1545 * Next, calculate the inode statistics
1552 /* Protect loop from wrap-around if s_inodes_count maxed */
1553 for (ino = 1; ino <= fs->super->s_inodes_count && ino > 0; ino++) {
1554 if (!ext2fs_fast_test_inode_bitmap2(fs->inode_map, ino)) {
1559 if ((count == fs->super->s_inodes_per_group) ||
1560 (ino == fs->super->s_inodes_count)) {
1561 ext2fs_bg_free_inodes_count_set(fs, group++,
1567 fs->super->s_free_inodes_count = total_free;
1568 ext2fs_mark_super_dirty(fs);
1572 #define list_for_each_safe(pos, pnext, head) \
1573 for (pos = (head)->next, pnext = pos->next; pos != (head); \
1574 pos = pnext, pnext = pos->next)
1576 static void free_blk_move_list(void)
1578 struct list_head *entry, *tmp;
1579 struct blk_move *bmv;
1581 list_for_each_safe(entry, tmp, &blk_move_list) {
1582 bmv = list_entry(entry, struct blk_move, list);
1584 ext2fs_free_mem(&bmv);
1589 static int resize_inode(ext2_filsys fs, unsigned long new_size)
1592 int new_ino_blks_per_grp;
1593 ext2fs_block_bitmap bmap;
1595 retval = ext2fs_read_inode_bitmap(fs);
1597 fputs(_("Failed to read inode bitmap\n"), stderr);
1600 retval = ext2fs_read_block_bitmap(fs);
1602 fputs(_("Failed to read blockbitmap\n"), stderr);
1605 INIT_LIST_HEAD(&blk_move_list);
1608 new_ino_blks_per_grp = ext2fs_div_ceil(
1609 EXT2_INODES_PER_GROUP(fs->super)*
1613 /* We may change the file system.
1614 * Mark the file system as invalid so that
1615 * the user is prompted to run fsck.
1617 fs->super->s_state &= ~EXT2_VALID_FS;
1619 retval = ext2fs_allocate_block_bitmap(fs, _("blocks to be moved"),
1622 fputs(_("Failed to allocate block bitmap when "
1623 "increasing inode size\n"), stderr);
1626 retval = get_move_bitmaps(fs, new_ino_blks_per_grp, bmap);
1628 fputs(_("Not enough space to increase inode size \n"), stderr);
1631 retval = move_block(fs, bmap);
1633 fputs(_("Failed to relocate blocks during inode resize \n"),
1637 retval = inode_scan_and_fix(fs, bmap);
1641 retval = group_desc_scan_and_fix(fs, bmap);
1645 retval = expand_inode_table(fs, new_size);
1649 ext2fs_calculate_summary_stats(fs);
1651 fs->super->s_state |= EXT2_VALID_FS;
1652 /* mark super block and block bitmap as dirty */
1653 ext2fs_mark_super_dirty(fs);
1654 ext2fs_mark_bb_dirty(fs);
1657 free_blk_move_list();
1658 ext2fs_free_block_bitmap(bmap);
1663 free_blk_move_list();
1664 ext2fs_free_block_bitmap(bmap);
1665 fputs(_("Error in resizing the inode size.\n"
1666 "Run e2undo to undo the "
1667 "file system changes. \n"), stderr);
1672 static int tune2fs_setup_tdb(const char *name, io_manager *io_ptr)
1674 errcode_t retval = 0;
1675 const char *tdb_dir;
1677 char *dev_name, *tmp_name;
1681 * Configuration via a conf file would be
1684 profile_get_string(profile, "scratch_files",
1688 tmp_name = strdup(name);
1691 com_err(program_name, ENOMEM,
1692 _("Couldn't allocate memory for tdb filename\n"));
1695 dev_name = basename(tmp_name);
1697 tdb_dir = getenv("E2FSPROGS_UNDO_DIR");
1699 tdb_dir = "/var/lib/e2fsprogs";
1701 if (!strcmp(tdb_dir, "none") || (tdb_dir[0] == 0) ||
1702 access(tdb_dir, W_OK))
1705 tdb_file = malloc(strlen(tdb_dir) + 9 + strlen(dev_name) + 7 + 1);
1708 sprintf(tdb_file, "%s/tune2fs-%s.e2undo", tdb_dir, dev_name);
1710 if (!access(tdb_file, F_OK)) {
1711 if (unlink(tdb_file) < 0) {
1713 com_err(program_name, retval,
1714 _("while trying to delete %s"),
1721 set_undo_io_backing_manager(*io_ptr);
1722 *io_ptr = undo_io_manager;
1723 set_undo_io_backup_file(tdb_file);
1724 printf(_("To undo the tune2fs operation please run "
1725 "the command\n e2undo %s %s\n\n"),
1732 int main(int argc, char **argv)
1736 struct ext2_super_block *sb;
1737 io_manager io_ptr, io_ptr_orig = NULL;
1740 setlocale(LC_MESSAGES, "");
1741 setlocale(LC_CTYPE, "");
1742 bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
1743 textdomain(NLS_CAT_NAME);
1746 program_name = *argv;
1747 add_error_table(&et_ext2_error_table);
1749 #ifdef CONFIG_BUILD_FINDFS
1750 if (strcmp(get_progname(argv[0]), "findfs") == 0)
1751 do_findfs(argc, argv);
1753 if (strcmp(get_progname(argv[0]), "e2label") == 0)
1754 parse_e2label_options(argc, argv);
1756 parse_tune2fs_options(argc, argv);
1758 #ifdef CONFIG_TESTIO_DEBUG
1759 if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_DEBUG")) {
1760 io_ptr = test_io_manager;
1761 test_io_backing_manager = unix_io_manager;
1764 io_ptr = unix_io_manager;
1767 retval = ext2fs_open2(device_name, io_options, open_flag,
1770 com_err(program_name, retval,
1771 _("while trying to open %s"),
1774 _("Couldn't find valid filesystem superblock.\n"));
1778 if (I_flag && !io_ptr_orig) {
1780 * Check the inode size is right so we can issue an
1781 * error message and bail before setting up the tdb
1784 if (new_inode_size == EXT2_INODE_SIZE(fs->super)) {
1785 fprintf(stderr, _("The inode size is already %lu\n"),
1789 if (new_inode_size < EXT2_INODE_SIZE(fs->super)) {
1790 fprintf(stderr, _("Shrinking the inode size is "
1791 "not supported\n"));
1796 * If inode resize is requested use the
1799 io_ptr_orig = io_ptr;
1800 retval = tune2fs_setup_tdb(device_name, &io_ptr);
1803 if (io_ptr != io_ptr_orig) {
1810 fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
1813 /* For e2label emulation */
1814 printf("%.*s\n", (int) sizeof(sb->s_volume_name),
1816 remove_error_table(&et_ext2_error_table);
1820 retval = ext2fs_check_if_mounted(device_name, &mount_flags);
1822 com_err("ext2fs_check_if_mount", retval,
1823 _("while determining whether %s is mounted."),
1827 /* Normally we only need to write out the superblock */
1828 fs->flags |= EXT2_FLAG_SUPER_ONLY;
1831 sb->s_max_mnt_count = max_mount_count;
1832 ext2fs_mark_super_dirty(fs);
1833 printf(_("Setting maximal mount count to %d\n"),
1837 sb->s_mnt_count = mount_count;
1838 ext2fs_mark_super_dirty(fs);
1839 printf(_("Setting current mount count to %d\n"), mount_count);
1842 sb->s_errors = errors;
1843 ext2fs_mark_super_dirty(fs);
1844 printf(_("Setting error behavior to %d\n"), errors);
1847 sb->s_def_resgid = resgid;
1848 ext2fs_mark_super_dirty(fs);
1849 printf(_("Setting reserved blocks gid to %lu\n"), resgid);
1852 if (interval >= (1ULL << 32)) {
1853 com_err(program_name, 0,
1854 _("interval between checks is too big (%lu)"),
1858 sb->s_checkinterval = interval;
1859 ext2fs_mark_super_dirty(fs);
1860 printf(_("Setting interval between checks to %lu seconds\n"),
1864 ext2fs_r_blocks_count_set(sb, reserved_ratio *
1865 ext2fs_blocks_count(sb) / 100.0);
1866 ext2fs_mark_super_dirty(fs);
1867 printf (_("Setting reserved blocks percentage to %g%% (%llu blocks)\n"),
1868 reserved_ratio, ext2fs_r_blocks_count(sb));
1871 if (reserved_blocks > ext2fs_blocks_count(sb)/2) {
1872 com_err(program_name, 0,
1873 _("reserved blocks count is too big (%llu)"),
1877 ext2fs_r_blocks_count_set(sb, reserved_blocks);
1878 ext2fs_mark_super_dirty(fs);
1879 printf(_("Setting reserved blocks count to %llu\n"),
1883 if (sb->s_feature_ro_compat &
1884 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)
1885 fputs(_("\nThe filesystem already has sparse "
1886 "superblocks.\n"), stderr);
1888 sb->s_feature_ro_compat |=
1889 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
1890 sb->s_state &= ~EXT2_VALID_FS;
1891 ext2fs_mark_super_dirty(fs);
1892 printf(_("\nSparse superblock flag set. %s"),
1897 fputs(_("\nClearing the sparse superflag not supported.\n"),
1902 sb->s_lastcheck = last_check_time;
1903 ext2fs_mark_super_dirty(fs);
1904 printf(_("Setting time filesystem last checked to %s\n"),
1905 ctime(&last_check_time));
1908 sb->s_def_resuid = resuid;
1909 ext2fs_mark_super_dirty(fs);
1910 printf(_("Setting reserved blocks uid to %lu\n"), resuid);
1913 if (strlen(new_label) > sizeof(sb->s_volume_name))
1914 fputs(_("Warning: label too long, truncating.\n"),
1916 memset(sb->s_volume_name, 0, sizeof(sb->s_volume_name));
1917 strncpy(sb->s_volume_name, new_label,
1918 sizeof(sb->s_volume_name));
1919 ext2fs_mark_super_dirty(fs);
1922 memset(sb->s_last_mounted, 0, sizeof(sb->s_last_mounted));
1923 strncpy(sb->s_last_mounted, new_last_mounted,
1924 sizeof(sb->s_last_mounted));
1925 ext2fs_mark_super_dirty(fs);
1928 update_mntopts(fs, mntopts_cmd);
1930 update_feature_set(fs, features_cmd);
1932 parse_extended_opts(fs, extended_cmd);
1933 if (journal_size || journal_device)
1937 if (mount_flags & EXT2_MF_MOUNTED) {
1938 fputs(_("The quota feature may only be changed when "
1939 "the filesystem is unmounted.\n"), stderr);
1942 handle_quota_options(fs);
1949 if (sb->s_feature_ro_compat &
1950 EXT4_FEATURE_RO_COMPAT_GDT_CSUM) {
1952 * Determine if the block group checksums are
1953 * correct so we know whether or not to set
1956 for (i = 0; i < fs->group_desc_count; i++)
1957 if (!ext2fs_group_desc_csum_verify(fs, i))
1959 if (i >= fs->group_desc_count)
1962 if ((strcasecmp(new_UUID, "null") == 0) ||
1963 (strcasecmp(new_UUID, "clear") == 0)) {
1964 uuid_clear(sb->s_uuid);
1965 } else if (strcasecmp(new_UUID, "time") == 0) {
1966 uuid_generate_time(sb->s_uuid);
1967 } else if (strcasecmp(new_UUID, "random") == 0) {
1968 uuid_generate(sb->s_uuid);
1969 } else if (uuid_parse(new_UUID, sb->s_uuid)) {
1970 com_err(program_name, 0, _("Invalid UUID format\n"));
1974 for (i = 0; i < fs->group_desc_count; i++)
1975 ext2fs_group_desc_csum_set(fs, i);
1976 fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
1978 ext2fs_mark_super_dirty(fs);
1981 if (mount_flags & EXT2_MF_MOUNTED) {
1982 fputs(_("The inode size may only be "
1983 "changed when the filesystem is "
1984 "unmounted.\n"), stderr);
1987 if (fs->super->s_feature_incompat &
1988 EXT4_FEATURE_INCOMPAT_FLEX_BG) {
1989 fputs(_("Changing the inode size not supported for "
1990 "filesystems with the flex_bg\n"
1991 "feature enabled.\n"),
1996 * We want to update group descriptor also
1997 * with the new free inode count
1999 fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
2000 if (resize_inode(fs, new_inode_size) == 0) {
2001 printf(_("Setting inode size %lu\n"),
2004 printf(_("Failed to change inode size\n"));
2012 sb->s_raid_stride = stride;
2013 ext2fs_mark_super_dirty(fs);
2014 printf(_("Setting stride size to %d\n"), stride);
2016 if (stripe_width_set) {
2017 sb->s_raid_stripe_width = stripe_width;
2018 ext2fs_mark_super_dirty(fs);
2019 printf(_("Setting stripe width to %d\n"), stripe_width);
2021 if (ext_mount_opts) {
2022 strncpy((char *)(fs->super->s_mount_opts), ext_mount_opts,
2023 sizeof(fs->super->s_mount_opts));
2024 fs->super->s_mount_opts[sizeof(fs->super->s_mount_opts)-1] = 0;
2025 ext2fs_mark_super_dirty(fs);
2026 printf(_("Setting extended default mount options to '%s'\n"),
2028 free(ext_mount_opts);
2031 remove_error_table(&et_ext2_error_table);
2032 return (ext2fs_close(fs) ? 1 : 0);