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() */
46 #include <sys/types.h>
50 #include "ext2fs/ext2_fs.h"
51 #include "ext2fs/ext2fs.h"
52 #include "et/com_err.h"
53 #include "uuid/uuid.h"
57 #include "blkid/blkid.h"
59 #include "../version.h"
60 #include "nls-enable.h"
62 const char *program_name
= "tune2fs";
64 char *new_label
, *new_last_mounted
, *new_UUID
;
66 static int c_flag
, C_flag
, e_flag
, f_flag
, g_flag
, i_flag
, l_flag
, L_flag
;
67 static int m_flag
, M_flag
, r_flag
, s_flag
= -1, u_flag
, U_flag
, T_flag
;
69 static time_t last_check_time
;
70 static int print_label
;
71 static int max_mount_count
, mount_count
, mount_flags
;
72 static unsigned long interval
, reserved_blocks
;
73 static double reserved_ratio
;
74 static unsigned long resgid
, resuid
;
75 static unsigned short errors
;
77 static char *features_cmd
;
78 static char *mntopts_cmd
;
79 static int stride
, stripe_width
;
80 static int stride_set
, stripe_width_set
;
81 static char *extended_cmd
;
82 static unsigned long new_inode_size
;
83 static char *ext_mount_opts
;
85 int journal_size
, journal_flags
;
88 static struct list_head blk_move_list
;
91 struct list_head list
;
97 static const char *please_fsck
= N_("Please run e2fsck on the filesystem.\n");
99 #ifdef CONFIG_BUILD_FINDFS
100 void do_findfs(int argc
, char **argv
);
103 static void usage(void)
106 _("Usage: %s [-c max_mounts_count] [-e errors_behavior] "
108 "\t[-i interval[d|m|w]] [-j] [-J journal_options] [-l]\n"
109 "\t[-m reserved_blocks_percent] "
110 "[-o [^]mount_options[,...]] \n"
111 "\t[-r reserved_blocks_count] [-u user] [-C mount_count] "
112 "[-L volume_label]\n"
113 "\t[-M last_mounted_dir] [-O [^]feature[,...]]\n"
114 "\t[-E extended-option[,...]] [-T last_check_time] "
115 "[-U UUID]\n\t[ -I new_inode_size ] device\n"), program_name
);
119 static __u32 ok_features
[3] = {
121 EXT3_FEATURE_COMPAT_HAS_JOURNAL
|
122 EXT2_FEATURE_COMPAT_DIR_INDEX
,
124 EXT2_FEATURE_INCOMPAT_FILETYPE
|
125 EXT3_FEATURE_INCOMPAT_EXTENTS
|
126 EXT4_FEATURE_INCOMPAT_FLEX_BG
,
128 EXT2_FEATURE_RO_COMPAT_LARGE_FILE
|
129 EXT4_FEATURE_RO_COMPAT_HUGE_FILE
|
130 EXT4_FEATURE_RO_COMPAT_DIR_NLINK
|
131 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE
|
132 EXT4_FEATURE_RO_COMPAT_GDT_CSUM
|
133 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER
136 static __u32 clear_ok_features
[3] = {
138 EXT3_FEATURE_COMPAT_HAS_JOURNAL
|
139 EXT2_FEATURE_COMPAT_RESIZE_INODE
|
140 EXT2_FEATURE_COMPAT_DIR_INDEX
,
142 EXT2_FEATURE_INCOMPAT_FILETYPE
|
143 EXT4_FEATURE_INCOMPAT_FLEX_BG
,
145 EXT2_FEATURE_RO_COMPAT_LARGE_FILE
|
146 EXT4_FEATURE_RO_COMPAT_HUGE_FILE
|
147 EXT4_FEATURE_RO_COMPAT_DIR_NLINK
|
148 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE
|
149 EXT4_FEATURE_RO_COMPAT_GDT_CSUM
153 * Remove an external journal from the filesystem
155 static void remove_journal_device(ext2_filsys fs
)
160 journal_superblock_t
*jsb
;
163 int commit_remove_journal
= 0;
167 commit_remove_journal
= 1; /* force removal even if error */
169 uuid_unparse(fs
->super
->s_journal_uuid
, buf
);
170 journal_path
= blkid_get_devname(NULL
, "UUID", buf
);
174 ext2fs_find_block_device(fs
->super
->s_journal_dev
);
179 #ifdef CONFIG_TESTIO_DEBUG
180 if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) {
181 io_ptr
= test_io_manager
;
182 test_io_backing_manager
= unix_io_manager
;
185 io_ptr
= unix_io_manager
;
186 retval
= ext2fs_open(journal_path
, EXT2_FLAG_RW
|
187 EXT2_FLAG_JOURNAL_DEV_OK
, 0,
188 fs
->blocksize
, io_ptr
, &jfs
);
190 com_err(program_name
, retval
,
191 _("while trying to open external journal"));
192 goto no_valid_journal
;
194 if (!(jfs
->super
->s_feature_incompat
& EXT3_FEATURE_INCOMPAT_JOURNAL_DEV
)) {
195 fprintf(stderr
, _("%s is not a journal device.\n"),
197 goto no_valid_journal
;
200 /* Get the journal superblock */
201 if ((retval
= io_channel_read_blk(jfs
->io
, 1, -1024, buf
))) {
202 com_err(program_name
, retval
,
203 _("while reading journal superblock"));
204 goto no_valid_journal
;
207 jsb
= (journal_superblock_t
*) buf
;
208 if ((jsb
->s_header
.h_magic
!= (unsigned) ntohl(JFS_MAGIC_NUMBER
)) ||
209 (jsb
->s_header
.h_blocktype
!= (unsigned) ntohl(JFS_SUPERBLOCK_V2
))) {
210 fputs(_("Journal superblock not found!\n"), stderr
);
211 goto no_valid_journal
;
214 /* Find the filesystem UUID */
215 nr_users
= ntohl(jsb
->s_nr_users
);
216 for (i
= 0; i
< nr_users
; i
++) {
217 if (memcmp(fs
->super
->s_uuid
,
218 &jsb
->s_users
[i
*16], 16) == 0)
222 fputs(_("Filesystem's UUID not found on journal device.\n"),
224 commit_remove_journal
= 1;
225 goto no_valid_journal
;
228 for (i
= 0; i
< nr_users
; i
++)
229 memcpy(&jsb
->s_users
[i
*16], &jsb
->s_users
[(i
+1)*16], 16);
230 jsb
->s_nr_users
= htonl(nr_users
);
232 /* Write back the journal superblock */
233 if ((retval
= io_channel_write_blk(jfs
->io
, 1, -1024, buf
))) {
234 com_err(program_name
, retval
,
235 "while writing journal superblock.");
236 goto no_valid_journal
;
239 commit_remove_journal
= 1;
242 if (commit_remove_journal
== 0) {
243 fputs(_("Journal NOT removed\n"), stderr
);
246 fs
->super
->s_journal_dev
= 0;
247 uuid_clear(fs
->super
->s_journal_uuid
);
248 ext2fs_mark_super_dirty(fs
);
249 fputs(_("Journal removed\n"), stdout
);
253 /* Helper function for remove_journal_inode */
254 static int release_blocks_proc(ext2_filsys fs
, blk_t
*blocknr
,
255 int blockcnt
EXT2FS_ATTR((unused
)),
256 void *private EXT2FS_ATTR((unused
)))
262 ext2fs_unmark_block_bitmap(fs
->block_map
, block
);
263 group
= ext2fs_group_of_blk(fs
, block
);
264 fs
->group_desc
[group
].bg_free_blocks_count
++;
265 ext2fs_group_desc_csum_set(fs
, group
);
266 fs
->super
->s_free_blocks_count
++;
271 * Remove the journal inode from the filesystem
273 static void remove_journal_inode(ext2_filsys fs
)
275 struct ext2_inode inode
;
277 ino_t ino
= fs
->super
->s_journal_inum
;
279 retval
= ext2fs_read_inode(fs
, ino
, &inode
);
281 com_err(program_name
, retval
,
282 _("while reading journal inode"));
285 if (ino
== EXT2_JOURNAL_INO
) {
286 retval
= ext2fs_read_bitmaps(fs
);
288 com_err(program_name
, retval
,
289 _("while reading bitmaps"));
292 retval
= ext2fs_block_iterate(fs
, ino
,
293 BLOCK_FLAG_READ_ONLY
, NULL
,
294 release_blocks_proc
, NULL
);
296 com_err(program_name
, retval
,
297 _("while clearing journal inode"));
300 memset(&inode
, 0, sizeof(inode
));
301 ext2fs_mark_bb_dirty(fs
);
302 fs
->flags
&= ~EXT2_FLAG_SUPER_ONLY
;
304 inode
.i_flags
&= ~EXT2_IMMUTABLE_FL
;
305 retval
= ext2fs_write_inode(fs
, ino
, &inode
);
307 com_err(program_name
, retval
,
308 _("while writing journal inode"));
311 fs
->super
->s_journal_inum
= 0;
312 ext2fs_mark_super_dirty(fs
);
316 * Update the default mount options
318 static void update_mntopts(ext2_filsys fs
, char *mntopts
)
320 struct ext2_super_block
*sb
= fs
->super
;
322 if (e2p_edit_mntopts(mntopts
, &sb
->s_default_mount_opts
, ~0)) {
323 fprintf(stderr
, _("Invalid mount option set: %s\n"),
327 ext2fs_mark_super_dirty(fs
);
330 static void request_fsck_afterwards(ext2_filsys fs
)
332 static int requested
= 0;
336 fs
->super
->s_state
&= ~EXT2_VALID_FS
;
337 printf("\n%s\n", _(please_fsck
));
338 if (mount_flags
& EXT2_MF_READONLY
)
339 printf(_("(and reboot afterwards!)\n"));
343 * Update the feature set as provided by the user.
345 static void update_feature_set(ext2_filsys fs
, char *features
)
347 struct ext2_super_block
*sb
= fs
->super
;
348 struct ext2_group_desc
*gd
;
350 __u32 old_features
[3];
352 unsigned int mask_err
;
354 #define FEATURE_ON(type, mask) (!(old_features[(type)] & (mask)) && \
355 ((&sb->s_feature_compat)[(type)] & (mask)))
356 #define FEATURE_OFF(type, mask) ((old_features[(type)] & (mask)) && \
357 !((&sb->s_feature_compat)[(type)] & (mask)))
358 #define FEATURE_CHANGED(type, mask) ((mask) & \
359 (old_features[(type)] ^ (&sb->s_feature_compat)[(type)]))
361 old_features
[E2P_FEATURE_COMPAT
] = sb
->s_feature_compat
;
362 old_features
[E2P_FEATURE_INCOMPAT
] = sb
->s_feature_incompat
;
363 old_features
[E2P_FEATURE_RO_INCOMPAT
] = sb
->s_feature_ro_compat
;
365 if (e2p_edit_feature2(features
, &sb
->s_feature_compat
,
366 ok_features
, clear_ok_features
,
367 &type_err
, &mask_err
)) {
370 _("Invalid filesystem option set: %s\n"),
372 else if (type_err
& E2P_FEATURE_NEGATE_FLAG
)
373 fprintf(stderr
, _("Clearing filesystem feature '%s' "
375 e2p_feature2string(type_err
&
376 E2P_FEATURE_TYPE_MASK
,
379 fprintf(stderr
, _("Setting filesystem feature '%s' "
381 e2p_feature2string(type_err
, mask_err
));
385 if (FEATURE_OFF(E2P_FEATURE_COMPAT
, EXT3_FEATURE_COMPAT_HAS_JOURNAL
)) {
386 if ((mount_flags
& EXT2_MF_MOUNTED
) &&
387 !(mount_flags
& EXT2_MF_READONLY
)) {
388 fputs(_("The has_journal feature may only be "
389 "cleared when the filesystem is\n"
390 "unmounted or mounted "
391 "read-only.\n"), stderr
);
394 if (sb
->s_feature_incompat
&
395 EXT3_FEATURE_INCOMPAT_RECOVER
) {
396 fputs(_("The needs_recovery flag is set. "
397 "Please run e2fsck before clearing\n"
398 "the has_journal flag.\n"), stderr
);
401 if (sb
->s_journal_inum
) {
402 remove_journal_inode(fs
);
404 if (sb
->s_journal_dev
) {
405 remove_journal_device(fs
);
409 if (FEATURE_ON(E2P_FEATURE_COMPAT
, EXT3_FEATURE_COMPAT_HAS_JOURNAL
)) {
411 * If adding a journal flag, let the create journal
412 * code below handle setting the flag and creating the
413 * journal. We supply a default size if necessary.
417 sb
->s_feature_compat
&= ~EXT3_FEATURE_COMPAT_HAS_JOURNAL
;
420 if (FEATURE_ON(E2P_FEATURE_COMPAT
, EXT2_FEATURE_COMPAT_DIR_INDEX
)) {
421 if (!sb
->s_def_hash_version
)
422 sb
->s_def_hash_version
= EXT2_HASH_HALF_MD4
;
423 if (uuid_is_null((unsigned char *) sb
->s_hash_seed
))
424 uuid_generate((unsigned char *) sb
->s_hash_seed
);
427 if (FEATURE_OFF(E2P_FEATURE_INCOMPAT
, EXT4_FEATURE_INCOMPAT_FLEX_BG
)) {
428 if (ext2fs_check_desc(fs
)) {
429 fputs(_("Clearing the flex_bg flag would "
430 "cause the the filesystem to be\n"
431 "inconsistent.\n"), stderr
);
436 if (FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT
,
437 EXT4_FEATURE_RO_COMPAT_HUGE_FILE
)) {
438 if ((mount_flags
& EXT2_MF_MOUNTED
) &&
439 !(mount_flags
& EXT2_MF_READONLY
)) {
440 fputs(_("The huge_file feature may only be "
441 "cleared when the filesystem is\n"
442 "unmounted or mounted "
443 "read-only.\n"), stderr
);
448 if (FEATURE_ON(E2P_FEATURE_RO_INCOMPAT
,
449 EXT4_FEATURE_RO_COMPAT_GDT_CSUM
)) {
451 for (i
= 0; i
< fs
->group_desc_count
; i
++, gd
++) {
452 gd
->bg_itable_unused
= 0;
453 gd
->bg_flags
= EXT2_BG_INODE_ZEROED
;
454 ext2fs_group_desc_csum_set(fs
, i
);
456 fs
->flags
&= ~EXT2_FLAG_SUPER_ONLY
;
459 if (FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT
,
460 EXT4_FEATURE_RO_COMPAT_GDT_CSUM
)) {
462 for (i
= 0; i
< fs
->group_desc_count
; i
++, gd
++) {
463 if ((gd
->bg_flags
& EXT2_BG_INODE_ZEROED
) == 0) {
465 * XXX what we really should do is zap
466 * uninitialized inode tables instead.
468 request_fsck_afterwards(fs
);
471 gd
->bg_itable_unused
= 0;
475 fs
->flags
&= ~EXT2_FLAG_SUPER_ONLY
;
478 if (sb
->s_rev_level
== EXT2_GOOD_OLD_REV
&&
479 (sb
->s_feature_compat
|| sb
->s_feature_ro_compat
||
480 sb
->s_feature_incompat
))
481 ext2fs_update_dynamic_rev(fs
);
483 if (FEATURE_CHANGED(E2P_FEATURE_RO_INCOMPAT
,
484 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER
) ||
485 FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT
,
486 EXT4_FEATURE_RO_COMPAT_HUGE_FILE
) ||
487 FEATURE_CHANGED(E2P_FEATURE_INCOMPAT
,
488 EXT2_FEATURE_INCOMPAT_FILETYPE
) ||
489 FEATURE_CHANGED(E2P_FEATURE_COMPAT
,
490 EXT2_FEATURE_COMPAT_RESIZE_INODE
) ||
491 FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT
,
492 EXT2_FEATURE_RO_COMPAT_LARGE_FILE
))
493 request_fsck_afterwards(fs
);
495 if ((old_features
[E2P_FEATURE_COMPAT
] != sb
->s_feature_compat
) ||
496 (old_features
[E2P_FEATURE_INCOMPAT
] != sb
->s_feature_incompat
) ||
497 (old_features
[E2P_FEATURE_RO_INCOMPAT
] != sb
->s_feature_ro_compat
))
498 ext2fs_mark_super_dirty(fs
);
502 * Add a journal to the filesystem.
504 static void add_journal(ext2_filsys fs
)
506 unsigned long journal_blocks
;
511 if (fs
->super
->s_feature_compat
&
512 EXT3_FEATURE_COMPAT_HAS_JOURNAL
) {
513 fputs(_("The filesystem already has a journal.\n"), stderr
);
516 if (journal_device
) {
517 check_plausibility(journal_device
);
518 check_mount(journal_device
, 0, _("journal"));
519 #ifdef CONFIG_TESTIO_DEBUG
520 if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) {
521 io_ptr
= test_io_manager
;
522 test_io_backing_manager
= unix_io_manager
;
525 io_ptr
= unix_io_manager
;
526 retval
= ext2fs_open(journal_device
, EXT2_FLAG_RW
|
527 EXT2_FLAG_JOURNAL_DEV_OK
, 0,
528 fs
->blocksize
, io_ptr
, &jfs
);
530 com_err(program_name
, retval
,
531 _("\n\twhile trying to open journal on %s\n"),
535 printf(_("Creating journal on device %s: "),
539 retval
= ext2fs_add_journal_device(fs
, jfs
);
542 com_err(program_name
, retval
,
543 _("while adding filesystem to journal on %s"),
547 fputs(_("done\n"), stdout
);
548 } else if (journal_size
) {
549 fputs(_("Creating journal inode: "), stdout
);
551 journal_blocks
= figure_journal_size(journal_size
, fs
);
553 retval
= ext2fs_add_journal_inode(fs
, journal_blocks
,
556 fprintf(stderr
, "\n");
557 com_err(program_name
, retval
,
558 _("\n\twhile trying to create journal file"));
561 fputs(_("done\n"), stdout
);
563 * If the filesystem wasn't mounted, we need to force
564 * the block group descriptors out.
566 if ((mount_flags
& EXT2_MF_MOUNTED
) == 0)
567 fs
->flags
&= ~EXT2_FLAG_SUPER_ONLY
;
569 print_check_message(fs
);
573 free(journal_device
);
578 static void parse_e2label_options(int argc
, char ** argv
)
580 if ((argc
< 2) || (argc
> 3)) {
581 fputs(_("Usage: e2label device [newlabel]\n"), stderr
);
584 io_options
= strchr(argv
[1], '?');
587 device_name
= blkid_get_devname(NULL
, argv
[1], NULL
);
589 com_err("e2label", 0, _("Unable to resolve '%s'"),
593 open_flag
= EXT2_FLAG_JOURNAL_DEV_OK
;
595 open_flag
|= EXT2_FLAG_RW
;
602 static time_t parse_time(char *str
)
606 if (strcmp(str
, "now") == 0) {
609 memset(&ts
, 0, sizeof(ts
));
611 strptime(str
, "%Y%m%d%H%M%S", &ts
);
613 sscanf(str
, "%4d%2d%2d%2d%2d%2d", &ts
.tm_year
, &ts
.tm_mon
,
614 &ts
.tm_mday
, &ts
.tm_hour
, &ts
.tm_min
, &ts
.tm_sec
);
617 if (ts
.tm_year
< 0 || ts
.tm_mon
< 0 || ts
.tm_mon
> 11 ||
618 ts
.tm_mday
< 0 || ts
.tm_mday
> 31 || ts
.tm_hour
> 23 ||
619 ts
.tm_min
> 59 || ts
.tm_sec
> 61)
622 if (ts
.tm_mday
== 0) {
623 com_err(program_name
, 0,
624 _("Couldn't parse date/time specifier: %s"),
629 return (mktime(&ts
));
632 static void parse_tune2fs_options(int argc
, char **argv
)
641 printf("tune2fs %s (%s)\n", E2FSPROGS_VERSION
, E2FSPROGS_DATE
);
642 while ((c
= getopt(argc
, argv
, "c:e:fg:i:jlm:o:r:s:u:C:E:I:J:L:M:O:T:U:")) != EOF
)
645 max_mount_count
= strtol(optarg
, &tmp
, 0);
646 if (*tmp
|| max_mount_count
> 16000) {
647 com_err(program_name
, 0,
648 _("bad mounts count - %s"),
652 if (max_mount_count
== 0)
653 max_mount_count
= -1;
655 open_flag
= EXT2_FLAG_RW
;
658 mount_count
= strtoul(optarg
, &tmp
, 0);
659 if (*tmp
|| mount_count
> 16000) {
660 com_err(program_name
, 0,
661 _("bad mounts count - %s"),
666 open_flag
= EXT2_FLAG_RW
;
669 if (strcmp(optarg
, "continue") == 0)
670 errors
= EXT2_ERRORS_CONTINUE
;
671 else if (strcmp(optarg
, "remount-ro") == 0)
672 errors
= EXT2_ERRORS_RO
;
673 else if (strcmp(optarg
, "panic") == 0)
674 errors
= EXT2_ERRORS_PANIC
;
676 com_err(program_name
, 0,
677 _("bad error behavior - %s"),
682 open_flag
= EXT2_FLAG_RW
;
685 extended_cmd
= optarg
;
686 open_flag
|= EXT2_FLAG_RW
;
688 case 'f': /* Force */
692 resgid
= strtoul(optarg
, &tmp
, 0);
694 gr
= getgrnam(optarg
);
703 com_err(program_name
, 0,
704 _("bad gid/group name - %s"),
709 open_flag
= EXT2_FLAG_RW
;
712 interval
= strtoul(optarg
, &tmp
, 0);
725 case 'M': /* months! */
726 interval
*= 86400 * 30;
730 case 'W': /* weeks */
731 interval
*= 86400 * 7;
736 com_err(program_name
, 0,
737 _("bad interval - %s"), optarg
);
741 open_flag
= EXT2_FLAG_RW
;
746 open_flag
= EXT2_FLAG_RW
;
749 parse_journal_opts(optarg
);
750 open_flag
= EXT2_FLAG_RW
;
758 open_flag
|= EXT2_FLAG_RW
|
759 EXT2_FLAG_JOURNAL_DEV_OK
;
762 reserved_ratio
= strtod(optarg
, &tmp
);
763 if (*tmp
|| reserved_ratio
> 50 ||
764 reserved_ratio
< 0) {
765 com_err(program_name
, 0,
766 _("bad reserved block ratio - %s"),
771 open_flag
= EXT2_FLAG_RW
;
774 new_last_mounted
= optarg
;
776 open_flag
= EXT2_FLAG_RW
;
780 com_err(program_name
, 0,
781 _("-o may only be specified once"));
784 mntopts_cmd
= optarg
;
785 open_flag
= EXT2_FLAG_RW
;
790 com_err(program_name
, 0,
791 _("-O may only be specified once"));
794 features_cmd
= optarg
;
795 open_flag
= EXT2_FLAG_RW
;
798 reserved_blocks
= strtoul(optarg
, &tmp
, 0);
800 com_err(program_name
, 0,
801 _("bad reserved blocks count - %s"),
806 open_flag
= EXT2_FLAG_RW
;
808 case 's': /* Deprecated */
809 s_flag
= atoi(optarg
);
810 open_flag
= EXT2_FLAG_RW
;
814 last_check_time
= parse_time(optarg
);
815 open_flag
= EXT2_FLAG_RW
;
818 resuid
= strtoul(optarg
, &tmp
, 0);
820 pw
= getpwnam(optarg
);
829 com_err(program_name
, 0,
830 _("bad uid/user name - %s"),
835 open_flag
= EXT2_FLAG_RW
;
840 open_flag
= EXT2_FLAG_RW
|
841 EXT2_FLAG_JOURNAL_DEV_OK
;
844 new_inode_size
= strtoul(optarg
, &tmp
, 0);
846 com_err(program_name
, 0,
847 _("bad inode size - %s"),
851 if (!((new_inode_size
&
852 (new_inode_size
- 1)) == 0)) {
853 com_err(program_name
, 0,
854 _("Inode size must be a "
859 open_flag
= EXT2_FLAG_RW
;
865 if (optind
< argc
- 1 || optind
== argc
)
867 if (!open_flag
&& !l_flag
)
869 io_options
= strchr(argv
[optind
], '?');
872 device_name
= blkid_get_devname(NULL
, argv
[optind
], NULL
);
874 com_err("tune2fs", 0, _("Unable to resolve '%s'"),
880 #ifdef CONFIG_BUILD_FINDFS
881 void do_findfs(int argc
, char **argv
)
886 (strncmp(argv
[1], "LABEL=", 6) && strncmp(argv
[1], "UUID=", 5))) {
887 fprintf(stderr
, "Usage: findfs LABEL=<label>|UUID=<uuid>\n");
890 dev
= blkid_get_devname(NULL
, argv
[1], NULL
);
892 com_err("findfs", 0, _("Unable to resolve '%s'"),
901 static void parse_extended_opts(ext2_filsys fs
, const char *opts
)
903 char *buf
, *token
, *next
, *p
, *arg
;
911 _("Couldn't allocate memory to parse options!\n"));
915 for (token
= buf
; token
&& *token
; token
= next
) {
916 p
= strchr(token
, ',');
922 arg
= strchr(token
, '=');
927 if (!strcmp(token
, "test_fs")) {
928 fs
->super
->s_flags
|= EXT2_FLAGS_TEST_FILESYS
;
929 printf("Setting test filesystem flag\n");
930 ext2fs_mark_super_dirty(fs
);
931 } else if (!strcmp(token
, "^test_fs")) {
932 fs
->super
->s_flags
&= ~EXT2_FLAGS_TEST_FILESYS
;
933 printf("Clearing test filesystem flag\n");
934 ext2fs_mark_super_dirty(fs
);
935 } else if (strcmp(token
, "stride") == 0) {
940 stride
= strtoul(arg
, &p
, 0);
943 _("Invalid RAID stride: %s\n"),
949 } else if (strcmp(token
, "stripe-width") == 0 ||
950 strcmp(token
, "stripe_width") == 0) {
955 stripe_width
= strtoul(arg
, &p
, 0);
958 _("Invalid RAID stripe-width: %s\n"),
963 stripe_width_set
= 1;
964 } else if (strcmp(token
, "hash_alg") == 0 ||
965 strcmp(token
, "hash-alg") == 0) {
970 hash_alg
= e2p_string2hash(arg
);
973 _("Invalid hash algorithm: %s\n"),
978 fs
->super
->s_def_hash_version
= hash_alg
;
979 printf(_("Setting default hash algorithm "
982 ext2fs_mark_super_dirty(fs
);
983 } else if (!strcmp(token
, "mount_opts")) {
988 if (strlen(arg
) >= sizeof(fs
->super
->s_mount_opts
)) {
990 "Extended mount options too long\n");
993 ext_mount_opts
= strdup(arg
);
998 fprintf(stderr
, _("\nBad options specified.\n\n"
999 "Extended options are separated by commas, "
1000 "and may take an argument which\n"
1001 "\tis set off by an equals ('=') sign.\n\n"
1002 "Valid extended options are:\n"
1003 "\thash_alg=<hash algorithm>\n"
1004 "\tmount_opts=<extended default mount options>\n"
1005 "\tstride=<RAID per-disk chunk size in blocks>\n"
1006 "\tstripe_width=<RAID stride*data disks in blocks>\n"
1016 * Fill in the block bitmap bmap with the information regarding the
1017 * blocks to be moved
1019 static int get_move_bitmaps(ext2_filsys fs
, int new_ino_blks_per_grp
,
1020 ext2fs_block_bitmap bmap
)
1024 ext2_badblocks_list bb_list
= 0;
1025 blk_t j
, needed_blocks
= 0;
1026 blk_t start_blk
, end_blk
;
1028 retval
= ext2fs_read_bb_inode(fs
, &bb_list
);
1032 for (i
= 0; i
< fs
->group_desc_count
; i
++) {
1033 start_blk
= fs
->group_desc
[i
].bg_inode_table
+
1034 fs
->inode_blocks_per_group
;
1036 end_blk
= fs
->group_desc
[i
].bg_inode_table
+
1037 new_ino_blks_per_grp
;
1039 for (j
= start_blk
; j
< end_blk
; j
++) {
1040 if (ext2fs_test_block_bitmap(fs
->block_map
, j
)) {
1042 * IF the block is a bad block we fail
1044 if (ext2fs_badblocks_list_test(bb_list
, j
)) {
1045 ext2fs_badblocks_list_free(bb_list
);
1049 ext2fs_mark_block_bitmap(bmap
, j
);
1052 * We are going to use this block for
1053 * inode table. So mark them used.
1055 ext2fs_mark_block_bitmap(fs
->block_map
, j
);
1058 needed_blocks
+= end_blk
- start_blk
;
1061 ext2fs_badblocks_list_free(bb_list
);
1062 if (needed_blocks
> fs
->super
->s_free_blocks_count
)
1068 static int ext2fs_is_meta_block(ext2_filsys fs
, blk_t blk
)
1071 group
= ext2fs_group_of_blk(fs
, blk
);
1072 if (fs
->group_desc
[group
].bg_block_bitmap
== blk
)
1074 if (fs
->group_desc
[group
].bg_inode_bitmap
== blk
)
1079 static int ext2fs_is_block_in_group(ext2_filsys fs
, dgrp_t group
, blk_t blk
)
1081 blk_t start_blk
, end_blk
;
1082 start_blk
= fs
->super
->s_first_data_block
+
1083 EXT2_BLOCKS_PER_GROUP(fs
->super
) * group
;
1085 * We cannot get new block beyond end_blk for for the last block group
1086 * so we can check with EXT2_BLOCKS_PER_GROUP even for last block group
1088 end_blk
= start_blk
+ EXT2_BLOCKS_PER_GROUP(fs
->super
);
1089 if (blk
>= start_blk
&& blk
<= end_blk
)
1094 static int move_block(ext2_filsys fs
, ext2fs_block_bitmap bmap
)
1101 blk_t blk
, new_blk
, goal
;
1102 struct blk_move
*bmv
;
1104 retval
= ext2fs_get_mem(fs
->blocksize
, &buf
);
1108 for (new_blk
= blk
= fs
->super
->s_first_data_block
;
1109 blk
< fs
->super
->s_blocks_count
; blk
++) {
1110 if (!ext2fs_test_block_bitmap(bmap
, blk
))
1113 if (ext2fs_is_meta_block(fs
, blk
)) {
1115 * If the block is mapping a fs meta data block
1116 * like group desc/block bitmap/inode bitmap. We
1117 * should find a block in the same group and fix
1118 * the respective fs metadata pointers. Otherwise
1121 group
= ext2fs_group_of_blk(fs
, blk
);
1122 goal
= ext2fs_group_first_block(fs
, group
);
1128 retval
= ext2fs_new_block(fs
, goal
, NULL
, &new_blk
);
1132 /* new fs meta data block should be in the same group */
1133 if (meta_data
&& !ext2fs_is_block_in_group(fs
, group
, new_blk
)) {
1138 /* Mark this block as allocated */
1139 ext2fs_mark_block_bitmap(fs
->block_map
, new_blk
);
1141 /* Add it to block move list */
1142 retval
= ext2fs_get_mem(sizeof(struct blk_move
), &bmv
);
1147 bmv
->new_loc
= new_blk
;
1149 list_add(&(bmv
->list
), &blk_move_list
);
1151 retval
= io_channel_read_blk(fs
->io
, blk
, 1, buf
);
1155 retval
= io_channel_write_blk(fs
->io
, new_blk
, 1, buf
);
1161 ext2fs_free_mem(&buf
);
1165 static blk_t
translate_block(blk_t blk
)
1167 struct list_head
*entry
;
1168 struct blk_move
*bmv
;
1170 list_for_each(entry
, &blk_move_list
) {
1171 bmv
= list_entry(entry
, struct blk_move
, list
);
1172 if (bmv
->old_loc
== blk
)
1173 return bmv
->new_loc
;
1179 static int process_block(ext2_filsys fs
EXT2FS_ATTR((unused
)),
1181 e2_blkcnt_t blockcnt
EXT2FS_ATTR((unused
)),
1182 blk_t ref_block
EXT2FS_ATTR((unused
)),
1183 int ref_offset
EXT2FS_ATTR((unused
)),
1188 ext2fs_block_bitmap bmap
= (ext2fs_block_bitmap
) priv_data
;
1190 if (!ext2fs_test_block_bitmap(bmap
, *block_nr
))
1192 new_blk
= translate_block(*block_nr
);
1194 *block_nr
= new_blk
;
1196 * This will force the ext2fs_write_inode in the iterator
1198 ret
|= BLOCK_CHANGED
;
1204 static int inode_scan_and_fix(ext2_filsys fs
, ext2fs_block_bitmap bmap
)
1206 errcode_t retval
= 0;
1209 char *block_buf
= 0;
1210 struct ext2_inode inode
;
1211 ext2_inode_scan scan
= NULL
;
1213 retval
= ext2fs_get_mem(fs
->blocksize
* 3, &block_buf
);
1217 retval
= ext2fs_open_inode_scan(fs
, 0, &scan
);
1222 retval
= ext2fs_get_next_inode(scan
, &ino
, &inode
);
1229 if (inode
.i_links_count
== 0)
1230 continue; /* inode not in use */
1233 * If we end up modifying the journal inode
1234 * the sb->s_jnl_blocks will differ. But a
1235 * subsequent e2fsck fixes that.
1236 * Do we need to fix this ??
1239 if (inode
.i_file_acl
&&
1240 ext2fs_test_block_bitmap(bmap
, inode
.i_file_acl
)) {
1241 blk
= translate_block(inode
.i_file_acl
);
1245 inode
.i_file_acl
= blk
;
1248 * Write the inode to disk so that inode table
1251 retval
= ext2fs_write_inode(fs
, ino
, &inode
);
1256 if (!ext2fs_inode_has_valid_blocks(&inode
))
1259 retval
= ext2fs_block_iterate2(fs
, ino
, 0, block_buf
,
1260 process_block
, bmap
);
1267 ext2fs_free_mem(&block_buf
);
1273 * We need to scan for inode and block bitmaps that may need to be
1274 * moved. This can take place if the filesystem was formatted for
1275 * RAID arrays using the mke2fs's extended option "stride".
1277 static int group_desc_scan_and_fix(ext2_filsys fs
, ext2fs_block_bitmap bmap
)
1282 for (i
= 0; i
< fs
->group_desc_count
; i
++) {
1283 blk
= fs
->group_desc
[i
].bg_block_bitmap
;
1284 if (ext2fs_test_block_bitmap(bmap
, blk
)) {
1285 new_blk
= translate_block(blk
);
1288 fs
->group_desc
[i
].bg_block_bitmap
= new_blk
;
1291 blk
= fs
->group_desc
[i
].bg_inode_bitmap
;
1292 if (ext2fs_test_block_bitmap(bmap
, blk
)) {
1293 new_blk
= translate_block(blk
);
1296 fs
->group_desc
[i
].bg_inode_bitmap
= new_blk
;
1302 static int expand_inode_table(ext2_filsys fs
, unsigned long new_ino_size
)
1307 int new_ino_blks_per_grp
;
1309 char *old_itable
= NULL
, *new_itable
= NULL
;
1310 char *tmp_old_itable
= NULL
, *tmp_new_itable
= NULL
;
1311 unsigned long old_ino_size
;
1312 int old_itable_size
, new_itable_size
;
1314 old_itable_size
= fs
->inode_blocks_per_group
* fs
->blocksize
;
1315 old_ino_size
= EXT2_INODE_SIZE(fs
->super
);
1317 new_ino_blks_per_grp
= ext2fs_div_ceil(
1318 EXT2_INODES_PER_GROUP(fs
->super
) *
1322 new_itable_size
= new_ino_blks_per_grp
* fs
->blocksize
;
1324 retval
= ext2fs_get_mem(old_itable_size
, &old_itable
);
1328 retval
= ext2fs_get_mem(new_itable_size
, &new_itable
);
1332 tmp_old_itable
= old_itable
;
1333 tmp_new_itable
= new_itable
;
1335 for (i
= 0; i
< fs
->group_desc_count
; i
++) {
1336 blk
= fs
->group_desc
[i
].bg_inode_table
;
1337 retval
= io_channel_read_blk(fs
->io
, blk
,
1338 fs
->inode_blocks_per_group
, old_itable
);
1342 for (j
= 0; j
< EXT2_INODES_PER_GROUP(fs
->super
); j
++) {
1343 memcpy(new_itable
, old_itable
, old_ino_size
);
1345 memset(new_itable
+old_ino_size
, 0,
1346 new_ino_size
- old_ino_size
);
1348 new_itable
+= new_ino_size
;
1349 old_itable
+= old_ino_size
;
1352 /* reset the pointer */
1353 old_itable
= tmp_old_itable
;
1354 new_itable
= tmp_new_itable
;
1356 retval
= io_channel_write_blk(fs
->io
, blk
,
1357 new_ino_blks_per_grp
, new_itable
);
1362 /* Update the meta data */
1363 fs
->inode_blocks_per_group
= new_ino_blks_per_grp
;
1364 fs
->super
->s_inode_size
= new_ino_size
;
1368 ext2fs_free_mem(&old_itable
);
1371 ext2fs_free_mem(&new_itable
);
1376 static errcode_t
ext2fs_calculate_summary_stats(ext2_filsys fs
)
1380 unsigned int group
= 0;
1381 unsigned int count
= 0;
1386 * First calculate the block statistics
1388 for (blk
= fs
->super
->s_first_data_block
;
1389 blk
< fs
->super
->s_blocks_count
; blk
++) {
1390 if (!ext2fs_fast_test_block_bitmap(fs
->block_map
, blk
)) {
1395 if ((count
== fs
->super
->s_blocks_per_group
) ||
1396 (blk
== fs
->super
->s_blocks_count
-1)) {
1397 fs
->group_desc
[group
++].bg_free_blocks_count
=
1403 fs
->super
->s_free_blocks_count
= total_free
;
1406 * Next, calculate the inode statistics
1413 /* Protect loop from wrap-around if s_inodes_count maxed */
1414 for (ino
= 1; ino
<= fs
->super
->s_inodes_count
&& ino
> 0; ino
++) {
1415 if (!ext2fs_fast_test_inode_bitmap(fs
->inode_map
, ino
)) {
1420 if ((count
== fs
->super
->s_inodes_per_group
) ||
1421 (ino
== fs
->super
->s_inodes_count
)) {
1422 fs
->group_desc
[group
++].bg_free_inodes_count
=
1428 fs
->super
->s_free_inodes_count
= total_free
;
1429 ext2fs_mark_super_dirty(fs
);
1433 #define list_for_each_safe(pos, pnext, head) \
1434 for (pos = (head)->next, pnext = pos->next; pos != (head); \
1435 pos = pnext, pnext = pos->next)
1437 static void free_blk_move_list(void)
1439 struct list_head
*entry
, *tmp
;
1440 struct blk_move
*bmv
;
1442 list_for_each_safe(entry
, tmp
, &blk_move_list
) {
1443 bmv
= list_entry(entry
, struct blk_move
, list
);
1445 ext2fs_free_mem(&bmv
);
1450 static int resize_inode(ext2_filsys fs
, unsigned long new_size
)
1453 int new_ino_blks_per_grp
;
1454 ext2fs_block_bitmap bmap
;
1456 ext2fs_read_inode_bitmap(fs
);
1457 ext2fs_read_block_bitmap(fs
);
1458 INIT_LIST_HEAD(&blk_move_list
);
1461 new_ino_blks_per_grp
= ext2fs_div_ceil(
1462 EXT2_INODES_PER_GROUP(fs
->super
)*
1466 /* We may change the file system.
1467 * Mark the file system as invalid so that
1468 * the user is prompted to run fsck.
1470 fs
->super
->s_state
&= ~EXT2_VALID_FS
;
1472 retval
= ext2fs_allocate_block_bitmap(fs
, _("blocks to be moved"),
1475 fputs(_("Failed to allocate block bitmap when "
1476 "increasing inode size\n"), stderr
);
1479 retval
= get_move_bitmaps(fs
, new_ino_blks_per_grp
, bmap
);
1481 fputs(_("Not enough space to increase inode size \n"), stderr
);
1484 retval
= move_block(fs
, bmap
);
1486 fputs(_("Failed to relocate blocks during inode resize \n"),
1490 retval
= inode_scan_and_fix(fs
, bmap
);
1494 retval
= group_desc_scan_and_fix(fs
, bmap
);
1498 retval
= expand_inode_table(fs
, new_size
);
1502 ext2fs_calculate_summary_stats(fs
);
1504 fs
->super
->s_state
|= EXT2_VALID_FS
;
1505 /* mark super block and block bitmap as dirty */
1506 ext2fs_mark_super_dirty(fs
);
1507 ext2fs_mark_bb_dirty(fs
);
1510 free_blk_move_list();
1511 ext2fs_free_block_bitmap(bmap
);
1516 free_blk_move_list();
1517 ext2fs_free_block_bitmap(bmap
);
1518 fputs(_("Error in resizing the inode size.\n"
1519 "Run e2undo to undo the "
1520 "file system changes. \n"), stderr
);
1525 static int tune2fs_setup_tdb(const char *name
, io_manager
*io_ptr
)
1527 errcode_t retval
= 0;
1528 const char *tdb_dir
;
1530 char *dev_name
, *tmp_name
;
1534 * Configuration via a conf file would be
1537 profile_get_string(profile
, "scratch_files",
1541 tmp_name
= strdup(name
);
1544 com_err(program_name
, ENOMEM
,
1545 _("Couldn't allocate memory for tdb filename\n"));
1548 dev_name
= basename(tmp_name
);
1550 tdb_dir
= getenv("E2FSPROGS_UNDO_DIR");
1552 tdb_dir
= "/var/lib/e2fsprogs";
1554 if (!strcmp(tdb_dir
, "none") || (tdb_dir
[0] == 0) ||
1555 access(tdb_dir
, W_OK
))
1558 tdb_file
= malloc(strlen(tdb_dir
) + 9 + strlen(dev_name
) + 7 + 1);
1561 sprintf(tdb_file
, "%s/tune2fs-%s.e2undo", tdb_dir
, dev_name
);
1563 if (!access(tdb_file
, F_OK
)) {
1564 if (unlink(tdb_file
) < 0) {
1566 com_err(program_name
, retval
,
1567 _("while trying to delete %s"),
1574 set_undo_io_backing_manager(*io_ptr
);
1575 *io_ptr
= undo_io_manager
;
1576 set_undo_io_backup_file(tdb_file
);
1577 printf(_("To undo the tune2fs operation please run "
1578 "the command\n e2undo %s %s\n\n"),
1585 int main(int argc
, char **argv
)
1589 struct ext2_super_block
*sb
;
1590 io_manager io_ptr
, io_ptr_orig
= NULL
;
1593 setlocale(LC_MESSAGES
, "");
1594 setlocale(LC_CTYPE
, "");
1595 bindtextdomain(NLS_CAT_NAME
, LOCALEDIR
);
1596 textdomain(NLS_CAT_NAME
);
1599 program_name
= *argv
;
1600 add_error_table(&et_ext2_error_table
);
1602 #ifdef CONFIG_BUILD_FINDFS
1603 if (strcmp(get_progname(argv
[0]), "findfs") == 0)
1604 do_findfs(argc
, argv
);
1606 if (strcmp(get_progname(argv
[0]), "e2label") == 0)
1607 parse_e2label_options(argc
, argv
);
1609 parse_tune2fs_options(argc
, argv
);
1611 #ifdef CONFIG_TESTIO_DEBUG
1612 if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_DEBUG")) {
1613 io_ptr
= test_io_manager
;
1614 test_io_backing_manager
= unix_io_manager
;
1617 io_ptr
= unix_io_manager
;
1620 retval
= ext2fs_open2(device_name
, io_options
, open_flag
,
1623 com_err(program_name
, retval
,
1624 _("while trying to open %s"),
1627 _("Couldn't find valid filesystem superblock.\n"));
1631 if (I_flag
&& !io_ptr_orig
) {
1633 * Check the inode size is right so we can issue an
1634 * error message and bail before setting up the tdb
1637 if (new_inode_size
== EXT2_INODE_SIZE(fs
->super
)) {
1638 fprintf(stderr
, _("The inode size is already %lu\n"),
1642 if (new_inode_size
< EXT2_INODE_SIZE(fs
->super
)) {
1643 fprintf(stderr
, _("Shrinking the inode size is "
1644 "not supported\n"));
1649 * If inode resize is requested use the
1652 io_ptr_orig
= io_ptr
;
1653 retval
= tune2fs_setup_tdb(device_name
, &io_ptr
);
1656 if (io_ptr
!= io_ptr_orig
) {
1663 fs
->flags
&= ~EXT2_FLAG_MASTER_SB_ONLY
;
1666 /* For e2label emulation */
1667 printf("%.*s\n", (int) sizeof(sb
->s_volume_name
),
1669 remove_error_table(&et_ext2_error_table
);
1673 retval
= ext2fs_check_if_mounted(device_name
, &mount_flags
);
1675 com_err("ext2fs_check_if_mount", retval
,
1676 _("while determining whether %s is mounted."),
1680 /* Normally we only need to write out the superblock */
1681 fs
->flags
|= EXT2_FLAG_SUPER_ONLY
;
1684 sb
->s_max_mnt_count
= max_mount_count
;
1685 ext2fs_mark_super_dirty(fs
);
1686 printf(_("Setting maximal mount count to %d\n"),
1690 sb
->s_mnt_count
= mount_count
;
1691 ext2fs_mark_super_dirty(fs
);
1692 printf(_("Setting current mount count to %d\n"), mount_count
);
1695 sb
->s_errors
= errors
;
1696 ext2fs_mark_super_dirty(fs
);
1697 printf(_("Setting error behavior to %d\n"), errors
);
1700 sb
->s_def_resgid
= resgid
;
1701 ext2fs_mark_super_dirty(fs
);
1702 printf(_("Setting reserved blocks gid to %lu\n"), resgid
);
1705 if (interval
>= (1ULL << 32)) {
1706 com_err(program_name
, 0,
1707 _("interval between checks is too big (%lu)"),
1711 sb
->s_checkinterval
= interval
;
1712 ext2fs_mark_super_dirty(fs
);
1713 printf(_("Setting interval between checks to %lu seconds\n"),
1717 sb
->s_r_blocks_count
= (unsigned int) (reserved_ratio
*
1718 sb
->s_blocks_count
/ 100.0);
1719 ext2fs_mark_super_dirty(fs
);
1720 printf(_("Setting reserved blocks percentage to %g%% "
1722 reserved_ratio
, sb
->s_r_blocks_count
);
1725 if (reserved_blocks
> sb
->s_blocks_count
/2) {
1726 com_err(program_name
, 0,
1727 _("reserved blocks count is too big (%lu)"),
1731 sb
->s_r_blocks_count
= reserved_blocks
;
1732 ext2fs_mark_super_dirty(fs
);
1733 printf(_("Setting reserved blocks count to %lu\n"),
1737 if (sb
->s_feature_ro_compat
&
1738 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER
)
1739 fputs(_("\nThe filesystem already has sparse "
1740 "superblocks.\n"), stderr
);
1742 sb
->s_feature_ro_compat
|=
1743 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER
;
1744 sb
->s_state
&= ~EXT2_VALID_FS
;
1745 ext2fs_mark_super_dirty(fs
);
1746 printf(_("\nSparse superblock flag set. %s"),
1751 fputs(_("\nClearing the sparse superflag not supported.\n"),
1756 sb
->s_lastcheck
= last_check_time
;
1757 ext2fs_mark_super_dirty(fs
);
1758 printf(_("Setting time filesystem last checked to %s\n"),
1759 ctime(&last_check_time
));
1762 sb
->s_def_resuid
= resuid
;
1763 ext2fs_mark_super_dirty(fs
);
1764 printf(_("Setting reserved blocks uid to %lu\n"), resuid
);
1767 if (strlen(new_label
) > sizeof(sb
->s_volume_name
))
1768 fputs(_("Warning: label too long, truncating.\n"),
1770 memset(sb
->s_volume_name
, 0, sizeof(sb
->s_volume_name
));
1771 strncpy(sb
->s_volume_name
, new_label
,
1772 sizeof(sb
->s_volume_name
));
1773 ext2fs_mark_super_dirty(fs
);
1776 memset(sb
->s_last_mounted
, 0, sizeof(sb
->s_last_mounted
));
1777 strncpy(sb
->s_last_mounted
, new_last_mounted
,
1778 sizeof(sb
->s_last_mounted
));
1779 ext2fs_mark_super_dirty(fs
);
1782 update_mntopts(fs
, mntopts_cmd
);
1784 update_feature_set(fs
, features_cmd
);
1786 parse_extended_opts(fs
, extended_cmd
);
1787 if (journal_size
|| journal_device
)
1794 if (sb
->s_feature_ro_compat
&
1795 EXT4_FEATURE_RO_COMPAT_GDT_CSUM
) {
1797 * Determine if the block group checksums are
1798 * correct so we know whether or not to set
1801 for (i
= 0; i
< fs
->group_desc_count
; i
++)
1802 if (!ext2fs_group_desc_csum_verify(fs
, i
))
1804 if (i
>= fs
->group_desc_count
)
1807 if ((strcasecmp(new_UUID
, "null") == 0) ||
1808 (strcasecmp(new_UUID
, "clear") == 0)) {
1809 uuid_clear(sb
->s_uuid
);
1810 } else if (strcasecmp(new_UUID
, "time") == 0) {
1811 uuid_generate_time(sb
->s_uuid
);
1812 } else if (strcasecmp(new_UUID
, "random") == 0) {
1813 uuid_generate(sb
->s_uuid
);
1814 } else if (uuid_parse(new_UUID
, sb
->s_uuid
)) {
1815 com_err(program_name
, 0, _("Invalid UUID format\n"));
1819 for (i
= 0; i
< fs
->group_desc_count
; i
++)
1820 ext2fs_group_desc_csum_set(fs
, i
);
1821 fs
->flags
&= ~EXT2_FLAG_SUPER_ONLY
;
1823 ext2fs_mark_super_dirty(fs
);
1826 if (mount_flags
& EXT2_MF_MOUNTED
) {
1827 fputs(_("The inode size may only be "
1828 "changed when the filesystem is "
1829 "unmounted.\n"), stderr
);
1832 if (fs
->super
->s_feature_incompat
&
1833 EXT4_FEATURE_INCOMPAT_FLEX_BG
) {
1834 fputs(_("Changing the inode size not supported for "
1835 "filesystems with the flex_bg\n"
1836 "feature enabled.\n"),
1841 * We want to update group descriptor also
1842 * with the new free inode count
1844 fs
->flags
&= ~EXT2_FLAG_SUPER_ONLY
;
1845 if (resize_inode(fs
, new_inode_size
) == 0) {
1846 printf(_("Setting inode size %lu\n"),
1854 sb
->s_raid_stride
= stride
;
1855 ext2fs_mark_super_dirty(fs
);
1856 printf(_("Setting stride size to %d\n"), stride
);
1858 if (stripe_width_set
) {
1859 sb
->s_raid_stripe_width
= stripe_width
;
1860 ext2fs_mark_super_dirty(fs
);
1861 printf(_("Setting stripe width to %d\n"), stripe_width
);
1863 if (ext_mount_opts
) {
1864 strncpy(fs
->super
->s_mount_opts
, ext_mount_opts
,
1865 sizeof(fs
->super
->s_mount_opts
));
1866 fs
->super
->s_mount_opts
[sizeof(fs
->super
->s_mount_opts
)-1] = 0;
1867 ext2fs_mark_super_dirty(fs
);
1868 printf(_("Setting extended default mount options to '%s'\n"),
1870 free(ext_mount_opts
);
1873 remove_error_table(&et_ext2_error_table
);
1874 return (ext2fs_close(fs
) ? 1 : 0);