From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ionut Nicu Date: Fri, 24 Jan 2014 09:59:42 +0100 Subject: [U-Boot] [PATCH] ext4fs: Add ext4 extent cache for read operations In-Reply-To: <52DE44CF.9090700@nsn.com> References: <52DE44CF.9090700@nsn.com> Message-ID: <52E22B7E.7090601@nsn.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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