OSDN Git Service

debugfs: improve dump_mmp handling
authorAndreas Dilger <adilger@dilger.ca>
Sun, 6 Mar 2016 00:38:32 +0000 (17:38 -0700)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 6 Mar 2016 23:11:48 +0000 (18:11 -0500)
If MMP is not enabled on a filesystem (s_mmp_block == 0), print this
clearly rather than "MMP: block number beyond filesystem range".

Add an option to "debugfs dump_mmp" to specify the MMP block number
instead of getting it from the superblock s_mmp_block field.

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
debugfs/debugfs.8.in
debugfs/debugfs.c

index bae14db..4928791 100644 (file)
@@ -221,8 +221,13 @@ option is given set the owner, group and permissions information on
 to match
 .IR filespec .
 .TP
-.B dump_mmp
-Display the multiple-mount protection (mmp) field values.
+.BI dump_mmp " [mmp_block]"
+Display the multiple-mount protection (mmp) field values.  If
+.I mmp_block
+is specified then verify and dump the MMP values from the given block
+number, otherwise use the
+.B s_mmp_block
+field in the superblock to locate and use the existing MMP block.
 .TP
 .BI dx_hash " [-h hash_alg] [-s hash_seed] filename"
 Calculate the directory hash of
index 5423634..260698c 100644 (file)
@@ -2351,12 +2351,31 @@ try_again:
 void do_dump_mmp(int argc EXT2FS_ATTR((unused)), char *argv[])
 {
        struct mmp_struct *mmp_s;
+       unsigned long long mmp_block;
        time_t t;
        errcode_t retval = 0;
 
        if (check_fs_open(argv[0]))
                return;
 
+       if (argc > 1) {
+               char *end = NULL;
+               mmp_block = strtoull(argv[1], &end, 0);
+               if (end == argv[0] || mmp_block == 0) {
+                       fprintf(stderr, "%s: invalid MMP block '%s' given\n",
+                               argv[0], argv[1]);
+                       return;
+               }
+       } else {
+               mmp_block = current_fs->super->s_mmp_block;
+       }
+
+       if (mmp_block == 0) {
+               fprintf(stderr, "%s: MMP: not active on this filesystem.\n",
+                       argv[0]);
+               return;
+       }
+
        if (current_fs->mmp_buf == NULL) {
                retval = ext2fs_get_mem(current_fs->blocksize,
                                        &current_fs->mmp_buf);
@@ -2368,10 +2387,10 @@ void do_dump_mmp(int argc EXT2FS_ATTR((unused)), char *argv[])
 
        mmp_s = current_fs->mmp_buf;
 
-       retval = ext2fs_mmp_read(current_fs, current_fs->super->s_mmp_block,
-                                current_fs->mmp_buf);
+       retval = ext2fs_mmp_read(current_fs, mmp_block, current_fs->mmp_buf);
        if (retval) {
-               com_err(argv[0], retval, "reading MMP block.\n");
+               com_err(argv[0], retval, "reading MMP block %llu.\n",
+                       mmp_block);
                return;
        }