From d4de4aa938339275515b2b5b6fcf8ca2b51c3d34 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Wed, 26 Dec 2001 08:58:01 -0500 Subject: [PATCH] tune2fs.8.in, tune2fs.c (parse_tune2fs_options, main): Add support for new option, -T, which allows the user to set the last checked time on the filesystem. --- misc/ChangeLog | 6 ++++++ misc/tune2fs.8.in | 20 ++++++++++++++++++++ misc/tune2fs.c | 38 ++++++++++++++++++++++++++++++++++---- 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/misc/ChangeLog b/misc/ChangeLog index 8f8ff02..a1fc259 100644 --- a/misc/ChangeLog +++ b/misc/ChangeLog @@ -1,3 +1,9 @@ +2001-12-26 Theodore Tso + + * tune2fs.8.in, tune2fs.c (parse_tune2fs_options, main): Add + support for new option, -T, which allows the user to set + the last checked time on the filesystem. + 2001-12-24 Theodore Tso * mke2fs.c (main, test_disk): If two -c options are diff --git a/misc/tune2fs.8.in b/misc/tune2fs.8.in index 2b22dbd..e47485c 100644 --- a/misc/tune2fs.8.in +++ b/misc/tune2fs.8.in @@ -66,6 +66,10 @@ tune2fs \- adjust tunable filesystem parameters on second extended filesystems .RI [^] feature [,...] ] [ +.B \-T +.I time-last-checked +] +[ .B \-U .I UUID ] @@ -294,6 +298,22 @@ doing! You need to run on the filesystem after changing this feature in order to have a valid filesystem. .TP +.BI \-T " time-last-checked" +Set the time the filesystem was last checked using +.BR e2fsck . +This can be useful in scripts which use a Logical Volume Manager to make +a consistent snapshot of a filesystem, and then check the filesystem +during off hours to make sure it hasn't been corrupted due to +hardware problems, etc. If the filesystem was clean, then this option can +be used to set the last checked time on the original filesystem. The format +of +.I time-last-checked +is the international date format, with an optional time specifier, i.e. +YYYYMMDD[[HHMM]SS]. The keyword +.B now +is also accepted, in which case the last checked time will be set to the +current time. +.TP .BI \-u " user" Set the user who can use the reserved filesystem blocks. .I user diff --git a/misc/tune2fs.c b/misc/tune2fs.c index 794f35b..a25d8bf 100644 --- a/misc/tune2fs.c +++ b/misc/tune2fs.c @@ -57,7 +57,8 @@ const char * program_name = "tune2fs"; char * device_name; char * new_label, *new_last_mounted, *new_UUID; static int c_flag, C_flag, e_flag, f_flag, g_flag, i_flag, l_flag, L_flag; -static int m_flag, M_flag, r_flag, s_flag = -1, u_flag, U_flag; +static int m_flag, M_flag, r_flag, s_flag = -1, u_flag, U_flag, T_flag; +static time_t last_check_time; static int print_label; static int max_mount_count, mount_count, mount_flags; static unsigned long interval, reserved_ratio, reserved_blocks; @@ -79,8 +80,9 @@ static void usage(void) "\t[-i interval[d|m|w]] [-j] [-J journal-options]\n" "\t[-l] [-s sparse-flag] [-m reserved-blocks-percent]\n" "\t[-r reserved-blocks-count] [-u user] [-C mount-count]\n" - "\t[-L volume-label] [-M last-mounted-dir] [-U UUID]\n" - "\t[-O [^]feature[,...]] device\n"), program_name); + "\t[-L volume-label] [-M last-mounted-dir]\n" + "\t[-O [^]feature[,...]] [-T last-check-time] [-U UUID]" + " device\n"), program_name); exit (1); } @@ -418,6 +420,23 @@ static void parse_e2label_options(int argc, char ** argv) print_label++; } +static time_t parse_time(char *str) +{ + struct tm ts; + + if (strcmp(str, "now") == 0) { + return (time(0)); + } + memset(&ts, 0, sizeof(ts)); + strptime(optarg, "%Y%m%d%H%M%S", &ts); + if (ts.tm_mday == 0) { + com_err(program_name, 0, + _("Couldn't parse date/time specifier: %s"), + str); + usage(); + } + return (mktime(&ts)); +} static void parse_tune2fs_options(int argc, char **argv) { @@ -427,7 +446,7 @@ static void parse_tune2fs_options(int argc, char **argv) struct passwd * pw; printf("tune2fs %s (%s)\n", E2FSPROGS_VERSION, E2FSPROGS_DATE); - while ((c = getopt (argc, argv, "c:e:fg:i:jlm:r:s:u:C:J:L:M:O:U:")) != EOF) + while ((c = getopt(argc, argv, "c:e:fg:i:jlm:r:s:u:C:J:L:M:O:T:U:")) != EOF) switch (c) { case 'c': @@ -583,6 +602,11 @@ static void parse_tune2fs_options(int argc, char **argv) s_flag = atoi(optarg); open_flag = EXT2_FLAG_RW; break; + case 'T': + T_flag = 1; + last_check_time = parse_time(optarg); + open_flag = EXT2_FLAG_RW; + break; case 'u': resuid = strtoul (optarg, &tmp, 0); if (*tmp) { @@ -741,6 +765,12 @@ int main (int argc, char ** argv) _(please_fsck)); } } + if (T_flag) { + sb->s_lastcheck = last_check_time; + ext2fs_mark_super_dirty(fs); + printf(_("Setting time filesystem last checked to %s\n"), + ctime(&last_check_time)); + } if (u_flag) { sb->s_def_resuid = resuid; ext2fs_mark_super_dirty(fs); -- 1.8.3.1