[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20110901003119.31048.40300.stgit@elm3c44.beaverton.ibm.com>
Date: Wed, 31 Aug 2011 17:31:19 -0700
From: "Darrick J. Wong" <djwong@...ibm.com>
To: Andreas Dilger <adilger.kernel@...ger.ca>,
Theodore Tso <tytso@....edu>,
"Darrick J. Wong" <djwong@...ibm.com>
Cc: Sunil Mushran <sunil.mushran@...cle.com>,
Amir Goldstein <amir73il@...il.com>,
linux-kernel <linux-kernel@...r.kernel.org>,
Andi Kleen <andi@...stfloor.org>,
Mingming Cao <cmm@...ibm.com>,
Joel Becker <jlbec@...lplan.org>,
linux-fsdevel <linux-fsdevel@...r.kernel.org>,
linux-ext4@...r.kernel.org, Coly Li <colyli@...il.com>
Subject: [PATCH 07/16] ext4: Create bitmap checksum helper functions
These helper functions will be used to calculate and verify the block and inode
bitmap checksums.
Signed-off-by: Darrick J. Wong <djwong@...ibm.com>
---
fs/ext4/bitmap.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
fs/ext4/ext4.h | 6 ++++++
2 files changed, 50 insertions(+), 0 deletions(-)
diff --git a/fs/ext4/bitmap.c b/fs/ext4/bitmap.c
index fa3af81..5421152 100644
--- a/fs/ext4/bitmap.c
+++ b/fs/ext4/bitmap.c
@@ -9,6 +9,7 @@
#include <linux/buffer_head.h>
#include <linux/jbd2.h>
+#include <linux/crc32c.h>
#include "ext4.h"
#ifdef EXT4FS_DEBUG
@@ -29,3 +30,46 @@ unsigned int ext4_count_free(struct buffer_head *map, unsigned int numchars)
#endif /* EXT4FS_DEBUG */
+__le32 ext4_bitmap_csum(struct super_block *sb, ext4_group_t group,
+ struct buffer_head *bh, int sz)
+{
+ __le32 crc;
+ struct ext4_sb_info *sbi = EXT4_SB(sb);
+
+ if (sbi->s_desc_size < EXT4_MIN_DESC_SIZE_64BIT)
+ return 0;
+ if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
+ EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
+ return 0;
+
+ group = cpu_to_le32(group);
+ crc = crc32c_le(~0, sbi->s_es->s_uuid, sizeof(sbi->s_es->s_uuid));
+ crc = crc32c_le(crc, (__u8 *)&group, sizeof(group));
+ crc = crc32c_le(crc, (__u8 *)bh->b_data, sz);
+
+ return cpu_to_le32(crc);
+}
+
+int ext4_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
+ __le32 provided, struct buffer_head *bh, int sz)
+{
+ struct ext4_sb_info *sbi = EXT4_SB(sb);
+
+ if (sbi->s_desc_size >= EXT4_MIN_DESC_SIZE_64BIT &&
+ EXT4_HAS_RO_COMPAT_FEATURE(sb,
+ EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) &&
+ (provided != ext4_bitmap_csum(sb, group, bh, sz)))
+ return 0;
+ return 1;
+}
+
+void ext4_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
+ __le32 *csum, struct buffer_head *bh, int sz)
+{
+ struct ext4_sb_info *sbi = EXT4_SB(sb);
+
+ if (sbi->s_desc_size >= EXT4_MIN_DESC_SIZE_64BIT &&
+ EXT4_HAS_RO_COMPAT_FEATURE(sb,
+ EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
+ *csum = ext4_bitmap_csum(sb, group, bh, sz);
+}
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index e2361cc..bc7ace1 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1722,6 +1722,12 @@ struct mmpd_data {
/* bitmap.c */
extern unsigned int ext4_count_free(struct buffer_head *, unsigned);
+__le32 ext4_bitmap_csum(struct super_block *sb, ext4_group_t group,
+ struct buffer_head *bh, int sz);
+int ext4_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
+ __le32 provided, struct buffer_head *bh, int sz);
+void ext4_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
+ __le32 *csum, struct buffer_head *bh, int sz);
/* balloc.c */
extern unsigned int ext4_block_group(struct super_block *sb,
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists