clang-format: ext4_dir
authorgkostka <kostka.grzegorz@gmail.com>
Tue, 16 Jun 2015 09:03:39 +0000 (10:03 +0100)
committergkostka <kostka.grzegorz@gmail.com>
Tue, 16 Jun 2015 11:14:43 +0000 (13:14 +0200)
lwext4/ext4_dir.c

index eabfa8dcfeb92921ac38559e24dc0b09caab8efc..cb15299672f737544eadadb45d915d5745f4371c 100644 (file)
@@ -47,8 +47,6 @@
 \r
 #include <string.h>\r
 \r
-\r
-\r
 /****************************************************************************/\r
 \r
 /**@brief Do some checks before returning iterator.\r
@@ -57,7 +55,7 @@
  * @return Error code\r
  */\r
 static int ext4_dir_iterator_set(struct ext4_directory_iterator *it,\r
-    uint32_t block_size)\r
+                                 uint32_t block_size)\r
 {\r
     it->current = NULL;\r
 \r
@@ -72,7 +70,7 @@ static int ext4_dir_iterator_set(struct ext4_directory_iterator *it,
         return EIO;\r
 \r
     struct ext4_directory_entry_ll *entry =\r
-            (void *)(it->current_block.data + offset_in_block);\r
+        (void *)(it->current_block.data + offset_in_block);\r
 \r
     /* Ensure that the whole entry does not overflow the block */\r
     uint16_t length = ext4_dir_entry_ll_get_entry_length(entry);\r
@@ -80,8 +78,8 @@ static int ext4_dir_iterator_set(struct ext4_directory_iterator *it,
         return EIO;\r
 \r
     /* Ensure the name length is not too large */\r
-    if (ext4_dir_entry_ll_get_name_length(\r
-            &it->inode_ref->fs->sb, entry) > length-8)\r
+    if (ext4_dir_entry_ll_get_name_length(&it->inode_ref->fs->sb, entry) >\r
+        length - 8)\r
         return EIO;\r
 \r
     /* Everything OK - "publish" the entry */\r
@@ -96,10 +94,10 @@ static int ext4_dir_iterator_set(struct ext4_directory_iterator *it,
  * @return Error code\r
  */\r
 static int ext4_dir_iterator_seek(struct ext4_directory_iterator *it,\r
-    uint64_t pos)\r
+                                  uint64_t pos)\r
 {\r
-    uint64_t size = ext4_inode_get_size(&it->inode_ref->fs->sb,\r
-            it->inode_ref->inode);\r
+    uint64_t size =\r
+        ext4_inode_get_size(&it->inode_ref->fs->sb, it->inode_ref->inode);\r
 \r
     /* The iterator is not valid until we seek to the desired position */\r
     it->current = NULL;\r
@@ -108,8 +106,8 @@ static int ext4_dir_iterator_seek(struct ext4_directory_iterator *it,
     if (pos >= size) {\r
         if (it->current_block.lb_id) {\r
 \r
-            int rc = ext4_block_set(it->inode_ref->fs->bdev,\r
-                    &it->current_block);\r
+            int rc =\r
+                ext4_block_set(it->inode_ref->fs->bdev, &it->current_block);\r
             it->current_block.lb_id = 0;\r
 \r
             if (rc != EOK)\r
@@ -121,8 +119,7 @@ static int ext4_dir_iterator_seek(struct ext4_directory_iterator *it,
     }\r
 \r
     /* Compute next block address */\r
-    uint32_t block_size =\r
-            ext4_sb_get_block_size(&it->inode_ref->fs->sb);\r
+    uint32_t block_size = ext4_sb_get_block_size(&it->inode_ref->fs->sb);\r
     uint64_t current_block_idx = it->current_offset / block_size;\r
     uint64_t next_block_idx = pos / block_size;\r
 \r
@@ -131,9 +128,10 @@ static int ext4_dir_iterator_seek(struct ext4_directory_iterator *it,
      * we need to get another block\r
      */\r
     if ((it->current_block.lb_id == 0) ||\r
-            (current_block_idx != next_block_idx)) {\r
+        (current_block_idx != next_block_idx)) {\r
         if (it->current_block.lb_id) {\r
-            int rc = ext4_block_set(it->inode_ref->fs->bdev, &it->current_block);\r
+            int rc =\r
+                ext4_block_set(it->inode_ref->fs->bdev, &it->current_block);\r
             it->current_block.lb_id = 0;\r
 \r
             if (rc != EOK)\r
@@ -141,14 +139,13 @@ static int ext4_dir_iterator_seek(struct ext4_directory_iterator *it,
         }\r
 \r
         uint32_t next_block_phys_idx;\r
-        int rc = ext4_fs_get_inode_data_block_index(it->inode_ref,\r
-                next_block_idx, &next_block_phys_idx);\r
+        int rc = ext4_fs_get_inode_data_block_index(\r
+            it->inode_ref, next_block_idx, &next_block_phys_idx);\r
         if (rc != EOK)\r
             return rc;\r
 \r
-\r
         rc = ext4_block_get(it->inode_ref->fs->bdev, &it->current_block,\r
-                next_block_phys_idx);\r
+                            next_block_phys_idx);\r
         if (rc != EOK) {\r
             it->current_block.lb_id = 0;\r
             return rc;\r
@@ -160,9 +157,8 @@ static int ext4_dir_iterator_seek(struct ext4_directory_iterator *it,
     return ext4_dir_iterator_set(it, block_size);\r
 }\r
 \r
-\r
 int ext4_dir_iterator_init(struct ext4_directory_iterator *it,\r
-    struct ext4_inode_ref *inode_ref, uint64_t pos)\r
+                           struct ext4_inode_ref *inode_ref, uint64_t pos)\r
 {\r
     it->inode_ref = inode_ref;\r
     it->current = 0;\r
@@ -177,14 +173,14 @@ int ext4_dir_iterator_next(struct ext4_directory_iterator *it)
     int r = EOK;\r
     uint16_t skip;\r
 \r
-    while(r == EOK){\r
+    while (r == EOK) {\r
         skip = ext4_dir_entry_ll_get_entry_length(it->current);\r
         r = ext4_dir_iterator_seek(it, it->current_offset + skip);\r
 \r
-        if(!it->current)\r
+        if (!it->current)\r
             break;\r
         /*Skip NULL referenced entry*/\r
-        if(it->current->inode != 0)\r
+        if (it->current->inode != 0)\r
             break;\r
     }\r
 \r
@@ -202,8 +198,9 @@ int ext4_dir_iterator_fini(struct ext4_directory_iterator *it)
 }\r
 \r
 void ext4_dir_write_entry(struct ext4_sblock *sb,\r
-    struct ext4_directory_entry_ll *entry, uint16_t entry_len,\r
-    struct ext4_inode_ref *child,  const char *name, size_t name_len)\r
+                          struct ext4_directory_entry_ll *entry,\r
+                          uint16_t entry_len, struct ext4_inode_ref *child,\r
+                          const char *name, size_t name_len)\r
 {\r
     /* Check maximum entry length */\r
     ext4_assert(entry_len <= ext4_sb_get_block_size(sb));\r
@@ -219,22 +216,22 @@ void ext4_dir_write_entry(struct ext4_sblock *sb,
     /* Set type of entry */\r
     if (ext4_inode_is_type(sb, child->inode, EXT4_INODE_MODE_DIRECTORY))\r
         ext4_dir_entry_ll_set_inode_type(sb, entry,\r
-                EXT4_DIRECTORY_FILETYPE_DIR);\r
+                                         EXT4_DIRECTORY_FILETYPE_DIR);\r
     else\r
         ext4_dir_entry_ll_set_inode_type(sb, entry,\r
-                EXT4_DIRECTORY_FILETYPE_REG_FILE);\r
+                                         EXT4_DIRECTORY_FILETYPE_REG_FILE);\r
 }\r
 \r
 int ext4_dir_add_entry(struct ext4_inode_ref *parent, const char *name,\r
-    uint32_t name_len, struct ext4_inode_ref *child)\r
+                       uint32_t name_len, struct ext4_inode_ref *child)\r
 {\r
     struct ext4_fs *fs = parent->fs;\r
 \r
 #if CONFIG_DIR_INDEX_ENABLE\r
     /* Index adding (if allowed) */\r
     if ((ext4_sb_has_feature_compatible(&fs->sb,\r
-            EXT4_FEATURE_COMPAT_DIR_INDEX)) &&\r
-            (ext4_inode_has_flag(parent->inode, EXT4_INODE_FLAG_INDEX))) {\r
+                                        EXT4_FEATURE_COMPAT_DIR_INDEX)) &&\r
+        (ext4_inode_has_flag(parent->inode, EXT4_INODE_FLAG_INDEX))) {\r
         int rc = ext4_dir_dx_add_entry(parent, child, name);\r
 \r
         /* Check if index is not corrupted */\r
@@ -258,24 +255,20 @@ int ext4_dir_add_entry(struct ext4_inode_ref *parent, const char *name,
     uint32_t inode_size = ext4_inode_get_size(&fs->sb, parent->inode);\r
     uint32_t total_blocks = inode_size / block_size;\r
 \r
-\r
     /* Find block, where is space for new entry and try to add */\r
     bool success = false;\r
     for (iblock = 0; iblock < total_blocks; ++iblock) {\r
-        int rc = ext4_fs_get_inode_data_block_index(parent,\r
-                iblock, &fblock);\r
+        int rc = ext4_fs_get_inode_data_block_index(parent, iblock, &fblock);\r
         if (rc != EOK)\r
             return rc;\r
 \r
-\r
         struct ext4_block block;\r
         rc = ext4_block_get(fs->bdev, &block, fblock);\r
         if (rc != EOK)\r
             return rc;\r
 \r
         /* If adding is successful, function can finish */\r
-        rc = ext4_dir_try_insert_entry(&fs->sb, &block,\r
-                child, name, name_len);\r
+        rc = ext4_dir_try_insert_entry(&fs->sb, &block, child, name, name_len);\r
         if (rc == EOK)\r
             success = true;\r
 \r
@@ -305,8 +298,8 @@ int ext4_dir_add_entry(struct ext4_inode_ref *parent, const char *name,
     /* Fill block with zeroes */\r
     memset(new_block.data, 0, block_size);\r
     struct ext4_directory_entry_ll *block_entry = (void *)new_block.data;\r
-    ext4_dir_write_entry(&fs->sb, block_entry, block_size,\r
-        child, name, name_len);\r
+    ext4_dir_write_entry(&fs->sb, block_entry, block_size, child, name,\r
+                         name_len);\r
 \r
     /* Save new block */\r
     new_block.dirty = true;\r
@@ -316,18 +309,16 @@ int ext4_dir_add_entry(struct ext4_inode_ref *parent, const char *name,
 }\r
 \r
 int ext4_dir_find_entry(struct ext4_directory_search_result *result,\r
-    struct ext4_inode_ref *parent, const char *name, uint32_t name_len)\r
+                        struct ext4_inode_ref *parent, const char *name,\r
+                        uint32_t name_len)\r
 {\r
     struct ext4_sblock *sb = &parent->fs->sb;\r
 \r
-\r
 #if CONFIG_DIR_INDEX_ENABLE\r
     /* Index search */\r
-    if ((ext4_sb_has_feature_compatible(sb,\r
-            EXT4_FEATURE_COMPAT_DIR_INDEX)) &&\r
-            (ext4_inode_has_flag(parent->inode, EXT4_INODE_FLAG_INDEX))) {\r
-        int rc = ext4_dir_dx_find_entry(result, parent, name_len,\r
-                name);\r
+    if ((ext4_sb_has_feature_compatible(sb, EXT4_FEATURE_COMPAT_DIR_INDEX)) &&\r
+        (ext4_inode_has_flag(parent->inode, EXT4_INODE_FLAG_INDEX))) {\r
+        int rc = ext4_dir_dx_find_entry(result, parent, name_len, name);\r
 \r
         /* Check if index is not corrupted */\r
         if (rc != EXT4_ERR_BAD_DX_DIR) {\r
@@ -354,21 +345,19 @@ int ext4_dir_find_entry(struct ext4_directory_search_result *result,
     /* Walk through all data blocks */\r
     for (iblock = 0; iblock < total_blocks; ++iblock) {\r
         /* Load block address */\r
-        int rc = ext4_fs_get_inode_data_block_index(parent, iblock,\r
-                &fblock);\r
+        int rc = ext4_fs_get_inode_data_block_index(parent, iblock, &fblock);\r
         if (rc != EOK)\r
             return rc;\r
 \r
         /* Load data block */\r
         struct ext4_block block;\r
-        rc = ext4_block_get( parent->fs->bdev, &block, fblock);\r
+        rc = ext4_block_get(parent->fs->bdev, &block, fblock);\r
         if (rc != EOK)\r
             return rc;\r
 \r
         /* Try to find entry in block */\r
         struct ext4_directory_entry_ll *res_entry;\r
-        rc = ext4_dir_find_in_block(&block, sb, name_len, name,\r
-                &res_entry);\r
+        rc = ext4_dir_find_in_block(&block, sb, name_len, name, &res_entry);\r
         if (rc == EOK) {\r
             result->block = block;\r
             result->dentry = res_entry;\r
@@ -391,11 +380,11 @@ int ext4_dir_find_entry(struct ext4_directory_search_result *result,
 }\r
 \r
 int ext4_dir_remove_entry(struct ext4_inode_ref *parent, const char *name,\r
-    uint32_t name_len)\r
+                          uint32_t name_len)\r
 {\r
     /* Check if removing from directory */\r
     if (!ext4_inode_is_type(&parent->fs->sb, parent->inode,\r
-            EXT4_INODE_MODE_DIRECTORY))\r
+                            EXT4_INODE_MODE_DIRECTORY))\r
         return ENOTDIR;\r
 \r
     /* Try to find entry */\r
@@ -408,7 +397,7 @@ int ext4_dir_remove_entry(struct ext4_inode_ref *parent, const char *name,
     ext4_dir_entry_ll_set_inode(result.dentry, 0);\r
 \r
     /* Store entry position in block */\r
-    uint32_t pos = (uint8_t *) result.dentry - result.block.data;\r
+    uint32_t pos = (uint8_t *)result.dentry - result.block.data;\r
 \r
     /*\r
      * If entry is not the first in block, it must be merged\r
@@ -420,24 +409,22 @@ int ext4_dir_remove_entry(struct ext4_inode_ref *parent, const char *name,
         /* Start from the first entry in block */\r
         struct ext4_directory_entry_ll *tmp_dentry = (void *)result.block.data;\r
         uint16_t tmp_dentry_length =\r
-                ext4_dir_entry_ll_get_entry_length(tmp_dentry);\r
+            ext4_dir_entry_ll_get_entry_length(tmp_dentry);\r
 \r
         /* Find direct predecessor of removed entry */\r
         while ((offset + tmp_dentry_length) < pos) {\r
-            offset +=\r
-                    ext4_dir_entry_ll_get_entry_length(tmp_dentry);\r
+            offset += ext4_dir_entry_ll_get_entry_length(tmp_dentry);\r
             tmp_dentry = (void *)(result.block.data + offset);\r
-            tmp_dentry_length =\r
-                    ext4_dir_entry_ll_get_entry_length(tmp_dentry);\r
+            tmp_dentry_length = ext4_dir_entry_ll_get_entry_length(tmp_dentry);\r
         }\r
 \r
         ext4_assert(tmp_dentry_length + offset == pos);\r
 \r
         /* Add to removed entry length to predecessor's length */\r
         uint16_t del_entry_length =\r
-                ext4_dir_entry_ll_get_entry_length(result.dentry);\r
-        ext4_dir_entry_ll_set_entry_length(tmp_dentry,\r
-            tmp_dentry_length + del_entry_length);\r
+            ext4_dir_entry_ll_get_entry_length(result.dentry);\r
+        ext4_dir_entry_ll_set_entry_length(tmp_dentry, tmp_dentry_length +\r
+                                                           del_entry_length);\r
     }\r
 \r
     result.block.dirty = true;\r
@@ -446,8 +433,9 @@ int ext4_dir_remove_entry(struct ext4_inode_ref *parent, const char *name,
 }\r
 \r
 int ext4_dir_try_insert_entry(struct ext4_sblock *sb,\r
-    struct ext4_block *target_block, struct ext4_inode_ref *child,\r
-    const char *name, uint32_t name_len)\r
+                              struct ext4_block *target_block,\r
+                              struct ext4_inode_ref *child, const char *name,\r
+                              uint32_t name_len)\r
 {\r
     /* Compute required length entry and align it to 4 bytes */\r
     uint32_t block_size = ext4_sb_get_block_size(sb);\r
@@ -457,9 +445,9 @@ int ext4_dir_try_insert_entry(struct ext4_sblock *sb,
         required_len += 4 - (required_len % 4);\r
 \r
     /* Initialize pointers, stop means to upper bound */\r
-    struct ext4_directory_entry_ll *dentry  = (void *)target_block->data;\r
+    struct ext4_directory_entry_ll *dentry = (void *)target_block->data;\r
     struct ext4_directory_entry_ll *stop =\r
-            (void *)(target_block->data + block_size);\r
+        (void *)(target_block->data + block_size);\r
 \r
     /*\r
      * Walk through the block and check for invalid entries\r
@@ -471,8 +459,7 @@ int ext4_dir_try_insert_entry(struct ext4_sblock *sb,
 \r
         /* If invalid and large enough entry, use it */\r
         if ((inode == 0) && (rec_len >= required_len)) {\r
-            ext4_dir_write_entry(sb, dentry, rec_len, child,\r
-                    name, name_len);\r
+            ext4_dir_write_entry(sb, dentry, rec_len, child, name, name_len);\r
             target_block->dirty = true;\r
 \r
             return EOK;\r
@@ -481,10 +468,10 @@ int ext4_dir_try_insert_entry(struct ext4_sblock *sb,
         /* Valid entry, try to split it */\r
         if (inode != 0) {\r
             uint16_t used_name_len =\r
-                    ext4_dir_entry_ll_get_name_length(sb, dentry);\r
+                ext4_dir_entry_ll_get_name_length(sb, dentry);\r
 \r
             uint16_t used_space =\r
-                    sizeof(struct ext4_fake_directory_entry) + used_name_len;\r
+                sizeof(struct ext4_fake_directory_entry) + used_name_len;\r
 \r
             if ((used_name_len % 4) != 0)\r
                 used_space += 4 - (used_name_len % 4);\r
@@ -496,9 +483,9 @@ int ext4_dir_try_insert_entry(struct ext4_sblock *sb,
                 /* Cut tail of current entry */\r
                 ext4_dir_entry_ll_set_entry_length(dentry, used_space);\r
                 struct ext4_directory_entry_ll *new_entry =\r
-                        (void *) ((uint8_t *)dentry + used_space);\r
-                ext4_dir_write_entry(sb, new_entry,\r
-                    free_space, child, name, name_len);\r
+                    (void *)((uint8_t *)dentry + used_space);\r
+                ext4_dir_write_entry(sb, new_entry, free_space, child, name,\r
+                                     name_len);\r
 \r
                 target_block->dirty = true;\r
                 return EOK;\r
@@ -506,54 +493,51 @@ int ext4_dir_try_insert_entry(struct ext4_sblock *sb,
         }\r
 \r
         /* Jump to the next entry */\r
-        dentry = (void *) ((uint8_t *)dentry + rec_len);\r
+        dentry = (void *)((uint8_t *)dentry + rec_len);\r
     }\r
 \r
     /* No free space found for new entry */\r
     return ENOSPC;\r
 }\r
 \r
-\r
 int ext4_dir_find_in_block(struct ext4_block *block, struct ext4_sblock *sb,\r
-    size_t name_len, const char *name,\r
-    struct ext4_directory_entry_ll **res_entry)\r
+                           size_t name_len, const char *name,\r
+                           struct ext4_directory_entry_ll **res_entry)\r
 {\r
     /* Start from the first entry in block */\r
     struct ext4_directory_entry_ll *dentry =\r
-            (struct ext4_directory_entry_ll *) block->data;\r
+        (struct ext4_directory_entry_ll *)block->data;\r
 \r
     /* Set upper bound for cycling */\r
     uint8_t *addr_limit = block->data + ext4_sb_get_block_size(sb);\r
 \r
     /* Walk through the block and check entries */\r
-    while ((uint8_t *) dentry < addr_limit) {\r
+    while ((uint8_t *)dentry < addr_limit) {\r
         /* Termination condition */\r
-        if ((uint8_t *) dentry + name_len > addr_limit)\r
+        if ((uint8_t *)dentry + name_len > addr_limit)\r
             break;\r
 \r
         /* Valid entry - check it */\r
         if (dentry->inode != 0) {\r
             /* For more effectivity compare firstly only lengths */\r
-            if (ext4_dir_entry_ll_get_name_length(sb, dentry) ==\r
-                    name_len) {\r
+            if (ext4_dir_entry_ll_get_name_length(sb, dentry) == name_len) {\r
                 /* Compare names */\r
-                if (memcmp((uint8_t *) name, dentry->name, name_len) == 0) {\r
+                if (memcmp((uint8_t *)name, dentry->name, name_len) == 0) {\r
                     *res_entry = dentry;\r
                     return EOK;\r
                 }\r
             }\r
         }\r
 \r
-        uint16_t dentry_len =\r
-                ext4_dir_entry_ll_get_entry_length(dentry);\r
+        uint16_t dentry_len = ext4_dir_entry_ll_get_entry_length(dentry);\r
 \r
         /* Corrupted entry */\r
         if (dentry_len == 0)\r
             return EINVAL;\r
 \r
         /* Jump to next entry */\r
-        dentry = (struct ext4_directory_entry_ll *)\r
-                        ((uint8_t *) dentry + dentry_len);\r
+        dentry =\r
+            (struct ext4_directory_entry_ll *)((uint8_t *)dentry + dentry_len);\r
     }\r
 \r
     /* Entry not found */\r
@@ -561,7 +545,7 @@ int ext4_dir_find_in_block(struct ext4_block *block, struct ext4_sblock *sb,
 }\r
 \r
 int ext4_dir_destroy_result(struct ext4_inode_ref *parent,\r
-    struct ext4_directory_search_result *result)\r
+                            struct ext4_directory_search_result *result)\r
 {\r
     if (result->block.lb_id)\r
         return ext4_block_set(parent->fs->bdev, &result->block);\r