ext4_dir: fix non existing entry creation issue
[lwext4.git] / include / ext4_fs.h
index 97e1d1d5408bd1e44de887ae9f9fea32548cb5cd..c52032681816106d874161b07941debfb35c220e 100644 (file)
 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
@@ -60,7 +94,7 @@ extern "C" {
 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);
@@ -93,9 +127,11 @@ static inline ext4_fsblk_t ext4_fs_first_bg_block_no(struct ext4_sblock *s,
 /**@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
@@ -202,7 +238,7 @@ int ext4_fs_indirect_find_goal(struct ext4_inode_ref *inode_ref,
  * @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.
@@ -212,7 +248,7 @@ int ext4_fs_get_inode_dblk_idx(struct ext4_inode_ref *inode_ref,
  * @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
@@ -221,7 +257,7 @@ int ext4_fs_init_inode_dblk_idx(struct ext4_inode_ref *inode_ref,
  * @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