extern "C" {
#endif
-#include "ext4_config.h"
-#include "ext4_types.h"
+#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;
+};
+
+struct ext4_inode_ref {
+ struct ext4_block block;
+ struct ext4_inode *inode;
+ struct ext4_fs *fs;
+ uint32_t index;
+ bool dirty;
+};
+
+
/**@brief Convert block address to relative index in block group.
* @param sb Superblock pointer
* @param baddr Block number to convert
static inline uint32_t ext4_fs_addr_to_idx_bg(struct ext4_sblock *s,
ext4_fsblk_t baddr)
{
- if (ext4_get32(s, first_data_block))
+ if (ext4_get32(s, first_data_block) && baddr)
baddr--;
return baddr % ext4_get32(s, blocks_per_group);
/**@brief Initialize filesystem and read all needed data.
* @param fs Filesystem instance to be initialized
* @param bdev Identifier if device with the filesystem
+ * @param read_only Mark the filesystem as read-only.
* @return Error code
*/
-int ext4_fs_init(struct ext4_fs *fs, struct ext4_blockdev *bdev);
+int ext4_fs_init(struct ext4_fs *fs, struct ext4_blockdev *bdev,
+ bool read_only);
/**@brief Destroy filesystem instance (used by unmount operation).
* @param fs Filesystem to be destroyed
* @return Error code
*/
int ext4_fs_get_inode_dblk_idx(struct ext4_inode_ref *inode_ref,
- uint64_t iblock, ext4_fsblk_t *fblock,
+ ext4_lblk_t iblock, ext4_fsblk_t *fblock,
bool support_unwritten);
/**@brief Initialize a part of unwritten range of the inode.
* @return Error code
*/
int ext4_fs_init_inode_dblk_idx(struct ext4_inode_ref *inode_ref,
- uint64_t iblock, ext4_fsblk_t *fblock);
+ ext4_lblk_t iblock, ext4_fsblk_t *fblock);
/**@brief Append following logical block to the i-node.
* @param inode_ref I-node to append block to
* @return Error code
*/
int ext4_fs_append_inode_dblk(struct ext4_inode_ref *inode_ref,
- ext4_fsblk_t *fblock, uint32_t *iblock);
+ ext4_fsblk_t *fblock, ext4_lblk_t *iblock);
/**@brief Increment inode link count.
* @param inode none handle