diff options
author | Theodore Ts'o <tytso@mit.edu> | 2021-02-14 10:37:00 -0500 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2021-02-14 10:37:00 -0500 |
commit | e3a13a47e6f215c5db5cb58f646b422d6330fc6a (patch) | |
tree | 851133d8f7ad07b897412b1ed6e210e8920ab309 | |
parent | ff9b039b1f6c86b144686d5baf57dbce14998285 (diff) | |
download | e2fsprogs-e3a13a47e6f215c5db5cb58f646b422d6330fc6a.tar.gz |
tune2fs: teach tune2fs to use a random value for "-c random"
Addresses-Debian-Bug: #926293
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r-- | misc/tune2fs.8.in | 25 | ||||
-rw-r--r-- | misc/tune2fs.c | 14 |
2 files changed, 21 insertions, 18 deletions
diff --git a/misc/tune2fs.8.in b/misc/tune2fs.8.in index 1a181a73b..b963f30ed 100644 --- a/misc/tune2fs.8.in +++ b/misc/tune2fs.8.in @@ -117,6 +117,9 @@ Adjust the number of mounts after which the filesystem will be checked by .BR e2fsck (8). If .I max-mount-counts +is the string "random", tune2fs will use a random value between 20 and 40. +If +.I max-mount-counts is 0 or \-1, the number of times the filesystem is mounted will be disregarded by .BR e2fsck (8) @@ -127,21 +130,13 @@ checked will avoid all filesystems being checked at one time when using journaled filesystems. .sp Mount-count-dependent checking is disabled by default to avoid -unanticipated long reboots while e2fsck does its work. However, -you may wish to consider the consequences of disabling -mount-count-dependent checking entirely. Bad disk drives, cables, -memory, and kernel bugs could all corrupt a filesystem without -marking the filesystem dirty or in error. If you are using -journaling on your filesystem, your filesystem will -.B never -be marked dirty, so it will not normally be checked. A -filesystem error detected by the kernel will still force -an fsck on the next reboot, but it may already be too late -to prevent data loss at that point. -.sp -See also the -.B \-i -option for time-dependent checking. +unanticipated long reboots while e2fsck does its work. If you +are concerned about file system corruptions caused by potential hardware +problems of kernel bugs, a better solution than mount-count-dependent +checking is to use the +.BR e2scrub (8) +program. This does require placing the file system on an LVM volume, +however. .TP .BI \-C " mount-count" Set the number of times the filesystem has been mounted. diff --git a/misc/tune2fs.c b/misc/tune2fs.c index 11715ba49..f739f16cd 100644 --- a/misc/tune2fs.c +++ b/misc/tune2fs.c @@ -1826,8 +1826,15 @@ static void parse_tune2fs_options(int argc, char **argv) while ((c = getopt(argc, argv, optstring)) != EOF) switch (c) { case 'c': + open_flag = EXT2_FLAG_RW; + c_flag = 1; + if (strcmp(optarg, "random") == 0) { + max_mount_count = 65536; + break; + } max_mount_count = strtol(optarg, &tmp, 0); - if (*tmp || max_mount_count > 16000) { + if (*tmp || max_mount_count > 16000 || + max_mount_count < -16000) { com_err(program_name, 0, _("bad mounts count - %s"), optarg); @@ -1835,8 +1842,6 @@ static void parse_tune2fs_options(int argc, char **argv) } if (max_mount_count == 0) max_mount_count = -1; - c_flag = 1; - open_flag = EXT2_FLAG_RW; break; case 'C': mount_count = strtoul(optarg, &tmp, 0); @@ -3104,6 +3109,9 @@ _("Warning: The journal is dirty. You may wish to replay the journal like:\n\n" fs->flags |= EXT2_FLAG_SUPER_ONLY; if (c_flag) { + if (max_mount_count == 65536) + max_mount_count = EXT2_DFL_MAX_MNT_COUNT + + (random() % EXT2_DFL_MAX_MNT_COUNT); sb->s_max_mnt_count = max_mount_count; ext2fs_mark_super_dirty(fs); printf(_("Setting maximal mount count to %d\n"), |