shithub: lwext4

Download patch

ref: e40f01af4ed918874efa5279c0e18ab47e80e989
parent: c7c5aba4d7e3af2e3676051d14ed9512fac76bc2
author: ngkaho1234 <[email protected]>
date: Tue Oct 27 18:50:44 EDT 2015

FIX: checksum is not calculated for just-initialized bitmap.

--- a/lwext4/ext4_balloc.c
+++ b/lwext4/ext4_balloc.c
@@ -101,9 +101,9 @@
  *       Currently we do not verify the checksum of bitmaps.
  */
 
-static void ext4_balloc_set_bitmap_csum(struct ext4_sblock *sb,
-					struct ext4_bgroup *bg,
-					void *bitmap)
+void ext4_balloc_set_bitmap_csum(struct ext4_sblock *sb,
+				 struct ext4_bgroup *bg,
+				 void *bitmap)
 {
 	int desc_size = ext4_sb_get_desc_size(sb);
 	uint32_t checksum = ext4_balloc_bitmap_csum(sb, bitmap);
--- a/lwext4/ext4_balloc.h
+++ b/lwext4/ext4_balloc.h
@@ -64,6 +64,15 @@
 ext4_fsblk_t ext4_balloc_get_block_of_bgid(struct ext4_sblock *s,
 				       uint32_t bgid);
 
+/**@brief Calculate and set checksum of block bitmap.
+ * @param sb superblock pointer.
+ * @param bg block group
+ * @param bitmap bitmap buffer
+ */
+void ext4_balloc_set_bitmap_csum(struct ext4_sblock *sb,
+				 struct ext4_bgroup *bg,
+				 void *bitmap);
+
 /**@brief   Free block from inode.
  * @param   inode_ref inode reference
  * @param   baddr block address
--- a/lwext4/ext4_fs.c
+++ b/lwext4/ext4_fs.c
@@ -374,6 +374,11 @@
         ext4_fs_mark_bitmap_end(group_blocks, block_size * 8, block_bitmap.data);
 	block_bitmap.dirty = true;
 
+	ext4_balloc_set_bitmap_csum(&bg_ref->fs->sb,
+				    bg_ref->block_group,
+				    block_bitmap.data);
+	bg_ref->dirty = true;
+
 	/* Save bitmap */
 	return ext4_block_set(bg_ref->fs->bdev, &block_bitmap);
 }
@@ -412,6 +417,11 @@
 		memset(block_bitmap.data + (i >> 3), 0xff, (end_bit - i) >> 3);
 
 	block_bitmap.dirty = true;
+
+	ext4_ialloc_set_bitmap_csum(&bg_ref->fs->sb,
+				    bg_ref->block_group,
+				    block_bitmap.data);
+	bg_ref->dirty = true;
 
 	/* Save bitmap */
 	return ext4_block_set(bg_ref->fs->bdev, &block_bitmap);
--- a/lwext4/ext4_ialloc.c
+++ b/lwext4/ext4_ialloc.c
@@ -109,9 +109,9 @@
  *       Currently we do not verify the checksum of bitmaps.
  */
 
-static void ext4_ialloc_set_bitmap_csum(struct ext4_sblock *sb,
-					struct ext4_bgroup *bg,
-					void *bitmap)
+void ext4_ialloc_set_bitmap_csum(struct ext4_sblock *sb,
+				 struct ext4_bgroup *bg,
+				 void *bitmap)
 {
 	int desc_size = ext4_sb_get_desc_size(sb);
 	uint32_t checksum = ext4_ialloc_bitmap_csum(sb, bitmap);
--- a/lwext4/ext4_ialloc.h
+++ b/lwext4/ext4_ialloc.h
@@ -49,6 +49,15 @@
 #include "ext4_config.h"
 #include "ext4_types.h"
 
+/**@brief Calculate and set checksum of inode bitmap.
+ * @param sb superblock pointer.
+ * @param bg block group
+ * @param bitmap bitmap buffer
+ */
+void ext4_ialloc_set_bitmap_csum(struct ext4_sblock *sb,
+				 struct ext4_bgroup *bg,
+				 void *bitmap);
+
 /**@brief Free i-node number and modify filesystem data structers.
  * @param fs     Filesystem, where the i-node is located
  * @param index  Index of i-node to be release