[U-Boot] [PATCH] ext4fs: Add ext4 extent cache for read operations
Ionut Nicu
ioan.nicu.ext at nsn.com
Fri Jan 24 09:59:42 CET 2014
Hi,
On 21.01.2014 10:58, Ionut Nicu wrote:
>
> +static int __ext4fs_build_extent_cache(struct ext2_data *data,
> + struct ext4_extent_header *ext_block)
> {
> + int blksz = EXT2_BLOCK_SIZE(data);
> + int log2_blksz = LOG2_BLOCK_SIZE(data)
> + - get_fs()->dev_desc->log2blksz;
> + struct ext4_extent_node *node;
> struct ext4_extent_idx *index;
> + struct ext4_extent *extent;
> unsigned long long block;
> - int blksz = EXT2_BLOCK_SIZE(data);
> - int i;
> + char *buf;
> + int i, err;
>
> - while (1) {
> - index = (struct ext4_extent_idx *)(ext_block + 1);
> + if (le16_to_cpu(ext_block->eh_magic) != EXT4_EXT_MAGIC)
> + return -EINVAL;
>
> - if (le16_to_cpu(ext_block->eh_magic) != EXT4_EXT_MAGIC)
> - return 0;
> -
> - if (ext_block->eh_depth == 0)
> - return ext_block;
> - i = -1;
> - do {
> - i++;
> - if (i >= le16_to_cpu(ext_block->eh_entries))
> - break;
> - } while (fileblock >= le32_to_cpu(index[i].ei_block));
> + if (ext_block->eh_depth == 0) {
> + extent = (struct ext4_extent *)(ext_block + 1);
> + for (i = 0; i < le16_to_cpu(ext_block->eh_entries); i++) {
> + node = malloc(sizeof(*node));
> + if (!node)
> + return -ENOMEM;
> + node->block = le32_to_cpu(extent[i].ee_block);
> + node->len = le16_to_cpu(extent[i].ee_len);
> + node->start = (le16_to_cpu(extent[i].ee_start_hi) << 16)
> + + le32_to_cpu(extent[i].ee_start_lo);
Should be (le16_to_cpu(extent[i].ee_start_hi) << 32)
> diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c
> index 735b256..7963f1d 100644
> --- a/fs/ext4/ext4fs.c
> +++ b/fs/ext4/ext4fs.c
> @@ -176,10 +176,25 @@ int ext4fs_ls(const char *dirname)
>
> int ext4fs_read(char *buf, unsigned len)
> {
> + int ret;
> +
> if (ext4fs_root == NULL || ext4fs_file == NULL)
> return 0;
>
> - return ext4fs_read_file(ext4fs_file, 0, len, buf);
> + if (le32_to_cpu(ext4fs_file->inode.flags) & EXT4_EXTENTS_FL) {
> + if (ext4fs_build_extent_cache(&(ext4fs_file->inode))) {
> + printf("Error building extent cache!\n");
> + ret = -1;
> + goto out_exit;
> + }
> + }
> +
> + ret = ext4fs_read_file(ext4fs_file, 0, len, buf);
> +
> +out_exit:
> + ext4fs_free_extent_cache();
> +
> + return ret;
> }
>
ext4fs_read_file is also called by ext4fs_iterate_dir and ext4fs_read_symlink
so the place where we build the extent cache should be ext4fs_read_file instead
of extfs_read.
Please ignore this version of the patch for now, I will send a revised version.
Regards,
Ionut
More information about the U-Boot
mailing list