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 500 /* for inclusion of strptime() */
29 #define _BSD_SOURCE /* for inclusion of strcasecmp() */
44 #include <sys/types.h>
46 #include "ext2fs/ext2_fs.h"
47 #include "ext2fs/ext2fs.h"
48 #include "et/com_err.h"
49 #include "uuid/uuid.h"
53 #include "blkid/blkid.h"
55 #include "../version.h"
56 #include "nls-enable.h"
59 * Tune2fs supports these features in addition to the standard features.
61 #define EXT2_TUNE2FS_INCOMPAT (EXT3_FEATURE_INCOMPAT_EXTENTS)
62 #define EXT2_TUNE2FS_RO_COMPAT (EXT4_FEATURE_RO_COMPAT_HUGE_FILE|\
63 EXT4_FEATURE_RO_COMPAT_GDT_CSUM| \
64 EXT4_FEATURE_RO_COMPAT_DIR_NLINK| \
65 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE)
68 const char * program_name = "tune2fs";
70 char * new_label, *new_last_mounted, *new_UUID;
72 static int c_flag, C_flag, e_flag, f_flag, g_flag, i_flag, l_flag, L_flag;
73 static int m_flag, M_flag, r_flag, s_flag = -1, u_flag, U_flag, T_flag;
74 static time_t last_check_time;
75 static int print_label;
76 static int max_mount_count, mount_count, mount_flags;
77 static unsigned long interval, reserved_blocks;
78 static double reserved_ratio;
79 static unsigned long resgid, resuid;
80 static unsigned short errors;
82 static char *features_cmd;
83 static char *mntopts_cmd;
84 static char *extended_cmd;
86 int journal_size, journal_flags;
89 static const char *please_fsck = N_("Please run e2fsck on the filesystem.\n");
91 void do_findfs(int argc, char **argv);
93 static void usage(void)
96 _("Usage: %s [-c max_mounts_count] [-e errors_behavior] "
98 "\t[-i interval[d|m|w]] [-j] [-J journal_options]\n"
99 "\t[-l] [-s sparse_flag] [-m reserved_blocks_percent]\n"
100 "\t[-o [^]mount_options[,...]] [-r reserved_blocks_count]\n"
101 "\t[-u user] [-C mount_count] [-L volume_label]\n"
102 "\t[-M last_mounted_dir] [-O [^]feature[,...]]\n"
103 "\t[-E extended-option[,...]] [-T last_check_time] "
104 "[-U UUID] device\n"), program_name);
108 static __u32 ok_features[3] = {
109 EXT3_FEATURE_COMPAT_HAS_JOURNAL |
110 EXT2_FEATURE_COMPAT_DIR_INDEX, /* Compat */
111 EXT2_FEATURE_INCOMPAT_FILETYPE, /* Incompat */
112 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER /* R/O compat */
116 * Remove an external journal from the filesystem
118 static void remove_journal_device(ext2_filsys fs)
123 journal_superblock_t *jsb;
126 int commit_remove_journal = 0;
130 commit_remove_journal = 1; /* force removal even if error */
132 uuid_unparse(fs->super->s_journal_uuid, buf);
133 journal_path = blkid_get_devname(NULL, "UUID", buf);
137 ext2fs_find_block_device(fs->super->s_journal_dev);
142 #ifdef CONFIG_TESTIO_DEBUG
143 io_ptr = test_io_manager;
144 test_io_backing_manager = unix_io_manager;
146 io_ptr = unix_io_manager;
148 retval = ext2fs_open(journal_path, EXT2_FLAG_RW|
149 EXT2_FLAG_JOURNAL_DEV_OK, 0,
150 fs->blocksize, io_ptr, &jfs);
152 com_err(program_name, retval,
153 _("while trying to open external journal"));
154 goto no_valid_journal;
156 if (!(jfs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)) {
157 fprintf(stderr, _("%s is not a journal device.\n"),
159 goto no_valid_journal;
162 /* Get the journal superblock */
163 if ((retval = io_channel_read_blk(jfs->io, 1, -1024, buf))) {
164 com_err(program_name, retval,
165 _("while reading journal superblock"));
166 goto no_valid_journal;
169 jsb = (journal_superblock_t *) buf;
170 if ((jsb->s_header.h_magic != (unsigned) ntohl(JFS_MAGIC_NUMBER)) ||
171 (jsb->s_header.h_blocktype != (unsigned) ntohl(JFS_SUPERBLOCK_V2))) {
172 fputs(_("Journal superblock not found!\n"), stderr);
173 goto no_valid_journal;
176 /* Find the filesystem UUID */
177 nr_users = ntohl(jsb->s_nr_users);
178 for (i=0; i < nr_users; i++) {
179 if (memcmp(fs->super->s_uuid,
180 &jsb->s_users[i*16], 16) == 0)
184 fputs(_("Filesystem's UUID not found on journal device.\n"),
186 commit_remove_journal = 1;
187 goto no_valid_journal;
190 for (i=0; i < nr_users; i++)
191 memcpy(&jsb->s_users[i*16], &jsb->s_users[(i+1)*16], 16);
192 jsb->s_nr_users = htonl(nr_users);
194 /* Write back the journal superblock */
195 if ((retval = io_channel_write_blk(jfs->io, 1, -1024, buf))) {
196 com_err(program_name, retval,
197 "while writing journal superblock.");
198 goto no_valid_journal;
201 commit_remove_journal = 1;
204 if (commit_remove_journal == 0) {
205 fputs(_("Journal NOT removed\n"), stderr);
208 fs->super->s_journal_dev = 0;
209 uuid_clear(fs->super->s_journal_uuid);
210 ext2fs_mark_super_dirty(fs);
211 fputs(_("Journal removed\n"), stdout);
215 /* Helper function for remove_journal_inode */
216 static int release_blocks_proc(ext2_filsys fs, blk_t *blocknr,
217 int blockcnt EXT2FS_ATTR((unused)),
218 void *private EXT2FS_ATTR((unused)))
224 ext2fs_unmark_block_bitmap(fs->block_map,block);
225 group = ext2fs_group_of_blk(fs, block);
226 fs->group_desc[group].bg_free_blocks_count++;
227 fs->super->s_free_blocks_count++;
232 * Remove the journal inode from the filesystem
234 static void remove_journal_inode(ext2_filsys fs)
236 struct ext2_inode inode;
238 ino_t ino = fs->super->s_journal_inum;
240 retval = ext2fs_read_inode(fs, ino, &inode);
242 com_err(program_name, retval,
243 _("while reading journal inode"));
246 if (ino == EXT2_JOURNAL_INO) {
247 retval = ext2fs_read_bitmaps(fs);
249 com_err(program_name, retval,
250 _("while reading bitmaps"));
253 retval = ext2fs_block_iterate(fs, ino, 0, NULL,
254 release_blocks_proc, NULL);
256 com_err(program_name, retval,
257 _("while clearing journal inode"));
260 memset(&inode, 0, sizeof(inode));
261 ext2fs_mark_bb_dirty(fs);
262 fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
264 inode.i_flags &= ~EXT2_IMMUTABLE_FL;
265 retval = ext2fs_write_inode(fs, ino, &inode);
267 com_err(program_name, retval,
268 _("while writing journal inode"));
271 fs->super->s_journal_inum = 0;
272 ext2fs_mark_super_dirty(fs);
276 * Update the default mount options
278 static void update_mntopts(ext2_filsys fs, char *mntopts)
280 struct ext2_super_block *sb= fs->super;
282 if (e2p_edit_mntopts(mntopts, &sb->s_default_mount_opts, ~0)) {
283 fprintf(stderr, _("Invalid mount option set: %s\n"),
287 ext2fs_mark_super_dirty(fs);
291 * Update the feature set as provided by the user.
293 static void update_feature_set(ext2_filsys fs, char *features)
295 int sparse, old_sparse, filetype, old_filetype;
296 int journal, old_journal, dxdir, old_dxdir;
297 struct ext2_super_block *sb= fs->super;
298 __u32 old_compat, old_incompat, old_ro_compat;
300 old_compat = sb->s_feature_compat;
301 old_ro_compat = sb->s_feature_ro_compat;
302 old_incompat = sb->s_feature_incompat;
304 old_sparse = sb->s_feature_ro_compat &
305 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
306 old_filetype = sb->s_feature_incompat &
307 EXT2_FEATURE_INCOMPAT_FILETYPE;
308 old_journal = sb->s_feature_compat &
309 EXT3_FEATURE_COMPAT_HAS_JOURNAL;
310 old_dxdir = sb->s_feature_compat &
311 EXT2_FEATURE_COMPAT_DIR_INDEX;
312 if (e2p_edit_feature(features, &sb->s_feature_compat,
314 fprintf(stderr, _("Invalid filesystem option set: %s\n"),
318 sparse = sb->s_feature_ro_compat &
319 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
320 filetype = sb->s_feature_incompat &
321 EXT2_FEATURE_INCOMPAT_FILETYPE;
322 journal = sb->s_feature_compat &
323 EXT3_FEATURE_COMPAT_HAS_JOURNAL;
324 dxdir = sb->s_feature_compat &
325 EXT2_FEATURE_COMPAT_DIR_INDEX;
326 if (old_journal && !journal) {
327 if ((mount_flags & EXT2_MF_MOUNTED) &&
328 !(mount_flags & EXT2_MF_READONLY)) {
329 fputs(_("The has_journal flag may only be "
330 "cleared when the filesystem is\n"
331 "unmounted or mounted "
332 "read-only.\n"), stderr);
335 if (sb->s_feature_incompat &
336 EXT3_FEATURE_INCOMPAT_RECOVER) {
337 fputs(_("The needs_recovery flag is set. "
338 "Please run e2fsck before clearing\n"
339 "the has_journal flag.\n"), stderr);
342 if (sb->s_journal_inum) {
343 remove_journal_inode(fs);
345 if (sb->s_journal_dev) {
346 remove_journal_device(fs);
349 if (journal && !old_journal) {
351 * If adding a journal flag, let the create journal
352 * code below handle creating setting the flag and
353 * creating the journal. We supply a default size if
358 sb->s_feature_compat &= ~EXT3_FEATURE_COMPAT_HAS_JOURNAL;
360 if (dxdir && !old_dxdir) {
361 if (!sb->s_def_hash_version)
362 sb->s_def_hash_version = EXT2_HASH_TEA;
363 if (uuid_is_null((unsigned char *) sb->s_hash_seed))
364 uuid_generate((unsigned char *) sb->s_hash_seed);
367 if (sb->s_rev_level == EXT2_GOOD_OLD_REV &&
368 (sb->s_feature_compat || sb->s_feature_ro_compat ||
369 sb->s_feature_incompat))
370 ext2fs_update_dynamic_rev(fs);
371 if ((sparse != old_sparse) ||
372 (filetype != old_filetype)) {
373 sb->s_state &= ~EXT2_VALID_FS;
374 printf("\n%s\n", _(please_fsck));
376 if ((old_compat != sb->s_feature_compat) ||
377 (old_ro_compat != sb->s_feature_ro_compat) ||
378 (old_incompat != sb->s_feature_incompat))
379 ext2fs_mark_super_dirty(fs);
383 * Add a journal to the filesystem.
385 static void add_journal(ext2_filsys fs)
387 unsigned long journal_blocks;
392 if (fs->super->s_feature_compat &
393 EXT3_FEATURE_COMPAT_HAS_JOURNAL) {
394 fputs(_("The filesystem already has a journal.\n"), stderr);
397 if (journal_device) {
398 check_plausibility(journal_device);
399 check_mount(journal_device, 0, _("journal"));
400 #ifdef CONFIG_TESTIO_DEBUG
401 io_ptr = test_io_manager;
402 test_io_backing_manager = unix_io_manager;
404 io_ptr = unix_io_manager;
406 retval = ext2fs_open(journal_device, EXT2_FLAG_RW|
407 EXT2_FLAG_JOURNAL_DEV_OK, 0,
408 fs->blocksize, io_ptr, &jfs);
410 com_err(program_name, retval,
411 _("\n\twhile trying to open journal on %s\n"),
415 printf(_("Creating journal on device %s: "),
419 retval = ext2fs_add_journal_device(fs, jfs);
422 com_err (program_name, retval,
423 _("while adding filesystem to journal on %s"),
427 fputs(_("done\n"), stdout);
428 } else if (journal_size) {
429 fputs(_("Creating journal inode: "), stdout);
431 journal_blocks = figure_journal_size(journal_size, fs);
433 retval = ext2fs_add_journal_inode(fs, journal_blocks,
436 fprintf(stderr, "\n");
437 com_err(program_name, retval,
438 _("\n\twhile trying to create journal file"));
441 fputs(_("done\n"), stdout);
443 * If the filesystem wasn't mounted, we need to force
444 * the block group descriptors out.
446 if ((mount_flags & EXT2_MF_MOUNTED) == 0)
447 fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
449 print_check_message(fs);
454 free(journal_device);
459 static void parse_e2label_options(int argc, char ** argv)
461 if ((argc < 2) || (argc > 3)) {
462 fputs(_("Usage: e2label device [newlabel]\n"), stderr);
465 io_options = strchr(argv[1], '?');
468 device_name = blkid_get_devname(NULL, argv[1], NULL);
470 com_err("e2label", 0, _("Unable to resolve '%s'"),
474 open_flag = EXT2_FLAG_SOFTSUPP_FEATURES | EXT2_FLAG_JOURNAL_DEV_OK;
476 open_flag |= EXT2_FLAG_RW;
483 static time_t parse_time(char *str)
487 if (strcmp(str, "now") == 0) {
490 memset(&ts, 0, sizeof(ts));
492 strptime(str, "%Y%m%d%H%M%S", &ts);
494 sscanf(str, "%4d%2d%2d%2d%2d%2d", &ts.tm_year, &ts.tm_mon,
495 &ts.tm_mday, &ts.tm_hour, &ts.tm_min, &ts.tm_sec);
498 if (ts.tm_year < 0 || ts.tm_mon < 0 || ts.tm_mon > 11 ||
499 ts.tm_mday < 0 || ts.tm_mday > 31 || ts.tm_hour > 23 ||
500 ts.tm_min > 59 || ts.tm_sec > 61)
503 if (ts.tm_mday == 0) {
504 com_err(program_name, 0,
505 _("Couldn't parse date/time specifier: %s"),
509 return (mktime(&ts));
512 static void parse_tune2fs_options(int argc, char **argv)
519 open_flag = EXT2_FLAG_SOFTSUPP_FEATURES;
521 printf("tune2fs %s (%s)\n", E2FSPROGS_VERSION, E2FSPROGS_DATE);
522 while ((c = getopt(argc, argv, "c:e:fg:i:jlm:o:r:s:u:C:E:J:L:M:O:T:U:")) != EOF)
526 max_mount_count = strtol (optarg, &tmp, 0);
527 if (*tmp || max_mount_count > 16000) {
528 com_err (program_name, 0,
529 _("bad mounts count - %s"),
533 if (max_mount_count == 0)
534 max_mount_count = -1;
536 open_flag = EXT2_FLAG_RW;
539 mount_count = strtoul (optarg, &tmp, 0);
540 if (*tmp || mount_count > 16000) {
541 com_err (program_name, 0,
542 _("bad mounts count - %s"),
547 open_flag = EXT2_FLAG_RW;
550 if (strcmp (optarg, "continue") == 0)
551 errors = EXT2_ERRORS_CONTINUE;
552 else if (strcmp (optarg, "remount-ro") == 0)
553 errors = EXT2_ERRORS_RO;
554 else if (strcmp (optarg, "panic") == 0)
555 errors = EXT2_ERRORS_PANIC;
557 com_err (program_name, 0,
558 _("bad error behavior - %s"),
563 open_flag = EXT2_FLAG_RW;
566 extended_cmd = optarg;
567 open_flag |= EXT2_FLAG_RW;
569 case 'f': /* Force */
573 resgid = strtoul (optarg, &tmp, 0);
575 gr = getgrnam (optarg);
584 com_err (program_name, 0,
585 _("bad gid/group name - %s"),
590 open_flag = EXT2_FLAG_RW;
593 interval = strtoul (optarg, &tmp, 0);
606 case 'M': /* months! */
607 interval *= 86400 * 30;
611 case 'W': /* weeks */
612 interval *= 86400 * 7;
617 com_err (program_name, 0,
618 _("bad interval - %s"), optarg);
622 open_flag = EXT2_FLAG_RW;
627 open_flag = EXT2_FLAG_RW;
630 parse_journal_opts(optarg);
631 open_flag = EXT2_FLAG_RW;
639 open_flag |= EXT2_FLAG_RW |
640 EXT2_FLAG_JOURNAL_DEV_OK;
643 reserved_ratio = strtod(optarg, &tmp);
644 if (*tmp || reserved_ratio > 50) {
645 com_err (program_name, 0,
646 _("bad reserved block ratio - %s"),
651 open_flag = EXT2_FLAG_RW;
654 new_last_mounted = optarg;
656 open_flag = EXT2_FLAG_RW;
660 com_err (program_name, 0,
661 _("-o may only be specified once"));
664 mntopts_cmd = optarg;
665 open_flag = EXT2_FLAG_RW;
670 com_err (program_name, 0,
671 _("-O may only be specified once"));
674 features_cmd = optarg;
675 open_flag = EXT2_FLAG_RW;
678 reserved_blocks = strtoul (optarg, &tmp, 0);
680 com_err (program_name, 0,
681 _("bad reserved blocks count - %s"),
686 open_flag = EXT2_FLAG_RW;
689 s_flag = atoi(optarg);
690 open_flag = EXT2_FLAG_RW;
694 last_check_time = parse_time(optarg);
695 open_flag = EXT2_FLAG_RW;
698 resuid = strtoul (optarg, &tmp, 0);
700 pw = getpwnam (optarg);
709 com_err (program_name, 0,
710 _("bad uid/user name - %s"),
715 open_flag = EXT2_FLAG_RW;
720 open_flag = EXT2_FLAG_RW |
721 EXT2_FLAG_JOURNAL_DEV_OK;
726 if (optind < argc - 1 || optind == argc)
728 if (!open_flag && !l_flag)
730 io_options = strchr(argv[optind], '?');
733 device_name = blkid_get_devname(NULL, argv[optind], NULL);
735 com_err("tune2fs", 0, _("Unable to resolve '%s'"),
741 void do_findfs(int argc, char **argv)
746 (strncmp(argv[1], "LABEL=", 6) && strncmp(argv[1], "UUID=", 5))) {
747 fprintf(stderr, "Usage: findfs LABEL=<label>|UUID=<uuid>\n");
750 dev = blkid_get_devname(NULL, argv[1], NULL);
752 com_err("findfs", 0, _("Unable to resolve '%s'"),
761 * Note! If any extended options are incompatible with the
762 * intersection of the SOFTSUPP features and those features explicitly
763 * enabled for tune2fs, there needs to be an explicit test for them
766 static void parse_extended_opts(ext2_filsys fs, const char *opts)
768 char *buf, *token, *next, *p, *arg;
776 _("Couldn't allocate memory to parse options!\n"));
780 for (token = buf; token && *token; token = next) {
781 p = strchr(token, ',');
787 arg = strchr(token, '=');
792 if (!strcmp(token, "test_fs")) {
793 fs->super->s_flags |= EXT2_FLAGS_TEST_FILESYS;
794 printf("Setting test filesystem flag\n");
795 ext2fs_mark_super_dirty(fs);
796 } else if (!strcmp(token, "^test_fs")) {
797 fs->super->s_flags &= ~EXT2_FLAGS_TEST_FILESYS;
798 printf("Clearing test filesystem flag\n");
799 ext2fs_mark_super_dirty(fs);
804 fprintf(stderr, _("\nBad options specified.\n\n"
805 "Extended options are separated by commas, "
806 "and may take an argument which\n"
807 "\tis set off by an equals ('=') sign.\n\n"
808 "Valid extended options are:\n"
818 int main (int argc, char ** argv)
822 struct ext2_super_block *sb;
826 setlocale(LC_MESSAGES, "");
827 setlocale(LC_CTYPE, "");
828 bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
829 textdomain(NLS_CAT_NAME);
832 program_name = *argv;
833 add_error_table(&et_ext2_error_table);
835 if (strcmp(get_progname(argv[0]), "findfs") == 0)
836 do_findfs(argc, argv);
837 if (strcmp(get_progname(argv[0]), "e2label") == 0)
838 parse_e2label_options(argc, argv);
840 parse_tune2fs_options(argc, argv);
842 #ifdef CONFIG_TESTIO_DEBUG
843 io_ptr = test_io_manager;
844 test_io_backing_manager = unix_io_manager;
846 io_ptr = unix_io_manager;
848 retval = ext2fs_open2(device_name, io_options, open_flag,
851 com_err (program_name, retval, _("while trying to open %s"),
854 _("Couldn't find valid filesystem superblock.\n"));
858 fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
859 if ((sb->s_feature_incompat & !EXT2_TUNE2FS_INCOMPAT) ||
860 (sb->s_feature_ro_compat & !EXT2_TUNE2FS_RO_COMPAT)) {
862 _("Filesystem %s has unsupported features enabled.\n"),
867 /* For e2label emulation */
868 printf("%.*s\n", (int) sizeof(sb->s_volume_name),
870 remove_error_table(&et_ext2_error_table);
873 retval = ext2fs_check_if_mounted(device_name, &mount_flags);
875 com_err("ext2fs_check_if_mount", retval,
876 _("while determining whether %s is mounted."),
880 /* Normally we only need to write out the superblock */
881 fs->flags |= EXT2_FLAG_SUPER_ONLY;
884 sb->s_max_mnt_count = max_mount_count;
885 ext2fs_mark_super_dirty(fs);
886 printf (_("Setting maximal mount count to %d\n"),
890 sb->s_mnt_count = mount_count;
891 ext2fs_mark_super_dirty(fs);
892 printf (_("Setting current mount count to %d\n"), mount_count);
895 sb->s_errors = errors;
896 ext2fs_mark_super_dirty(fs);
897 printf (_("Setting error behavior to %d\n"), errors);
900 sb->s_def_resgid = resgid;
901 ext2fs_mark_super_dirty(fs);
902 printf (_("Setting reserved blocks gid to %lu\n"), resgid);
905 sb->s_checkinterval = interval;
906 ext2fs_mark_super_dirty(fs);
907 printf (_("Setting interval between checks to %lu seconds\n"), interval);
910 sb->s_r_blocks_count = e2p_percent(reserved_ratio,
912 ext2fs_mark_super_dirty(fs);
913 printf (_("Setting reserved blocks percentage to %g%% (%u blocks)\n"),
914 reserved_ratio, sb->s_r_blocks_count);
917 if (reserved_blocks >= sb->s_blocks_count/2) {
918 com_err (program_name, 0,
919 _("reserved blocks count is too big (%lu)"),
923 sb->s_r_blocks_count = reserved_blocks;
924 ext2fs_mark_super_dirty(fs);
925 printf (_("Setting reserved blocks count to %lu\n"),
929 if (sb->s_feature_ro_compat &
930 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)
931 fputs(_("\nThe filesystem already has sparse "
932 "superblocks.\n"), stderr);
934 sb->s_feature_ro_compat |=
935 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
936 sb->s_state &= ~EXT2_VALID_FS;
937 ext2fs_mark_super_dirty(fs);
938 printf(_("\nSparse superblock flag set. %s"),
943 if (!(sb->s_feature_ro_compat &
944 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER))
945 fputs(_("\nThe filesystem already has sparse "
946 "superblocks disabled.\n"), stderr);
948 sb->s_feature_ro_compat &=
949 ~EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
950 sb->s_state &= ~EXT2_VALID_FS;
951 fs->flags |= EXT2_FLAG_MASTER_SB_ONLY;
952 ext2fs_mark_super_dirty(fs);
953 printf(_("\nSparse superblock flag cleared. %s"),
958 sb->s_lastcheck = last_check_time;
959 ext2fs_mark_super_dirty(fs);
960 printf(_("Setting time filesystem last checked to %s\n"),
961 ctime(&last_check_time));
964 sb->s_def_resuid = resuid;
965 ext2fs_mark_super_dirty(fs);
966 printf (_("Setting reserved blocks uid to %lu\n"), resuid);
969 if (strlen(new_label) > sizeof(sb->s_volume_name))
970 fputs(_("Warning: label too long, truncating.\n"),
972 memset(sb->s_volume_name, 0, sizeof(sb->s_volume_name));
973 strncpy(sb->s_volume_name, new_label,
974 sizeof(sb->s_volume_name));
975 ext2fs_mark_super_dirty(fs);
978 memset(sb->s_last_mounted, 0, sizeof(sb->s_last_mounted));
979 strncpy(sb->s_last_mounted, new_last_mounted,
980 sizeof(sb->s_last_mounted));
981 ext2fs_mark_super_dirty(fs);
984 update_mntopts(fs, mntopts_cmd);
986 update_feature_set(fs, features_cmd);
988 parse_extended_opts(fs, extended_cmd);
989 if (journal_size || journal_device)
993 if ((strcasecmp(new_UUID, "null") == 0) ||
994 (strcasecmp(new_UUID, "clear") == 0)) {
995 uuid_clear(sb->s_uuid);
996 } else if (strcasecmp(new_UUID, "time") == 0) {
997 uuid_generate_time(sb->s_uuid);
998 } else if (strcasecmp(new_UUID, "random") == 0) {
999 uuid_generate(sb->s_uuid);
1000 } else if (uuid_parse(new_UUID, sb->s_uuid)) {
1001 com_err(program_name, 0, _("Invalid UUID format\n"));
1004 ext2fs_mark_super_dirty(fs);
1009 remove_error_table(&et_ext2_error_table);
1010 return (ext2fs_close (fs) ? 1 : 0);