shithub: lwext4

Download patch

ref: 252c506239ab570c0f671513a3b17d3a44f86b5c
parent: 3e42ad4c558d5f3e12cdf22f4d6610836c7df129
author: ngkaho1234 <ngkaho1234@gmail.com>
date: Sun Jan 31 17:31:05 EST 2016

Refactor header files dependencies.

--- a/include/ext4.h
+++ b/include/ext4.h
@@ -46,9 +46,11 @@
 #include <stddef.h>
 
 #include "ext4_config.h"
+#include "ext4_types.h"
 #include "ext4_errno.h"
 #include "ext4_oflags.h"
-#include "ext4_types.h"
+#include "ext4_debug.h"
+
 #include "ext4_blockdev.h"
 
 /********************************OS LOCK INFERFACE***************************/
--- a/include/ext4_balloc.h
+++ b/include/ext4_balloc.h
@@ -48,6 +48,8 @@
 #include "ext4_config.h"
 #include "ext4_types.h"
 
+#include "ext4_fs.h"
+
 #include <stdint.h>
 #include <stdbool.h>
 
--- a/include/ext4_blockdev.h
+++ b/include/ext4_blockdev.h
@@ -42,8 +42,6 @@
 
 #include "ext4_config.h"
 #include "ext4_bcache.h"
-#include "ext4_trans.h"
-#include "ext4_debug.h"
 
 #include <stdbool.h>
 #include <stdint.h>
--- a/include/ext4_dir.h
+++ b/include/ext4_dir.h
@@ -48,6 +48,7 @@
 
 #include "ext4_config.h"
 #include "ext4_types.h"
+#include "ext4_misc.h"
 #include "ext4_blockdev.h"
 #include "ext4_super.h"
 
--- a/include/ext4_dir_idx.h
+++ b/include/ext4_dir_idx.h
@@ -49,6 +49,9 @@
 #include "ext4_config.h"
 #include "ext4_types.h"
 
+#include "ext4_fs.h"
+#include "ext4_dir.h"
+
 #include <stdint.h>
 #include <stdbool.h>
 
--- a/include/ext4_extent.h
+++ b/include/ext4_extent.h
@@ -50,6 +50,23 @@
 #include "ext4_inode.h"
 
 
+/*
+ * Array of ext4_ext_path contains path to some extent.
+ * Creation/lookup routines use it for traversal/splitting/etc.
+ * Truncate uses it to simulate recursive walking.
+ */
+struct ext4_extent_path {
+	ext4_fsblk_t p_block;
+	struct ext4_block block;
+	int32_t depth;
+	int32_t maxdepth;
+	struct ext4_extent_header *header;
+	struct ext4_extent_index *index;
+	struct ext4_extent *extent;
+
+};
+
+
 /**@brief Get logical number of the block covered by extent.
  * @param extent Extent to load number from
  * @return Logical number of the first block covered by extent */
--- a/include/ext4_fs.h
+++ b/include/ext4_fs.h
@@ -48,9 +48,35 @@
 
 #include "ext4_config.h"
 #include "ext4_types.h"
+#include "ext4_misc.h"
 
 #include <stdint.h>
 #include <stdbool.h>
+
+struct ext4_fs {
+	bool read_only;
+
+	struct ext4_blockdev *bdev;
+	struct ext4_sblock sb;
+
+	uint64_t inode_block_limits[4];
+	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;
+};
+
+struct ext4_block_group_ref {
+	struct ext4_block block;
+	struct ext4_bgroup *block_group;
+	struct ext4_fs *fs;
+	uint32_t index;
+	bool dirty;
+};
+
 
 /**@brief Convert block address to relative index in block group.
  * @param sb Superblock pointer
--- a/include/ext4_hash.h
+++ b/include/ext4_hash.h
@@ -45,6 +45,14 @@
 
 #include <stdint.h>
 
+struct ext4_hash_info {
+	uint32_t hash;
+	uint32_t minor_hash;
+	uint32_t hash_version;
+	const uint32_t *seed;
+};
+
+
 /**@brief   Directory entry name hash function.
  * @param   name entry name
  * @param   len entry name length
--- a/include/ext4_inode.h
+++ b/include/ext4_inode.h
@@ -47,6 +47,7 @@
 #endif
 
 #include "ext4_config.h"
+#include "ext4_types.h"
 
 #include <stdint.h>
 
--- a/include/ext4_journal.h
+++ b/include/ext4_journal.h
@@ -43,6 +43,74 @@
 
 #include "ext4_config.h"
 #include "ext4_types.h"
+#include "misc/queue.h"
+#include "misc/tree.h"
+
+struct jbd_fs {
+	/* If journal block device is used, bdev will be non-null */
+	struct ext4_blockdev *bdev;
+	struct ext4_inode_ref inode_ref;
+	struct jbd_sb sb;
+
+	bool dirty;
+};
+
+struct jbd_buf {
+	uint64_t jbd_lba;
+	struct ext4_block block;
+	struct jbd_trans *trans;
+	struct jbd_block_rec *block_rec;
+	TAILQ_ENTRY(jbd_buf) buf_node;
+	TAILQ_ENTRY(jbd_buf) dirty_buf_node;
+};
+
+struct jbd_revoke_rec {
+	ext4_fsblk_t lba;
+	LIST_ENTRY(jbd_revoke_rec) revoke_node;
+};
+
+struct jbd_block_rec {
+	ext4_fsblk_t lba;
+	struct ext4_buf *buf;
+	struct jbd_trans *trans;
+	RB_ENTRY(jbd_block_rec) block_rec_node;
+	LIST_ENTRY(jbd_block_rec) tbrec_node;
+	TAILQ_HEAD(jbd_buf_dirty, jbd_buf) dirty_buf_queue;
+};
+
+struct jbd_trans {
+	uint32_t trans_id;
+
+	uint32_t start_iblock;
+	int alloc_blocks;
+	int data_cnt;
+	uint32_t data_csum;
+	int written_cnt;
+	int error;
+
+	struct jbd_journal *journal;
+
+	TAILQ_HEAD(jbd_trans_buf, jbd_buf) buf_queue;
+	LIST_HEAD(jbd_revoke_list, jbd_revoke_rec) revoke_list;
+	LIST_HEAD(jbd_trans_block_rec, jbd_block_rec) tbrec_list;
+	TAILQ_ENTRY(jbd_trans) trans_node;
+};
+
+struct jbd_journal {
+	uint32_t first;
+	uint32_t start;
+	uint32_t last;
+	uint32_t trans_id;
+	uint32_t alloc_trans_id;
+
+	uint32_t block_size;
+
+	TAILQ_HEAD(jbd_trans_queue, jbd_trans) trans_queue;
+	TAILQ_HEAD(jbd_cp_queue, jbd_trans) cp_queue;
+	RB_HEAD(jbd_block, jbd_block_rec) block_rec_root;
+
+	struct jbd_fs *jbd_fs;
+};
 
 int jbd_get_fs(struct ext4_fs *fs,
 	       struct jbd_fs *jbd_fs);
--- /dev/null
+++ b/include/ext4_misc.h
@@ -1,0 +1,151 @@
+/*
+ * Copyright (c) 2015 Grzegorz Kostka (kostka.grzegorz@gmail.com)
+ * Copyright (c) 2015 Kaho Ng (ngkaho1234@gmail.com)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup lwext4
+ * @{
+ */
+/**
+ * @file  ext4_misc.h
+ * @brief Miscellaneous helpers.
+ */
+
+#ifndef EXT4_MISC_H_
+#define EXT4_MISC_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+
+/****************************Endian conversion*****************/
+
+static inline uint64_t reorder64(uint64_t n)
+{
+	return  ((n & 0xff) << 56) |
+		((n & 0xff00) << 40) |
+		((n & 0xff0000) << 24) |
+		((n & 0xff000000LL) << 8) |
+		((n & 0xff00000000LL) >> 8) |
+		((n & 0xff0000000000LL) >> 24) |
+		((n & 0xff000000000000LL) >> 40) |
+		((n & 0xff00000000000000LL) >> 56);
+}
+
+static inline uint32_t reorder32(uint32_t n)
+{
+	return  ((n & 0xff) << 24) |
+		((n & 0xff00) << 8) |
+		((n & 0xff0000) >> 8) |
+		((n & 0xff000000) >> 24);
+}
+
+static inline uint16_t reorder16(uint16_t n)
+{
+	return  ((n & 0xff) << 8) |
+		((n & 0xff00) >> 8);
+}
+
+#ifdef CONFIG_BIG_ENDIAN
+#define to_le64(_n) reorder64(_n)
+#define to_le32(_n) reorder32(_n)
+#define to_le16(_n) reorder16(_n)
+
+#define to_be64(_n) _n
+#define to_be32(_n) _n
+#define to_be16(_n) _n
+
+#else
+#define to_le64(_n) _n
+#define to_le32(_n) _n
+#define to_le16(_n) _n
+
+#define to_be64(_n) reorder64(_n)
+#define to_be32(_n) reorder32(_n)
+#define to_be16(_n) reorder16(_n)
+#endif
+
+/****************************Access macros to ext4 structures*****************/
+
+#define ext4_get32(s, f) to_le32((s)->f)
+#define ext4_get16(s, f) to_le16((s)->f)
+#define ext4_get8(s, f) (s)->f
+
+#define ext4_set32(s, f, v)                                                    \
+	do {                                                                   \
+		(s)->f = to_le32(v);                                           \
+	} while (0)
+#define ext4_set16(s, f, v)                                                    \
+	do {                                                                   \
+		(s)->f = to_le16(v);                                           \
+	} while (0)
+#define ext4_set8                                                              \
+	(s, f, v) do { (s)->f = (v); }                                         \
+	while (0)
+
+/****************************Access macros to jbd2 structures*****************/
+
+#define jbd_get32(s, f) to_be32((s)->f)
+#define jbd_get16(s, f) to_be16((s)->f)
+#define jbd_get8(s, f) (s)->f
+
+#define jbd_set32(s, f, v)                                                    \
+	do {                                                                   \
+		(s)->f = to_be32(v);                                           \
+	} while (0)
+#define jbd_set16(s, f, v)                                                    \
+	do {                                                                   \
+		(s)->f = to_be16(v);                                           \
+	} while (0)
+#define jbd_set8                                                              \
+	(s, f, v) do { (s)->f = (v); }                                         \
+	while (0)
+
+#ifdef __GNUC__
+ #ifndef __unused
+ #define __unused __attribute__ ((__unused__))
+ #endif
+#else
+ #define __unused
+#endif
+
+#ifndef offsetof
+#define offsetof(type, field) 		\
+	((size_t)(&(((type *)0)->field)))
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* EXT4_MISC_H_ */
+
+/**
+ * @}
+ */
--- a/include/ext4_mkfs.h
+++ b/include/ext4_mkfs.h
@@ -43,12 +43,13 @@
 
 #include "ext4_config.h"
 #include "ext4_types.h"
+
 #include "ext4_blockdev.h"
+#include "ext4_fs.h"
 
 #include <stdbool.h>
 #include <stdint.h>
 
-
 struct ext4_mkfs_info {
 	uint64_t len;
 	uint32_t block_size;
@@ -65,6 +66,7 @@
 	uint8_t journal;
 	const char *label;
 };
+
 
 int ext4_mkfs_read_info(struct ext4_blockdev *bd, struct ext4_mkfs_info *info);
 
--- a/include/ext4_super.h
+++ b/include/ext4_super.h
@@ -48,6 +48,7 @@
 
 #include "ext4_config.h"
 #include "ext4_types.h"
+#include "ext4_misc.h"
 
 /**@brief   Blocks count get stored in superblock.
  * @param   s superblock descriptor
--- a/include/ext4_types.h
+++ b/include/ext4_types.h
@@ -53,6 +53,13 @@
 #include <stddef.h>
 #include <stdint.h>
 
+/*
+ * Types of blocks.
+ */
+typedef uint32_t ext4_lblk_t;
+typedef uint64_t ext4_fsblk_t;
+
+
 #define EXT4_CHECKSUM_CRC32C 1
 
 #define UUID_SIZE 16
@@ -302,22 +309,7 @@
                      EXT4_FRO_COM_QUOTA)
 #endif
 
-struct ext4_fs {
-	bool read_only;
 
-	struct ext4_blockdev *bdev;
-	struct ext4_sblock sb;
-
-	uint64_t inode_block_limits[4];
-	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 */
 #define EXT4_BLOCK_GROUP_INODE_UNINIT 0x0001
 /* Block bitmap not in use */
@@ -355,13 +347,6 @@
 	uint32_t reserved;	     /* Padding */
 };
 
-struct ext4_block_group_ref {
-	struct ext4_block block;
-	struct ext4_bgroup *block_group;
-	struct ext4_fs *fs;
-	uint32_t index;
-	bool dirty;
-};
 
 #define EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE 32
 #define EXT4_MAX_BLOCK_GROUP_DESCRIPTOR_SIZE 64
@@ -699,29 +684,6 @@
 #pragma pack(pop)
 
 
-/*
- * Types of blocks.
- */
-typedef uint32_t ext4_lblk_t;
-typedef uint64_t ext4_fsblk_t;
-
-/*
- * Array of ext4_ext_path contains path to some extent.
- * Creation/lookup routines use it for traversal/splitting/etc.
- * Truncate uses it to simulate recursive walking.
- */
-struct ext4_extent_path {
-	ext4_fsblk_t p_block;
-	struct ext4_block block;
-	int32_t depth;
-	int32_t maxdepth;
-	struct ext4_extent_header *header;
-	struct ext4_extent_index *index;
-	struct ext4_extent *extent;
-
-};
-
-
 #define EXT4_EXTENT_MAGIC 0xF30A
 
 #define EXT4_EXTENT_FIRST(header)                                              \
@@ -800,12 +762,6 @@
 
 #define EXT2_HTREE_EOF 0x7FFFFFFFUL
 
-struct ext4_hash_info {
-	uint32_t hash;
-	uint32_t minor_hash;
-	uint32_t hash_version;
-	const uint32_t *seed;
-};
 
 /* Extended Attribute(EA) */
 
@@ -853,38 +809,6 @@
 
 #pragma pack(pop)
 
-struct ext4_xattr_item {
-	/* This attribute should be stored in inode body */
-	bool in_inode;
-
-	uint8_t name_index;
-	char  *name;
-	size_t name_len;
-	void  *data;
-	size_t data_size;
-
-	RB_ENTRY(ext4_xattr_item) node;
-};
-
-struct ext4_xattr_ref {
-	bool block_loaded;
-	struct ext4_block block;
-	struct ext4_inode_ref *inode_ref;
-	bool   dirty;
-	size_t ea_size;
-	struct ext4_fs *fs;
-
-	void *iter_arg;
-	struct ext4_xattr_item *iter_from;
-
-	RB_HEAD(ext4_xattr_tree,
-		ext4_xattr_item) root;
-};
-
-#define EXT4_XATTR_ITERATE_CONT 0
-#define EXT4_XATTR_ITERATE_STOP 1
-#define EXT4_XATTR_ITERATE_PAUSE 2
-
 #define EXT4_GOOD_OLD_INODE_SIZE	128
 
 #define EXT4_XATTR_PAD_BITS		2
@@ -1129,171 +1053,11 @@
 					 JBD_FEATURE_INCOMPAT_CSUM_V2|\
 					 JBD_FEATURE_INCOMPAT_CSUM_V3)
 
-struct jbd_fs {
-	/* If journal block device is used, bdev will be non-null */
-	struct ext4_blockdev *bdev;
-	struct ext4_inode_ref inode_ref;
-	struct jbd_sb sb;
-
-	bool dirty;
-};
-
-struct jbd_buf {
-	uint64_t jbd_lba;
-	struct ext4_block block;
-	struct jbd_trans *trans;
-	struct jbd_block_rec *block_rec;
-	TAILQ_ENTRY(jbd_buf) buf_node;
-	TAILQ_ENTRY(jbd_buf) dirty_buf_node;
-};
-
-struct jbd_revoke_rec {
-	ext4_fsblk_t lba;
-	LIST_ENTRY(jbd_revoke_rec) revoke_node;
-};
-
-struct jbd_block_rec {
-	ext4_fsblk_t lba;
-	struct ext4_buf *buf;
-	struct jbd_trans *trans;
-	RB_ENTRY(jbd_block_rec) block_rec_node;
-	LIST_ENTRY(jbd_block_rec) tbrec_node;
-	TAILQ_HEAD(jbd_buf_dirty, jbd_buf) dirty_buf_queue;
-};
-
-struct jbd_trans {
-	uint32_t trans_id;
-
-	uint32_t start_iblock;
-	int alloc_blocks;
-	int data_cnt;
-	uint32_t data_csum;
-	int written_cnt;
-	int error;
-
-	struct jbd_journal *journal;
-
-	TAILQ_HEAD(jbd_trans_buf, jbd_buf) buf_queue;
-	LIST_HEAD(jbd_revoke_list, jbd_revoke_rec) revoke_list;
-	LIST_HEAD(jbd_trans_block_rec, jbd_block_rec) tbrec_list;
-	TAILQ_ENTRY(jbd_trans) trans_node;
-};
-
-struct jbd_journal {
-	uint32_t first;
-	uint32_t start;
-	uint32_t last;
-	uint32_t trans_id;
-	uint32_t alloc_trans_id;
-
-	uint32_t block_size;
-
-	TAILQ_HEAD(jbd_trans_queue, jbd_trans) trans_queue;
-	TAILQ_HEAD(jbd_cp_queue, jbd_trans) cp_queue;
-	RB_HEAD(jbd_block, jbd_block_rec) block_rec_root;
-
-	struct jbd_fs *jbd_fs;
-};
-
 /*****************************************************************************/
 
 #define EXT4_CRC32_INIT (0xFFFFFFFFUL)
 
 /*****************************************************************************/
-
-static inline uint64_t reorder64(uint64_t n)
-{
-	return  ((n & 0xff) << 56) |
-		((n & 0xff00) << 40) |
-		((n & 0xff0000) << 24) |
-		((n & 0xff000000LL) << 8) |
-		((n & 0xff00000000LL) >> 8) |
-		((n & 0xff0000000000LL) >> 24) |
-		((n & 0xff000000000000LL) >> 40) |
-		((n & 0xff00000000000000LL) >> 56);
-}
-
-static inline uint32_t reorder32(uint32_t n)
-{
-	return  ((n & 0xff) << 24) |
-		((n & 0xff00) << 8) |
-		((n & 0xff0000) >> 8) |
-		((n & 0xff000000) >> 24);
-}
-
-static inline uint16_t reorder16(uint16_t n)
-{
-	return  ((n & 0xff) << 8) |
-		((n & 0xff00) >> 8);
-}
-
-#ifdef CONFIG_BIG_ENDIAN
-#define to_le64(_n) reorder64(_n)
-#define to_le32(_n) reorder32(_n)
-#define to_le16(_n) reorder16(_n)
-
-#define to_be64(_n) _n
-#define to_be32(_n) _n
-#define to_be16(_n) _n
-
-#else
-#define to_le64(_n) _n
-#define to_le32(_n) _n
-#define to_le16(_n) _n
-
-#define to_be64(_n) reorder64(_n)
-#define to_be32(_n) reorder32(_n)
-#define to_be16(_n) reorder16(_n)
-#endif
-
-/****************************Access macros to ext4 structures*****************/
-
-#define ext4_get32(s, f) to_le32((s)->f)
-#define ext4_get16(s, f) to_le16((s)->f)
-#define ext4_get8(s, f) (s)->f
-
-#define ext4_set32(s, f, v)                                                    \
-	do {                                                                   \
-		(s)->f = to_le32(v);                                           \
-	} while (0)
-#define ext4_set16(s, f, v)                                                    \
-	do {                                                                   \
-		(s)->f = to_le16(v);                                           \
-	} while (0)
-#define ext4_set8                                                              \
-	(s, f, v) do { (s)->f = (v); }                                         \
-	while (0)
-
-/****************************Access macros to jbd2 structures*****************/
-
-#define jbd_get32(s, f) to_be32((s)->f)
-#define jbd_get16(s, f) to_be16((s)->f)
-#define jbd_get8(s, f) (s)->f
-
-#define jbd_set32(s, f, v)                                                    \
-	do {                                                                   \
-		(s)->f = to_be32(v);                                           \
-	} while (0)
-#define jbd_set16(s, f, v)                                                    \
-	do {                                                                   \
-		(s)->f = to_be16(v);                                           \
-	} while (0)
-#define jbd_set8                                                              \
-	(s, f, v) do { (s)->f = (v); }                                         \
-	while (0)
-
-#ifdef __GNUC__
- #ifndef __unused
- #define __unused __attribute__ ((__unused__))
- #endif
-#else
- #define __unused
-#endif
-
-#ifndef offsetof
-#define offsetof(type, field) 		\
-	((size_t)(&(((type *)0)->field)))
-#endif
 
 #ifdef __cplusplus
 }
--- a/include/ext4_xattr.h
+++ b/include/ext4_xattr.h
@@ -43,6 +43,40 @@
 
 #include "ext4_config.h"
 #include "ext4_types.h"
+#include "misc/tree.h"
+#include "misc/queue.h"
+
+struct ext4_xattr_item {
+	/* This attribute should be stored in inode body */
+	bool in_inode;
+
+	uint8_t name_index;
+	char  *name;
+	size_t name_len;
+	void  *data;
+	size_t data_size;
+
+	RB_ENTRY(ext4_xattr_item) node;
+};
+
+struct ext4_xattr_ref {
+	bool block_loaded;
+	struct ext4_block block;
+	struct ext4_inode_ref *inode_ref;
+	bool   dirty;
+	size_t ea_size;
+	struct ext4_fs *fs;
+
+	void *iter_arg;
+	struct ext4_xattr_item *iter_from;
+
+	RB_HEAD(ext4_xattr_tree,
+		ext4_xattr_item) root;
+};
+
+#define EXT4_XATTR_ITERATE_CONT 0
+#define EXT4_XATTR_ITERATE_STOP 1
+#define EXT4_XATTR_ITERATE_PAUSE 2
 
 int ext4_fs_get_xattr_ref(struct ext4_fs *fs, struct ext4_inode_ref *inode_ref,
 			  struct ext4_xattr_ref *ref);
--- a/src/ext4.c
+++ b/src/ext4.c
@@ -35,11 +35,15 @@
  */
 
 #include "ext4_config.h"
-#include "ext4.h"
-#include "ext4_blockdev.h"
 #include "ext4_types.h"
-#include "ext4_debug.h"
+#include "ext4_misc.h"
 #include "ext4_errno.h"
+#include "ext4_oflags.h"
+#include "ext4_debug.h"
+
+#include "ext4.h"
+#include "ext4_trans.h"
+#include "ext4_blockdev.h"
 #include "ext4_fs.h"
 #include "ext4_dir.h"
 #include "ext4_inode.h"
--- a/src/ext4_balloc.c
+++ b/src/ext4_balloc.c
@@ -39,6 +39,12 @@
  */
 
 #include "ext4_config.h"
+#include "ext4_types.h"
+#include "ext4_misc.h"
+#include "ext4_errno.h"
+#include "ext4_debug.h"
+
+#include "ext4_trans.h"
 #include "ext4_balloc.h"
 #include "ext4_super.h"
 #include "ext4_crc32.h"
--- a/src/ext4_bitmap.c
+++ b/src/ext4_bitmap.c
@@ -35,9 +35,12 @@
  */
 
 #include "ext4_config.h"
-#include "ext4_bitmap.h"
-
+#include "ext4_types.h"
+#include "ext4_misc.h"
 #include "ext4_errno.h"
+#include "ext4_debug.h"
+
+#include "ext4_bitmap.h"
 
 void ext4_bmap_bits_free(uint8_t *bmap, uint32_t sbit, uint32_t bcnt)
 {
--- a/src/ext4_block_group.c
+++ b/src/ext4_block_group.c
@@ -40,6 +40,11 @@
  */
 
 #include "ext4_config.h"
+#include "ext4_types.h"
+#include "ext4_misc.h"
+#include "ext4_errno.h"
+#include "ext4_debug.h"
+
 #include "ext4_block_group.h"
 
 /**@brief CRC-16 look up table*/
--- a/src/ext4_blockdev.c
+++ b/src/ext4_blockdev.c
@@ -35,9 +35,12 @@
  */
 
 #include "ext4_config.h"
-#include "ext4_blockdev.h"
+#include "ext4_types.h"
+#include "ext4_misc.h"
 #include "ext4_errno.h"
 #include "ext4_debug.h"
+
+#include "ext4_blockdev.h"
 
 #include <string.h>
 #include <stdlib.h>
--- a/src/ext4_crc32.c
+++ b/src/ext4_crc32.c
@@ -37,6 +37,11 @@
  */
 
 #include "ext4_config.h"
+#include "ext4_types.h"
+#include "ext4_misc.h"
+#include "ext4_errno.h"
+#include "ext4_debug.h"
+
 #include "ext4_crc32.h"
 
 static const uint32_t crc32_tab[] = {
--- a/src/ext4_debug.c
+++ b/src/ext4_debug.c
@@ -35,6 +35,9 @@
  */
 
 #include "ext4_config.h"
+#include "ext4_types.h"
+#include "ext4_misc.h"
+#include "ext4_errno.h"
 #include "ext4_debug.h"
 
 #include <stdarg.h>
--- a/src/ext4_dir.c
+++ b/src/ext4_dir.c
@@ -40,6 +40,12 @@
  */
 
 #include "ext4_config.h"
+#include "ext4_types.h"
+#include "ext4_misc.h"
+#include "ext4_errno.h"
+#include "ext4_debug.h"
+
+#include "ext4_trans.h"
 #include "ext4_dir.h"
 #include "ext4_dir_idx.h"
 #include "ext4_crc32.h"
--- a/src/ext4_dir_idx.c
+++ b/src/ext4_dir_idx.c
@@ -35,6 +35,12 @@
  */
 
 #include "ext4_config.h"
+#include "ext4_types.h"
+#include "ext4_misc.h"
+#include "ext4_errno.h"
+#include "ext4_debug.h"
+
+#include "ext4_trans.h"
 #include "ext4_dir_idx.h"
 #include "ext4_dir.h"
 #include "ext4_blockdev.h"
--- a/src/ext4_extent.c
+++ b/src/ext4_extent.c
@@ -27,12 +27,18 @@
  */
 
 #include "ext4_config.h"
+#include "ext4_types.h"
+#include "ext4_misc.h"
+#include "ext4_errno.h"
+#include "ext4_debug.h"
+
 #include "ext4_blockdev.h"
+#include "ext4_trans.h"
 #include "ext4_fs.h"
 #include "ext4_super.h"
 #include "ext4_crc32.h"
 #include "ext4_balloc.h"
-#include "ext4_debug.h"
+#include "ext4_extent.h"
 
 #include <stdlib.h>
 #include <string.h>
@@ -39,7 +45,6 @@
 #include <inttypes.h>
 #include <stddef.h>
 
-#include "ext4_extent.h"
 
 /*
  * used by extent splitting.
--- a/src/ext4_fs.c
+++ b/src/ext4_fs.c
@@ -40,12 +40,15 @@
 
 #include "ext4_config.h"
 #include "ext4_types.h"
-#include "ext4_fs.h"
+#include "ext4_misc.h"
 #include "ext4_errno.h"
+#include "ext4_debug.h"
+
+#include "ext4_trans.h"
+#include "ext4_fs.h"
 #include "ext4_blockdev.h"
 #include "ext4_super.h"
 #include "ext4_crc32.h"
-#include "ext4_debug.h"
 #include "ext4_block_group.h"
 #include "ext4_balloc.h"
 #include "ext4_bitmap.h"
--- a/src/ext4_hash.c
+++ b/src/ext4_hash.c
@@ -63,7 +63,9 @@
 
 #include "ext4_config.h"
 #include "ext4_types.h"
+#include "ext4_misc.h"
 #include "ext4_errno.h"
+#include "ext4_debug.h"
 
 #include <string.h>
 
--- a/src/ext4_ialloc.c
+++ b/src/ext4_ialloc.c
@@ -41,6 +41,11 @@
 
 #include "ext4_config.h"
 #include "ext4_types.h"
+#include "ext4_misc.h"
+#include "ext4_errno.h"
+#include "ext4_debug.h"
+
+#include "ext4_trans.h"
 #include "ext4_ialloc.h"
 #include "ext4_super.h"
 #include "ext4_crc32.h"
--- a/src/ext4_inode.c
+++ b/src/ext4_inode.c
@@ -41,6 +41,10 @@
 
 #include "ext4_config.h"
 #include "ext4_types.h"
+#include "ext4_misc.h"
+#include "ext4_errno.h"
+#include "ext4_debug.h"
+
 #include "ext4_inode.h"
 #include "ext4_super.h"
 
--- a/src/ext4_journal.c
+++ b/src/ext4_journal.c
@@ -37,13 +37,16 @@
 
 #include "ext4_config.h"
 #include "ext4_types.h"
+#include "ext4_misc.h"
+#include "ext4_errno.h"
+#include "ext4_debug.h"
+
 #include "ext4_fs.h"
 #include "ext4_super.h"
 #include "ext4_journal.h"
-#include "ext4_errno.h"
 #include "ext4_blockdev.h"
 #include "ext4_crc32.h"
-#include "ext4_debug.h"
+#include "ext4_journal.h"
 
 #include <string.h>
 #include <stdlib.h>
--- a/src/ext4_mbr.c
+++ b/src/ext4_mbr.c
@@ -36,7 +36,10 @@
 
 #include "ext4_config.h"
 #include "ext4_types.h"
+#include "ext4_misc.h"
+#include "ext4_errno.h"
 #include "ext4_debug.h"
+
 #include "ext4_mbr.h"
 
 #include <inttypes.h>
--- a/src/ext4_mkfs.c
+++ b/src/ext4_mkfs.c
@@ -35,6 +35,11 @@
  */
 
 #include "ext4_config.h"
+#include "ext4_types.h"
+#include "ext4_misc.h"
+#include "ext4_errno.h"
+#include "ext4_debug.h"
+
 #include "ext4_super.h"
 #include "ext4_block_group.h"
 #include "ext4_dir.h"
@@ -41,7 +46,6 @@
 #include "ext4_dir_idx.h"
 #include "ext4_fs.h"
 #include "ext4_inode.h"
-#include "ext4_debug.h"
 #include "ext4_ialloc.h"
 #include "ext4_mkfs.h"
 
--- a/src/ext4_super.c
+++ b/src/ext4_super.c
@@ -40,6 +40,11 @@
  */
 
 #include "ext4_config.h"
+#include "ext4_types.h"
+#include "ext4_misc.h"
+#include "ext4_errno.h"
+#include "ext4_debug.h"
+
 #include "ext4_super.h"
 #include "ext4_crc32.h"
 
--- a/src/ext4_trans.c
+++ b/src/ext4_trans.c
@@ -37,6 +37,11 @@
 
 #include "ext4_config.h"
 #include "ext4_types.h"
+#include "ext4_misc.h"
+#include "ext4_errno.h"
+#include "ext4_debug.h"
+
+#include "ext4_fs.h"
 #include "ext4_journal.h"
 
 static int ext4_trans_get_write_access(struct ext4_fs *fs __unused,
--- a/src/ext4_xattr.c
+++ b/src/ext4_xattr.c
@@ -36,12 +36,16 @@
 
 #include "ext4_config.h"
 #include "ext4_types.h"
-#include "ext4_fs.h"
+#include "ext4_misc.h"
 #include "ext4_errno.h"
+#include "ext4_debug.h"
+
+#include "ext4_fs.h"
+#include "ext4_trans.h"
+#include "ext4_xattr.h"
 #include "ext4_blockdev.h"
 #include "ext4_super.h"
 #include "ext4_crc32.h"
-#include "ext4_debug.h"
 #include "ext4_block_group.h"
 #include "ext4_balloc.h"
 #include "ext4_inode.h"