shithub: lwext4

Download patch

ref: 2b928635d2a1258edcee77b315a2e66f41c6fd45
parent: 8f81cab8ae1a5d77fefb69698e92fa0a1dd1cdb4
author: ngkaho1234 <[email protected]>
date: Sun Nov 15 12:25:38 EST 2015

ext4_journal: two changes below

 - Add JBD_SUPERBLOCK_SIZE macro
 - Add jbd_sb_read & jbd_sb_write

--- a/lwext4/ext4_journal.c
+++ b/lwext4/ext4_journal.c
@@ -6,6 +6,7 @@
 #include "ext4_config.h"
 #include "ext4_types.h"
 #include "ext4_fs.h"
+#include "ext4_super.h"
 #include "ext4_errno.h"
 #include "ext4_blockdev.h"
 #include "ext4_crc32c.h"
@@ -12,6 +13,40 @@
 #include "ext4_debug.h"
 
 #include <string.h>
+
+int jbd_inode_bmap(struct jbd_fs *jbd_fs,
+		   ext4_lblk_t iblock,
+		   ext4_fsblk_t *fblock);
+
+int jbd_sb_write(struct jbd_fs *jbd_fs, struct jbd_sb *s)
+{
+	int rc;
+	struct ext4_fs *fs = jbd_fs->inode_ref.fs;
+	uint64_t offset;
+	ext4_fsblk_t fblock;
+	rc = jbd_inode_bmap(jbd_fs, 0, &fblock);
+	if (rc != EOK)
+		return rc;
+
+	offset = fblock * ext4_sb_get_block_size(&fs->sb);
+	return ext4_block_writebytes(fs->bdev, offset, s,
+				     EXT4_SUPERBLOCK_SIZE);
+}
+
+int jbd_sb_read(struct jbd_fs *jbd_fs, struct ext4_sblock *s)
+{
+	int rc;
+	struct ext4_fs *fs = jbd_fs->inode_ref.fs;
+	uint64_t offset;
+	ext4_fsblk_t fblock;
+	rc = jbd_inode_bmap(jbd_fs, 0, &fblock);
+	if (rc != EOK)
+		return rc;
+
+	offset = fblock * ext4_sb_get_block_size(&fs->sb);
+	return ext4_block_readbytes(fs->bdev, offset, s,
+				    EXT4_SUPERBLOCK_SIZE);
+}
 
 int jbd_get_fs(struct ext4_fs *fs,
 	       struct jbd_fs *jbd_fs)
--- a/lwext4/ext4_types.h
+++ b/lwext4/ext4_types.h
@@ -1049,6 +1049,8 @@
 /* 0x0400 */
 };
 
+#define JBD_SUPERBLOCK_SIZE sizeof(struct jbd_sb)
+
 #define JBD_HAS_COMPAT_FEATURE(jsb,mask)					\
 	((jsb)->header.blocktype >= to_be32(2) &&				\
 	 ((jsb)->feature_compat & to_be32((mask))))