ext4_dir: fix non existing entry creation issue
[lwext4.git] / include / ext4_fs.h
index ba55da9c0392bbecc8a1127cfb6924cbd7570814..c52032681816106d874161b07941debfb35c220e 100644 (file)
@@ -46,9 +46,9 @@
 extern "C" {
 #endif
 
-#include "ext4_config.h"
-#include "ext4_types.h"
-#include "ext4_misc.h"
+#include <ext4_config.h>
+#include <ext4_types.h>
+#include <ext4_misc.h>
 
 #include <stdint.h>
 #include <stdbool.h>
@@ -77,6 +77,14 @@ struct ext4_block_group_ref {
        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
@@ -86,7 +94,7 @@ struct ext4_block_group_ref {
 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);
@@ -230,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.
@@ -240,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
@@ -249,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