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 int stride, stripe_width;
85 static int stride_set, stripe_width_set;
86 static char *extended_cmd;
88 int journal_size, journal_flags;
91 static const char *please_fsck = N_("Please run e2fsck on the filesystem.\n");
93 void do_findfs(int argc, char **argv);
95 static void usage(void)
98 _("Usage: %s [-c max_mounts_count] [-e errors_behavior] "
100 "\t[-i interval[d|m|w]] [-j] [-J journal_options] [-l]\n"
101 "\t[-m reserved_blocks_percent] "
102 "[-o [^]mount_options[,...]] \n"
103 "\t[-r reserved_blocks_count] [-u user] [-C mount_count] "
104 "[-L volume_label]\n"
105 "\t[-M last_mounted_dir] [-O [^]feature[,...]]\n"
106 "\t[-E extended-option[,...]] [-T last_check_time] "
107 "[-U UUID] device\n"), program_name);
111 static __u32 ok_features[3] = {
113 EXT3_FEATURE_COMPAT_HAS_JOURNAL |
114 EXT2_FEATURE_COMPAT_DIR_INDEX,
116 EXT2_FEATURE_INCOMPAT_FILETYPE,
118 EXT2_FEATURE_RO_COMPAT_LARGE_FILE |
119 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER
122 static __u32 clear_ok_features[3] = {
124 EXT3_FEATURE_COMPAT_HAS_JOURNAL |
125 EXT2_FEATURE_COMPAT_RESIZE_INODE |
126 EXT2_FEATURE_COMPAT_DIR_INDEX,
128 EXT2_FEATURE_INCOMPAT_FILETYPE,
130 EXT2_FEATURE_RO_COMPAT_LARGE_FILE
134 * Remove an external journal from the filesystem
136 static void remove_journal_device(ext2_filsys fs)
141 journal_superblock_t *jsb;
144 int commit_remove_journal = 0;
148 commit_remove_journal = 1; /* force removal even if error */
150 uuid_unparse(fs->super->s_journal_uuid, buf);
151 journal_path = blkid_get_devname(NULL, "UUID", buf);
155 ext2fs_find_block_device(fs->super->s_journal_dev);
160 #ifdef CONFIG_TESTIO_DEBUG
161 io_ptr = test_io_manager;
162 test_io_backing_manager = unix_io_manager;
164 io_ptr = unix_io_manager;
166 retval = ext2fs_open(journal_path, EXT2_FLAG_RW|
167 EXT2_FLAG_JOURNAL_DEV_OK, 0,
168 fs->blocksize, io_ptr, &jfs);
170 com_err(program_name, retval,
171 _("while trying to open external journal"));
172 goto no_valid_journal;
174 if (!(jfs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)) {
175 fprintf(stderr, _("%s is not a journal device.\n"),
177 goto no_valid_journal;
180 /* Get the journal superblock */
181 if ((retval = io_channel_read_blk(jfs->io, 1, -1024, buf))) {
182 com_err(program_name, retval,
183 _("while reading journal superblock"));
184 goto no_valid_journal;
187 jsb = (journal_superblock_t *) buf;
188 if ((jsb->s_header.h_magic != (unsigned) ntohl(JFS_MAGIC_NUMBER)) ||
189 (jsb->s_header.h_blocktype != (unsigned) ntohl(JFS_SUPERBLOCK_V2))) {
190 fputs(_("Journal superblock not found!\n"), stderr);
191 goto no_valid_journal;
194 /* Find the filesystem UUID */
195 nr_users = ntohl(jsb->s_nr_users);
196 for (i=0; i < nr_users; i++) {
197 if (memcmp(fs->super->s_uuid,
198 &jsb->s_users[i*16], 16) == 0)
202 fputs(_("Filesystem's UUID not found on journal device.\n"),
204 commit_remove_journal = 1;
205 goto no_valid_journal;
208 for (i=0; i < nr_users; i++)
209 memcpy(&jsb->s_users[i*16], &jsb->s_users[(i+1)*16], 16);
210 jsb->s_nr_users = htonl(nr_users);
212 /* Write back the journal superblock */
213 if ((retval = io_channel_write_blk(jfs->io, 1, -1024, buf))) {
214 com_err(program_name, retval,
215 "while writing journal superblock.");
216 goto no_valid_journal;
219 commit_remove_journal = 1;
222 if (commit_remove_journal == 0) {
223 fputs(_("Journal NOT removed\n"), stderr);
226 fs->super->s_journal_dev = 0;
227 uuid_clear(fs->super->s_journal_uuid);
228 ext2fs_mark_super_dirty(fs);
229 fputs(_("Journal removed\n"), stdout);
233 /* Helper function for remove_journal_inode */
234 static int release_blocks_proc(ext2_filsys fs, blk_t *blocknr,
235 int blockcnt EXT2FS_ATTR((unused)),
236 void *private EXT2FS_ATTR((unused)))
242 ext2fs_unmark_block_bitmap(fs->block_map,block);
243 group = ext2fs_group_of_blk(fs, block);
244 fs->group_desc[group].bg_free_blocks_count++;
245 fs->super->s_free_blocks_count++;
250 * Remove the journal inode from the filesystem
252 static void remove_journal_inode(ext2_filsys fs)
254 struct ext2_inode inode;
256 ino_t ino = fs->super->s_journal_inum;
258 retval = ext2fs_read_inode(fs, ino, &inode);
260 com_err(program_name, retval,
261 _("while reading journal inode"));
264 if (ino == EXT2_JOURNAL_INO) {
265 retval = ext2fs_read_bitmaps(fs);
267 com_err(program_name, retval,
268 _("while reading bitmaps"));
271 retval = ext2fs_block_iterate(fs, ino, 0, NULL,
272 release_blocks_proc, NULL);
274 com_err(program_name, retval,
275 _("while clearing journal inode"));
278 memset(&inode, 0, sizeof(inode));
279 ext2fs_mark_bb_dirty(fs);
280 fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
282 inode.i_flags &= ~EXT2_IMMUTABLE_FL;
283 retval = ext2fs_write_inode(fs, ino, &inode);
285 com_err(program_name, retval,
286 _("while writing journal inode"));
289 fs->super->s_journal_inum = 0;
290 ext2fs_mark_super_dirty(fs);
294 * Update the default mount options
296 static void update_mntopts(ext2_filsys fs, char *mntopts)
298 struct ext2_super_block *sb= fs->super;
300 if (e2p_edit_mntopts(mntopts, &sb->s_default_mount_opts, ~0)) {
301 fprintf(stderr, _("Invalid mount option set: %s\n"),
305 ext2fs_mark_super_dirty(fs);
309 * Update the feature set as provided by the user.
311 static void update_feature_set(ext2_filsys fs, char *features)
313 struct ext2_super_block *sb= fs->super;
314 __u32 old_compat, old_incompat, old_ro_compat;
315 __u32 old_features[3];
317 unsigned int mask_err;
319 #define FEATURE_ON(type, mask) (!(old_features[(type)] & (mask)) && \
320 ((&sb->s_feature_compat)[(type)] & (mask)))
321 #define FEATURE_OFF(type, mask) ((old_features[(type)] & (mask)) && \
322 !((&sb->s_feature_compat)[(type)] & (mask)))
323 #define FEATURE_CHANGED(type, mask) ((mask) & \
324 (old_features[(type)] ^ (&sb->s_feature_compat)[(type)]))
326 old_features[E2P_FEATURE_COMPAT] = sb->s_feature_compat;
327 old_features[E2P_FEATURE_INCOMPAT] = sb->s_feature_incompat;
328 old_features[E2P_FEATURE_RO_INCOMPAT] = sb->s_feature_ro_compat;
330 if (e2p_edit_feature2(features, &sb->s_feature_compat,
331 ok_features, clear_ok_features,
332 &type_err, &mask_err)) {
335 _("Invalid filesystem option set: %s\n"),
337 else if (type_err & E2P_FEATURE_NEGATE_FLAG)
338 fprintf(stderr, _("Clearing filesystem feature '%s' "
340 e2p_feature2string(type_err &
341 E2P_FEATURE_TYPE_MASK,
344 fprintf(stderr, _("Setting filesystem feature '%s' "
346 e2p_feature2string(type_err, mask_err));
350 if (FEATURE_OFF(E2P_FEATURE_COMPAT, EXT3_FEATURE_COMPAT_HAS_JOURNAL)) {
351 if ((mount_flags & EXT2_MF_MOUNTED) &&
352 !(mount_flags & EXT2_MF_READONLY)) {
353 fputs(_("The has_journal flag may only be "
354 "cleared when the filesystem is\n"
355 "unmounted or mounted "
356 "read-only.\n"), stderr);
359 if (sb->s_feature_incompat &
360 EXT3_FEATURE_INCOMPAT_RECOVER) {
361 fputs(_("The needs_recovery flag is set. "
362 "Please run e2fsck before clearing\n"
363 "the has_journal flag.\n"), stderr);
366 if (sb->s_journal_inum) {
367 remove_journal_inode(fs);
369 if (sb->s_journal_dev) {
370 remove_journal_device(fs);
374 if (FEATURE_ON(E2P_FEATURE_COMPAT, EXT3_FEATURE_COMPAT_HAS_JOURNAL)) {
376 * If adding a journal flag, let the create journal
377 * code below handle creating setting the flag and
378 * creating the journal. We supply a default size if
383 sb->s_feature_compat &= ~EXT3_FEATURE_COMPAT_HAS_JOURNAL;
386 if (FEATURE_ON(E2P_FEATURE_COMPAT, EXT2_FEATURE_COMPAT_DIR_INDEX)) {
387 if (!sb->s_def_hash_version)
388 sb->s_def_hash_version = EXT2_HASH_TEA;
389 if (uuid_is_null((unsigned char *) sb->s_hash_seed))
390 uuid_generate((unsigned char *) sb->s_hash_seed);
393 if (sb->s_rev_level == EXT2_GOOD_OLD_REV &&
394 (sb->s_feature_compat || sb->s_feature_ro_compat ||
395 sb->s_feature_incompat))
396 ext2fs_update_dynamic_rev(fs);
398 if (FEATURE_CHANGED(E2P_FEATURE_RO_INCOMPAT,
399 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER) ||
400 FEATURE_CHANGED(E2P_FEATURE_INCOMPAT,
401 EXT2_FEATURE_INCOMPAT_FILETYPE) ||
402 FEATURE_CHANGED(E2P_FEATURE_COMPAT,
403 EXT2_FEATURE_COMPAT_RESIZE_INODE) ||
404 FEATURE_OFF(E2P_FEATURE_RO_INCOMPAT,
405 EXT2_FEATURE_RO_COMPAT_LARGE_FILE)) {
406 sb->s_state &= ~EXT2_VALID_FS;
407 printf("\n%s\n", _(please_fsck));
410 if ((old_features[E2P_FEATURE_COMPAT] != sb->s_feature_compat) ||
411 (old_features[E2P_FEATURE_INCOMPAT] != sb->s_feature_incompat) ||
412 (old_features[E2P_FEATURE_RO_INCOMPAT] != sb->s_feature_ro_compat))
413 ext2fs_mark_super_dirty(fs);
417 * Add a journal to the filesystem.
419 static void add_journal(ext2_filsys fs)
421 unsigned long journal_blocks;
426 if (fs->super->s_feature_compat &
427 EXT3_FEATURE_COMPAT_HAS_JOURNAL) {
428 fputs(_("The filesystem already has a journal.\n"), stderr);
431 if (journal_device) {
432 check_plausibility(journal_device);
433 check_mount(journal_device, 0, _("journal"));
434 #ifdef CONFIG_TESTIO_DEBUG
435 io_ptr = test_io_manager;
436 test_io_backing_manager = unix_io_manager;
438 io_ptr = unix_io_manager;
440 retval = ext2fs_open(journal_device, EXT2_FLAG_RW|
441 EXT2_FLAG_JOURNAL_DEV_OK, 0,
442 fs->blocksize, io_ptr, &jfs);
444 com_err(program_name, retval,
445 _("\n\twhile trying to open journal on %s\n"),
449 printf(_("Creating journal on device %s: "),
453 retval = ext2fs_add_journal_device(fs, jfs);
456 com_err (program_name, retval,
457 _("while adding filesystem to journal on %s"),
461 fputs(_("done\n"), stdout);
462 } else if (journal_size) {
463 fputs(_("Creating journal inode: "), stdout);
465 journal_blocks = figure_journal_size(journal_size, fs);
467 retval = ext2fs_add_journal_inode(fs, journal_blocks,
470 fprintf(stderr, "\n");
471 com_err(program_name, retval,
472 _("\n\twhile trying to create journal file"));
475 fputs(_("done\n"), stdout);
477 * If the filesystem wasn't mounted, we need to force
478 * the block group descriptors out.
480 if ((mount_flags & EXT2_MF_MOUNTED) == 0)
481 fs->flags &= ~EXT2_FLAG_SUPER_ONLY;
483 print_check_message(fs);
488 free(journal_device);
493 static void parse_e2label_options(int argc, char ** argv)
495 if ((argc < 2) || (argc > 3)) {
496 fputs(_("Usage: e2label device [newlabel]\n"), stderr);
499 io_options = strchr(argv[1], '?');
502 device_name = blkid_get_devname(NULL, argv[1], NULL);
504 com_err("e2label", 0, _("Unable to resolve '%s'"),
508 open_flag = EXT2_FLAG_SOFTSUPP_FEATURES | EXT2_FLAG_JOURNAL_DEV_OK;
510 open_flag |= EXT2_FLAG_RW;
517 static time_t parse_time(char *str)
521 if (strcmp(str, "now") == 0) {
524 memset(&ts, 0, sizeof(ts));
526 strptime(str, "%Y%m%d%H%M%S", &ts);
528 sscanf(str, "%4d%2d%2d%2d%2d%2d", &ts.tm_year, &ts.tm_mon,
529 &ts.tm_mday, &ts.tm_hour, &ts.tm_min, &ts.tm_sec);
532 if (ts.tm_year < 0 || ts.tm_mon < 0 || ts.tm_mon > 11 ||
533 ts.tm_mday < 0 || ts.tm_mday > 31 || ts.tm_hour > 23 ||
534 ts.tm_min > 59 || ts.tm_sec > 61)
537 if (ts.tm_mday == 0) {
538 com_err(program_name, 0,
539 _("Couldn't parse date/time specifier: %s"),
544 return (mktime(&ts));
547 static void parse_tune2fs_options(int argc, char **argv)
554 open_flag = EXT2_FLAG_SOFTSUPP_FEATURES;
556 printf("tune2fs %s (%s)\n", E2FSPROGS_VERSION, E2FSPROGS_DATE);
557 while ((c = getopt(argc, argv, "c:e:fg:i:jlm:o:r:s:u:C:E:J:L:M:O:T:U:")) != EOF)
561 max_mount_count = strtol (optarg, &tmp, 0);
562 if (*tmp || max_mount_count > 16000) {
563 com_err (program_name, 0,
564 _("bad mounts count - %s"),
568 if (max_mount_count == 0)
569 max_mount_count = -1;
571 open_flag = EXT2_FLAG_RW;
574 mount_count = strtoul (optarg, &tmp, 0);
575 if (*tmp || mount_count > 16000) {
576 com_err (program_name, 0,
577 _("bad mounts count - %s"),
582 open_flag = EXT2_FLAG_RW;
585 if (strcmp (optarg, "continue") == 0)
586 errors = EXT2_ERRORS_CONTINUE;
587 else if (strcmp (optarg, "remount-ro") == 0)
588 errors = EXT2_ERRORS_RO;
589 else if (strcmp (optarg, "panic") == 0)
590 errors = EXT2_ERRORS_PANIC;
592 com_err (program_name, 0,
593 _("bad error behavior - %s"),
598 open_flag = EXT2_FLAG_RW;
601 extended_cmd = optarg;
602 open_flag |= EXT2_FLAG_RW;
604 case 'f': /* Force */
608 resgid = strtoul (optarg, &tmp, 0);
610 gr = getgrnam (optarg);
619 com_err (program_name, 0,
620 _("bad gid/group name - %s"),
625 open_flag = EXT2_FLAG_RW;
628 interval = strtoul (optarg, &tmp, 0);
641 case 'M': /* months! */
642 interval *= 86400 * 30;
646 case 'W': /* weeks */
647 interval *= 86400 * 7;
652 com_err (program_name, 0,
653 _("bad interval - %s"), optarg);
657 open_flag = EXT2_FLAG_RW;
662 open_flag = EXT2_FLAG_RW;
665 parse_journal_opts(optarg);
666 open_flag = EXT2_FLAG_RW;
674 open_flag |= EXT2_FLAG_RW |
675 EXT2_FLAG_JOURNAL_DEV_OK;
678 reserved_ratio = strtod(optarg, &tmp);
679 if (*tmp || reserved_ratio > 50) {
680 com_err (program_name, 0,
681 _("bad reserved block ratio - %s"),
686 open_flag = EXT2_FLAG_RW;
689 new_last_mounted = optarg;
691 open_flag = EXT2_FLAG_RW;
695 com_err (program_name, 0,
696 _("-o may only be specified once"));
699 mntopts_cmd = optarg;
700 open_flag = EXT2_FLAG_RW;
705 com_err (program_name, 0,
706 _("-O may only be specified once"));
709 features_cmd = optarg;
710 open_flag = EXT2_FLAG_RW;
713 reserved_blocks = strtoul (optarg, &tmp, 0);
715 com_err (program_name, 0,
716 _("bad reserved blocks count - %s"),
721 open_flag = EXT2_FLAG_RW;
723 case 's': /* Deprecated */
724 s_flag = atoi(optarg);
725 open_flag = EXT2_FLAG_RW;
729 last_check_time = parse_time(optarg);
730 open_flag = EXT2_FLAG_RW;
733 resuid = strtoul (optarg, &tmp, 0);
735 pw = getpwnam (optarg);
744 com_err (program_name, 0,
745 _("bad uid/user name - %s"),
750 open_flag = EXT2_FLAG_RW;
755 open_flag = EXT2_FLAG_RW |
756 EXT2_FLAG_JOURNAL_DEV_OK;
761 if (optind < argc - 1 || optind == argc)
763 if (!open_flag && !l_flag)
765 io_options = strchr(argv[optind], '?');
768 device_name = blkid_get_devname(NULL, argv[optind], NULL);
770 com_err("tune2fs", 0, _("Unable to resolve '%s'"),
776 void do_findfs(int argc, char **argv)
781 (strncmp(argv[1], "LABEL=", 6) && strncmp(argv[1], "UUID=", 5))) {
782 fprintf(stderr, "Usage: findfs LABEL=<label>|UUID=<uuid>\n");
785 dev = blkid_get_devname(NULL, argv[1], NULL);
787 com_err("findfs", 0, _("Unable to resolve '%s'"),
796 * Note! If any extended options are incompatible with the
797 * intersection of the SOFTSUPP features and those features explicitly
798 * enabled for tune2fs, there needs to be an explicit test for them
801 static void parse_extended_opts(ext2_filsys fs, const char *opts)
803 char *buf, *token, *next, *p, *arg;
811 _("Couldn't allocate memory to parse options!\n"));
815 for (token = buf; token && *token; token = next) {
816 p = strchr(token, ',');
822 arg = strchr(token, '=');
827 if (!strcmp(token, "test_fs")) {
828 fs->super->s_flags |= EXT2_FLAGS_TEST_FILESYS;
829 printf("Setting test filesystem flag\n");
830 ext2fs_mark_super_dirty(fs);
831 } else if (!strcmp(token, "^test_fs")) {
832 fs->super->s_flags &= ~EXT2_FLAGS_TEST_FILESYS;
833 printf("Clearing test filesystem flag\n");
834 ext2fs_mark_super_dirty(fs);
835 } else if (strcmp(token, "stride") == 0) {
840 stride = strtoul(arg, &p, 0);
841 if (*p || (stride == 0)) {
843 _("Invalid RAID stride: %s\n"),
849 } else if (strcmp(token, "stripe-width") == 0 ||
850 strcmp(token, "stripe_width") == 0) {
855 stripe_width = strtoul(arg, &p, 0);
856 if (*p || (stripe_width == 0)) {
858 _("Invalid RAID stripe-width: %s\n"),
863 stripe_width_set = 1;
868 fprintf(stderr, _("\nBad options specified.\n\n"
869 "Extended options are separated by commas, "
870 "and may take an argument which\n"
871 "\tis set off by an equals ('=') sign.\n\n"
872 "Valid extended options are:\n"
873 "\tstride=<RAID per-disk chunk size in blocks>\n"
874 "\tstripe-width=<RAID stride*data disks in blocks>\n"
884 int main (int argc, char ** argv)
888 struct ext2_super_block *sb;
892 setlocale(LC_MESSAGES, "");
893 setlocale(LC_CTYPE, "");
894 bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
895 textdomain(NLS_CAT_NAME);
898 program_name = *argv;
899 add_error_table(&et_ext2_error_table);
901 if (strcmp(get_progname(argv[0]), "findfs") == 0)
902 do_findfs(argc, argv);
903 if (strcmp(get_progname(argv[0]), "e2label") == 0)
904 parse_e2label_options(argc, argv);
906 parse_tune2fs_options(argc, argv);
908 #ifdef CONFIG_TESTIO_DEBUG
909 io_ptr = test_io_manager;
910 test_io_backing_manager = unix_io_manager;
912 io_ptr = unix_io_manager;
914 retval = ext2fs_open2(device_name, io_options, open_flag,
917 com_err (program_name, retval, _("while trying to open %s"),
920 _("Couldn't find valid filesystem superblock.\n"));
924 fs->flags &= ~EXT2_FLAG_MASTER_SB_ONLY;
925 if ((sb->s_feature_incompat & !EXT2_TUNE2FS_INCOMPAT) ||
926 (sb->s_feature_ro_compat & !EXT2_TUNE2FS_RO_COMPAT)) {
928 _("Filesystem %s has unsupported features enabled.\n"),
933 /* For e2label emulation */
934 printf("%.*s\n", (int) sizeof(sb->s_volume_name),
936 remove_error_table(&et_ext2_error_table);
939 retval = ext2fs_check_if_mounted(device_name, &mount_flags);
941 com_err("ext2fs_check_if_mount", retval,
942 _("while determining whether %s is mounted."),
946 /* Normally we only need to write out the superblock */
947 fs->flags |= EXT2_FLAG_SUPER_ONLY;
950 sb->s_max_mnt_count = max_mount_count;
951 ext2fs_mark_super_dirty(fs);
952 printf (_("Setting maximal mount count to %d\n"),
956 sb->s_mnt_count = mount_count;
957 ext2fs_mark_super_dirty(fs);
958 printf (_("Setting current mount count to %d\n"), mount_count);
961 sb->s_errors = errors;
962 ext2fs_mark_super_dirty(fs);
963 printf (_("Setting error behavior to %d\n"), errors);
966 sb->s_def_resgid = resgid;
967 ext2fs_mark_super_dirty(fs);
968 printf (_("Setting reserved blocks gid to %lu\n"), resgid);
971 sb->s_checkinterval = interval;
972 ext2fs_mark_super_dirty(fs);
973 printf (_("Setting interval between checks to %lu seconds\n"), interval);
976 sb->s_r_blocks_count = e2p_percent(reserved_ratio,
978 ext2fs_mark_super_dirty(fs);
979 printf (_("Setting reserved blocks percentage to %g%% (%u blocks)\n"),
980 reserved_ratio, sb->s_r_blocks_count);
983 if (reserved_blocks >= sb->s_blocks_count/2) {
984 com_err (program_name, 0,
985 _("reserved blocks count is too big (%lu)"),
989 sb->s_r_blocks_count = reserved_blocks;
990 ext2fs_mark_super_dirty(fs);
991 printf (_("Setting reserved blocks count to %lu\n"),
995 if (sb->s_feature_ro_compat &
996 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)
997 fputs(_("\nThe filesystem already has sparse "
998 "superblocks.\n"), stderr);
1000 sb->s_feature_ro_compat |=
1001 EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER;
1002 sb->s_state &= ~EXT2_VALID_FS;
1003 ext2fs_mark_super_dirty(fs);
1004 printf(_("\nSparse superblock flag set. %s"),
1009 fputs(_("\nClearing the sparse superflag not supported.\n"),
1014 sb->s_lastcheck = last_check_time;
1015 ext2fs_mark_super_dirty(fs);
1016 printf(_("Setting time filesystem last checked to %s\n"),
1017 ctime(&last_check_time));
1020 sb->s_def_resuid = resuid;
1021 ext2fs_mark_super_dirty(fs);
1022 printf (_("Setting reserved blocks uid to %lu\n"), resuid);
1025 if (strlen(new_label) > sizeof(sb->s_volume_name))
1026 fputs(_("Warning: label too long, truncating.\n"),
1028 memset(sb->s_volume_name, 0, sizeof(sb->s_volume_name));
1029 strncpy(sb->s_volume_name, new_label,
1030 sizeof(sb->s_volume_name));
1031 ext2fs_mark_super_dirty(fs);
1034 memset(sb->s_last_mounted, 0, sizeof(sb->s_last_mounted));
1035 strncpy(sb->s_last_mounted, new_last_mounted,
1036 sizeof(sb->s_last_mounted));
1037 ext2fs_mark_super_dirty(fs);
1040 update_mntopts(fs, mntopts_cmd);
1042 update_feature_set(fs, features_cmd);
1044 parse_extended_opts(fs, extended_cmd);
1045 if (journal_size || journal_device)
1049 if ((strcasecmp(new_UUID, "null") == 0) ||
1050 (strcasecmp(new_UUID, "clear") == 0)) {
1051 uuid_clear(sb->s_uuid);
1052 } else if (strcasecmp(new_UUID, "time") == 0) {
1053 uuid_generate_time(sb->s_uuid);
1054 } else if (strcasecmp(new_UUID, "random") == 0) {
1055 uuid_generate(sb->s_uuid);
1056 } else if (uuid_parse(new_UUID, sb->s_uuid)) {
1057 com_err(program_name, 0, _("Invalid UUID format\n"));
1060 ext2fs_mark_super_dirty(fs);
1066 sb->s_raid_stride = stride;
1067 ext2fs_mark_super_dirty(fs);
1068 printf(_("Setting stride size to %d\n"), stride);
1070 if (stripe_width_set) {
1071 sb->s_raid_stripe_width = stripe_width;
1072 ext2fs_mark_super_dirty(fs);
1073 printf(_("Setting stripe width to %d\n"), stripe_width);
1075 remove_error_table(&et_ext2_error_table);
1076 return (ext2fs_close (fs) ? 1 : 0);