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
, blk_t
*blocknr
,
255 int blockcnt
EXT2FS_ATTR((unused
)),
256 void *private EXT2FS_ATTR((unused
)))
262 ext2fs_unmark_block_bitmap2(fs
->block_map
, block
);
263 group
= ext2fs_group_of_blk2(fs
, block
);
264 ext2fs_bg_free_blocks_count_set(fs
, group
, ext2fs_bg_free_blocks_count(fs
, group
) + 1);
265 ext2fs_group_desc_csum_set(fs
, group
);
266 ext2fs_free_blocks_count_add(fs
->super
, 1);
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
);
331 * Update the feature set as provided by the user.
333 static void update_feature_set(ext2_filsys fs
, char *features
)
335 struct ext2_super_block
*sb
= fs
->super
;
336 __u32 old_features
[3];
338 unsigned int mask_err
;
340 #define FEATURE_ON(type, mask) (!(old_features[(type)] & (mask)) && \
341 ((&sb->s_feature_compat)[(type)] & (mask)))
342 #define FEATURE_OFF(type, mask) ((old_features[(type)] & (mask)) && \
343 !((&sb->s_feature_compat)[(type)] & (mask)))
344 #define FEATURE_CHANGED(type, mask) ((mask) & \
345 (old_features[(type)] ^ (&sb->s_feature_compat)[(type)]))
347 old_features
[E2P_FEATURE_COMPAT
] = sb
->s_feature_compat
;
348 old_features
[E2P_FEATURE_INCOMPAT
] = sb
->s_feature_incompat
;
349 old_features
[E2P_FEATURE_RO_INCOMPAT
] = sb
->s_feature_ro_compat
;
351 if (e2p_edit_feature2(features
, &sb
->s_feature_compat
,
352 ok_features
, clear_ok_features
,
353 &type_err
, &mask_err
)) {
356 _("Invalid filesystem option set: %s\n"),
358 else if (type_err
& E2P_FEATURE_NEGATE_FLAG
)
359 fprintf(stderr
, _("Clearing filesystem feature '%s' "
361 e2p_feature2string(type_err
&
362 E2P_FEATURE_TYPE_MASK
,
365 fprintf(stderr
, _("Setting filesystem feature '%s' "
367 e2p_feature2string(type_err
, mask_err
));
371 if (FEATURE_OFF(E2P_FEATURE_COMPAT
, EXT3_FEATURE_COMPAT_HAS_JOURNAL
)) {
372 if ((mount_flags
& EXT2_MF_MOUNTED
) &&
373 !(mount_flags
& EXT2_MF_READONLY
)) {
374 fputs(_("The has_journal feature may only be "
375 "cleared when the filesystem is\n"
376 "unmounted or mounted "
377 "read-only.\n"), stderr
);
380 if (sb
->s_feature_incompat
&
381 EXT3_FEATURE_INCOMPAT_RECOVER
) {
382 fputs(_("The needs_recovery flag is set. "
383 "Please run e2fsck before clearing\n"
384 "the has_journal flag.\n"), stderr
);
387 if (sb
->s_journal_inum
) {
388 remove_journal_inode(fs
);
390 if (sb
->s_journal_dev
) {
391 remove_journal_device(fs
);
395 if (FEATURE_ON(E2P_FEATURE_COMPAT
, EXT3_FEATURE_COMPAT_HAS_JOURNAL
)) {
397 * If adding a journal flag, let the create journal
398 * code below handle setting the flag and creating the
399 * journal. We supply a default size if necessary.
403 sb
->s_feature_compat
&= ~EXT3_FEATURE_COMPAT_HAS_JOURNAL
;
406 if (FEATURE_ON(E2P_FEATURE_COMPAT
, EXT2_FEATURE_COMPAT_DIR_INDEX
)) {
407 if (!sb
->s_def_hash_version
)
408 sb
->s_def_hash_version
= EXT2_HASH_HALF_MD4
;
409 if (uuid_is_null((unsigned char *) sb
->s_hash_seed
))
410 uuid_generate((unsigned char *) sb
->s_hash_seed
);
413 if (FEATURE_OFF(E2P_FEATURE_INCOMPAT
, EXT4_FEATURE_INCOMPAT_FLEX_BG
)) {
414 if (ext2fs_check_desc(fs
)) {
415 fputs(_("Clearing the flex_bg flag would "
416 "cause the the filesystem to be\n"
417 "inconsistent.\n"), stderr
);
422 if (FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT
,
423 EXT4_FEATURE_RO_COMPAT_HUGE_FILE
)) {
424 if ((mount_flags
& EXT2_MF_MOUNTED
) &&
425 !(mount_flags
& EXT2_MF_READONLY
)) {
426 fputs(_("The huge_file feature may only be "
427 "cleared when the filesystem is\n"
428 "unmounted or mounted "
429 "read-only.\n"), stderr
);
434 if (sb
->s_rev_level
== EXT2_GOOD_OLD_REV
&&
435 (sb
->s_feature_compat
|| sb
->s_feature_ro_compat
||
436 sb
->s_feature_incompat
))
437 ext2fs_update_dynamic_rev(fs
);
439 if (FEATURE_CHANGED(E2P_FEATURE_RO_INCOMPAT
,
440 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER
) ||
441 FEATURE_CHANGED(E2P_FEATURE_RO_INCOMPAT
,
442 EXT4_FEATURE_RO_COMPAT_GDT_CSUM
) ||
443 FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT
,
444 EXT4_FEATURE_RO_COMPAT_HUGE_FILE
) ||
445 FEATURE_CHANGED(E2P_FEATURE_INCOMPAT
,
446 EXT2_FEATURE_INCOMPAT_FILETYPE
) ||
447 FEATURE_CHANGED(E2P_FEATURE_COMPAT
,
448 EXT2_FEATURE_COMPAT_RESIZE_INODE
) ||
449 FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT
,
450 EXT2_FEATURE_RO_COMPAT_LARGE_FILE
)) {
451 sb
->s_state
&= ~EXT2_VALID_FS
;
452 printf("\n%s\n", _(please_fsck
));
453 if (mount_flags
& EXT2_MF_READONLY
)
454 printf(_("(and reboot afterwards!)\n"));
457 if ((old_features
[E2P_FEATURE_COMPAT
] != sb
->s_feature_compat
) ||
458 (old_features
[E2P_FEATURE_INCOMPAT
] != sb
->s_feature_incompat
) ||
459 (old_features
[E2P_FEATURE_RO_INCOMPAT
] != sb
->s_feature_ro_compat
))
460 ext2fs_mark_super_dirty(fs
);
464 * Add a journal to the filesystem.
466 static void add_journal(ext2_filsys fs
)
468 unsigned long journal_blocks
;
473 if (fs
->super
->s_feature_compat
&
474 EXT3_FEATURE_COMPAT_HAS_JOURNAL
) {
475 fputs(_("The filesystem already has a journal.\n"), stderr
);
478 if (journal_device
) {
479 check_plausibility(journal_device
);
480 check_mount(journal_device
, 0, _("journal"));
481 #ifdef CONFIG_TESTIO_DEBUG
482 if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) {
483 io_ptr
= test_io_manager
;
484 test_io_backing_manager
= unix_io_manager
;
487 io_ptr
= unix_io_manager
;
488 retval
= ext2fs_open(journal_device
, EXT2_FLAG_RW
|
489 EXT2_FLAG_JOURNAL_DEV_OK
, 0,
490 fs
->blocksize
, io_ptr
, &jfs
);
492 com_err(program_name
, retval
,
493 _("\n\twhile trying to open journal on %s\n"),
497 printf(_("Creating journal on device %s: "),
501 retval
= ext2fs_add_journal_device(fs
, jfs
);
504 com_err(program_name
, retval
,
505 _("while adding filesystem to journal on %s"),
509 fputs(_("done\n"), stdout
);
510 } else if (journal_size
) {
511 fputs(_("Creating journal inode: "), stdout
);
513 journal_blocks
= figure_journal_size(journal_size
, fs
);
515 retval
= ext2fs_add_journal_inode(fs
, journal_blocks
,
518 fprintf(stderr
, "\n");
519 com_err(program_name
, retval
,
520 _("\n\twhile trying to create journal file"));
523 fputs(_("done\n"), stdout
);
525 * If the filesystem wasn't mounted, we need to force
526 * the block group descriptors out.
528 if ((mount_flags
& EXT2_MF_MOUNTED
) == 0)
529 fs
->flags
&= ~EXT2_FLAG_SUPER_ONLY
;
531 print_check_message(fs
);
535 free(journal_device
);
540 static void parse_e2label_options(int argc
, char ** argv
)
542 if ((argc
< 2) || (argc
> 3)) {
543 fputs(_("Usage: e2label device [newlabel]\n"), stderr
);
546 io_options
= strchr(argv
[1], '?');
549 device_name
= blkid_get_devname(NULL
, argv
[1], NULL
);
551 com_err("e2label", 0, _("Unable to resolve '%s'"),
555 open_flag
= EXT2_FLAG_JOURNAL_DEV_OK
;
557 open_flag
|= EXT2_FLAG_RW
;
564 static time_t parse_time(char *str
)
568 if (strcmp(str
, "now") == 0) {
571 memset(&ts
, 0, sizeof(ts
));
573 strptime(str
, "%Y%m%d%H%M%S", &ts
);
575 sscanf(str
, "%4d%2d%2d%2d%2d%2d", &ts
.tm_year
, &ts
.tm_mon
,
576 &ts
.tm_mday
, &ts
.tm_hour
, &ts
.tm_min
, &ts
.tm_sec
);
579 if (ts
.tm_year
< 0 || ts
.tm_mon
< 0 || ts
.tm_mon
> 11 ||
580 ts
.tm_mday
< 0 || ts
.tm_mday
> 31 || ts
.tm_hour
> 23 ||
581 ts
.tm_min
> 59 || ts
.tm_sec
> 61)
584 if (ts
.tm_mday
== 0) {
585 com_err(program_name
, 0,
586 _("Couldn't parse date/time specifier: %s"),
591 return (mktime(&ts
));
594 static void parse_tune2fs_options(int argc
, char **argv
)
603 printf("tune2fs %s (%s)\n", E2FSPROGS_VERSION
, E2FSPROGS_DATE
);
604 while ((c
= getopt(argc
, argv
, "c:e:fg:i:jlm:o:r:s:u:C:E:I:J:L:M:O:T:U:")) != EOF
)
607 max_mount_count
= strtol(optarg
, &tmp
, 0);
608 if (*tmp
|| max_mount_count
> 16000) {
609 com_err(program_name
, 0,
610 _("bad mounts count - %s"),
614 if (max_mount_count
== 0)
615 max_mount_count
= -1;
617 open_flag
= EXT2_FLAG_RW
;
620 mount_count
= strtoul(optarg
, &tmp
, 0);
621 if (*tmp
|| mount_count
> 16000) {
622 com_err(program_name
, 0,
623 _("bad mounts count - %s"),
628 open_flag
= EXT2_FLAG_RW
;
631 if (strcmp(optarg
, "continue") == 0)
632 errors
= EXT2_ERRORS_CONTINUE
;
633 else if (strcmp(optarg
, "remount-ro") == 0)
634 errors
= EXT2_ERRORS_RO
;
635 else if (strcmp(optarg
, "panic") == 0)
636 errors
= EXT2_ERRORS_PANIC
;
638 com_err(program_name
, 0,
639 _("bad error behavior - %s"),
644 open_flag
= EXT2_FLAG_RW
;
647 extended_cmd
= optarg
;
648 open_flag
|= EXT2_FLAG_RW
;
650 case 'f': /* Force */
654 resgid
= strtoul(optarg
, &tmp
, 0);
656 gr
= getgrnam(optarg
);
665 com_err(program_name
, 0,
666 _("bad gid/group name - %s"),
671 open_flag
= EXT2_FLAG_RW
;
674 interval
= strtoul(optarg
, &tmp
, 0);
687 case 'M': /* months! */
688 interval
*= 86400 * 30;
692 case 'W': /* weeks */
693 interval
*= 86400 * 7;
698 com_err(program_name
, 0,
699 _("bad interval - %s"), optarg
);
703 open_flag
= EXT2_FLAG_RW
;
708 open_flag
= EXT2_FLAG_RW
;
711 parse_journal_opts(optarg
);
712 open_flag
= EXT2_FLAG_RW
;
720 open_flag
|= EXT2_FLAG_RW
|
721 EXT2_FLAG_JOURNAL_DEV_OK
;
724 reserved_ratio
= strtod(optarg
, &tmp
);
725 if (*tmp
|| reserved_ratio
> 50 ||
726 reserved_ratio
< 0) {
727 com_err(program_name
, 0,
728 _("bad reserved block ratio - %s"),
733 open_flag
= EXT2_FLAG_RW
;
736 new_last_mounted
= optarg
;
738 open_flag
= EXT2_FLAG_RW
;
742 com_err(program_name
, 0,
743 _("-o may only be specified once"));
746 mntopts_cmd
= optarg
;
747 open_flag
= EXT2_FLAG_RW
;
752 com_err(program_name
, 0,
753 _("-O may only be specified once"));
756 features_cmd
= optarg
;
757 open_flag
= EXT2_FLAG_RW
;
760 reserved_blocks
= strtoul(optarg
, &tmp
, 0);
762 com_err(program_name
, 0,
763 _("bad reserved blocks count - %s"),
768 open_flag
= EXT2_FLAG_RW
;
770 case 's': /* Deprecated */
771 s_flag
= atoi(optarg
);
772 open_flag
= EXT2_FLAG_RW
;
776 last_check_time
= parse_time(optarg
);
777 open_flag
= EXT2_FLAG_RW
;
780 resuid
= strtoul(optarg
, &tmp
, 0);
782 pw
= getpwnam(optarg
);
791 com_err(program_name
, 0,
792 _("bad uid/user name - %s"),
797 open_flag
= EXT2_FLAG_RW
;
802 open_flag
= EXT2_FLAG_RW
|
803 EXT2_FLAG_JOURNAL_DEV_OK
;
806 new_inode_size
= strtoul(optarg
, &tmp
, 0);
808 com_err(program_name
, 0,
809 _("bad inode size - %s"),
813 if (!((new_inode_size
&
814 (new_inode_size
- 1)) == 0)) {
815 com_err(program_name
, 0,
816 _("Inode size must be a "
821 open_flag
= EXT2_FLAG_RW
;
827 if (optind
< argc
- 1 || optind
== argc
)
829 if (!open_flag
&& !l_flag
)
831 io_options
= strchr(argv
[optind
], '?');
834 device_name
= blkid_get_devname(NULL
, argv
[optind
], NULL
);
836 com_err("tune2fs", 0, _("Unable to resolve '%s'"),
842 #ifdef CONFIG_BUILD_FINDFS
843 void do_findfs(int argc
, char **argv
)
848 (strncmp(argv
[1], "LABEL=", 6) && strncmp(argv
[1], "UUID=", 5))) {
849 fprintf(stderr
, "Usage: findfs LABEL=<label>|UUID=<uuid>\n");
852 dev
= blkid_get_devname(NULL
, argv
[1], NULL
);
854 com_err("findfs", 0, _("Unable to resolve '%s'"),
863 static void parse_extended_opts(ext2_filsys fs
, const char *opts
)
865 char *buf
, *token
, *next
, *p
, *arg
;
873 _("Couldn't allocate memory to parse options!\n"));
877 for (token
= buf
; token
&& *token
; token
= next
) {
878 p
= strchr(token
, ',');
884 arg
= strchr(token
, '=');
889 if (!strcmp(token
, "test_fs")) {
890 fs
->super
->s_flags
|= EXT2_FLAGS_TEST_FILESYS
;
891 printf("Setting test filesystem flag\n");
892 ext2fs_mark_super_dirty(fs
);
893 } else if (!strcmp(token
, "^test_fs")) {
894 fs
->super
->s_flags
&= ~EXT2_FLAGS_TEST_FILESYS
;
895 printf("Clearing test filesystem flag\n");
896 ext2fs_mark_super_dirty(fs
);
897 } else if (strcmp(token
, "stride") == 0) {
902 stride
= strtoul(arg
, &p
, 0);
903 if (*p
|| (stride
== 0)) {
905 _("Invalid RAID stride: %s\n"),
911 } else if (strcmp(token
, "stripe-width") == 0 ||
912 strcmp(token
, "stripe_width") == 0) {
917 stripe_width
= strtoul(arg
, &p
, 0);
918 if (*p
|| (stripe_width
== 0)) {
920 _("Invalid RAID stripe-width: %s\n"),
925 stripe_width_set
= 1;
926 } else if (strcmp(token
, "hash_alg") == 0 ||
927 strcmp(token
, "hash-alg") == 0) {
932 hash_alg
= e2p_string2hash(arg
);
935 _("Invalid hash algorithm: %s\n"),
940 fs
->super
->s_def_hash_version
= hash_alg
;
941 printf(_("Setting default hash algorithm "
944 ext2fs_mark_super_dirty(fs
);
949 fprintf(stderr
, _("\nBad options specified.\n\n"
950 "Extended options are separated by commas, "
951 "and may take an argument which\n"
952 "\tis set off by an equals ('=') sign.\n\n"
953 "Valid extended options are:\n"
954 "\tstride=<RAID per-disk chunk size in blocks>\n"
955 "\tstripe_width=<RAID stride*data disks in blocks>\n"
956 "\thash_alg=<hash algorithm>\n"
966 * Fill in the block bitmap bmap with the information regarding the
969 static int get_move_bitmaps(ext2_filsys fs
, int new_ino_blks_per_grp
,
970 ext2fs_block_bitmap bmap
)
974 ext2_badblocks_list bb_list
= 0;
975 blk_t j
, needed_blocks
= 0;
976 blk_t start_blk
, end_blk
;
978 retval
= ext2fs_read_bb_inode(fs
, &bb_list
);
982 for (i
= 0; i
< fs
->group_desc_count
; i
++) {
983 start_blk
= ext2fs_inode_table_loc(fs
, i
) +
984 fs
->inode_blocks_per_group
;
986 end_blk
= ext2fs_inode_table_loc(fs
, i
) +
987 new_ino_blks_per_grp
;
989 for (j
= start_blk
; j
< end_blk
; j
++) {
990 if (ext2fs_test_block_bitmap2(fs
->block_map
, j
)) {
992 * IF the block is a bad block we fail
994 if (ext2fs_badblocks_list_test(bb_list
, j
)) {
995 ext2fs_badblocks_list_free(bb_list
);
999 ext2fs_mark_block_bitmap2(bmap
, j
);
1002 * We are going to use this block for
1003 * inode table. So mark them used.
1005 ext2fs_mark_block_bitmap2(fs
->block_map
, j
);
1008 needed_blocks
+= end_blk
- start_blk
;
1011 ext2fs_badblocks_list_free(bb_list
);
1012 if (needed_blocks
> ext2fs_free_blocks_count(fs
->super
))
1018 static int ext2fs_is_meta_block(ext2_filsys fs
, blk_t blk
)
1021 group
= ext2fs_group_of_blk(fs
, blk
);
1022 if (ext2fs_block_bitmap_loc(fs
, group
) == blk
)
1024 if (ext2fs_inode_bitmap_loc(fs
, group
) == blk
)
1029 static int ext2fs_is_block_in_group(ext2_filsys fs
, dgrp_t group
, blk_t blk
)
1031 blk_t start_blk
, end_blk
;
1032 start_blk
= fs
->super
->s_first_data_block
+
1033 EXT2_BLOCKS_PER_GROUP(fs
->super
) * group
;
1035 * We cannot get new block beyond end_blk for for the last block group
1036 * so we can check with EXT2_BLOCKS_PER_GROUP even for last block group
1038 end_blk
= start_blk
+ EXT2_BLOCKS_PER_GROUP(fs
->super
);
1039 if (blk
>= start_blk
&& blk
<= end_blk
)
1044 static int move_block(ext2_filsys fs
, ext2fs_block_bitmap bmap
)
1051 blk_t blk
, new_blk
, goal
;
1052 struct blk_move
*bmv
;
1054 retval
= ext2fs_get_mem(fs
->blocksize
, &buf
);
1058 for (new_blk
= blk
= fs
->super
->s_first_data_block
;
1059 blk
< ext2fs_blocks_count(fs
->super
); blk
++) {
1060 if (!ext2fs_test_block_bitmap2(bmap
, blk
))
1063 if (ext2fs_is_meta_block(fs
, blk
)) {
1065 * If the block is mapping a fs meta data block
1066 * like group desc/block bitmap/inode bitmap. We
1067 * should find a block in the same group and fix
1068 * the respective fs metadata pointers. Otherwise
1071 group
= ext2fs_group_of_blk(fs
, blk
);
1072 goal
= ext2fs_group_first_block2(fs
, group
);
1078 retval
= ext2fs_new_block(fs
, goal
, NULL
, &new_blk
);
1082 /* new fs meta data block should be in the same group */
1083 if (meta_data
&& !ext2fs_is_block_in_group(fs
, group
, new_blk
)) {
1088 /* Mark this block as allocated */
1089 ext2fs_mark_block_bitmap2(fs
->block_map
, new_blk
);
1091 /* Add it to block move list */
1092 retval
= ext2fs_get_mem(sizeof(struct blk_move
), &bmv
);
1097 bmv
->new_loc
= new_blk
;
1099 list_add(&(bmv
->list
), &blk_move_list
);
1101 retval
= io_channel_read_blk64(fs
->io
, blk
, 1, buf
);
1105 retval
= io_channel_write_blk64(fs
->io
, new_blk
, 1, buf
);
1111 ext2fs_free_mem(&buf
);
1115 static blk_t
translate_block(blk_t blk
)
1117 struct list_head
*entry
;
1118 struct blk_move
*bmv
;
1120 list_for_each(entry
, &blk_move_list
) {
1121 bmv
= list_entry(entry
, struct blk_move
, list
);
1122 if (bmv
->old_loc
== blk
)
1123 return bmv
->new_loc
;
1129 static int process_block(ext2_filsys fs
EXT2FS_ATTR((unused
)),
1131 e2_blkcnt_t blockcnt
EXT2FS_ATTR((unused
)),
1132 blk_t ref_block
EXT2FS_ATTR((unused
)),
1133 int ref_offset
EXT2FS_ATTR((unused
)),
1138 ext2fs_block_bitmap bmap
= (ext2fs_block_bitmap
) priv_data
;
1140 if (!ext2fs_test_block_bitmap2(bmap
, *block_nr
))
1142 new_blk
= translate_block(*block_nr
);
1144 *block_nr
= new_blk
;
1146 * This will force the ext2fs_write_inode in the iterator
1148 ret
|= BLOCK_CHANGED
;
1154 static int inode_scan_and_fix(ext2_filsys fs
, ext2fs_block_bitmap bmap
)
1156 errcode_t retval
= 0;
1159 char *block_buf
= 0;
1160 struct ext2_inode inode
;
1161 ext2_inode_scan scan
= NULL
;
1163 retval
= ext2fs_get_mem(fs
->blocksize
* 3, &block_buf
);
1167 retval
= ext2fs_open_inode_scan(fs
, 0, &scan
);
1172 retval
= ext2fs_get_next_inode(scan
, &ino
, &inode
);
1179 if (inode
.i_links_count
== 0)
1180 continue; /* inode not in use */
1183 * If we end up modifying the journal inode
1184 * the sb->s_jnl_blocks will differ. But a
1185 * subsequent e2fsck fixes that.
1186 * Do we need to fix this ??
1189 if (ext2fs_file_acl_block(&inode
) &&
1190 ext2fs_test_block_bitmap2(bmap
,
1191 ext2fs_file_acl_block(&inode
))) {
1192 blk
= translate_block(ext2fs_file_acl_block(&inode
));
1196 ext2fs_file_acl_block_set(&inode
, blk
);
1199 * Write the inode to disk so that inode table
1202 retval
= ext2fs_write_inode(fs
, ino
, &inode
);
1207 if (!ext2fs_inode_has_valid_blocks(&inode
))
1210 retval
= ext2fs_block_iterate2(fs
, ino
, 0, block_buf
,
1211 process_block
, bmap
);
1218 ext2fs_free_mem(&block_buf
);
1224 * We need to scan for inode and block bitmaps that may need to be
1225 * moved. This can take place if the filesystem was formatted for
1226 * RAID arrays using the mke2fs's extended option "stride".
1228 static int group_desc_scan_and_fix(ext2_filsys fs
, ext2fs_block_bitmap bmap
)
1233 for (i
= 0; i
< fs
->group_desc_count
; i
++) {
1234 blk
= ext2fs_block_bitmap_loc(fs
, i
);
1235 if (ext2fs_test_block_bitmap2(bmap
, blk
)) {
1236 new_blk
= translate_block(blk
);
1239 ext2fs_block_bitmap_loc_set(fs
, i
, new_blk
);
1242 blk
= ext2fs_inode_bitmap_loc(fs
, i
);
1243 if (ext2fs_test_block_bitmap2(bmap
, blk
)) {
1244 new_blk
= translate_block(blk
);
1247 ext2fs_inode_bitmap_loc_set(fs
, i
, new_blk
);
1253 static int expand_inode_table(ext2_filsys fs
, unsigned long new_ino_size
)
1258 int new_ino_blks_per_grp
;
1260 char *old_itable
= NULL
, *new_itable
= NULL
;
1261 char *tmp_old_itable
= NULL
, *tmp_new_itable
= NULL
;
1262 unsigned long old_ino_size
;
1263 int old_itable_size
, new_itable_size
;
1265 old_itable_size
= fs
->inode_blocks_per_group
* fs
->blocksize
;
1266 old_ino_size
= EXT2_INODE_SIZE(fs
->super
);
1268 new_ino_blks_per_grp
= ext2fs_div_ceil(
1269 EXT2_INODES_PER_GROUP(fs
->super
) *
1273 new_itable_size
= new_ino_blks_per_grp
* fs
->blocksize
;
1275 retval
= ext2fs_get_mem(old_itable_size
, &old_itable
);
1279 retval
= ext2fs_get_mem(new_itable_size
, &new_itable
);
1283 tmp_old_itable
= old_itable
;
1284 tmp_new_itable
= new_itable
;
1286 for (i
= 0; i
< fs
->group_desc_count
; i
++) {
1287 blk
= ext2fs_inode_table_loc(fs
, i
);
1288 retval
= io_channel_read_blk64(fs
->io
, blk
,
1289 fs
->inode_blocks_per_group
, old_itable
);
1293 for (j
= 0; j
< EXT2_INODES_PER_GROUP(fs
->super
); j
++) {
1294 memcpy(new_itable
, old_itable
, old_ino_size
);
1296 memset(new_itable
+old_ino_size
, 0,
1297 new_ino_size
- old_ino_size
);
1299 new_itable
+= new_ino_size
;
1300 old_itable
+= old_ino_size
;
1303 /* reset the pointer */
1304 old_itable
= tmp_old_itable
;
1305 new_itable
= tmp_new_itable
;
1307 retval
= io_channel_write_blk64(fs
->io
, blk
,
1308 new_ino_blks_per_grp
, new_itable
);
1313 /* Update the meta data */
1314 fs
->inode_blocks_per_group
= new_ino_blks_per_grp
;
1315 fs
->super
->s_inode_size
= new_ino_size
;
1319 ext2fs_free_mem(&old_itable
);
1322 ext2fs_free_mem(&new_itable
);
1327 static errcode_t
ext2fs_calculate_summary_stats(ext2_filsys fs
)
1331 unsigned int group
= 0;
1332 unsigned int count
= 0;
1337 * First calculate the block statistics
1339 for (blk
= fs
->super
->s_first_data_block
;
1340 blk
< ext2fs_blocks_count(fs
->super
); blk
++) {
1341 if (!ext2fs_fast_test_block_bitmap2(fs
->block_map
, blk
)) {
1346 if ((count
== fs
->super
->s_blocks_per_group
) ||
1347 (blk
== ext2fs_blocks_count(fs
->super
)-1)) {
1348 ext2fs_bg_free_blocks_count_set(fs
, group
++,
1354 ext2fs_free_blocks_count_set(fs
->super
, total_free
);
1357 * Next, calculate the inode statistics
1364 /* Protect loop from wrap-around if s_inodes_count maxed */
1365 for (ino
= 1; ino
<= fs
->super
->s_inodes_count
&& ino
> 0; ino
++) {
1366 if (!ext2fs_fast_test_inode_bitmap2(fs
->inode_map
, ino
)) {
1371 if ((count
== fs
->super
->s_inodes_per_group
) ||
1372 (ino
== fs
->super
->s_inodes_count
)) {
1373 ext2fs_bg_free_inodes_count_set(fs
, group
++,
1379 fs
->super
->s_free_inodes_count
= total_free
;
1380 ext2fs_mark_super_dirty(fs
);
1384 #define list_for_each_safe(pos, pnext, head) \
1385 for (pos = (head)->next, pnext = pos->next; pos != (head); \
1386 pos = pnext, pnext = pos->next)
1388 static void free_blk_move_list(void)
1390 struct list_head
*entry
, *tmp
;
1391 struct blk_move
*bmv
;
1393 list_for_each_safe(entry
, tmp
, &blk_move_list
) {
1394 bmv
= list_entry(entry
, struct blk_move
, list
);
1396 ext2fs_free_mem(&bmv
);
1401 static int resize_inode(ext2_filsys fs
, unsigned long new_size
)
1404 int new_ino_blks_per_grp
;
1405 ext2fs_block_bitmap bmap
;
1407 ext2fs_read_inode_bitmap(fs
);
1408 ext2fs_read_block_bitmap(fs
);
1409 INIT_LIST_HEAD(&blk_move_list
);
1412 new_ino_blks_per_grp
= ext2fs_div_ceil(
1413 EXT2_INODES_PER_GROUP(fs
->super
)*
1417 /* We may change the file system.
1418 * Mark the file system as invalid so that
1419 * the user is prompted to run fsck.
1421 fs
->super
->s_state
&= ~EXT2_VALID_FS
;
1423 retval
= ext2fs_allocate_block_bitmap(fs
, _("blocks to be moved"),
1426 fputs(_("Failed to allocate block bitmap when "
1427 "increasing inode size\n"), stderr
);
1430 retval
= get_move_bitmaps(fs
, new_ino_blks_per_grp
, bmap
);
1432 fputs(_("Not enough space to increase inode size \n"), stderr
);
1435 retval
= move_block(fs
, bmap
);
1437 fputs(_("Failed to relocate blocks during inode resize \n"),
1441 retval
= inode_scan_and_fix(fs
, bmap
);
1445 retval
= group_desc_scan_and_fix(fs
, bmap
);
1449 retval
= expand_inode_table(fs
, new_size
);
1453 ext2fs_calculate_summary_stats(fs
);
1455 fs
->super
->s_state
|= EXT2_VALID_FS
;
1456 /* mark super block and block bitmap as dirty */
1457 ext2fs_mark_super_dirty(fs
);
1458 ext2fs_mark_bb_dirty(fs
);
1461 free_blk_move_list();
1462 ext2fs_free_block_bitmap(bmap
);
1467 free_blk_move_list();
1468 ext2fs_free_block_bitmap(bmap
);
1469 fputs(_("Error in resizing the inode size.\n"
1470 "Run e2undo to undo the "
1471 "file system changes. \n"), stderr
);
1476 static int tune2fs_setup_tdb(const char *name
, io_manager
*io_ptr
)
1478 errcode_t retval
= 0;
1479 const char *tdb_dir
;
1481 char *dev_name
, *tmp_name
;
1485 * Configuration via a conf file would be
1488 profile_get_string(profile
, "scratch_files",
1492 tmp_name
= strdup(name
);
1495 com_err(program_name
, ENOMEM
,
1496 _("Couldn't allocate memory for tdb filename\n"));
1499 dev_name
= basename(tmp_name
);
1501 tdb_dir
= getenv("E2FSPROGS_UNDO_DIR");
1503 tdb_dir
= "/var/lib/e2fsprogs";
1505 if (!strcmp(tdb_dir
, "none") || (tdb_dir
[0] == 0) ||
1506 access(tdb_dir
, W_OK
))
1509 tdb_file
= malloc(strlen(tdb_dir
) + 9 + strlen(dev_name
) + 7 + 1);
1512 sprintf(tdb_file
, "%s/tune2fs-%s.e2undo", tdb_dir
, dev_name
);
1514 if (!access(tdb_file
, F_OK
)) {
1515 if (unlink(tdb_file
) < 0) {
1517 com_err(program_name
, retval
,
1518 _("while trying to delete %s"),
1525 set_undo_io_backing_manager(*io_ptr
);
1526 *io_ptr
= undo_io_manager
;
1527 set_undo_io_backup_file(tdb_file
);
1528 printf(_("To undo the tune2fs operation please run "
1529 "the command\n e2undo %s %s\n\n"),
1536 int main(int argc
, char **argv
)
1540 struct ext2_super_block
*sb
;
1541 io_manager io_ptr
, io_ptr_orig
= NULL
;
1544 setlocale(LC_MESSAGES
, "");
1545 setlocale(LC_CTYPE
, "");
1546 bindtextdomain(NLS_CAT_NAME
, LOCALEDIR
);
1547 textdomain(NLS_CAT_NAME
);
1550 program_name
= *argv
;
1551 add_error_table(&et_ext2_error_table
);
1553 #ifdef CONFIG_BUILD_FINDFS
1554 if (strcmp(get_progname(argv
[0]), "findfs") == 0)
1555 do_findfs(argc
, argv
);
1557 if (strcmp(get_progname(argv
[0]), "e2label") == 0)
1558 parse_e2label_options(argc
, argv
);
1560 parse_tune2fs_options(argc
, argv
);
1562 #ifdef CONFIG_TESTIO_DEBUG
1563 if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_DEBUG")) {
1564 io_ptr
= test_io_manager
;
1565 test_io_backing_manager
= unix_io_manager
;
1568 io_ptr
= unix_io_manager
;
1571 retval
= ext2fs_open2(device_name
, io_options
, open_flag
,
1574 com_err(program_name
, retval
,
1575 _("while trying to open %s"),
1578 _("Couldn't find valid filesystem superblock.\n"));
1582 if (I_flag
&& !io_ptr_orig
) {
1584 * Check the inode size is right so we can issue an
1585 * error message and bail before setting up the tdb
1588 if (new_inode_size
== EXT2_INODE_SIZE(fs
->super
)) {
1589 fprintf(stderr
, _("The inode size is already %lu\n"),
1593 if (new_inode_size
< EXT2_INODE_SIZE(fs
->super
)) {
1594 fprintf(stderr
, _("Shrinking the inode size is "
1595 "not supported\n"));
1600 * If inode resize is requested use the
1603 io_ptr_orig
= io_ptr
;
1604 retval
= tune2fs_setup_tdb(device_name
, &io_ptr
);
1607 if (io_ptr
!= io_ptr_orig
) {
1614 fs
->flags
&= ~EXT2_FLAG_MASTER_SB_ONLY
;
1617 /* For e2label emulation */
1618 printf("%.*s\n", (int) sizeof(sb
->s_volume_name
),
1620 remove_error_table(&et_ext2_error_table
);
1624 retval
= ext2fs_check_if_mounted(device_name
, &mount_flags
);
1626 com_err("ext2fs_check_if_mount", retval
,
1627 _("while determining whether %s is mounted."),
1631 /* Normally we only need to write out the superblock */
1632 fs
->flags
|= EXT2_FLAG_SUPER_ONLY
;
1635 sb
->s_max_mnt_count
= max_mount_count
;
1636 ext2fs_mark_super_dirty(fs
);
1637 printf(_("Setting maximal mount count to %d\n"),
1641 sb
->s_mnt_count
= mount_count
;
1642 ext2fs_mark_super_dirty(fs
);
1643 printf(_("Setting current mount count to %d\n"), mount_count
);
1646 sb
->s_errors
= errors
;
1647 ext2fs_mark_super_dirty(fs
);
1648 printf(_("Setting error behavior to %d\n"), errors
);
1651 sb
->s_def_resgid
= resgid
;
1652 ext2fs_mark_super_dirty(fs
);
1653 printf(_("Setting reserved blocks gid to %lu\n"), resgid
);
1656 sb
->s_checkinterval
= interval
;
1657 ext2fs_mark_super_dirty(fs
);
1658 printf(_("Setting interval between checks to %lu seconds\n"),
1662 ext2fs_r_blocks_count_set(sb
, reserved_ratio
*
1663 ext2fs_blocks_count(sb
) / 100.0);
1664 ext2fs_mark_super_dirty(fs
);
1665 printf (_("Setting reserved blocks percentage to %g%% (%llu blocks)\n"),
1666 reserved_ratio
, ext2fs_r_blocks_count(sb
));
1669 if (reserved_blocks
>= ext2fs_blocks_count(sb
)/2) {
1670 com_err(program_name
, 0,
1671 _("reserved blocks count is too big (%llu)"),
1675 ext2fs_r_blocks_count_set(sb
, reserved_blocks
);
1676 ext2fs_mark_super_dirty(fs
);
1677 printf(_("Setting reserved blocks count to %llu\n"),
1681 if (sb
->s_feature_ro_compat
&
1682 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER
)
1683 fputs(_("\nThe filesystem already has sparse "
1684 "superblocks.\n"), stderr
);
1686 sb
->s_feature_ro_compat
|=
1687 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER
;
1688 sb
->s_state
&= ~EXT2_VALID_FS
;
1689 ext2fs_mark_super_dirty(fs
);
1690 printf(_("\nSparse superblock flag set. %s"),
1695 fputs(_("\nClearing the sparse superflag not supported.\n"),
1700 sb
->s_lastcheck
= last_check_time
;
1701 ext2fs_mark_super_dirty(fs
);
1702 printf(_("Setting time filesystem last checked to %s\n"),
1703 ctime(&last_check_time
));
1706 sb
->s_def_resuid
= resuid
;
1707 ext2fs_mark_super_dirty(fs
);
1708 printf(_("Setting reserved blocks uid to %lu\n"), resuid
);
1711 if (strlen(new_label
) > sizeof(sb
->s_volume_name
))
1712 fputs(_("Warning: label too long, truncating.\n"),
1714 memset(sb
->s_volume_name
, 0, sizeof(sb
->s_volume_name
));
1715 strncpy(sb
->s_volume_name
, new_label
,
1716 sizeof(sb
->s_volume_name
));
1717 ext2fs_mark_super_dirty(fs
);
1720 memset(sb
->s_last_mounted
, 0, sizeof(sb
->s_last_mounted
));
1721 strncpy(sb
->s_last_mounted
, new_last_mounted
,
1722 sizeof(sb
->s_last_mounted
));
1723 ext2fs_mark_super_dirty(fs
);
1726 update_mntopts(fs
, mntopts_cmd
);
1728 update_feature_set(fs
, features_cmd
);
1730 parse_extended_opts(fs
, extended_cmd
);
1731 if (journal_size
|| journal_device
)
1738 if (sb
->s_feature_ro_compat
&
1739 EXT4_FEATURE_RO_COMPAT_GDT_CSUM
) {
1741 * Determine if the block group checksums are
1742 * correct so we know whether or not to set
1745 for (i
= 0; i
< fs
->group_desc_count
; i
++)
1746 if (!ext2fs_group_desc_csum_verify(fs
, i
))
1748 if (i
>= fs
->group_desc_count
)
1751 if ((strcasecmp(new_UUID
, "null") == 0) ||
1752 (strcasecmp(new_UUID
, "clear") == 0)) {
1753 uuid_clear(sb
->s_uuid
);
1754 } else if (strcasecmp(new_UUID
, "time") == 0) {
1755 uuid_generate_time(sb
->s_uuid
);
1756 } else if (strcasecmp(new_UUID
, "random") == 0) {
1757 uuid_generate(sb
->s_uuid
);
1758 } else if (uuid_parse(new_UUID
, sb
->s_uuid
)) {
1759 com_err(program_name
, 0, _("Invalid UUID format\n"));
1763 for (i
= 0; i
< fs
->group_desc_count
; i
++)
1764 ext2fs_group_desc_csum_set(fs
, i
);
1765 fs
->flags
&= ~EXT2_FLAG_SUPER_ONLY
;
1767 ext2fs_mark_super_dirty(fs
);
1770 if (mount_flags
& EXT2_MF_MOUNTED
) {
1771 fputs(_("The inode size may only be "
1772 "changed when the filesystem is "
1773 "unmounted.\n"), stderr
);
1776 if (fs
->super
->s_feature_incompat
&
1777 EXT4_FEATURE_INCOMPAT_FLEX_BG
) {
1778 fputs(_("Changing the inode size not supported for "
1779 "filesystems with the flex_bg\n"
1780 "feature enabled.\n"),
1785 * We want to update group descriptor also
1786 * with the new free inode count
1788 fs
->flags
&= ~EXT2_FLAG_SUPER_ONLY
;
1789 if (resize_inode(fs
, new_inode_size
) == 0) {
1790 printf(_("Setting inode size %lu\n"),
1798 sb
->s_raid_stride
= stride
;
1799 ext2fs_mark_super_dirty(fs
);
1800 printf(_("Setting stride size to %d\n"), stride
);
1802 if (stripe_width_set
) {
1803 sb
->s_raid_stripe_width
= stripe_width
;
1804 ext2fs_mark_super_dirty(fs
);
1805 printf(_("Setting stripe width to %d\n"), stripe_width
);
1808 remove_error_table(&et_ext2_error_table
);
1809 return (ext2fs_close(fs
) ? 1 : 0);