]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
e2image: complain if running e2image -r or -Q on a mounted filesystem
authorCarlos Maiolino <cmaiolino@redhat.com>
Sat, 12 Oct 2013 01:38:53 +0000 (21:38 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 12 Oct 2013 01:49:16 +0000 (21:49 -0400)
Several users have used e2image on a mounted RW filesystem, resulting in
inconsistent, useless e2images for debugging purposes.

This commit will forbid this and print an error message, although the
user can override this using a new force option.

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
misc/e2image.8.in
misc/e2image.c

index 84b97296665f05e05afd98cda0a6d38017b93ead..78f06828d75d16d2f4f8ae5b8ebb936890f5ad18 100644 (file)
@@ -30,6 +30,16 @@ recovering catastrophically corrupted filesystems.  In the future,
 e2fsck will be enhanced to be able to use the image file to help
 recover a badly damaged filesystem.
 .PP
+When saving an e2image for debugging purposes, using either the
+.B \-r
+or
+.B \-Q
+options, the filesystem must be unmounted or be mounted read/only, in order
+for the image file to be in a consistent state.  This requirement can be
+overriden using the
+.B -f
+option, but the resulting image file is very likely not going to be useful.
+.PP
 If
 .I image-file
 is \-, then the output of
index 885a79433f0d6f77ded86346ac4aecbffb580432..4a5bb22d49cf52ea4c56c9662e0ddb523aaa9dd3 100644 (file)
@@ -87,7 +87,7 @@ static int get_bits_from_size(size_t size)
 
 static void usage(void)
 {
-       fprintf(stderr, _("Usage: %s [-rsIQa] device image_file\n"),
+       fprintf(stderr, _("Usage: %s [-rsIQaf] device image_file\n"),
                program_name);
        exit (1);
 }
@@ -1252,9 +1252,11 @@ int main (int argc, char ** argv)
        int open_flag = EXT2_FLAG_64BITS;
        int img_type = 0;
        int flags = 0;
+       int mount_flags = 0;
        int qcow2_fd = 0;
        int fd = 0;
        int ret = 0;
+       int ignore_rw_mount = 0;
        struct stat st;
 
 #ifdef ENABLE_NLS
@@ -1269,7 +1271,7 @@ int main (int argc, char ** argv)
        if (argc && *argv)
                program_name = *argv;
        add_error_table(&et_ext2_error_table);
-       while ((c = getopt(argc, argv, "rsIQa")) != EOF)
+       while ((c = getopt(argc, argv, "rsIQaf")) != EOF)
                switch (c) {
                case 'I':
                        flags |= E2IMAGE_INSTALL_FLAG;
@@ -1290,6 +1292,9 @@ int main (int argc, char ** argv)
                case 'a':
                        all_data = 1;
                        break;
+               case 'f':
+                       ignore_rw_mount = 1;
+                       break;
                default:
                        usage();
                }
@@ -1305,6 +1310,19 @@ int main (int argc, char ** argv)
        device_name = argv[optind];
        image_fn = argv[optind+1];
 
+       ext2fs_check_if_mounted(device_name, &mount_flags);
+
+       if (img_type && !ignore_rw_mount &&
+           (mount_flags & EXT2_MF_MOUNTED) &&
+          !(mount_flags & EXT2_MF_READONLY)) {
+               fprintf(stderr, "\nRunning e2image on a R/W mounted "
+                       "filesystem can result in an\n"
+                       "inconsistent image which will not be useful "
+                       "for debugging purposes.\n"
+                       "Use -f option if you really want to do that.\n");
+               exit(1);
+       }
+
        if (flags & E2IMAGE_INSTALL_FLAG) {
                install_image(device_name, image_fn, img_type);
                exit (0);