summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2014-05-05 00:20:31 -0400
committerTheodore Ts'o <tytso@mit.edu>2014-05-07 10:51:39 -0400
commit352fbedb211a1df3eebedd6b6aecddea44008525 (patch)
tree38de87186034d4d6828b89deed9a6368ebb7e6cb
parenta11ccebd899a40986948afd81f218271605b650f (diff)
downloade2fsprogs-352fbedb211a1df3eebedd6b6aecddea44008525.tar.gz
mke2fs: print extra information about existing ext2/3/4 file systems
The basic idea is to provide a bit more context in this situation: % ./misc/mke2fs -t ext4 /dev/sdc3 mke2fs 1.42.9 (4-Feb-2014) /dev/sdc3 contains a ext4 file system Proceed anyway? (y,n) ... by adding this bit of context: % ./misc/mke2fs -t ext4 /dev/sdc3 mke2fs 1.42.9 (4-Feb-2014) /dev/sdc3 contains a ext4 file system last mounted on /SOX-backups on Mon May 5 08:59:53 2014 Proceed anyway? (y,n) Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
-rw-r--r--misc/util.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/misc/util.c b/misc/util.c
index 15b4ce5c..051183ef 100644
--- a/misc/util.c
+++ b/misc/util.c
@@ -105,6 +105,42 @@ void proceed_question(int delay)
signal(SIGALRM, SIG_IGN);
}
+static void print_ext2_info(const char *device)
+
+{
+ struct ext2_super_block *sb;
+ ext2_filsys fs;
+ errcode_t retval;
+ time_t tm;
+ char buf[80];
+
+ retval = ext2fs_open2(device, 0, EXT2_FLAG_64BITS, 0, 0,
+ unix_io_manager, &fs);
+ if (retval)
+ return;
+ sb = fs->super;
+
+ if (sb->s_mtime) {
+ tm = sb->s_mtime;
+ if (sb->s_last_mounted[0]) {
+ memset(buf, 0, sizeof(buf));
+ strncpy(buf, sb->s_last_mounted,
+ sizeof(sb->s_last_mounted));
+ printf(_("\tlast mounted on %s on %s"), buf,
+ ctime(&tm));
+ } else
+ printf(_("\tlast mounted on %s"), ctime(&tm));
+ } else if (sb->s_mkfs_time) {
+ tm = sb->s_mkfs_time;
+ printf(_("\tcreated on %s"), ctime(&tm));
+ } else if (sb->s_wtime) {
+ tm = sb->s_wtime;
+ printf(_("\tlast modified on %s"), ctime(&tm));
+ }
+ ext2fs_close(fs);
+}
+
+
/*
* return 1 if the device looks plausible, creating the file if necessary
*/
@@ -168,6 +204,8 @@ int check_plausibility(const char *device, int flags, int *ret_is_dev)
else
printf(_("%s contains a %s file system\n"), device,
fs_type);
+ if (strncmp(fs_type, "ext", 3) == 0)
+ print_ext2_info(device);
free(fs_type);
free(fs_label);
return 0;