Rename 'initialize_dir_tail' to 'ext4_dir_init_entry_tail'
[lwext4.git] / lwext4 / ext4_dir.h
index 6f61e3c2b38ca1e95e1bccd5b5154bcf9526eeed..a18b777ff10bfc44363ef43b1811e5271e07a6f1 100644 (file)
 #ifndef EXT4_DIR_H_
 #define EXT4_DIR_H_
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include "ext4_config.h"
 #include "ext4_types.h"
 #include "ext4_blockdev.h"
@@ -54,7 +58,7 @@
  * @return I-node number
  */
 static inline uint32_t
-ext4_dir_entry_ll_get_inode(struct ext4_directory_entry_ll *de)
+ext4_dir_entry_ll_get_inode(struct ext4_dir_entry_ll *de)
 {
        return to_le32(de->inode);
 }
@@ -64,7 +68,7 @@ ext4_dir_entry_ll_get_inode(struct ext4_directory_entry_ll *de)
  * @param inode I-node number
  */
 static inline void
-ext4_dir_entry_ll_set_inode(struct ext4_directory_entry_ll *de, uint32_t inode)
+ext4_dir_entry_ll_set_inode(struct ext4_dir_entry_ll *de, uint32_t inode)
 {
        de->inode = to_le32(inode);
 }
@@ -74,7 +78,7 @@ ext4_dir_entry_ll_set_inode(struct ext4_directory_entry_ll *de, uint32_t inode)
  * @param inode I-node number
  */
 static inline void
-ext4_dx_dot_entry_set_inode(struct ext4_directory_dx_dot_entry *de, uint32_t inode)
+ext4_dx_dot_entry_set_inode(struct ext4_dir_idx_dot_entry *de, uint32_t inode)
 {
        de->inode = to_le32(inode);
 }
@@ -84,7 +88,7 @@ ext4_dx_dot_entry_set_inode(struct ext4_directory_dx_dot_entry *de, uint32_t ino
  * @return Entry length
  */
 static inline uint16_t
-ext4_dir_entry_ll_get_entry_length(struct ext4_directory_entry_ll *de)
+ext4_dir_entry_ll_get_entry_length(struct ext4_dir_entry_ll *de)
 {
        return to_le16(de->entry_length);
 }
@@ -94,7 +98,7 @@ ext4_dir_entry_ll_get_entry_length(struct ext4_directory_entry_ll *de)
  * @param length Entry length
  */
 static inline void
-ext4_dir_entry_ll_set_entry_length(struct ext4_directory_entry_ll *de,
+ext4_dir_entry_ll_set_entry_length(struct ext4_dir_entry_ll *de,
                                   uint16_t len)
 {
        de->entry_length = to_le16(len);
@@ -107,7 +111,7 @@ ext4_dir_entry_ll_set_entry_length(struct ext4_directory_entry_ll *de,
  */
 static inline uint16_t
 ext4_dir_entry_ll_get_name_length(struct ext4_sblock *sb,
-                                 struct ext4_directory_entry_ll *de)
+                                 struct ext4_dir_entry_ll *de)
 {
        uint16_t v = de->name_length;
 
@@ -124,7 +128,7 @@ ext4_dir_entry_ll_get_name_length(struct ext4_sblock *sb,
  * @param length Entry name length
  */
 static inline void ext4_dir_entry_ll_set_name_length(
-    struct ext4_sblock *sb, struct ext4_directory_entry_ll *de, uint16_t len)
+    struct ext4_sblock *sb, struct ext4_dir_entry_ll *de, uint16_t len)
 {
        de->name_length = (len << 8) >> 8;
 
@@ -140,13 +144,13 @@ static inline void ext4_dir_entry_ll_set_name_length(
  */
 static inline uint8_t
 ext4_dir_entry_ll_get_inode_type(struct ext4_sblock *sb,
-                                struct ext4_directory_entry_ll *de)
+                                struct ext4_dir_entry_ll *de)
 {
        if ((ext4_get32(sb, rev_level) > 0) ||
            (ext4_get32(sb, minor_rev_level) >= 5))
                return de->in.inode_type;
 
-       return EXT4_DIRECTORY_FILETYPE_UNKNOWN;
+       return EXT4_DIRENTRY_UNKNOWN;
 }
 /**@brief Set i-node type of directory entry.
  * @param sb   Superblock
@@ -155,13 +159,22 @@ ext4_dir_entry_ll_get_inode_type(struct ext4_sblock *sb,
  */
 
 static inline void ext4_dir_entry_ll_set_inode_type(
-    struct ext4_sblock *sb, struct ext4_directory_entry_ll *de, uint8_t type)
+    struct ext4_sblock *sb, struct ext4_dir_entry_ll *de, uint8_t type)
 {
        if ((ext4_get32(sb, rev_level) > 0) ||
            (ext4_get32(sb, minor_rev_level) >= 5))
                de->in.inode_type = type;
 }
 
+/**@brief Verify checksum of a linear directory leaf block
+ * @param inode_ref Directory i-node
+ * @param dirent    Linear directory leaf block
+ * @return true means the block passed checksum verification
+ */
+bool
+ext4_dir_checksum_verify(struct ext4_inode_ref *inode_ref,
+                        struct ext4_dir_entry_ll *dirent);
+
 /**@brief Initialize directory iterator.
  * Set position to the first valid entry from the required position.
  * @param it        Pointer to iterator to be initialized
@@ -169,21 +182,21 @@ static inline void ext4_dir_entry_ll_set_inode_type(
  * @param pos       Position to start reading entries from
  * @return Error code
  */
-int ext4_dir_iterator_init(struct ext4_directory_iterator *it,
+int ext4_dir_iterator_init(struct ext4_dir_iterator *it,
                           struct ext4_inode_ref *inode_ref, uint64_t pos);
 
 /**@brief Jump to the next valid entry
  * @param it Initialized iterator
  * @return Error code
  */
-int ext4_dir_iterator_next(struct ext4_directory_iterator *it);
+int ext4_dir_iterator_next(struct ext4_dir_iterator *it);
 
 /**@brief Uninitialize directory iterator.
  *        Release all allocated structures.
  * @param it Iterator to be finished
  * @return Error code
  */
-int ext4_dir_iterator_fini(struct ext4_directory_iterator *it);
+int ext4_dir_iterator_fini(struct ext4_dir_iterator *it);
 
 /**@brief Write directory entry to concrete data block.
  * @param sb        Superblock
@@ -194,7 +207,7 @@ int ext4_dir_iterator_fini(struct ext4_directory_iterator *it);
  * @param name_len  Length of entry name
  */
 void ext4_dir_write_entry(struct ext4_sblock *sb,
-                         struct ext4_directory_entry_ll *entry,
+                         struct ext4_dir_entry_ll *entry,
                          uint16_t entry_len, struct ext4_inode_ref *child,
                          const char *name, size_t name_len);
 
@@ -214,7 +227,7 @@ int ext4_dir_add_entry(struct ext4_inode_ref *parent, const char *name,
  * @param name_len  Name length
  * @return Error code
  */
-int ext4_dir_find_entry(struct ext4_directory_search_result *result,
+int ext4_dir_find_entry(struct ext4_dir_search_result *result,
                        struct ext4_inode_ref *parent, const char *name,
                        uint32_t name_len);
 
@@ -229,6 +242,7 @@ int ext4_dir_remove_entry(struct ext4_inode_ref *parent, const char *name,
 
 /**@brief Try to insert entry to concrete data block.
  * @param sb           Superblock
+ * @param inode_ref     Directory i-node
  * @param target_block Block to try to insert entry to
  * @param child        Child i-node to be inserted by new entry
  * @param name         Name of the new entry
@@ -236,6 +250,7 @@ int ext4_dir_remove_entry(struct ext4_inode_ref *parent, const char *name,
  * @return Error code
  */
 int ext4_dir_try_insert_entry(struct ext4_sblock *sb,
+                             struct ext4_inode_ref *inode_ref,
                              struct ext4_block *target_block,
                              struct ext4_inode_ref *child, const char *name,
                              uint32_t name_len);
@@ -250,7 +265,7 @@ int ext4_dir_try_insert_entry(struct ext4_sblock *sb,
  */
 int ext4_dir_find_in_block(struct ext4_block *block, struct ext4_sblock *sb,
                           size_t name_len, const char *name,
-                          struct ext4_directory_entry_ll **res_entry);
+                          struct ext4_dir_entry_ll **res_entry);
 
 /**@brief Simple function to release allocated data from result.
  * @param parent Parent inode
@@ -259,7 +274,17 @@ int ext4_dir_find_in_block(struct ext4_block *block, struct ext4_sblock *sb,
  *
  */
 int ext4_dir_destroy_result(struct ext4_inode_ref *parent,
-                           struct ext4_directory_search_result *result);
+                           struct ext4_dir_search_result *result);
+
+void ext4_dir_set_checksum(struct ext4_inode_ref *inode_ref,
+                          struct ext4_dir_entry_ll *dirent);
+
+
+void ext4_dir_init_entry_tail(struct ext4_dir_entry_tail *t);
+
+#ifdef __cplusplus
+}
+#endif
 
 #endif /* EXT4_DIR_H_ */