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
;
73 static blk64_t reserved_blocks
;
74 static double reserved_ratio
;
75 static unsigned long resgid
, resuid
;
76 static unsigned short errors
;
78 static char *features_cmd
;
79 static char *mntopts_cmd
;
80 static int stride
, stripe_width
;
81 static int stride_set
, stripe_width_set
;
82 static char *extended_cmd
;
83 static unsigned long new_inode_size
;
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_blk64(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_blk64(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
, blk64_t
*blocknr
,
255 e2_blkcnt_t blockcnt
EXT2FS_ATTR((unused
)),
256 blk64_t ref_block
EXT2FS_ATTR((unused
)),
257 int ref_offset
EXT2FS_ATTR((unused
)),
258 void *private EXT2FS_ATTR((unused
)))
264 ext2fs_unmark_block_bitmap2(fs
->block_map
, block
);
265 group
= ext2fs_group_of_blk2(fs
, block
);
266 ext2fs_bg_free_blocks_count_set(fs
, group
, ext2fs_bg_free_blocks_count(fs
, group
) + 1);
267 ext2fs_group_desc_csum_set(fs
, group
);
268 ext2fs_free_blocks_count_add(fs
->super
, 1);
273 * Remove the journal inode from the filesystem
275 static void remove_journal_inode(ext2_filsys fs
)
277 struct ext2_inode inode
;
279 ino_t ino
= fs
->super
->s_journal_inum
;
281 retval
= ext2fs_read_inode(fs
, ino
, &inode
);
283 com_err(program_name
, retval
,
284 _("while reading journal inode"));
287 if (ino
== EXT2_JOURNAL_INO
) {
288 retval
= ext2fs_read_bitmaps(fs
);
290 com_err(program_name
, retval
,
291 _("while reading bitmaps"));
294 retval
= ext2fs_block_iterate3(fs
, ino
,
295 BLOCK_FLAG_READ_ONLY
, NULL
,
296 release_blocks_proc
, NULL
);
298 com_err(program_name
, retval
,
299 _("while clearing journal inode"));
302 memset(&inode
, 0, sizeof(inode
));
303 ext2fs_mark_bb_dirty(fs
);
304 fs
->flags
&= ~EXT2_FLAG_SUPER_ONLY
;
306 inode
.i_flags
&= ~EXT2_IMMUTABLE_FL
;
307 retval
= ext2fs_write_inode(fs
, ino
, &inode
);
309 com_err(program_name
, retval
,
310 _("while writing journal inode"));
313 fs
->super
->s_journal_inum
= 0;
314 ext2fs_mark_super_dirty(fs
);
318 * Update the default mount options
320 static void update_mntopts(ext2_filsys fs
, char *mntopts
)
322 struct ext2_super_block
*sb
= fs
->super
;
324 if (e2p_edit_mntopts(mntopts
, &sb
->s_default_mount_opts
, ~0)) {
325 fprintf(stderr
, _("Invalid mount option set: %s\n"),
329 ext2fs_mark_super_dirty(fs
);
332 static void request_fsck_afterwards(ext2_filsys fs
)
334 static int requested
= 0;
338 fs
->super
->s_state
&= ~EXT2_VALID_FS
;
339 printf("\n%s\n", _(please_fsck
));
340 if (mount_flags
& EXT2_MF_READONLY
)
341 printf(_("(and reboot afterwards!)\n"));
345 * Update the feature set as provided by the user.
347 static void update_feature_set(ext2_filsys fs
, char *features
)
349 struct ext2_super_block
*sb
= fs
->super
;
350 struct ext2_group_desc
*gd
;
352 __u32 old_features
[3];
354 unsigned int mask_err
;
356 #define FEATURE_ON(type, mask) (!(old_features[(type)] & (mask)) && \
357 ((&sb->s_feature_compat)[(type)] & (mask)))
358 #define FEATURE_OFF(type, mask) ((old_features[(type)] & (mask)) && \
359 !((&sb->s_feature_compat)[(type)] & (mask)))
360 #define FEATURE_CHANGED(type, mask) ((mask) & \
361 (old_features[(type)] ^ (&sb->s_feature_compat)[(type)]))
363 old_features
[E2P_FEATURE_COMPAT
] = sb
->s_feature_compat
;
364 old_features
[E2P_FEATURE_INCOMPAT
] = sb
->s_feature_incompat
;
365 old_features
[E2P_FEATURE_RO_INCOMPAT
] = sb
->s_feature_ro_compat
;
367 if (e2p_edit_feature2(features
, &sb
->s_feature_compat
,
368 ok_features
, clear_ok_features
,
369 &type_err
, &mask_err
)) {
372 _("Invalid filesystem option set: %s\n"),
374 else if (type_err
& E2P_FEATURE_NEGATE_FLAG
)
375 fprintf(stderr
, _("Clearing filesystem feature '%s' "
377 e2p_feature2string(type_err
&
378 E2P_FEATURE_TYPE_MASK
,
381 fprintf(stderr
, _("Setting filesystem feature '%s' "
383 e2p_feature2string(type_err
, mask_err
));
387 if (FEATURE_OFF(E2P_FEATURE_COMPAT
, EXT3_FEATURE_COMPAT_HAS_JOURNAL
)) {
388 if ((mount_flags
& EXT2_MF_MOUNTED
) &&
389 !(mount_flags
& EXT2_MF_READONLY
)) {
390 fputs(_("The has_journal feature may only be "
391 "cleared when the filesystem is\n"
392 "unmounted or mounted "
393 "read-only.\n"), stderr
);
396 if (sb
->s_feature_incompat
&
397 EXT3_FEATURE_INCOMPAT_RECOVER
) {
398 fputs(_("The needs_recovery flag is set. "
399 "Please run e2fsck before clearing\n"
400 "the has_journal flag.\n"), stderr
);
403 if (sb
->s_journal_inum
) {
404 remove_journal_inode(fs
);
406 if (sb
->s_journal_dev
) {
407 remove_journal_device(fs
);
411 if (FEATURE_ON(E2P_FEATURE_COMPAT
, EXT3_FEATURE_COMPAT_HAS_JOURNAL
)) {
413 * If adding a journal flag, let the create journal
414 * code below handle setting the flag and creating the
415 * journal. We supply a default size if necessary.
419 sb
->s_feature_compat
&= ~EXT3_FEATURE_COMPAT_HAS_JOURNAL
;
422 if (FEATURE_ON(E2P_FEATURE_COMPAT
, EXT2_FEATURE_COMPAT_DIR_INDEX
)) {
423 if (!sb
->s_def_hash_version
)
424 sb
->s_def_hash_version
= EXT2_HASH_HALF_MD4
;
425 if (uuid_is_null((unsigned char *) sb
->s_hash_seed
))
426 uuid_generate((unsigned char *) sb
->s_hash_seed
);
429 if (FEATURE_OFF(E2P_FEATURE_INCOMPAT
, EXT4_FEATURE_INCOMPAT_FLEX_BG
)) {
430 if (ext2fs_check_desc(fs
)) {
431 fputs(_("Clearing the flex_bg flag would "
432 "cause the the filesystem to be\n"
433 "inconsistent.\n"), stderr
);
438 if (FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT
,
439 EXT4_FEATURE_RO_COMPAT_HUGE_FILE
)) {
440 if ((mount_flags
& EXT2_MF_MOUNTED
) &&
441 !(mount_flags
& EXT2_MF_READONLY
)) {
442 fputs(_("The huge_file feature may only be "
443 "cleared when the filesystem is\n"
444 "unmounted or mounted "
445 "read-only.\n"), stderr
);
450 if (FEATURE_ON(E2P_FEATURE_RO_INCOMPAT
,
451 EXT4_FEATURE_RO_COMPAT_GDT_CSUM
)) {
452 for (i
= 0; i
< fs
->group_desc_count
; i
++) {
453 gd
= ext2fs_group_desc(fs
, fs
->group_desc
, i
);
454 gd
->bg_itable_unused
= 0;
455 gd
->bg_flags
= EXT2_BG_INODE_ZEROED
;
456 ext2fs_group_desc_csum_set(fs
, i
);
458 fs
->flags
&= ~EXT2_FLAG_SUPER_ONLY
;
461 if (FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT
,
462 EXT4_FEATURE_RO_COMPAT_GDT_CSUM
)) {
463 for (i
= 0; i
< fs
->group_desc_count
; i
++) {
464 gd
= ext2fs_group_desc(fs
, fs
->group_desc
, i
);
465 if ((gd
->bg_flags
& EXT2_BG_INODE_ZEROED
) == 0) {
467 * XXX what we really should do is zap
468 * uninitialized inode tables instead.
470 request_fsck_afterwards(fs
);
473 gd
->bg_itable_unused
= 0;
477 fs
->flags
&= ~EXT2_FLAG_SUPER_ONLY
;
480 if (sb
->s_rev_level
== EXT2_GOOD_OLD_REV
&&
481 (sb
->s_feature_compat
|| sb
->s_feature_ro_compat
||
482 sb
->s_feature_incompat
))
483 ext2fs_update_dynamic_rev(fs
);
485 if (FEATURE_CHANGED(E2P_FEATURE_RO_INCOMPAT
,
486 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER
) ||
487 FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT
,
488 EXT4_FEATURE_RO_COMPAT_HUGE_FILE
) ||
489 FEATURE_CHANGED(E2P_FEATURE_INCOMPAT
,
490 EXT2_FEATURE_INCOMPAT_FILETYPE
) ||
491 FEATURE_CHANGED(E2P_FEATURE_COMPAT
,
492 EXT2_FEATURE_COMPAT_RESIZE_INODE
) ||
493 FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT
,
494 EXT2_FEATURE_RO_COMPAT_LARGE_FILE
))
495 request_fsck_afterwards(fs
);
497 if ((old_features
[E2P_FEATURE_COMPAT
] != sb
->s_feature_compat
) ||
498 (old_features
[E2P_FEATURE_INCOMPAT
] != sb
->s_feature_incompat
) ||
499 (old_features
[E2P_FEATURE_RO_INCOMPAT
] != sb
->s_feature_ro_compat
))
500 ext2fs_mark_super_dirty(fs
);
504 * Add a journal to the filesystem.
506 static void add_journal(ext2_filsys fs
)
508 unsigned long journal_blocks
;
513 if (fs
->super
->s_feature_compat
&
514 EXT3_FEATURE_COMPAT_HAS_JOURNAL
) {
515 fputs(_("The filesystem already has a journal.\n"), stderr
);
518 if (journal_device
) {
519 check_plausibility(journal_device
);
520 check_mount(journal_device
, 0, _("journal"));
521 #ifdef CONFIG_TESTIO_DEBUG
522 if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) {
523 io_ptr
= test_io_manager
;
524 test_io_backing_manager
= unix_io_manager
;
527 io_ptr
= unix_io_manager
;
528 retval
= ext2fs_open(journal_device
, EXT2_FLAG_RW
|
529 EXT2_FLAG_JOURNAL_DEV_OK
, 0,
530 fs
->blocksize
, io_ptr
, &jfs
);
532 com_err(program_name
, retval
,
533 _("\n\twhile trying to open journal on %s\n"),
537 printf(_("Creating journal on device %s: "),
541 retval
= ext2fs_add_journal_device(fs
, jfs
);
544 com_err(program_name
, retval
,
545 _("while adding filesystem to journal on %s"),
549 fputs(_("done\n"), stdout
);
550 } else if (journal_size
) {
551 fputs(_("Creating journal inode: "), stdout
);
553 journal_blocks
= figure_journal_size(journal_size
, fs
);
555 retval
= ext2fs_add_journal_inode(fs
, journal_blocks
,
558 fprintf(stderr
, "\n");
559 com_err(program_name
, retval
,
560 _("\n\twhile trying to create journal file"));
563 fputs(_("done\n"), stdout
);
565 * If the filesystem wasn't mounted, we need to force
566 * the block group descriptors out.
568 if ((mount_flags
& EXT2_MF_MOUNTED
) == 0)
569 fs
->flags
&= ~EXT2_FLAG_SUPER_ONLY
;
571 print_check_message(fs
);
575 free(journal_device
);
580 static void parse_e2label_options(int argc
, char ** argv
)
582 if ((argc
< 2) || (argc
> 3)) {
583 fputs(_("Usage: e2label device [newlabel]\n"), stderr
);
586 io_options
= strchr(argv
[1], '?');
589 device_name
= blkid_get_devname(NULL
, argv
[1], NULL
);
591 com_err("e2label", 0, _("Unable to resolve '%s'"),
595 open_flag
= EXT2_FLAG_JOURNAL_DEV_OK
;
597 open_flag
|= EXT2_FLAG_RW
;
604 static time_t parse_time(char *str
)
608 if (strcmp(str
, "now") == 0) {
611 memset(&ts
, 0, sizeof(ts
));
613 strptime(str
, "%Y%m%d%H%M%S", &ts
);
615 sscanf(str
, "%4d%2d%2d%2d%2d%2d", &ts
.tm_year
, &ts
.tm_mon
,
616 &ts
.tm_mday
, &ts
.tm_hour
, &ts
.tm_min
, &ts
.tm_sec
);
619 if (ts
.tm_year
< 0 || ts
.tm_mon
< 0 || ts
.tm_mon
> 11 ||
620 ts
.tm_mday
< 0 || ts
.tm_mday
> 31 || ts
.tm_hour
> 23 ||
621 ts
.tm_min
> 59 || ts
.tm_sec
> 61)
624 if (ts
.tm_mday
== 0) {
625 com_err(program_name
, 0,
626 _("Couldn't parse date/time specifier: %s"),
631 return (mktime(&ts
));
634 static void parse_tune2fs_options(int argc
, char **argv
)
643 printf("tune2fs %s (%s)\n", E2FSPROGS_VERSION
, E2FSPROGS_DATE
);
644 while ((c
= getopt(argc
, argv
, "c:e:fg:i:jlm:o:r:s:u:C:E:I:J:L:M:O:T:U:")) != EOF
)
647 max_mount_count
= strtol(optarg
, &tmp
, 0);
648 if (*tmp
|| max_mount_count
> 16000) {
649 com_err(program_name
, 0,
650 _("bad mounts count - %s"),
654 if (max_mount_count
== 0)
655 max_mount_count
= -1;
657 open_flag
= EXT2_FLAG_RW
;
660 mount_count
= strtoul(optarg
, &tmp
, 0);
661 if (*tmp
|| mount_count
> 16000) {
662 com_err(program_name
, 0,
663 _("bad mounts count - %s"),
668 open_flag
= EXT2_FLAG_RW
;
671 if (strcmp(optarg
, "continue") == 0)
672 errors
= EXT2_ERRORS_CONTINUE
;
673 else if (strcmp(optarg
, "remount-ro") == 0)
674 errors
= EXT2_ERRORS_RO
;
675 else if (strcmp(optarg
, "panic") == 0)
676 errors
= EXT2_ERRORS_PANIC
;
678 com_err(program_name
, 0,
679 _("bad error behavior - %s"),
684 open_flag
= EXT2_FLAG_RW
;
687 extended_cmd
= optarg
;
688 open_flag
|= EXT2_FLAG_RW
;
690 case 'f': /* Force */
694 resgid
= strtoul(optarg
, &tmp
, 0);
696 gr
= getgrnam(optarg
);
705 com_err(program_name
, 0,
706 _("bad gid/group name - %s"),
711 open_flag
= EXT2_FLAG_RW
;
714 interval
= strtoul(optarg
, &tmp
, 0);
727 case 'M': /* months! */
728 interval
*= 86400 * 30;
732 case 'W': /* weeks */
733 interval
*= 86400 * 7;
738 com_err(program_name
, 0,
739 _("bad interval - %s"), optarg
);
743 open_flag
= EXT2_FLAG_RW
;
748 open_flag
= EXT2_FLAG_RW
;
751 parse_journal_opts(optarg
);
752 open_flag
= EXT2_FLAG_RW
;
760 open_flag
|= EXT2_FLAG_RW
|
761 EXT2_FLAG_JOURNAL_DEV_OK
;
764 reserved_ratio
= strtod(optarg
, &tmp
);
765 if (*tmp
|| reserved_ratio
> 50 ||
766 reserved_ratio
< 0) {
767 com_err(program_name
, 0,
768 _("bad reserved block ratio - %s"),
773 open_flag
= EXT2_FLAG_RW
;
776 new_last_mounted
= optarg
;
778 open_flag
= EXT2_FLAG_RW
;
782 com_err(program_name
, 0,
783 _("-o may only be specified once"));
786 mntopts_cmd
= optarg
;
787 open_flag
= EXT2_FLAG_RW
;
792 com_err(program_name
, 0,
793 _("-O may only be specified once"));
796 features_cmd
= optarg
;
797 open_flag
= EXT2_FLAG_RW
;
800 reserved_blocks
= strtoul(optarg
, &tmp
, 0);
802 com_err(program_name
, 0,
803 _("bad reserved blocks count - %s"),
808 open_flag
= EXT2_FLAG_RW
;
810 case 's': /* Deprecated */
811 s_flag
= atoi(optarg
);
812 open_flag
= EXT2_FLAG_RW
;
816 last_check_time
= parse_time(optarg
);
817 open_flag
= EXT2_FLAG_RW
;
820 resuid
= strtoul(optarg
, &tmp
, 0);
822 pw
= getpwnam(optarg
);
831 com_err(program_name
, 0,
832 _("bad uid/user name - %s"),
837 open_flag
= EXT2_FLAG_RW
;
842 open_flag
= EXT2_FLAG_RW
|
843 EXT2_FLAG_JOURNAL_DEV_OK
;
846 new_inode_size
= strtoul(optarg
, &tmp
, 0);
848 com_err(program_name
, 0,
849 _("bad inode size - %s"),
853 if (!((new_inode_size
&
854 (new_inode_size
- 1)) == 0)) {
855 com_err(program_name
, 0,
856 _("Inode size must be a "
861 open_flag
= EXT2_FLAG_RW
;
867 if (optind
< argc
- 1 || optind
== argc
)
869 if (!open_flag
&& !l_flag
)
871 io_options
= strchr(argv
[optind
], '?');
874 device_name
= blkid_get_devname(NULL
, argv
[optind
], NULL
);
876 com_err("tune2fs", 0, _("Unable to resolve '%s'"),
882 #ifdef CONFIG_BUILD_FINDFS
883 void do_findfs(int argc
, char **argv
)
888 (strncmp(argv
[1], "LABEL=", 6) && strncmp(argv
[1], "UUID=", 5))) {
889 fprintf(stderr
, "Usage: findfs LABEL=<label>|UUID=<uuid>\n");
892 dev
= blkid_get_devname(NULL
, argv
[1], NULL
);
894 com_err("findfs", 0, _("Unable to resolve '%s'"),
903 static void parse_extended_opts(ext2_filsys fs
, const char *opts
)
905 char *buf
, *token
, *next
, *p
, *arg
;
913 _("Couldn't allocate memory to parse options!\n"));
917 for (token
= buf
; token
&& *token
; token
= next
) {
918 p
= strchr(token
, ',');
924 arg
= strchr(token
, '=');
929 if (!strcmp(token
, "test_fs")) {
930 fs
->super
->s_flags
|= EXT2_FLAGS_TEST_FILESYS
;
931 printf("Setting test filesystem flag\n");
932 ext2fs_mark_super_dirty(fs
);
933 } else if (!strcmp(token
, "^test_fs")) {
934 fs
->super
->s_flags
&= ~EXT2_FLAGS_TEST_FILESYS
;
935 printf("Clearing test filesystem flag\n");
936 ext2fs_mark_super_dirty(fs
);
937 } else if (strcmp(token
, "stride") == 0) {
942 stride
= strtoul(arg
, &p
, 0);
943 if (*p
|| (stride
== 0)) {
945 _("Invalid RAID stride: %s\n"),
951 } else if (strcmp(token
, "stripe-width") == 0 ||
952 strcmp(token
, "stripe_width") == 0) {
957 stripe_width
= strtoul(arg
, &p
, 0);
958 if (*p
|| (stripe_width
== 0)) {
960 _("Invalid RAID stripe-width: %s\n"),
965 stripe_width_set
= 1;
966 } else if (strcmp(token
, "hash_alg") == 0 ||
967 strcmp(token
, "hash-alg") == 0) {
972 hash_alg
= e2p_string2hash(arg
);
975 _("Invalid hash algorithm: %s\n"),
980 fs
->super
->s_def_hash_version
= hash_alg
;
981 printf(_("Setting default hash algorithm "
984 ext2fs_mark_super_dirty(fs
);
985 } else if (strcmp(token
, "mount-options")) {
990 if (strlen(arg
) >= sizeof(fs
->super
->s_mount_opts
)) {
992 "Extended mount options too long\n");
995 strcpy(fs
->super
->s_mount_opts
, arg
);
996 ext2fs_mark_super_dirty(fs
);
1001 fprintf(stderr
, _("\nBad options specified.\n\n"
1002 "Extended options are separated by commas, "
1003 "and may take an argument which\n"
1004 "\tis set off by an equals ('=') sign.\n\n"
1005 "Valid extended options are:\n"
1006 "\tstride=<RAID per-disk chunk size in blocks>\n"
1007 "\tstripe_width=<RAID stride*data disks in blocks>\n"
1008 "\thash_alg=<hash algorithm>\n"
1018 * Fill in the block bitmap bmap with the information regarding the
1019 * blocks to be moved
1021 static int get_move_bitmaps(ext2_filsys fs
, int new_ino_blks_per_grp
,
1022 ext2fs_block_bitmap bmap
)
1026 ext2_badblocks_list bb_list
= 0;
1027 blk64_t j
, needed_blocks
= 0;
1028 blk64_t start_blk
, end_blk
;
1030 retval
= ext2fs_read_bb_inode(fs
, &bb_list
);
1034 for (i
= 0; i
< fs
->group_desc_count
; i
++) {
1035 start_blk
= ext2fs_inode_table_loc(fs
, i
) +
1036 fs
->inode_blocks_per_group
;
1038 end_blk
= ext2fs_inode_table_loc(fs
, i
) +
1039 new_ino_blks_per_grp
;
1041 for (j
= start_blk
; j
< end_blk
; j
++) {
1042 if (ext2fs_test_block_bitmap2(fs
->block_map
, j
)) {
1044 * IF the block is a bad block we fail
1046 if (ext2fs_badblocks_list_test(bb_list
, j
)) {
1047 ext2fs_badblocks_list_free(bb_list
);
1051 ext2fs_mark_block_bitmap2(bmap
, j
);
1054 * We are going to use this block for
1055 * inode table. So mark them used.
1057 ext2fs_mark_block_bitmap2(fs
->block_map
, j
);
1060 needed_blocks
+= end_blk
- start_blk
;
1063 ext2fs_badblocks_list_free(bb_list
);
1064 if (needed_blocks
> ext2fs_free_blocks_count(fs
->super
))
1070 static int ext2fs_is_meta_block(ext2_filsys fs
, blk_t blk
)
1073 group
= ext2fs_group_of_blk(fs
, blk
);
1074 if (ext2fs_block_bitmap_loc(fs
, group
) == blk
)
1076 if (ext2fs_inode_bitmap_loc(fs
, group
) == blk
)
1081 static int ext2fs_is_block_in_group(ext2_filsys fs
, dgrp_t group
, blk_t blk
)
1083 blk_t start_blk
, end_blk
;
1084 start_blk
= fs
->super
->s_first_data_block
+
1085 EXT2_BLOCKS_PER_GROUP(fs
->super
) * group
;
1087 * We cannot get new block beyond end_blk for for the last block group
1088 * so we can check with EXT2_BLOCKS_PER_GROUP even for last block group
1090 end_blk
= start_blk
+ EXT2_BLOCKS_PER_GROUP(fs
->super
);
1091 if (blk
>= start_blk
&& blk
<= end_blk
)
1096 static int move_block(ext2_filsys fs
, ext2fs_block_bitmap bmap
)
1103 blk64_t blk
, new_blk
, goal
;
1104 struct blk_move
*bmv
;
1106 retval
= ext2fs_get_mem(fs
->blocksize
, &buf
);
1110 for (new_blk
= blk
= fs
->super
->s_first_data_block
;
1111 blk
< ext2fs_blocks_count(fs
->super
); blk
++) {
1112 if (!ext2fs_test_block_bitmap2(bmap
, blk
))
1115 if (ext2fs_is_meta_block(fs
, blk
)) {
1117 * If the block is mapping a fs meta data block
1118 * like group desc/block bitmap/inode bitmap. We
1119 * should find a block in the same group and fix
1120 * the respective fs metadata pointers. Otherwise
1123 group
= ext2fs_group_of_blk(fs
, blk
);
1124 goal
= ext2fs_group_first_block2(fs
, group
);
1130 retval
= ext2fs_new_block2(fs
, goal
, NULL
, &new_blk
);
1134 /* new fs meta data block should be in the same group */
1135 if (meta_data
&& !ext2fs_is_block_in_group(fs
, group
, new_blk
)) {
1140 /* Mark this block as allocated */
1141 ext2fs_mark_block_bitmap2(fs
->block_map
, new_blk
);
1143 /* Add it to block move list */
1144 retval
= ext2fs_get_mem(sizeof(struct blk_move
), &bmv
);
1149 bmv
->new_loc
= new_blk
;
1151 list_add(&(bmv
->list
), &blk_move_list
);
1153 retval
= io_channel_read_blk64(fs
->io
, blk
, 1, buf
);
1157 retval
= io_channel_write_blk64(fs
->io
, new_blk
, 1, buf
);
1163 ext2fs_free_mem(&buf
);
1167 static blk64_t
translate_block(blk64_t blk
)
1169 struct list_head
*entry
;
1170 struct blk_move
*bmv
;
1172 list_for_each(entry
, &blk_move_list
) {
1173 bmv
= list_entry(entry
, struct blk_move
, list
);
1174 if (bmv
->old_loc
== blk
)
1175 return bmv
->new_loc
;
1181 static int process_block(ext2_filsys fs
EXT2FS_ATTR((unused
)),
1183 e2_blkcnt_t blockcnt
EXT2FS_ATTR((unused
)),
1184 blk64_t ref_block
EXT2FS_ATTR((unused
)),
1185 int ref_offset
EXT2FS_ATTR((unused
)),
1190 ext2fs_block_bitmap bmap
= (ext2fs_block_bitmap
) priv_data
;
1192 if (!ext2fs_test_block_bitmap2(bmap
, *block_nr
))
1194 new_blk
= translate_block(*block_nr
);
1196 *block_nr
= new_blk
;
1198 * This will force the ext2fs_write_inode in the iterator
1200 ret
|= BLOCK_CHANGED
;
1206 static int inode_scan_and_fix(ext2_filsys fs
, ext2fs_block_bitmap bmap
)
1208 errcode_t retval
= 0;
1211 char *block_buf
= 0;
1212 struct ext2_inode inode
;
1213 ext2_inode_scan scan
= NULL
;
1215 retval
= ext2fs_get_mem(fs
->blocksize
* 3, &block_buf
);
1219 retval
= ext2fs_open_inode_scan(fs
, 0, &scan
);
1224 retval
= ext2fs_get_next_inode(scan
, &ino
, &inode
);
1231 if (inode
.i_links_count
== 0)
1232 continue; /* inode not in use */
1235 * If we end up modifying the journal inode
1236 * the sb->s_jnl_blocks will differ. But a
1237 * subsequent e2fsck fixes that.
1238 * Do we need to fix this ??
1241 if (ext2fs_file_acl_block(&inode
) &&
1242 ext2fs_test_block_bitmap2(bmap
,
1243 ext2fs_file_acl_block(&inode
))) {
1244 blk
= translate_block(ext2fs_file_acl_block(&inode
));
1248 ext2fs_file_acl_block_set(&inode
, blk
);
1251 * Write the inode to disk so that inode table
1254 retval
= ext2fs_write_inode(fs
, ino
, &inode
);
1259 if (!ext2fs_inode_has_valid_blocks(&inode
))
1262 retval
= ext2fs_block_iterate3(fs
, ino
, 0, block_buf
,
1263 process_block
, bmap
);
1270 ext2fs_free_mem(&block_buf
);
1276 * We need to scan for inode and block bitmaps that may need to be
1277 * moved. This can take place if the filesystem was formatted for
1278 * RAID arrays using the mke2fs's extended option "stride".
1280 static int group_desc_scan_and_fix(ext2_filsys fs
, ext2fs_block_bitmap bmap
)
1285 for (i
= 0; i
< fs
->group_desc_count
; i
++) {
1286 blk
= ext2fs_block_bitmap_loc(fs
, i
);
1287 if (ext2fs_test_block_bitmap2(bmap
, blk
)) {
1288 new_blk
= translate_block(blk
);
1291 ext2fs_block_bitmap_loc_set(fs
, i
, new_blk
);
1294 blk
= ext2fs_inode_bitmap_loc(fs
, i
);
1295 if (ext2fs_test_block_bitmap2(bmap
, blk
)) {
1296 new_blk
= translate_block(blk
);
1299 ext2fs_inode_bitmap_loc_set(fs
, i
, new_blk
);
1305 static int expand_inode_table(ext2_filsys fs
, unsigned long new_ino_size
)
1310 int new_ino_blks_per_grp
;
1312 char *old_itable
= NULL
, *new_itable
= NULL
;
1313 char *tmp_old_itable
= NULL
, *tmp_new_itable
= NULL
;
1314 unsigned long old_ino_size
;
1315 int old_itable_size
, new_itable_size
;
1317 old_itable_size
= fs
->inode_blocks_per_group
* fs
->blocksize
;
1318 old_ino_size
= EXT2_INODE_SIZE(fs
->super
);
1320 new_ino_blks_per_grp
= ext2fs_div_ceil(
1321 EXT2_INODES_PER_GROUP(fs
->super
) *
1325 new_itable_size
= new_ino_blks_per_grp
* fs
->blocksize
;
1327 retval
= ext2fs_get_mem(old_itable_size
, &old_itable
);
1331 retval
= ext2fs_get_mem(new_itable_size
, &new_itable
);
1335 tmp_old_itable
= old_itable
;
1336 tmp_new_itable
= new_itable
;
1338 for (i
= 0; i
< fs
->group_desc_count
; i
++) {
1339 blk
= ext2fs_inode_table_loc(fs
, i
);
1340 retval
= io_channel_read_blk64(fs
->io
, blk
,
1341 fs
->inode_blocks_per_group
, old_itable
);
1345 for (j
= 0; j
< EXT2_INODES_PER_GROUP(fs
->super
); j
++) {
1346 memcpy(new_itable
, old_itable
, old_ino_size
);
1348 memset(new_itable
+old_ino_size
, 0,
1349 new_ino_size
- old_ino_size
);
1351 new_itable
+= new_ino_size
;
1352 old_itable
+= old_ino_size
;
1355 /* reset the pointer */
1356 old_itable
= tmp_old_itable
;
1357 new_itable
= tmp_new_itable
;
1359 retval
= io_channel_write_blk64(fs
->io
, blk
,
1360 new_ino_blks_per_grp
, new_itable
);
1365 /* Update the meta data */
1366 fs
->inode_blocks_per_group
= new_ino_blks_per_grp
;
1367 fs
->super
->s_inode_size
= new_ino_size
;
1371 ext2fs_free_mem(&old_itable
);
1374 ext2fs_free_mem(&new_itable
);
1379 static errcode_t
ext2fs_calculate_summary_stats(ext2_filsys fs
)
1383 unsigned int group
= 0;
1384 unsigned int count
= 0;
1389 * First calculate the block statistics
1391 for (blk
= fs
->super
->s_first_data_block
;
1392 blk
< ext2fs_blocks_count(fs
->super
); blk
++) {
1393 if (!ext2fs_fast_test_block_bitmap2(fs
->block_map
, blk
)) {
1398 if ((count
== fs
->super
->s_blocks_per_group
) ||
1399 (blk
== ext2fs_blocks_count(fs
->super
)-1)) {
1400 ext2fs_bg_free_blocks_count_set(fs
, group
++,
1406 ext2fs_free_blocks_count_set(fs
->super
, total_free
);
1409 * Next, calculate the inode statistics
1416 /* Protect loop from wrap-around if s_inodes_count maxed */
1417 for (ino
= 1; ino
<= fs
->super
->s_inodes_count
&& ino
> 0; ino
++) {
1418 if (!ext2fs_fast_test_inode_bitmap2(fs
->inode_map
, ino
)) {
1423 if ((count
== fs
->super
->s_inodes_per_group
) ||
1424 (ino
== fs
->super
->s_inodes_count
)) {
1425 ext2fs_bg_free_inodes_count_set(fs
, group
++,
1431 fs
->super
->s_free_inodes_count
= total_free
;
1432 ext2fs_mark_super_dirty(fs
);
1436 #define list_for_each_safe(pos, pnext, head) \
1437 for (pos = (head)->next, pnext = pos->next; pos != (head); \
1438 pos = pnext, pnext = pos->next)
1440 static void free_blk_move_list(void)
1442 struct list_head
*entry
, *tmp
;
1443 struct blk_move
*bmv
;
1445 list_for_each_safe(entry
, tmp
, &blk_move_list
) {
1446 bmv
= list_entry(entry
, struct blk_move
, list
);
1448 ext2fs_free_mem(&bmv
);
1453 static int resize_inode(ext2_filsys fs
, unsigned long new_size
)
1456 int new_ino_blks_per_grp
;
1457 ext2fs_block_bitmap bmap
;
1459 ext2fs_read_inode_bitmap(fs
);
1460 ext2fs_read_block_bitmap(fs
);
1461 INIT_LIST_HEAD(&blk_move_list
);
1464 new_ino_blks_per_grp
= ext2fs_div_ceil(
1465 EXT2_INODES_PER_GROUP(fs
->super
)*
1469 /* We may change the file system.
1470 * Mark the file system as invalid so that
1471 * the user is prompted to run fsck.
1473 fs
->super
->s_state
&= ~EXT2_VALID_FS
;
1475 retval
= ext2fs_allocate_block_bitmap(fs
, _("blocks to be moved"),
1478 fputs(_("Failed to allocate block bitmap when "
1479 "increasing inode size\n"), stderr
);
1482 retval
= get_move_bitmaps(fs
, new_ino_blks_per_grp
, bmap
);
1484 fputs(_("Not enough space to increase inode size \n"), stderr
);
1487 retval
= move_block(fs
, bmap
);
1489 fputs(_("Failed to relocate blocks during inode resize \n"),
1493 retval
= inode_scan_and_fix(fs
, bmap
);
1497 retval
= group_desc_scan_and_fix(fs
, bmap
);
1501 retval
= expand_inode_table(fs
, new_size
);
1505 ext2fs_calculate_summary_stats(fs
);
1507 fs
->super
->s_state
|= EXT2_VALID_FS
;
1508 /* mark super block and block bitmap as dirty */
1509 ext2fs_mark_super_dirty(fs
);
1510 ext2fs_mark_bb_dirty(fs
);
1513 free_blk_move_list();
1514 ext2fs_free_block_bitmap(bmap
);
1519 free_blk_move_list();
1520 ext2fs_free_block_bitmap(bmap
);
1521 fputs(_("Error in resizing the inode size.\n"
1522 "Run e2undo to undo the "
1523 "file system changes. \n"), stderr
);
1528 static int tune2fs_setup_tdb(const char *name
, io_manager
*io_ptr
)
1530 errcode_t retval
= 0;
1531 const char *tdb_dir
;
1533 char *dev_name
, *tmp_name
;
1537 * Configuration via a conf file would be
1540 profile_get_string(profile
, "scratch_files",
1544 tmp_name
= strdup(name
);
1547 com_err(program_name
, ENOMEM
,
1548 _("Couldn't allocate memory for tdb filename\n"));
1551 dev_name
= basename(tmp_name
);
1553 tdb_dir
= getenv("E2FSPROGS_UNDO_DIR");
1555 tdb_dir
= "/var/lib/e2fsprogs";
1557 if (!strcmp(tdb_dir
, "none") || (tdb_dir
[0] == 0) ||
1558 access(tdb_dir
, W_OK
))
1561 tdb_file
= malloc(strlen(tdb_dir
) + 9 + strlen(dev_name
) + 7 + 1);
1564 sprintf(tdb_file
, "%s/tune2fs-%s.e2undo", tdb_dir
, dev_name
);
1566 if (!access(tdb_file
, F_OK
)) {
1567 if (unlink(tdb_file
) < 0) {
1569 com_err(program_name
, retval
,
1570 _("while trying to delete %s"),
1577 set_undo_io_backing_manager(*io_ptr
);
1578 *io_ptr
= undo_io_manager
;
1579 set_undo_io_backup_file(tdb_file
);
1580 printf(_("To undo the tune2fs operation please run "
1581 "the command\n e2undo %s %s\n\n"),
1588 int main(int argc
, char **argv
)
1592 struct ext2_super_block
*sb
;
1593 io_manager io_ptr
, io_ptr_orig
= NULL
;
1596 setlocale(LC_MESSAGES
, "");
1597 setlocale(LC_CTYPE
, "");
1598 bindtextdomain(NLS_CAT_NAME
, LOCALEDIR
);
1599 textdomain(NLS_CAT_NAME
);
1602 program_name
= *argv
;
1603 add_error_table(&et_ext2_error_table
);
1605 #ifdef CONFIG_BUILD_FINDFS
1606 if (strcmp(get_progname(argv
[0]), "findfs") == 0)
1607 do_findfs(argc
, argv
);
1609 if (strcmp(get_progname(argv
[0]), "e2label") == 0)
1610 parse_e2label_options(argc
, argv
);
1612 parse_tune2fs_options(argc
, argv
);
1614 #ifdef CONFIG_TESTIO_DEBUG
1615 if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_DEBUG")) {
1616 io_ptr
= test_io_manager
;
1617 test_io_backing_manager
= unix_io_manager
;
1620 io_ptr
= unix_io_manager
;
1623 retval
= ext2fs_open2(device_name
, io_options
, open_flag
,
1626 com_err(program_name
, retval
,
1627 _("while trying to open %s"),
1630 _("Couldn't find valid filesystem superblock.\n"));
1634 if (I_flag
&& !io_ptr_orig
) {
1636 * Check the inode size is right so we can issue an
1637 * error message and bail before setting up the tdb
1640 if (new_inode_size
== EXT2_INODE_SIZE(fs
->super
)) {
1641 fprintf(stderr
, _("The inode size is already %lu\n"),
1645 if (new_inode_size
< EXT2_INODE_SIZE(fs
->super
)) {
1646 fprintf(stderr
, _("Shrinking the inode size is "
1647 "not supported\n"));
1652 * If inode resize is requested use the
1655 io_ptr_orig
= io_ptr
;
1656 retval
= tune2fs_setup_tdb(device_name
, &io_ptr
);
1659 if (io_ptr
!= io_ptr_orig
) {
1666 fs
->flags
&= ~EXT2_FLAG_MASTER_SB_ONLY
;
1669 /* For e2label emulation */
1670 printf("%.*s\n", (int) sizeof(sb
->s_volume_name
),
1672 remove_error_table(&et_ext2_error_table
);
1676 retval
= ext2fs_check_if_mounted(device_name
, &mount_flags
);
1678 com_err("ext2fs_check_if_mount", retval
,
1679 _("while determining whether %s is mounted."),
1683 /* Normally we only need to write out the superblock */
1684 fs
->flags
|= EXT2_FLAG_SUPER_ONLY
;
1687 sb
->s_max_mnt_count
= max_mount_count
;
1688 ext2fs_mark_super_dirty(fs
);
1689 printf(_("Setting maximal mount count to %d\n"),
1693 sb
->s_mnt_count
= mount_count
;
1694 ext2fs_mark_super_dirty(fs
);
1695 printf(_("Setting current mount count to %d\n"), mount_count
);
1698 sb
->s_errors
= errors
;
1699 ext2fs_mark_super_dirty(fs
);
1700 printf(_("Setting error behavior to %d\n"), errors
);
1703 sb
->s_def_resgid
= resgid
;
1704 ext2fs_mark_super_dirty(fs
);
1705 printf(_("Setting reserved blocks gid to %lu\n"), resgid
);
1708 if (interval
>= (1ULL << 32)) {
1709 com_err(program_name
, 0,
1710 _("interval between checks is too big (%lu)"),
1714 sb
->s_checkinterval
= interval
;
1715 ext2fs_mark_super_dirty(fs
);
1716 printf(_("Setting interval between checks to %lu seconds\n"),
1720 ext2fs_r_blocks_count_set(sb
, reserved_ratio
*
1721 ext2fs_blocks_count(sb
) / 100.0);
1722 ext2fs_mark_super_dirty(fs
);
1723 printf (_("Setting reserved blocks percentage to %g%% (%llu blocks)\n"),
1724 reserved_ratio
, ext2fs_r_blocks_count(sb
));
1727 if (reserved_blocks
> ext2fs_blocks_count(sb
)/2) {
1728 com_err(program_name
, 0,
1729 _("reserved blocks count is too big (%llu)"),
1733 ext2fs_r_blocks_count_set(sb
, reserved_blocks
);
1734 ext2fs_mark_super_dirty(fs
);
1735 printf(_("Setting reserved blocks count to %llu\n"),
1739 if (sb
->s_feature_ro_compat
&
1740 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER
)
1741 fputs(_("\nThe filesystem already has sparse "
1742 "superblocks.\n"), stderr
);
1744 sb
->s_feature_ro_compat
|=
1745 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER
;
1746 sb
->s_state
&= ~EXT2_VALID_FS
;
1747 ext2fs_mark_super_dirty(fs
);
1748 printf(_("\nSparse superblock flag set. %s"),
1753 fputs(_("\nClearing the sparse superflag not supported.\n"),
1758 sb
->s_lastcheck
= last_check_time
;
1759 ext2fs_mark_super_dirty(fs
);
1760 printf(_("Setting time filesystem last checked to %s\n"),
1761 ctime(&last_check_time
));
1764 sb
->s_def_resuid
= resuid
;
1765 ext2fs_mark_super_dirty(fs
);
1766 printf(_("Setting reserved blocks uid to %lu\n"), resuid
);
1769 if (strlen(new_label
) > sizeof(sb
->s_volume_name
))
1770 fputs(_("Warning: label too long, truncating.\n"),
1772 memset(sb
->s_volume_name
, 0, sizeof(sb
->s_volume_name
));
1773 strncpy(sb
->s_volume_name
, new_label
,
1774 sizeof(sb
->s_volume_name
));
1775 ext2fs_mark_super_dirty(fs
);
1778 memset(sb
->s_last_mounted
, 0, sizeof(sb
->s_last_mounted
));
1779 strncpy(sb
->s_last_mounted
, new_last_mounted
,
1780 sizeof(sb
->s_last_mounted
));
1781 ext2fs_mark_super_dirty(fs
);
1784 update_mntopts(fs
, mntopts_cmd
);
1786 update_feature_set(fs
, features_cmd
);
1788 parse_extended_opts(fs
, extended_cmd
);
1789 if (journal_size
|| journal_device
)
1796 if (sb
->s_feature_ro_compat
&
1797 EXT4_FEATURE_RO_COMPAT_GDT_CSUM
) {
1799 * Determine if the block group checksums are
1800 * correct so we know whether or not to set
1803 for (i
= 0; i
< fs
->group_desc_count
; i
++)
1804 if (!ext2fs_group_desc_csum_verify(fs
, i
))
1806 if (i
>= fs
->group_desc_count
)
1809 if ((strcasecmp(new_UUID
, "null") == 0) ||
1810 (strcasecmp(new_UUID
, "clear") == 0)) {
1811 uuid_clear(sb
->s_uuid
);
1812 } else if (strcasecmp(new_UUID
, "time") == 0) {
1813 uuid_generate_time(sb
->s_uuid
);
1814 } else if (strcasecmp(new_UUID
, "random") == 0) {
1815 uuid_generate(sb
->s_uuid
);
1816 } else if (uuid_parse(new_UUID
, sb
->s_uuid
)) {
1817 com_err(program_name
, 0, _("Invalid UUID format\n"));
1821 for (i
= 0; i
< fs
->group_desc_count
; i
++)
1822 ext2fs_group_desc_csum_set(fs
, i
);
1823 fs
->flags
&= ~EXT2_FLAG_SUPER_ONLY
;
1825 ext2fs_mark_super_dirty(fs
);
1828 if (mount_flags
& EXT2_MF_MOUNTED
) {
1829 fputs(_("The inode size may only be "
1830 "changed when the filesystem is "
1831 "unmounted.\n"), stderr
);
1834 if (fs
->super
->s_feature_incompat
&
1835 EXT4_FEATURE_INCOMPAT_FLEX_BG
) {
1836 fputs(_("Changing the inode size not supported for "
1837 "filesystems with the flex_bg\n"
1838 "feature enabled.\n"),
1843 * We want to update group descriptor also
1844 * with the new free inode count
1846 fs
->flags
&= ~EXT2_FLAG_SUPER_ONLY
;
1847 if (resize_inode(fs
, new_inode_size
) == 0) {
1848 printf(_("Setting inode size %lu\n"),
1856 sb
->s_raid_stride
= stride
;
1857 ext2fs_mark_super_dirty(fs
);
1858 printf(_("Setting stride size to %d\n"), stride
);
1860 if (stripe_width_set
) {
1861 sb
->s_raid_stripe_width
= stripe_width
;
1862 ext2fs_mark_super_dirty(fs
);
1863 printf(_("Setting stripe width to %d\n"), stripe_width
);
1866 remove_error_table(&et_ext2_error_table
);
1867 return (ext2fs_close(fs
) ? 1 : 0);