Whamcloud - gitweb
Merge branch 'maint' into next
[tools/e2fsprogs.git] / lib / ext2fs / mmp.c
index 98562e7..00f3461 100644 (file)
@@ -33,6 +33,7 @@
 
 errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf)
 {
+#ifdef CONFIG_MMP
        struct mmp_struct *mmp_cmp;
        errcode_t retval = 0;
 
@@ -75,6 +76,11 @@ errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf)
        }
 
        mmp_cmp = fs->mmp_cmp;
+
+       if (!(fs->flags & EXT2_FLAG_IGNORE_CSUM_ERRORS) &&
+           !ext2fs_mmp_csum_verify(fs, mmp_cmp))
+               retval = EXT2_ET_MMP_CSUM_INVALID;
+
 #ifdef WORDS_BIGENDIAN
        ext2fs_swap_mmp(mmp_cmp);
 #endif
@@ -89,10 +95,14 @@ errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf)
 
 out:
        return retval;
+#else
+       return EXT2_ET_OP_NOT_SUPPORTED;
+#endif
 }
 
 errcode_t ext2fs_mmp_write(ext2_filsys fs, blk64_t mmp_blk, void *buf)
 {
+#ifdef CONFIG_MMP
        struct mmp_struct *mmp_s = buf;
        struct timeval tv;
        errcode_t retval = 0;
@@ -109,6 +119,10 @@ errcode_t ext2fs_mmp_write(ext2_filsys fs, blk64_t mmp_blk, void *buf)
        ext2fs_swap_mmp(mmp_s);
 #endif
 
+       retval = ext2fs_mmp_csum_set(fs, mmp_s);
+       if (retval)
+               return retval;
+
        /* I was tempted to make this use O_DIRECT and the mmp_fd, but
         * this caused no end of grief, while leaving it as-is works. */
        retval = io_channel_write_blk64(fs->io, mmp_blk, -(int)sizeof(struct mmp_struct), buf);
@@ -120,6 +134,9 @@ errcode_t ext2fs_mmp_write(ext2_filsys fs, blk64_t mmp_blk, void *buf)
        /* Make sure the block gets to disk quickly */
        io_channel_flush(fs->io);
        return retval;
+#else
+       return EXT2_ET_OP_NOT_SUPPORTED;
+#endif
 }
 
 #ifdef HAVE_SRANDOM
@@ -129,6 +146,7 @@ errcode_t ext2fs_mmp_write(ext2_filsys fs, blk64_t mmp_blk, void *buf)
 
 unsigned ext2fs_mmp_new_seq()
 {
+#ifdef CONFIG_MMP
        unsigned new_seq;
        struct timeval tv;
 
@@ -145,6 +163,9 @@ unsigned ext2fs_mmp_new_seq()
        } while (new_seq > EXT4_MMP_SEQ_MAX);
 
        return new_seq;
+#else
+       return EXT2_ET_OP_NOT_SUPPORTED;
+#endif
 }
 
 static errcode_t ext2fs_mmp_reset(ext2_filsys fs)
@@ -181,8 +202,14 @@ out:
        return retval;
 }
 
+errcode_t ext2fs_mmp_update(ext2_filsys fs)
+{
+       return ext2fs_mmp_update2(fs, 0);
+}
+
 errcode_t ext2fs_mmp_clear(ext2_filsys fs)
 {
+#ifdef CONFIG_MMP
        errcode_t retval = 0;
 
        if (!(fs->flags & EXT2_FLAG_RW))
@@ -191,10 +218,14 @@ errcode_t ext2fs_mmp_clear(ext2_filsys fs)
        retval = ext2fs_mmp_reset(fs);
 
        return retval;
+#else
+       return EXT2_ET_OP_NOT_SUPPORTED;
+#endif
 }
 
 errcode_t ext2fs_mmp_init(ext2_filsys fs)
 {
+#ifdef CONFIG_MMP
        struct ext2_super_block *sb = fs->super;
        blk64_t mmp_block;
        errcode_t retval;
@@ -223,6 +254,9 @@ errcode_t ext2fs_mmp_init(ext2_filsys fs)
 
 out:
        return retval;
+#else
+       return EXT2_ET_OP_NOT_SUPPORTED;
+#endif
 }
 
 /*
@@ -230,6 +264,7 @@ out:
  */
 errcode_t ext2fs_mmp_start(ext2_filsys fs)
 {
+#ifdef CONFIG_MMP
        struct mmp_struct *mmp_s;
        unsigned seq;
        unsigned int mmp_check_interval;
@@ -319,6 +354,9 @@ clean_seq:
 
 mmp_error:
        return retval;
+#else
+       return EXT2_ET_OP_NOT_SUPPORTED;
+#endif
 }
 
 /*
@@ -329,6 +367,7 @@ mmp_error:
  */
 errcode_t ext2fs_mmp_stop(ext2_filsys fs)
 {
+#ifdef CONFIG_MMP
        struct mmp_struct *mmp, *mmp_cmp;
        errcode_t retval = 0;
 
@@ -358,6 +397,9 @@ mmp_error:
        }
 
        return retval;
+#else
+       return EXT2_ET_OP_NOT_SUPPORTED;
+#endif
 }
 
 #define EXT2_MIN_MMP_UPDATE_INTERVAL 60
@@ -365,8 +407,9 @@ mmp_error:
 /*
  * Update the on-disk mmp buffer, after checking that it hasn't been changed.
  */
-errcode_t ext2fs_mmp_update(ext2_filsys fs)
+errcode_t ext2fs_mmp_update2(ext2_filsys fs, int immediately)
 {
+#ifdef CONFIG_MMP
        struct mmp_struct *mmp, *mmp_cmp;
        struct timeval tv;
        errcode_t retval = 0;
@@ -376,7 +419,8 @@ errcode_t ext2fs_mmp_update(ext2_filsys fs)
                return 0;
 
        gettimeofday(&tv, 0);
-       if (tv.tv_sec - fs->mmp_last_written < EXT2_MIN_MMP_UPDATE_INTERVAL)
+       if (!immediately &&
+           tv.tv_sec - fs->mmp_last_written < EXT2_MIN_MMP_UPDATE_INTERVAL)
                return 0;
 
        retval = ext2fs_mmp_read(fs, fs->super->s_mmp_block, NULL);
@@ -395,4 +439,7 @@ errcode_t ext2fs_mmp_update(ext2_filsys fs)
 
 mmp_error:
        return retval;
+#else
+       return EXT2_ET_OP_NOT_SUPPORTED;
+#endif
 }