diff options
| author | gkostka <kostka.grzegorz@gmail.com> | 2015-10-16 18:50:48 +0200 |
|---|---|---|
| committer | gkostka <kostka.grzegorz@gmail.com> | 2015-10-16 18:50:48 +0200 |
| commit | 2548f2436138aa5fb080920be0a5ac7e02001199 (patch) | |
| tree | c3469b50ba4fc2b1a917182e135e1c040225b519 | |
| parent | cb2a68d7aa16480a753ca55e3b87e80527a9b5d0 (diff) | |
Extent full & simple API unification
| -rw-r--r-- | lwext4/ext4_extent.c | 54 | ||||
| -rw-r--r-- | lwext4/ext4_extent.h | 55 | ||||
| -rw-r--r-- | lwext4/ext4_extent_full.c | 19 | ||||
| -rw-r--r-- | lwext4/ext4_extent_full.h | 46 | ||||
| -rw-r--r-- | lwext4/ext4_fs.c | 17 |
5 files changed, 89 insertions, 102 deletions
diff --git a/lwext4/ext4_extent.c b/lwext4/ext4_extent.c index 9139727..abd4d83 100644 --- a/lwext4/ext4_extent.c +++ b/lwext4/ext4_extent.c @@ -123,7 +123,14 @@ static void ext4_extent_binsearch(struct ext4_extent_header *header, *extent = l - 1; } -int ext4_extent_find_block(struct ext4_inode_ref *inode_ref, uint32_t iblock, +/**@brief Get physical block in the extent tree by logical block number. + * There is no need to save path in the tree during this algorithm. + * @param inode_ref I-node to load block from + * @param iblock Logical block number to find + * @param fblock Output value for physical block number + * @return Error code*/ +static int +ext4_extent_find_block(struct ext4_inode_ref *inode_ref, uint32_t iblock, uint32_t *fblock) { int rc; @@ -348,13 +355,16 @@ static int ext4_extent_release_branch(struct ext4_inode_ref *inode_ref, return ext4_balloc_free_block(inode_ref, fblock); } -int ext4_extent_release_blocks_from(struct ext4_inode_ref *inode_ref, - uint32_t iblock_from) +int ext4_extent_remove_space(struct ext4_inode_ref *inode_ref, ext4_lblk_t from, + ext4_lblk_t to) { + if (to != (ext4_lblk_t)-1) + return ENOTSUP; + /* Find the first extent to modify */ struct ext4_extent_path *path; uint16_t i; - int rc = ext4_extent_find_extent(inode_ref, iblock_from, &path); + int rc = ext4_extent_find_extent(inode_ref, from, &path); if (rc != EOK) return rc; @@ -368,7 +378,7 @@ int ext4_extent_release_blocks_from(struct ext4_inode_ref *inode_ref, /* First extent maybe released partially */ uint32_t first_iblock = ext4_extent_get_first_block(path_ptr->extent); uint32_t first_fblock = ext4_extent_get_start(path_ptr->extent) + - iblock_from - first_iblock; + from - first_iblock; uint16_t block_count = ext4_extent_get_block_count(path_ptr->extent); @@ -716,7 +726,17 @@ static int ext4_extent_append_extent(struct ext4_inode_ref *inode_ref, return EOK; } -int ext4_extent_append_block(struct ext4_inode_ref *inode_ref, uint32_t *iblock, +/**@brief Append data block to the i-node. + * This function allocates data block, tries to append it + * to some existing extent or creates new extents. + * It includes possible extent tree modifications (splitting). + * @param inode_ref I-node to append block to + * @param iblock Output logical number of newly allocated block + * @param fblock Output physical block address of newly allocated block + * + * @return Error code*/ +static int +ext4_extent_append_block(struct ext4_inode_ref *inode_ref, uint32_t *iblock, uint32_t *fblock, bool update_size) { uint16_t i; @@ -872,6 +892,28 @@ finish: return rc; } +int ext4_extent_get_blocks(struct ext4_inode_ref *inode_ref, ext4_fsblk_t iblock, + uint32_t max_blocks, ext4_fsblk_t *result, bool create, + uint32_t *blocks_count) +{ + uint32_t iblk = iblock; + uint32_t fblk = 0; + int r; + + if (blocks_count) + return ENOTSUP; + if (max_blocks != 1) + return ENOTSUP; + + if (!create) + r = ext4_extent_find_block(inode_ref, iblk, &fblk); + else + r = ext4_extent_append_block(inode_ref, &iblk, &fblk, false); + + *result = fblk; + return r; +} + #endif /** * @} diff --git a/lwext4/ext4_extent.h b/lwext4/ext4_extent.h index 97d3d43..2684e3b 100644 --- a/lwext4/ext4_extent.h +++ b/lwext4/ext4_extent.h @@ -43,8 +43,8 @@ #include "ext4_config.h" #include "ext4_types.h" +#include "ext4_inode.h" -#if !CONFIG_EXTENT_FULL /**@brief Get logical number of the block covered by extent. * @param extent Extent to load number from @@ -237,35 +237,42 @@ ext4_extent_header_set_generation(struct ext4_extent_header *header, header->generation = to_le32(generation); } -/**@brief Find physical block in the extent tree by logical block number. - * There is no need to save path in the tree during this algorithm. - * @param inode_ref I-node to load block from - * @param iblock Logical block number to find - * @param fblock Output value for physical block number - * @return Error code*/ -int ext4_extent_find_block(struct ext4_inode_ref *inode_ref, uint32_t iblock, - uint32_t *fblock); +/******************************************************************************/ + +/**TODO: */ +static inline void ext4_extent_tree_init(struct ext4_inode_ref *inode_ref) +{ + /* Initialize extent root header */ + struct ext4_extent_header *header = + ext4_inode_get_extent_header(inode_ref->inode); + ext4_extent_header_set_depth(header, 0); + ext4_extent_header_set_entries_count(header, 0); + ext4_extent_header_set_generation(header, 0); + ext4_extent_header_set_magic(header, EXT4_EXTENT_MAGIC); + + uint16_t max_entries = (EXT4_INODE_BLOCKS * sizeof(uint32_t) - + sizeof(struct ext4_extent_header)) / + sizeof(struct ext4_extent); + + ext4_extent_header_set_max_entries_count(header, max_entries); + inode_ref->dirty = true; +} + + + +/**TODO: */ +int ext4_extent_get_blocks(struct ext4_inode_ref *inode_ref, ext4_fsblk_t iblock, + uint32_t max_blocks, ext4_fsblk_t *result, bool create, + uint32_t *blocks_count); + /**@brief Release all data blocks starting from specified logical block. * @param inode_ref I-node to release blocks from * @param iblock_from First logical block to release * @return Error code */ -int ext4_extent_release_blocks_from(struct ext4_inode_ref *inode_ref, - uint32_t iblock_from); - -/**@brief Append data block to the i-node. - * This function allocates data block, tries to append it - * to some existing extent or creates new extents. - * It includes possible extent tree modifications (splitting). - * @param inode_ref I-node to append block to - * @param iblock Output logical number of newly allocated block - * @param fblock Output physical block address of newly allocated block - * - * @return Error code*/ -int ext4_extent_append_block(struct ext4_inode_ref *inode_ref, uint32_t *iblock, - uint32_t *fblock, bool update_size); +int ext4_extent_remove_space(struct ext4_inode_ref *inode_ref, ext4_lblk_t from, + ext4_lblk_t to); -#endif #endif /* EXT4_EXTENT_H_ */ /** diff --git a/lwext4/ext4_extent_full.c b/lwext4/ext4_extent_full.c index 5231c94..4212fae 100644 --- a/lwext4/ext4_extent_full.c +++ b/lwext4/ext4_extent_full.c @@ -37,7 +37,7 @@ #include <inttypes.h> #include <stddef.h> -#include "ext4_extent_full.h" +#include "ext4_extent.h" #if CONFIG_EXTENT_FULL @@ -1372,7 +1372,7 @@ static int ext4_ext_more_to_rm(struct ext4_extent_path *path, ext4_lblk_t to) return 1; } -int ext4_ext_remove_space(struct ext4_inode_ref *inode_ref, ext4_lblk_t from, +int ext4_extent_remove_space(struct ext4_inode_ref *inode_ref, ext4_lblk_t from, ext4_lblk_t to) { struct ext4_extent_path *path = NULL; @@ -1566,19 +1566,6 @@ static int ext4_ext_convert_to_initialized(struct ext4_inode_ref *inode_ref, return err; } -int ext4_ext_tree_init(struct ext4_inode_ref *inode_ref) -{ - struct ext4_extent_header *eh; - - eh = ext_inode_hdr(inode_ref->inode); - eh->depth = 0; - eh->entries_count = 0; - eh->magic = to_le16(EXT4_EXTENT_MAGIC); - eh->max_entries_count = to_le16(ext4_ext_space_root(inode_ref)); - inode_ref->dirty = true; - return EOK; -} - /* * ext4_ext_next_allocated_block: * returns allocated block in subsequent extent or EXT_MAX_BLOCKS. @@ -1641,7 +1628,7 @@ static int ext4_ext_zero_unwritten_range(struct ext4_inode_ref *inode_ref, return err; } -int ext4_ext_get_blocks(struct ext4_inode_ref *inode_ref, ext4_fsblk_t iblock, +int ext4_extent_get_blocks(struct ext4_inode_ref *inode_ref, ext4_fsblk_t iblock, uint32_t max_blocks, ext4_fsblk_t *result, bool create, uint32_t *blocks_count) { diff --git a/lwext4/ext4_extent_full.h b/lwext4/ext4_extent_full.h deleted file mode 100644 index 61ff6d9..0000000 --- a/lwext4/ext4_extent_full.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2015 Grzegorz Kostka (kostka.grzegorz@gmail.com) - * Copyright (c) 2015 Kaho Ng (ngkaho1234@gmail.com) - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef EXT4_EXTENT_FULL_H_ -#define EXT4_EXTENT_FULL_H_ - -#include "ext4_config.h" -#include "ext4_types.h" - -#if CONFIG_EXTENT_FULL -int ext4_ext_get_blocks(struct ext4_inode_ref *inode_ref, ext4_fsblk_t iblock, - uint32_t max_blocks, ext4_fsblk_t *result, bool create, - uint32_t *blocks_count); - -int ext4_ext_tree_init(struct ext4_inode_ref *inode_ref); - -int ext4_ext_remove_space(struct ext4_inode_ref *inode_ref, ext4_lblk_t from, - ext4_lblk_t to); -#endif - -#endif /* EXT4_EXTENT_H_ */ diff --git a/lwext4/ext4_fs.c b/lwext4/ext4_fs.c index eec746a..f31d0ca 100644 --- a/lwext4/ext4_fs.c +++ b/lwext4/ext4_fs.c @@ -51,7 +51,6 @@ #include "ext4_inode.h" #include "ext4_ialloc.h" #include "ext4_extent.h" -#include "ext4_extent_full.h" #include <string.h> @@ -698,7 +697,7 @@ void ext4_fs_inode_blocks_init(struct ext4_fs *fs, struct ext4_inode_ref *inode_ ext4_inode_set_flag(inode, EXT4_INODE_FLAG_EXTENTS); /* Initialize extent root header */ - ext4_ext_tree_init(inode_ref); + ext4_extent_tree_init(inode_ref); } #endif } @@ -974,10 +973,8 @@ int ext4_fs_truncate_inode(struct ext4_inode_ref *inode_ref, uint64_t new_size) /* Extents require special operation */ if (diff_blocks_count) { - int rc = ext4_ext_remove_space( - inode_ref, - new_blocks_count, - (ext4_lblk_t)-1); + int rc = ext4_extent_remove_space(inode_ref, + new_blocks_count, (ext4_lblk_t)-1); if (rc != EOK) return rc; @@ -1026,8 +1023,8 @@ static int ext4_fs_get_inode_data_block_idx(struct ext4_inode_ref *inode_ref, (ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS))) { ext4_fsblk_t current_fsblk; - int rc = ext4_ext_get_blocks(inode_ref, iblock, 1, ¤t_fsblk, - extent_create, NULL); + int rc = ext4_extent_get_blocks(inode_ref, iblock, 1, + ¤t_fsblk, extent_create, NULL); if (rc != EOK) return rc; @@ -1412,8 +1409,8 @@ int ext4_fs_append_inode_block(struct ext4_inode_ref *inode_ref, *iblock = (inode_size + block_size - 1) / block_size; - rc = ext4_ext_get_blocks(inode_ref, *iblock, 1, ¤t_fsblk, - true, NULL); + rc = ext4_extent_get_blocks(inode_ref, *iblock, 1, + ¤t_fsblk, true, NULL); *fblock = current_fsblk; |
