shithub: lwext4

Download patch

ref: c568b087e35003acc2b4d3a14049787d22617c3a
parent: 8f8a935ae145b9cd6cbee7df121fdee177513cae
author: ngkaho1234 <ngkaho1234@gmail.com>
date: Thu Dec 24 13:14:40 EST 2015

ext4: journalling <---> lwext4 main code junction skeleton code.

--- a/lwext4/ext4.c
+++ b/lwext4/ext4.c
@@ -83,6 +83,9 @@
 
 	/**@brief   Dynamic allocation cache flag.*/
 	bool cache_dynamic;
+
+	struct jbd_fs jbd_fs;
+	struct jbd_journal jbd_journal;
 };
 
 /**@brief   Block devices descriptor.*/
@@ -412,6 +415,16 @@
 		return r;
 	}
 
+	if (ext4_sb_feature_com(&mp->fs.sb,
+				EXT4_FCOM_HAS_JOURNAL)) {
+		r = jbd_get_fs(&mp->fs, &mp->jbd_fs);
+		ext4_assert(r == EOK);
+		r = jbd_journal_start(&mp->jbd_fs, &mp->jbd_journal);
+		ext4_assert(r == EOK);
+		mp->fs.jbd_fs = &mp->jbd_fs;
+		mp->fs.jbd_journal = &mp->jbd_journal;
+	}
+
 	return r;
 }
 
@@ -432,6 +445,16 @@
 	if (!mp)
 		return ENODEV;
 
+	if (ext4_sb_feature_com(&mp->fs.sb,
+				EXT4_FCOM_HAS_JOURNAL)) {
+		r = jbd_journal_stop(&mp->jbd_journal);
+		ext4_assert(r == EOK);
+		r = jbd_put_fs(&mp->jbd_fs);
+		ext4_assert(r == EOK);
+		mp->fs.jbd_journal = NULL;
+		mp->fs.jbd_fs = NULL;
+	}
+
 	r = ext4_fs_fini(&mp->fs);
 	if (r != EOK)
 		return r;
@@ -494,6 +517,46 @@
 	return r;
 }
 
+int ext4_trans_start(struct ext4_mountpoint *mp)
+{
+	int r = EOK;
+	if (mp->fs.jbd_journal) {
+		struct jbd_journal *journal = mp->fs.jbd_journal;
+		struct jbd_trans *trans;
+		trans = jbd_journal_new_trans(journal);
+		if (!trans) {
+			r = ENOMEM;
+			goto Finish;
+		}
+		mp->fs.curr_trans = trans;
+	}
+Finish:
+	return r;
+}
+
+int ext4_trans_stop(struct ext4_mountpoint *mp)
+{
+	int r = EOK;
+	if (mp->fs.jbd_journal) {
+		struct jbd_journal *journal = mp->fs.jbd_journal;
+		struct jbd_trans *trans = mp->fs.curr_trans;
+		r = jbd_journal_commit_trans(journal, trans);
+		mp->fs.curr_trans = NULL;
+	}
+	return r;
+}
+
+int ext4_trans_abort(struct ext4_mountpoint *mp)
+{
+	int r = EOK;
+	if (mp->fs.jbd_journal) {
+		struct jbd_journal *journal = mp->fs.jbd_journal;
+		struct jbd_trans *trans = mp->fs.curr_trans;
+		r = jbd_journal_commit_trans(journal, trans);
+		mp->fs.curr_trans = NULL;
+	}
+	return r;
+}
 
 int ext4_mount_point_stats(const char *mount_point,
 			   struct ext4_mount_stats *stats)
--- a/lwext4/ext4_types.h
+++ b/lwext4/ext4_types.h
@@ -306,6 +306,10 @@
 	uint64_t inode_blocks_per_level[4];
 
 	uint32_t last_inode_bg_id;
+
+	struct jbd_fs *jbd_fs;
+	struct jbd_journal *jbd_journal;
+	struct jbd_trans *curr_trans;
 };
 
 /* Inode table/bitmap not in use */